diff --git a/core/src/accounts_hash_verifier.rs b/core/src/accounts_hash_verifier.rs index 3448a71d7..bfc820aff 100644 --- a/core/src/accounts_hash_verifier.rs +++ b/core/src/accounts_hash_verifier.rs @@ -276,7 +276,9 @@ impl AccountsHashVerifier { ) { if accounts_package.snapshot_type.is_none() || pending_snapshot_package.is_none() - || snapshot_config.is_none() + || !snapshot_config + .map(|snapshot_config| snapshot_config.should_generate_snapshots()) + .unwrap_or(false) { return; }; diff --git a/ledger-tool/src/main.rs b/ledger-tool/src/main.rs index 29785620b..baaf6ec0e 100644 --- a/ledger-tool/src/main.rs +++ b/ledger-tool/src/main.rs @@ -946,12 +946,10 @@ fn load_bank_forks( } Some(SnapshotConfig { - full_snapshot_archive_interval_slots: Slot::MAX, - incremental_snapshot_archive_interval_slots: Slot::MAX, full_snapshot_archives_dir, incremental_snapshot_archives_dir, bank_snapshots_dir, - ..SnapshotConfig::default() + ..SnapshotConfig::new_load_only() }) }; diff --git a/local-cluster/src/local_cluster.rs b/local-cluster/src/local_cluster.rs index 6f2c619ab..1007dcc72 100644 --- a/local-cluster/src/local_cluster.rs +++ b/local-cluster/src/local_cluster.rs @@ -745,7 +745,7 @@ impl LocalCluster { incremental_snapshot_archive_interval_slots: Slot::MAX, full_snapshot_archives_dir: DUMMY_SNAPSHOT_CONFIG_PATH_MARKER.into(), bank_snapshots_dir: DUMMY_SNAPSHOT_CONFIG_PATH_MARKER.into(), - ..SnapshotConfig::default() + ..SnapshotConfig::new_load_only() } } } diff --git a/local-cluster/tests/common.rs b/local-cluster/tests/common.rs index 1e436ea60..8e7569a85 100644 --- a/local-cluster/tests/common.rs +++ b/local-cluster/tests/common.rs @@ -457,6 +457,7 @@ impl SnapshotValidatorConfig { ) -> SnapshotValidatorConfig { assert!(accounts_hash_interval_slots > 0); assert!(full_snapshot_archive_interval_slots > 0); + assert!(full_snapshot_archive_interval_slots != Slot::MAX); assert!(full_snapshot_archive_interval_slots % accounts_hash_interval_slots == 0); if incremental_snapshot_archive_interval_slots != Slot::MAX { assert!(incremental_snapshot_archive_interval_slots > 0); diff --git a/runtime/src/snapshot_config.rs b/runtime/src/snapshot_config.rs index 07c1def31..e98cedb88 100644 --- a/runtime/src/snapshot_config.rs +++ b/runtime/src/snapshot_config.rs @@ -7,6 +7,9 @@ use { /// Snapshot configuration and runtime information #[derive(Clone, Debug)] pub struct SnapshotConfig { + /// Specifies the ways thats snapshots are allowed to be used + pub usage: SnapshotUsage, + /// Generate a new full snapshot archive every this many slots pub full_snapshot_archive_interval_slots: Slot, @@ -45,6 +48,7 @@ pub struct SnapshotConfig { impl Default for SnapshotConfig { fn default() -> Self { Self { + usage: SnapshotUsage::LoadAndGenerate, full_snapshot_archive_interval_slots: snapshot_utils::DEFAULT_FULL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS, incremental_snapshot_archive_interval_slots: @@ -63,3 +67,30 @@ impl Default for SnapshotConfig { } } } + +impl SnapshotConfig { + /// A new snapshot config used for only loading at startup + #[must_use] + pub fn new_load_only() -> Self { + Self { + usage: SnapshotUsage::LoadOnly, + ..Self::default() + } + } + + /// Should snapshots be generated? + #[must_use] + pub fn should_generate_snapshots(&self) -> bool { + self.usage == SnapshotUsage::LoadAndGenerate + } +} + +/// Specify the ways that snapshots are allowed to be used +#[derive(Debug, Clone, Eq, PartialEq)] +pub enum SnapshotUsage { + /// Snapshots are only used at startup, to load the accounts and bank + LoadOnly, + /// Snapshots are used everywhere; both at startup (i.e. load) and steady-state (i.e. + /// generate). This enables taking snapshots. + LoadAndGenerate, +} diff --git a/validator/src/main.rs b/validator/src/main.rs index 630bc4ff7..5cd04830c 100644 --- a/validator/src/main.rs +++ b/validator/src/main.rs @@ -50,7 +50,7 @@ use { }, hardened_unpack::MAX_GENESIS_ARCHIVE_UNPACKED_SIZE, runtime_config::RuntimeConfig, - snapshot_config::SnapshotConfig, + snapshot_config::{SnapshotConfig, SnapshotUsage}, snapshot_utils::{ self, ArchiveFormat, SnapshotVersion, DEFAULT_ARCHIVE_COMPRESSION, DEFAULT_FULL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS, @@ -2929,6 +2929,11 @@ pub fn main() { }; validator_config.snapshot_config = Some(SnapshotConfig { + usage: if full_snapshot_archive_interval_slots == Slot::MAX { + SnapshotUsage::LoadOnly + } else { + SnapshotUsage::LoadAndGenerate + }, full_snapshot_archive_interval_slots, incremental_snapshot_archive_interval_slots, bank_snapshots_dir,