From 52e85bed4518b3134e70343e78e8b75ec83c23ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Mon, 28 Oct 2024 15:23:46 +0000 Subject: [PATCH] bugfix: mark migrated gateways as rewarded in the previous epoch in case theyre in the rewarded set --- contracts/mixnet/src/gateways/transactions.rs | 6 ++++++ contracts/mixnet/src/nodes/helpers.rs | 9 ++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/contracts/mixnet/src/gateways/transactions.rs b/contracts/mixnet/src/gateways/transactions.rs index 541e7e86c8..ef8f282f3e 100644 --- a/contracts/mixnet/src/gateways/transactions.rs +++ b/contracts/mixnet/src/gateways/transactions.rs @@ -4,6 +4,7 @@ use super::helpers::must_get_gateway_bond_by_owner; use super::storage; use crate::constants::default_node_costs; +use crate::interval::storage as interval_storage; use crate::mixnet_contract_settings::storage as mixnet_params_storage; use crate::nodes::helpers::save_new_nymnode_with_id; use crate::nodes::transactions::add_nym_node_inner; @@ -115,6 +116,10 @@ pub fn try_migrate_to_nymnode( comment: "legacy gateway did not have a pre-assigned node id".to_string(), })?; + let current_epoch = + interval_storage::current_interval(deps.storage)?.current_epoch_absolute_id(); + let previous_epoch = current_epoch.saturating_sub(1); + // create nym-node entry // for gateways it's quite straightforward as there are no delegations or rewards to worry about save_new_nymnode_with_id( @@ -125,6 +130,7 @@ pub fn try_migrate_to_nymnode( cost_params, info.sender.clone(), gateway_bond.pledge_amount, + previous_epoch, )?; storage::PREASSIGNED_LEGACY_IDS.remove(deps.storage, gateway_identity.clone()); diff --git a/contracts/mixnet/src/nodes/helpers.rs b/contracts/mixnet/src/nodes/helpers.rs index b9b2706380..12c01ab1f6 100644 --- a/contracts/mixnet/src/nodes/helpers.rs +++ b/contracts/mixnet/src/nodes/helpers.rs @@ -22,6 +22,8 @@ pub(crate) fn save_new_nymnode( pledge: Coin, ) -> Result { let node_id = next_nymnode_id_counter(storage)?; + let current_epoch = interval_storage::current_interval(storage)?.current_epoch_absolute_id(); + save_new_nymnode_with_id( storage, node_id, @@ -30,11 +32,13 @@ pub(crate) fn save_new_nymnode( cost_params, owner, pledge, + current_epoch, )?; Ok(node_id) } +#[allow(clippy::too_many_arguments)] pub(crate) fn save_new_nymnode_with_id( storage: &mut dyn Storage, node_id: NodeId, @@ -43,10 +47,9 @@ pub(crate) fn save_new_nymnode_with_id( cost_params: NodeCostParams, owner: Addr, pledge: Coin, + last_rewarding_epoch: u32, ) -> Result<(), MixnetContractError> { - let current_epoch = interval_storage::current_interval(storage)?.current_epoch_absolute_id(); - - let node_rewarding = NodeRewarding::initialise_new(cost_params, &pledge, current_epoch)?; + let node_rewarding = NodeRewarding::initialise_new(cost_params, &pledge, last_rewarding_epoch)?; let node_bond = NymNodeBond::new(node_id, owner, pledge, node, bonding_height); // save node bond data