From 7a404c79886d792fdfa16f9f24f16a21fbdb8f55 Mon Sep 17 00:00:00 2001 From: fh Date: Sun, 25 Jun 2023 17:19:55 +0800 Subject: [PATCH] remove trie cache --- Cargo.toml | 10 +++------- crates/api/src/adapter.rs | 4 ++-- crates/executor/src/adapter/mod.rs | 23 ++++++++++------------- crates/model/src/types/primitive.rs | 2 +- crates/model/src/types/transaction.rs | 6 +----- crates/storage/src/lib.rs | 4 ++-- examples/demo.rs | 1 - src/lib.rs | 18 ++++++------------ 8 files changed, 25 insertions(+), 43 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6816711..c37bd0b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,13 +51,9 @@ rug = "1.19" sha2 = "0.10" ripemd = "0.1" -ruc = { version = "4.1.0", features = ["crypto"] } - -vsdb = { version = "0.55.0", features = ["extra_types"] } -# vsdb = { path = "../vsdb/wrappers", features = ["extra_types"] } - -vsdb_trie_db = "0.7.0" -# vsdb_trie_db = { path = "../vsdb/utils/trie_db" } +ruc = { version = "5.0.10", features = ["crypto"] } +vsdb = { version = "0.60.0", default-features = false, features = ["extra_types"] } +vsdb_trie_db = "0.14.0" #################################################################### #################################################################### diff --git a/crates/api/src/adapter.rs b/crates/api/src/adapter.rs index 5800ae8..a10fcd2 100644 --- a/crates/api/src/adapter.rs +++ b/crates/api/src/adapter.rs @@ -169,7 +169,7 @@ impl APIAdapter for DefaultAPIAdapter { ) -> Result> { let state_trie_tree = self .trie_db - .trie_restore(&WORLD_STATE_META_KEY, None, state_root.into()) + .trie_restore(&WORLD_STATE_META_KEY, state_root.into()) .c(d!())?; let raw_account = state_trie_tree @@ -181,7 +181,7 @@ impl APIAdapter for DefaultAPIAdapter { let storage_trie_tree = self .trie_db - .trie_restore(address.as_bytes(), None, account.storage_root.into()) + .trie_restore(address.as_bytes(), account.storage_root.into()) .c(d!())?; let hash: Hash = BigEndianHash::from_uint(&position); diff --git a/crates/executor/src/adapter/mod.rs b/crates/executor/src/adapter/mod.rs index f18e9e3..8b10a58 100644 --- a/crates/executor/src/adapter/mod.rs +++ b/crates/executor/src/adapter/mod.rs @@ -165,7 +165,7 @@ impl<'a> Backend for RTEvmExecutorAdapter<'a> { Ok(H256::default()) } else { self.trie_db - .trie_restore(address.as_bytes(), None, storage_root.into()) + .trie_restore(address.as_bytes(), storage_root.into()) .map(|trie| match trie.get(index.as_bytes()) { Ok(Some(res)) => H256::from_slice(res.as_ref()), _ => H256::default(), @@ -223,11 +223,8 @@ impl<'a> RTEvmExecutorAdapter<'a> { trie_db: &'a MptStore, storage: &'a Storage, exec_ctx: ExecutorContext, - world_state_cache_size: Option, ) -> Result { - let state = trie_db - .trie_create(&WORLD_STATE_META_KEY, world_state_cache_size, false) - .c(d!())?; + let state = trie_db.trie_create(&WORLD_STATE_META_KEY, false).c(d!())?; Ok(RTEvmExecutorAdapter { state, trie_db, @@ -243,7 +240,7 @@ impl<'a> RTEvmExecutorAdapter<'a> { exec_ctx: ExecutorContext, ) -> Result { let state = trie_db - .trie_restore(&WORLD_STATE_META_KEY, None, state_root.into()) + .trie_restore(&WORLD_STATE_META_KEY, state_root.into()) .c(d!())?; Ok(RTEvmExecutorAdapter { @@ -276,19 +273,19 @@ impl<'a> RTEvmExecutorAdapter<'a> { }; let storage_trie = if reset_storage { - self.trie_db - .trie_create(address.as_bytes(), None, true) - .c(d!()) + self.trie_db.trie_create(address.as_bytes(), true).c(d!()) } else if existing { self.trie_db - .trie_restore(address.as_bytes(), None, old_account.storage_root.into()) + .trie_restore(address.as_bytes(), old_account.storage_root.into()) .c(d!()) } else { // this address does not exist in the world state, // so we reset it in the trie backend db also. - self.trie_db - .trie_create(address.as_bytes(), None, true) - .c(d!("{}, {:?}", address, address.as_bytes())) + self.trie_db.trie_create(address.as_bytes(), true).c(d!( + "{}, {:?}", + address, + address.as_bytes() + )) }; let mut storage_trie = pnk!(storage_trie); diff --git a/crates/model/src/types/primitive.rs b/crates/model/src/types/primitive.rs index 8748b21..b6f68af 100644 --- a/crates/model/src/types/primitive.rs +++ b/crates/model/src/types/primitive.rs @@ -14,7 +14,7 @@ pub struct Hasher; impl Hasher { pub fn digest(data: impl AsRef<[u8]>) -> Hash { - crypto::hash(data.as_ref()).into() + crypto::keccak_hash(data.as_ref()).into() } } diff --git a/crates/model/src/types/transaction.rs b/crates/model/src/types/transaction.rs index 6eaee75..1e89e1e 100644 --- a/crates/model/src/types/transaction.rs +++ b/crates/model/src/types/transaction.rs @@ -408,11 +408,7 @@ impl SignatureComponents { } pub fn extract_chain_id(v: u64) -> Option { - if v >= 35 { - Some((v - 35) / 2u64) - } else { - None - } + if v >= 35 { Some((v - 35) / 2u64) } else { None } } #[allow(clippy::len_without_is_empty)] diff --git a/crates/storage/src/lib.rs b/crates/storage/src/lib.rs index befb9e9..ffede56 100644 --- a/crates/storage/src/lib.rs +++ b/crates/storage/src/lib.rs @@ -390,7 +390,7 @@ pub fn get_account_by_backend( }; let state = trie_db - .trie_restore(&WORLD_STATE_META_KEY, None, header.state_root.into()) + .trie_restore(&WORLD_STATE_META_KEY, header.state_root.into()) .c(d!())?; get_account_by_state(&state, address).c(d!()) @@ -416,7 +416,7 @@ pub fn save_account_by_backend( ) -> Result<()> { let header = storage.get_latest_block_header().c(d!())?; let mut state = trie_db - .trie_restore(&WORLD_STATE_META_KEY, None, header.state_root.into()) + .trie_restore(&WORLD_STATE_META_KEY, header.state_root.into()) .c(d!())?; save_account_by_state(&mut state, address, account).c(d!()) diff --git a/examples/demo.rs b/examples/demo.rs index d9c5783..2d0080a 100644 --- a/examples/demo.rs +++ b/examples/demo.rs @@ -41,7 +41,6 @@ impl Config { let rt = EvmRuntime::restore_or_create( self.chain_id, &self.genesis_token_distributions, - None, ) .c(d!())?; diff --git a/src/lib.rs b/src/lib.rs index 354470d..0ebf29b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -85,18 +85,13 @@ impl EvmRuntime { pub fn create( chain_id: u64, token_distributions: &[TokenDistributon], - world_state_cache_size: Option, ) -> Result { let r = Self::new(chain_id, MptStore::new(), Storage::default()); { - let mut exector_adapter = RTEvmExecutorAdapter::new( - &r.trie_db, - &r.storage, - Default::default(), - world_state_cache_size, - ) - .c(d!())?; + let mut exector_adapter = + RTEvmExecutorAdapter::new(&r.trie_db, &r.storage, Default::default()) + .c(d!())?; token_distributions .iter() @@ -171,12 +166,11 @@ impl EvmRuntime { pub fn restore_or_create( chain_id: u64, token_distributions: &[TokenDistributon], - world_state_cache_size: Option, ) -> Result { if let Some(rt) = Self::restore().c(d!())? { Ok(rt) } else { - Self::create(chain_id, token_distributions, world_state_cache_size).c(d!()) + Self::create(chain_id, token_distributions).c(d!()) } } @@ -255,11 +249,11 @@ impl EvmRuntime { .c(d!())?; if let Some(hdr) = http_hdr { - tokio::spawn(async { hdr.await }); + tokio::spawn(hdr); } if let Some(hdr) = ws_hdr { - tokio::spawn(async { hdr.await }); + tokio::spawn(hdr); } Ok(())