From 234e85b55100793777c0b2bfc1cf5157df652916 Mon Sep 17 00:00:00 2001 From: Eason Date: Mon, 12 Jun 2023 19:03:21 +0800 Subject: [PATCH] feat: add some special config --- core/api/src/adapter.rs | 11 +++++++++-- core/api/src/jsonrpc/impl/web3.rs | 2 ++ core/executor/src/lib.rs | 16 ++++++++++++++-- core/executor/src/tracing.rs | 15 ++++++++++++--- protocol/src/traits/api.rs | 1 + 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/core/api/src/adapter.rs b/core/api/src/adapter.rs index e5dd06d7a..81de4f6f0 100644 --- a/core/api/src/adapter.rs +++ b/core/api/src/adapter.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use core_executor::{ system_contract::metadata::MetadataHandle, AxonExecutor, AxonExecutorAdapter, MPTTrie, }; -use protocol::traits::{APIAdapter, Context, ExecutorAdapter, MemPool, Network, Storage}; +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, @@ -182,6 +182,7 @@ where data: Vec, state_root: Hash, mock_header: Proposal, + enable_trace: bool, ) -> ProtocolResult { let mut exec_ctx = ExecutorContext::from(mock_header); exec_ctx.origin = from.unwrap_or_default(); @@ -197,7 +198,13 @@ where .map(|gas| gas.as_u64()) .unwrap_or(MAX_BLOCK_GAS_LIMIT); - Ok(AxonExecutor::default().tracing_call(&backend, gas_limit, from, to, value, data)) + if enable_trace { + return Ok( + AxonExecutor::default().tracing_call(&backend, gas_limit, from, to, value, data) + ); + } + + Ok(AxonExecutor::default().call(&backend, gas_limit, from, to, value, data)) } async fn get_code_by_hash(&self, ctx: Context, hash: &Hash) -> ProtocolResult> { diff --git a/core/api/src/jsonrpc/impl/web3.rs b/core/api/src/jsonrpc/impl/web3.rs index 50df9af0d..49408fd6f 100644 --- a/core/api/src/jsonrpc/impl/web3.rs +++ b/core/api/src/jsonrpc/impl/web3.rs @@ -77,6 +77,7 @@ impl Web3RpcImpl { let mock_header = mock_header_by_call_req(header, &req); + // Todo: change the enable_trace flag to false self.adapter .evm_call( Context::new(), @@ -88,6 +89,7 @@ impl Web3RpcImpl { data.to_vec(), mock_header.state_root, Proposal::new_without_state_root(&mock_header), + true, ) .await } diff --git a/core/executor/src/lib.rs b/core/executor/src/lib.rs index 84ff2ca68..be8792551 100644 --- a/core/executor/src/lib.rs +++ b/core/executor/src/lib.rs @@ -66,7 +66,7 @@ impl Executor for AxonExecutor { value: U256, data: Vec, ) -> TxResp { - let config = Config::london(); + let config = self.config(false); let metadata = StackSubstateMetadata::new(gas_limit, &config); let state = MemoryStackState::new(metadata, backend); let precompiles = build_precompile_set(); @@ -123,7 +123,7 @@ impl Executor for AxonExecutor { let mut hashes = Vec::with_capacity(txs_len); let (mut gas, mut fee) = (0u64, U256::zero()); let precompiles = build_precompile_set(); - let config = Config::london(); + let config = self.config(block_number.is_zero()); // Execute system contracts before block hook. before_block_hook(adapter); @@ -311,6 +311,18 @@ impl AxonExecutor { }) } + // Todo: add the is_genesis judgement + fn config(&self, _is_genesis: bool) -> Config { + let mut config = Config::london(); + + // if is_genesis { + // config.create_contract_limit = Some(0xc000); + // } + + config.create_contract_limit = Some(0xc000); + config + } + #[cfg(test)] fn test_exec( &self, diff --git a/core/executor/src/tracing.rs b/core/executor/src/tracing.rs index 033117e0a..89b5a78d6 100644 --- a/core/executor/src/tracing.rs +++ b/core/executor/src/tracing.rs @@ -485,7 +485,7 @@ mod wrapped_event { .field("scheme", scheme) .field("value", value) .field("gas", target_gas) - .finish(), + .finish_non_exhaustive(), Event::TransactCreate { caller, value, @@ -498,7 +498,7 @@ mod wrapped_event { .field("value", value) .field("gas", gas_limit) .field("address", address) - .finish(), + .finish_non_exhaustive(), Event::TransactCreate2 { caller, value, @@ -513,7 +513,7 @@ mod wrapped_event { .field("salt", salt) .field("gas", gas_limit) .field("address", address) - .finish(), + .finish_non_exhaustive(), _ => Debug::fmt(event, f), } } @@ -532,6 +532,15 @@ mod wrapped_event { .field("opcode", opcode) .field("position", position) .field("stack", stack) + .finish_non_exhaustive(), + Event::StepResult { + result, + return_value, + } => f + .debug_struct("StepResult") + .field("result", result) + .field("return_len", &return_value.len()) + .field("return_value", return_value) .finish(), _ => Debug::fmt(event, f), } diff --git a/protocol/src/traits/api.rs b/protocol/src/traits/api.rs index 8092b36d4..770550314 100644 --- a/protocol/src/traits/api.rs +++ b/protocol/src/traits/api.rs @@ -78,6 +78,7 @@ pub trait APIAdapter: Send + Sync { data: Vec, state_root: Hash, proposal: Proposal, + enable_trace: bool, ) -> ProtocolResult; async fn get_code_by_hash(&self, ctx: Context, hash: &Hash) -> ProtocolResult>;