Skip to content

Commit

Permalink
Fix ledger change to take into account cancelled message balance chan…
Browse files Browse the repository at this point in the history
…ge (#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
  • Loading branch information
Leo-Besancon authored Jul 2, 2024
1 parent 5322c76 commit 5ae7c4c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 19 deletions.
9 changes: 3 additions & 6 deletions massa-execution-worker/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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(),
Expand Down
13 changes: 0 additions & 13 deletions massa-execution-worker/src/speculative_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,6 @@ pub(crate) struct SpeculativeLedger {
active_history: Arc<RwLock<ActiveHistory>>,

/// 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
Expand Down

0 comments on commit 5ae7c4c

Please sign in to comment.