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

feat: add get transaction by index methods #4579

Merged
merged 6 commits into from
Nov 15, 2023

Conversation

agostbiro
Copy link
Member

Add support for eth_getTransactionByBlockHashAndIndex and eth_getTransactionByBlockNumberAndIndex:

  • Follows Hardhat logic.
  • Unit tests only for resolving block tags as rest of the provider logic is tested by the dependencies.
  • No tests for RPC logic as these will be tested by Hardhat integration tests once those are wired in.

@agostbiro agostbiro self-assigned this Nov 10, 2023
Copy link

changeset-bot bot commented Nov 10, 2023

⚠️ No Changeset found

Latest commit: 90e252d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Nov 10, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
hardhat ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 14, 2023 1:26pm
hardhat-storybook ✅ Ready (Inspect) Visit Preview Nov 14, 2023 1:26pm

@@ -76,14 +82,4 @@ pub enum ProviderError {
/// The address is not owned by this node.
#[error("{address} is not owned by this node")]
UnknownAddress { address: Address },
/// Block number doesn't exist in blockchain
Copy link
Member Author

Choose a reason for hiding this comment

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

I replaced these with a single InvalidBlockNumberOrHash as we only check if any of these match to return None in the RPC and there will be many methods making this check.

@agostbiro agostbiro linked an issue Nov 10, 2023 that may be closed by this pull request
8 tasks
crates/edr_eth/src/remote/cacheable_method_invocation.rs Outdated Show resolved Hide resolved
crates/edr_eth/src/remote/methods.rs Show resolved Hide resolved
crates/edr_provider/src/data.rs Outdated Show resolved Hide resolved
crates/edr_provider/src/error.rs Outdated Show resolved Hide resolved
pub async fn handle_get_transaction_by_block_hash_and_index(
data: &ProviderData,
block_hash: B256,
index: U256,
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious whether the type used in the JSON-RPC type was correct. Does the standard specifically call for a U256? I know I made some mistakes with other types where I used U256 but it turned out it's just a quantity type with 1 or more values after the 0x..

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question. I went with U256, because Hardhat accepts U256 as its rpcQuantity type.

Copy link
Member Author

Choose a reason for hiding this comment

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

Created follow up issue: NomicFoundation/edr#236

} else {
None
};

Ok(transaction)
}

pub fn transaction_from_block(
Copy link
Member

@alcuadrado alcuadrado Nov 11, 2023

Choose a reason for hiding this comment

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

I would have expected this logic to happen in the rpc handler, not here.

PS/Disclaimer: I didn't review the entire PR

Copy link
Member Author

Choose a reason for hiding this comment

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

My thinking with the GetTransactionResult (for which transaction_from_block is a helper method) is this:

The transaction getter RPC methods need some data from the block (header stuff and the transaction index) in addition to the signed transaction. To avoid cloning entire blocks just to get a transaction, the GetTransactionResult type exposes just the data needed by the transaction getter RPC methods in the internal representation (e.g. block number as u64) and then lets the RPC methods convert to the data types expected in the RPC layer.

Copy link
Member Author

@agostbiro agostbiro Nov 14, 2023

Choose a reason for hiding this comment

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

Actually on second thought we cloning the block would be cheap, because it's behind an Arc. But we still need a structure to return both the signed transaction and the block and I prefer explicit types.

Co-authored-by: Wodann <Wodann@users.noreply.github.com>
Co-authored-by: Wodann <Wodann@users.noreply.github.com>
Co-authored-by: Wodann <Wodann@users.noreply.github.com>
@Wodann Wodann merged commit 76883ad into edr/main Nov 15, 2023
48 of 50 checks passed
@Wodann Wodann deleted the edr/feat/get-transaction-by-index-methods branch November 15, 2023 08:27
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
Archived in project
Archived in project
Development

Successfully merging this pull request may close these issues.

Port eth_* RPC getter methods related to blockchain
3 participants