Skip to content

Commit

Permalink
feat(staking): discard nanoWits for average epoch computation when ad…
Browse files Browse the repository at this point in the history
…ding stake
drcpu-github committed Jul 4, 2024
1 parent 54e4172 commit 0a8869e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions data_structures/src/staking/stake.rs
Original file line number Diff line number Diff line change
@@ -81,12 +81,14 @@ where

for capability in ALL_CAPABILITIES {
let epoch_before = self.epochs.get(capability);
let product_before = coins_before * epoch_before;
let product_added = coins * epoch;
let product_before = coins_before.lose_precision(WIT_DECIMAL_PLACES) * epoch_before;
let product_added = coins.lose_precision(WIT_DECIMAL_PLACES) * epoch;

#[allow(clippy::cast_possible_truncation)]
let epoch_after = Epoch::from(
(u64::from(product_before + product_added) / u64::from(coins_after)) as u32,
(u64::from(product_before + product_added)
/ u64::from(coins_after.lose_precision(WIT_DECIMAL_PLACES)))
as u32,
);
self.epochs.update(capability, epoch_after);
}

0 comments on commit 0a8869e

Please sign in to comment.