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
  • Loading branch information
drcpu-github committed Jul 2, 2024
1 parent 724ca71 commit 651280c
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
Expand Up @@ -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);
}
Expand Down

0 comments on commit 651280c

Please sign in to comment.