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: improve Reth bindings and fix debug_traceCallMany and trace_callMany methods #1076

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3b90d48
should skip serializing block_override if none
zerosnacks Jul 19, 2024
8c45751
feat: Add call_many (#1085)
DoTheBestToGetTheBest Jul 22, 2024
3ecfc3d
Merge branch 'main' into zerosnacks/fix-all-many-methods-rpc
zerosnacks Jul 22, 2024
a3ca720
merge in main
zerosnacks Sep 9, 2024
b860cbb
add tempdir utility
zerosnacks Sep 9, 2024
c684b70
clean up tests
zerosnacks Sep 9, 2024
d03af40
add debug_trace_call_many test
zerosnacks Sep 9, 2024
a9f4e76
fix tests
zerosnacks Sep 9, 2024
d877ce7
add trace_call
zerosnacks Sep 9, 2024
5783ab1
seemingly correct api results in incorrect api response from Reth
zerosnacks Sep 9, 2024
fb8a29d
simplify types, fix request formatting
zerosnacks Sep 11, 2024
8a0901e
revert type changes to keep compatibility with RpcWithBlock optional …
zerosnacks Sep 11, 2024
96062a2
format output
zerosnacks Sep 11, 2024
03fd742
clean up, add random_instance for reduced flakiness
zerosnacks Sep 11, 2024
bbc5ebc
fix clippy
zerosnacks Sep 11, 2024
157860c
add back utils namespace
zerosnacks Sep 11, 2024
c83dc57
merge in main
zerosnacks Sep 11, 2024
c83cba8
Merge branch 'main' into zerosnacks/fix-all-many-methods-rpc
zerosnacks Sep 11, 2024
072cc26
Update crates/rpc-types-eth/src/call.rs
zerosnacks Sep 11, 2024
4f31750
re-export TraceCallList
zerosnacks Sep 11, 2024
8c896d2
Merge branch 'zerosnacks/fix-all-many-methods-rpc' of github.com:allo…
zerosnacks Sep 11, 2024
0dc8adc
add back `init_tracing`
zerosnacks Sep 11, 2024
f3f6340
undo unrelated test_* prefix changes in anvil tests
zerosnacks Sep 11, 2024
7f76e24
clean up
zerosnacks Sep 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/provider/src/ext/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub use net::NetApi;
#[cfg(feature = "trace-api")]
mod trace;
#[cfg(feature = "trace-api")]
pub use trace::{TraceApi, TraceCallList};
pub use trace::TraceApi;

#[cfg(feature = "rpc-api")]
mod rpc;
Expand Down
151 changes: 78 additions & 73 deletions crates/provider/src/ext/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ use alloy_rpc_types_trace::{
};
use alloy_transport::{Transport, TransportResult};

/// List of trace calls for use with [`TraceApi::trace_call_many`]
pub type TraceCallList<'a, 'b, N> = [(&'a <N as Network>::TransactionRequest, &'b [TraceType])];

/// Trace namespace rpc interface that gives access to several non-standard RPC methods.
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
Expand All @@ -26,11 +23,11 @@ where
/// # Note
///
/// Not all nodes support this call.
fn trace_call<'a, 'b>(
async fn trace_call(
&self,
request: &'a N::TransactionRequest,
trace_type: &'b [TraceType],
) -> RpcWithBlock<T, (&'a N::TransactionRequest, &'b [TraceType]), TraceResults>;
request: N::TransactionRequest,
trace_type: &[TraceType],
) -> TransportResult<TraceResults>;

/// Traces multiple transactions on top of the same block, i.e. transaction `n` will be executed
/// on top of the given block with all `n - 1` transaction applied first.
Expand All @@ -40,10 +37,10 @@ where
/// # Note
///
/// Not all nodes support this call.
fn trace_call_many<'a, 'b>(
async fn trace_call_many(
&self,
request: &'a TraceCallList<'a, 'b, N>,
) -> RpcWithBlock<T, &'a TraceCallList<'a, 'b, N>, TraceResults>;
request: Vec<(N::TransactionRequest, &[TraceType])>,
) -> TransportResult<Vec<TraceResults>>;

/// Parity trace transaction.
async fn trace_transaction(
Expand Down Expand Up @@ -106,20 +103,19 @@ where
T: Transport + Clone,
P: Provider<T, N>,
{
fn trace_call<'a, 'b>(
async fn trace_call(
&self,
request: &'a <N as Network>::TransactionRequest,
trace_types: &'b [TraceType],
) -> RpcWithBlock<T, (&'a <N as Network>::TransactionRequest, &'b [TraceType]), TraceResults>
{
RpcWithBlock::new(self.weak_client(), "trace_call", (request, trace_types))
request: N::TransactionRequest,
trace_types: &[TraceType],
) -> TransportResult<TraceResults> {
self.client().request("trace_call", (request, trace_types)).await
}

fn trace_call_many<'a, 'b>(
async fn trace_call_many(
&self,
request: &'a TraceCallList<'a, 'b, N>,
) -> RpcWithBlock<T, &'a TraceCallList<'a, 'b, N>, TraceResults> {
RpcWithBlock::new(self.weak_client(), "trace_callMany", request)
request: Vec<(N::TransactionRequest, &[TraceType])>,
) -> TransportResult<Vec<TraceResults>> {
self.client().request("trace_callMany", (request,)).await
}

async fn trace_transaction(
Expand Down Expand Up @@ -180,7 +176,7 @@ mod test {
use alloy_eips::BlockNumberOrTag;
use alloy_network::TransactionBuilder;
use alloy_node_bindings::{utils::run_with_tempdir, Reth};
use alloy_primitives::U256;
use alloy_primitives::{bytes, U256};
use alloy_rpc_types_eth::TransactionRequest;

use super::*;
Expand Down Expand Up @@ -218,7 +214,7 @@ mod test {
.with_nonce(0)
.with_value(U256::from(100));

let result = provider.trace_call(&tx, &[TraceType::Trace]).await;
let result = provider.trace_call(tx, &[TraceType::Trace]).await;
assert!(result.is_ok());

let traces = result.unwrap();
Expand Down Expand Up @@ -280,58 +276,67 @@ mod test {
.with_value(U256::from(100));

let result = provider
.trace_call_many(&[(&tx1, &[TraceType::Trace]), (&tx2, &[TraceType::Trace])])
.trace_call_many(vec![(tx1, &[TraceType::Trace]), (tx2, &[TraceType::Trace])])
.await;
println!("{:?}", result);

// [
// (
// TransactionRequest {
// from: Some(0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266),
// to: Some(Call(0x70997970c51812dc3a010c7d01b50e0d17dc79c8)),
// gas_price: None,
// max_fee_per_gas: None,
// max_priority_fee_per_gas: None,
// max_fee_per_blob_gas: None,
// gas: None,
// value: Some(100),
// input: TransactionInput { input: None, data: None },
// nonce: Some(0),
// chain_id: None,
// access_list: None,
// transaction_type: None,
// blob_versioned_hashes: None,
// sidecar: None,
// authorization_list: None,
// },
// [Trace],
// ),
// (
// TransactionRequest {
// from: Some(0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266),
// to: Some(Call(0x70997970c51812dc3a010c7d01b50e0d17dc79c8)),
// gas_price: None,
// max_fee_per_gas: None,
// max_priority_fee_per_gas: None,
// max_fee_per_blob_gas: None,
// gas: None,
// value: Some(100),
// input: TransactionInput { input: None, data: None },
// nonce: Some(1),
// chain_id: None,
// access_list: None,
// transaction_type: None,
// blob_versioned_hashes: None,
// sidecar: None,
// authorization_list: None,
// },
// [Trace],
// ),
// ]

// Err(ErrorResp(ErrorPayload { code: -32602, message: "Invalid params", data:
// Some(RawValue("invalid type: map, expected a tuple of size 2 at line 1 column 1"))
// }))
assert!(result.is_ok());

let traces = result.unwrap();
assert_eq!(
serde_json::to_string_pretty(&traces).unwrap().trim(),
r#"
[
{
"output": "0x",
"stateDiff": null,
"trace": [
{
"type": "call",
"action": {
"from": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
"callType": "call",
"gas": "0x2fa9e78",
"input": "0x",
"to": "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
"value": "0x64"
},
"result": {
"gasUsed": "0x0",
"output": "0x"
},
"subtraces": 0,
"traceAddress": []
}
],
"vmTrace": null
},
{
"output": "0x",
"stateDiff": null,
"trace": [
{
"type": "call",
"action": {
"from": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
"callType": "call",
"gas": "0x2fa9e78",
"input": "0x",
"to": "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
"value": "0x64"
},
"result": {
"gasUsed": "0x0",
"output": "0x"
},
"subtraces": 0,
"traceAddress": []
}
],
"vmTrace": null
}
]
"#
.trim()
);
})
.await
}
Expand Down
Loading