use crate::{
key::{StableKey, StableKeyError},
ledger::LedgerPayloadEnvelopeError,
physical::CommitRecoveryError,
slot::MemoryManagerSlot,
};
#[non_exhaustive]
#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
pub enum LedgerIntegrityError {
#[error("ledger exceeds {resource} limit {limit}")]
LimitExceeded {
resource: &'static str,
limit: usize,
},
#[error("stable key '{stable_key}' appears in more than one allocation record")]
DuplicateStableKey { stable_key: StableKey },
#[error("allocation slot '{slot:?}' appears in more than one allocation record")]
DuplicateSlot { slot: MemoryManagerSlot },
#[error("genesis ledger contains allocation records")]
NonemptyGenesis,
}
#[non_exhaustive]
#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
pub enum LedgerCommitError {
#[error(transparent)]
Recovery(CommitRecoveryError),
#[error(transparent)]
PayloadEnvelope(LedgerPayloadEnvelopeError),
#[error(
"physical generation {physical_generation} does not match logical ledger generation {logical_generation}"
)]
PhysicalLogicalGenerationMismatch {
physical_generation: u64,
logical_generation: u64,
},
#[error("allocation ledger codec failed: {0}")]
Codec(String),
#[error(transparent)]
Integrity(LedgerIntegrityError),
}
#[non_exhaustive]
#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
pub enum AllocationStageError {
#[error("ledger generation {generation} cannot be advanced without overflow")]
GenerationOverflow { generation: u64 },
#[error(transparent)]
Integrity(#[from] LedgerIntegrityError),
#[error(
"validated allocations were produced at generation {validated_generation}, but ledger is at generation {ledger_generation}"
)]
StaleValidatedAllocations {
validated_generation: u64,
ledger_generation: u64,
},
#[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
StableKeySlotConflict {
stable_key: StableKey,
historical_slot: MemoryManagerSlot,
declared_slot: MemoryManagerSlot,
},
#[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
SlotStableKeyConflict {
slot: MemoryManagerSlot,
historical_key: StableKey,
declared_key: StableKey,
},
#[error("stable key '{stable_key}' was explicitly retired and cannot be redeclared")]
RetiredAllocation {
stable_key: StableKey,
slot: MemoryManagerSlot,
},
}
#[non_exhaustive]
#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
pub enum AllocationReservationError {
#[error(transparent)]
Integrity(#[from] LedgerIntegrityError),
#[error("ledger generation {generation} cannot be advanced without overflow")]
GenerationOverflow {
generation: u64,
},
#[error("generation contains {count} reservations, exceeding the 255-allocation limit")]
TooManyReservations {
count: usize,
},
#[error("stable key '{stable_key}' was historically bound to a different allocation slot")]
StableKeySlotConflict {
stable_key: StableKey,
historical_slot: MemoryManagerSlot,
reserved_slot: MemoryManagerSlot,
},
#[error("allocation slot '{slot:?}' was historically bound to stable key '{historical_key}'")]
SlotStableKeyConflict {
slot: MemoryManagerSlot,
historical_key: StableKey,
reserved_key: StableKey,
},
#[error("stable key '{stable_key}' is already active and cannot be reserved")]
ActiveAllocation {
stable_key: StableKey,
slot: MemoryManagerSlot,
},
#[error("stable key '{stable_key}' was explicitly retired and cannot be reserved")]
RetiredAllocation {
stable_key: StableKey,
slot: MemoryManagerSlot,
},
}
#[non_exhaustive]
#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
pub enum AllocationRetirementError {
#[error(transparent)]
Integrity(#[from] LedgerIntegrityError),
#[error(transparent)]
Key(StableKeyError),
#[error("ledger generation {generation} cannot be advanced without overflow")]
GenerationOverflow {
generation: u64,
},
#[error("stable key '{0}' has no allocation record to retire")]
UnknownStableKey(StableKey),
#[error("stable key '{stable_key}' cannot be retired for a different allocation slot")]
SlotMismatch {
stable_key: StableKey,
historical_slot: MemoryManagerSlot,
retired_slot: MemoryManagerSlot,
},
#[error("stable key '{stable_key}' was already retired")]
AlreadyRetired {
stable_key: StableKey,
slot: MemoryManagerSlot,
},
}