-
Notifications
You must be signed in to change notification settings - Fork 9
Enable writing of intermediate nodes #135
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
base: main
Are you sure you want to change the base?
Conversation
🟡 Heimdall Review Status
|
}); | ||
} else { | ||
// None value means deletion, skip | ||
return None; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll probably need to track explicit deletions here, so that this can be applied when merging with the on-disk nodes.
new_children[i] = Some(ptr); | ||
} | ||
(Some(d_ptr), None) => { | ||
// Only on-disk: keep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted above, we'll need to be able to merge in deletions from the in-memory trie.
|
||
/// Converts a Node to an InMemoryNode for writing to disk. Necessary for merging an in-memory | ||
/// trie with an on-disk trie | ||
fn node_to_in_memory_node(&self, node: &Node) -> Result<InMemoryNode, Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can probably consume node
to avoid cloning the contents.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is only an in-memory conversion, this can also just implement https://doc.rust-lang.org/std/convert/trait.TryInto.html
fn in_memory_to_disk_node( | ||
&mut self, | ||
context: &mut TransactionContext, | ||
node: &InMemoryNode, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can probably also consume node
to avoid cloning contents.
context: &mut TransactionContext, | ||
node: &InMemoryNode, | ||
) -> Result<Pointer, Error> { | ||
let page = self.allocate_page(context)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll want to avoid allocating a fresh page for each node. Ideally this would have a designated page already picked out
This PR contains
InMemoryNode
andInMemoryChild
types to build recursive in-memory triesbuild_in_memory_trie
andbuild_in_memory_trie_rec
functions to build in-memory trie for(Nibbles, Option<TrieValue>)
key-value pairs. TheOption
allows for both insertion/update and delete for a key at a given value.set_subtrie
andmerge_in_memory_with_disk
functions which allow merging an in-memory subtrie with an existing on-disk trie at the specified nibbles path.Still in progress:
HashVerificationMode
enum which will be used to set the level of trust for hashes, either Ignore (always recompute), Check (optimistic hash checking, i.e. verify hashes and use if correct, otherwise recompute), or UnsafeTrust (blindly trust given hashes- currently using for quick tests but could be removed if deemed too risky)set_subtrie
andmerge_in_memory_with_disk
functionsMore context in the Linear Ticket