Skip to content

Conversation

@jdowning100
Copy link
Contributor

No description provided.

Copilot AI review requested due to automatic review settings July 31, 2025 03:25
Copy link

Copilot AI left a 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 SafeBlockNumber and FinalizedBlockNumber constants 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")

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
Copy link

Copilot AI Jul 31, 2025

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.

Suggested change
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 uses AI. Check for mistakes.
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
Copy link

Copilot AI Jul 31, 2025

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.

Suggested change
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)

Copilot uses AI. Check for mistakes.
}
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())
Copy link

Copilot AI Jul 31, 2025

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.

Suggested change
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())

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant