Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix evm config init #1484

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions core/api/src/jsonrpc/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ pub enum RpcError {
#[display(fmt = "Invalid filter id {}", _0)]
CannotFindFilterId(u64),

#[display(fmt = "CKB-VM error {}", "decode_revert_msg(&_0.ret)")]
VM(TxResp),
#[display(fmt = "EVM error {}", "decode_revert_msg(&_0.ret)")]
Evm(TxResp),
#[display(fmt = "Internal error")]
Internal(String),
}
Expand Down Expand Up @@ -92,7 +92,7 @@ impl RpcError {
RpcError::InvalidFromBlockAndToBlockUnion => -40021,
RpcError::CannotFindFilterId(_) => -40022,

RpcError::VM(_) => -49998,
RpcError::Evm(_) => -49998,
RpcError::Internal(_) => -49999,
}
}
Expand Down Expand Up @@ -134,7 +134,7 @@ impl From<RpcError> for ErrorObjectOwned {
}
RpcError::CannotFindFilterId(_) => ErrorObject::owned(err_code, err, none_data),

RpcError::VM(resp) => {
RpcError::Evm(resp) => {
ErrorObject::owned(err_code, err.clone(), Some(vm_err(resp.clone())))
}
RpcError::Internal(msg) => ErrorObject::owned(err_code, err.clone(), Some(msg)),
Expand Down
4 changes: 2 additions & 2 deletions core/api/src/jsonrpc/impl/web3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ impl<Adapter: APIAdapter + 'static> Web3RpcServer for Web3RpcImpl<Adapter> {
return Ok(call_hex_result);
}

Err(RpcError::VM(resp).into())
Err(RpcError::Evm(resp).into())
}

#[metrics_rpc("eth_estimateGas")]
Expand Down Expand Up @@ -557,7 +557,7 @@ impl<Adapter: APIAdapter + 'static> Web3RpcServer for Web3RpcImpl<Adapter> {
return Ok(resp.gas_used.into());
}

Err(RpcError::VM(resp).into())
Err(RpcError::Evm(resp).into())
}

#[metrics_rpc("eth_getCode")]
Expand Down
11 changes: 6 additions & 5 deletions core/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl Executor for AxonExecutor {
value: U256,
data: Vec<u8>,
) -> TxResp {
self.init_local_system_contract_roots(backend);
let config = self.config();
let metadata = StackSubstateMetadata::new(gas_limit, &config);
let state = MemoryStackState::new(metadata, backend);
Expand Down Expand Up @@ -138,9 +139,8 @@ 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 = self.config();

self.init_local_system_contract_roots(adapter);
let config = self.config();

// Execute system contracts before block hook.
before_block_hook(adapter);
Expand Down Expand Up @@ -309,7 +309,7 @@ impl AxonExecutor {
/// The `exec()` function is run in `tokio::task::block_in_place()` and all
/// the read or write operations are in the scope of exec function. The
/// thread context is not switched during exec function.
fn init_local_system_contract_roots<Adapter: ExecutorAdapter>(&self, adapter: &mut Adapter) {
fn init_local_system_contract_roots<Adapter: Backend>(&self, adapter: &Adapter) {
CURRENT_HEADER_CELL_ROOT.with(|root| {
*root.borrow_mut() =
adapter.storage(CKB_LIGHT_CLIENT_CONTRACT_ADDRESS, *HEADER_CELL_ROOT_KEY);
Expand All @@ -324,13 +324,14 @@ impl AxonExecutor {
let mut config = Config::london();
let create_contract_limit = {
let latest_hardfork_info = &**HARDFORK_INFO.load();
let enable_contract_limit_flag = H256::from_low_u64_be(HardforkName::Andromeda as u64);
let enable_contract_limit_flag =
H256::from_low_u64_be((HardforkName::Andromeda as u64).to_be());
if latest_hardfork_info & &enable_contract_limit_flag == enable_contract_limit_flag {
let handle = MetadataHandle::new(CURRENT_METADATA_ROOT.with(|r| *r.borrow()));
let config = handle.get_consensus_config().unwrap();
Some(config.max_contract_limit as usize)
} else {
None
Some(0x6000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to use fn default_max_contract_limit instead of hardcoding 0x6000?

}
};
config.create_contract_limit = create_contract_limit;
Expand Down
7 changes: 5 additions & 2 deletions core/executor/src/tests/system_script/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,11 @@ fn prepare_validator() -> ValidatorExtend {
// .gas(21000)
// .nonce(nonce);

// let wallet = LocalWallet::from_str(PRIVATE_KEY).expect("failed to create
// wallet"); let tx = Legacy(transaction_request);
// let wallet = LocalWallet::from_str(PRIVATE_KEY).expect(
// "failed to create
// wallet",
// );
// let tx = Legacy(transaction_request);
// let signature: Signature = wallet.sign_transaction(&tx).await.unwrap();

// provider
Expand Down
Loading