Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Fix runtime build #264

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions substrate/runtime/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,8 @@ impl<T: Trait> Module<T> {
if normal_rotation {
// reward
let ideal_elapsed = <session::Module<T>>::ideal_session_duration();
let percent: usize = (T::Moment::sa(65536usize) * ideal_elapsed.clone() / actual_elapsed.max(ideal_elapsed)).as_();
let reward = Self::session_reward() * T::Balance::sa(percent) / T::Balance::sa(65536usize);
let percent: u64 = (T::Moment::sa(65536u64) * ideal_elapsed.clone() / actual_elapsed.max(ideal_elapsed)).as_();
let reward = Self::session_reward() * T::Balance::sa(percent) / T::Balance::sa(65536u64);
// apply good session reward
for v in <session::Module<T>>::validators().iter() {
let noms = Self::current_nominators_for(v);
Expand All @@ -580,7 +580,7 @@ impl<T: Trait> Module<T> {
let total = noms.iter().map(Self::voting_balance).fold(Zero::zero(), |acc, x| acc + x);
for n in noms.iter() {
//let r = Self::voting_balance(n) * reward / total; // correct formula, but might overflow with large slash * total.
let quant = T::Balance::sa(1usize << 31);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shouldn't be needed...

let quant = T::Balance::sa(1u64 << 31);
let s = (Self::voting_balance(n) * quant / total) * rem / quant; // avoid overflow by using quant as a denominator.
let _ = Self::slash(n, s); // best effort - not much that can be done on fail.
}
Expand Down