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

fix: return proper synthetic tx in eth_getBlockByNumber RPC #3634

Merged
merged 5 commits into from
Mar 5, 2025

Conversation

skosito
Copy link
Contributor

@skosito skosito commented Mar 4, 2025

Description

no need to emit gas payment events

it appears that eth_getBlockByNumber that blosckout use for indexing is indexing gas payment deposit instead of proper tx

2 solutions here, both can be implemented or one:

  • add noEthereumTxEvent to deposit zrc20, and for both usages of pay gas set true, skipping emitting these events, is there a use case for events to be here?

  • it seems in get block by number, order of events is reversed, so simply taking last works on these txs at least, looks like a bare minimum fix, without changing how events are emitted, so there will still be redundant data

How Has This Been Tested?

  • Tested CCTX in localnet
  • Tested in development environment
  • Go unit tests
  • Go integration tests
  • Tested via GitHub Actions

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced block query responses so that the eth_getBlockByNumber RPC now returns the correct synthetic transaction data, ensuring improved reliability in the information provided to users.

Copy link
Contributor

coderabbitai bot commented Mar 4, 2025

📝 Walkthrough

Walkthrough

This pull request introduces a changelog entry for PR [3634] that specifies the eth_getBlockByNumber RPC now returns the correct synthetic transaction. Additionally, several test files have reorganized their import statements without affecting underlying functionality. Finally, the ParseTxBlockResult function in rpc/types/events.go has been updated to select the last transaction from the list instead of the first, with a note for further investigation into the order of synthetic transaction events.

Changes

Files Change Summary
changelog.md Added a changelog entry for PR [3634] to indicate that eth_getBlockByNumber now returns the proper synthetic transaction.
precompiles/bank/method_test.go, precompiles/staking/staking_test.go, x/crosschain/keeper/utils_test.go, x/fungible/keeper/deposits_test.go Reorganized import statements (including adjustments of the erc1967proxy, math/big, and testing packages) without altering functionality.
rpc/types/events.go Modified the ParseTxBlockResult function to use the last transaction (txs.Txs[len(txs.Txs)-1]) instead of the first, with an investigation note regarding event order.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant RPC_Server
    participant TxParser
    Client->>RPC_Server: Request block by number (eth_getBlockByNumber)
    RPC_Server->>TxParser: Retrieve tx block result
    TxParser->>TxParser: Select last synthetic transaction from txs.Txs
    TxParser->>RPC_Server: Return block with accurate synthetic tx
    RPC_Server->>Client: Deliver block with correct synthetic tx data
Loading

Possibly related PRs

Suggested labels

bug, CONSENSUS_TESTS

Suggested reviewers

  • gartnera
  • lumtis
  • kingpinXD
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@skosito skosito changed the title fix gas payment event indexing fix: gas payment event indexing Mar 4, 2025
skosito added 3 commits March 5, 2025 15:13
…enter a commit message to explain why this merge is necessary, # especially if it merges an updated upstream into a

topic branch. # # Lines starting with '#' will be ignored, and an empty message aborts # the commit.
@skosito skosito linked an issue Mar 5, 2025 that may be closed by this pull request
Copy link

codecov bot commented Mar 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 64.56%. Comparing base (f7681d8) to head (8f22729).
Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #3634   +/-   ##
========================================
  Coverage    64.56%   64.56%           
========================================
  Files          469      469           
  Lines        32772    32772           
========================================
  Hits         21159    21159           
  Misses       10648    10648           
  Partials       965      965           

@skosito skosito changed the title fix: gas payment event indexing fix: return proper synthetic tx in eth_getBlockByNumber RPC Mar 5, 2025
@skosito skosito marked this pull request as ready for review March 5, 2025 14:58
@skosito skosito requested a review from a team as a code owner March 5, 2025 14:58
@skosito skosito requested a review from kingpinXD March 5, 2025 14:58
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
rpc/types/events.go (1)

276-277: The fix addresses the symptom, but consider investigating the root cause.

The change correctly modifies the behavior to select the last transaction from the array instead of the first one, which should fix the immediate issue with the RPC returning incorrect transactions. However, the TODO comment indicates that there's still a need to understand why synthetic transaction events are in reversed order.

Consider investigating the core issue in event emission to potentially address this at the source rather than adjusting the consumption pattern.

You could add more detailed documentation about this behavior by expanding the TODO comment:

- // TODO: check why when there are multiple synthetic txs events are in reversed order
+ // TODO: check why when there are multiple synthetic txs events are in reversed order.
+ // For now, we're taking the last transaction instead of the first one to return
+ // the correct synthetic transaction rather than gas payment deposits.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f7681d8 and 8f22729.

📒 Files selected for processing (6)
  • changelog.md (1 hunks)
  • precompiles/bank/method_test.go (1 hunks)
  • precompiles/staking/staking_test.go (1 hunks)
  • rpc/types/events.go (1 hunks)
  • x/crosschain/keeper/utils_test.go (1 hunks)
  • x/fungible/keeper/deposits_test.go (1 hunks)
✅ Files skipped from review due to trivial changes (4)
  • precompiles/staking/staking_test.go
  • x/fungible/keeper/deposits_test.go
  • x/crosschain/keeper/utils_test.go
  • precompiles/bank/method_test.go
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.go`: Review the Go code, point out issues relative to ...

**/*.go: Review the Go code, point out issues relative to principles of clean code, expressiveness, and performance.

  • rpc/types/events.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: start-e2e-test / e2e
🔇 Additional comments (2)
changelog.md (1)

46-46: The changelog entry accurately reflects the fix implemented.

This entry properly documents the change that addresses the issue with the eth_getBlockByNumber RPC now returning the correct synthetic transaction instead of gas payment deposits.

rpc/types/events.go (1)

276-277:

❓ Verification inconclusive

Verify the fix works across different node configurations.

Since this change affects how transactions are selected from events, it's important to ensure that this behavior is consistent across different node configurations and blockchain environments.


🏁 Script executed:

#!/bin/bash
# Test the behavior of eth_getBlockByNumber RPC with multiple synthetic transactions

# 1. Find a recent block with multiple synthetic transactions
rg --json -e "multiple synthetic txs" rpc/types/events.go | grep "TODO"

# 2. Look for any test cases or implementations that might be affected
fd -e go -H "eth_getBlockByNumber" --exec grep -l "ParseTxBlockResult" {} \;

Length of output: 442


ACTION: Confirm Consistent Transaction Ordering Across Node Configurations

The change in rpc/types/events.go (lines 276–277) now selects the last transaction (parsedTx := txs.Txs[len(txs.Txs)-1]) when handling multiple synthetic transactions. The shell script outputs confirm the presence of the TODO comment referencing potential reverse order issues and that no additional references (like tests around ParseTxBlockResult) were found.

  • Verify that this transaction selection logic produces consistent results on various node configurations and blockchain environments.
  • Suggestion: If the affected scenario isn’t already covered by automated tests, consider adding tests to simulate different synthetic transaction orders to ensure production-grade stability.

@skosito skosito added this pull request to the merge queue Mar 5, 2025
Merged via the queue into develop with commit 33eb8ef Mar 5, 2025
47 checks passed
@skosito skosito deleted the fix-gas-payment-events-indexing branch March 5, 2025 15:49
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.

Wrong outbound tx hash indexed for reverting cctx
3 participants