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

[Bug] DebugApi problem #657

Closed
dexloom opened this issue May 1, 2024 · 4 comments
Closed

[Bug] DebugApi problem #657

dexloom opened this issue May 1, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@dexloom
Copy link
Contributor

dexloom commented May 1, 2024

Component

network, json-rpc

What version of Alloy are you on?

rev = "5a5f29e"

Operating System

None

Describe the bug

The following code returns :"server returned an error response: error code -32602: Invalid params"
in case debug_trace_block_by_number is used, most likely block number is encoded incorrectly,

and client.debug_trace_block_by_hash returns VecGethTrace::JS instead of VecGethTrace::PreStateTracer

client.debug_trace_call seems to be working well

let tracer_opts = GethDebugTracingOptions {
        tracer: Some(GethDebugTracerType::BuiltInTracer(
            GethDebugBuiltInTracerType::PreStateTracer,
        )),
        config: GethDefaultTracingOptions::default().disable_storage().disable_stack().disable_memory().disable_return_data(),
        timeout: None,
        tracer_config: GethDebugTracerConfig::default(),
    }.prestate_config(PreStateConfig { diff_mode: Some(true) });

let trace_result_vec = match block_id {
        BlockId::Number(block_number) => {
            client.debug_trace_block_by_number(block_number.as_number().unwrap(), tracer_opts).await?
        }
        BlockId::Hash(rpc_block_hash) => {
            client.debug_trace_block_by_hash(rpc_block_hash.block_hash, tracer_opts).await?
        }
    };

@dexloom dexloom added the bug Something isn't working label May 1, 2024
@mattsse
Copy link
Member

mattsse commented May 1, 2024

could you please prepare a serde roundtrip test for the given tracer_opts

@dexloom
Copy link
Contributor Author

dexloom commented May 2, 2024

Not really sure about proper serialization in both cases.

full request params_ty=(u64, alloy_rpc_types_trace::geth::GethDebugTracingOptions) request=Request { meta: RequestMeta { method: "debug_traceBlockByNumber", id: Number(0), is_subscription: false }, params: (19780651, GethDebugTracingOptions { config: GethDefaultTracingOptions { enable_memory: None, disable_memory: None, disable_stack: None, disable_storage: None, enable_return_data: None, disable_return_data: None, debug: None, limit: None }, tracer: Some(BuiltInTracer(PreStateTracer)), tracer_config: GethDebugTracerConfig(Object {"diffMode": Bool(true)}), timeout: None }) }


serialized request request={"method":"debug_traceBlockByNumber","params":[19780651,{"tracer":"prestateTracer","tracerConfig":{"diffMode":true}}],"id":0,"jsonrpc":"2.0"}

Error: server returned an error response: error code -32602: Invalid params

BlockHash : 
full request params_ty=(alloy_primitives::bits::fixed::FixedBytes<32>, alloy_rpc_types_trace::geth::GethDebugTracingOptions) request=Request { meta: RequestMeta { method: "debug_traceBlockByHash", id: Number(0), is_subscription: false }, params: (0x1b9f245b55515d17fd5b3467bfe595670c9599b3d54837cd32cfde5e2e667830, GethDebugTracingOptions { config: GethDefaultTracingOptions { enable_memory: None, disable_memory: None, disable_stack: None, disable_storage: None, enable_return_data: None, disable_return_data: None, debug: None, limit: None }, tracer: Some(BuiltInTracer(PreStateTracer)), tracer_config: GethDebugTracerConfig(Object {"diffMode": Bool(true)}), timeout: None }) }


serialized request request={"method":"debug_traceBlockByHash","params":["0x1b9f245b55515d17fd5b3467bfe595670c9599b3d54837cd32cfde5e2e667830",{"tracer":"prestateTracer","tracerConfig":{"diffMode":true}}],"id":0,"jsonrpc":"2.0"}

deserializing response ty=alloc::vec::Vec<alloy_rpc_types_trace::geth::GethTrace> json="[{\"result\":{\"post\":{\"0x4838b106fce9647bdf1e7877bf73ce8b0bad5f97\":{\"balance\":\"0xaa0ed21ce62b6798\"},\"0x5db1f2d3e3305fba32523a426aff85d9e6a48b83\":{\"balance\":\"0x524f24e6cec000\",\"nonce\":5},\"0xd1d2eb1b1e90b638588728b4130137d262c87cae\":{\"storage\":{\"0x74170c1c296510419d064eb0866c1501bb50ce27462e8abc70cb542599fec707\":\"0x000000000000000000000000000000000000000000000000011a644f422e3971\"}}},\"pre\":{\"0x4838b106fce9647bdf1e7877bf73ce8b0bad5f97\":{\"balance\":\"0xaa09a4c9813dc3f8\",\"nonce\":305953},\"0x5db1f2d3e3305fba32523a426aff85d9e6a48b83\":{\"balance\":\"0x585225bdac7000\",\"nonce\":4},\"0xd1d2eb1b1e90b638588728b4130137d262c87cae\":{\"balance\":\"0x0\",\"code\":\"0x60806040523661001357610011610017565b005b6100115b61002761002261005e565b610096565b565b606061004e838360405180606001604052806027815260200161024c602791396100ba565b9392505050565b3b151590565b90565b60006100917f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc546001600160a01b031690565b905090565b3660008037600080366000845af43d6000803e8080156100b5573d6000f35b3d6000fd5b6060833b61011e5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f6044820152651b9d1c9858dd60d21b60648201526084015b60405180910390fd5b600080856001600160a01b03168560405161013991906101fc565b600060405180830381855af49150503d8060008114610174576040519150601f19603f3d011682016040523d82523d6000602084013e610179565b606091505b5091509150610189828286610193565b9695505050505050565b606083156101a257508161004e565b8251156101b25782518084602001fd5b8160405162461bcd60e51b81526004016101159190610218565b60005b838110156101e75781810151838201526020016101cf565b838111156101f6576000848401525b50505050565b6000825161020e8184602087016101cc565b9190910192915050565b60208152600082518060208401526102378160408501602087016101cc565b601f01601f1916919091016040019291505056fe416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c206661696c6564a264697066735822122041f64d2ff908c9983923017ed36c949dd92697a1f359295e2ea2f809da86127664736f6c63430008090033\",\"nonce\":1,\"storage\":{\"0x1e0928ac539dadc58dccebc6a2457475f21e7d610eea3031f22af51dbf79a945\":\"0x00000000000000000000000000000000000000000000000000000913a064f700\"....

@dexloom
Copy link
Contributor Author

dexloom commented May 3, 2024

I guess I found out what is wrong in bth cases :

debug_traceBlockByNumber should have encoded block number in hexadecimal form with 0x prefix like :
"0xccde12",

and I believe both debug_traceBlockByNumber and debug_traceBlockByHash return not Vec<GethTrace> but Vec<GethTraceResponse> where :

type struct GethTraceResponse {
   txHash : String
   result:   GethTrace
}

Hope that will help

@Ebolon
Copy link
Contributor

Ebolon commented Jun 17, 2024

@dexloom I could not reproduce the issue with the latest master version. Did I got the code right? Could you have a look again?

My example:

use alloy_primitives::b256;
use alloy_provider::{ext::DebugApi, ProviderBuilder};
use alloy_rpc_types_trace::geth::{
    GethDebugBuiltInTracerType, GethDebugTracerConfig, GethDebugTracerType, GethDebugTracingOptions, GethDefaultTracingOptions, GethTrace,
    PreStateConfig, TraceResult,
};

#[tokio::main]
async fn main() {
    let url = std::env::var("ETH_MAINNET_HTTP").expect("$ETH_MAINNET_HTTP must be set.");
    let node_url = url::Url::parse(url.as_str()).unwrap();
    let provider = ProviderBuilder::new().on_http(node_url);

    let tracer_opts = GethDebugTracingOptions {
        tracer: Some(GethDebugTracerType::BuiltInTracer(GethDebugBuiltInTracerType::PreStateTracer)),
        config: GethDefaultTracingOptions::default().disable_storage().disable_stack().disable_memory().disable_return_data(),
        timeout: None,
        tracer_config: GethDebugTracerConfig::default(),
    }
    .with_prestate_config(PreStateConfig { diff_mode: Some(true) });

    // CASE: by hash
    let trace_results = provider
        .debug_trace_block_by_hash(b256!("1b9f245b55515d17fd5b3467bfe595670c9599b3d54837cd32cfde5e2e667830"), tracer_opts)
        .await
        .unwrap();
    // CASE: by number
    //let trace_results = provider.debug_trace_block_by_number(BlockNumberOrTag::Number(19780651), tracer_opts).await.unwrap();

    for trace_result in trace_results {
        match trace_result {
            TraceResult::Success { tx_hash, result } => match result {
                GethTrace::Default(_) => {}
                GethTrace::CallTracer(_) => {}
                GethTrace::FourByteTracer(_) => {}
                GethTrace::PreStateTracer(_) => {
                    println!("PreState trace: {:?}", tx_hash);
                }
                GethTrace::NoopTracer(_) => {}
                GethTrace::MuxTracer(_) => {}
                GethTrace::JS(_) => {
                    println!("JS trace: {:?}", tx_hash);
                }
            },
            TraceResult::Error { .. } => {}
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants