solana_runtime/
snapshot_config.rs

1use {
2    crate::{
3        snapshot_bank_utils,
4        snapshot_utils::{self, ArchiveFormat, SnapshotVersion, ZstdConfig},
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                config: ZstdConfig::default(),
64            },
65            snapshot_version: SnapshotVersion::default(),
66            maximum_full_snapshot_archives_to_retain:
67                snapshot_utils::DEFAULT_MAX_FULL_SNAPSHOT_ARCHIVES_TO_RETAIN,
68            maximum_incremental_snapshot_archives_to_retain:
69                snapshot_utils::DEFAULT_MAX_INCREMENTAL_SNAPSHOT_ARCHIVES_TO_RETAIN,
70            accounts_hash_debug_verify: false,
71            packager_thread_niceness_adj: 0,
72        }
73    }
74}
75
76impl SnapshotConfig {
77    /// A new snapshot config used for only loading at startup
78    #[must_use]
79    pub fn new_load_only() -> Self {
80        Self {
81            usage: SnapshotUsage::LoadOnly,
82            ..Self::default()
83        }
84    }
85
86    /// Should snapshots be generated?
87    #[must_use]
88    pub fn should_generate_snapshots(&self) -> bool {
89        self.usage == SnapshotUsage::LoadAndGenerate
90    }
91}
92
93/// Specify the ways that snapshots are allowed to be used
94#[derive(Debug, Clone, Eq, PartialEq)]
95pub enum SnapshotUsage {
96    /// Snapshots are only used at startup, to load the accounts and bank
97    LoadOnly,
98    /// Snapshots are used everywhere; both at startup (i.e. load) and steady-state (i.e.
99    /// generate).  This enables taking snapshots.
100    LoadAndGenerate,
101}