Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc: handle crash on empty safe block #532

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why blockNum would be nil?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe after sync, before finalize in parlia is called safe hash is empty one, but I couldn't reproduce it I had to go over the code and find potential issue

return *blockNum, blockHash, false, nil
}
}
blockNumber, err = GetSafeBlockNumber(tx)
if err != nil {
Expand Down
Loading