Skip to content

Commit

Permalink
fixed linter issues and outdated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jstuczyn committed Oct 10, 2024
1 parent f76d677 commit 45f4eee
Show file tree
Hide file tree
Showing 28 changed files with 581 additions and 412 deletions.
88 changes: 88 additions & 0 deletions 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 @@ -732,7 +732,6 @@ where
mod tests {
use super::*;
use crate::nyxd::contract_traits::tests::IgnoreValue;
use nym_mixnet_contract_common::QueryMsg;

// it's enough that this compiles and clippy is happy about it
#[allow(dead_code)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -845,13 +845,6 @@ mod tests {
client.update_nymnode_config(update, None).ignore()
}

ExecuteMsg::TestingUncheckedBondLegacyMixnode { .. } => {
todo!("purposely not implemented")
}
ExecuteMsg::TestingUncheckedBondLegacyGateway { .. } => {
todo!("purposely not implemented")
}

#[cfg(feature = "contract-testing")]
MixnetExecuteMsg::TestingResolveAllPendingEvents { .. } => {
client.testing_resolve_all_pending_events(None).ignore()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@
// SPDX-License-Identifier: Apache-2.0

use crate::context::SigningClient;
use anyhow::anyhow;
use crate::validator::mixnet::operators::nymnode;
use clap::Parser;
use cosmwasm_std::Uint128;
use log::info;
use nym_mixnet_contract_common::{NodeCostParams, Percent};
use nym_validator_client::nyxd::contract_traits::{MixnetQueryClient, MixnetSigningClient};
use nym_validator_client::nyxd::CosmWasmCoin;

#[derive(Debug, Parser)]
pub struct Args {
Expand All @@ -26,48 +21,13 @@ pub struct Args {
}

pub async fn update_cost_params(args: Args, client: SigningClient) -> anyhow::Result<()> {
let denom = client.current_chain_details().mix_denom.base.as_str();

let current_parameters = if let Some(client_mixnode) = client
.get_owned_mixnode(&client.address())
.await?
.mixnode_details
{
client_mixnode.rewarding_details.cost_params
} else {
client
.get_owned_nymnode(&client.address())
.await?
.details
.ok_or_else(|| anyhow!("the client does not own any nodes"))?
.rewarding_details
.cost_params
};

let profit_margin_percent = args
.profit_margin_percent
.map(|pm| Percent::from_percentage_value(pm as u64))
.unwrap_or(Ok(current_parameters.profit_margin_percent))?;

let interval_operating_cost = args
.interval_operating_cost
.map(|oc| CosmWasmCoin {
denom: denom.into(),
amount: Uint128::new(oc),
})
.unwrap_or(current_parameters.interval_operating_cost);

let cost_params = NodeCostParams {
profit_margin_percent,
interval_operating_cost,
};

info!("Starting cost params updating using {cost_params:?} !");
let res = client
.update_cost_params(cost_params, None)
.await
.expect("failed to update cost params");

info!("Cost params result: {:?}", res);
Ok(())
// the below can handle both, nymnode and legacy mixnode
nymnode::settings::update_cost_params::update_cost_params(
nymnode::settings::update_cost_params::Args {
profit_margin_percent: args.profit_margin_percent,
interval_operating_cost: args.interval_operating_cost,
},
client,
)
.await
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use anyhow::anyhow;
use clap::Parser;
use cosmwasm_std::Uint128;
use log::info;
use nym_mixnet_contract_common::{
NodeCostParams, Percent, DEFAULT_INTERVAL_OPERATING_COST_AMOUNT, DEFAULT_PROFIT_MARGIN_PERCENT,
};
use nym_mixnet_contract_common::{NodeCostParams, Percent};
use nym_validator_client::nyxd::contract_traits::{MixnetQueryClient, MixnetSigningClient};
use nym_validator_client::nyxd::CosmWasmCoin;

Expand All @@ -18,7 +16,7 @@ pub struct Args {
long,
help = "input your profit margin as follows; (so it would be 20, rather than 0.2)"
)]
pub profit_margin_percent: Option<u64>,
pub profit_margin_percent: Option<u8>,

#[clap(
long,
Expand All @@ -30,37 +28,41 @@ pub struct Args {
pub async fn update_cost_params(args: Args, client: SigningClient) -> anyhow::Result<()> {
let denom = client.current_chain_details().mix_denom.base.as_str();

let default_profit_margin =
Percent::from_percentage_value(DEFAULT_PROFIT_MARGIN_PERCENT).unwrap();

let node_details = client
.get_owned_nymnode(&client.address())
let current_parameters = if let Some(client_mixnode) = client
.get_owned_mixnode(&client.address())
.await?
.details
.ok_or_else(|| anyhow!("the client does not own any nodes"))?;
let current_parameters = node_details.rewarding_details.cost_params;

let profit_margin_percent = current_parameters
.map(|rd| rd.cost_params.profit_margin_percent)
.unwrap_or(default_profit_margin);
.mixnode_details
{
client_mixnode.rewarding_details.cost_params
} else {
client
.get_owned_nymnode(&client.address())
.await?
.details
.ok_or_else(|| anyhow!("the client does not own any nodes"))?
.rewarding_details
.cost_params
};

let profit_margin_value = args
let profit_margin_percent = args
.profit_margin_percent
.map(|pm| Percent::from_percentage_value(pm as u64))
.unwrap_or(profit_margin_percent)?;
.unwrap_or(Ok(current_parameters.profit_margin_percent))?;

let cost_params = NodeCostParams {
profit_margin_percent: profit_margin_value,
interval_operating_cost: CosmWasmCoin {
let interval_operating_cost = args
.interval_operating_cost
.map(|oc| CosmWasmCoin {
denom: denom.into(),
amount: Uint128::new(
args.interval_operating_cost
.unwrap_or(DEFAULT_INTERVAL_OPERATING_COST_AMOUNT),
),
},
amount: Uint128::new(oc),
})
.unwrap_or(current_parameters.interval_operating_cost);

let cost_params = NodeCostParams {
profit_margin_percent,
interval_operating_cost,
};

info!("Starting nym node params updating!");
info!("Starting cost params updating using {cost_params:?} !");
let res = client
.update_cost_params(cost_params, None)
.await
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ impl ContractBuildInformation {
#[cfg(test)]
mod tests {
use super::*;
use cosmwasm_std::Fraction;

#[test]
fn percent_serde() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ impl Interval {
}

pub fn ensure_current_epoch_is_over(&self, env: &Env) -> Result<(), MixnetContractError> {
if !self.is_current_epoch_over(&env) {
if !self.is_current_epoch_over(env) {
return Err(MixnetContractError::EpochInProgress {
current_block_time: env.block.time.seconds(),
epoch_start: self.current_epoch_start_unix_timestamp(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ impl NymNodeDetails {
}
}

///
#[cw_serde]
pub struct NymNodeBond {
/// Unique id assigned to the bonded node.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,3 @@ pub fn truncate_reward(reward: Decimal, denom: impl Into<String>) -> Coin {
pub fn truncate_reward_amount(reward: Decimal) -> Uint128 {
truncate_decimal(reward)
}

pub fn legacy_standby_work_factor() -> Decimal {
todo!()
}

pub fn legacy_active_work_factor() -> Decimal {
todo!()
}
5 changes: 1 addition & 4 deletions common/nymsphinx/src/receiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ mod message_receiver {
1,
vec![mix::LegacyNode {
mix_id: 123,
owner: None,
host: "10.20.30.40".parse().unwrap(),
mix_host: "10.20.30.40:1789".parse().unwrap(),
identity_key: identity::PublicKey::from_base58_string(
Expand All @@ -255,7 +254,6 @@ mod message_receiver {
2,
vec![mix::LegacyNode {
mix_id: 234,
owner: None,
host: "11.21.31.41".parse().unwrap(),
mix_host: "11.21.31.41:1789".parse().unwrap(),
identity_key: identity::PublicKey::from_base58_string(
Expand All @@ -275,7 +273,6 @@ mod message_receiver {
3,
vec![mix::LegacyNode {
mix_id: 456,
owner: None,
host: "12.22.32.42".parse().unwrap(),
mix_host: "12.22.32.42:1789".parse().unwrap(),
identity_key: identity::PublicKey::from_base58_string(
Expand All @@ -295,7 +292,7 @@ mod message_receiver {
// currently coco_nodes don't really exist so this is still to be determined
mixes,
vec![gateway::LegacyNode {
owner: None,
node_id: 789,
host: "1.2.3.4".parse().unwrap(),
mix_host: "1.2.3.4:1789".parse().unwrap(),
clients_ws_port: 9000,
Expand Down
Loading

0 comments on commit 45f4eee

Please sign in to comment.