Save Boundary States (#6542)

This commit is contained in:
Nishant Das 2020-07-11 00:00:41 +08:00 committed by GitHub
parent 2c9474ab7f
commit cc8b3e349d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -221,11 +221,16 @@ func (s *Service) onBlockBatch(ctx context.Context, blks []*ethpb.SignedBeaconBl
Messages: [][32]byte{}, Messages: [][32]byte{},
} }
set := new(bls.SignatureSet) set := new(bls.SignatureSet)
boundaries := make(map[[32]byte]*stateTrie.BeaconState)
for i, b := range blks { for i, b := range blks {
set, preState, err = state.ExecuteStateTransitionNoVerifyAnySig(ctx, preState, b) set, preState, err = state.ExecuteStateTransitionNoVerifyAnySig(ctx, preState, b)
if err != nil { if err != nil {
return nil, nil, nil, err return nil, nil, nil, err
} }
// Save potential boundary states.
if helpers.IsEpochStart(preState.Slot()) {
boundaries[blockRoots[i]] = preState.Copy()
}
jCheckpoints[i] = preState.CurrentJustifiedCheckpoint() jCheckpoints[i] = preState.CurrentJustifiedCheckpoint()
fCheckpoints[i] = preState.FinalizedCheckpoint() fCheckpoints[i] = preState.FinalizedCheckpoint()
sigSet.Join(set) sigSet.Join(set)
@ -237,6 +242,11 @@ func (s *Service) onBlockBatch(ctx context.Context, blks []*ethpb.SignedBeaconBl
if !verify { if !verify {
return nil, nil, nil, errors.New("batch block signature verification failed") return nil, nil, nil, errors.New("batch block signature verification failed")
} }
for r, st := range boundaries {
if err := s.stateGen.SaveState(ctx, r, st); err != nil {
return nil, nil, nil, err
}
}
return preState, fCheckpoints, jCheckpoints, nil return preState, fCheckpoints, jCheckpoints, nil
} }