chore: storage -> store
This commit is contained in:
parent
8cb245dc1f
commit
17eb8d78d3
3 changed files with 12 additions and 12 deletions
|
@ -71,8 +71,8 @@ impl fmt::Display for MerkleError {
|
||||||
InvalidPath(_path) => write!(f, "the provided path is not valid"),
|
InvalidPath(_path) => write!(f, "the provided path is not valid"),
|
||||||
InvalidEntriesCount(max, provided) => write!(f, "the provided number of entries is {provided}, but the maximum for the given depth is {max}"),
|
InvalidEntriesCount(max, provided) => write!(f, "the provided number of entries is {provided}, but the maximum for the given depth is {max}"),
|
||||||
NodeNotInSet(index) => write!(f, "the node indexed by {index} is not in the set"),
|
NodeNotInSet(index) => write!(f, "the node indexed by {index} is not in the set"),
|
||||||
NodeNotInStore(hash, index) => write!(f, "the node {:?} indexed by {} and depth {} is not in the storage", hash, index.value(), index.depth(),),
|
NodeNotInStore(hash, index) => write!(f, "the node {:?} indexed by {} and depth {} is not in the store", hash, index.value(), index.depth(),),
|
||||||
RootNotInStore(root) => write!(f, "the root {:?} is not in the storage", root),
|
RootNotInStore(root) => write!(f, "the root {:?} is not in the store", root),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,12 +92,12 @@ impl MerkleStore {
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// This method can return the following errors:
|
/// This method can return the following errors:
|
||||||
/// - `RootNotInStore` if the `root` is not present in the storage.
|
/// - `RootNotInStore` if the `root` is not present in the store.
|
||||||
/// - `NodeNotInStore` if a node needed to traverse from `root` to `index` is not present in the store.
|
/// - `NodeNotInStore` if a node needed to traverse from `root` to `index` is not present in the store.
|
||||||
pub fn get_node(&self, root: Word, index: NodeIndex) -> Result<Word, MerkleError> {
|
pub fn get_node(&self, root: Word, index: NodeIndex) -> Result<Word, MerkleError> {
|
||||||
let mut hash: RpoDigest = root.into();
|
let mut hash: RpoDigest = root.into();
|
||||||
|
|
||||||
// corner case: check the root is in the storage when called with index `NodeIndex::root()`
|
// corner case: check the root is in the store when called with index `NodeIndex::root()`
|
||||||
self.nodes
|
self.nodes
|
||||||
.get(&hash)
|
.get(&hash)
|
||||||
.ok_or(MerkleError::RootNotInStore(hash.into()))?;
|
.ok_or(MerkleError::RootNotInStore(hash.into()))?;
|
||||||
|
@ -120,7 +120,7 @@ impl MerkleStore {
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// This method can return the following errors:
|
/// This method can return the following errors:
|
||||||
/// - `RootNotInStore` if the `root` is not present in the storage.
|
/// - `RootNotInStore` if the `root` is not present in the store.
|
||||||
/// - `NodeNotInStore` if a node needed to traverse from `root` to `index` is not present in the store.
|
/// - `NodeNotInStore` if a node needed to traverse from `root` to `index` is not present in the store.
|
||||||
pub fn get_path(
|
pub fn get_path(
|
||||||
&self,
|
&self,
|
||||||
|
@ -130,7 +130,7 @@ impl MerkleStore {
|
||||||
let mut hash: RpoDigest = root.into();
|
let mut hash: RpoDigest = root.into();
|
||||||
let mut path = Vec::with_capacity(index.depth().into());
|
let mut path = Vec::with_capacity(index.depth().into());
|
||||||
|
|
||||||
// corner case: check the root is in the storage when called with index `NodeIndex::root()`
|
// corner case: check the root is in the store when called with index `NodeIndex::root()`
|
||||||
self.nodes
|
self.nodes
|
||||||
.get(&hash)
|
.get(&hash)
|
||||||
.ok_or(MerkleError::RootNotInStore(hash.into()))?;
|
.ok_or(MerkleError::RootNotInStore(hash.into()))?;
|
||||||
|
@ -160,7 +160,7 @@ impl MerkleStore {
|
||||||
/// Adds all the nodes of a Merkle tree represented by `leaves`.
|
/// Adds all the nodes of a Merkle tree represented by `leaves`.
|
||||||
///
|
///
|
||||||
/// This will instantiate a Merkle tree using `leaves` and include all the nodes into the
|
/// This will instantiate a Merkle tree using `leaves` and include all the nodes into the
|
||||||
/// storage.
|
/// store.
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
|
@ -208,7 +208,7 @@ impl MerkleStore {
|
||||||
/// Adds all the nodes of a Sparse Merkle tree represented by `entries`.
|
/// Adds all the nodes of a Sparse Merkle tree represented by `entries`.
|
||||||
///
|
///
|
||||||
/// This will instantiate a Sparse Merkle tree using `entries` and include all the nodes into
|
/// This will instantiate a Sparse Merkle tree using `entries` and include all the nodes into
|
||||||
/// the storage.
|
/// the store.
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
|
@ -236,7 +236,7 @@ impl MerkleStore {
|
||||||
/// Adds all the nodes of a Merkle path represented by `path`.
|
/// Adds all the nodes of a Merkle path represented by `path`.
|
||||||
///
|
///
|
||||||
/// This will compute the sibling elements determined by the Merkle `path` and `node`, and
|
/// This will compute the sibling elements determined by the Merkle `path` and `node`, and
|
||||||
/// include all the nodes into the storage.
|
/// include all the nodes into the store.
|
||||||
pub fn add_merkle_path(
|
pub fn add_merkle_path(
|
||||||
&mut self,
|
&mut self,
|
||||||
index_value: u64,
|
index_value: u64,
|
||||||
|
@ -270,7 +270,7 @@ impl MerkleStore {
|
||||||
/// Adds all the nodes of multiple Merkle paths into the store.
|
/// Adds all the nodes of multiple Merkle paths into the store.
|
||||||
///
|
///
|
||||||
/// This will compute the sibling elements for each Merkle `path` and include all the nodes
|
/// This will compute the sibling elements for each Merkle `path` and include all the nodes
|
||||||
/// into the storage.
|
/// into the store.
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
|
@ -315,7 +315,7 @@ impl MerkleStore {
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// This method can return the following errors:
|
/// This method can return the following errors:
|
||||||
/// - `RootNotInStore` if the `root` is not present in the storage.
|
/// - `RootNotInStore` if the `root` is not present in the store.
|
||||||
/// - `NodeNotInStore` if a node needed to traverse from `root` to `index` is not present in the store.
|
/// - `NodeNotInStore` if a node needed to traverse from `root` to `index` is not present in the store.
|
||||||
pub fn set_node(
|
pub fn set_node(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
|
@ -14,7 +14,7 @@ const LEAVES4: [Word; 4] = [
|
||||||
];
|
];
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_root_not_in_storage() -> Result<(), MerkleError> {
|
fn test_root_not_in_store() -> Result<(), MerkleError> {
|
||||||
let mtree = MerkleTree::new(LEAVES4.to_vec())?;
|
let mtree = MerkleTree::new(LEAVES4.to_vec())?;
|
||||||
let store = MerkleStore::default().with_merkle_tree(LEAVES4)?;
|
let store = MerkleStore::default().with_merkle_tree(LEAVES4)?;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
Loading…
Add table
Reference in a new issue