Skip to content

Commit

Permalink
Remove version checks and so on
Browse files Browse the repository at this point in the history
- Remove version checks in hamt
- CHange HashKey to HashPrefix
  • Loading branch information
appcypher committed Dec 21, 2022
1 parent 42266cc commit 22622fa
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 166 deletions.
7 changes: 2 additions & 5 deletions wnfs/src/common/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,8 @@ pub enum FsError {
#[error("Cannot find shard for file content")]
FileShardNotFound,

#[error("The hashkey index is out of bounds")]
InvalidHashKeyIndex,

#[error("HAMT versions don't match")]
HamtVersionMismatch,
#[error("The hashprefix index is out of bounds")]
InvalidHashPrefixIndex,

#[error("Key does not exist in HAMT")]
KeyNotFoundInHamt,
Expand Down
30 changes: 13 additions & 17 deletions wnfs/src/private/forest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use super::{
namefilter::Namefilter,
Key, PrivateNode, PrivateRef,
};
use crate::{error, utils::UnwrapOrClone, BlockStore, FsError, HashOutput, Hasher, Link};
use crate::{utils::UnwrapOrClone, BlockStore, HashOutput, Hasher, Link};
use anyhow::Result;
use libipld::Cid;
use log::debug;
Expand Down Expand Up @@ -369,22 +369,18 @@ where
/// }
/// ```
pub async fn merge<B: BlockStore>(&self, other: &Self, store: &mut B) -> Result<Self> {
if self.version == other.version {
let merge_node = hamt::merge(
Link::from(Rc::clone(&self.root)),
Link::from(Rc::clone(&other.root)),
|a, b| Ok(a.union(b).cloned().collect()),
store,
)
.await?;

return Ok(Self {
version: self.version.clone(),
root: merge_node,
});
}

error(FsError::HamtVersionMismatch)
let merge_node = hamt::merge(
Link::from(Rc::clone(&self.root)),
Link::from(Rc::clone(&other.root)),
|a, b| Ok(a.union(b).cloned().collect()),
store,
)
.await?;

Ok(Self {
version: self.version.clone(),
root: merge_node,
})
}
}

Expand Down
8 changes: 4 additions & 4 deletions wnfs/src/private/hamt/diff/key_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ where
for change in node_changes {
match change.r#type {
ChangeType::Add => {
let result = main_node.get_node_at(&change.hashkey, store).await?;
let result = main_node.get_node_at(&change.hashprefix, store).await?;
kv_changes
.extend(generate_add_or_remove_changes(result, ChangeType::Add, store).await?);
}
ChangeType::Remove => {
let result = other_node.get_node_at(&change.hashkey, store).await?;
let result = other_node.get_node_at(&change.hashprefix, store).await?;
kv_changes.extend(
generate_add_or_remove_changes(result, ChangeType::Remove, store).await?,
);
}
ChangeType::Modify => match (
main_node.get_node_at(&change.hashkey, store).await?,
other_node.get_node_at(&change.hashkey, store).await?,
main_node.get_node_at(&change.hashprefix, store).await?,
other_node.get_node_at(&change.hashprefix, store).await?,
) {
(Some(Left(main_pair)), Some(Left(other_pair))) => {
kv_changes.push(KeyValueChange {
Expand Down
Loading

0 comments on commit 22622fa

Please sign in to comment.