1use crate::{
2 key::{StableKey, StableKeyError},
3 ledger::LedgerPayloadEnvelopeError,
4 physical::CommitRecoveryError,
5 slot::MemoryManagerSlot,
6};
7
8#[non_exhaustive]
15#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
16pub enum LedgerIntegrityError {
17 #[error("ledger exceeds {resource} limit {limit}")]
19 LimitExceeded {
20 resource: &'static str,
21 limit: usize,
22 },
23 #[error("stable key '{stable_key}' appears in more than one allocation record")]
25 DuplicateStableKey { stable_key: StableKey },
26 #[error("allocation slot '{slot:?}' appears in more than one allocation record")]
28 DuplicateSlot { slot: MemoryManagerSlot },
29 #[error("genesis ledger contains allocation records")]
31 NonemptyGenesis,
32}
33
34#[non_exhaustive]
39#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
40pub enum LedgerCommitError {
41 #[error(transparent)]
43 Recovery(CommitRecoveryError),
44 #[error(transparent)]
46 PayloadEnvelope(LedgerPayloadEnvelopeError),
47 #[error(
49 "physical generation {physical_generation} does not match logical ledger generation {logical_generation}"
50 )]
51 PhysicalLogicalGenerationMismatch {
52 physical_generation: u64,
54 logical_generation: u64,
56 },
57 #[error("allocation ledger codec failed: {0}")]
59 Codec(String),
60 #[error(transparent)]
62 Integrity(LedgerIntegrityError),
63}
64
65#[non_exhaustive]
72#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
73pub enum AllocationStageError {
74 #[error("ledger generation {generation} cannot be advanced without overflow")]
76 GenerationOverflow { generation: u64 },
77 #[error(transparent)]
78 Integrity(#[from] LedgerIntegrityError),
79 #[error(
81 "validated allocations were produced at generation {validated_generation}, but ledger is at generation {ledger_generation}"
82 )]
83 StaleValidatedAllocations {
84 validated_generation: u64,
86 ledger_generation: u64,
88 },
89 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
91 StableKeySlotConflict {
92 stable_key: StableKey,
94 historical_slot: MemoryManagerSlot,
96 declared_slot: MemoryManagerSlot,
98 },
99 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
101 SlotStableKeyConflict {
102 slot: MemoryManagerSlot,
104 historical_key: StableKey,
106 declared_key: StableKey,
108 },
109 #[error("stable key '{stable_key}' was explicitly retired and cannot be redeclared")]
111 RetiredAllocation {
112 stable_key: StableKey,
114 slot: MemoryManagerSlot,
116 },
117}
118
119#[non_exhaustive]
124#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
125pub enum AllocationReservationError {
126 #[error(transparent)]
127 Integrity(#[from] LedgerIntegrityError),
128 #[error("ledger generation {generation} cannot be advanced without overflow")]
130 GenerationOverflow {
131 generation: u64,
133 },
134 #[error("generation contains {count} reservations, exceeding the 255-allocation limit")]
136 TooManyReservations {
137 count: usize,
139 },
140 #[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
142 StableKeySlotConflict {
143 stable_key: StableKey,
145 historical_slot: MemoryManagerSlot,
147 reserved_slot: MemoryManagerSlot,
149 },
150 #[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
152 SlotStableKeyConflict {
153 slot: MemoryManagerSlot,
155 historical_key: StableKey,
157 reserved_key: StableKey,
159 },
160 #[error("stable key '{stable_key}' is already active and cannot be reserved")]
162 ActiveAllocation {
163 stable_key: StableKey,
165 slot: MemoryManagerSlot,
167 },
168 #[error("stable key '{stable_key}' was explicitly retired and cannot be reserved")]
170 RetiredAllocation {
171 stable_key: StableKey,
173 slot: MemoryManagerSlot,
175 },
176}
177
178#[non_exhaustive]
183#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
184pub enum AllocationRetirementError {
185 #[error(transparent)]
186 Integrity(#[from] LedgerIntegrityError),
187 #[error(transparent)]
189 Key(StableKeyError),
190 #[error("ledger generation {generation} cannot be advanced without overflow")]
192 GenerationOverflow {
193 generation: u64,
195 },
196 #[error("stable key '{0}' has no allocation record to retire")]
198 UnknownStableKey(StableKey),
199 #[error("stable key '{stable_key}' cannot be retired for a different allocation slot")]
201 SlotMismatch {
202 stable_key: StableKey,
204 historical_slot: MemoryManagerSlot,
206 retired_slot: MemoryManagerSlot,
208 },
209 #[error("stable key '{stable_key}' was already retired")]
211 AlreadyRetired {
212 stable_key: StableKey,
214 slot: MemoryManagerSlot,
216 },
217}