Skip to content

Commit

Permalink
feat: add debug transaction trace
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason committed Jul 25, 2023
1 parent 234e85b commit 7417d44
Show file tree
Hide file tree
Showing 8 changed files with 963 additions and 840 deletions.
1,208 changes: 564 additions & 644 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 11 additions & 7 deletions core/api/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use core_executor::{
use protocol::traits::{APIAdapter, Context, Executor, ExecutorAdapter, MemPool, Network, Storage};
use protocol::types::{
Account, BigEndianHash, Block, BlockNumber, Bytes, CkbRelatedInfo, ExecutorContext, Hash,
Header, Metadata, Proposal, Receipt, SignedTransaction, TxResp, H160, MAX_BLOCK_GAS_LIMIT,
NIL_DATA, RLP_NULL, U256,
Header, Metadata, Proposal, Receipt, SignedTransaction, TransactionTrace, TxResp, H160,
MAX_BLOCK_GAS_LIMIT, NIL_DATA, RLP_NULL, U256,
};
use protocol::{async_trait, codec::ProtocolCodec, trie, ProtocolResult};

Expand Down Expand Up @@ -183,7 +183,7 @@ where
state_root: Hash,
mock_header: Proposal,
enable_trace: bool,
) -> ProtocolResult<TxResp> {
) -> ProtocolResult<(TxResp, Option<TransactionTrace>)> {
let mut exec_ctx = ExecutorContext::from(mock_header);
exec_ctx.origin = from.unwrap_or_default();
exec_ctx.gas_price = gas_price.unwrap_or_else(U256::one);
Expand All @@ -199,12 +199,16 @@ where
.unwrap_or(MAX_BLOCK_GAS_LIMIT);

if enable_trace {
return Ok(
AxonExecutor::default().tracing_call(&backend, gas_limit, from, to, value, data)
);
let ret =
AxonExecutor::default().tracing_call(&backend, gas_limit, from, to, value, data);

return Ok((ret.0, Some(ret.1)));
}

Ok(AxonExecutor::default().call(&backend, gas_limit, from, to, value, data))
Ok((
AxonExecutor::default().call(&backend, gas_limit, from, to, value, data),
None,
))
}

async fn get_code_by_hash(&self, ctx: Context, hash: &Hash) -> ProtocolResult<Option<Bytes>> {
Expand Down
1 change: 1 addition & 0 deletions core/api/src/jsonrpc/impl/web3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ impl<Adapter: APIAdapter> Web3RpcImpl<Adapter> {
true,
)
.await
.map(|r| r.0)
}

async fn calculate_rewards(
Expand Down
1 change: 1 addition & 0 deletions core/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ lru = "0.10"
molecule = "0.7"
parking_lot = "0.12"
protocol = { path = "../../protocol", package = "axon-protocol", default-features = false }
revm-interpreter = "1.1"
ripemd = "0.1"
rlp = "0.5"
rlp-derive = "0.1"
Expand Down
16 changes: 9 additions & 7 deletions core/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ mod tracing;
mod utils;

pub use crate::adapter::{AxonExecutorAdapter, MPTTrie, RocksTrieDB};
pub use crate::tracing::TransactionTrace;
pub use crate::utils::{
code_address, decode_revert_msg, logs_bloom, DefaultFeeAllocator, FeeInlet,
};
Expand All @@ -27,8 +26,9 @@ use common_merkle::TrieMerkle;
use protocol::codec::ProtocolCodec;
use protocol::traits::{Backend, Executor, ExecutorAdapter};
use protocol::types::{
data_gas_cost, Account, Config, ExecResp, Hasher, SignedTransaction, TransactionAction, TxResp,
ValidatorExtend, GAS_CALL_TRANSACTION, GAS_CREATE_TRANSACTION, H160, NIL_DATA, RLP_NULL, U256,
data_gas_cost, Account, Config, ExecResp, Hasher, SignedTransaction, TransactionAction,
TransactionTrace, TxResp, ValidatorExtend, GAS_CALL_TRANSACTION, GAS_CREATE_TRANSACTION, H160,
NIL_DATA, RLP_NULL, U256,
};

use crate::precompiles::build_precompile_set;
Expand Down Expand Up @@ -136,7 +136,7 @@ impl Executor for AxonExecutor {
// transaction called EVM
let mut r = if cfg!(feature = "tracing") {
let mut listener = AxonListener::new();
trace_using(&mut listener, || {
trace_using(&mut listener, true, || {
system_contract_dispatch(adapter, tx)
.unwrap_or_else(|| Self::evm_exec(adapter, &config, &precompiles, tx))
})
Expand Down Expand Up @@ -304,11 +304,13 @@ impl AxonExecutor {
to: Option<H160>,
value: U256,
data: Vec<u8>,
) -> TxResp {
) -> (TxResp, TransactionTrace) {
let mut listener = AxonListener::new();
trace_using(&mut listener, || {
let resp = trace_using(&mut listener, false, || {
self.call(backend, gas_limit, from, to, value, data)
})
});

(resp, listener.finish().try_into().unwrap())
}

// Todo: add the is_genesis judgement
Expand Down
Loading

0 comments on commit 7417d44

Please sign in to comment.