Commit fd19665c authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

Merge pull request #7838 from LuisMarcano-antithesis/fix/race

fix: race condition updating last updated scorebook timestamp
parents 31704c5a d2ad25ef
......@@ -2,6 +2,7 @@ package store
import (
"context"
"sync/atomic"
"time"
"github.com/ethereum-optimism/optimism/op-service/clock"
......@@ -17,17 +18,18 @@ const (
var scoresBase = ds.NewKey("/peers/scores")
// LastUpdate requires atomic update operations. Use the helper functions SetLastUpdated and LastUpdated to modify and access this field.
type scoreRecord struct {
PeerScores PeerScores `json:"peerScores"`
LastUpdate int64 `json:"lastUpdate"` // unix timestamp in seconds
PeerScores PeerScores `json:"peerScores"`
}
func (s *scoreRecord) SetLastUpdated(t time.Time) {
s.LastUpdate = t.Unix()
atomic.StoreInt64(&s.LastUpdate, t.Unix())
}
func (s *scoreRecord) LastUpdated() time.Time {
return time.Unix(s.LastUpdate, 0)
return time.Unix(atomic.LoadInt64(&s.LastUpdate), 0)
}
func (s *scoreRecord) MarshalBinary() (data []byte, err error) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment