From 46c67f1e9e33b56921d49b8f65f3ee91ee36457d Mon Sep 17 00:00:00 2001 From: Nishant Das Date: Fri, 18 Dec 2020 02:49:22 +0800 Subject: [PATCH] Fallback To Historical Sync For Powchain (#8146) Co-authored-by: Raul Jordan Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> --- beacon-chain/powchain/log_processing.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/beacon-chain/powchain/log_processing.go b/beacon-chain/powchain/log_processing.go index 210b04e3d..9368bb3df 100644 --- a/beacon-chain/powchain/log_processing.go +++ b/beacon-chain/powchain/log_processing.go @@ -31,6 +31,7 @@ var ( const eth1LookBackPeriod = 100 const eth1DataSavingInterval = 100 +const maxTolerableDifference = 50 const defaultEth1HeaderReqLimit = uint64(1000) const depositlogRequestLimit = 10000 @@ -360,6 +361,11 @@ func (s *Service) requestBatchedHeadersAndLogs(ctx context.Context) error { if err != nil { return err } + if requestedBlock > s.latestEth1Data.LastRequestedBlock && + requestedBlock-s.latestEth1Data.LastRequestedBlock > maxTolerableDifference { + log.Infof("Falling back to historical headers and logs sync. Current difference is %d", requestedBlock-s.latestEth1Data.LastRequestedBlock) + return s.processPastLogs(ctx) + } for i := s.latestEth1Data.LastRequestedBlock + 1; i <= requestedBlock; i++ { // Cache eth1 block header here. _, err := s.BlockHashByHeight(ctx, big.NewInt(int64(i)))