Skip to content

Commit

Permalink
feat: enable contract size limit change with evm
Browse files Browse the repository at this point in the history
  • Loading branch information
driftluo committed Oct 10, 2023
1 parent 5e8a0e6 commit a444455
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
6 changes: 3 additions & 3 deletions core/api/src/jsonrpc/impl/axon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ fn enabled_and_determined(iter: &[HardforkInfoInner], current_number: u64) -> (H
if iter.len() < 2 {
match iter.last() {
Some(latest) => {
if latest.block_number >= current_number {
(latest.flags, H256::zero())
} else {
if latest.block_number > current_number {
(H256::zero(), latest.flags)
} else {
(latest.flags, H256::zero())
}
}
None => (H256::zero(), H256::zero()),
Expand Down
27 changes: 24 additions & 3 deletions core/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ mod utils;
pub use crate::adapter::{
AxonExecutorApplyAdapter, AxonExecutorReadOnlyAdapter, MPTTrie, RocksTrieDB,
};
pub use crate::system_contract::{metadata::MetadataHandle, DataProvider};
pub use crate::system_contract::{
metadata::{MetadataHandle, HARDFORK_INFO},
DataProvider,
};
pub use crate::utils::{code_address, decode_revert_msg, DefaultFeeAllocator, FeeInlet};

use std::cell::RefCell;
use std::collections::BTreeMap;
use std::iter::FromIterator;

use arc_swap::ArcSwap;
use common_config_parser::types::spec::HardforkName;
use evm::executor::stack::{MemoryStackState, PrecompileFn, StackExecutor, StackSubstateMetadata};
use evm::CreateScheme;

Expand Down Expand Up @@ -69,7 +73,7 @@ impl Executor for AxonExecutor {
value: U256,
data: Vec<u8>,
) -> TxResp {
let config = Config::london();
let config = self.config();
let metadata = StackSubstateMetadata::new(gas_limit, &config);
let state = MemoryStackState::new(metadata, backend);
let precompiles = build_precompile_set();
Expand Down Expand Up @@ -134,7 +138,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();

self.init_local_system_contract_roots(adapter);

Expand Down Expand Up @@ -316,6 +320,23 @@ impl AxonExecutor {
});
}

fn config(&self) -> Config {
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);
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
}
};
config.create_contract_limit = create_contract_limit;
config
}

#[cfg(test)]
fn test_exec<Adapter: ExecutorAdapter>(
&self,
Expand Down
6 changes: 5 additions & 1 deletion core/executor/src/system_contract/metadata/handle.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use protocol::types::{CkbRelatedInfo, HardforkInfo, Metadata, H160, H256};
use protocol::types::{CkbRelatedInfo, ConsensusConfig, HardforkInfo, Metadata, H160, H256};
use protocol::ProtocolResult;

use std::sync::Arc;
Expand Down Expand Up @@ -62,4 +62,8 @@ impl MetadataHandle {
HARDFORK_INFO.swap(Arc::new(hardfork));
Ok(())
}

pub fn get_consensus_config(&self) -> ProtocolResult<ConsensusConfig> {
MetadataStore::new(self.root)?.get_consensus_config()
}
}
4 changes: 3 additions & 1 deletion core/executor/src/system_contract/metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ lazy_static::lazy_static! {
static ref CKB_RELATED_INFO_KEY: H256 = Hasher::digest("ckb_related_info");
pub static ref CONSENSUS_CONFIG: H256 = Hasher::digest("consensus_config");
pub static ref HARDFORK_KEY: H256 = Hasher::digest("hardfork");
static ref HARDFORK_INFO: ArcSwap<H256> = ArcSwap::new(Arc::new(H256::zero()));
pub static ref HARDFORK_INFO: ArcSwap<H256> = ArcSwap::new(Arc::new(H256::zero()));
static ref METADATA_CACHE: RwLock<LruCache<Epoch, Metadata>> = RwLock::new(LruCache::new(METADATA_CACHE_SIZE));
}

Expand Down Expand Up @@ -129,6 +129,8 @@ impl<Adapter: ExecutorAdapter + ApplyBackend> SystemContract<Adapter>
HARDFORK_INFO.swap(Arc::new(hardfork));

if block_number.is_zero() {
let changes = generate_mpt_root_changes(adapter, Self::ADDRESS);
adapter.apply(changes, vec![], false);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion core/executor/src/system_contract/metadata/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl MetadataStore {
MetadataInner::decode(raw)
}

fn get_consensus_config(&self) -> ProtocolResult<ConsensusConfig> {
pub fn get_consensus_config(&self) -> ProtocolResult<ConsensusConfig> {
let raw = self
.trie
.get(CONSENSUS_CONFIG.as_bytes())?
Expand Down

0 comments on commit a444455

Please sign in to comment.