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:
terence tsao 2020-08-03 11:34:54 -07:00 committed by GitHub
parent 69e0e302b3
commit ee7da0d451
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -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

View File

@ -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)
}
}