From e94c57f71fbf46b3250182c8aebde7cad3f8cba6 Mon Sep 17 00:00:00 2001 From: modship Date: Thu, 25 Jul 2024 11:21:48 +0200 Subject: [PATCH] in case of fail, refound sender --- massa-execution-worker/src/context.rs | 27 +++++++++++++++++++++++++ massa-execution-worker/src/execution.rs | 6 ++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/massa-execution-worker/src/context.rs b/massa-execution-worker/src/context.rs index e09fa74f3c2..51a9a404f64 100644 --- a/massa-execution-worker/src/context.rs +++ b/massa-execution-worker/src/context.rs @@ -1190,6 +1190,33 @@ impl ExecutionContext { self.speculative_deferred_calls.get_call(call_id).is_some() } + /// when a deferred call execution fail we need to refund the coins to the caller + pub fn deferred_call_fail_exec( + &mut self, + call: &DeferredCall, + ) -> Option<(Address, Result)> { + #[allow(unused_assignments, unused_mut)] + let mut result = None; + + let transfer_result = + self.transfer_coins(None, Some(call.sender_address), call.coins, false); + if let Err(e) = transfer_result.as_ref() { + debug!( + "deferred call cancel: reimbursement of {} failed: {}", + call.sender_address, e + ); + } + + #[cfg(feature = "execution-info")] + if let Err(e) = transfer_result { + result = Some((call.sender_address, Err(e.to_string()))) + } else { + result = Some((call.sender_address, Ok(call.coins))); + } + + result + } + pub fn deferred_call_delete(&mut self, call_id: &DeferredCallId, slot: Slot) { self.speculative_deferred_calls.delete_call(call_id, slot); } diff --git a/massa-execution-worker/src/execution.rs b/massa-execution-worker/src/execution.rs index 1ab57bceb6e..548f33b9f7c 100644 --- a/massa-execution-worker/src/execution.rs +++ b/massa-execution-worker/src/execution.rs @@ -1273,8 +1273,7 @@ impl ExecutionState { )); context.reset_to_snapshot(snapshot, err.clone()); - // TODO cancel the deferred call - // context.cancel_async_message(&message); + context.deferred_call_fail_exec(&call); return Err(err); } @@ -1334,8 +1333,7 @@ impl ExecutionState { }; let mut context = context_guard!(self); context.reset_to_snapshot(snapshot, err.clone()); - // TODO cancel the deferred call - // context.cancel_async_message(&message); + context.deferred_call_fail_exec(&call); Err(err) } }