Skip to content

Commit

Permalink
feat: add some special config
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason committed Jul 24, 2023
1 parent 510944d commit 234e85b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
11 changes: 9 additions & 2 deletions core/api/src/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -182,6 +182,7 @@ where
data: Vec<u8>,
state_root: Hash,
mock_header: Proposal,
enable_trace: bool,
) -> ProtocolResult<TxResp> {
let mut exec_ctx = ExecutorContext::from(mock_header);
exec_ctx.origin = from.unwrap_or_default();
Expand All @@ -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<Option<Bytes>> {
Expand Down
2 changes: 2 additions & 0 deletions core/api/src/jsonrpc/impl/web3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ impl<Adapter: APIAdapter> Web3RpcImpl<Adapter> {

let mock_header = mock_header_by_call_req(header, &req);

// Todo: change the enable_trace flag to false
self.adapter
.evm_call(
Context::new(),
Expand All @@ -88,6 +89,7 @@ impl<Adapter: APIAdapter> Web3RpcImpl<Adapter> {
data.to_vec(),
mock_header.state_root,
Proposal::new_without_state_root(&mock_header),
true,
)
.await
}
Expand Down
16 changes: 14 additions & 2 deletions core/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl Executor for AxonExecutor {
value: U256,
data: Vec<u8>,
) -> 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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<Adapter: ExecutorAdapter>(
&self,
Expand Down
15 changes: 12 additions & 3 deletions core/executor/src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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),
}
}
Expand All @@ -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),
}
Expand Down
1 change: 1 addition & 0 deletions protocol/src/traits/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub trait APIAdapter: Send + Sync {
data: Vec<u8>,
state_root: Hash,
proposal: Proposal,
enable_trace: bool,
) -> ProtocolResult<TxResp>;

async fn get_code_by_hash(&self, ctx: Context, hash: &Hash) -> ProtocolResult<Option<Bytes>>;
Expand Down

0 comments on commit 234e85b

Please sign in to comment.