feat: Implement HADS using single RocksDB#4
Merged
fominok merged 11 commits intogrovedb_newfrom Dec 1, 2021
Merged
Conversation
f0c4e66 to
ef331bc
Compare
ef331bc to
9188e30
Compare
QuantumExplorer
requested changes
Dec 1, 2021
merk/src/merk/mod.rs
Outdated
| fn simulated_crash() { | ||
| let path = thread::current().name().unwrap().to_owned(); | ||
| let mut merk = CrashMerk::open(path).expect("failed to open merk"); | ||
| // #[test] |
| let path = thread::current().name().unwrap().to_owned(); | ||
| let mut merk = TempMerk::open(&path).expect("failed to open merk"); | ||
| // #[test] | ||
| // fn checkpoint() { |
Member
There was a problem hiding this comment.
I guess getting checkpointing working will come later?
QuantumExplorer
pushed a commit
that referenced
this pull request
Aug 11, 2022
Add mutation instrumentation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements HADS structure using dense Merkle tree (rs-merkle) as a root tree and merkelized AVL tree (Merk) as any other subtree. This PR doesn't include proofs generation.
As it contains a lot of changes I'll try to describe how it works to verify that we're on the same page.
Note that GroveDB methods expects bytes as paths, keys and values, this example uses strings for clarity.
0. GroveDB structure
First, here is a description of GroveDB internal state:
root_tree)db)subtrees)root_leaf_keys)* subtree prefix is a concatenated path of a subtree, like if we had
path == [b"aa", b"bb", b"cc"]it will beprefix == b"aabbcc"; then each key for a Merk will be prefixed with this prefix before insertion to RocksDB, retrieval works the same way, so that's how we're able to access a proper Merk object by path and save/restore multiple Merks using single RocksDB.Next we'll apply some changed to GroveDB to see how its state is changed.
1. Insert two subtrees into the root tree
This will result into the following state:
subtrees[b"key1"].root_hash()subtrees[b"key2"].root_hash()subtreesmapMerk::open(...) // prefix is b"key1"Merk::open(...) // prefix is b"key2"root_leaf_keysmapserialize(subtrees.keys()) // this stores all used prefixes into RocksDB to restore laterserialize(root_leaf_keys) // this stores top level subtrees' positions to rebuild root tree later2. Insert a subtree into subtree
This will result into the following state:
subtreesmapMerk::open(...) // prefix is b"key1"Merk::open(...) // prefix is b"key2"Merk::open(...) // prefix is b"key1key11"root_leaf_keysmap is unchangedserialize(subtrees.keys())serialize(root_leaf_keys)serialize(Element::Tree(subtrees[b"key1key11"].root_hash())) // prefix is "key1" and key is "key11", their concatenation is a RocksDB key to store an element which wraps a root hash of a sub-sub tree3. Insert a value into a sub-sub tree
This example should finally shed some light on how prefixes work.
This will result into the following state:
subtreesmap is unchangedroot_leaf_keysmap is unchangedserialize(subtrees.keys())serialize(root_leaf_keys)serialize(Element::Tree(subtrees[b"key1key11"].root_hash())) // recomputed as Merk was changedserialize(Element::Value(b"ayy")) // subtree prefix is "key1key11", key is "key_final", their concatenation is RocksDB keyP.S. Please ignore
restorerandcrash_merkmodules as they're temporary disabled