Skip to content

Commit

Permalink
fix ci issues
Browse files Browse the repository at this point in the history
  • Loading branch information
forcodedancing committed Sep 10, 2024
1 parent 08db562 commit 46f19f6
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 35 deletions.
2 changes: 1 addition & 1 deletion crates/chain-state/src/cached_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub struct CachedStateProvider {
}

impl CachedStateProvider {
/// Create a new CachedStateProvider
/// Create a new `CachedStateProvider`
pub fn new(
underlying: Box<dyn StateProvider>,
state_cache: &'static dyn StateCache<
Expand Down
1 change: 1 addition & 0 deletions crates/engine/tree/src/cache/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(clippy::type_complexity)]
mod plain_state;
pub use plain_state::CACHED_PLAIN_STATES;

Expand Down
21 changes: 10 additions & 11 deletions crates/engine/tree/src/cache/plain_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ type AddressStorageKey = (Address, StorageKey);

lazy_static! {
/// Account cache
static ref ACCOUNT_CACHE: Cache<Address, Account> = Cache::new(ACCOUNT_CACHE_SIZE);
static ref PLAIN_ACCOUNTS: Cache<Address, Account> = Cache::new(ACCOUNT_CACHE_SIZE);

/// Storage cache
static ref STORAGE_CACHE: Cache<AddressStorageKey, StorageValue> = Cache::new(STORAGE_CACHE_SIZE);
static ref PLAIN_STORAGES: Cache<AddressStorageKey, StorageValue> = Cache::new(STORAGE_CACHE_SIZE);

/// Contract cache
/// The size of contract is large and the hot contracts should be limited.
static ref CONTRACT_CACHE: Cache<B256, Bytecode> = Cache::new(CONTRACT_CACHE_SIZE);
static ref PLAIN_CONTRACTS: Cache<B256, Bytecode> = Cache::new(CONTRACT_CACHE_SIZE);

/// Cached plain states
pub static ref CACHED_PLAIN_STATES: (&'static Cache<Address, Account>, &'static Cache<AddressStorageKey, StorageValue>, &'static Cache<B256, Bytecode>) = (&ACCOUNT_CACHE, &STORAGE_CACHE, &CONTRACT_CACHE);
pub static ref CACHED_PLAIN_STATES: (&'static Cache<Address, Account>, &'static Cache<AddressStorageKey, StorageValue>, &'static Cache<B256, Bytecode>) = (&PLAIN_ACCOUNTS, &PLAIN_STORAGES, &PLAIN_CONTRACTS);
}

// Implementing StateCache trait for CACHED_PLAIN_STATES
Expand Down Expand Up @@ -94,10 +94,10 @@ pub(crate) fn write_plain_state(bundle: BundleState) {
for (address, account_info) in &change_set.accounts {
match account_info {
None => {
ACCOUNT_CACHE.remove(address);
PLAIN_ACCOUNTS.remove(address);
}
Some(acc) => {
ACCOUNT_CACHE.insert(
PLAIN_ACCOUNTS.insert(
*address,
Account {
nonce: acc.nonce,
Expand All @@ -115,14 +115,13 @@ pub(crate) fn write_plain_state(bundle: BundleState) {
if storage.wipe_storage {
to_wipe = true;
break;
} else {
for (k, v) in storage.storage.clone() {
STORAGE_CACHE.insert((storage.address, StorageKey::from(k)), v);
}
}
for (k, v) in storage.storage.clone() {
PLAIN_STORAGES.insert((storage.address, StorageKey::from(k)), v);
}
}
if to_wipe {
STORAGE_CACHE.clear();
PLAIN_STORAGES.clear();
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/engine/tree/src/tree/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pub(crate) use metrics::histogram;
use reth_metrics::{
metrics::{Counter, Gauge, Histogram},
Metrics,
};
pub(crate) use metrics::histogram as histogram;

/// Metrics for the `EngineApi`.
#[derive(Metrics)]
Expand Down
4 changes: 2 additions & 2 deletions crates/engine/tree/src/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1785,7 +1785,7 @@ where
let elapsed = exec_time.elapsed();
debug!(target: "engine", elapsed=?elapsed, ?block_number, "Executed block");
metrics::histogram!("execution.total").record(elapsed.as_nanos() as f64);

self.consensus.validate_block_post_execution(
&block,
PostExecutionInput::new(&output.receipts, &output.requests),
Expand All @@ -1802,7 +1802,7 @@ where
)
.into())
}
let elapsed=root_time.elapsed();
let elapsed = root_time.elapsed();
debug!(target: "engine", elapsed=?elapsed, ?block_number, "Calculated state root");
metrics::histogram!("state-root.total").record(elapsed.as_nanos() as f64);

Expand Down
10 changes: 5 additions & 5 deletions crates/storage/provider/src/test_utils/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,11 +603,11 @@ impl StateRootProvider for MockEthProvider {

fn state_root_from_nodes_caches_with_updates(
&self,
nodes: TrieUpdates,
hashed_state: HashedPostState,
prefix_sets: TriePrefixSetsMut,
hashed_cache: &'static dyn TrieCache<B256, Account, (B256, B256), U256>,
trie_cache: &'static dyn TrieCache<
_nodes: TrieUpdates,
_hashed_state: HashedPostState,
_prefix_sets: TriePrefixSetsMut,
_hashed_cache: &'static dyn TrieCache<B256, Account, (B256, B256), U256>,
_trie_cache: &'static dyn TrieCache<
Nibbles,
BranchNodeCompact,
(B256, Nibbles),
Expand Down
10 changes: 5 additions & 5 deletions crates/storage/provider/src/test_utils/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,11 @@ impl StateRootProvider for NoopProvider {

fn state_root_from_nodes_caches_with_updates(
&self,
nodes: TrieUpdates,
hashed_state: HashedPostState,
prefix_sets: TriePrefixSetsMut,
hashed_cache: &'static dyn TrieCache<B256, Account, (B256, B256), U256>,
trie_cache: &'static dyn TrieCache<
_nodes: TrieUpdates,
_hashed_state: HashedPostState,
_prefix_sets: TriePrefixSetsMut,
_hashed_cache: &'static dyn TrieCache<B256, Account, (B256, B256), U256>,
_trie_cache: &'static dyn TrieCache<
Nibbles,
BranchNodeCompact,
(B256, Nibbles),
Expand Down
17 changes: 7 additions & 10 deletions crates/trie/db/src/cached_trie_cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,22 +121,22 @@ where
return Ok(Some((key, result)))
};

return match self.cursor.seek(StoredNibbles(key))? {
match self.cursor.seek(StoredNibbles(key))? {
Some(value) => {
self.trie_cache.insert_account(value.0 .0.clone(), value.1.clone());

Ok(Some((value.0 .0, value.1)))
}
None => Ok(None),
};
}
}

/// Move the cursor to the next entry in the account trie.
fn next_inner(
&mut self,
last: Nibbles,
) -> Result<Option<(Nibbles, BranchNodeCompact)>, DatabaseError> {
let _ = self.cursor.seek(StoredNibbles(last.clone()))?;
let _ = self.cursor.seek(StoredNibbles(last))?;
match self.cursor.next()? {
Some(value) => {
self.trie_cache.insert_account(value.0 .0.clone(), value.1.clone());
Expand Down Expand Up @@ -236,7 +236,7 @@ where
return Ok(Some((key, result)))
};

return match self
match self
.cursor
.seek_by_key_subkey(self.hashed_address, StoredNibblesSubKey(key.clone()))?
{
Expand All @@ -251,7 +251,7 @@ where
}
}
None => Ok(None),
};
}
}

/// Seek a key in the storage trie that matches or is greater than the provided key.
Expand All @@ -264,18 +264,15 @@ where
return Ok(Some((key, result)))
};

return match self
.cursor
.seek_by_key_subkey(self.hashed_address, StoredNibblesSubKey(key))?
{
match self.cursor.seek_by_key_subkey(self.hashed_address, StoredNibblesSubKey(key))? {
Some(value) => {
let key = (self.hashed_address, value.nibbles.0.clone());
self.trie_cache.insert_storage(key, value.node.clone());

Ok(Some((value.nibbles.0, value.node)))
}
None => Ok(None),
};
}
}

/// Move the cursor to the next entry in the storage trie.
Expand Down

0 comments on commit 46f19f6

Please sign in to comment.