Skip to content

Commit

Permalink
Use Key type instead of Box<[u8]> (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Laine authored Feb 21, 2024
1 parent b7f000f commit 7786a89
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
7 changes: 2 additions & 5 deletions firewood/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub use crate::{
};
use crate::{
file,
merkle::{Bincode, Merkle, MerkleError, Node, Proof, ProofError, TrieHash, TRIE_HASH_LEN},
merkle::{Bincode, Key, Merkle, MerkleError, Node, Proof, ProofError, TrieHash, TRIE_HASH_LEN},
storage::{
buffer::{DiskBuffer, DiskBufferRequester},
CachedSpace, MemStoreR, SpaceWrite, StoreConfig, StoreDelta, StoreRevMut, StoreRevShared,
Expand Down Expand Up @@ -323,10 +323,7 @@ impl<S: ShaleStore<Node> + Send + Sync> DbRev<S> {
self.merkle.key_value_iter(self.header.kv_root)
}

pub fn stream_from(
&self,
start_key: Box<[u8]>,
) -> merkle::MerkleKeyValueStream<'_, S, Bincode> {
pub fn stream_from(&self, start_key: Key) -> merkle::MerkleKeyValueStream<'_, S, Bincode> {
self.merkle
.key_value_iter_from_key(self.header.kv_root, start_key)
}
Expand Down
4 changes: 2 additions & 2 deletions firewood/src/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type NodeObjRef<'a> = shale::ObjRef<'a, Node>;
type ParentRefs<'a> = Vec<(NodeObjRef<'a>, u8)>;
type ParentAddresses = Vec<(DiskAddress, u8)>;

type Key = Box<[u8]>;
pub type Key = Box<[u8]>;
type Value = Vec<u8>;

#[derive(Debug, Error)]
Expand Down Expand Up @@ -1381,7 +1381,7 @@ impl<S: ShaleStore<Node> + Send + Sync, T> Merkle<S, T> {
pub(crate) fn key_value_iter_from_key(
&self,
root: DiskAddress,
key: Box<[u8]>,
key: Key,
) -> MerkleKeyValueStream<'_, S, T> {
MerkleKeyValueStream::from_key(self, root, key)
}
Expand Down
4 changes: 2 additions & 2 deletions firewood/src/merkle/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl<'a, S: ShaleStore<Node> + Send + Sync, T> Stream for MerkleNodeStream<'a, S

// The child's key is its parent's key, followed by the child's index,
// followed by the child's partial path (if any).
let child_key: Box<[u8]> = key
let child_key: Key = key
.iter()
.copied()
.chain(once(pos))
Expand Down Expand Up @@ -599,7 +599,7 @@ mod tests {
pub(crate) fn node_iter_from(
&self,
root: DiskAddress,
key: Box<[u8]>,
key: Key,
) -> MerkleNodeStream<'_, S, T> {
MerkleNodeStream::new(self, root, key)
}
Expand Down
6 changes: 3 additions & 3 deletions fwdctl/src/dump.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright (C) 2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE.md for licensing terms.

use std::borrow::Cow;

use clap::Args;
use firewood::{
db::{Db, DbConfig, WalConfig},
merkle::Key,
v2::api::{self, Db as _},
};
use futures_util::StreamExt;
use log;
use std::borrow::Cow;

#[derive(Debug, Args)]
pub struct Options {
Expand All @@ -30,7 +30,7 @@ pub struct Options {
value_parser = key_parser,
help = "Start dumping from this key (inclusive)."
)]
pub start_key: Option<Box<[u8]>>,
pub start_key: Option<Key>,
}

pub(super) async fn run(opts: &Options) -> Result<(), api::Error> {
Expand Down

0 comments on commit 7786a89

Please sign in to comment.