Skip to content

Commit

Permalink
track more
Browse files Browse the repository at this point in the history
  • Loading branch information
lightsing committed Dec 23, 2024
1 parent 38b5381 commit 5de8e19
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 49 deletions.
4 changes: 2 additions & 2 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ scroll = [
]
debug-account = ["sbv-helpers/debug-account"]
debug-storage = ["sbv-helpers/debug-storage"]
dev = ["sbv-primitives/dev", "sbv-helpers/dev"]
dev = ["sbv-primitives/dev", "sbv-helpers/dev", "sbv-trie/dev"]
metrics = ["sbv-helpers/metrics"]

# sp1 related
sp1 = []
cycle-tracker = []
cycle-tracker = ["sbv-trie/cycle-tracker"]
ordered-db = ["revm/ordered-cache-db"]
5 changes: 4 additions & 1 deletion crates/core/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ impl<
nodes_provider: NodesProvider,
block_hashes: BlockHashProvider,
) -> Self {
let state = PartialStateTrie::open(&nodes_provider, state_root_before);
let state = cycle_track!(
PartialStateTrie::open(&nodes_provider, state_root_before),
"PartialStateTrie::open"
);

EvmDatabase {
code_db,
Expand Down
5 changes: 3 additions & 2 deletions crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub use alloy_primitives::{
address, b256, keccak256, Address, BlockHash, BlockNumber, Bytes, ChainId, B256, U256,
};
pub use reth_primitives::{Block, BlockBody, BlockWithSenders, Receipt, TransactionSigned};
use sbv_helpers::cycle_track;

/// The spec of an Ethereum network
pub mod chainspec {
Expand Down Expand Up @@ -142,7 +143,7 @@ impl<T: BlockWitness> BlockWitnessCodeExt for T {
fn import_codes<CodeDb: KeyValueStore<B256, Bytes>>(&self, mut code_db: CodeDb) {
for code in self.codes_iter() {
let code = code.as_ref();
let code_hash = keccak256(code);
let code_hash = cycle_track!(keccak256(code), "keccak256");
code_db.or_insert_with(code_hash, || Bytes::copy_from_slice(code))
}
}
Expand All @@ -152,7 +153,7 @@ impl<T: BlockWitness> BlockWitnessCodeExt for [T] {
fn import_codes<CodeDb: KeyValueStore<B256, Bytes>>(&self, mut code_db: CodeDb) {
for code in self.iter().flat_map(|w| w.codes_iter()) {
let code = code.as_ref();
let code_hash = keccak256(code);
let code_hash = cycle_track!(keccak256(code), "keccak256");
code_db.or_insert_with(code_hash, || Bytes::copy_from_slice(code))
}
}
Expand Down
39 changes: 0 additions & 39 deletions crates/primitives/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,3 @@ pub use signature::{ArchivedSignature, Signature};
pub use transaction::{ArchivedTransaction, Transaction};
pub use withdrawal::{ArchivedWithdrawal, Withdrawal};
pub use witness::{ArchivedBlockWitness, BlockWitness};

#[cfg(test)]
mod test {
use super::*;
use alloy_rpc_types_debug::ExecutionWitness;
use alloy_rpc_types_eth::Block;

const BLOCK_2BA60C: &str =
include_str!("../../../../testdata/holesky_witness/0x2ba60c/block.json");
const BLOCK_2BA60D: &str =
include_str!("../../../../testdata/holesky_witness/0x2ba60d/block.json");
const WITNESS_2BA60C: &str =
include_str!("../../../../testdata/holesky_witness/0x2ba60c/witness.json");
const WITNESS_2BA60D: &str =
include_str!("../../../../testdata/holesky_witness/0x2ba60d/witness.json");

#[test]
fn test_deserialize_block() {
serde_json::from_str::<Block>(BLOCK_2BA60C).unwrap();
serde_json::from_str::<Block>(BLOCK_2BA60D).unwrap();
serde_json::from_str::<ExecutionWitness>(WITNESS_2BA60C).unwrap();
serde_json::from_str::<ExecutionWitness>(WITNESS_2BA60D).unwrap();
}

#[test]
fn test_build() {
let block = serde_json::from_str::<Block>(BLOCK_2BA60D).unwrap();
let prev_state_root = serde_json::from_str::<Block>(BLOCK_2BA60C)
.unwrap()
.header
.state_root;
let witness = serde_json::from_str::<ExecutionWitness>(WITNESS_2BA60D).unwrap();

let block_witness = BlockWitness::new_from_block(block, prev_state_root, witness);
test_block_witness(block_witness);
}

fn test_block_witness<B: crate::BlockWitness>(_block_witness: B) {}
}
3 changes: 2 additions & 1 deletion crates/trie/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ alloy-rpc-types-eth.workspace = true
serde_json.workspace = true

[features]
dev = ["sbv-helpers/dev"]
dev = ["sbv-helpers/dev"]
cycle-tracker = []
8 changes: 4 additions & 4 deletions crates/trie/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Partial Merkle Patricia Trie
extern crate core;
#[macro_use]
extern crate sbv_helpers;

use alloy_rlp::{Decodable, Encodable};
use alloy_trie::{
Expand Down Expand Up @@ -55,8 +55,8 @@ pub fn decode_nodes<
) -> Result<(), alloy_rlp::Error> {
for byte in iter {
let mut buf = byte.as_ref();
let node_hash = keccak256(buf);
let node = TrieNode::decode(&mut buf)?;
let node_hash = cycle_track!(keccak256(buf), "keccak256");
let node = cycle_track!(TrieNode::decode(&mut buf), "TrieNode::decode")?;
assert!(
buf.is_empty(),
"the rlp buffer should only contains the node"
Expand Down

0 comments on commit 5de8e19

Please sign in to comment.