diff --git a/massa-deferred-calls/src/registry_changes.rs b/massa-deferred-calls/src/registry_changes.rs index c6475df304..1895e0c042 100644 --- a/massa-deferred-calls/src/registry_changes.rs +++ b/massa-deferred-calls/src/registry_changes.rs @@ -1,5 +1,3 @@ -use std::{collections::BTreeMap, ops::Bound}; - use massa_models::{ amount::Amount, deferred_calls::DeferredCallId, @@ -18,6 +16,8 @@ use nom::{ }; use serde::{Deserialize, Serialize}; use serde_with::serde_as; +use std::collections::btree_map::Entry; +use std::{collections::BTreeMap, ops::Bound}; use crate::{ config::DeferredCallsConfig, @@ -50,6 +50,24 @@ impl Default for DeferredCallRegistryChanges { } impl DeferredCallRegistryChanges { + pub fn apply(&mut self, changes: DeferredCallRegistryChanges) { + for (slot, changes) in changes.slots_change.into_iter() { + match self.slots_change.entry(slot) { + Entry::Occupied(mut occ) => { + // apply incoming change if a change on this entry already exists + *occ.get_mut() = changes; + } + Entry::Vacant(vac) => { + // otherwise insert the incoming change + vac.insert(changes); + } + } + } + + self.effective_total_gas = changes.effective_total_gas; + self.total_calls_registered = changes.total_calls_registered; + } + pub fn delete_call(&mut self, target_slot: Slot, id: &DeferredCallId) { self.slots_change .entry(target_slot) diff --git a/massa-execution-worker/src/active_history.rs b/massa-execution-worker/src/active_history.rs index 08aeeb923a..3841a98dd1 100644 --- a/massa-execution-worker/src/active_history.rs +++ b/massa-execution-worker/src/active_history.rs @@ -444,7 +444,6 @@ mod test { executed_ops_changes: Default::default(), executed_denunciations_changes: Default::default(), execution_trail_hash_change: Default::default(), - deferred_call_changes: Default::default(), }; let state_changes_2 = StateChanges { ledger_changes: Default::default(), @@ -454,7 +453,6 @@ mod test { executed_ops_changes: Default::default(), executed_denunciations_changes: Default::default(), execution_trail_hash_change: Default::default(), - deferred_call_changes: Default::default(), }; let exec_output_1 = ExecutionOutput { diff --git a/massa-final-state/src/state_changes.rs b/massa-final-state/src/state_changes.rs index ce1b02746a..eb7e47a14d 100644 --- a/massa-final-state/src/state_changes.rs +++ b/massa-final-state/src/state_changes.rs @@ -233,7 +233,6 @@ impl Deserializer for StateChangesDeserializer { impl StateChanges { /// extends the current `StateChanges` with another one pub fn apply(&mut self, changes: StateChanges) { - // TODO deferred_call_changes ? use massa_models::types::Applicable; self.ledger_changes.apply(changes.ledger_changes); self.async_pool_changes.apply(changes.async_pool_changes); @@ -244,6 +243,8 @@ impl StateChanges { .extend(changes.executed_denunciations_changes); self.execution_trail_hash_change .apply(changes.execution_trail_hash_change); + self.deferred_call_changes + .apply(changes.deferred_call_changes); } } @@ -274,16 +275,16 @@ mod test { impl PartialEq for StateChanges { fn eq(&self, other: &StateChanges) -> bool { - self.ledger_changes == other.ledger_changes && - self.async_pool_changes == other.async_pool_changes && - // pos_changes - self.pos_changes.seed_bits == other.pos_changes.seed_bits && - self.pos_changes.roll_changes == other.pos_changes.roll_changes && - self.pos_changes.production_stats == other.pos_changes.production_stats && - self.pos_changes.deferred_credits.credits == other.pos_changes.deferred_credits.credits && - self.executed_ops_changes == other.executed_ops_changes && - self.executed_denunciations_changes == other.executed_denunciations_changes && - self.execution_trail_hash_change == other.execution_trail_hash_change + self.ledger_changes == other.ledger_changes + && self.async_pool_changes == other.async_pool_changes + && self.pos_changes.seed_bits == other.pos_changes.seed_bits + && self.pos_changes.roll_changes == other.pos_changes.roll_changes + && self.pos_changes.production_stats == other.pos_changes.production_stats + && self.pos_changes.deferred_credits.credits + == other.pos_changes.deferred_credits.credits + && self.executed_ops_changes == other.executed_ops_changes + && self.executed_denunciations_changes == other.executed_denunciations_changes + && self.execution_trail_hash_change == other.execution_trail_hash_change } }