Skip to content

Commit a98e53c

Browse files
committed
improve start block determination for poller
1 parent 451af23 commit a98e53c

File tree

2 files changed

+626
-1
lines changed

2 files changed

+626
-1
lines changed

internal/orchestrator/poller.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,20 @@ func NewPoller(rpc rpc.IRPCClient, storage storage.IStorage, opts ...PollerOptio
8585
if err != nil || highestBlockFromStaging == nil || highestBlockFromStaging.Sign() <= 0 {
8686
log.Warn().Err(err).Msgf("No last polled block found, setting to %s", lastPolledBlock.String())
8787
} else {
88-
lastPolledBlock = highestBlockFromStaging
8988
log.Debug().Msgf("Last polled block found in staging: %s", lastPolledBlock.String())
89+
if highestBlockFromStaging.Cmp(pollFromBlock) > 0 {
90+
log.Debug().Msgf("Staging block %s is higher than configured start block %s", highestBlockFromStaging.String(), pollFromBlock.String())
91+
lastPolledBlock = highestBlockFromStaging
92+
}
93+
}
94+
highestBlockFromMainStorage, err := storage.MainStorage.GetMaxBlockNumber(rpc.GetChainID())
95+
if err != nil {
96+
log.Error().Err(err).Msg("Error getting last block in main storage")
97+
} else {
98+
if highestBlockFromMainStorage.Cmp(pollFromBlock) > 0 {
99+
log.Debug().Msgf("Main storage block %s is higher than configured start block %s", highestBlockFromMainStorage.String(), pollFromBlock.String())
100+
lastPolledBlock = highestBlockFromMainStorage
101+
}
90102
}
91103
}
92104
poller.lastPolledBlock = lastPolledBlock

0 commit comments

Comments
 (0)