Skip to content

Commit

Permalink
add debug_traceTransaction RPC (#165)
Browse files Browse the repository at this point in the history
* remove DbcFinality

* remove benchmarking.rs

* fix

* remove cli feature

* fix runtime-benchmarks

* add evm debug

* fix

* remove logs

* update

* update

* fmt
  • Loading branch information
frank0528 authored Oct 14, 2024
1 parent 2cedfb2 commit a0be150
Show file tree
Hide file tree
Showing 71 changed files with 8,273 additions and 2,616 deletions.
2,767 changes: 1,551 additions & 1,216 deletions Cargo.lock

Large diffs are not rendered by default.

25 changes: 23 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ resolver = "2"
members = [
"node",
"node/cli",
"client/rpc/finality",
"primitives",
"rpc",
"runtime",

"pallets/assets",
Expand Down Expand Up @@ -237,6 +235,29 @@ fc-storage = { git = "https://github.com/DeepBrainChain/DBC-EVM", branch = "polk
fp-consensus = { git = "https://github.com/DeepBrainChain/DBC-EVM", branch = "polkadot-v0.9.43" }
fp-storage = { git = "https://github.com/DeepBrainChain/DBC-EVM", branch = "polkadot-v0.9.43" }

# DBC (client)
dbc-primitives = { path = "primitives", default-features = false }
dbc-primitives-ext = { path = "primitives/ext", default-features = false }
dbc-primitives-rpc-debug = { path = "primitives/rpc/debug", default-features = false }
dbc-primitives-rpc-evm-tracing-events = { path = "primitives/rpc/evm-tracing-events", default-features = false }
dbc-primitives-rpc-trace = { path = "primitives/rpc/trace", default-features = false }
dbc-primitives-rpc-txpool = { path = "primitives/rpc/txpool", default-features = false }

dbc-client-evm-tracing = { path = "client/evm-tracing" }
dbc-client-rpc-core-debug = { path = "client/rpc-core/debug" }
dbc-client-rpc-core-trace = { path = "client/rpc-core/trace" }
dbc-client-rpc-core-txpool = { path = "client/rpc-core/txpool" }
dbc-client-rpc-core-types = { path = "client/rpc-core/types" }
dbc-client-rpc-debug = { path = "client/rpc/debug" }
dbc-client-rpc-trace = { path = "client/rpc/trace" }
dbc-client-rpc-txpool = { path = "client/rpc/txpool" }

dbc-evm-tracer = { path = "runtime/evm-tracer", default-features = false }

evm = { git = "https://github.com/rust-blockchain/evm", rev = "b7b82c7e1fc57b7449d6dfa6826600de37cc1e65", default-features = false }
evm-gasometer = { git = "https://github.com/rust-blockchain/evm", rev = "b7b82c7e1fc57b7449d6dfa6826600de37cc1e65", default-features = false }
evm-runtime = { git = "https://github.com/rust-blockchain/evm", rev = "b7b82c7e1fc57b7449d6dfa6826600de37cc1e65", default-features = false }

ethabi = { version = "18.0.0", default-features = false }
env_logger = { version = "0.11.5", default-features = false }

Expand Down
17 changes: 16 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ build:
build-runtime:
cargo build --release -p dbc-runtime

.PHONY: build-evm-tracing-runtime
build-evm-tracing-runtime:
cargo build --features evm-tracing --release -p dbc-runtime

.PHONY: build-try-runtime
build-try-runtime:
cargo build --features try-runtime --release -p dbc-runtime
Expand All @@ -23,7 +27,18 @@ fmt:

.PHONY: run
run:
cargo run -- --dev -lruntime=debug,evm=debug --rpc-port=9944 --rpc-external --rpc-cors=all --rpc-methods=unsafe --pruning=archive
cargo run \
--features evm-tracing \
-- \
--dev \
-lruntime=debug,evm=trace \
--rpc-port=9944 \
--rpc-external \
--rpc-cors=all \
--rpc-methods=unsafe \
--pruning=archive \
--ethapi=debug,trace,txpool
#--wasm-runtime-overrides=./runtime-overrides

NODE_URI ?=wss://info1.dbcwallet.io:443
BLOCK_HASH ?=0xc4d4e9b1a2b8c44d7859a6004c43ad6eebb61c57b6173a53fe794a6aa479a49b
Expand Down
18 changes: 18 additions & 0 deletions client/evm-tracing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "dbc-client-evm-tracing"
version = { workspace = true }
authors = { workspace = true }
edition = "2021"

[dependencies]
ethereum-types = { workspace = true, features = [ "std" ] }
hex = { workspace = true, features = [ "serde" ] }
serde = { workspace = true, features = [ "derive", "std" ] }
serde_json = { workspace = true }

dbc-primitives-rpc-evm-tracing-events = { workspace = true, features = [ "std" ] }
dbc-primitives-rpc-debug = { workspace = true, features = [ "std" ] }

# Substrate
parity-scale-codec = { workspace = true, features = [ "std" ] }
sp-std = { workspace = true, features = [ "std" ] }
75 changes: 75 additions & 0 deletions client/evm-tracing/src/formatters/blockscout.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use crate::{
listeners::call_list::Listener,
types::{
serialization::*,
single::{Call, TransactionTrace},
CallResult, CallType, CreateResult,
},
};
use ethereum_types::{H160, U256};
use parity_scale_codec::{Decode, Encode};
use serde::Serialize;

pub struct Formatter;

impl super::ResponseFormatter for Formatter {
type Listener = Listener;
type Response = TransactionTrace;

fn format(listener: Listener) -> Option<TransactionTrace> {
if let Some(entry) = listener.entries.last() {
return Some(TransactionTrace::CallList(
entry.into_iter().map(|(_, value)| Call::Blockscout(value.clone())).collect(),
))
}
None
}
}

#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, Serialize)]
#[serde(rename_all = "lowercase", tag = "type")]
pub enum BlockscoutCallInner {
Call {
#[serde(rename(serialize = "callType"))]
/// Type of call.
call_type: CallType,
to: H160,
#[serde(serialize_with = "bytes_0x_serialize")]
input: Vec<u8>,
/// "output" or "error" field
#[serde(flatten)]
res: CallResult,
},
Create {
#[serde(serialize_with = "bytes_0x_serialize")]
init: Vec<u8>,
#[serde(flatten)]
res: CreateResult,
},
SelfDestruct {
#[serde(skip)]
balance: U256,
to: H160,
},
}

#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct BlockscoutCall {
pub from: H160,
/// Indices of parent calls.
pub trace_address: Vec<u32>,
/// Number of children calls.
/// Not needed for Blockscout, but needed for `crate::block`
/// types that are build from this type.
#[serde(skip)]
pub subtraces: u32,
/// Sends funds to the (payable) function
pub value: U256,
/// Remaining gas in the runtime.
pub gas: U256,
/// Gas used by this context.
pub gas_used: U256,
#[serde(flatten)]
pub inner: BlockscoutCallInner,
}
Loading

0 comments on commit a0be150

Please sign in to comment.