Skip to content

Commit

Permalink
Remove MerkleError and DbError (#811)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkuris authored Mar 6, 2025
1 parent ecbb627 commit 59e22db
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 160 deletions.
15 changes: 6 additions & 9 deletions firewood/src/db.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (C) 2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE.md for licensing terms.

use crate::merkle::{Merkle, MerkleError};
use crate::merkle::Merkle;
use crate::proof::{Proof, ProofNode};
use crate::range_proof::RangeProof;
use crate::stream::MerkleKeyValueStream;
Expand All @@ -23,16 +23,13 @@ use typed_builder::TypedBuilder;
#[non_exhaustive]
/// Represents the different types of errors that can occur in the database.
pub enum DbError {
/// Merkle error occurred.
Merkle(MerkleError),
/// I/O error occurred.
IO(std::io::Error),
}

impl fmt::Display for DbError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
DbError::Merkle(e) => write!(f, "merkle error: {e:?}"),
DbError::IO(e) => write!(f, "I/O error: {e:?}"),
}
}
Expand Down Expand Up @@ -69,7 +66,7 @@ pub trait DbViewSync {
impl DbViewSync for HistoricalRev {
fn val_sync<K: KeyType>(&self, key: K) -> Result<Option<Box<[u8]>>, DbError> {
let merkle = Merkle::from(self);
let value = merkle.get_value(key.as_ref()).map_err(DbError::Merkle)?;
let value = merkle.get_value(key.as_ref())?;
Ok(value)
}
}
Expand Down Expand Up @@ -312,21 +309,21 @@ impl Db {
}

/// Dump the Trie of the latest revision.
pub async fn dump(&self, w: &mut dyn Write) -> Result<(), DbError> {
pub async fn dump(&self, w: &mut dyn Write) -> Result<(), std::io::Error> {
self.dump_sync(w)
}

/// Dump the Trie of the latest revision, synchronously.
pub fn dump_sync(&self, w: &mut dyn Write) -> Result<(), DbError> {
pub fn dump_sync(&self, w: &mut dyn Write) -> Result<(), std::io::Error> {
let latest_rev_nodestore = self
.manager
.read()
.expect("poisoned lock")
.current_revision();
let merkle = Merkle::from(latest_rev_nodestore);
// TODO: This should be a stream
let output = merkle.dump().map_err(DbError::Merkle)?;
write!(w, "{}", output).map_err(DbError::IO)
let output = merkle.dump()?;
write!(w, "{}", output)
}

/// Get a copy of the database metrics
Expand Down
Loading

0 comments on commit 59e22db

Please sign in to comment.