Skip to content

Commit

Permalink
make cache size smaller
Browse files Browse the repository at this point in the history
  • Loading branch information
forcodedancing committed Oct 17, 2024
1 parent cafd825 commit e03c10a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion crates/chain-state/src/cache/plain_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ use reth_db::{cursor::DbDupCursorRO, table::TableRow, tables, DatabaseError, Pla
use reth_db_api::transaction::DbTx;
use reth_primitives::{Account, Address, Bytecode, StorageKey, StorageValue, B256, U256};
use reth_revm::db::{BundleState, OriginalValuesKnown};
use std::sync::atomic::AtomicU64;

lazy_static! {
static ref CACHE_SZ: AtomicU64 = AtomicU64::new(0);
}
use tracing::info;

// Cache sizes
const ACCOUNT_CACHE_SIZE: usize = 1000000;
const STORAGE_CACHE_SIZE: usize = ACCOUNT_CACHE_SIZE * 10;
const STORAGE_CACHE_SIZE: usize = ACCOUNT_CACHE_SIZE * 5;
const CONTRACT_CACHE_SIZE: usize = ACCOUNT_CACHE_SIZE / 100;

// Type alias for address and storage key tuple
Expand All @@ -33,6 +39,12 @@ pub(crate) fn insert_account(k: Address, v: Account) {
/// Insert storage into the cache
pub(crate) fn insert_storage(k: AddressStorageKey, v: U256) {
PLAIN_STORAGES.insert(k, v);

let current = CACHE_SZ.load(std::sync::atomic::Ordering::Relaxed);
CACHE_SZ.store(current + 1, std::sync::atomic::Ordering::Relaxed);
if current % 10000 == 0 {
info!("CACHE_SZ {}", current);
}
}

// Get account from cache
Expand Down

0 comments on commit e03c10a

Please sign in to comment.