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

Fix runtime #266

Merged
merged 2 commits into from
Jun 29, 2018
Merged
Show file tree
Hide file tree
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
18 changes: 0 additions & 18 deletions polkadot/runtime/wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 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 per65536: u64 = (T::Moment::sa(65536u64) * ideal_elapsed.clone() / actual_elapsed.max(ideal_elapsed)).as_();
let reward = Self::session_reward() * T::Balance::sa(per65536) / 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 @@ -577,12 +577,12 @@ impl<T: Trait> Module<T> {
for v in <session::Module<T>>::validators().iter() {
if let Some(rem) = Self::slash(v, early_era_slash) {
let noms = Self::current_nominators_for(v);
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);
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.
let total = noms.iter().map(Self::voting_balance).fold(T::Balance::zero(), |acc, x| acc + x);
if !total.is_zero() {
let safe_mul_rational = |b| b * rem / total;// TODO: avoid overflow
for n in noms.iter() {
let _ = Self::slash(n, safe_mul_rational(Self::voting_balance(n))); // best effort - not much that can be done on fail.
}
}
}
}
Expand Down