Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions crates/floresta-chain/src/pruned_utreexo/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use rustreexo::stump::StumpError;
use crate::proof_util::UtreexoLeafError;
use crate::pruned_utreexo::chain_state_builder::BlockchainBuilderError;

pub trait DatabaseError: Debug + Send + Sync + 'static {}
pub trait DatabaseError: Debug + Display + Send + Sync + 'static {}
#[derive(Debug)]
/// This is the highest level error type in floresta-chain, returned by the [crate::ChainState] methods.
/// It represents errors encountered during blockchain validation.
Expand Down Expand Up @@ -203,7 +203,29 @@ impl_error_from!(BlockchainError, StumpError, UtreexoError);

impl Display for BlockchainError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{self:?}")
match self {
BlockchainError::BlockNotPresent => write!(f, "Block not found in the chain"),
BlockchainError::OrphanOrInvalidBlock => {
write!(f, "Block is either orphan or invalid")
}
BlockchainError::Parsing(msg) => write!(f, "Parsing error: {msg}"),
BlockchainError::BlockValidation(e) => write!(f, "Block validation failed: {e}"),
BlockchainError::TransactionError(e) => write!(f, "{e}"),
BlockchainError::InvalidProof => write!(f, "Invalid Utreexo proof"),
BlockchainError::UtreexoError(e) => write!(f, "Utreexo accumulator error: {e:?}"),
BlockchainError::UtreexoLeaf(e) => write!(f, "Utreexo leaf error: {e}"),
BlockchainError::Database(e) => write!(f, "Database error: {e}"),
BlockchainError::ConsensusDecode(e) => write!(f, "Consensus decoding error: {e}"),
BlockchainError::ChainNotInitialized => write!(f, "Chain is not initialized"),
BlockchainError::InvalidTip(msg) => write!(f, "Invalid chain tip: {msg}"),
BlockchainError::Io(e) => write!(f, "I/O error: {e}"),
BlockchainError::UnsupportedNetwork(net) => {
write!(f, "Unsupported network: {net}")
}
BlockchainError::BadValidationIndex => {
write!(f, "Validation index is out of range")
}
}
}
}

Expand Down
36 changes: 36 additions & 0 deletions crates/floresta-chain/src/pruned_utreexo/flat_chain_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@

extern crate std;

use core::fmt;
use core::fmt::Display;
use core::fmt::Formatter;
use core::mem::size_of;
use core::num::NonZeroUsize;
use std::fs::DirBuilder;
Expand Down Expand Up @@ -384,6 +387,39 @@ pub enum FlatChainstoreError {
InvalidValidationIndex,
}

impl Display for FlatChainstoreError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
FlatChainstoreError::Io(e) => write!(f, "I/O error: {e}"),
FlatChainstoreError::BlockNotFound => write!(f, "Block not found"),
FlatChainstoreError::IndexIsFull => {
write!(f, "Index is full, cannot add more blocks")
}
FlatChainstoreError::DbTooNew(v) => {
write!(f, "Database has unsupported version {v}")
}
FlatChainstoreError::Poisoned => write!(f, "Cache lock is poisoned"),
FlatChainstoreError::InvalidMagic(m) => {
write!(f, "Invalid magic value {m:#x}, possibly database corruption")
}
FlatChainstoreError::AccumulatorTooBig => {
write!(f, "The provided accumulator is too big")
}
FlatChainstoreError::IndexTooBig => {
write!(f, "Tried to create an index longer than 31 bits")
}
FlatChainstoreError::InvalidMetadataPointer => {
write!(f, "Invalid metadata file mmap pointer")
}
FlatChainstoreError::DbCorrupted => write!(f, "Database is corrupted"),
FlatChainstoreError::InvalidValidationIndex => write!(
f,
"Validation index has no height (likely in a fork or invalid chain)"
),
}
}
}

/// Need this to use [FlatChainstoreError] as a [DatabaseError] in [ChainStore]
impl DatabaseError for FlatChainstoreError {}

Expand Down
9 changes: 8 additions & 1 deletion crates/floresta-compact-filters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@ impl From<std::io::Error> for IterableFilterStoreError {

impl Display for IterableFilterStoreError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
Debug::fmt(self, f)
match self {
IterableFilterStoreError::Io(e) => write!(f, "I/O error: {e}"),
IterableFilterStoreError::Eof => write!(f, "Unexpected end of file"),
IterableFilterStoreError::Poisoned => write!(f, "Lock poisoned"),
IterableFilterStoreError::FilterTooLarge => {
write!(f, "Filter exceeds maximum allowed size")
}
}
}
}

Expand Down