Skip to content

Commit

Permalink
Add HasBlock to verify parent check (#5478)
Browse files Browse the repository at this point in the history
* Add HasBlock to verify parent check
* Comment
* Fixed existing tests
* Merge refs/heads/master into fix-verify-blk-pre-state
  • Loading branch information
terencechain authored Apr 18, 2020
1 parent 7a65e0e commit ce6ce5a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions beacon-chain/blockchain/process_block_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ func (s *Service) verifyBlkPreState(ctx context.Context, b *ethpb.BeaconBlock) (

if !featureconfig.Get().DisableNewStateMgmt {
parentRoot := bytesutil.ToBytes32(b.ParentRoot)
if !s.stateGen.StateSummaryExists(ctx, parentRoot) {
return nil, errors.New("provided block root does not have block saved in the db")
// Loosen the check to HasBlock because state summary gets saved in batches
// during initial syncing. There's no risk given a state summary object is just a
// a subset of the block object.
if !s.stateGen.StateSummaryExists(ctx, parentRoot) && !s.beaconDB.HasBlock(ctx, parentRoot) {
return nil, errors.New("could not reconstruct parent state")
}
preState, err := s.stateGen.StateByRoot(ctx, parentRoot)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/blockchain/process_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func TestStore_OnBlock(t *testing.T) {
name: "parent block root does not have a state",
blk: &ethpb.BeaconBlock{},
s: st.Copy(),
wantErrString: "provided block root does not have block saved in the db",
wantErrString: "could not reconstruct parent state",
},
{
name: "block is from the feature",
Expand Down Expand Up @@ -354,7 +354,7 @@ func TestCachedPreState_CanGetFromDB(t *testing.T) {

service.finalizedCheckpt = &ethpb.Checkpoint{Root: r[:]}
_, err = service.verifyBlkPreState(ctx, b)
wanted := "provided block root does not have block saved in the db"
wanted := "could not reconstruct parent state"
if err.Error() != wanted {
t.Error("Did not get wanted error")
}
Expand Down

0 comments on commit ce6ce5a

Please sign in to comment.