Feature/field renaming (#1654)
* Replaced serde renames to aliases Ideally I would have removed all serde macros, but then it would have broken existing QA deployments - perhaps we should do it later * Renamed 'node_id' in Delegation to 'mix_id' * Further renamings of 'node_id' to 'mix_id' in various places
This commit is contained in:
committed by
GitHub
parent
996f0bf732
commit
879ce3f2d5
@@ -63,7 +63,7 @@ async fn print_delegations(delegations: Vec<Delegation>, client: &SigningClientW
|
||||
for delegation in delegations {
|
||||
table.add_row(vec![
|
||||
to_iso_timestamp(delegation.height as u32, client).await,
|
||||
delegation.node_id.to_string(),
|
||||
delegation.mix_id.to_string(),
|
||||
pretty_cosmwasm_coin(&delegation.amount),
|
||||
delegation
|
||||
.proxy
|
||||
|
||||
@@ -34,12 +34,13 @@ pub struct Delegation {
|
||||
pub owner: Addr,
|
||||
|
||||
/// Id of the MixNode that this delegation was performed against.
|
||||
pub node_id: NodeId,
|
||||
#[serde(alias = "node_id")]
|
||||
pub mix_id: NodeId,
|
||||
|
||||
// Note to UI/UX devs: there's absolutely no point in displaying this value to the users,
|
||||
// it would serve them no purpose. It's only used for calculating rewards
|
||||
/// Value of the "unit delegation" associated with the mixnode at the time of delegation.
|
||||
#[serde(rename = "crr")]
|
||||
#[serde(alias = "crr")]
|
||||
pub cumulative_reward_ratio: Decimal,
|
||||
|
||||
/// Original delegation amount. Note that it is never mutated as delegation accumulates rewards.
|
||||
@@ -55,7 +56,7 @@ pub struct Delegation {
|
||||
impl Delegation {
|
||||
pub fn new(
|
||||
owner: Addr,
|
||||
node_id: NodeId,
|
||||
mix_id: NodeId,
|
||||
cumulative_reward_ratio: Decimal,
|
||||
amount: Coin,
|
||||
height: u64,
|
||||
@@ -63,7 +64,7 @@ impl Delegation {
|
||||
) -> Self {
|
||||
Delegation {
|
||||
owner,
|
||||
node_id,
|
||||
mix_id,
|
||||
cumulative_reward_ratio,
|
||||
amount,
|
||||
height,
|
||||
@@ -72,20 +73,20 @@ impl Delegation {
|
||||
}
|
||||
|
||||
pub fn generate_storage_key(
|
||||
node_id: NodeId,
|
||||
mix_id: NodeId,
|
||||
owner_address: &Addr,
|
||||
proxy: Option<&Addr>,
|
||||
) -> StorageKey {
|
||||
(node_id, generate_owner_storage_subkey(owner_address, proxy))
|
||||
(mix_id, generate_owner_storage_subkey(owner_address, proxy))
|
||||
}
|
||||
|
||||
// this function might seem a bit redundant, but I'd rather explicitly keep it around in case
|
||||
// some types change in the future
|
||||
pub fn generate_storage_key_with_subkey(
|
||||
node_id: NodeId,
|
||||
mix_id: NodeId,
|
||||
owner_proxy_subkey: OwnerProxySubKey,
|
||||
) -> StorageKey {
|
||||
(node_id, owner_proxy_subkey)
|
||||
(mix_id, owner_proxy_subkey)
|
||||
}
|
||||
|
||||
pub fn dec_amount(&self) -> Decimal {
|
||||
@@ -99,7 +100,7 @@ impl Delegation {
|
||||
}
|
||||
|
||||
pub fn storage_key(&self) -> StorageKey {
|
||||
Self::generate_storage_key(self.node_id, &self.owner, self.proxy.as_ref())
|
||||
Self::generate_storage_key(self.mix_id, &self.owner, self.proxy.as_ref())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,8 +31,8 @@ pub enum MixnetContractError {
|
||||
#[error("Not enough funds sent for node delegation. (received {received}, minimum {minimum})")]
|
||||
InsufficientDelegation { received: Coin, minimum: Coin },
|
||||
|
||||
#[error("Mixnode ({id}) does not exist")]
|
||||
MixNodeBondNotFound { id: NodeId },
|
||||
#[error("Mixnode ({mix_id}) does not exist")]
|
||||
MixNodeBondNotFound { mix_id: NodeId },
|
||||
|
||||
#[error("{owner} does not seem to own any mixnodes")]
|
||||
NoAssociatedMixNodeBond { owner: Addr },
|
||||
@@ -83,23 +83,23 @@ pub enum MixnetContractError {
|
||||
epoch_end: i64,
|
||||
},
|
||||
|
||||
#[error("Mixnode {node_id} has already been rewarded during the current rewarding epoch ({absolute_epoch_id})")]
|
||||
#[error("Mixnode {mix_id} has already been rewarded during the current rewarding epoch ({absolute_epoch_id})")]
|
||||
MixnodeAlreadyRewarded {
|
||||
node_id: NodeId,
|
||||
mix_id: NodeId,
|
||||
absolute_epoch_id: u32,
|
||||
},
|
||||
|
||||
#[error("Mixnode {node_id} hasn't been selected to the rewarding set in this epoch ({absolute_epoch_id})")]
|
||||
#[error("Mixnode {mix_id} hasn't been selected to the rewarding set in this epoch ({absolute_epoch_id})")]
|
||||
MixnodeNotInRewardedSet {
|
||||
node_id: NodeId,
|
||||
mix_id: NodeId,
|
||||
absolute_epoch_id: u32,
|
||||
},
|
||||
|
||||
#[error("Mixnode {node_id} is currently in the process of unbonding")]
|
||||
MixnodeIsUnbonding { node_id: NodeId },
|
||||
#[error("Mixnode {mix_id} is currently in the process of unbonding")]
|
||||
MixnodeIsUnbonding { mix_id: NodeId },
|
||||
|
||||
#[error("Mixnode {node_id} has already unbonded")]
|
||||
MixnodeHasUnbonded { node_id: NodeId },
|
||||
#[error("Mixnode {mix_id} has already unbonded")]
|
||||
MixnodeHasUnbonded { mix_id: NodeId },
|
||||
|
||||
#[error("The contract has ended up in a state that was deemed impossible: {comment}")]
|
||||
InconsistentState { comment: String },
|
||||
@@ -134,6 +134,6 @@ pub enum MixnetContractError {
|
||||
#[error("Received unexpected value for the rewarded set. Got: {received}, expected at most: {expected}")]
|
||||
UnexpectedRewardedSetSize { received: u32, expected: u32 },
|
||||
|
||||
#[error("Mixnode {node_id} appears multiple times in the provided rewarded set update!")]
|
||||
DuplicateRewardedSetNode { node_id: NodeId },
|
||||
#[error("Mixnode {mix_id} appears multiple times in the provided rewarded set update!")]
|
||||
DuplicateRewardedSetNode { mix_id: NodeId },
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ pub const DELEGATION_TARGET_KEY: &str = "delegation_target";
|
||||
pub const DELEGATION_HEIGHT_KEY: &str = "delegation_latest_block_height";
|
||||
|
||||
// bonding/unbonding
|
||||
pub const NODE_ID_KEY: &str = "node_id";
|
||||
pub const MIX_ID_KEY: &str = "mix_id";
|
||||
pub const NODE_IDENTITY_KEY: &str = "identity";
|
||||
pub const ASSIGNED_LAYER_KEY: &str = "assigned_layer";
|
||||
|
||||
@@ -202,7 +202,7 @@ pub fn new_withdraw_operator_reward_event(
|
||||
.add_attribute(OWNER_KEY, owner.as_str())
|
||||
.add_optional_attribute(PROXY_KEY, proxy.as_ref())
|
||||
.add_attribute(AMOUNT_KEY, amount.to_string())
|
||||
.add_attribute(NODE_ID_KEY, mix_id.to_string())
|
||||
.add_attribute(MIX_ID_KEY, mix_id.to_string())
|
||||
}
|
||||
|
||||
pub fn new_withdraw_delegator_reward_event(
|
||||
@@ -269,7 +269,7 @@ pub fn new_undelegation_event(delegator: &Addr, proxy: &Option<Addr>, mix_id: No
|
||||
Event::new(MixnetEventType::Undelegation)
|
||||
.add_attribute(DELEGATOR_KEY, delegator)
|
||||
.add_optional_attribute(PROXY_KEY, proxy.as_ref())
|
||||
.add_attribute(NODE_ID_KEY, mix_id.to_string())
|
||||
.add_attribute(MIX_ID_KEY, mix_id.to_string())
|
||||
}
|
||||
|
||||
pub fn new_pending_undelegation_event(
|
||||
@@ -280,7 +280,7 @@ pub fn new_pending_undelegation_event(
|
||||
Event::new(MixnetEventType::PendingUndelegation)
|
||||
.add_attribute(DELEGATOR_KEY, delegator)
|
||||
.add_optional_attribute(PROXY_KEY, proxy.as_ref())
|
||||
.add_attribute(NODE_ID_KEY, mix_id.to_string())
|
||||
.add_attribute(MIX_ID_KEY, mix_id.to_string())
|
||||
}
|
||||
|
||||
pub fn new_gateway_bonding_event(
|
||||
@@ -314,12 +314,12 @@ pub fn new_mixnode_bonding_event(
|
||||
proxy: &Option<Addr>,
|
||||
amount: &Coin,
|
||||
identity: IdentityKeyRef<'_>,
|
||||
node_id: NodeId,
|
||||
mix_id: NodeId,
|
||||
assigned_layer: Layer,
|
||||
) -> Event {
|
||||
// coin implements Display trait and we use that implementation here
|
||||
Event::new(MixnetEventType::MixnodeBonding)
|
||||
.add_attribute(NODE_ID_KEY, node_id.to_string())
|
||||
.add_attribute(MIX_ID_KEY, mix_id.to_string())
|
||||
.add_attribute(NODE_IDENTITY_KEY, identity)
|
||||
.add_attribute(OWNER_KEY, owner)
|
||||
.add_optional_attribute(PROXY_KEY, proxy.as_ref())
|
||||
@@ -327,55 +327,55 @@ pub fn new_mixnode_bonding_event(
|
||||
.add_attribute(AMOUNT_KEY, amount.to_string())
|
||||
}
|
||||
|
||||
pub fn new_mixnode_unbonding_event(node_id: NodeId) -> Event {
|
||||
Event::new(MixnetEventType::MixnodeUnbonding).add_attribute(NODE_ID_KEY, node_id.to_string())
|
||||
pub fn new_mixnode_unbonding_event(mix_id: NodeId) -> Event {
|
||||
Event::new(MixnetEventType::MixnodeUnbonding).add_attribute(MIX_ID_KEY, mix_id.to_string())
|
||||
}
|
||||
|
||||
pub fn new_pending_mixnode_unbonding_event(
|
||||
owner: &Addr,
|
||||
proxy: &Option<Addr>,
|
||||
identity: IdentityKeyRef<'_>,
|
||||
node_id: NodeId,
|
||||
mix_id: NodeId,
|
||||
) -> Event {
|
||||
Event::new(MixnetEventType::PendingMixnodeUnbonding)
|
||||
.add_attribute(NODE_ID_KEY, node_id.to_string())
|
||||
.add_attribute(MIX_ID_KEY, mix_id.to_string())
|
||||
.add_attribute(NODE_IDENTITY_KEY, identity)
|
||||
.add_attribute(OWNER_KEY, owner)
|
||||
.add_optional_attribute(PROXY_KEY, proxy.as_ref())
|
||||
}
|
||||
|
||||
pub fn new_mixnode_config_update_event(
|
||||
node_id: NodeId,
|
||||
mix_id: NodeId,
|
||||
owner: &Addr,
|
||||
proxy: &Option<Addr>,
|
||||
update: &MixNodeConfigUpdate,
|
||||
) -> Event {
|
||||
Event::new(MixnetEventType::MixnodeConfigUpdate)
|
||||
.add_attribute(NODE_ID_KEY, node_id.to_string())
|
||||
.add_attribute(MIX_ID_KEY, mix_id.to_string())
|
||||
.add_attribute(OWNER_KEY, owner)
|
||||
.add_optional_attribute(PROXY_KEY, proxy.as_ref())
|
||||
.add_attribute(UPDATED_MIXNODE_CONFIG_KEY, update.to_inline_json())
|
||||
}
|
||||
|
||||
pub fn new_mixnode_pending_cost_params_update_event(
|
||||
node_id: NodeId,
|
||||
mix_id: NodeId,
|
||||
owner: &Addr,
|
||||
proxy: &Option<Addr>,
|
||||
new_costs: &MixNodeCostParams,
|
||||
) -> Event {
|
||||
Event::new(MixnetEventType::PendingMixnodeCostParamsUpdate)
|
||||
.add_attribute(NODE_ID_KEY, node_id.to_string())
|
||||
.add_attribute(MIX_ID_KEY, mix_id.to_string())
|
||||
.add_attribute(OWNER_KEY, owner)
|
||||
.add_optional_attribute(PROXY_KEY, proxy.as_ref())
|
||||
.add_attribute(UPDATED_MIXNODE_COST_PARAMS_KEY, new_costs.to_inline_json())
|
||||
}
|
||||
|
||||
pub fn new_mixnode_cost_params_update_event(
|
||||
node_id: NodeId,
|
||||
mix_id: NodeId,
|
||||
new_costs: &MixNodeCostParams,
|
||||
) -> Event {
|
||||
Event::new(MixnetEventType::MixnodeCostParamsUpdate)
|
||||
.add_attribute(NODE_ID_KEY, node_id.to_string())
|
||||
.add_attribute(MIX_ID_KEY, mix_id.to_string())
|
||||
.add_attribute(UPDATED_MIXNODE_COST_PARAMS_KEY, new_costs.to_inline_json())
|
||||
}
|
||||
|
||||
@@ -431,29 +431,29 @@ pub fn new_settings_update_event(
|
||||
event
|
||||
}
|
||||
|
||||
pub fn new_not_found_mix_operator_rewarding_event(interval: Interval, node_id: NodeId) -> Event {
|
||||
pub fn new_not_found_mix_operator_rewarding_event(interval: Interval, mix_id: NodeId) -> Event {
|
||||
Event::new(MixnetEventType::MixnodeRewarding)
|
||||
.add_attribute(
|
||||
INTERVAL_KEY,
|
||||
interval.current_epoch_absolute_id().to_string(),
|
||||
)
|
||||
.add_attribute(NODE_ID_KEY, node_id.to_string())
|
||||
.add_attribute(MIX_ID_KEY, mix_id.to_string())
|
||||
.add_attribute(NO_REWARD_REASON_KEY, BOND_NOT_FOUND_VALUE)
|
||||
}
|
||||
|
||||
pub fn new_zero_uptime_mix_operator_rewarding_event(interval: Interval, node_id: NodeId) -> Event {
|
||||
pub fn new_zero_uptime_mix_operator_rewarding_event(interval: Interval, mix_id: NodeId) -> Event {
|
||||
Event::new(MixnetEventType::MixnodeRewarding)
|
||||
.add_attribute(
|
||||
INTERVAL_KEY,
|
||||
interval.current_epoch_absolute_id().to_string(),
|
||||
)
|
||||
.add_attribute(NODE_ID_KEY, node_id.to_string())
|
||||
.add_attribute(MIX_ID_KEY, mix_id.to_string())
|
||||
.add_attribute(NO_REWARD_REASON_KEY, ZERO_PERFORMANCE_VALUE)
|
||||
}
|
||||
|
||||
pub fn new_mix_rewarding_event(
|
||||
interval: Interval,
|
||||
node_id: NodeId,
|
||||
mix_id: NodeId,
|
||||
reward_distribution: RewardDistribution,
|
||||
prior_delegates: Decimal,
|
||||
prior_unit_delegation: Decimal,
|
||||
@@ -465,7 +465,7 @@ pub fn new_mix_rewarding_event(
|
||||
)
|
||||
.add_attribute(PRIOR_DELEGATES_KEY, prior_delegates.to_string())
|
||||
.add_attribute(PRIOR_UNIT_DELEGATION_KEY, prior_unit_delegation.to_string())
|
||||
.add_attribute(NODE_ID_KEY, node_id.to_string())
|
||||
.add_attribute(MIX_ID_KEY, mix_id.to_string())
|
||||
.add_attribute(
|
||||
OPERATOR_REWARD_KEY,
|
||||
reward_distribution.operator.to_string(),
|
||||
|
||||
@@ -78,34 +78,34 @@ impl MixNodeDetails {
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, JsonSchema)]
|
||||
pub struct MixNodeRewarding {
|
||||
/// Information provided by the operator that influence the cost function.
|
||||
#[serde(rename = "cp")]
|
||||
#[serde(alias = "cp")]
|
||||
pub cost_params: MixNodeCostParams,
|
||||
|
||||
/// Total pledge and compounded reward earned by the node operator.
|
||||
#[serde(rename = "op")]
|
||||
#[serde(alias = "op")]
|
||||
pub operator: Decimal,
|
||||
|
||||
/// Total delegation and compounded reward earned by all node delegators.
|
||||
#[serde(rename = "dg")]
|
||||
#[serde(alias = "dg")]
|
||||
pub delegates: Decimal,
|
||||
|
||||
/// Cumulative reward earned by the "unit delegation" since the block 0.
|
||||
#[serde(rename = "tur")]
|
||||
#[serde(alias = "tur")]
|
||||
pub total_unit_reward: Decimal,
|
||||
|
||||
/// Value of the theoretical "unit delegation" that has delegated to this mixnode at block 0.
|
||||
#[serde(rename = "ud")]
|
||||
#[serde(alias = "ud")]
|
||||
pub unit_delegation: Decimal,
|
||||
|
||||
/// Marks the epoch when this node was last rewarded so that we wouldn't accidentally attempt
|
||||
/// to reward it multiple times in the same epoch.
|
||||
#[serde(rename = "le")]
|
||||
#[serde(alias = "le")]
|
||||
pub last_rewarded_epoch: EpochId,
|
||||
|
||||
// technically we don't need that field to determine reward magnitude or anything
|
||||
// but it saves on extra queries to determine if we're removing the final delegation
|
||||
// (so that we could zero the field correctly)
|
||||
#[serde(rename = "uqd")]
|
||||
#[serde(alias = "uqd")]
|
||||
pub unique_delegations: u32,
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ impl Delegation {
|
||||
) -> Result<Self, TypesError> {
|
||||
Ok(Delegation {
|
||||
owner: delegation.owner.to_string(),
|
||||
mix_id: delegation.node_id,
|
||||
mix_id: delegation.mix_id,
|
||||
amount: reg.attempt_convert_to_display_dec_coin(delegation.amount.into())?,
|
||||
height: delegation.height,
|
||||
proxy: delegation.proxy.map(|d| d.to_string()),
|
||||
|
||||
@@ -15,7 +15,7 @@ pub(crate) fn undelegate(
|
||||
) -> Result<Coin, MixnetContractError> {
|
||||
let tokens = mix_rewarding.undelegate(&delegation)?;
|
||||
|
||||
rewards_storage::MIXNODE_REWARDING.save(store, delegation.node_id, &mix_rewarding)?;
|
||||
rewards_storage::MIXNODE_REWARDING.save(store, delegation.mix_id, &mix_rewarding)?;
|
||||
storage::delegations().replace(store, delegation.storage_key(), None, Some(&delegation))?;
|
||||
|
||||
Ok(tokens)
|
||||
|
||||
@@ -74,7 +74,7 @@ pub(crate) fn query_delegator_delegations_paged(
|
||||
|
||||
let start_next_after = delegations
|
||||
.last()
|
||||
.map(|del| (del.node_id, del.proxy_storage_key()));
|
||||
.map(|del| (del.mix_id, del.proxy_storage_key()));
|
||||
|
||||
Ok(PagedDelegatorDelegationsResponse::new(
|
||||
delegations,
|
||||
@@ -284,19 +284,19 @@ mod tests {
|
||||
|
||||
let res1 = query_mixnode_delegations_paged(test.deps(), mix_id1, None, None).unwrap();
|
||||
assert_eq!(res1.delegations.len(), 10);
|
||||
assert!(res1.delegations.into_iter().all(|d| d.node_id == mix_id1));
|
||||
assert!(res1.delegations.into_iter().all(|d| d.mix_id == mix_id1));
|
||||
|
||||
let res2 = query_mixnode_delegations_paged(test.deps(), mix_id2, None, None).unwrap();
|
||||
assert_eq!(res2.delegations.len(), 14);
|
||||
assert!(res2.delegations.into_iter().all(|d| d.node_id == mix_id2));
|
||||
assert!(res2.delegations.into_iter().all(|d| d.mix_id == mix_id2));
|
||||
|
||||
let res3 = query_mixnode_delegations_paged(test.deps(), mix_id3, None, None).unwrap();
|
||||
assert_eq!(res3.delegations.len(), 10);
|
||||
assert!(res3.delegations.into_iter().all(|d| d.node_id == mix_id3));
|
||||
assert!(res3.delegations.into_iter().all(|d| d.mix_id == mix_id3));
|
||||
|
||||
let res4 = query_mixnode_delegations_paged(test.deps(), mix_id4, None, None).unwrap();
|
||||
assert_eq!(res4.delegations.len(), 10);
|
||||
assert!(res4.delegations.into_iter().all(|d| d.node_id == mix_id4));
|
||||
assert!(res4.delegations.into_iter().all(|d| d.mix_id == mix_id4));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -610,7 +610,7 @@ mod tests {
|
||||
assert_eq!(1, page1.delegations.len());
|
||||
assert!(
|
||||
page1.delegations[0].owner.as_str() == delegator1
|
||||
&& page1.delegations[0].node_id == mix_id1
|
||||
&& page1.delegations[0].mix_id == mix_id1
|
||||
);
|
||||
|
||||
test.add_immediate_delegation(delegator1, 1000u32, mix_id2);
|
||||
@@ -621,11 +621,11 @@ mod tests {
|
||||
assert_eq!(2, page1.delegations.len());
|
||||
assert!(
|
||||
page1.delegations[0].owner.as_str() == delegator1
|
||||
&& page1.delegations[0].node_id == mix_id1
|
||||
&& page1.delegations[0].mix_id == mix_id1
|
||||
);
|
||||
assert!(
|
||||
page1.delegations[1].owner.as_str() == delegator1
|
||||
&& page1.delegations[1].node_id == mix_id2
|
||||
&& page1.delegations[1].mix_id == mix_id2
|
||||
);
|
||||
|
||||
test.add_immediate_delegation(delegator2, 1000u32, mix_id1);
|
||||
@@ -636,11 +636,11 @@ mod tests {
|
||||
assert_eq!(2, another_page1.delegations.len());
|
||||
assert!(
|
||||
another_page1.delegations[0].owner.as_str() == delegator1
|
||||
&& another_page1.delegations[0].node_id == mix_id1
|
||||
&& another_page1.delegations[0].mix_id == mix_id1
|
||||
);
|
||||
assert!(
|
||||
another_page1.delegations[1].owner.as_str() == delegator2
|
||||
&& another_page1.delegations[1].node_id == mix_id1
|
||||
&& another_page1.delegations[1].mix_id == mix_id1
|
||||
);
|
||||
|
||||
// retrieving the next page should start after the last key on this page
|
||||
@@ -652,7 +652,7 @@ mod tests {
|
||||
assert_eq!(1, page2.delegations.len());
|
||||
assert!(
|
||||
page2.delegations[0].owner.as_str() == delegator1
|
||||
&& page2.delegations[0].node_id == mix_id2
|
||||
&& page2.delegations[0].mix_id == mix_id2
|
||||
);
|
||||
|
||||
// save another one
|
||||
@@ -665,11 +665,11 @@ mod tests {
|
||||
assert_eq!(2, page2.delegations.len());
|
||||
assert!(
|
||||
page2.delegations[0].owner.as_str() == delegator1
|
||||
&& page2.delegations[0].node_id == mix_id2
|
||||
&& page2.delegations[0].mix_id == mix_id2
|
||||
);
|
||||
assert!(
|
||||
page2.delegations[1].owner.as_str() == delegator2
|
||||
&& page2.delegations[1].node_id == mix_id2
|
||||
&& page2.delegations[1].mix_id == mix_id2
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ pub(crate) fn delegations<'a>() -> IndexedMap<'a, PrimaryKey, Delegation, Delega
|
||||
DELEGATION_OWNER_IDX_NAMESPACE,
|
||||
),
|
||||
mixnode: MultiIndex::new(
|
||||
|d| d.node_id,
|
||||
|d| d.mix_id,
|
||||
DELEGATION_PK_NAMESPACE,
|
||||
DELEGATION_MIXNODE_IDX_NAMESPACE,
|
||||
),
|
||||
|
||||
@@ -49,9 +49,9 @@ pub(crate) fn _try_delegate_to_mixnode(
|
||||
|
||||
// check if the target node actually exists and is still bonded
|
||||
match mixnodes_storage::mixnode_bonds().may_load(deps.storage, mix_id)? {
|
||||
None => return Err(MixnetContractError::MixNodeBondNotFound { id: mix_id }),
|
||||
None => return Err(MixnetContractError::MixNodeBondNotFound { mix_id }),
|
||||
Some(bond) if bond.is_unbonding => {
|
||||
return Err(MixnetContractError::MixnodeIsUnbonding { node_id: mix_id })
|
||||
return Err(MixnetContractError::MixnodeIsUnbonding { mix_id })
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
@@ -144,7 +144,7 @@ mod tests {
|
||||
let res = try_delegate_to_mixnode(test.deps_mut(), sender, 42);
|
||||
assert_eq!(
|
||||
res,
|
||||
Err(MixnetContractError::MixNodeBondNotFound { id: 42 })
|
||||
Err(MixnetContractError::MixNodeBondNotFound { mix_id: 42 })
|
||||
)
|
||||
}
|
||||
|
||||
@@ -240,7 +240,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
res,
|
||||
Err(MixnetContractError::MixnodeIsUnbonding {
|
||||
node_id: mix_id_unbonding
|
||||
mix_id: mix_id_unbonding
|
||||
})
|
||||
);
|
||||
|
||||
@@ -248,7 +248,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
res,
|
||||
Err(MixnetContractError::MixNodeBondNotFound {
|
||||
id: mix_id_unbonded
|
||||
mix_id: mix_id_unbonded
|
||||
})
|
||||
);
|
||||
|
||||
@@ -256,7 +256,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
res,
|
||||
Err(MixnetContractError::MixNodeBondNotFound {
|
||||
id: mix_id_unbonded_leftover
|
||||
mix_id: mix_id_unbonded_leftover
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ fn update_rewarded_set(
|
||||
let mut tmp_set = BTreeSet::new();
|
||||
for node_id in &new_rewarded_set {
|
||||
if !tmp_set.insert(node_id) {
|
||||
return Err(MixnetContractError::DuplicateRewardedSetNode { node_id: *node_id });
|
||||
return Err(MixnetContractError::DuplicateRewardedSetNode { mix_id: *node_id });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1015,7 +1015,7 @@ mod tests {
|
||||
.unwrap_err();
|
||||
assert_eq!(
|
||||
err,
|
||||
MixnetContractError::DuplicateRewardedSetNode { node_id: 1 }
|
||||
MixnetContractError::DuplicateRewardedSetNode { mix_id: 1 }
|
||||
);
|
||||
let nodes_with_duplicate = vec![1, 2, 3, 5, 4, 5];
|
||||
let err = update_rewarded_set(
|
||||
@@ -1026,7 +1026,7 @@ mod tests {
|
||||
.unwrap_err();
|
||||
assert_eq!(
|
||||
err,
|
||||
MixnetContractError::DuplicateRewardedSetNode { node_id: 5 }
|
||||
MixnetContractError::DuplicateRewardedSetNode { mix_id: 5 }
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,9 +28,9 @@ pub(crate) fn must_get_mixnode_bond_by_owner(
|
||||
|
||||
pub(crate) fn get_mixnode_details_by_id(
|
||||
store: &dyn Storage,
|
||||
node_id: NodeId,
|
||||
mix_id: NodeId,
|
||||
) -> StdResult<Option<MixNodeDetails>> {
|
||||
if let Some(bond_information) = storage::mixnode_bonds().may_load(store, node_id)? {
|
||||
if let Some(bond_information) = storage::mixnode_bonds().may_load(store, mix_id)? {
|
||||
// if bond exists, rewarding details MUST also exist
|
||||
let rewarding_details =
|
||||
rewards_storage::MIXNODE_REWARDING.load(store, bond_information.id)?;
|
||||
|
||||
@@ -453,10 +453,7 @@ pub mod tests {
|
||||
|
||||
// but fails if repeated (since the node is already in the "unbonding" state)(
|
||||
let res = try_remove_mixnode(deps.as_mut(), info);
|
||||
assert_eq!(
|
||||
res,
|
||||
Err(MixnetContractError::MixnodeIsUnbonding { node_id: mix_id })
|
||||
)
|
||||
assert_eq!(res, Err(MixnetContractError::MixnodeIsUnbonding { mix_id }))
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -522,10 +519,7 @@ pub mod tests {
|
||||
// but we cannot perform any updates whilst the mixnode is already unbonding
|
||||
try_remove_mixnode(deps.as_mut(), info.clone()).unwrap();
|
||||
let res = try_update_mixnode_config(deps.as_mut(), info, update);
|
||||
assert_eq!(
|
||||
res,
|
||||
Err(MixnetContractError::MixnodeIsUnbonding { node_id: mix_id })
|
||||
)
|
||||
assert_eq!(res, Err(MixnetContractError::MixnodeIsUnbonding { mix_id }))
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -586,7 +580,7 @@ pub mod tests {
|
||||
assert_eq!(1, event.0);
|
||||
assert_eq!(
|
||||
PendingIntervalEventData::ChangeMixCostParams {
|
||||
mix_id: mix_id,
|
||||
mix_id,
|
||||
new_costs: update.clone()
|
||||
},
|
||||
event.1
|
||||
@@ -604,10 +598,7 @@ pub mod tests {
|
||||
// but we cannot perform any updates whilst the mixnode is already unbonding
|
||||
try_remove_mixnode(deps.as_mut(), info.clone()).unwrap();
|
||||
let res = try_update_mixnode_cost_params(deps.as_mut(), info, update);
|
||||
assert_eq!(
|
||||
res,
|
||||
Err(MixnetContractError::MixnodeIsUnbonding { node_id: mix_id })
|
||||
)
|
||||
assert_eq!(res, Err(MixnetContractError::MixnodeIsUnbonding { mix_id }))
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -57,7 +57,7 @@ pub(crate) fn withdraw_delegator_reward(
|
||||
delegation: Delegation,
|
||||
mut mix_rewarding: MixNodeRewarding,
|
||||
) -> Result<Coin, MixnetContractError> {
|
||||
let mix_id = delegation.node_id;
|
||||
let mix_id = delegation.mix_id;
|
||||
let mut updated_delegation = delegation.clone();
|
||||
let reward = mix_rewarding.withdraw_delegator_reward(&mut updated_delegation)?;
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ pub(crate) fn try_reward_mixnode(
|
||||
deps: DepsMut<'_>,
|
||||
env: Env,
|
||||
info: MessageInfo,
|
||||
node_id: NodeId,
|
||||
mix_id: NodeId,
|
||||
node_performance: Performance,
|
||||
) -> Result<Response, MixnetContractError> {
|
||||
ensure_is_authorized(info.sender, deps.storage)?;
|
||||
@@ -50,15 +50,12 @@ pub(crate) fn try_reward_mixnode(
|
||||
|
||||
// there's a chance of this failing to load the details if the mixnode unbonded before rewards
|
||||
// were distributed and all of its delegators are also gone
|
||||
let mut mix_rewarding = match storage::MIXNODE_REWARDING.may_load(deps.storage, node_id)? {
|
||||
let mut mix_rewarding = match storage::MIXNODE_REWARDING.may_load(deps.storage, mix_id)? {
|
||||
Some(mix_rewarding) if mix_rewarding.still_bonded() => mix_rewarding,
|
||||
// don't fail if the node has unbonded as we don't want to fail the underlying transaction
|
||||
_ => {
|
||||
return Ok(
|
||||
Response::new().add_event(new_not_found_mix_operator_rewarding_event(
|
||||
interval, node_id,
|
||||
)),
|
||||
);
|
||||
return Ok(Response::new()
|
||||
.add_event(new_not_found_mix_operator_rewarding_event(interval, mix_id)));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -71,16 +68,16 @@ pub(crate) fn try_reward_mixnode(
|
||||
let absolute_epoch_id = interval.current_epoch_absolute_id();
|
||||
if absolute_epoch_id == mix_rewarding.last_rewarded_epoch {
|
||||
return Err(MixnetContractError::MixnodeAlreadyRewarded {
|
||||
node_id,
|
||||
mix_id,
|
||||
absolute_epoch_id,
|
||||
});
|
||||
}
|
||||
|
||||
// again a hard error since the rewarding validator should have known not to reward this node
|
||||
let node_status = interval_storage::REWARDED_SET
|
||||
.load(deps.storage, node_id)
|
||||
.load(deps.storage, mix_id)
|
||||
.map_err(|_| MixnetContractError::MixnodeNotInRewardedSet {
|
||||
node_id,
|
||||
mix_id,
|
||||
absolute_epoch_id,
|
||||
})?;
|
||||
|
||||
@@ -88,10 +85,10 @@ pub(crate) fn try_reward_mixnode(
|
||||
// however, we still need to update last_rewarded_epoch field
|
||||
if node_performance.is_zero() {
|
||||
mix_rewarding.last_rewarded_epoch = absolute_epoch_id;
|
||||
storage::MIXNODE_REWARDING.save(deps.storage, node_id, &mix_rewarding)?;
|
||||
storage::MIXNODE_REWARDING.save(deps.storage, mix_id, &mix_rewarding)?;
|
||||
return Ok(
|
||||
Response::new().add_event(new_zero_uptime_mix_operator_rewarding_event(
|
||||
interval, node_id,
|
||||
interval, mix_id,
|
||||
)),
|
||||
);
|
||||
}
|
||||
@@ -109,12 +106,12 @@ pub(crate) fn try_reward_mixnode(
|
||||
mix_rewarding.distribute_rewards(reward_distribution, absolute_epoch_id);
|
||||
|
||||
// persist changes happened to the storage
|
||||
storage::MIXNODE_REWARDING.save(deps.storage, node_id, &mix_rewarding)?;
|
||||
storage::MIXNODE_REWARDING.save(deps.storage, mix_id, &mix_rewarding)?;
|
||||
storage::reward_accounting(deps.storage, node_reward)?;
|
||||
|
||||
Ok(Response::new().add_event(new_mix_rewarding_event(
|
||||
interval,
|
||||
node_id,
|
||||
mix_id,
|
||||
reward_distribution,
|
||||
prior_delegates,
|
||||
prior_unit_delegation,
|
||||
@@ -233,9 +230,9 @@ pub(crate) fn _try_withdraw_delegator_reward(
|
||||
// (in that case the expected path of getting your tokens back is via undelegation)
|
||||
match mixnodes_storage::mixnode_bonds().may_load(deps.storage, mix_id)? {
|
||||
Some(mix_bond) if mix_bond.is_unbonding => {
|
||||
return Err(MixnetContractError::MixnodeIsUnbonding { node_id: mix_id })
|
||||
return Err(MixnetContractError::MixnodeIsUnbonding { mix_id })
|
||||
}
|
||||
None => return Err(MixnetContractError::MixnodeHasUnbonded { node_id: mix_id }),
|
||||
None => return Err(MixnetContractError::MixnodeHasUnbonded { mix_id }),
|
||||
_ => (),
|
||||
};
|
||||
|
||||
@@ -528,7 +525,7 @@ pub mod tests {
|
||||
assert!(res_standby.is_ok());
|
||||
assert!(matches!(
|
||||
res_inactive,
|
||||
Err(MixnetContractError::MixnodeNotInRewardedSet { node_id, .. }) if node_id == inactive_mix_id
|
||||
Err(MixnetContractError::MixnodeNotInRewardedSet { mix_id, .. }) if mix_id == inactive_mix_id
|
||||
));
|
||||
}
|
||||
|
||||
@@ -557,7 +554,7 @@ pub mod tests {
|
||||
let res = try_reward_mixnode(test.deps_mut(), env, sender.clone(), mix_id, performance);
|
||||
assert!(matches!(
|
||||
res,
|
||||
Err(MixnetContractError::MixnodeAlreadyRewarded { node_id, .. }) if node_id == mix_id
|
||||
Err(MixnetContractError::MixnodeAlreadyRewarded { mix_id, .. }) if mix_id == mix_id
|
||||
));
|
||||
|
||||
// in the following epoch we're good again
|
||||
@@ -606,7 +603,7 @@ pub mod tests {
|
||||
);
|
||||
assert!(matches!(
|
||||
res,
|
||||
Err(MixnetContractError::MixnodeAlreadyRewarded { node_id, .. }) if node_id == mix_id
|
||||
Err(MixnetContractError::MixnodeAlreadyRewarded { mix_id, .. }) if mix_id == mix_id
|
||||
));
|
||||
|
||||
// but in the next epoch, as always, we're good again
|
||||
@@ -917,7 +914,7 @@ pub mod tests {
|
||||
assert_eq!(
|
||||
res,
|
||||
Err(MixnetContractError::MixnodeIsUnbonding {
|
||||
node_id: mix_id_unbonding
|
||||
mix_id: mix_id_unbonding
|
||||
})
|
||||
);
|
||||
|
||||
@@ -926,7 +923,7 @@ pub mod tests {
|
||||
assert_eq!(
|
||||
res,
|
||||
Err(MixnetContractError::MixnodeHasUnbonded {
|
||||
node_id: mix_id_unbonded_leftover
|
||||
mix_id: mix_id_unbonded_leftover
|
||||
})
|
||||
);
|
||||
}
|
||||
@@ -1198,7 +1195,7 @@ pub mod tests {
|
||||
assert_eq!(
|
||||
res,
|
||||
Err(MixnetContractError::MixnodeIsUnbonding {
|
||||
node_id: mix_id_unbonding
|
||||
mix_id: mix_id_unbonding
|
||||
})
|
||||
);
|
||||
|
||||
|
||||
@@ -152,7 +152,7 @@ pub(crate) fn ensure_proxy_match(
|
||||
|
||||
pub(crate) fn ensure_bonded(bond: &MixNodeBond) -> Result<(), MixnetContractError> {
|
||||
if bond.is_unbonding {
|
||||
return Err(MixnetContractError::MixnodeIsUnbonding { node_id: bond.id });
|
||||
return Err(MixnetContractError::MixnodeIsUnbonding { mix_id: bond.id });
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -173,10 +173,10 @@ fn get_common_owner(delegations: &[Delegation]) -> Option<Addr> {
|
||||
}
|
||||
|
||||
fn get_common_mix_id(delegations: &[Delegation]) -> Option<NodeId> {
|
||||
let mix_id = delegations.iter().next()?.node_id;
|
||||
let mix_id = delegations.iter().next()?.mix_id;
|
||||
if delegations
|
||||
.iter()
|
||||
.any(|delegation| delegation.node_id != mix_id)
|
||||
.any(|delegation| delegation.mix_id != mix_id)
|
||||
{
|
||||
log::warn!("Unexpected different node identities when summing delegations");
|
||||
return None;
|
||||
|
||||
@@ -119,11 +119,11 @@ impl<C> ValidatorCacheRefresher<C> {
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_performance(&self, node_id: NodeId, epoch: Interval) -> Option<Performance> {
|
||||
async fn get_performance(&self, mix_id: NodeId, epoch: Interval) -> Option<Performance> {
|
||||
self.storage
|
||||
.as_ref()?
|
||||
.get_average_mixnode_uptime_in_the_last_24hrs(
|
||||
node_id,
|
||||
mix_id,
|
||||
epoch.current_epoch_end_unix_timestamp(),
|
||||
)
|
||||
.await
|
||||
|
||||
Reference in New Issue
Block a user