diff --git a/atxsdata/data.go b/atxsdata/data.go index dc30cf50800..be5ca5a1283 100644 --- a/atxsdata/data.go +++ b/atxsdata/data.go @@ -2,8 +2,7 @@ package atxsdata import ( "sync" - - "go.uber.org/atomic" + "sync/atomic" "github.com/spacemeshos/go-spacemesh/common/types" ) @@ -74,8 +73,6 @@ func (d *Data) IsEvicted(epoch types.EpochID) bool { // OnEpoch is a notification for cache to evict epochs that are not useful // to keep in memory. func (d *Data) OnEpoch(applied types.EpochID) { - d.mu.Lock() - defer d.mu.Unlock() if applied < d.capacity { return } @@ -83,6 +80,9 @@ func (d *Data) OnEpoch(applied types.EpochID) { if d.IsEvicted(evict) { return } + + d.mu.Lock() + defer d.mu.Unlock() if d.evicted.Load() < evict.Uint32() { d.evicted.Store(evict.Uint32()) } @@ -102,11 +102,11 @@ func (d *Data) Add( nonce types.VRFPostIndex, malicious bool, ) { - d.mu.Lock() - defer d.mu.Unlock() if d.IsEvicted(epoch) { return } + d.mu.Lock() + defer d.mu.Unlock() ecache, exists := d.epochs[epoch] if !exists { ecache = epochCache{ diff --git a/atxsdata/warmup.go b/atxsdata/warmup.go index 5f22a952e9d..e61888d8266 100644 --- a/atxsdata/warmup.go +++ b/atxsdata/warmup.go @@ -54,13 +54,3 @@ func Warmup(db sql.Executor, cache *Data) error { } return ierr } - -func ToATXData(atx *types.ActivationTxHeader, nonce types.VRFPostIndex, malicious bool) *ATX { - return &ATX{ - Weight: atx.GetWeight(), - BaseHeight: atx.BaseTickHeight, - Height: atx.TickHeight(), - Nonce: nonce, - Malicious: malicious, - } -}