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

Add multi trie management #21

Merged
merged 26 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a2a0d5e
Add multi trie management and update of the documentation
AurelienFT Mar 14, 2024
5b2a080
Uncomment trie log test
AurelienFT Mar 14, 2024
2754970
Fix clippy and batch db writes
AurelienFT Mar 14, 2024
42eef75
Format
AurelienFT Mar 14, 2024
0af9411
Re-ignore doc test
AurelienFT Mar 14, 2024
27d4178
Add function to init tree
AurelienFT Mar 14, 2024
8802b65
Fix a bug in deletion of keys
AurelienFT Mar 15, 2024
808131f
Remove dead code
AurelienFT Mar 15, 2024
19490c1
Add new way to merge parent branch
AurelienFT Mar 15, 2024
b933ddf
Fix double merge in deletion
AurelienFT Mar 15, 2024
031dbd6
Update build
AurelienFT Mar 15, 2024
5956a3d
Fix bad preload nodes
AurelienFT Mar 16, 2024
2a6c72d
Fix last deletion issue
AurelienFT Mar 17, 2024
7d9dd3f
Fix clippy
AurelienFT Mar 17, 2024
fadf864
Add more test and fix a special case in deletion
AurelienFT Mar 17, 2024
b58dd17
Fix don't traverse when key doesn't exists
AurelienFT Mar 22, 2024
3ded99d
Fix issue binary as a last node
AurelienFT Mar 22, 2024
b12c558
Format
AurelienFT Mar 22, 2024
e1bc115
Add rayon support for hash calculation
AurelienFT Mar 22, 2024
fc50023
Format
AurelienFT Mar 22, 2024
14316cd
Fix clippy warnings
AurelienFT Mar 22, 2024
b4e7828
Add verification to not load trie for nothing
AurelienFT Mar 22, 2024
c36f3f7
Fix no std
AurelienFT Mar 25, 2024
0d36b9e
Add get keys and improve iteration on changes
AurelienFT Mar 27, 2024
1e585c0
Remove misleading function and add a constructor for triekey
AurelienFT Mar 28, 2024
5c11f97
Fix no std
AurelienFT Mar 28, 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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ derive_more = { version = "0.99.17", default-features = false, features = [
hashbrown = "0.14.3"
log = "0.4.20"
smallvec = "1.11.2"
rayon = "1.9.0"

parity-scale-codec = { version = "3.0.0", default-features = false, features = [
"derive",
Expand Down
31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,19 @@ fn main() {
// Create a simple incremental ID builder for commit IDs.
// This is not necessary, you can use any kind of strictly monotonically increasing value to tag your commits.
let mut id_builder = BasicIdBuilder::new();

// Define an idenfitier for a trie. All insert, get, remove and root hash will use this identifier. Define multiple identifier to use multiple tries that have separate root hash.
let identifier = vec![];

// Insert an item `pair1`.
let pair1 = (vec![1, 2, 1], Felt::from_hex("0x66342762FDD54D033c195fec3ce2568b62052e").unwrap());
let bitvec_1 = BitVec::from_vec(pair1.0.clone());
bonsai_storage.insert(&bitvec_1, &pair1.1).unwrap();
bonsai_storage.insert(&identifier, &bitvec_1, &pair1.1).unwrap();

// Insert a second item `pair2`.
let pair2 = (vec![1, 2, 2], Felt::from_hex("0x66342762FD54D033c195fec3ce2568b62052e").unwrap());
let bitvec = BitVec::from_vec(pair2.0.clone());
bonsai_storage.insert(&bitvec, &pair2.1).unwrap();
bonsai_storage.insert(&identifier, &bitvec, &pair2.1).unwrap();

// Commit the insertion of `pair1` and `pair2`.
let id1 = id_builder.new_id()
Expand All @@ -73,31 +76,31 @@ fn main() {
// Insert a new item `pair3`.
let pair3 = (vec![1, 2, 2], Felt::from_hex("0x664D033c195fec3ce2568b62052e").unwrap());
let bitvec = BitVec::from_vec(pair3.0.clone());
bonsai_storage.insert(&bitvec, &pair3.1).unwrap();
bonsai_storage.insert(&identifier, &bitvec, &pair3.1).unwrap();

// Commit the insertion of `pair3`. Save the commit ID to the `revert_to_id` variable.
let revert_to_id = id_builder.new_id();
bonsai_storage.commit(revert_to_id);

// Remove `pair3`.
bonsai_storage.remove(&bitvec).unwrap();
bonsai_storage.remove(&identifier, &bitvec).unwrap();

// Commit the removal of `pair3`.
bonsai_storage.commit(id_builder.new_id());

// Print the root hash and item `pair1`.
println!("root: {:#?}", bonsai_storage.root_hash());
println!("root: {:#?}", bonsai_storage.root_hash(&identifier));
println!(
"value: {:#?}",
bonsai_storage.get(&bitvec_1).unwrap()
bonsai_storage.get(&identifier, &bitvec_1).unwrap()
);

// Revert the collection state back to the commit tagged by the `revert_to_id` variable.
bonsai_storage.revert_to(revert_to_id).unwrap();

// Print the root hash and item `pair3`.
println!("root: {:#?}", bonsai_storage.root_hash());
println!("value: {:#?}", bonsai_storage.get(&bitvec).unwrap());
println!("root: {:#?}", bonsai_storage.root_hash(&identifier));
println!("value: {:#?}", bonsai_storage.get(&identifier, &bitvec).unwrap());

// Launch two threads that will simultaneously take transactional states to the commit identified by `id1`,
// asserting in both of them that the item `pair1` is present and has the right value.
Expand All @@ -108,7 +111,7 @@ fn main() {
.unwrap()
.unwrap();
let bitvec = BitVec::from_vec(pair1.0.clone());
assert_eq!(bonsai_at_txn.get(&bitvec).unwrap().unwrap(), pair1.1);
assert_eq!(bonsai_at_txn.get(&identifier, &bitvec).unwrap().unwrap(), pair1.1);
});

s.spawn(|| {
Expand All @@ -117,13 +120,13 @@ fn main() {
.unwrap()
.unwrap();
let bitvec = BitVec::from_vec(pair1.0.clone());
assert_eq!(bonsai_at_txn.get(&bitvec).unwrap().unwrap(), pair1.1);
assert_eq!(bonsai_at_txn.get(&identifier, &bitvec).unwrap().unwrap(), pair1.1);
});
});

// Read item `pair1`.
let pair1_val = bonsai_storage
.get(&BitVec::from_vec(vec![1, 2, 2]))
.get(&identifier, &BitVec::from_vec(vec![1, 2, 2]))
.unwrap();

// Insert a new item and commit.
Expand All @@ -132,15 +135,15 @@ fn main() {
Felt::from_hex("0x66342762FDD54D033c195fec3ce2568b62052e").unwrap(),
);
bonsai_storage
.insert(&BitVec::from_vec(pair4.0.clone()), &pair4.1)
.insert(&identifier, &BitVec::from_vec(pair4.0.clone()), &pair4.1)
.unwrap();
bonsai_storage.commit(id_builder.new_id()).unwrap();
let proof = bonsai_storage
.get_proof(&BitVec::from_vec(pair3.0.clone()))
.get_proof(&identifier, &BitVec::from_vec(pair3.0.clone()))
.unwrap();
assert_eq!(
BonsaiStorage::<BasicId, RocksDB<BasicId>>::verify_proof(
bonsai_storage.root_hash().unwrap(),
bonsai_storage.root_hash(&identifier).unwrap(),
&BitVec::from_vec(pair3.0.clone()),
pair3.1,
&proof
Expand Down
52 changes: 52 additions & 0 deletions ensure_no_std/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading