mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 19:07:57 +00:00
Allow Staking tests to run with session length other than 1 (#7719)
* fix periodic session * Allow staking tests to run with session lengths other than 1. * Update frame/staking/src/mock.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * Fix all tests with session length 5. * Test for active != current * Better doc * Update frame/staking/src/lib.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com> * also set the timestamp properly. * trigger CI * Revert "trigger CI" This reverts commit 0f254944cdad848aa6e63bd8a618db95447a8e68. * Update frame/staking/src/lib.rs Co-authored-by: Guillaume Thiolliere <gui.thiolliere@gmail.com>
This commit is contained in:
@@ -952,11 +952,14 @@ decl_storage! {
|
||||
|
||||
/// The active era information, it holds index and start.
|
||||
///
|
||||
/// The active era is the era currently rewarded.
|
||||
/// Validator set of this era must be equal to `SessionInterface::validators`.
|
||||
/// The active era is the era being currently rewarded. Validator set of this era must be
|
||||
/// equal to [`SessionInterface::validators`].
|
||||
pub ActiveEra get(fn active_era): Option<ActiveEraInfo>;
|
||||
|
||||
/// The session index at which the era start for the last `HISTORY_DEPTH` eras.
|
||||
///
|
||||
/// Note: This tracks the starting session (i.e. session index when era start being active)
|
||||
/// for the eras in `[CurrentEra - HISTORY_DEPTH, CurrentEra]`.
|
||||
pub ErasStartSessionIndex get(fn eras_start_session_index):
|
||||
map hasher(twox_64_concat) EraIndex => Option<SessionIndex>;
|
||||
|
||||
@@ -2630,14 +2633,17 @@ impl<T: Config> Module<T> {
|
||||
/// Start a session potentially starting an era.
|
||||
fn start_session(start_session: SessionIndex) {
|
||||
let next_active_era = Self::active_era().map(|e| e.index + 1).unwrap_or(0);
|
||||
// This is only `Some` when current era has already progressed to the next era, while the
|
||||
// active era is one behind (i.e. in the *last session of the active era*, or *first session
|
||||
// of the new current era*, depending on how you look at it).
|
||||
if let Some(next_active_era_start_session_index) =
|
||||
Self::eras_start_session_index(next_active_era)
|
||||
{
|
||||
if next_active_era_start_session_index == start_session {
|
||||
Self::start_era(start_session);
|
||||
} else if next_active_era_start_session_index < start_session {
|
||||
// This arm should never happen, but better handle it than to stall the
|
||||
// staking pallet.
|
||||
// This arm should never happen, but better handle it than to stall the staking
|
||||
// pallet.
|
||||
frame_support::print("Warning: A session appears to have been skipped.");
|
||||
Self::start_era(start_session);
|
||||
}
|
||||
@@ -2893,9 +2899,11 @@ impl<T: Config> Module<T> {
|
||||
/// Self votes are added and nominations before the most recent slashing span are ignored.
|
||||
///
|
||||
/// No storage item is updated.
|
||||
pub fn do_phragmen<Accuracy: PerThing>(iterations: usize)
|
||||
-> Option<PrimitiveElectionResult<T::AccountId, Accuracy>>
|
||||
where ExtendedBalance: From<InnerOf<Accuracy>>
|
||||
pub fn do_phragmen<Accuracy: PerThing>(
|
||||
iterations: usize,
|
||||
) -> Option<PrimitiveElectionResult<T::AccountId, Accuracy>>
|
||||
where
|
||||
ExtendedBalance: From<InnerOf<Accuracy>>,
|
||||
{
|
||||
let weight_of = Self::slashable_balance_of_fn();
|
||||
let mut all_nominators: Vec<(T::AccountId, VoteWeight, Vec<T::AccountId>)> = Vec::new();
|
||||
@@ -2928,7 +2936,11 @@ impl<T: Config> Module<T> {
|
||||
|
||||
if all_validators.len() < Self::minimum_validator_count().max(1) as usize {
|
||||
// If we don't have enough candidates, nothing to do.
|
||||
log!(error, "💸 Chain does not have enough staking candidates to operate. Era {:?}.", Self::current_era());
|
||||
log!(
|
||||
warn,
|
||||
"💸 Chain does not have enough staking candidates to operate. Era {:?}.",
|
||||
Self::current_era()
|
||||
);
|
||||
None
|
||||
} else {
|
||||
seq_phragmen::<_, Accuracy>(
|
||||
@@ -3090,12 +3102,30 @@ impl<T: Config> Module<T> {
|
||||
/// some session can lag in between the newest session planned and the latest session started.
|
||||
impl<T: Config> pallet_session::SessionManager<T::AccountId> for Module<T> {
|
||||
fn new_session(new_index: SessionIndex) -> Option<Vec<T::AccountId>> {
|
||||
frame_support::debug::native::trace!(
|
||||
target: LOG_TARGET,
|
||||
"[{}] planning new_session({})",
|
||||
<frame_system::Module<T>>::block_number(),
|
||||
new_index
|
||||
);
|
||||
Self::new_session(new_index)
|
||||
}
|
||||
fn start_session(start_index: SessionIndex) {
|
||||
frame_support::debug::native::trace!(
|
||||
target: LOG_TARGET,
|
||||
"[{}] starting start_session({})",
|
||||
<frame_system::Module<T>>::block_number(),
|
||||
start_index
|
||||
);
|
||||
Self::start_session(start_index)
|
||||
}
|
||||
fn end_session(end_index: SessionIndex) {
|
||||
frame_support::debug::native::trace!(
|
||||
target: LOG_TARGET,
|
||||
"[{}] ending end_session({})",
|
||||
<frame_system::Module<T>>::block_number(),
|
||||
end_index
|
||||
);
|
||||
Self::end_session(end_index)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user