From ec94857a5f1c0487fd5bcefbbf1bb3fb9fc9a980 Mon Sep 17 00:00:00 2001 From: steelgeek091 <130330379+steelgeek091@users.noreply.github.com> Date: Sat, 20 Jul 2024 21:21:41 +0800 Subject: [PATCH] Only execute the init function when module publishing is successful. (#2237) * If it is successful, execute the init function --- moveos/moveos/src/vm/moveos_vm.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/moveos/moveos/src/vm/moveos_vm.rs b/moveos/moveos/src/vm/moveos_vm.rs index 4f8160ba2..12d7effb7 100644 --- a/moveos/moveos/src/vm/moveos_vm.rs +++ b/moveos/moveos/src/vm/moveos_vm.rs @@ -464,18 +464,20 @@ where } }; - self.resolve_pending_init_functions()?; + if action_result.is_ok() { + self.resolve_pending_init_functions()?; + // Check if there are modules upgrading + let module_flag = self.tx_context().get::().map_err(|e| { + PartialVMError::new(StatusCode::UNKNOWN_VALIDATION_STATUS) + .with_message(e.to_string()) + .finish(Location::Undefined) + })?; + let is_upgrade = module_flag.map_or(false, |flag| flag.is_upgrade); + if is_upgrade { + self.vm.mark_loader_cache_as_invalid(); + }; + } - // Check if there are modules upgrading - let module_flag = self.tx_context().get::().map_err(|e| { - PartialVMError::new(StatusCode::UNKNOWN_VALIDATION_STATUS) - .with_message(e.to_string()) - .finish(Location::Undefined) - })?; - let is_upgrade = module_flag.map_or(false, |flag| flag.is_upgrade); - if is_upgrade { - self.vm.mark_loader_cache_as_invalid(); - }; action_result }