diff --git a/Cargo.lock b/Cargo.lock index 10582a60e6..bec364ced3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -581,7 +581,7 @@ dependencies = [ [[package]] name = "client-core" -version = "1.0.0-rc.1" +version = "1.0.0-rc.2" dependencies = [ "config", "crypto", @@ -1594,7 +1594,7 @@ dependencies = [ [[package]] name = "explorer-api" -version = "1.0.0-rc.1" +version = "1.0.0-rc.2" dependencies = [ "chrono", "humantime-serde", @@ -3043,7 +3043,7 @@ dependencies = [ [[package]] name = "nym-client" -version = "1.0.0-rc.1" +version = "1.0.0-rc.2" dependencies = [ "clap 2.34.0", "client-core", @@ -3078,7 +3078,7 @@ dependencies = [ [[package]] name = "nym-gateway" -version = "1.0.0-rc.1" +version = "1.0.0-rc.2" dependencies = [ "anyhow", "async-trait", @@ -3124,7 +3124,7 @@ dependencies = [ [[package]] name = "nym-mixnode" -version = "1.0.0-rc.1" +version = "1.0.0-rc.2" dependencies = [ "anyhow", "bs58", @@ -3162,7 +3162,7 @@ dependencies = [ [[package]] name = "nym-network-requester" -version = "1.0.0-rc.1" +version = "1.0.0-rc.2" dependencies = [ "clap 2.34.0", "dirs", @@ -3183,7 +3183,7 @@ dependencies = [ [[package]] name = "nym-socks5-client" -version = "1.0.0-rc.1" +version = "1.0.0-rc.2" dependencies = [ "clap 2.34.0", "client-core", @@ -3219,7 +3219,7 @@ dependencies = [ [[package]] name = "nym-validator-api" -version = "1.0.0-rc.1" +version = "1.0.0-rc.2" dependencies = [ "anyhow", "async-trait", diff --git a/Makefile b/Makefile index 3d87c659b5..cabf711c99 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ clippy-all-wallet: cargo clippy --workspace --manifest-path nym-wallet/Cargo.toml --all-features -- -D warnings test-main: - cargo test --all-features --workspace + cargo test --all-features --workspace --release test-contracts: cargo test --manifest-path contracts/Cargo.toml --all-features diff --git a/clients/client-core/Cargo.toml b/clients/client-core/Cargo.toml index 9b2cdaf2c7..dae8290d0d 100644 --- a/clients/client-core/Cargo.toml +++ b/clients/client-core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "client-core" -version = "1.0.0-rc.1" +version = "1.0.0-rc.2" authors = ["Dave Hrycyszyn "] edition = "2021" diff --git a/clients/native/Cargo.toml b/clients/native/Cargo.toml index a0692eda1b..d08b2281f5 100644 --- a/clients/native/Cargo.toml +++ b/clients/native/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "nym-client" -version = "1.0.0-rc.1" +version = "1.0.0-rc.2" authors = ["Dave Hrycyszyn ", "Jędrzej Stuczyński "] edition = "2021" rust-version = "1.56" diff --git a/clients/socks5/Cargo.toml b/clients/socks5/Cargo.toml index 24771d1b6a..e0a52c131f 100644 --- a/clients/socks5/Cargo.toml +++ b/clients/socks5/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "nym-socks5-client" -version = "1.0.0-rc.1" +version = "1.0.0-rc.2" authors = ["Dave Hrycyszyn "] edition = "2021" rust-version = "1.56" diff --git a/clients/webassembly/Cargo.toml b/clients/webassembly/Cargo.toml index 77aadd6ef3..bf35c6076c 100644 --- a/clients/webassembly/Cargo.toml +++ b/clients/webassembly/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "nym-client-wasm" authors = ["Dave Hrycyszyn ", "Jedrzej Stuczynski "] -version = "1.0.0-rc.1" +version = "1.0.0-rc.2" edition = "2021" keywords = ["nym", "sphinx", "wasm", "webassembly", "privacy", "client"] license = "Apache-2.0" diff --git a/common/network-defaults/src/mainnet.rs b/common/network-defaults/src/mainnet.rs index c8f46de121..98b5f7044a 100644 --- a/common/network-defaults/src/mainnet.rs +++ b/common/network-defaults/src/mainnet.rs @@ -21,6 +21,6 @@ pub(crate) const REWARDING_VALIDATOR_ADDRESS: &str = "n10yyd98e2tuwu0f7ypz9dy3hh pub(crate) fn validators() -> Vec { vec![ValidatorDetails::new( "https://rpc.nyx.nodes.guru/", - Some("https://api.nyx.nodes.guru/"), + Some("https://validator.nymtech.net/api"), )] } diff --git a/contracts/Cargo.lock b/contracts/Cargo.lock index 5a2f7c1752..f2384aaa4f 100644 --- a/contracts/Cargo.lock +++ b/contracts/Cargo.lock @@ -41,7 +41,7 @@ checksum = "f771a5d1f5503f7f4279a30f3643d3421ba149848b89ecaaec0ea2acf04a5ac4" [[package]] name = "bandwidth-claim" -version = "1.0.0-rc.1" +version = "1.0.0-rc.2" dependencies = [ "bandwidth-claim-contract", "config", diff --git a/contracts/bandwidth-claim/Cargo.toml b/contracts/bandwidth-claim/Cargo.toml index 670f3f0809..babaf618d3 100644 --- a/contracts/bandwidth-claim/Cargo.toml +++ b/contracts/bandwidth-claim/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bandwidth-claim" -version = "1.0.0-rc.1" +version = "1.0.0-rc.2" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/contracts/mixnet/src/contract.rs b/contracts/mixnet/src/contract.rs index 0dc0fffc28..a81e0b538a 100644 --- a/contracts/mixnet/src/contract.rs +++ b/contracts/mixnet/src/contract.rs @@ -30,12 +30,10 @@ use crate::rewards::queries::{ }; use crate::rewards::storage as rewards_storage; use cosmwasm_std::{ - entry_point, to_binary, Addr, Deps, DepsMut, Env, MessageInfo, QueryResponse, Response, - Storage, Uint128, + entry_point, to_binary, Addr, Deps, DepsMut, Env, MessageInfo, QueryResponse, Response, Uint128, }; -use cw_storage_plus::PrimaryKey; use mixnet_contract_common::{ - ContractStateParams, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, SphinxKey, + ContractStateParams, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, }; use time::OffsetDateTime; @@ -386,87 +384,7 @@ pub fn query(deps: Deps<'_>, env: Env, msg: QueryMsg) -> Result, _env: Env, _msg: MigrateMsg) -> Result { - use crate::mixnodes::storage::StoredMixnodeBond; - use cw_storage_plus::{Index, IndexList, IndexedSnapshotMap, Strategy, UniqueIndex}; - use mixnet_contract_common::{Addr, IdentityKeyRef}; - - const MIXNODES_PK_NAMESPACE: &str = "mn"; - const MIXNODES_PK_CHECKPOINTS: &str = "mn__check"; - const MIXNODES_PK_CHANGELOG: &str = "mn__change"; - const MIXNODES_OWNER_IDX_NAMESPACE: &str = "mno"; - const MIXNODES_SPHINX_IDX_NAMESPACE: &str = "mns"; - - pub(crate) struct MixnodeBondIndex<'a> { - pub(crate) owner: UniqueIndex<'a, Addr, StoredMixnodeBond>, - } - - impl<'a> IndexList for MixnodeBondIndex<'a> { - fn get_indexes( - &'_ self, - ) -> Box> + '_> { - let v: Vec<&dyn Index> = vec![&self.owner]; - Box::new(v.into_iter()) - } - } - - pub(crate) fn old_mixnodes<'a>( - ) -> IndexedSnapshotMap<'a, IdentityKeyRef<'a>, StoredMixnodeBond, MixnodeBondIndex<'a>> { - let indexes = MixnodeBondIndex { - owner: UniqueIndex::new(|d| d.owner.clone(), MIXNODES_OWNER_IDX_NAMESPACE), - }; - IndexedSnapshotMap::new( - MIXNODES_PK_NAMESPACE, - MIXNODES_PK_CHECKPOINTS, - MIXNODES_PK_CHANGELOG, - Strategy::Never, - indexes, - ) - } - - const PAGE_SIZE: usize = 50; - - fn migrate_page( - store: &mut dyn Storage, - start_after: Option, - index: &mut UniqueIndex<'_, SphinxKey, StoredMixnodeBond>, - ) -> Option { - let start = start_after - .as_deref() - .map(cw_storage_plus::Bound::exclusive); - - let page: Vec<_> = old_mixnodes() - .range(store, start, None, cosmwasm_std::Order::Ascending) - .map(|v| v.expect("failed to deserialize stored mixnode")) - .collect(); - - let last_pk = if page.len() == PAGE_SIZE { - Some(page.last().unwrap().0.clone()) - } else { - None - }; - - for (pk, mix) in page { - index - .save(store, &pk.joined_key(), &mix) - .expect("failed to save new index information"); - } - - last_pk - } - - // attempt to just add indices, see how it works out - let mut sphinx_index: UniqueIndex<'_, SphinxKey, StoredMixnodeBond> = UniqueIndex::new( - |d| d.mix_node.sphinx_key.clone(), - MIXNODES_SPHINX_IDX_NAMESPACE, - ); - - let mut start_after = None; - - while let Some(new_start) = migrate_page(deps.storage, start_after.clone(), &mut sphinx_index) { - start_after = Some(new_start) - } - +pub fn migrate(_deps: DepsMut<'_>, _env: Env, _msg: MigrateMsg) -> Result { Ok(Default::default()) } @@ -510,216 +428,4 @@ pub mod tests { tests::queries::query_contract_balance(env.contract.address, deps) ); } - - #[cfg(test)] - mod migration { - use super::*; - use crate::mixnodes::storage::{mixnodes, StoredMixnodeBond}; - use crate::support::tests::test_helpers; - use cw_storage_plus::{Index, IndexList, IndexedSnapshotMap, Strategy, UniqueIndex}; - use mixnet_contract_common::{Addr, IdentityKeyRef, Layer, MixNode}; - use rand::thread_rng; - - const MIXNODES_PK_NAMESPACE: &str = "mn"; - const MIXNODES_PK_CHECKPOINTS: &str = "mn__check"; - const MIXNODES_PK_CHANGELOG: &str = "mn__change"; - const MIXNODES_OWNER_IDX_NAMESPACE: &str = "mno"; - - pub(crate) struct MixnodeBondIndex<'a> { - pub(crate) owner: UniqueIndex<'a, Addr, StoredMixnodeBond>, - } - - // IndexList is just boilerplate code for fetching a struct's indexes - // note that from my understanding this will be converted into a macro at some point in the future - impl<'a> IndexList for MixnodeBondIndex<'a> { - fn get_indexes( - &'_ self, - ) -> Box> + '_> { - let v: Vec<&dyn Index> = vec![&self.owner]; - Box::new(v.into_iter()) - } - } - - pub(crate) fn old_mixnodes<'a>( - ) -> IndexedSnapshotMap<'a, IdentityKeyRef<'a>, StoredMixnodeBond, MixnodeBondIndex<'a>> - { - let indexes = MixnodeBondIndex { - owner: UniqueIndex::new(|d| d.owner.clone(), MIXNODES_OWNER_IDX_NAMESPACE), - }; - IndexedSnapshotMap::new( - MIXNODES_PK_NAMESPACE, - MIXNODES_PK_CHECKPOINTS, - MIXNODES_PK_CHANGELOG, - Strategy::Never, - indexes, - ) - } - - fn change_stored_bond(store: &mut dyn Storage, key: &str, height: u64) { - // just to have something changing, update ports to some stupid values - let mut old = old_mixnodes().load(store, key).unwrap(); - old.mix_node.mix_port += 1; - old.mix_node.verloc_port -= 1; - - let reward = old.accumulated_rewards.unwrap_or_default(); - old.accumulated_rewards = Some(reward + Uint128::new(42)); - - old_mixnodes().save(store, key, &old, height).unwrap() - } - - fn bond_old_mixnode( - store: &mut dyn Storage, - sender: &str, - height: u64, - ) -> (String, String) { - let keypair = crypto::asymmetric::identity::KeyPair::new(&mut thread_rng()); - let legit_sphix = crypto::asymmetric::encryption::KeyPair::new(&mut thread_rng()); - let key = keypair.public_key().to_base58_string(); - let key2 = legit_sphix.public_key().to_base58_string(); - - old_mixnodes() - .save( - store, - &key, - &StoredMixnodeBond { - pledge_amount: Default::default(), - owner: Addr::unchecked(sender), - layer: Layer::One, - block_height: height, - mix_node: MixNode { - host: "1.2.3.4".to_string(), - mix_port: 1234, - verloc_port: 1234, - http_api_port: 123, - sphinx_key: key2.clone(), - identity_key: key.clone(), - version: "1.2.3".to_string(), - profit_margin_percent: 42, - }, - proxy: None, - accumulated_rewards: None, - epoch_rewards: None, - }, - height, - ) - .unwrap(); - - (key, key2) - } - - #[test] - fn empty() { - let mut deps = test_helpers::init_contract(); - let env = mock_env(); - assert!(migrate(deps.as_mut(), env, MigrateMsg {}).is_ok()) - } - - fn check_mixnode(storage: &dyn Storage, owner: Addr, id: &str, expected_sphinx: &str) { - assert_eq!( - mixnodes().load(storage, &id).unwrap().mix_node.sphinx_key, - expected_sphinx - ); - assert_eq!( - mixnodes() - .idx - .owner - .item(storage, owner) - .unwrap() - .unwrap() - .1 - .mix_node - .sphinx_key, - expected_sphinx - ); - assert_eq!( - mixnodes() - .idx - .sphinx_key - .item(storage, expected_sphinx.to_owned()) - .unwrap() - .unwrap() - .1 - .mix_node - .sphinx_key, - expected_sphinx - ); - } - - #[test] - fn single_bond() { - let mut deps = test_helpers::init_contract(); - let env = mock_env(); - - let (id, sphinx) = bond_old_mixnode(deps.as_mut().storage, "bob", 42); - - assert!(migrate(deps.as_mut(), env, MigrateMsg {}).is_ok()); - check_mixnode(deps.as_ref().storage, Addr::unchecked("bob"), &id, &sphinx); - } - - #[test] - fn multiple_bonds() { - let mut deps = test_helpers::init_contract(); - let env = mock_env(); - - let (id1, sphinx1) = bond_old_mixnode(deps.as_mut().storage, "bob", 42); - let (id2, sphinx2) = bond_old_mixnode(deps.as_mut().storage, "alice", 43); - let (id3, sphinx3) = bond_old_mixnode(deps.as_mut().storage, "eve", 44); - - assert!(migrate(deps.as_mut(), env, MigrateMsg {}).is_ok()); - check_mixnode( - deps.as_ref().storage, - Addr::unchecked("bob"), - &id1, - &sphinx1, - ); - check_mixnode( - deps.as_ref().storage, - Addr::unchecked("alice"), - &id2, - &sphinx2, - ); - check_mixnode( - deps.as_ref().storage, - Addr::unchecked("eve"), - &id3, - &sphinx3, - ); - } - - #[test] - fn multiple_bonds_with_history() { - let mut deps = test_helpers::init_contract(); - let env = mock_env(); - - let (id1, sphinx1) = bond_old_mixnode(deps.as_mut().storage, "bob", 42); - let (id2, sphinx2) = bond_old_mixnode(deps.as_mut().storage, "alice", 43); - let (id3, sphinx3) = bond_old_mixnode(deps.as_mut().storage, "eve", 44); - - // make alice change her bond multiple times - change_stored_bond(deps.as_mut().storage, &id2, 1234); - change_stored_bond(deps.as_mut().storage, &id2, 4326); - change_stored_bond(deps.as_mut().storage, &id2, 432576); - change_stored_bond(deps.as_mut().storage, &id2, 5474746); - - assert!(migrate(deps.as_mut(), env, MigrateMsg {}).is_ok()); - check_mixnode( - deps.as_ref().storage, - Addr::unchecked("bob"), - &id1, - &sphinx1, - ); - check_mixnode( - deps.as_ref().storage, - Addr::unchecked("alice"), - &id2, - &sphinx2, - ); - check_mixnode( - deps.as_ref().storage, - Addr::unchecked("eve"), - &id3, - &sphinx3, - ); - } - } } diff --git a/contracts/mixnet/src/interval/transactions.rs b/contracts/mixnet/src/interval/transactions.rs index 83428bafaf..ba2e63daeb 100644 --- a/contracts/mixnet/src/interval/transactions.rs +++ b/contracts/mixnet/src/interval/transactions.rs @@ -27,9 +27,8 @@ pub fn try_write_rewarded_set( return Err(ContractError::Unauthorized); } - // sanity check to make sure the sending validator is in sync with the contract state - // (i.e. so that we'd known that top k nodes are actually expected to be active) - if active_set_size != state.params.mixnode_active_set_size { + // We don't want more then we need, less should be fine, as we could have less nodes bonded overall + if active_set_size > state.params.mixnode_active_set_size { return Err(ContractError::UnexpectedActiveSetSize { received: active_set_size, expected: state.params.mixnode_active_set_size, @@ -43,15 +42,16 @@ pub fn try_write_rewarded_set( }); } - let last_update = storage::CURRENT_REWARDED_SET_HEIGHT.load(deps.storage)?; let block_height = env.block.height; - if last_update + crate::constants::REWARDED_SET_REFRESH_BLOCKS > block_height { - return Err(ContractError::TooFrequentRewardedSetUpdate { - last_update, - minimum_delay: crate::constants::REWARDED_SET_REFRESH_BLOCKS, - current_height: block_height, - }); + if let Some(last_update) = storage::CURRENT_REWARDED_SET_HEIGHT.may_load(deps.storage)? { + if last_update + crate::constants::REWARDED_SET_REFRESH_BLOCKS > block_height { + return Err(ContractError::TooFrequentRewardedSetUpdate { + last_update, + minimum_delay: crate::constants::REWARDED_SET_REFRESH_BLOCKS, + current_height: block_height, + }); + } } let num_nodes = rewarded_set.len(); diff --git a/explorer-api/Cargo.toml b/explorer-api/Cargo.toml index 39fcd654dd..d281ac81d6 100644 --- a/explorer-api/Cargo.toml +++ b/explorer-api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "explorer-api" -version = "1.0.0-rc.1" +version = "1.0.0-rc.2" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/gateway/Cargo.toml b/gateway/Cargo.toml index e304bb4dc4..3e0b7b6f08 100644 --- a/gateway/Cargo.toml +++ b/gateway/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "nym-gateway" -version = "1.0.0-rc.1" +version = "1.0.0-rc.2" authors = ["Dave Hrycyszyn ", "Jędrzej Stuczyński "] description = "Implementation of the Nym Mixnet Gateway" edition = "2021" diff --git a/mixnode/Cargo.toml b/mixnode/Cargo.toml index 0166209753..91473d8226 100644 --- a/mixnode/Cargo.toml +++ b/mixnode/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "nym-mixnode" -version = "1.0.0-rc.1" +version = "1.0.0-rc.2" authors = [ "Dave Hrycyszyn ", "Jędrzej Stuczyński ", diff --git a/nym-wallet/src/pages/settings/useSettingsState.ts b/nym-wallet/src/pages/settings/useSettingsState.ts index 1be1bd15b6..dc42750a4c 100644 --- a/nym-wallet/src/pages/settings/useSettingsState.ts +++ b/nym-wallet/src/pages/settings/useSettingsState.ts @@ -1,7 +1,7 @@ import { useContext, useEffect, useState } from 'react'; import { ClientContext } from '../../context/main'; import { - getMixnodeRewardEstimation, +// getMixnodeRewardEstimation, getMixnodeStakeSaturation, getMixnodeStatus, minorToMajor, @@ -33,14 +33,6 @@ export const useSettingsState = (shouldUpdate: boolean) => { } }; - const getRewardEstimation = async (mixnodeKey: string) => { - const newRewardEstimation = await getMixnodeRewardEstimation(mixnodeKey); - if (newRewardEstimation) { - const toMajor = await minorToMajor(newRewardEstimation.estimated_total_node_reward.toString()); - setRewardEstimation(parseInt(toMajor.amount, Number(10))); - } - }; - const getMixnodeInclusionProbability = async (mixnodeKey: string) => { const probability = await getInclusionProbability(mixnodeKey); if (probability) { @@ -64,7 +56,6 @@ export const useSettingsState = (shouldUpdate: boolean) => { (async () => { await getStatus(mixnodeDetails?.mix_node.identity_key); await getStakeSaturation(mixnodeDetails?.mix_node.identity_key); - await getRewardEstimation(mixnodeDetails?.mix_node.identity_key); await getMixnodeInclusionProbability(mixnodeDetails?.mix_node.identity_key); })(); } else { diff --git a/nym-wallet/src/requests/queries.ts b/nym-wallet/src/requests/queries.ts index 8772214948..6ccd6111ef 100644 --- a/nym-wallet/src/requests/queries.ts +++ b/nym-wallet/src/requests/queries.ts @@ -6,7 +6,7 @@ import { InclusionProbabilityResponse, MixnodeStatusResponse, Operation, - RewardEstimationResponse, + // RewardEstimationResponse, StakeSaturationResponse, TMixnodeBondDetails, TPagedDelegations, @@ -38,11 +38,6 @@ export const getMixnodeStakeSaturation = async (identity: string): Promise => { - const res: RewardEstimationResponse = await invoke('mixnode_reward_estimation', { identity }); - return res; -}; - export const getMixnodeStatus = async (identity: string): Promise => { const res: MixnodeStatusResponse = await invoke('mixnode_status', { identity }); return res; diff --git a/nym-wallet/src/types/rust/index.ts b/nym-wallet/src/types/rust/index.ts index d82e3f75c5..a18c302a33 100644 --- a/nym-wallet/src/types/rust/index.ts +++ b/nym-wallet/src/types/rust/index.ts @@ -12,7 +12,6 @@ export * from './network'; export * from './operation'; export * from './originalvestingresponse'; export * from './rewardedsetnodestatus'; -export * from './rewardestimationresponse'; export * from './stakesaturationresponse'; export * from './stateparams'; export * from './tauritxresult'; diff --git a/service-providers/network-requester/Cargo.toml b/service-providers/network-requester/Cargo.toml index 6f8990388b..7a24cb7ec2 100644 --- a/service-providers/network-requester/Cargo.toml +++ b/service-providers/network-requester/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "nym-network-requester" -version = "1.0.0-rc.1" +version = "1.0.0-rc.2" authors = ["Dave Hrycyszyn ", "Jędrzej Stuczyński "] edition = "2021" diff --git a/validator-api/Cargo.toml b/validator-api/Cargo.toml index 8a29473d50..52bdfcdce8 100644 --- a/validator-api/Cargo.toml +++ b/validator-api/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "nym-validator-api" -version = "1.0.0-rc.1" +version = "1.0.0-rc.2" authors = [ "Dave Hrycyszyn ", "Jędrzej Stuczyński ",