Skip to content

Commit 134fbac

Browse files
docs(nns): Follow up on PR 2339 (dfinity#3771)
dfinity#2339 All changes here are comments.
1 parent cdb473b commit 134fbac

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

rs/nns/governance/src/governance.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,17 @@ impl VotingPowerEconomics {
373373
Self::DEFAULT
374374
}
375375

376+
/// Returns 1 if a neuron has refreshed (its voting power/following)
377+
/// recently.
378+
///
379+
/// Otherwise, if a neuron has not refreshed for >
380+
/// start_reducing_voting_power_after_seconds, returns < 1 (but >= 0).
381+
///
382+
/// Once a neuron has not refresehd for
383+
/// start_reducing_voting_power_after_seconds +
384+
/// clear_following_after_seconds, this returns 0.
385+
///
386+
/// Between these two points, the decrease is linear.
376387
pub fn deciding_voting_power_adjustment_factor(
377388
&self,
378389
time_since_last_voting_power_refreshed: Duration,

rs/nns/governance/src/neuron/types.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use ic_nervous_system_common::ONE_DAY_SECONDS;
2424
use ic_nns_common::pb::v1::{NeuronId, ProposalId};
2525
use ic_nns_governance_api::pb::v1::{self as api, NeuronInfo};
2626
use icp_ledger::Subaccount;
27-
use rust_decimal::Decimal;
27+
use rust_decimal::{Decimal, RoundingStrategy};
2828
use std::{
2929
collections::{BTreeSet, HashMap},
3030
time::Duration,
@@ -294,7 +294,7 @@ impl Neuron {
294294
> 0
295295
}
296296

297-
/// How much swap this neuron has when it casts its vote on proposals.
297+
/// How much sway this neuron has when it casts its vote on proposals.
298298
pub fn deciding_voting_power(
299299
&self,
300300
voting_power_economics: &VotingPowerEconomics,
@@ -318,8 +318,10 @@ impl Neuron {
318318
// Main calculation.
319319
let result = adjustment_factor * Decimal::from(potential_voting_power);
320320

321-
// Convert (back) to u64.
322-
let result = result.round();
321+
// Convert (back) to u64. The particular type of rounding used here does
322+
// not matter to us very much, because we are not for example
323+
// apportioning (where rounding down is best), nor anything like that.
324+
let result = result.round_dp_with_strategy(0, RoundingStrategy::MidpointNearestEven);
323325
u64::try_from(result).unwrap_or_else(|err| {
324326
// Log and fall back to potential voting power. Assuming
325327
// adjustment_factor is in [0, 1], I see no way this can happen.

0 commit comments

Comments
 (0)