From 92a2f459d835a513a9ce4a2ea28f4d765823c59c Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Thu, 20 Jun 2024 08:56:58 +0200 Subject: [PATCH 1/5] Take again the speculative changes after async message cancellation --- massa-execution-worker/src/context.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/massa-execution-worker/src/context.rs b/massa-execution-worker/src/context.rs index e77060c5394..56ee82f62a7 100644 --- a/massa-execution-worker/src/context.rs +++ b/massa-execution-worker/src/context.rs @@ -894,7 +894,7 @@ impl ExecutionContext { 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(); + let mut ledger_changes = self.speculative_ledger.take(); // settle emitted async messages and reimburse the senders of deleted messages let deleted_messages = self @@ -908,6 +908,13 @@ impl ExecutionContext { } } + // take the ledger changes again to take into account the balance change of canceled messages + let ledger_changes_canceled = self.speculative_ledger.take(); + + for (address, change) in ledger_changes_canceled.0 { + ledger_changes.0.insert(address, change); + } + // update module cache let bc_updates = ledger_changes.get_bytecode_updates(); { From b10ba7991ed35879e71099547a35ea4b8d3be448 Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Thu, 20 Jun 2024 14:00:24 +0200 Subject: [PATCH 2/5] use .apply() to merge the two LedgerChanges --- massa-execution-worker/src/context.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/massa-execution-worker/src/context.rs b/massa-execution-worker/src/context.rs index 56ee82f62a7..6b3db6751ea 100644 --- a/massa-execution-worker/src/context.rs +++ b/massa-execution-worker/src/context.rs @@ -22,7 +22,7 @@ use massa_execution_exports::{ }; use massa_final_state::{FinalStateController, StateChanges}; use massa_hash::Hash; -use massa_ledger_exports::{LedgerChanges, SetOrKeep}; +use massa_ledger_exports::{Applicable, LedgerChanges, SetOrKeep}; use massa_models::address::ExecutionAddressCycleInfo; use massa_models::block_id::BlockIdSerializer; use massa_models::bytecode::Bytecode; @@ -911,9 +911,7 @@ impl ExecutionContext { // take the ledger changes again to take into account the balance change of canceled messages let ledger_changes_canceled = self.speculative_ledger.take(); - for (address, change) in ledger_changes_canceled.0 { - ledger_changes.0.insert(address, change); - } + ledger_changes.apply(ledger_changes_canceled); // update module cache let bc_updates = ledger_changes.get_bytecode_updates(); From 5601eacff73d871f515b5daae650d9c53f8c1b55 Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Thu, 27 Jun 2024 15:47:57 +0200 Subject: [PATCH 3/5] Fix: we cannot combine two ledger changes with apply --- massa-execution-worker/src/context.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/massa-execution-worker/src/context.rs b/massa-execution-worker/src/context.rs index 6b3db6751ea..ecd3a34ad0b 100644 --- a/massa-execution-worker/src/context.rs +++ b/massa-execution-worker/src/context.rs @@ -22,7 +22,7 @@ use massa_execution_exports::{ }; use massa_final_state::{FinalStateController, StateChanges}; use massa_hash::Hash; -use massa_ledger_exports::{Applicable, LedgerChanges, SetOrKeep}; +use massa_ledger_exports::{LedgerChanges, SetOrKeep}; use massa_models::address::ExecutionAddressCycleInfo; use massa_models::block_id::BlockIdSerializer; use massa_models::bytecode::Bytecode; @@ -894,7 +894,7 @@ impl ExecutionContext { let deferred_credits_transfers = self.execute_deferred_credits(&slot); // take the ledger changes first as they are needed for async messages and cache - let mut ledger_changes = self.speculative_ledger.take(); + let mut ledger_changes = self.speculative_ledger.get_snapshot(); // settle emitted async messages and reimburse the senders of deleted messages let deleted_messages = self @@ -908,10 +908,7 @@ impl ExecutionContext { } } - // take the ledger changes again to take into account the balance change of canceled messages - let ledger_changes_canceled = self.speculative_ledger.take(); - - ledger_changes.apply(ledger_changes_canceled); + ledger_changes = self.speculative_ledger.take(); // update module cache let bc_updates = ledger_changes.get_bytecode_updates(); From 65b77f41334ff860a72ff9290eae00de3d436cb5 Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Fri, 28 Jun 2024 09:58:08 +0200 Subject: [PATCH 4/5] avoid cloning the changes --- 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 ecd3a34ad0b..35f2ff89e54 100644 --- a/massa-execution-worker/src/context.rs +++ b/massa-execution-worker/src/context.rs @@ -894,12 +894,11 @@ impl ExecutionContext { let deferred_credits_transfers = self.execute_deferred_credits(&slot); // take the ledger changes first as they are needed for async messages and cache - let mut ledger_changes = self.speculative_ledger.get_snapshot(); // 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 { @@ -908,10 +907,8 @@ impl ExecutionContext { } } - ledger_changes = self.speculative_ledger.take(); - // 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 { @@ -937,7 +934,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 From d64f9d65a0430d992053e84dc0476bbf56526bf2 Mon Sep 17 00:00:00 2001 From: Leo-Besancon Date: Tue, 2 Jul 2024 09:26:08 +0200 Subject: [PATCH 5/5] Remove comment --- massa-execution-worker/src/context.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/massa-execution-worker/src/context.rs b/massa-execution-worker/src/context.rs index 35f2ff89e54..50eeda621f5 100644 --- a/massa-execution-worker/src/context.rs +++ b/massa-execution-worker/src/context.rs @@ -893,8 +893,6 @@ 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 - // settle emitted async messages and reimburse the senders of deleted messages let deleted_messages = self .speculative_async_pool