From 28839fbab26502ac52823c222770b2ad90e92b1a Mon Sep 17 00:00:00 2001 From: terence tsao Date: Sat, 13 Feb 2021 15:13:20 -0800 Subject: [PATCH] Use latest block header + slot as skip slot cache key (#8443) --- beacon-chain/core/state/skip_slot_cache.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/beacon-chain/core/state/skip_slot_cache.go b/beacon-chain/core/state/skip_slot_cache.go index f3fe4fe94..371618789 100644 --- a/beacon-chain/core/state/skip_slot_cache.go +++ b/beacon-chain/core/state/skip_slot_cache.go @@ -2,6 +2,7 @@ package state import ( "context" + "errors" "github.com/prysmaticlabs/prysm/beacon-chain/cache" beaconstate "github.com/prysmaticlabs/prysm/beacon-chain/state" @@ -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 }