Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

use cosmwasm_std::{Decimal, StdError, StdResult, Uint128};

#[track_caller]
pub fn compare_decimals(a: Decimal, b: Decimal, epsilon: Option<Decimal>) {
let epsilon = epsilon.unwrap_or_else(|| Decimal::from_ratio(1u128, 100_000_000u128));
if a > b {
assert!(a - b < epsilon, "{a} != {b}")
assert!(a - b < epsilon, "{a} != {b}, delta: {}", a - b)
} else {
assert!(b - a < epsilon, "{a} != {b}")
assert!(b - a < epsilon, "{a} != {b}, delta: {}", b - a)
}
}

Expand Down
21 changes: 20 additions & 1 deletion common/cosmwasm-smart-contracts/mixnet-contract/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ pub enum QueryMsg {
/// Gets the basic list of all unbonded mixnodes that belonged to a particular owner.
#[cfg_attr(feature = "schema", returns(PagedUnbondedMixnodesResponse))]
GetUnbondedMixNodesByOwner {
/// The address of the owner of the the mixnodes used for the query.
/// The address of the owner of the mixnodes used for the query.
owner: String,

/// Controls the maximum number of entries returned by the query. Note that too large values will be overwritten by a saner default.
Expand Down Expand Up @@ -783,7 +783,26 @@ pub enum QueryMsg {
},
}

#[cw_serde]
pub struct AffectedDelegator {
pub address: String,
pub missing_ratio: Decimal,
}

#[cw_serde]
pub struct AffectedNode {
pub mix_id: MixId,
pub delegators: Vec<AffectedDelegator>,
}

impl AffectedNode {
pub fn total_ratio(&self) -> Decimal {
self.delegators.iter().map(|d| d.missing_ratio).sum()
}
}

#[cw_serde]
pub struct MigrateMsg {
pub vesting_contract_address: Option<String>,
pub fix_nodes: Option<Vec<AffectedNode>>,
}
6 changes: 4 additions & 2 deletions contracts/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ pub fn instantiate_contracts(
mixnet_contract_address.clone(),
&nym_mixnet_contract_common::MigrateMsg {
vesting_contract_address: Some(vesting_contract_address.to_string()),
fix_nodes: None,
},
mixnet_code_id,
)
Expand Down
1 change: 1 addition & 0 deletions contracts/mixnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ time = { version = "0.3", features = ["macros"] }

[dev-dependencies]
rand_chacha = "0.3"
rand = "0.8.5"
nym-crypto = { path = "../../common/crypto", features = ["asymmetric", "rand"] }

[features]
Expand Down
56 changes: 54 additions & 2 deletions contracts/mixnet/schema/nym-mixnet-contract.json
Original file line number Diff line number Diff line change
Expand Up @@ -2150,7 +2150,7 @@
"minimum": 0.0
},
"owner": {
"description": "The address of the owner of the the mixnodes used for the query.",
"description": "The address of the owner of the mixnodes used for the query.",
"type": "string"
},
"start_after": {
Expand Down Expand Up @@ -2961,14 +2961,66 @@
"title": "MigrateMsg",
"type": "object",
"properties": {
"fix_nodes": {
"type": [
"array",
"null"
],
"items": {
"$ref": "#/definitions/AffectedNode"
}
},
"vesting_contract_address": {
"type": [
"string",
"null"
]
}
},
"additionalProperties": false
"additionalProperties": false,
"definitions": {
"AffectedDelegator": {
"type": "object",
"required": [
"address",
"missing_ratio"
],
"properties": {
"address": {
"type": "string"
},
"missing_ratio": {
"$ref": "#/definitions/Decimal"
}
},
"additionalProperties": false
},
"AffectedNode": {
"type": "object",
"required": [
"delegators",
"mix_id"
],
"properties": {
"delegators": {
"type": "array",
"items": {
"$ref": "#/definitions/AffectedDelegator"
}
},
"mix_id": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
},
"Decimal": {
"description": "A fixed-point decimal value with 18 fractional digits, i.e. Decimal(1_000_000_000_000_000_000) == 1.0\n\nThe greatest possible value that can be represented is 340282366920938463463.374607431768211455 (which is (2^128 - 1) / 10^18)",
"type": "string"
}
}
},
"sudo": null,
"responses": {
Expand Down
54 changes: 53 additions & 1 deletion contracts/mixnet/schema/raw/migrate.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,64 @@
"title": "MigrateMsg",
"type": "object",
"properties": {
"fix_nodes": {
"type": [
"array",
"null"
],
"items": {
"$ref": "#/definitions/AffectedNode"
}
},
"vesting_contract_address": {
"type": [
"string",
"null"
]
}
},
"additionalProperties": false
"additionalProperties": false,
"definitions": {
"AffectedDelegator": {
"type": "object",
"required": [
"address",
"missing_ratio"
],
"properties": {
"address": {
"type": "string"
},
"missing_ratio": {
"$ref": "#/definitions/Decimal"
}
},
"additionalProperties": false
},
"AffectedNode": {
"type": "object",
"required": [
"delegators",
"mix_id"
],
"properties": {
"delegators": {
"type": "array",
"items": {
"$ref": "#/definitions/AffectedDelegator"
}
},
"mix_id": {
"type": "integer",
"format": "uint32",
"minimum": 0.0
}
},
"additionalProperties": false
},
"Decimal": {
"description": "A fixed-point decimal value with 18 fractional digits, i.e. Decimal(1_000_000_000_000_000_000) == 1.0\n\nThe greatest possible value that can be represented is 340282366920938463463.374607431768211455 (which is (2^128 - 1) / 10^18)",
"type": "string"
}
}
}
2 changes: 1 addition & 1 deletion contracts/mixnet/schema/raw/query.json
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@
"minimum": 0.0
},
"owner": {
"description": "The address of the owner of the the mixnodes used for the query.",
"description": "The address of the owner of the mixnodes used for the query.",
"type": "string"
},
"start_after": {
Expand Down
13 changes: 10 additions & 3 deletions contracts/mixnet/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::constants::{INITIAL_GATEWAY_PLEDGE_AMOUNT, INITIAL_MIXNODE_PLEDGE_AMO
use crate::interval::storage as interval_storage;
use crate::mixnet_contract_settings::storage as mixnet_params_storage;
use crate::mixnodes::storage as mixnode_storage;
use crate::queued_migrations;
use crate::rewards::storage as rewards_storage;
use cosmwasm_std::{
entry_point, to_binary, Addr, Coin, Deps, DepsMut, Env, MessageInfo, QueryResponse, Response,
Expand Down Expand Up @@ -272,7 +273,7 @@ pub fn execute(
crate::vesting_migration::try_migrate_vested_mixnode(deps, info)
}
ExecuteMsg::MigrateVestedDelegation { mix_id } => {
crate::vesting_migration::try_migrate_vested_delegation(deps, info, mix_id)
crate::vesting_migration::try_migrate_vested_delegation(deps, env, info, mix_id)
}

// legacy vesting
Expand Down Expand Up @@ -539,7 +540,7 @@ pub fn query(
#[entry_point]
pub fn migrate(
deps: DepsMut<'_>,
_env: Env,
env: Env,
msg: MigrateMsg,
) -> Result<Response, MixnetContractError> {
set_build_information!(deps.storage)?;
Expand All @@ -555,7 +556,13 @@ pub fn migrate(
mixnet_params_storage::CONTRACT_STATE.save(deps.storage, &current_state)?;
}

Ok(Default::default())
let mut response = Response::new();

if let Some(nodes_to_fix) = msg.fix_nodes {
queued_migrations::restore_vested_delegations(&mut response, deps, env, nodes_to_fix)?;
}

Ok(response)
}

#[cfg(test)]
Expand Down
Loading