mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 22:11:06 +00:00
@@ -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);
|
||||
@@ -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.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user