Feature/rewarding revamp (#1472)
* Query for node stake saturation * Queries for currently pending events * Rewarded set query * Moved ContractState to common types since it's being returned as a result of one of the queries on the mixnet contract and thus it needs to be accessible outside the contract itself * Cleaend up storage initialisation * started restoring unit tests * Removed attached 1ucoin for cross-contract execute msgs * wip * query for rewarding details of a mix node * Changes for mixnodes and gateways * Furher progress on v2 changelog(-ish) description * wip * first version of the description * mixnode bonding queries tests and fixes * ibid for storage * MixnodeEventType enum + created events for missing mixnode txs * tests for adding new mixnode * Additional mixnode-related tests + bug fixes * Display for Percent * Bunch of tests for try_reward_mixnode * More tests and fixes * ibid * tests for updating rewarding params + important bug fix * Started removing unused imports * rewarding queries tests + undelegation bugfix * A lot of todo()-ing and commenting out unimplemented code * implements https://github.com/nymtech/team-core/issues/113 * Delegation tests + fixes * Emiting events by top level interval txs + incorporating limit * question * Missing events emissions * removed some code duplication * wip * pending delegation tests * Vesting contract update * More tests (and fixes) for pending events txs * Restored gateway tx tests * Another cleanup iteration * removed redundant comment * Unit tests, fixes and simplifcations for interval-related txs * Unit tests for helper functions * Interval queries unit tests * Test for correct contract initialisation * Another round of cleanup * Work on mixnet_query_client trait * mixnet_signing_client trait * Removed redundant methods * Slowly restoring validator client functionality * Added deprecated query for mix details by identity * wip restoration of validator-api * Work on deprecating validator API routes * Further validator-api routes * Restored rest of status api routes * Resolved all todos in ValidatorApiStorage There's still bunch left in StorageManager though * Changed NodeId from u64 to u32 * Updating sql code * Network monitor internals * Changed behaviour of full_epoch_id and updated epoch operations * Fixed sql queries * [most likely] finished updating rest of the validator API * Post rebasing fixes * Feature/rewarding revamp explorer api changes (#1511) * Changed cache to allow for non-string keys * Helper method for best-effort conversion of pubkey to nodeid * Updated validator-api client routes * Updated routes to use mix-id indexing * Introduction of deprecated routes callable by identity key * Fixed mixnode compatibility by changing read node details fields (#1512) * Fixed bond to topology conversion for client compatibility (#1513) * Updated 'verify_gateway_owner' to use correct nymd_client method for obtaining gateway details (#1515) * Updated constructor for ValidatorCacheInner * Fixed wasm client topology construction * Run cargo fmt on the entire codebase * Feature/rewarding revamp wallet backend changes (#1529) * Updated mixnode-related ts types * Updated nym-wallet-types * Updated 'get_contract_settings' and commented out code of other tauri commands * 'update_contract_settings' * 'bond_gateway' * unbond_gateway' * Utility commands for the transition period * 'bond_mixnode' * 'unbond_mixnode' * Ability to update mixnode cost paramaters * Mixnode config update * Updated mixnode_bond_details It also returns a different underlying type now * Updated 'gateway_bond_details' * Obtaining pending operator rewards * Improved way of obtaining number of mixnode delegators * simplified error handling in 'fetch_mix_node_description' * mixnode and gateway ownership queries * updated get_number_of_mixnode_delegators to use mix_id since we have the conversion utils helper * mixnode delegation * undelegating * Obtaining pending delegator rewards * Command for obtaining current interval details * Queries to handle paging for pending events * Additional level of indirection to pending events to incorporate event id into response * Wallet compatible pending event types * Commands fo obtaining pending events * Re-implemented pending delegation events * Further work on delegation * Removed unused imports * Commands for withdrawing rewards * Admin-related simulations * mixnet-related simulation commands * Validator-api related routes * Bond-related vesting operations * Vesting simulations * Vesting handler for UpdateMixnodeCostParams * Vesting reward claiming * Vesting queries * claim_locked_and_unlocked_delegator_reward * The massive delegation query * cleanup * updated typescript requests * sorted the new type exports in ts-rs-cli * Regenerated typescript types * temporarily ignoring unreachable code in vesting migration * Updated missed test fixture * Fixed missing coconut-specific import * cargo fmt * Exporting reward-related types * utility to convert stringified decimal to cosmjs Decimal * deriving Eq alongside PartialEq * wip - typescript fixes * using default operating cost when bonding mixnode * Using default operating cost when updating mixnode cost params * most delegation fixes * Wrapping delegation with node identity * Added MultiIndex on owner and identity key to unbonded mixnodes * Support for queries for unbonded nodes by owner or by identity key * Cargo fmt + ts types update * feature locking unused imports * fix(nym-wallet): typing and error (#1548) * post-rebase fixes * Changed storage key for new delegations map in vesting contract * fix(wallet): typing issues (#1562) * fix(wallet): error UI feedback (#1565) * clean(wallet): remove useless files (with flamethrowers 🔥) (#1567) * Changed default_mixnode_cost_params to allow accepting f32 instead * Revert "Changed default_mixnode_cost_params to allow accepting f32 instead" This reverts commitfb62a0014f. * Fixed APY calculation for 0 pledge value * Don't send rewarding transactions for empty rewarded set * Fixed mixnode rewarding in validator API * fix(nym-wallet): profit margin (#1574) * Correctly assigning Delegate event type to PendingEpochEventData::Delegate * Replaced 'history' in with 'pending_events' in DelegationWithEverything * Updated typescript side of things * Removed todo!() from vesting contract migration since its going to be dealt with differently * fix(nym-wallet): stake saturation and delegations (#1578) * fix(nym-wallet): stake saturation percentage * fix(nym-wallet): stake saturation percentage * Correctly assigning Delegate event type to PendingEpochEventData::Delegate * fix(nym-wallet): get rid of delegation history * Replaced 'history' in with 'pending_events' in DelegationWithEverything * Updated typescript side of things * Correctly assigning Delegate event type to PendingEpochEventData::Delegate * Replaced 'history' in with 'pending_events' in DelegationWithEverything * Updated typescript side of things * fix(nym-wallet): welcome back pending events and delegation menu * fix(nym-wallet): stake saturation percentage * fix(nym-wallet): stake saturation percentage * fix(nym-wallet): get rid of delegation history * Updated typescript side of things * fix(nym-wallet): welcome back pending events and delegation menu * fix(nym-wallet): fix clippy Co-authored-by: Jędrzej Stuczyński <jedrzej.stuczynski@gmail.com> * Updated vesting contract migration to update the mixnet contract address * feat(wallet): add confirmation/warning modal for unbonding * Post rebasing fixes * commented out all code * Bunch of work in progres, but working simulator * Removing redundant fields + increased precision to 9decimal places * deserialization of Percent with value validation * wip * Further moving things around + mixnode bonding * Mixnode unbonding * Starting restoration on contract state * Revamping interval * More work on epoch/interval * progress on mixnode rewarding * Moved MixNodeRewarding to rewards storage * wip on delegations * Removed concept of periods and historical records and moved cummulative reward ratio directly to delegation * more wip delegation * Full delegation flow * mixnode config updates * Mixnode cost function updates * Work on moving mixnode unbonding to post-epoch actions * Unbonding * Processing undelegation * changing cost params * Uncommented existing gateways features without much changes so far, however, things like unbonding should probably also go to epoch queue * ExecuteMsg cleanup * unit tests for withdrawing rewards against known values * Transactions for withdrawing rewards * Transactions for updating various parameters * First round of post-tx cleanup * Moved all storage keys to constants.rs * Using correct initial gateway pledge amount * Renamed sybil_resistance_percent to sybil_resistance with percent being implicit from the typ * Starting with contract queries * Keeping minimal details of unbonded mixnoces * Checking for owner address rather than rewarding validator when updating rewarding params * Mixnode-related queries * Gateway-related queries * Query for paged unbonded mixnodes * Delegations queries * Query for current interval details * Removed 'fixed' dependency from the mixnet common * wip on implementing rewards-related queries * Pending rewards queries * Query for node stake saturation * Queries for currently pending events * Rewarded set query * Moved ContractState to common types since it's being returned as a result of one of the queries on the mixnet contract and thus it needs to be accessible outside the contract itself * Cleaend up storage initialisation * started restoring unit tests * Removed attached 1ucoin for cross-contract execute msgs * wip * query for rewarding details of a mix node * Changes for mixnodes and gateways * Furher progress on v2 changelog(-ish) description * wip * first version of the description * mixnode bonding queries tests and fixes * ibid for storage * MixnodeEventType enum + created events for missing mixnode txs * tests for adding new mixnode * Additional mixnode-related tests + bug fixes * Display for Percent * Bunch of tests for try_reward_mixnode * More tests and fixes * ibid * tests for updating rewarding params + important bug fix * Started removing unused imports * rewarding queries tests + undelegation bugfix * A lot of todo()-ing and commenting out unimplemented code * implements https://github.com/nymtech/team-core/issues/113 * Delegation tests + fixes * Emiting events by top level interval txs + incorporating limit * question * Missing events emissions * removed some code duplication * wip * pending delegation tests * Vesting contract update * More tests (and fixes) for pending events txs * Restored gateway tx tests * Another cleanup iteration * removed redundant comment * Unit tests, fixes and simplifcations for interval-related txs * Unit tests for helper functions * Interval queries unit tests * Test for correct contract initialisation * Another round of cleanup * Work on mixnet_query_client trait * mixnet_signing_client trait * Removed redundant methods * Slowly restoring validator client functionality * Added deprecated query for mix details by identity * wip restoration of validator-api * Work on deprecating validator API routes * Further validator-api routes * Restored rest of status api routes * Resolved all todos in ValidatorApiStorage There's still bunch left in StorageManager though * Changed NodeId from u64 to u32 * Updating sql code * Network monitor internals * Changed behaviour of full_epoch_id and updated epoch operations * Fixed sql queries * [most likely] finished updating rest of the validator API * Post rebasing fixes * Feature/rewarding revamp explorer api changes (#1511) * Changed cache to allow for non-string keys * Helper method for best-effort conversion of pubkey to nodeid * Updated validator-api client routes * Updated routes to use mix-id indexing * Introduction of deprecated routes callable by identity key * Fixed mixnode compatibility by changing read node details fields (#1512) * Fixed bond to topology conversion for client compatibility (#1513) * Updated 'verify_gateway_owner' to use correct nymd_client method for obtaining gateway details (#1515) * Updated constructor for ValidatorCacheInner * Fixed wasm client topology construction * Run cargo fmt on the entire codebase * Feature/rewarding revamp wallet backend changes (#1529) * Updated mixnode-related ts types * Updated nym-wallet-types * Updated 'get_contract_settings' and commented out code of other tauri commands * 'update_contract_settings' * 'bond_gateway' * unbond_gateway' * Utility commands for the transition period * 'bond_mixnode' * 'unbond_mixnode' * Ability to update mixnode cost paramaters * Mixnode config update * Updated mixnode_bond_details It also returns a different underlying type now * Updated 'gateway_bond_details' * Obtaining pending operator rewards * Improved way of obtaining number of mixnode delegators * simplified error handling in 'fetch_mix_node_description' * mixnode and gateway ownership queries * updated get_number_of_mixnode_delegators to use mix_id since we have the conversion utils helper * mixnode delegation * undelegating * Obtaining pending delegator rewards * Command for obtaining current interval details * Queries to handle paging for pending events * Additional level of indirection to pending events to incorporate event id into response * Wallet compatible pending event types * Commands fo obtaining pending events * Re-implemented pending delegation events * Further work on delegation * Removed unused imports * Commands for withdrawing rewards * Admin-related simulations * mixnet-related simulation commands * Validator-api related routes * Bond-related vesting operations * Vesting simulations * Vesting handler for UpdateMixnodeCostParams * Vesting reward claiming * Vesting queries * claim_locked_and_unlocked_delegator_reward * The massive delegation query * cleanup * updated typescript requests * sorted the new type exports in ts-rs-cli * Regenerated typescript types * temporarily ignoring unreachable code in vesting migration * Updated missed test fixture * Fixed missing coconut-specific import * cargo fmt * Exporting reward-related types * utility to convert stringified decimal to cosmjs Decimal * deriving Eq alongside PartialEq * wip - typescript fixes * using default operating cost when bonding mixnode * Using default operating cost when updating mixnode cost params * most delegation fixes * Wrapping delegation with node identity * Added MultiIndex on owner and identity key to unbonded mixnodes * Support for queries for unbonded nodes by owner or by identity key * Cargo fmt + ts types update * feature locking unused imports * fix(nym-wallet): typing and error (#1548) * post-rebase fixes * Changed storage key for new delegations map in vesting contract * fix(wallet): typing issues (#1562) * fix(wallet): error UI feedback (#1565) * clean(wallet): remove useless files (with flamethrowers 🔥) (#1567) * Changed default_mixnode_cost_params to allow accepting f32 instead * Revert "Changed default_mixnode_cost_params to allow accepting f32 instead" This reverts commitfb62a0014f. * Fixed APY calculation for 0 pledge value * Don't send rewarding transactions for empty rewarded set * Fixed mixnode rewarding in validator API * fix(nym-wallet): profit margin (#1574) * Correctly assigning Delegate event type to PendingEpochEventData::Delegate * Replaced 'history' in with 'pending_events' in DelegationWithEverything * Updated typescript side of things * Removed todo!() from vesting contract migration since its going to be dealt with differently * fix(nym-wallet): stake saturation and delegations (#1578) * fix(nym-wallet): stake saturation percentage * fix(nym-wallet): stake saturation percentage * Correctly assigning Delegate event type to PendingEpochEventData::Delegate * fix(nym-wallet): get rid of delegation history * Replaced 'history' in with 'pending_events' in DelegationWithEverything * Updated typescript side of things * Correctly assigning Delegate event type to PendingEpochEventData::Delegate * Replaced 'history' in with 'pending_events' in DelegationWithEverything * Updated typescript side of things * fix(nym-wallet): welcome back pending events and delegation menu * fix(nym-wallet): stake saturation percentage * fix(nym-wallet): stake saturation percentage * fix(nym-wallet): get rid of delegation history * Updated typescript side of things * fix(nym-wallet): welcome back pending events and delegation menu * fix(nym-wallet): fix clippy Co-authored-by: Jędrzej Stuczyński <jedrzej.stuczynski@gmail.com> * Updated vesting contract migration to update the mixnet contract address * feat(wallet): add confirmation/warning modal for unbonding * Post rebasing fixes * Removed deprecation on GetMixnodeDetailsByIdentity * Fixed nym-cli * Removed needless borrow * Updated colorMap and textMap Co-authored-by: durch <durch@users.noreply.github.com> Co-authored-by: Mark Sinclair <mmsinclair@gmail.com> Co-authored-by: Pierre Dommerc <dommerc.pierre@gmail.com>
This commit is contained in:
committed by
GitHub
parent
ecbf5296a5
commit
136666d759
@@ -1,22 +1,20 @@
|
||||
// Copyright 2022 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
use crate::contract_cache::{Cache, CacheNotification, ValidatorCache};
|
||||
use mixnet_contract_common::rewarding::helpers::truncate_decimal;
|
||||
use mixnet_contract_common::{MixNodeDetails, NodeId, RewardingParams};
|
||||
use rocket::fairing::AdHoc;
|
||||
use serde::Serialize;
|
||||
use std::{sync::Arc, time::Duration};
|
||||
use tap::TapFallible;
|
||||
use task::ShutdownListener;
|
||||
use tokio::{
|
||||
sync::{watch, RwLock},
|
||||
time,
|
||||
};
|
||||
|
||||
use std::{sync::Arc, time::Duration};
|
||||
|
||||
use mixnet_contract_common::{reward_params::EpochRewardParams, MixNodeBond};
|
||||
use task::ShutdownListener;
|
||||
use validator_api_requests::models::InclusionProbability;
|
||||
|
||||
use crate::contract_cache::{Cache, CacheNotification, ValidatorCache};
|
||||
|
||||
const CACHE_TIMOUT_MS: u64 = 100;
|
||||
const MAX_SIMULATION_SAMPLES: u64 = 5000;
|
||||
const MAX_SIMULATION_TIME_SEC: u64 = 15;
|
||||
@@ -48,8 +46,8 @@ pub(crate) struct InclusionProbabilities {
|
||||
}
|
||||
|
||||
impl InclusionProbabilities {
|
||||
pub fn node(&self, id: &str) -> Option<&InclusionProbability> {
|
||||
self.inclusion_probabilities.iter().find(|x| x.id == id)
|
||||
pub fn node(&self, mix_id: NodeId) -> Option<&InclusionProbability> {
|
||||
self.inclusion_probabilities.iter().find(|x| x.id == mix_id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +175,12 @@ impl NodeStatusCacheRefresher {
|
||||
async fn refresh_cache(&self) -> Result<(), NodeStatusCacheError> {
|
||||
log::info!("Updating node status cache");
|
||||
let mixnode_bonds = self.contract_cache.mixnodes().await;
|
||||
let params = self.contract_cache.epoch_reward_params().await.into_inner();
|
||||
let params = self
|
||||
.contract_cache
|
||||
.interval_reward_params()
|
||||
.await
|
||||
.into_inner()
|
||||
.ok_or(NodeStatusCacheError::SimulationFailed)?;
|
||||
let inclusion_probabilities = compute_inclusion_probabilities(&mixnode_bonds, params)
|
||||
.ok_or_else(|| {
|
||||
error!(
|
||||
@@ -192,30 +195,23 @@ impl NodeStatusCacheRefresher {
|
||||
}
|
||||
|
||||
fn compute_inclusion_probabilities(
|
||||
mixnode_bonds: &[MixNodeBond],
|
||||
params: EpochRewardParams,
|
||||
mixnodes: &[MixNodeDetails],
|
||||
params: RewardingParams,
|
||||
) -> Option<InclusionProbabilities> {
|
||||
let active_set_size = params
|
||||
.active_set_size()
|
||||
.try_into()
|
||||
.tap_err(|e| error!("Active set size unexpectantly large: {e}"))
|
||||
.ok()?;
|
||||
let standby_set_size = (params.rewarded_set_size() - params.active_set_size())
|
||||
.try_into()
|
||||
.tap_err(|e| error!("Active set size larger than rewarded set size, a contradiction: {e}"))
|
||||
.ok()?;
|
||||
let active_set_size = params.active_set_size;
|
||||
let standby_set_size = params.rewarded_set_size - active_set_size;
|
||||
|
||||
// Unzip list of total bonds into ids and bonds.
|
||||
// We need to go through this zip/unzip procedure to make sure we have matching identities
|
||||
// for the input to the simulator, which assumes the identity is the position in the vec
|
||||
let (ids, mixnode_total_bonds) = unzip_into_mixnode_ids_and_total_bonds(mixnode_bonds);
|
||||
let (ids, mixnode_total_bonds) = unzip_into_mixnode_ids_and_total_bonds(mixnodes);
|
||||
|
||||
// Compute inclusion probabilitites and keep track of how long time it took.
|
||||
let mut rng = rand::thread_rng();
|
||||
let results = inclusion_probability::simulate_selection_probability_mixnodes(
|
||||
&mixnode_total_bonds,
|
||||
active_set_size,
|
||||
standby_set_size,
|
||||
active_set_size as usize,
|
||||
standby_set_size as usize,
|
||||
MAX_SIMULATION_SAMPLES,
|
||||
Duration::from_secs(MAX_SIMULATION_TIME_SEC),
|
||||
&mut rng,
|
||||
@@ -232,24 +228,22 @@ fn compute_inclusion_probabilities(
|
||||
})
|
||||
}
|
||||
|
||||
fn unzip_into_mixnode_ids_and_total_bonds(
|
||||
mixnode_bonds: &[MixNodeBond],
|
||||
) -> (Vec<&String>, Vec<u128>) {
|
||||
mixnode_bonds
|
||||
fn unzip_into_mixnode_ids_and_total_bonds(mixnodes: &[MixNodeDetails]) -> (Vec<NodeId>, Vec<u128>) {
|
||||
mixnodes
|
||||
.iter()
|
||||
.filter_map(|m| m.total_bond().map(|b| (m.identity(), b)))
|
||||
.map(|m| (m.mix_id(), truncate_decimal(m.total_stake()).u128()))
|
||||
.unzip()
|
||||
}
|
||||
|
||||
fn zip_ids_together_with_results(
|
||||
ids: &[&String],
|
||||
ids: &[NodeId],
|
||||
results: &inclusion_probability::SelectionProbability,
|
||||
) -> Vec<InclusionProbability> {
|
||||
ids.iter()
|
||||
.zip(results.active_set_probability.iter())
|
||||
.zip(results.reserve_set_probability.iter())
|
||||
.map(|((id, a), r)| InclusionProbability {
|
||||
id: (*id).to_string(),
|
||||
.map(|((&id, a), r)| InclusionProbability {
|
||||
id,
|
||||
in_active: *a,
|
||||
in_reserve: *r,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user