Skip to content

Commit

Permalink
rpc: handle crash on empty safe block (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatusKysel authored Oct 15, 2024
1 parent f10d0fe commit 4df9747
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions turbo/rpchelper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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 {
Expand Down

0 comments on commit 4df9747

Please sign in to comment.