From 782d86eefaaf0fffe62b2a8bea981701964d418c Mon Sep 17 00:00:00 2001 From: Nya Candy Date: Tue, 23 May 2023 14:56:36 +0800 Subject: [PATCH] fix: nil block caused panic --- listener/ethereum.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/listener/ethereum.go b/listener/ethereum.go index a5acbef..19448d5 100644 --- a/listener/ethereum.go +++ b/listener/ethereum.go @@ -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 }