Add a cli option for the snapshot cache size (#5270)

* Add a cli option for snapshot cache size

* Remove junk

* Make snapshot_cache module public

* lint

* Update docs
This commit is contained in:
Pawan Dhananjay 2024-02-26 10:49:39 +05:30 committed by GitHub
parent de6ede163c
commit 3ab9d3a84e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 42 additions and 4 deletions

View File

@ -12,7 +12,7 @@ use crate::light_client_server_cache::LightClientServerCache;
use crate::migrate::{BackgroundMigrator, MigratorConfig}; use crate::migrate::{BackgroundMigrator, MigratorConfig};
use crate::persisted_beacon_chain::PersistedBeaconChain; use crate::persisted_beacon_chain::PersistedBeaconChain;
use crate::shuffling_cache::{BlockShufflingIds, ShufflingCache}; use crate::shuffling_cache::{BlockShufflingIds, ShufflingCache};
use crate::snapshot_cache::{SnapshotCache, DEFAULT_SNAPSHOT_CACHE_SIZE}; use crate::snapshot_cache::SnapshotCache;
use crate::timeout_rw_lock::TimeoutRwLock; use crate::timeout_rw_lock::TimeoutRwLock;
use crate::validator_monitor::{ValidatorMonitor, ValidatorMonitorConfig}; use crate::validator_monitor::{ValidatorMonitor, ValidatorMonitorConfig};
use crate::validator_pubkey_cache::ValidatorPubkeyCache; use crate::validator_pubkey_cache::ValidatorPubkeyCache;
@ -870,6 +870,7 @@ where
let head_for_snapshot_cache = head_snapshot.clone(); let head_for_snapshot_cache = head_snapshot.clone();
let canonical_head = CanonicalHead::new(fork_choice, Arc::new(head_snapshot)); let canonical_head = CanonicalHead::new(fork_choice, Arc::new(head_snapshot));
let shuffling_cache_size = self.chain_config.shuffling_cache_size; let shuffling_cache_size = self.chain_config.shuffling_cache_size;
let snapshot_cache_size = self.chain_config.snapshot_cache_size;
// Calculate the weak subjectivity point in which to backfill blocks to. // Calculate the weak subjectivity point in which to backfill blocks to.
let genesis_backfill_slot = if self.chain_config.genesis_backfill { let genesis_backfill_slot = if self.chain_config.genesis_backfill {
@ -946,7 +947,7 @@ where
event_handler: self.event_handler, event_handler: self.event_handler,
head_tracker, head_tracker,
snapshot_cache: TimeoutRwLock::new(SnapshotCache::new( snapshot_cache: TimeoutRwLock::new(SnapshotCache::new(
DEFAULT_SNAPSHOT_CACHE_SIZE, snapshot_cache_size,
head_for_snapshot_cache, head_for_snapshot_cache,
)), )),
shuffling_cache: TimeoutRwLock::new(ShufflingCache::new( shuffling_cache: TimeoutRwLock::new(ShufflingCache::new(

View File

@ -72,6 +72,8 @@ pub struct ChainConfig {
pub optimistic_finalized_sync: bool, pub optimistic_finalized_sync: bool,
/// The size of the shuffling cache, /// The size of the shuffling cache,
pub shuffling_cache_size: usize, pub shuffling_cache_size: usize,
/// The size of the snapshot cache.
pub snapshot_cache_size: usize,
/// If using a weak-subjectivity sync, whether we should download blocks all the way back to /// If using a weak-subjectivity sync, whether we should download blocks all the way back to
/// genesis. /// genesis.
pub genesis_backfill: bool, pub genesis_backfill: bool,
@ -112,6 +114,7 @@ impl Default for ChainConfig {
// This value isn't actually read except in tests. // This value isn't actually read except in tests.
optimistic_finalized_sync: true, optimistic_finalized_sync: true,
shuffling_cache_size: crate::shuffling_cache::DEFAULT_CACHE_SIZE, shuffling_cache_size: crate::shuffling_cache::DEFAULT_CACHE_SIZE,
snapshot_cache_size: crate::snapshot_cache::DEFAULT_SNAPSHOT_CACHE_SIZE,
genesis_backfill: false, genesis_backfill: false,
always_prepare_payload: false, always_prepare_payload: false,
progressive_balances_mode: ProgressiveBalancesMode::Fast, progressive_balances_mode: ProgressiveBalancesMode::Fast,

View File

@ -50,7 +50,7 @@ mod pre_finalization_cache;
pub mod proposer_prep_service; pub mod proposer_prep_service;
pub mod schema_change; pub mod schema_change;
pub mod shuffling_cache; pub mod shuffling_cache;
mod snapshot_cache; pub mod snapshot_cache;
pub mod state_advance_timer; pub mod state_advance_timer;
pub mod sync_committee_rewards; pub mod sync_committee_rewards;
pub mod sync_committee_verification; pub mod sync_committee_verification;

View File

@ -9,7 +9,7 @@ use types::{
}; };
/// The default size of the cache. /// The default size of the cache.
pub const DEFAULT_SNAPSHOT_CACHE_SIZE: usize = 4; pub const DEFAULT_SNAPSHOT_CACHE_SIZE: usize = 3;
/// The minimum block delay to clone the state in the cache instead of removing it. /// The minimum block delay to clone the state in the cache instead of removing it.
/// This helps keep block processing fast during re-orgs from late blocks. /// This helps keep block processing fast during re-orgs from late blocks.
@ -174,6 +174,7 @@ impl<T: EthSpec> SnapshotCache<T> {
self.snapshots.iter().map(|s| s.beacon_block_root).collect() self.snapshots.iter().map(|s| s.beacon_block_root).collect()
} }
#[allow(clippy::len_without_is_empty)]
/// The number of snapshots contained in `self`. /// The number of snapshots contained in `self`.
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.snapshots.len() self.snapshots.len()

View File

@ -622,6 +622,13 @@ pub fn cli_app<'a, 'b>() -> App<'a, 'b> {
.help("Specifies how many states from the freezer database should cache in memory [default: 1]") .help("Specifies how many states from the freezer database should cache in memory [default: 1]")
.takes_value(true) .takes_value(true)
) )
.arg(
Arg::with_name("state-cache-size")
.long("state-cache-size")
.value_name("STATE_CACHE_SIZE")
.help("Specifies the size of the snapshot cache [default: 3]")
.takes_value(true)
)
/* /*
* Execution Layer Integration * Execution Layer Integration
*/ */

View File

@ -170,6 +170,9 @@ pub fn get_config<E: EthSpec>(
if let Some(cache_size) = clap_utils::parse_optional(cli_args, "shuffling-cache-size")? { if let Some(cache_size) = clap_utils::parse_optional(cli_args, "shuffling-cache-size")? {
client_config.chain.shuffling_cache_size = cache_size; client_config.chain.shuffling_cache_size = cache_size;
} }
if let Some(cache_size) = clap_utils::parse_optional(cli_args, "state-cache-size")? {
client_config.chain.snapshot_cache_size = cache_size;
}
/* /*
* Prometheus metrics HTTP server * Prometheus metrics HTTP server

View File

@ -461,6 +461,9 @@ OPTIONS:
--slots-per-restore-point <SLOT_COUNT> --slots-per-restore-point <SLOT_COUNT>
Specifies how often a freezer DB restore point should be stored. Cannot be changed after initialization. Specifies how often a freezer DB restore point should be stored. Cannot be changed after initialization.
[default: 8192 (mainnet) or 64 (minimal)] [default: 8192 (mainnet) or 64 (minimal)]
--state-cache-size <STATE_CACHE_SIZE>
Specifies the size of the snapshot cache [default: 3]
--suggested-fee-recipient <SUGGESTED-FEE-RECIPIENT> --suggested-fee-recipient <SUGGESTED-FEE-RECIPIENT>
Emergency fallback fee recipient for use in case the validator client does not have one configured. You Emergency fallback fee recipient for use in case the validator client does not have one configured. You
should set this flag on the validator client instead of (or in addition to) setting it here. should set this flag on the validator client instead of (or in addition to) setting it here.

View File

@ -172,6 +172,26 @@ fn shuffling_cache_set() {
.with_config(|config| assert_eq!(config.chain.shuffling_cache_size, 500)); .with_config(|config| assert_eq!(config.chain.shuffling_cache_size, 500));
} }
#[test]
fn snapshot_cache_default() {
CommandLineTest::new()
.run_with_zero_port()
.with_config(|config| {
assert_eq!(
config.chain.snapshot_cache_size,
beacon_node::beacon_chain::snapshot_cache::DEFAULT_SNAPSHOT_CACHE_SIZE
)
});
}
#[test]
fn snapshot_cache_set() {
CommandLineTest::new()
.flag("state-cache-size", Some("500"))
.run_with_zero_port()
.with_config(|config| assert_eq!(config.chain.snapshot_cache_size, 500));
}
#[test] #[test]
fn fork_choice_before_proposal_timeout_default() { fn fork_choice_before_proposal_timeout_default() {
CommandLineTest::new() CommandLineTest::new()