Skip to content

Commit

Permalink
Keep nonce by value in CachedDB
Browse files Browse the repository at this point in the history
  • Loading branch information
poszu committed May 20, 2024
1 parent 150e1fc commit f2681e7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions datastore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type CachedDB struct {
atxsdata *atxsdata.Data

atxCache *lru.Cache[types.ATXID, *types.ActivationTx]
vrfNonceCache *lru.Cache[VrfNonceKey, *types.VRFPostIndex]
vrfNonceCache *lru.Cache[VrfNonceKey, types.VRFPostIndex]

// used to coordinate db update and cache
mu sync.Mutex
Expand Down Expand Up @@ -108,7 +108,7 @@ func NewCachedDB(db Executor, lg log.Log, opts ...Opt) *CachedDB {
lg.Fatal("failed to create malfeasance cache", err)
}

vrfNonceCache, err := lru.New[VrfNonceKey, *types.VRFPostIndex](o.cfg.ATXSize)
vrfNonceCache, err := lru.New[VrfNonceKey, types.VRFPostIndex](o.cfg.ATXSize)
if err != nil {
lg.Fatal("failed to create vrf nonce cache", err)
}
Expand Down Expand Up @@ -194,15 +194,15 @@ func (db *CachedDB) CacheMalfeasanceProof(id types.NodeID, proof *wire.Malfeasan
func (db *CachedDB) VRFNonce(id types.NodeID, epoch types.EpochID) (types.VRFPostIndex, error) {
key := VrfNonceKey{id, epoch}
if nonce, ok := db.vrfNonceCache.Get(key); ok {
return *nonce, nil
return nonce, nil
}

nonce, err := atxs.VRFNonce(db, id, epoch)
if err != nil {
return types.VRFPostIndex(0), err
}

db.vrfNonceCache.Add(key, &nonce)
db.vrfNonceCache.Add(key, nonce)
return nonce, nil
}

Expand Down

0 comments on commit f2681e7

Please sign in to comment.