Skip to content

Commit

Permalink
Apply deferred calls
Browse files Browse the repository at this point in the history
  • Loading branch information
sydhds committed Dec 18, 2024
1 parent 77f22ba commit e2996ca
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
22 changes: 20 additions & 2 deletions massa-deferred-calls/src/registry_changes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::{collections::BTreeMap, ops::Bound};

use massa_models::{
amount::Amount,
deferred_calls::DeferredCallId,
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions massa-execution-worker/src/active_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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 {
Expand Down
23 changes: 12 additions & 11 deletions massa-final-state/src/state_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ impl Deserializer<StateChanges> 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);
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -274,16 +275,16 @@ mod test {

impl PartialEq<StateChanges> 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
}
}

Expand Down

0 comments on commit e2996ca

Please sign in to comment.