From c94991382214d4f25def31ef935c28f5c4624f6a Mon Sep 17 00:00:00 2001 From: Nishant Das Date: Tue, 3 Nov 2020 22:43:06 +0800 Subject: [PATCH] start from finalized checkpoint (#7715) --- beacon-chain/powchain/log_processing.go | 18 ++++++++---------- beacon-chain/powchain/service.go | 18 +++++++++++------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/beacon-chain/powchain/log_processing.go b/beacon-chain/powchain/log_processing.go index 27ba66114..85d7d885a 100644 --- a/beacon-chain/powchain/log_processing.go +++ b/beacon-chain/powchain/log_processing.go @@ -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 } diff --git a/beacon-chain/powchain/service.go b/beacon-chain/powchain/service.go index 55db17af0..dc323d02a 100644 --- a/beacon-chain/powchain/service.go +++ b/beacon-chain/powchain/service.go @@ -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