Skip to content

Commit f52ceaa

Browse files
committed
Reduce DB creation
1 parent 2859431 commit f52ceaa

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

crates/phactory/src/contracts/pink.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ impl OCalls for RuntimeHandleMut<'_> {
391391
if !context::get().mode.is_transaction() {
392392
return;
393393
}
394-
warn!("commit state root: {:?}", root);
394+
info!("commit state root: {:?}", root);
395395
self.cluster.storage.commit(root, changes);
396396
}
397397

crates/phala-trie-storage/src/kvdb/database.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ pub(crate) fn with_cache_dir<T>(cache_dir: &str, f: impl FnOnce() -> T) -> T {
128128

129129
pub(crate) fn create_db() -> (TransactionDB<MultiThreaded>, usize) {
130130
let test_path = test_cached_path::with(|path| path.clone());
131+
// The PRUNTIME_TRIE_CACHE_PATH would be hardcoded in the manifest when running in gramine.
131132
let cache_path = &test_path
132133
.or_else(|| std::env::var("PRUNTIME_TRIE_CACHE_PATH").ok())
133134
.unwrap_or_else(|| "data/protected_files/caches".to_string());

crates/phala-trie-storage/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ where
173173

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

216218
pub fn set_root(&mut self, root: H::Out) {
217-
let storage = core::mem::take(self).0.into_storage();
219+
let storage = core::mem::replace(self, Self::default_memdb())
220+
.0
221+
.into_storage();
218222
let _ = core::mem::replace(&mut self.0, TrieBackendBuilder::new(storage, root).build());
219223
}
220224

0 commit comments

Comments
 (0)