im-online: send heartbeats at a random period (#8819)

* im-online: send heartbeats at a random period

* support: use permill to represent session progress

* im-online: increase probability of heartbeating with session progress

* babe, session: fix tests

* babe: fix test
This commit is contained in:
André Silva
2021-06-12 16:58:36 +01:00
committed by GitHub
parent 517fd6149a
commit f21243e4e5
8 changed files with 140 additions and 36 deletions
+3 -3
View File
@@ -31,7 +31,7 @@ use sp_application_crypto::Public;
use sp_runtime::{
generic::DigestItem,
traits::{IsMember, One, SaturatedConversion, Saturating, Zero},
ConsensusEngineId, KeyTypeId, Percent,
ConsensusEngineId, KeyTypeId, Permill,
};
use sp_session::{GetSessionNumber, GetValidatorCount};
use sp_std::prelude::*;
@@ -848,11 +848,11 @@ impl<T: Config> frame_support::traits::EstimateNextSessionRotation<T::BlockNumbe
T::EpochDuration::get().saturated_into()
}
fn estimate_current_session_progress(_now: T::BlockNumber) -> (Option<Percent>, Weight) {
fn estimate_current_session_progress(_now: T::BlockNumber) -> (Option<Permill>, Weight) {
let elapsed = CurrentSlot::<T>::get().saturating_sub(Self::current_epoch_start()) + 1;
(
Some(Percent::from_rational(
Some(Permill::from_rational(
*elapsed,
T::EpochDuration::get(),
)),