node: Fixed potential latest block nil dereference

This commit is contained in:
Kevin Peters 2022-09-16 15:40:51 +00:00 committed by Evan Gray
parent 64952c8d85
commit e31f3e603d
1 changed files with 4 additions and 3 deletions

View File

@ -167,13 +167,14 @@ func (e *PollImpl) SubscribeForBlocks(ctx context.Context, sink chan<- *common.N
// See if the next block has been created yet.
if currentBlockNumber.Cmp(latestBlock.Number) > 0 {
latestBlock, err = e.getBlock(ctx, nil)
if err != nil {
tmpLatestBlock, latestBlockErr := e.getBlock(ctx, nil)
if latestBlockErr != nil {
errorOccurred = true
e.logger.Error("failed to look up latest block", zap.String("eth_network", e.BaseEth.NetworkName),
zap.Uint64("block", currentBlockNumber.Uint64()), zap.Error(err))
zap.Uint64("block", currentBlockNumber.Uint64()), zap.Error(latestBlockErr))
break
}
latestBlock = tmpLatestBlock
if currentBlockNumber.Cmp(latestBlock.Number) > 0 {
// We have to wait for this block to become available.