Skip to content

Commit

Permalink
Merge pull request #3636 from JackyWYX/bc_validatorsnapshotcache_fix
Browse files Browse the repository at this point in the history
[blockchain] added cache in ReadValidatorSnapshot
  • Loading branch information
rlan35 authored Apr 3, 2021
2 parents 52ac53e + cff288a commit 7875921
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2332,7 +2332,12 @@ func (bc *BlockChain) ReadValidatorSnapshot(
if cached, ok := bc.validatorSnapshotCache.Get(key); ok {
return cached.(*staking.ValidatorSnapshot), nil
}
return rawdb.ReadValidatorSnapshot(bc.db, addr, epoch)
vs, err := rawdb.ReadValidatorSnapshot(bc.db, addr, epoch)
if err != nil {
return nil, err
}
bc.validatorSnapshotCache.Add(key, vs)
return vs, nil
}

// WriteValidatorSnapshot writes the snapshot of provided validator
Expand Down

0 comments on commit 7875921

Please sign in to comment.