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

Add missing fields to the response of eth_getTransactionByHash #309

Merged
merged 2 commits into from
Jun 18, 2024

Conversation

m-Peter
Copy link
Collaborator

@m-Peter m-Peter commented Jun 17, 2024

Closes: #306

Description

Adds the following optional fields:

  • chainId
  • accessList
  • maxFeePerGas
  • maxPriorityFeePerGas

Fixes the value returned for the following fields:

  • Gas (this is the gas limit set by the sender, and not the consumed gas)
  • GasPrice (this is the gas price set by the sender, and not the effectiveGasPrice from the transaction receipt)

For contributor use:

  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the standards mentioned here.
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

Summary by CodeRabbit

  • New Features

    • Enhanced transaction handling to support various transaction types with additional fields.
    • Implemented new methods for gas fee calculations and blob hash management in the transaction interface.
  • Bug Fixes

    • Adjusted gas-related assertions in tests to reflect accurate values.
  • Tests

    • Added end-to-end test for eth_getTransactionByHash.
    • Introduced a new test for Web3.js transaction handling.

@m-Peter m-Peter added this to the Flex Testnet Release milestone Jun 17, 2024
@m-Peter m-Peter self-assigned this Jun 17, 2024
Copy link
Contributor

coderabbitai bot commented Jun 17, 2024

Walkthrough

The changes enhance the GetTransactionByHash method by ensuring it returns additional transaction information, including gas fees and access lists, using a new config parameter. This is aligned with updating functionalities across several files (api.go, models.go, stream.go, transaction.go) and adding new tests to validate the eth_getTransactionByHash method in e2e_web3js_test.go and corresponding JavaScript test files.

Changes

Files Change Summary
api/api.go, api/stream.go Updated GetTransactionByHash and NewPendingTransactions to pass config parameter to NewTransaction function.
api/models.go Modified NewTransaction function to accept and utilize the config parameter, handling various transaction types.
models/transaction.go Added new methods to the Transaction interface and DirectCall struct, supporting gas fees and access lists.
tests/e2e_web3js_test.go Introduced new tests for eth_getTransactionByHash and adjusted gas-related assertions in other test cases.
tests/web3js/eth_get_transaction_by_hash_test.js Implemented a new test file to validate eth_getTransactionByHash functionality using Web3.js.
tests/web3js/eth_non_interactive_test.js Adjusted gas-related assertions and added comments for additional checks in existing test cases.

Sequence Diagrams

sequenceDiagram
    participant Client
    participant BlockChainAPI
    participant Config
    participant Transaction
    
    Client->>BlockChainAPI: eth_getTransactionByHash(hash)
    BlockChainAPI->>Config: Fetch Config
    BlockChainAPI->>Transaction: NewTransaction(tx, rcp, config)
    Transaction->>BlockChainAPI: Transaction Details
    
    BlockChainAPI-->>Client: Return Transaction details
Loading

Assessment against linked issues

Objective Addressed Explanation
eth_getTransactionByHash method should return chainId (#306)

Poem

In the blockchain's tangled thread,
New paths we've deftly spread,
Gas fees, lists in view, and
Config's whisper, all come through,
Transactions bright, our code has fed.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e412885 and 16d1674.

Files selected for processing (7)
  • api/api.go (1 hunks)
  • api/models.go (3 hunks)
  • api/stream.go (1 hunks)
  • models/transaction.go (4 hunks)
  • tests/e2e_web3js_test.go (2 hunks)
  • tests/web3js/eth_get_transaction_by_hash_test.js (1 hunks)
  • tests/web3js/eth_non_interactive_test.js (3 hunks)
Files skipped from review due to trivial changes (2)
  • tests/e2e_web3js_test.go
  • tests/web3js/eth_get_transaction_by_hash_test.js
Additional comments not posted (6)
models/transaction.go (2)

Line range hint 87-121: The DirectCall struct now implements the newly added methods in the Transaction interface. Check if the default values returned by these methods (big.NewInt(0) and []common.Hash{}) are appropriate for all use cases. If there are scenarios where these defaults are not suitable, consider parameterizing or providing a configuration option.


25-32: Ensure the newly added methods in the Transaction interface are implemented in all concrete types that implement this interface. This is crucial for maintaining the integrity of the type system.

Verification successful

The verification script executed successfully, identifying the types implementing the Transaction interface. It also verified the presence of the new methods (GasFeeCap, GasTipCap, BlobGasFeeCap, BlobHashes, and AccessList) in each type.

No missing methods were reported for the types implementing the Transaction interface, indicating that all required methods are present.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all concrete types implementing the `Transaction` interface have the new methods.

# Test: Search for classes implementing `Transaction` and check for the new methods.
ast-grep --lang go --pattern $'type $_ implements Transaction {
  $$$
  GasFeeCap()
  GasTipCap()
  BlobGasFeeCap()
  BlobHashes()
  AccessList()
  $$$  
}'

Length of output: 704



Script:

#!/bin/bash
# Description: Verify all concrete types implementing the `Transaction` interface have the new methods.

# Test: Search for types implementing `Transaction` and check for the new methods.
# Correct the pattern for Go interface implementation and method definitions
ast-grep --lang go --pattern $'type $_ struct {
  $$$
}
func ($_ *$_) GasFeeCap() *big.Int {
  $$$
}
func ($_ *$_) GasTipCap() *big.Int {
  $$$
}
func ($_ *$_) BlobGasFeeCap() *big.Int {
  $$$
}
func ($_ *$_) BlobHashes() []common.Hash {
  $$$
}
func ($_ *$_) AccessList() gethTypes.AccessList {
  $$$
}'

Length of output: 1000



Script:

#!/bin/bash
# Description: Verify all concrete types implementing the `Transaction` interface have the new methods.

# Test: Search for types implementing `Transaction` and check for the new methods.
# Simplify the pattern to focus on method signatures only
ast-grep --lang go --pattern $'func ($_ *$_) GasFeeCap() *big.Int {
  $$$
}
func ($_ *$_) GasTipCap() *big.Int {
  $$$
}
func ($_ *$_) BlobGasFeeCap() *big.Int {
  $$$
}
func ($_ *$_) BlobHashes() []common.Hash {
  $$$
}
func ($_ *$_) AccessList() gethTypes.AccessList {
  $$$
}'

Length of output: 950



Script:

#!/bin/bash
# Description: Verify all concrete types implementing the `Transaction` interface have the new methods.

# Step 1: Identify types implementing the `Transaction` interface
implementing_types=$(ast-grep --lang go --pattern 'type $_ struct { $$$ }' | grep -oP 'type \K\w+')

# Step 2: Check each implementing type for the required methods
for type in $implementing_types; do
  echo "Checking methods for type: $type"
  ast-grep --lang go --pattern "func ($_ *$type) GasFeeCap() *big.Int { $$$ }" || echo "Missing GasFeeCap in $type"
  ast-grep --lang go --pattern "func ($_ *$type) GasTipCap() *big.Int { $$$ }" || echo "Missing GasTipCap in $type"
  ast-grep --lang go --pattern "func ($_ *$type) BlobGasFeeCap() *big.Int { $$$ }" || echo "Missing BlobGasFeeCap in $type"
  ast-grep --lang go --pattern "func ($_ *$type) BlobHashes() []common.Hash { $$$ }" || echo "Missing BlobHashes in $type"
  ast-grep --lang go --pattern "func ($_ *$type) AccessList() gethTypes.AccessList { $$$ }" || echo "Missing AccessList in $type"
done

Length of output: 149438

tests/web3js/eth_non_interactive_test.js (1)

Line range hint 80-95: The test assertions for eth_getTransactionByHash have been updated to reflect the new gas fields. Ensure that the hardcoded values (e.g., 300000n for gas and 21000n for cumulative gas used) are consistent with expected results based on the transaction context used in these tests.

api/models.go (1)

Line range hint 95-174: The NewTransaction function has been significantly modified to include a new config parameter and to handle different transaction types. Ensure all transaction types are correctly handled and that the config parameter is used appropriately throughout the function. Also, verify that the error handling is robust, especially in cases where transaction or receipt retrieval might fail.

Verification successful

The NewTransaction function in api/models.go has been verified to handle different transaction types correctly. The error handling within the function is also robust, with appropriate error returns in case of issues with transaction hashing or retrieving the From address.

  • The function handles LegacyTxType, AccessListTxType, DynamicFeeTxType, and BlobTxType appropriately.
  • Error handling is in place for transaction hashing and retrieving the From address.

This confirms that the changes made to the NewTransaction function are correctly implemented.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct handling of different transaction types and robust error handling in `NewTransaction`.

# Test: Search for usages of `NewTransaction` and verify that all possible transaction types are handled.
rg --type go $'NewTransaction'

Length of output: 1667



Script:

#!/bin/bash
# Verify the handling of different transaction types and error handling in `NewTransaction`.

# Test: Search for the definition and detailed usage of `NewTransaction` to verify transaction type handling.
ast-grep --lang go --pattern $'func NewTransaction(tx models.Transaction, receipt types.Receipt, config config.Config) (*Transaction, error) {
  $$$
}'

# Test: Search for error handling within the `NewTransaction` function.
rg --type go 'return nil, err' api/models.go

Length of output: 4331

api/stream.go (1)

148-148: The NewPendingTransactions function now passes the config parameter to the NewTransaction function. Ensure that this configuration is being correctly utilized within NewTransaction to affect transaction creation as intended.

api/api.go (1)

244-244: The addition of *b.config in the NewTransaction call is a positive change, enhancing the transaction creation with configuration data.

Verification successful

The NewTransaction function in api/models.go correctly includes the config parameter. Additionally, the usage in api/stream.go also correctly passes the configuration parameter *s.config. This confirms that the integration of the new config parameter is consistent and correct across the relevant files.

  • api/models.go: The NewTransaction function signature includes the config parameter.
  • api/stream.go: The call to NewTransaction correctly passes *s.config.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the integration of the new config parameter with existing configurations.

# Test: Search for the usage of the `NewTransaction` function. Expect: Correct passing of config in all usages.
rg --type python $'NewTransaction'

Length of output: 64



Script:

#!/bin/bash
# Description: Verify the integration of the new config parameter with existing configurations.

# Test: Search for the usage of the `NewTransaction` function. Expect: Correct passing of config in all usages.
rg --type go $'NewTransaction'

Length of output: 1667



Script:

#!/bin/bash
# Description: Extract and review the context of `NewTransaction` calls in `api/stream.go` and `api/models.go`.

# Extract 5 lines before and after the instances of `NewTransaction` in the specified files.
rg --type go --context 5 'NewTransaction' api/stream.go api/models.go

Length of output: 947

@m-Peter m-Peter requested a review from franklywatson June 17, 2024 15:34
Copy link
Contributor

@ramtinms ramtinms left a comment

Choose a reason for hiding this comment

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

looks good to me

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 16d1674 and d85b44f.

Files selected for processing (2)
  • models/transaction.go (4 hunks)
  • tests/web3js/eth_non_interactive_test.js (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • models/transaction.go
  • tests/web3js/eth_non_interactive_test.js

@m-Peter m-Peter merged commit d5292a2 into onflow:main Jun 18, 2024
2 checks passed
@m-Peter m-Peter deleted the eth-get-tx-by-hash-add-chain-id branch June 18, 2024 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

eth_getTransactionByHash method doesn't return chainId
2 participants