start from finalized checkpoint (#7715)

This commit is contained in:
Nishant Das 2020-11-03 22:43:06 +08:00 committed by GitHub
parent cd00b6f594
commit c949913822
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 17 deletions

View File

@ -346,25 +346,23 @@ func (s *Service) processPastLogs(ctx context.Context) error {
}
s.latestEth1Data.LastRequestedBlock = currentBlockNum
b, err := s.beaconDB.HeadBlock(ctx)
c, err := s.beaconDB.FinalizedCheckpoint(ctx)
if err != nil {
return err
}
if b == nil || b.Block == nil {
fRoot := bytesutil.ToBytes32(c.Root)
// Return if no checkpoint exists yet.
if fRoot == params.BeaconConfig().ZeroHash {
return nil
}
r, err := b.Block.HashTreeRoot()
fState, err := s.stateGen.StateByRoot(ctx, fRoot)
if err != nil {
return err
}
currentState, err := s.stateGen.StateByRoot(ctx, r)
if err != nil {
return errors.Wrap(err, "could not get head state")
if fState != nil && fState.Eth1DepositIndex() > 0 {
s.depositCache.PrunePendingDeposits(ctx, int64(fState.Eth1DepositIndex()))
}
if currentState != nil && currentState.Eth1DepositIndex() > 0 {
s.depositCache.PrunePendingDeposits(ctx, int64(currentState.Eth1DepositIndex()))
}
return nil
}

View File

@ -520,19 +520,23 @@ func (s *Service) initDepositCaches(ctx context.Context, ctrs []*protodb.Deposit
return err
}
// Default to all deposits post-genesis deposits in
// the event we cannot find a suitable head state.
// the event we cannot find a finalized state.
currIndex := genesisState.Eth1DepositIndex()
rt := s.beaconDB.LastArchivedRoot(ctx)
chkPt, err := s.beaconDB.FinalizedCheckpoint(ctx)
if err != nil {
return err
}
rt := bytesutil.ToBytes32(chkPt.Root)
if rt != [32]byte{} {
currentState, err := s.beaconDB.State(ctx, rt)
fState, err := s.stateGen.StateByRoot(ctx, rt)
if err != nil {
return errors.Wrap(err, "could not get last archived state")
return errors.Wrap(err, "could not get finalized state")
}
if currentState == nil {
return errors.Errorf("archived state with root %#x does not exist in the db", rt)
if fState == nil {
return errors.Errorf("finalized state with root %#x does not exist in the db", rt)
}
// Set deposit index to the one in the current archived state.
currIndex = currentState.Eth1DepositIndex()
currIndex = fState.Eth1DepositIndex()
}
validDepositsCount.Add(float64(currIndex + 1))
// Only add pending deposits if the container slice length