Skip to content

Commit

Permalink
Use latest block header + slot as skip slot cache key (#8443)
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain authored Feb 13, 2021
1 parent 0716519 commit 28839fb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion beacon-chain/core/state/skip_slot_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package state

import (
"context"
"errors"

"github.com/prysmaticlabs/prysm/beacon-chain/cache"
beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state"
Expand All @@ -19,7 +20,11 @@ var SkipSlotCache = cache.NewSkipSlotCache()
// state root is in the mix to defend against different forks with same skip slots
// to hit the same cache. We don't want beacon states mixed up between different chains.
func cacheKey(ctx context.Context, state *beaconstate.BeaconState) ([32]byte, error) {
r, err := state.HashTreeRoot(ctx)
bh := state.LatestBlockHeader()
if bh == nil {
return [32]byte{}, errors.New("block head in state can't be nil")
}
r, err := bh.HashTreeRoot()
if err != nil {
return [32]byte{}, err
}
Expand Down

0 comments on commit 28839fb

Please sign in to comment.