From 5ae7c4ca8c04475e71de31c1139837a90ab8886e Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Tue, 2 Jul 2024 16:12:08 +0200 Subject: [PATCH] Fix ledger change to take into account cancelled message balance change (#4715) * Take again the speculative changes after async message cancellation * use .apply() to merge the two LedgerChanges * Fix: we cannot combine two ledger changes with apply * avoid cloning the changes * Remove comment --- massa-execution-worker/src/context.rs | 9 +++------ massa-execution-worker/src/speculative_ledger.rs | 13 ------------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/massa-execution-worker/src/context.rs b/massa-execution-worker/src/context.rs index e77060c5394..50eeda621f5 100644 --- a/massa-execution-worker/src/context.rs +++ b/massa-execution-worker/src/context.rs @@ -893,13 +893,10 @@ impl ExecutionContext { // execute the deferred credits coming from roll sells let deferred_credits_transfers = self.execute_deferred_credits(&slot); - // take the ledger changes first as they are needed for async messages and cache - let ledger_changes = self.speculative_ledger.take(); - // settle emitted async messages and reimburse the senders of deleted messages let deleted_messages = self .speculative_async_pool - .settle_slot(&slot, &ledger_changes); + .settle_slot(&slot, &self.speculative_ledger.added_changes); let mut cancel_async_message_transfers = vec![]; for (_msg_id, msg) in deleted_messages { @@ -909,7 +906,7 @@ impl ExecutionContext { } // update module cache - let bc_updates = ledger_changes.get_bytecode_updates(); + let bc_updates = self.speculative_ledger.added_changes.get_bytecode_updates(); { let mut cache_write_lock = self.module_cache.write(); for bytecode in bc_updates { @@ -935,7 +932,7 @@ impl ExecutionContext { // generate the execution output let state_changes = StateChanges { - ledger_changes, + ledger_changes: self.speculative_ledger.take(), async_pool_changes: self.speculative_async_pool.take(), pos_changes: self.speculative_roll_state.take(), executed_ops_changes: self.speculative_executed_ops.take(), diff --git a/massa-execution-worker/src/speculative_ledger.rs b/massa-execution-worker/src/speculative_ledger.rs index 16bc6a98053..238d3128321 100644 --- a/massa-execution-worker/src/speculative_ledger.rs +++ b/massa-execution-worker/src/speculative_ledger.rs @@ -34,19 +34,6 @@ pub(crate) struct SpeculativeLedger { active_history: Arc>, /// list of ledger changes that were applied to this `SpeculativeLedger` since its creation - #[cfg(all( - not(feature = "gas_calibration"), - not(feature = "benchmarking"), - not(feature = "test-exports"), - not(test) - ))] - added_changes: LedgerChanges, - #[cfg(any( - feature = "gas_calibration", - feature = "benchmarking", - feature = "test-exports", - test - ))] pub added_changes: LedgerChanges, /// max datastore key length