Fallback To Historical Sync For Powchain (#8146)

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Nishant Das 2020-12-18 02:49:22 +08:00 committed by GitHub
parent 44c3adb367
commit 46c67f1e9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)))