Skip to content

Commit

Permalink
Merge pull request #27 from Crossbell-Box/fix/nil-block-caused-panic
Browse files Browse the repository at this point in the history
fix: nil block caused panic
  • Loading branch information
iavl authored May 23, 2023
2 parents 2bcb920 + 782d86e commit e743987
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions listener/ethereum.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,13 +254,15 @@ func (e *EthereumListener) GetSubscriptions() map[string]*bridgeCore.Subscribe {
}

func (e *EthereumListener) UpdateCurrentBlock(block bridgeCore.Block) error {
if block != nil && e.GetCurrentBlock().GetHeight() < block.GetHeight() {
log.Info(fmt.Sprintf("[%sListener] UpdateCurrentBlock", e.name), "new block", block.GetHeight(), "current block", e.GetCurrentBlock().GetHeight())
e.currentBlock.Store(block)
return e.SaveCurrentBlockToDB()
} else if e.GetCurrentBlock().GetHeight() >= block.GetHeight() {
log.Info(fmt.Sprintf("[%sListener] UpdateCurrentBlock: block <= current block. Check the RPC if needed", e.name), "new block", block.GetHeight(), "current block", e.GetCurrentBlock().GetHeight())
}
if block != nil {
if e.GetCurrentBlock().GetHeight() < block.GetHeight() {
log.Info(fmt.Sprintf("[%sListener] UpdateCurrentBlock", e.name), "new block", block.GetHeight(), "current block", e.GetCurrentBlock().GetHeight())
e.currentBlock.Store(block)
return e.SaveCurrentBlockToDB()
} else if e.GetCurrentBlock().GetHeight() >= block.GetHeight() {
log.Info(fmt.Sprintf("[%sListener] UpdateCurrentBlock: block <= current block. Check the RPC if needed", e.name), "new block", block.GetHeight(), "current block", e.GetCurrentBlock().GetHeight())
}
} // else just skip this block
return nil
}

Expand Down

0 comments on commit e743987

Please sign in to comment.