From c949df8c3e8854a719e8302cb430b23b95159d51 Mon Sep 17 00:00:00 2001 From: Dmitry Murzin Date: Fri, 27 Sep 2024 21:13:47 +0300 Subject: [PATCH] Review fixes Signed-off-by: Dmitry Murzin --- crates/iroha_core/src/executor.rs | 6 +++--- crates/iroha_core/src/smartcontracts/wasm/cache.rs | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/iroha_core/src/executor.rs b/crates/iroha_core/src/executor.rs index aca3ad504d..326676f4d5 100644 --- a/crates/iroha_core/src/executor.rs +++ b/crates/iroha_core/src/executor.rs @@ -142,14 +142,14 @@ impl Executor { } Self::UserProvided(loaded_executor) => { let wasm_cache = WasmCache::change_lifetime(wasm_cache); - let mut runtime = - wasm_cache.create_runtime_cached(state_transaction, &loaded_executor.module)?; + let mut runtime = wasm_cache + .take_or_create_cached_runtime(state_transaction, &loaded_executor.module)?; let result = runtime.execute_executor_validate_transaction( state_transaction, authority, transaction, )?; - wasm_cache.save_cached_runtime(runtime); + wasm_cache.put_cached_runtime(runtime); result } } diff --git a/crates/iroha_core/src/smartcontracts/wasm/cache.rs b/crates/iroha_core/src/smartcontracts/wasm/cache.rs index f2d12f3a14..bf745df587 100644 --- a/crates/iroha_core/src/smartcontracts/wasm/cache.rs +++ b/crates/iroha_core/src/smartcontracts/wasm/cache.rs @@ -30,11 +30,13 @@ impl<'world, 'block, 'state> WasmCache<'world, 'block, 'state> { if let Some(cache) = wasm_cache.cache.as_ref() { assert!(cache.store.data().is_none()); } + // SAFETY: since we have ensured that `cache.store.data()` is `None`, + // the lifetime parameters we are transmuting are not used by any references. unsafe { std::mem::transmute::<&mut WasmCache, &mut WasmCache>(wasm_cache) } } /// Returns cached saved runtime, or creates a new one. - pub fn create_runtime_cached( + pub fn take_or_create_cached_runtime( &mut self, state_transaction: &StateTransaction<'_, '_>, module: &Module, @@ -69,7 +71,7 @@ impl<'world, 'block, 'state> WasmCache<'world, 'block, 'state> { } /// Saves runtime to be reused later. - pub fn save_cached_runtime( + pub fn put_cached_runtime( &mut self, runtime: RuntimeFull>, ) {