Skip to content

Commit

Permalink
in case of fail, refound sender
Browse files Browse the repository at this point in the history
  • Loading branch information
modship committed Jul 25, 2024
1 parent 43923d1 commit e94c57f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
27 changes: 27 additions & 0 deletions massa-execution-worker/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Amount, String>)> {
#[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);
}
Expand Down
6 changes: 2 additions & 4 deletions massa-execution-worker/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit e94c57f

Please sign in to comment.