solana_runtime/
snapshot_archive_info.rs1use {
4 crate::{
5 snapshot_hash::SnapshotHash,
6 snapshot_utils::{self, ArchiveFormat, Result},
7 },
8 solana_sdk::clock::Slot,
9 std::{cmp::Ordering, path::PathBuf},
10};
11
12pub trait SnapshotArchiveInfoGetter {
14 fn snapshot_archive_info(&self) -> &SnapshotArchiveInfo;
15
16 fn path(&self) -> &PathBuf {
17 &self.snapshot_archive_info().path
18 }
19
20 fn slot(&self) -> Slot {
21 self.snapshot_archive_info().slot
22 }
23
24 fn hash(&self) -> &SnapshotHash {
25 &self.snapshot_archive_info().hash
26 }
27
28 fn archive_format(&self) -> ArchiveFormat {
29 self.snapshot_archive_info().archive_format
30 }
31
32 fn is_remote(&self) -> bool {
33 self.snapshot_archive_info()
34 .path
35 .parent()
36 .map_or(false, |p| {
37 p.ends_with(snapshot_utils::SNAPSHOT_ARCHIVE_DOWNLOAD_DIR)
38 })
39 }
40}
41
42#[derive(PartialEq, Eq, Debug, Clone)]
44pub struct SnapshotArchiveInfo {
45 pub path: PathBuf,
47
48 pub slot: Slot,
50
51 pub hash: SnapshotHash,
53
54 pub archive_format: ArchiveFormat,
56}
57
58#[derive(PartialEq, Eq, Debug, Clone)]
60pub struct FullSnapshotArchiveInfo(SnapshotArchiveInfo);
61
62impl FullSnapshotArchiveInfo {
63 pub fn new_from_path(path: PathBuf) -> Result<Self> {
65 let filename = snapshot_utils::path_to_file_name_str(path.as_path())?;
66 let (slot, hash, archive_format) =
67 snapshot_utils::parse_full_snapshot_archive_filename(filename)?;
68
69 Ok(Self::new(SnapshotArchiveInfo {
70 path,
71 slot,
72 hash,
73 archive_format,
74 }))
75 }
76
77 pub(crate) fn new(snapshot_archive_info: SnapshotArchiveInfo) -> Self {
78 Self(snapshot_archive_info)
79 }
80}
81
82impl SnapshotArchiveInfoGetter for FullSnapshotArchiveInfo {
83 fn snapshot_archive_info(&self) -> &SnapshotArchiveInfo {
84 &self.0
85 }
86}
87
88impl PartialOrd for FullSnapshotArchiveInfo {
89 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
90 Some(self.cmp(other))
91 }
92}
93
94impl Ord for FullSnapshotArchiveInfo {
96 fn cmp(&self, other: &Self) -> Ordering {
97 self.slot().cmp(&other.slot())
98 }
99}
100
101#[derive(PartialEq, Eq, Debug, Clone)]
103pub struct IncrementalSnapshotArchiveInfo {
104 base_slot: Slot,
107
108 inner: SnapshotArchiveInfo,
111}
112
113impl IncrementalSnapshotArchiveInfo {
114 pub fn new_from_path(path: PathBuf) -> Result<Self> {
116 let filename = snapshot_utils::path_to_file_name_str(path.as_path())?;
117 let (base_slot, slot, hash, archive_format) =
118 snapshot_utils::parse_incremental_snapshot_archive_filename(filename)?;
119
120 Ok(Self::new(
121 base_slot,
122 SnapshotArchiveInfo {
123 path,
124 slot,
125 hash,
126 archive_format,
127 },
128 ))
129 }
130
131 pub(crate) fn new(base_slot: Slot, snapshot_archive_info: SnapshotArchiveInfo) -> Self {
132 Self {
133 base_slot,
134 inner: snapshot_archive_info,
135 }
136 }
137
138 pub fn base_slot(&self) -> Slot {
139 self.base_slot
140 }
141}
142
143impl SnapshotArchiveInfoGetter for IncrementalSnapshotArchiveInfo {
144 fn snapshot_archive_info(&self) -> &SnapshotArchiveInfo {
145 &self.inner
146 }
147}
148
149impl PartialOrd for IncrementalSnapshotArchiveInfo {
150 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
151 Some(self.cmp(other))
152 }
153}
154
155impl Ord for IncrementalSnapshotArchiveInfo {
158 fn cmp(&self, other: &Self) -> Ordering {
159 self.base_slot()
160 .cmp(&other.base_slot())
161 .then(self.slot().cmp(&other.slot()))
162 }
163}