-
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?
Conversation
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.
Pull Request Overview
This PR implements support for "finalized" and "safe" block number keywords in the RPC interface and fixes legacy RPC compatibility issues. The changes enable Ethereum-compatible clients to query for finalized and safe blocks while maintaining native Quai functionality.
- Adds
SafeBlockNumberandFinalizedBlockNumberconstants with JSON unmarshaling support - Updates filter API to support namespace-aware header marshaling for ETH compatibility
- Implements block number resolution for safe and finalized blocks in the API backend
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| rpc/types.go | Adds new block number constants and JSON parsing for "safe" and "finalized" keywords |
| quai/filters/api.go | Updates filter API constructor to accept namespace parameter and adds ETH-compatible header marshaling |
| quai/filters/filter_system_test.go | Updates test cases to provide namespace parameter to NewPublicFilterAPI calls |
| quai/backend.go | Adds namespace parameters when registering filter APIs for "eth" and "quai" namespaces |
| quai/api_backend.go | Implements block resolution logic for safe, finalized, latest, and pending block numbers |
| internal/quaiapi/transaction_args.go | Adds address validation for Qi transaction outputs |
| internal/quaiapi/api.go | Filters transactions to only include QuaiTxType in ETH block marshaling |
Comments suppressed due to low confidence (1)
quai/filters/filter_system_test.go:362
- [nitpick] This test uses "test" as the namespace parameter, which differs from the production namespaces "eth" and "quai". Consider using one of the actual production namespaces to better reflect real usage scenarios.
api = NewPublicFilterAPI(backend, deadline, 1, "test")
| 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 |
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 safe block number should be defined as a named constant to improve maintainability and make the offset configurable.
| 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) |
| 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 |
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) |
| } | ||
| for i, out := range args.TxOut { | ||
| if len(out.Address.Address().Bytes()) != 20 { | ||
| return 0, fmt.Errorf("Qi transaction has an output with an invalid address: %s", out.Address.Address().Bytes()) |
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 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.
| return 0, fmt.Errorf("Qi transaction has an output with an invalid address: %s", out.Address.Address().Bytes()) | |
| return 0, fmt.Errorf("Qi transaction has an output with an invalid address: %x", out.Address.Address().Bytes()) |
…ror return in CalculateQiTxGas
83a73e7 to
4f728ef
Compare
No description provided.