Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix edge case where existing range end block causes crashes #121

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions internal/orchestrator/poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ func NewBoundlessPoller(rpc rpc.IRPCClient, storage storage.IStorage) *Poller {
}
}

var ErrNoNewBlocks = fmt.Errorf("no new blocks to poll")

func NewPoller(rpc rpc.IRPCClient, storage storage.IStorage) *Poller {
poller := NewBoundlessPoller(rpc, storage)
untilBlock := big.NewInt(int64(config.Cfg.Poller.UntilBlock))
Expand Down Expand Up @@ -89,7 +91,9 @@ func (p *Poller) Start() {
blockRangeMutex.Unlock()

if err != nil {
log.Error().Err(err).Msg("Error getting block range")
if err != ErrNoNewBlocks {
log.Error().Err(err).Msg("Failed to get block range to poll")
}
continue
}

Expand Down Expand Up @@ -132,7 +136,7 @@ func (p *Poller) Poll(blockNumbers []*big.Int) (lastPolledBlock *big.Int) {
}

func (p *Poller) reachedPollLimit(blockNumber *big.Int) bool {
return p.pollUntilBlock.Sign() > 0 && blockNumber.Cmp(p.pollUntilBlock) >= 0
return blockNumber == nil || (p.pollUntilBlock.Sign() > 0 && blockNumber.Cmp(p.pollUntilBlock) >= 0)
}

func (p *Poller) getNextBlockRange() ([]*big.Int, error) {
Expand All @@ -145,7 +149,7 @@ func (p *Poller) getNextBlockRange() ([]*big.Int, error) {
startBlock := new(big.Int).Add(p.lastPolledBlock, big.NewInt(1))
if startBlock.Cmp(latestBlock) > 0 {
log.Debug().Msgf("Start block %s is greater than latest block %s, skipping", startBlock, latestBlock)
return nil, nil
return nil, ErrNoNewBlocks
}
endBlock := p.getEndBlockForRange(startBlock, latestBlock)
if startBlock.Cmp(endBlock) > 0 {
Expand Down
Loading