-
Notifications
You must be signed in to change notification settings - Fork 489
Finalized keyword and legacy RPC fixes #2655
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -119,15 +119,25 @@ func (b *QuaiAPIBackend) HeaderByHash(ctx context.Context, hash common.Hash) (*t | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| func (b *QuaiAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.WorkObject, error) { | ||||||||||||||||||||||||||||||||||||||||||
| // Pending block is only known by the miner | ||||||||||||||||||||||||||||||||||||||||||
| if number == rpc.PendingBlockNumber { | ||||||||||||||||||||||||||||||||||||||||||
| switch number { | ||||||||||||||||||||||||||||||||||||||||||
| case rpc.PendingBlockNumber: | ||||||||||||||||||||||||||||||||||||||||||
| block := b.quai.core.PendingBlock() | ||||||||||||||||||||||||||||||||||||||||||
| return block, nil | ||||||||||||||||||||||||||||||||||||||||||
| case rpc.SafeBlockNumber: | ||||||||||||||||||||||||||||||||||||||||||
| latestNumber := rpc.BlockNumber(b.quai.core.CurrentHeader().NumberU64(b.NodeCtx())) | ||||||||||||||||||||||||||||||||||||||||||
| safeNumber := rpc.BlockNumber(latestNumber - 5) // TODO: make this a constant param | ||||||||||||||||||||||||||||||||||||||||||
| return b.quai.core.GetBlockByNumber(uint64(safeNumber)), nil | ||||||||||||||||||||||||||||||||||||||||||
| case rpc.FinalizedBlockNumber: | ||||||||||||||||||||||||||||||||||||||||||
| latestNumber := rpc.BlockNumber(b.quai.core.CurrentHeader().NumberU64(b.NodeCtx())) | ||||||||||||||||||||||||||||||||||||||||||
| finalizedNumber := rpc.BlockNumber(latestNumber - 5) // TODO: make this a constant param | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+128
to
+132
|
||||||||||||||||||||||||||||||||||||||||||
| safeNumber := rpc.BlockNumber(latestNumber - 5) // TODO: make this a constant param | |
| return b.quai.core.GetBlockByNumber(uint64(safeNumber)), nil | |
| case rpc.FinalizedBlockNumber: | |
| latestNumber := rpc.BlockNumber(b.quai.core.CurrentHeader().NumberU64(b.NodeCtx())) | |
| finalizedNumber := rpc.BlockNumber(latestNumber - 5) // TODO: make this a constant param | |
| safeNumber := rpc.BlockNumber(latestNumber - SafeBlockOffset) | |
| return b.quai.core.GetBlockByNumber(uint64(safeNumber)), nil | |
| case rpc.FinalizedBlockNumber: | |
| latestNumber := rpc.BlockNumber(b.quai.core.CurrentHeader().NumberU64(b.NodeCtx())) | |
| finalizedNumber := rpc.BlockNumber(latestNumber - SafeBlockOffset) |
Copilot
AI
Jul 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic number 5 for calculating finalized block number should be defined as a named constant. Additionally, safe and finalized blocks having the same offset seems incorrect - finalized blocks should typically be further back than safe blocks.
| safeNumber := rpc.BlockNumber(latestNumber - 5) // TODO: make this a constant param | |
| return b.quai.core.GetBlockByNumber(uint64(safeNumber)), nil | |
| case rpc.FinalizedBlockNumber: | |
| latestNumber := rpc.BlockNumber(b.quai.core.CurrentHeader().NumberU64(b.NodeCtx())) | |
| finalizedNumber := rpc.BlockNumber(latestNumber - 5) // TODO: make this a constant param | |
| safeNumber := rpc.BlockNumber(latestNumber - SafeBlockOffset) | |
| return b.quai.core.GetBlockByNumber(uint64(safeNumber)), nil | |
| case rpc.FinalizedBlockNumber: | |
| latestNumber := rpc.BlockNumber(b.quai.core.CurrentHeader().NumberU64(b.NodeCtx())) | |
| finalizedNumber := rpc.BlockNumber(latestNumber - FinalizedBlockOffset) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message formats bytes as a string using %s, which will not display the address in a readable format. Consider using %x for hex formatting or converting to a proper address string representation.