Skip to content

Commit

Permalink
debug_traceTransaction RPC method support (#196)
Browse files Browse the repository at this point in the history
* Bootstrap impls for runner and executor

* Fix frontier version

* Cargo lock

* Bootstrap rpc handler + runtime api

* Refactor + bootstrap impls

* Refactor response types

* Cargo lock

* `ethereum-types` 0.10.0

* Error handling

* Add `storage` field

* Copyright

* Remove unused

* Use evm getters

* Update frontier and evm dependencies

* Update `ethereum` dependency

* Update frontier pin

* Fix fmt

* Context helper + update evm pin

* Switch to executor wrapper design

* Remove stack module in favor of wrapper

* Use BlockchainBackend

* Modify runtime api fn signature

* Apply subset of extrinsic before tracing

* First simple test to validate tracing over intermediate state

* Fix nesting

* Keep it simple

* WIP update evm

* Move executor declaration to parent scope

* Fix some deps

* Update gas_cost retrieval to new evm changes

* u8 to stringified opcode conversion

* Use getters for StackSubstateMetadata

* Handle evm transfers

* Chunkify memory

* No need to specify type

* Add serializer to remove 0x prefix

* Serialize U256 as low u64

* Add cli debug option

* Add debug option to ts tests

* Handle gas_limit

* storage tracing (not tested)

* update storage cache AFTER step

* Move debug flag to RunCmd

* remove duplicated response types

* wip blockscout tracing

* wip blockscout entries insertion

* almost complete tracing in wrapper

* working tracing (raw + blockscout), need small fixes in rpc

* Depth trace format is EVM's returned depth + 1

* Add test for nested calls (raw)

* Add test for nested calls (blockscout)

* Move nested test to own fn

* Fix formatting

* 0x prefixes

* Pass scheme to `trace_create`

* WIP fix staticcall

* Add missing gas correction on trace (fix staticcall ok)

* Bump spec_version

* Add simple replay test utility

* Handle request processing error in replay test utility

* Add copyright

* Prettier

* Change the tracer hash

* Set `debug` and `txpool` as as optional RPC extensions

* Update tests

* Prettier

* Update frontier pin

* Set `require_delimiter` flag to true

* Add missing serde camelCase renames

* Fix previous commit..

* Default transaction index None in txpool

* Update frontier pin

* Update test-block to new totalDifficulty

* Update frontier

* Fix trace_address fields

* fix runtime api

* Fix fmt

* Update frontier + evm

* Sync with master

* Fix checker

* bump frontier dependency hash

* Update settings.json

* Remove old comments

* TraceParams additional fields (unused)

* Bump sha3 0.9

* Document evm extension

* Opcode greater that 255 is unreachable

* Remove frame_support re-export

* Fix checker

* Fix checker

* Try to fix docs

* Document TraceRunner

* Remove unused

* ethers 5.0.32

* Remove comment

Co-authored-by: nanocryk <[email protected]>
Co-authored-by: Alan Sapede <[email protected]>
Co-authored-by: Crystalin <[email protected]>
  • Loading branch information
4 people authored Mar 31, 2021
1 parent afc6246 commit 01ddc3e
Show file tree
Hide file tree
Showing 33 changed files with 2,548 additions and 11 deletions.
76 changes: 76 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions client/rpc-core/debug/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "moonbeam-rpc-core-debug"
version = '0.1.0'
authors = ['PureStake']
edition = '2018'
homepage = 'https://moonbeam.network'
license = 'GPL-3.0-only'
repository = 'https://github.com/PureStake/moonbeam/'

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ethereum-types = "0.11.0"
jsonrpc-core = "15.0.0"
jsonrpc-core-client = "14.0.3"
jsonrpc-derive = "14.0.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sp-core = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" }
moonbeam-rpc-primitives-debug = { path = "../../../primitives/rpc/debug" }
#evm = { version = "0.20.0", default-features = false, features = ["with-codec"] }
52 changes: 52 additions & 0 deletions client/rpc-core/debug/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2019-2020 PureStake Inc.
// This file is part of Moonbeam.

// Moonbeam is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Moonbeam is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Moonbeam. If not, see <http://www.gnu.org/licenses/>.

use ethereum_types::H256;
use jsonrpc_core::Result;
use jsonrpc_derive::rpc;
use serde::Deserialize;

pub use crate::types::{StepLog, TraceExecutorResponse};

pub use rpc_impl_Debug::gen_server::Debug as DebugServer;

pub mod types {
pub use moonbeam_rpc_primitives_debug::{StepLog, TraceExecutorResponse};
}

// TODO: Add support for additional params.
// - `disableStorage`, `disableMemory`, `disableStack`.
// - `timeout` should be ignored unless we find out a way for actually evaluating the tracer input.
#[derive(Clone, Eq, PartialEq, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TraceParams {
/// Javascript tracer (we just check if it's Blockscout tracer string)
pub disable_storage: Option<bool>,
pub disable_memory: Option<bool>,
pub disable_stack: Option<bool>,
pub tracer: Option<String>,
pub timeout: Option<String>,
}

#[rpc(server)]
pub trait Debug {
#[rpc(name = "debug_traceTransaction")]
fn trace_transaction(
&self,
transaction_hash: H256,
params: Option<TraceParams>,
) -> Result<TraceExecutorResponse>;
}
3 changes: 3 additions & 0 deletions client/rpc-core/txpool/src/types/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub struct Transaction {
pub gas: U256,
/// Data
pub input: Bytes,
/// Transaction Index
pub transaction_index: Option<U256>,
}

fn block_hash_serialize<S>(hash: &Option<H256>, serializer: S) -> Result<S::Ok, S::Error>
Expand Down Expand Up @@ -77,6 +79,7 @@ impl GetT for Transaction {
gas_price: txn.gas_price,
gas: txn.gas_limit,
input: Bytes(txn.input.clone()),
transaction_index: None,
}
}
}
26 changes: 26 additions & 0 deletions client/rpc/debug/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "moonbeam-rpc-debug"
version = '0.1.0'
authors = ['PureStake']
edition = '2018'
homepage = 'https://moonbeam.network'
license = 'GPL-3.0-only'
repository = 'https://github.com/PureStake/moonbeam/'

[dependencies]
jsonrpc-core = "15.0.0"
ethereum = { version = "0.7.1", default-features = false, features = ["with-codec"] }
ethereum-types = "0.11.0"
sp-core = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" }
sp-api = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" }
sp-io = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" }
sp-blockchain = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" }
sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "rococo-v1" }

moonbeam-rpc-core-debug = { path = "../../rpc-core/debug" }
moonbeam-rpc-primitives-debug = { path = "../../../primitives/rpc/debug" }
fc-consensus = { git = "https://github.com/purestake/frontier", branch = "notlesh-moonbeam-v0.7" }
fc-db = { git = "https://github.com/purestake/frontier", branch = "notlesh-moonbeam-v0.7" }
fp-rpc = { git = "https://github.com/purestake/frontier", branch = "notlesh-moonbeam-v0.7" }
Loading

0 comments on commit 01ddc3e

Please sign in to comment.