Skip to content

Commit

Permalink
fix validator snapshot cache
Browse files Browse the repository at this point in the history
  • Loading branch information
rlan35 authored and Leo Chen committed Apr 5, 2020
1 parent 8f5f287 commit 350b7a0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2229,7 +2229,8 @@ func (bc *BlockChain) ReadValidatorSnapshotAtEpoch(
func (bc *BlockChain) ReadValidatorSnapshot(
addr common.Address,
) (*staking.ValidatorWrapper, error) {
if cached, ok := bc.validatorCache.Get("validator-snapshot-" + string(addr.Bytes())); ok {
epoch := bc.CurrentBlock().Epoch()
if cached, ok := bc.validatorCache.Get("validator-snapshot-" + string(addr.Bytes()) + epoch.String()); ok {
by := cached.([]byte)
v := staking.ValidatorWrapper{}
if err := rlp.DecodeBytes(by, &v); err != nil {
Expand All @@ -2238,7 +2239,7 @@ func (bc *BlockChain) ReadValidatorSnapshot(
return &v, nil
}

return rawdb.ReadValidatorSnapshot(bc.db, addr, bc.CurrentBlock().Epoch())
return rawdb.ReadValidatorSnapshot(bc.db, addr, epoch)
}

// writeValidatorSnapshots writes the snapshot of provided list of validators
Expand Down Expand Up @@ -2266,7 +2267,7 @@ func (bc *BlockChain) writeValidatorSnapshots(
for i := range validators {
by, err := rlp.EncodeToBytes(validators[i])
if err == nil {
key := "validator-snapshot-" + string(validators[i].Address.Bytes())
key := "validator-snapshot-" + string(validators[i].Address.Bytes()) + epoch.String()
bc.validatorCache.Add(key, by)
}
}
Expand Down

0 comments on commit 350b7a0

Please sign in to comment.