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

Merge transactionnal state with uncommitted changes #28

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ serde = { version = "1.0.195", default-features = false, features = [
"derive",
"alloc",
] }
starknet-types-core = { git = "https://github.com/starknet-io/types-rs", branch = "main", default-features = false, features = [
starknet-types-core = { version = "0.1", default-features = false, features = [
"hash",
"parity-scale-codec",
] }
Expand All @@ -38,6 +38,8 @@ rocksdb = { optional = true, version = "0.21.0", features = [
] }

[dev-dependencies]
env_logger = "0.11.3"
once_cell = "1.19.0"
pprof = { version = "0.3", features = ["flamegraph"] }
pathfinder-common = { git = "https://github.com/massalabs/pathfinder.git", package = "pathfinder-common", rev = "b7b6d76a76ab0e10f92e5f84ce099b5f727cb4db" }
pathfinder-crypto = { git = "https://github.com/massalabs/pathfinder.git", package = "pathfinder-crypto", rev = "b7b6d76a76ab0e10f92e5f84ce099b5f727cb4db" }
Expand Down
32 changes: 8 additions & 24 deletions ensure_no_std/Cargo.lock

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

2 changes: 1 addition & 1 deletion src/databases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ pub use hashmap_db::HashMapDb;
mod rocks_db;

#[cfg(feature = "rocksdb")]
pub use rocks_db::{create_rocks_db, RocksDB, RocksDBBatch, RocksDBConfig};
pub use rocks_db::{create_rocks_db, RocksDB, RocksDBBatch, RocksDBConfig, RocksDBTransaction};
37 changes: 33 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
#[cfg(not(feature = "std"))]
extern crate alloc;

use crate::trie::merkle_tree::MerkleTree;
use crate::trie::merkle_tree::{bytes_to_bitvec, MerkleTree};
#[cfg(not(feature = "std"))]
use alloc::{format, vec::Vec};
use bitvec::{order::Msb0, slice::BitSlice, vec::BitVec};
Expand Down Expand Up @@ -488,9 +488,38 @@ where
&mut self,
transactional_bonsai_storage: BonsaiStorage<ChangeID, DB::Transaction, H>,
) -> Result<(), BonsaiStorageError<<DB as BonsaiPersistentDatabase<ChangeID>>::DatabaseError>>
where
<DB as BonsaiDatabase>::DatabaseError: core::fmt::Debug,
{
self.tries
.db_mut()
.merge(transactional_bonsai_storage.tries.db())
// memorize changes
let MerkleTrees { db, trees, .. } = transactional_bonsai_storage.tries;

self.tries.db_mut().merge(db)?;

// apply changes
for (identifier, tree) in trees {
for (k, op) in tree.cache_leaf_modified() {
match op {
crate::trie::merkle_tree::InsertOrRemove::Insert(v) => {
self.insert(&identifier, &bytes_to_bitvec(k), v)
.map_err(|e| {
BonsaiStorageError::Merge(format!(
"While merging insert({:?} {}) faced error: {:?}",
k, v, e
))
})?;
}
crate::trie::merkle_tree::InsertOrRemove::Remove => {
self.remove(&identifier, &bytes_to_bitvec(k)).map_err(|e| {
BonsaiStorageError::Merge(format!(
"While merging remove({:?}) faced error: {:?}",
k, e
))
})?;
}
}
}
}
Ok(())
}
}
Loading
Loading