Skip to content

Commit

Permalink
add debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
forcodedancing committed Sep 11, 2024
1 parent 54a2a8a commit 1665976
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 63 deletions.
34 changes: 18 additions & 16 deletions crates/chain-state/src/cache/hashed_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ impl CACHED_HASH_STATES {
impl TrieCache<B256, Account, HashedStorageKey, U256> for CACHED_HASH_STATES {
/// Get an account from the cache
fn get_account(&self, k: &B256) -> Option<Account> {
counter!("hashed-cache.account.total").increment(1);
match self.0.get(k) {
Some(r) => {
counter!("hashed-cache.account.hit").increment(1);
Some(r)
}
None => None,
}
self.0.get(k)
// counter!("hashed-cache.account.total").increment(1);
// match self.0.get(k) {
// Some(r) => {
// counter!("hashed-cache.account.hit").increment(1);
// Some(r)
// }
// None => None,
// }
}

/// Insert an account into the cache
Expand All @@ -59,14 +60,15 @@ impl TrieCache<B256, Account, HashedStorageKey, U256> for CACHED_HASH_STATES {

/// Get storage from the cache
fn get_storage(&self, k: &HashedStorageKey) -> Option<U256> {
counter!("hashed-cache.storage.total").increment(1);
match self.1.get(k) {
Some(r) => {
counter!("hashed-cache.storage.hit").increment(1);
Some(r)
}
None => None,
}
self.1.get(k)
// counter!("hashed-cache.storage.total").increment(1);
// match self.1.get(k) {
// Some(r) => {
// counter!("hashed-cache.storage.hit").increment(1);
// Some(r)
// }
// None => None,
// }
}

/// Insert storage into the cache
Expand Down
5 changes: 3 additions & 2 deletions crates/chain-state/src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ mod plain_state;
pub use plain_state::CACHED_PLAIN_STATES;

mod hashed_state;
use crate::ExecutedBlock;
pub use hashed_state::CACHED_HASH_STATES;
use tracing::debug;
use crate::ExecutedBlock;

mod trie_node;
use crate::cache::{
Expand All @@ -18,13 +18,14 @@ pub use trie_node::CACHED_TRIE_NODES;
/// Writes the execution outcomes, trie updates, and hashed states of the given blocks to the cache.
pub fn write_to_cache(blocks: Vec<ExecutedBlock>) {
for block in blocks {
debug!("Writing block {} to cache", block.block.header.number);
debug!("Start to write block {} to cache", block.block.header.number);
let bundle_state = block.execution_outcome().clone().bundle;
let trie_updates = block.trie_updates().clone();
let hashed_state = block.hashed_state();
write_plain_state(bundle_state);
write_hashed_state(&hashed_state.clone().into_sorted());
write_trie_updates(&trie_updates);
debug!("Finish to write block {} to cache", block.block.header.number);
}
}

Expand Down
56 changes: 29 additions & 27 deletions crates/chain-state/src/cache/plain_state.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use lazy_static::lazy_static;
use quick_cache::sync::Cache;

use metrics::counter;
use crate::StateCache;
use metrics::counter;
use reth_primitives::{Account, Address, Bytecode, StorageKey, StorageValue, B256};
use reth_revm::db::BundleState;
use reth_revm::db::OriginalValuesKnown;
use reth_revm::db::{BundleState, OriginalValuesKnown};

// Cache sizes
const ACCOUNT_CACHE_SIZE: usize = 1000000;
Expand Down Expand Up @@ -36,14 +35,15 @@ impl StateCache<Address, Account, AddressStorageKey, StorageValue, B256, Bytecod
{
// Get account from cache
fn get_account(&self, k: &Address) -> Option<Account> {
counter!("plain-cache.account.total").increment(1);
match self.0.get(k) {
Some(r) => {
counter!("plain-cache.account.hit").increment(1);
Some(r)
}
None => None,
}
self.0.get(k)
// counter!("plain-cache.account.total").increment(1);
// match self.0.get(k) {
// Some(r) => {
// counter!("plain-cache.account.hit").increment(1);
// Some(r)
// }
// None => None,
// }
}

// Insert account into cache
Expand All @@ -53,14 +53,15 @@ impl StateCache<Address, Account, AddressStorageKey, StorageValue, B256, Bytecod

// Get storage from cache
fn get_storage(&self, k: &AddressStorageKey) -> Option<StorageValue> {
counter!("plain-cache.storage.total").increment(1);
match self.1.get(k) {
Some(r) => {
counter!("plain-cache.storage.hit").increment(1);
Some(r)
}
None => None,
}
self.1.get(k)
// counter!("plain-cache.storage.total").increment(1);
// match self.1.get(k) {
// Some(r) => {
// counter!("plain-cache.storage.hit").increment(1);
// Some(r)
// }
// None => None,
// }
}

// Insert storage into cache
Expand All @@ -70,14 +71,15 @@ impl StateCache<Address, Account, AddressStorageKey, StorageValue, B256, Bytecod

// Get code from cache
fn get_code(&self, k: &B256) -> Option<Bytecode> {
counter!("plain-cache.code.total").increment(1);
match self.2.get(k) {
Some(r) => {
counter!("plain-cache.code.hit").increment(1);
Some(r)
}
None => None,
}
self.2.get(k)
// counter!("plain-cache.code.total").increment(1);
// match self.2.get(k) {
// Some(r) => {
// counter!("plain-cache.code.hit").increment(1);
// Some(r)
// }
// None => None,
// }
}

// Insert code into cache
Expand Down
34 changes: 18 additions & 16 deletions crates/chain-state/src/cache/trie_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@ impl TrieCache<Nibbles, BranchNodeCompact, TrieStorageKey, BranchNodeCompact>
{
// Get an account node from the cache
fn get_account(&self, k: &Nibbles) -> Option<BranchNodeCompact> {
counter!("trie-cache.account.total").increment(1);
match self.0.get(k) {
Some(r) => {
counter!("trie-cache.account.hit").increment(1);
Some(r)
}
None => None,
}
self.0.get(k)
// counter!("trie-cache.account.total").increment(1);
// match self.0.get(k) {
// Some(r) => {
// counter!("trie-cache.account.hit").increment(1);
// Some(r)
// }
// None => None,
// }
}

// Insert an account node into the cache
Expand All @@ -68,14 +69,15 @@ impl TrieCache<Nibbles, BranchNodeCompact, TrieStorageKey, BranchNodeCompact>

// Get a storage node from the cache
fn get_storage(&self, k: &TrieStorageKey) -> Option<BranchNodeCompact> {
counter!("trie-cache.storage.total").increment(1);
match self.1.get(k) {
Some(r) => {
counter!("trie-cache.storage.hit").increment(1);
Some(r)
}
None => None,
}
self.1.get(k)
// counter!("trie-cache.storage.total").increment(1);
// match self.1.get(k) {
// Some(r) => {
// counter!("trie-cache.storage.hit").increment(1);
// Some(r)
// }
// None => None,
// }
}

// Insert a storage node into the cache
Expand Down
5 changes: 3 additions & 2 deletions crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ use reth_blockchain_tree::{
BlockBuffer, BlockStatus2, InsertPayloadOk2,
};
use reth_chain_state::{
CanonicalInMemoryState, ExecutedBlock, MemoryOverlayStateProvider,
NewCanonicalChain,
CanonicalInMemoryState, ExecutedBlock, MemoryOverlayStateProvider, NewCanonicalChain,
};
use reth_consensus::{Consensus, PostExecutionInput};
use reth_engine_primitives::EngineTypes;
Expand Down Expand Up @@ -1774,6 +1773,7 @@ where
.collect::<HashMap<_, _>>();

let exec_time = Instant::now();
debug!(target: "engine", ?block_number, "Start to execute block");
let output = executor.execute((&block, U256::MAX, Some(&ancestor_blocks)).into())?;
let elapsed = exec_time.elapsed();
debug!(target: "engine", elapsed=?elapsed, ?block_number, "Executed block");
Expand All @@ -1787,6 +1787,7 @@ where
let hashed_state = HashedPostState::from_bundle_state(&output.state.state);

let root_time = Instant::now();
debug!(target: "engine", ?block_number, "Start to calculate state root");
let (state_root, trie_output) =
state_provider.state_root_with_updates(hashed_state.clone())?;
if state_root != block.state_root {
Expand Down

0 comments on commit 1665976

Please sign in to comment.