Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement merkle.remove #644

Merged
merged 77 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
bb6c63c
WIP handle node movement upon update in insert
May 9, 2024
f18ad1b
WIP handle node movement upon update in insert
May 9, 2024
b3c377e
WIP handle node movement upon update in insert
May 9, 2024
c244e84
WIP handle node movement upon update in insert
May 9, 2024
6a502aa
WIP handle node movement upon update in insert
May 9, 2024
1d95fe9
WIP handle node movement upon update in insert
May 9, 2024
73ceb2c
WIP handle node movement upon update in insert
May 9, 2024
61cd68d
WIP handle node movement upon update in insert
May 9, 2024
1d55548
WIP handle node movement upon update in insert
May 10, 2024
0b42b5b
WIP handle node movement upon update in insert
May 10, 2024
8b9a734
WIP handle node movement upon update in insert
May 10, 2024
c8ac0d0
WIP handle node movement upon update in insert
May 10, 2024
e9b3f6f
WIP handle node movement upon update in insert
May 10, 2024
040ee97
WIP handle node movement upon update in insert
May 10, 2024
7c39c59
Merge branch 'remove-shale' into remove-shale-insert-handle-move
May 10, 2024
5ff2ba2
merge
May 10, 2024
ff7e146
make ancestors a DoubleEndedIterator so we don't have to rev() the tr…
May 10, 2024
4b0de0c
use split_first() to handle getting next key nibble
May 10, 2024
51cfe7b
bug fix; use split_first() to handle getting next key nibble
May 10, 2024
b98dbf2
cleaunp
May 10, 2024
c0d60ad
implement child helper on BranchNode
May 10, 2024
0880c23
nit rename mut_child to child_mut
May 10, 2024
a10872b
change ancestor update logic
May 10, 2024
6da5717
re-add TODO
May 10, 2024
bbe321d
comment nit
May 13, 2024
33f2641
remove insert_and_return_ancestors
May 13, 2024
5e15608
WIP handle node movement upon update in insert
May 13, 2024
2383226
WIP handle node movement upon update in insert
May 13, 2024
2de7402
cleanup
May 13, 2024
78e8e08
cleanup
May 13, 2024
20eaac4
cleanup
May 13, 2024
3bca02b
cleanup
May 13, 2024
4d5a206
clean up traversal_path
May 13, 2024
df06e05
renames
May 13, 2024
e40c5cd
cleanup
May 13, 2024
6aba160
cleanup
May 13, 2024
9b1cd5b
cleanup
May 13, 2024
15e8b43
cleanup
May 13, 2024
57869ac
cleanup
May 13, 2024
4ef2495
cleanup
May 13, 2024
446cf76
cleanup
May 13, 2024
78851da
cleanup
May 13, 2024
5dc7477
cleanup
May 13, 2024
e3a0017
comment nits
May 14, 2024
4e71a84
Merge remote-tracking branch 'origin/remove-shale' into remove-shale-…
May 14, 2024
c704ac4
nits
May 14, 2024
c0dcd42
Merge branch 'remove-shale' into remove-shale-insert-handle-move
May 14, 2024
21a9e06
WIP implement remove. Allow nodestore's root to be set to None.
May 14, 2024
d9e4e6a
WIP implement remove. Uncomment test remove_one
May 14, 2024
146f05f
WIP implement remove
May 14, 2024
0d43fa6
remove unused method
May 14, 2024
15f5ab4
combine iterator usages into 1
May 15, 2024
a978e8d
cleanup
May 15, 2024
4a2ee4f
add to test
May 15, 2024
ea5fda6
WIP fix leaf removal
May 15, 2024
4f954b8
WIP fix leaf removal
May 15, 2024
4eb6d58
WIP fix leaf removal
May 15, 2024
bdb659f
uncomment removal test
May 15, 2024
bef03ed
appease clippy
May 15, 2024
b135240
Merge remote-tracking branch 'origin/remove-shale' into remove-shale-…
May 16, 2024
cc19ed4
remove unneeded calls to from_nibbles_iterator
May 16, 2024
4f17a29
Merge branch 'remove-shale-insert-handle-move' into remove-shale-impl…
May 16, 2024
ea0e143
typo fix
May 16, 2024
f3b1299
appease clippy
May 16, 2024
e3b8d43
change remove implementation
May 16, 2024
b951dc4
Merge branch 'remove-shale' into remove-shale-insert-handle-move
May 16, 2024
940c164
Merge branch 'remove-shale' into remove-shale-insert-handle-move
May 16, 2024
46a1542
Merge branch 'remove-shale-insert-handle-move' into remove-shale-impl…
May 16, 2024
e843730
Merge branch 'remove-shale' into remove-shale-insert-handle-move
May 17, 2024
dcd5959
Merge branch 'remove-shale' into remove-shale-insert-handle-move
May 21, 2024
da72c19
Merge branch 'remove-shale-insert-handle-move' into remove-shale-impl…
May 21, 2024
ac11dce
fix test
May 21, 2024
00ea8db
fix insertion by cleaning up content at old child address (#654)
May 21, 2024
6e9a04f
Merge branch 'remove-shale-insert-handle-move' into remove-shale-impl…
May 21, 2024
c406a72
fix merge
May 21, 2024
f60851b
Code review comments
rkuris May 22, 2024
a976cea
Merge branch 'remove-shale' into remove-shale-implement-remove
May 22, 2024
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
16 changes: 11 additions & 5 deletions firewood/src/hashednode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ impl<T: ReadLinearStore> From<NodeStore<T>> for HashedNodeStore<T> {

impl<T: ReadLinearStore> HashedNodeStore<T> {
pub fn read_node(&self, addr: LinearAddress) -> Result<Arc<Node>, Error> {
if let Some(modified_node) = self.modified.get(&addr) {
Ok(modified_node.0.clone())
if let Some((modified_node, _)) = self.modified.get(&addr) {
Ok(modified_node.clone())
} else {
Ok(self.nodestore.read_node(addr)?)
}
Expand Down Expand Up @@ -158,6 +158,7 @@ impl<T: WriteLinearStore> HashedNodeStore<T> {
Node::Leaf(_) => Ok(self.hash_internal(node, path_prefix)),
}
}

pub fn freeze(mut self) -> Result<HashedNodeStore<ProposedImmutable>, Error> {
// fill in all remaining hashes, including the root hash
if let Some(root_address) = self.root_address() {
Expand All @@ -174,12 +175,17 @@ impl<T: WriteLinearStore> HashedNodeStore<T> {
root_hash: Default::default(),
})
}

pub fn create_node(&mut self, node: Node) -> Result<LinearAddress, Error> {
let (addr, size) = self.nodestore.allocate_node(&node)?;
self.modified.insert(addr, (Arc::new(node), size));
Ok(addr)
}

pub fn delete_node(&mut self, addr: LinearAddress) -> Result<(), Error> {
self.nodestore.delete_node(addr)
}

/// Fixes the trie after a node is updated.
/// When a node is updated, it might move to a different LinearAddress.
/// If it does, we need to update its parent so that it points to the
Expand All @@ -199,7 +205,7 @@ impl<T: WriteLinearStore> HashedNodeStore<T> {
new_addr: LinearAddress,
) -> Result<(), MerkleError> {
let Some(parent) = ancestors.next_back() else {
self.set_root(new_addr)?;
self.set_root(Some(new_addr))?;
return Ok(());
};

Expand Down Expand Up @@ -285,7 +291,7 @@ impl<T: WriteLinearStore> HashedNodeStore<T> {
Ok(new_address)
}

pub fn set_root(&mut self, root_addr: LinearAddress) -> Result<(), Error> {
pub fn set_root(&mut self, root_addr: Option<LinearAddress>) -> Result<(), Error> {
self.nodestore.set_root(root_addr)
}
}
Expand Down Expand Up @@ -424,7 +430,7 @@ mod test {
value: Box::new(*b"abc"),
});
let addr = hns.create_node(node).unwrap();
hns.set_root(addr).unwrap();
hns.set_root(Some(addr)).unwrap();

let frozen = hns.freeze().unwrap();
assert_ne!(frozen.root_hash().unwrap(), Default::default());
Expand Down
Loading
Loading