From 3686e53ddbcda2f46c2adf39566e6a97cde10198 Mon Sep 17 00:00:00 2001 From: Matus Kysel Date: Mon, 14 Oct 2024 14:44:59 +0200 Subject: [PATCH] rpc: handle crash on empty safe block --- turbo/rpchelper/helper.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/turbo/rpchelper/helper.go b/turbo/rpchelper/helper.go index 23f7344bbc3..90600decd4e 100644 --- a/turbo/rpchelper/helper.go +++ b/turbo/rpchelper/helper.go @@ -20,6 +20,7 @@ import ( "context" "errors" "fmt" + libcommon "github.com/erigontech/erigon-lib/common" "github.com/erigontech/erigon-lib/kv" "github.com/erigontech/erigon-lib/kv/kvcache" @@ -85,8 +86,7 @@ func _GetBlockNumber(ctx context.Context, requireCanonical bool, blockNrOrHash r } if fs := parliafinality.GetFinalizationService(); fs != nil { blockHash := fs.GetFinalizeBlockHash() - blockNum := rawdb.ReadHeaderNumber(tx, blockHash) - if blockNum != nil { + if blockNum := rawdb.ReadHeaderNumber(tx, blockHash); blockNum != nil { return *blockNum, blockHash, false, nil } } @@ -97,8 +97,9 @@ func _GetBlockNumber(ctx context.Context, requireCanonical bool, blockNrOrHash r case rpc.SafeBlockNumber: if fs := parliafinality.GetFinalizationService(); fs != nil { blockHash := fs.GetSafeBlockHash() - blockNum := rawdb.ReadHeaderNumber(tx, blockHash) - return *blockNum, blockHash, false, nil + if blockNum := rawdb.ReadHeaderNumber(tx, blockHash); blockNum != nil { + return *blockNum, blockHash, false, nil + } } blockNumber, err = GetSafeBlockNumber(tx) if err != nil {