Skip to content

Commit

Permalink
Reduce DB creation
Browse files Browse the repository at this point in the history
  • Loading branch information
kvinwang committed May 16, 2023
1 parent a78cc1d commit 936ed73
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/phactory/src/contracts/pink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ impl OCalls for RuntimeHandleMut<'_> {
if !context::get().mode.is_transaction() {
return;
}
warn!("commit state root: {:?}", root);
info!("commit state root: {:?}", root);
self.cluster.storage.commit(root, changes);
}

Expand Down
1 change: 1 addition & 0 deletions crates/phala-trie-storage/src/kvdb/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ pub(crate) fn with_cache_dir<T>(cache_dir: &str, f: impl FnOnce() -> T) -> T {

pub(crate) fn create_db() -> (TransactionDB<MultiThreaded>, usize) {
let test_path = test_cached_path::with(|path| path.clone());
// The PRUNTIME_TRIE_CACHE_PATH would be hardcoded in the manifest when running in gramine.
let cache_path = &test_path
.or_else(|| std::env::var("PRUNTIME_TRIE_CACHE_PATH").ok())
.unwrap_or_else(|| "data/protected_files/caches".to_string());
Expand Down
8 changes: 6 additions & 2 deletions crates/phala-trie-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ where

/// Apply storage changes calculated from `calc_root_if_changes`.
pub fn apply_changes(&mut self, root: H::Out, transaction: MemoryDB<H>) {
let mut storage = core::mem::take(self).0.into_storage();
let mut storage = core::mem::replace(self, Self::default_memdb())
.0
.into_storage();
storage.consolidate_mdb(transaction);
let _ = core::mem::replace(&mut self.0, TrieBackendBuilder::new(storage, root).build());
}
Expand Down Expand Up @@ -214,7 +216,9 @@ where
}

pub fn set_root(&mut self, root: H::Out) {
let storage = core::mem::take(self).0.into_storage();
let storage = core::mem::replace(self, Self::default_memdb())
.0
.into_storage();
let _ = core::mem::replace(&mut self.0, TrieBackendBuilder::new(storage, root).build());
}

Expand Down

0 comments on commit 936ed73

Please sign in to comment.