diff --git a/crates/core/src/database.rs b/crates/core/src/database.rs index 96ac65b..63c3811 100644 --- a/crates/core/src/database.rs +++ b/crates/core/src/database.rs @@ -1,7 +1,7 @@ use crate::error::DatabaseError; use once_cell::sync::Lazy; use revm::{ - db::{AccountState, DatabaseRef}, + db::DatabaseRef, primitives::{AccountInfo, Address, Bytecode, B256, U256}, }; use sbv_primitives::{ @@ -124,28 +124,18 @@ impl EvmDatabase, - ) { - let mut storage_trie_refs = self.storage_trie_refs.borrow_mut(); - for (address, account_state) in account_states { - if account_state != AccountState::None { - storage_trie_refs.remove(&address); - } - } - } } impl DatabaseRef diff --git a/crates/core/src/executor/mod.rs b/crates/core/src/executor/mod.rs index 159c460..49f52aa 100644 --- a/crates/core/src/executor/mod.rs +++ b/crates/core/src/executor/mod.rs @@ -43,13 +43,6 @@ impl EvmExecutor<'_, Cod /// Update the DB pub fn update_db(&mut self, l2_trace: &T) -> Result<(), DatabaseError> { - self.db.db.invalidate_storage_root_caches( - self.db - .accounts - .iter() - .map(|(addr, acc)| (*addr, acc.account_state.clone())), - ); - self.db.db.update(l2_trace) } @@ -58,7 +51,7 @@ impl EvmExecutor<'_, Cod #[allow(clippy::let_and_return)] let gas_used = measure_duration_millis!( handle_block_duration_milliseconds, - self.handle_block_inner(l2_trace) + cycle_track!(self.handle_block_inner(l2_trace), "handle_block") )?; #[cfg(feature = "metrics")] @@ -90,7 +83,7 @@ impl EvmExecutor<'_, Cod let mut gas_used = 0; for (idx, tx) in l2_trace.transactions().enumerate() { - cycle_tracker_start!("handle tx {}", idx); + cycle_tracker_start!("handle tx"); dev_trace!("handle {idx}th tx"); @@ -171,7 +164,7 @@ impl EvmExecutor<'_, Cod self.hooks.post_tx_execution(self, idx); dev_debug!("handle {idx}th tx done"); - cycle_tracker_end!("handle tx {}", idx); + cycle_tracker_end!("handle tx"); } Ok(gas_used) } @@ -215,7 +208,7 @@ impl EvmExecutor<'_, Cod } dev_trace!("committing {addr}, {:?} {db_acc:?}", db_acc.account_state); - cycle_tracker_start!("commit account {}", addr); + cycle_tracker_start!("commit account"); let mut storage_root = self.db.db.prev_storage_root(addr); @@ -224,10 +217,13 @@ impl EvmExecutor<'_, Cod let storage_root_before = storage_root; // get storage tire cycle_tracker_start!("update storage_tire"); - let mut storage_trie = ZkTrie::::new_with_root( - zktrie_db.clone(), - NoCacheHasher, - storage_root_before, + let mut storage_trie = cycle_track!( + ZkTrie::::new_with_root( + zktrie_db.clone(), + NoCacheHasher, + storage_root_before, + ), + "Zktrie::new_with_root" ) .expect("unable to get storage trie"); for (key, value) in db_acc.storage.iter() { @@ -255,7 +251,7 @@ impl EvmExecutor<'_, Cod measure_duration_micros!( zktrie_commit_duration_microseconds, - storage_trie.commit()? + cycle_track!(storage_trie.commit()?, "Zktrie::commit") ); cycle_tracker_end!("update storage_tire"); @@ -298,10 +294,13 @@ impl EvmExecutor<'_, Cod ) ); - cycle_tracker_end!("commit account {}", addr); + cycle_tracker_end!("commit account"); } - measure_duration_micros!(zktrie_commit_duration_microseconds, zktrie.commit()?); + measure_duration_micros!( + zktrie_commit_duration_microseconds, + cycle_track!(zktrie.commit()?, "Zktrie::commit") + ); let root_after = *zktrie.root().unwrap_ref(); diff --git a/crates/primitives/Cargo.toml b/crates/primitives/Cargo.toml index 15ffc8f..493b911 100644 --- a/crates/primitives/Cargo.toml +++ b/crates/primitives/Cargo.toml @@ -28,4 +28,6 @@ zktrie-ng.workspace = true serde_json.workspace = true [features] -dev = ["sbv-utils/dev"] \ No newline at end of file +dev = ["sbv-utils/dev"] +sp1 = [] +cycle-tracker = [] \ No newline at end of file diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index f0f7f7a..982df16 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -85,10 +85,18 @@ pub trait Block: Debug { if bytes == MAGIC_NODE_BYTES { continue; } - let node = Node::::try_from(bytes).expect("invalid node"); - let node_hash = node.get_or_calculate_node_hash().expect("infallible"); + let node = cycle_track!(Node::::try_from(bytes), "Node::try_from") + .expect("invalid node"); + let node_hash = cycle_track!( + node.get_or_calculate_node_hash(), + "Node::get_or_calculate_node_hash" + ) + .expect("infallible"); dev_trace!("put zktrie node: {:?}", node); - db.put_owned(node_hash.as_slice(), node.canonical_value(false))?; + cycle_track!( + db.put_owned(node_hash.as_slice(), node.canonical_value(false))?, + "KVDatabase::put_owned" + ); } Ok(()) } diff --git a/crates/sbv/Cargo.toml b/crates/sbv/Cargo.toml index 4a07c1c..0195497 100644 --- a/crates/sbv/Cargo.toml +++ b/crates/sbv/Cargo.toml @@ -21,6 +21,6 @@ dev = ["sbv-core/dev", "sbv-utils/dev", "sbv-primitives/dev"] metrics = ["sbv-core/metrics", "sbv-utils/metrics"] # sp1 related -sp1 = ["sbv-core/sp1"] -cycle-tracker = ["sbv-core/cycle-tracker"] +sp1 = ["sbv-core/sp1", "sbv-primitives/sp1"] +cycle-tracker = ["sbv-core/cycle-tracker", "sbv-primitives/cycle-tracker"] ordered-db = ["sbv-core/ordered-db"] \ No newline at end of file