solana_runtime/
snapshot_config.rs

1use {
2    crate::{
3        snapshot_bank_utils,
4        snapshot_utils::{self, ArchiveFormat, SnapshotVersion},
5    },
6    solana_sdk::clock::Slot,
7    std::{num::NonZeroUsize, path::PathBuf},
8};
9
10/// Snapshot configuration and runtime information
11#[derive(Clone, Debug)]
12pub struct SnapshotConfig {
13    /// Specifies the ways thats snapshots are allowed to be used
14    pub usage: SnapshotUsage,
15
16    /// Generate a new full snapshot archive every this many slots
17    pub full_snapshot_archive_interval_slots: Slot,
18
19    /// Generate a new incremental snapshot archive every this many slots
20    pub incremental_snapshot_archive_interval_slots: Slot,
21
22    /// Path to the directory where full snapshot archives are stored
23    pub full_snapshot_archives_dir: PathBuf,
24
25    /// Path to the directory where incremental snapshot archives are stored
26    pub incremental_snapshot_archives_dir: PathBuf,
27
28    /// Path to the directory where bank snapshots are stored
29    pub bank_snapshots_dir: PathBuf,
30
31    /// The archive format to use for snapshots
32    pub archive_format: ArchiveFormat,
33
34    /// Snapshot version to generate
35    pub snapshot_version: SnapshotVersion,
36
37    /// Maximum number of full snapshot archives to retain
38    pub maximum_full_snapshot_archives_to_retain: NonZeroUsize,
39
40    /// Maximum number of incremental snapshot archives to retain
41    /// NOTE: Incremental snapshots will only be kept for the latest full snapshot
42    pub maximum_incremental_snapshot_archives_to_retain: NonZeroUsize,
43
44    /// This is the `debug_verify` parameter to use when calling `update_accounts_hash()`
45    pub accounts_hash_debug_verify: bool,
46
47    // Thread niceness adjustment for snapshot packager service
48    pub packager_thread_niceness_adj: i8,
49}
50
51impl Default for SnapshotConfig {
52    fn default() -> Self {
53        Self {
54            usage: SnapshotUsage::LoadAndGenerate,
55            full_snapshot_archive_interval_slots:
56                snapshot_bank_utils::DEFAULT_FULL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS,
57            incremental_snapshot_archive_interval_slots:
58                snapshot_bank_utils::DEFAULT_INCREMENTAL_SNAPSHOT_ARCHIVE_INTERVAL_SLOTS,
59            full_snapshot_archives_dir: PathBuf::default(),
60            incremental_snapshot_archives_dir: PathBuf::default(),
61            bank_snapshots_dir: PathBuf::default(),
62            archive_format: ArchiveFormat::TarZstd,
63            snapshot_version: SnapshotVersion::default(),
64            maximum_full_snapshot_archives_to_retain:
65                snapshot_utils::DEFAULT_MAX_FULL_SNAPSHOT_ARCHIVES_TO_RETAIN,
66            maximum_incremental_snapshot_archives_to_retain:
67                snapshot_utils::DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
68            accounts_hash_debug_verify: false,
69            packager_thread_niceness_adj: 0,
70        }
71    }
72}
73
74impl SnapshotConfig {
75    /// A new snapshot config used for only loading at startup
76    #[must_use]
77    pub fn new_load_only() -> Self {
78        Self {
79            usage: SnapshotUsage::LoadOnly,
80            ..Self::default()
81        }
82    }
83
84    /// Should snapshots be generated?
85    #[must_use]
86    pub fn should_generate_snapshots(&self) -> bool {
87        self.usage == SnapshotUsage::LoadAndGenerate
88    }
89}
90
91/// Specify the ways that snapshots are allowed to be used
92#[derive(Debug, Clone, Eq, PartialEq)]
93pub enum SnapshotUsage {
94    /// Snapshots are only used at startup, to load the accounts and bank
95    LoadOnly,
96    /// Snapshots are used everywhere; both at startup (i.e. load) and steady-state (i.e.
97    /// generate).  This enables taking snapshots.
98    LoadAndGenerate,
99}