mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-12 04:30:04 +00:00
ForceCheckpoint
return early when zero hashes (#6852)
* Setter: return early with zero hashes * Test: zero hashes don't panic * Merge branch 'master' of github.com:prysmaticlabs/prysm * Merge refs/heads/master into zero-hashes * Merge refs/heads/master into zero-hashes * Merge refs/heads/master into zero-hashes
This commit is contained in:
parent
69e0e302b3
commit
ee7da0d451
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/prysmaticlabs/prysm/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
@ -29,6 +30,12 @@ func (s *State) ForceCheckpoint(ctx context.Context, root []byte) error {
|
||||
defer span.End()
|
||||
|
||||
root32 := bytesutil.ToBytes32(root)
|
||||
// Before the first finalized check point, the finalized root is zero hash.
|
||||
// Return early if there hasn't been a finalized check point.
|
||||
if root32 == params.BeaconConfig().ZeroHash {
|
||||
return nil
|
||||
}
|
||||
|
||||
fs, err := s.loadHotStateByRoot(ctx, root32)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -99,4 +99,9 @@ func TestState_ForceCheckpoint_SavesStateToDatabase(t *testing.T) {
|
||||
if !db.HasState(ctx, r) {
|
||||
t.Error("Did not save checkpoint to database")
|
||||
}
|
||||
|
||||
// Should not panic with genesis finalized root.
|
||||
if err := svc.ForceCheckpoint(ctx, params.BeaconConfig().ZeroHash[:]); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user