Skip to content

Commit

Permalink
run try state for staking
Browse files Browse the repository at this point in the history
  • Loading branch information
Ank4n committed May 13, 2024
1 parent 6e3045f commit 159d1bf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions substrate/frame/delegated-staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use frame_election_provider_support::{
onchain, SequentialPhragmen,
};
use frame_support::dispatch::RawOrigin;
use pallet_staking::CurrentEra;
use pallet_staking::{ActiveEra, ActiveEraInfo, CurrentEra};
use sp_staking::{Stake, StakingInterface};

pub type T = Runtime;
Expand Down Expand Up @@ -113,7 +113,7 @@ impl pallet_staking::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Slash = ();
type Reward = ();
type SessionsPerEra = ();
type SessionsPerEra = ConstU32<1>;
type SlashDeferDuration = ();
type AdminOrigin = frame_system::EnsureRoot<Self::AccountId>;
type BondingDuration = BondingDuration;
Expand Down Expand Up @@ -220,6 +220,8 @@ impl ExtBuilder {
ext.execute_with(|| {
// for events to be deposited.
frame_system::Pallet::<Runtime>::set_block_number(1);
// set era for staking.
start_era(0);
});

ext
Expand All @@ -229,6 +231,9 @@ impl ExtBuilder {
let mut ext = self.build();
ext.execute_with(test);
ext.execute_with(|| {
#[cfg(feature = "try-runtime")]
<AllPalletsWithSystem as frame_support::traits::TryState<u64>>::try_state(frame_system::Pallet::<Runtime>::block_number(), frame_support::traits::TryStateSelect::All).unwrap();
#[cfg(not(feature = "try-runtime"))]
DelegatedStaking::do_try_state().unwrap();
});
}
Expand Down Expand Up @@ -274,6 +279,7 @@ pub(crate) fn setup_delegation_stake(

pub(crate) fn start_era(era: sp_staking::EraIndex) {
CurrentEra::<T>::set(Some(era));
ActiveEra::<T>::set(Some(ActiveEraInfo { index: era, start: None }));
}

pub(crate) fn eq_stake(who: AccountId, total: Balance, active: Balance) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion substrate/frame/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ pub struct ActiveEraInfo {
///
/// Start can be none if start hasn't been set for the era yet,
/// Start is set on the first on_finalize of the era to guarantee usage of `Time`.
start: Option<u64>,
pub start: Option<u64>,
}

/// Reward points of an era. Used to split era total payout between validators.
Expand Down

0 comments on commit 159d1bf

Please sign in to comment.