mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
Stategen: always invalidate hot cache state in StateByRootInitialSync (#6698)
* Stategen: always invalidate hot cache state in StateByRootInitialSync * Sanity test. @nisdas feedback * Merge refs/heads/master into defer-invalidate
This commit is contained in:
parent
c72db6f96a
commit
2c11fcb242
@ -51,6 +51,9 @@ func (s *State) StateByRootInitialSync(ctx context.Context, blockRoot [32]byte)
|
||||
return s.beaconDB.State(ctx, blockRoot)
|
||||
}
|
||||
|
||||
// To invalidate cache for parent root because pre state will get mutated.
|
||||
defer s.hotStateCache.Delete(blockRoot)
|
||||
|
||||
if s.hotStateCache.Has(blockRoot) {
|
||||
return s.hotStateCache.GetWithoutCopy(blockRoot), nil
|
||||
}
|
||||
@ -87,9 +90,6 @@ func (s *State) StateByRootInitialSync(ctx context.Context, blockRoot [32]byte)
|
||||
return nil, errors.Wrap(err, "could not replay blocks for hot state using root")
|
||||
}
|
||||
|
||||
// To invalidate cache for parent root because pre state will get mutated.
|
||||
s.hotStateCache.Delete(blockRoot)
|
||||
|
||||
return startState, nil
|
||||
}
|
||||
|
||||
|
@ -139,11 +139,14 @@ func TestStateByRootInitialSync_UseCache(t *testing.T) {
|
||||
require.NoError(t, service.beaconDB.SaveStateSummary(ctx, &pb.StateSummary{Root: r[:]}))
|
||||
service.hotStateCache.Put(r, beaconState)
|
||||
|
||||
loadedState, err := service.StateByRoot(ctx, r)
|
||||
loadedState, err := service.StateByRootInitialSync(ctx, r)
|
||||
require.NoError(t, err)
|
||||
if !proto.Equal(loadedState.InnerStateUnsafe(), beaconState.InnerStateUnsafe()) {
|
||||
t.Error("Did not correctly cache state")
|
||||
}
|
||||
if service.hotStateCache.Has(r) {
|
||||
t.Error("Hot state cache was not invalidated")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStateByRootInitialSync_CanProcessUpTo(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user