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

Commit 75116bd

Browse files
gavofyorkgui1117shawntabrizi
authored
Lazy payouts (#4474)
* TODOs * Remove superfluous: * partial implementation * full implementation * fix preferences * update comments * upgrade test WIP * fix more tests * fix cutoff * fix saturation * comment * upgrade mock * upgrade test * WIP migration * WIP migration * remove slot stake stuff * fix merge * migration of ledger * remove equalize from test * add test * fix * update doc * fix compilation * improve test readibility * improve doc * fix most todo * fix migration and test * remove println * WIP * add test and spec * weight * update doc * safer end_era * fix exposure of conversion * Revert "safer end_era" This reverts commit 72ff737. * fix useless put * exposure clipped * doc * fix payout with clipped * fix node runtime * add doc * pluggable and generalized staking module * remove print * update doc * refactor * improve documentation and implementation * fix test * Fix test * fix test * fix test * fix remove lowest stake from exposure, not biggest. * nomination index arguments in nominator_payout * add test * try to fix offence * apply slashed and bond eras until active era * doc * update spec version * add test upgrade from previous test environment * Apply suggestions from code review Co-Authored-By: Shawn Tabrizi <[email protected]> * nominators upgrade has been cleaned * dynamic history depth implementation * make current_era - history_depth included * Change equality check to start era to less than or equal * Use era specific validator prefs * Add print statement and comment about start era if < * fix next_reward overflow * make more check for bad era claim for zero cost * small refactor * code refactor + fix use of deprecated storage * fix wasm build * add comment * Fix tests * remove outdated comment * Apply suggestions from code review Co-Authored-By: Shawn Tabrizi <[email protected]> * gather active era information into one storage Co-authored-by: thiolliere <[email protected]> Co-authored-by: Shawn Tabrizi <[email protected]>
1 parent 870540b commit 75116bd

File tree

11 files changed

+1701
-669
lines changed

11 files changed

+1701
-669
lines changed

bin/node/cli/src/chain_spec.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ pub fn testnet_genesis(
247247
}).collect::<Vec<_>>(),
248248
}),
249249
pallet_staking: Some(StakingConfig {
250-
current_era: 0,
251250
validator_count: initial_authorities.len() as u32 * 2,
252251
minimum_validator_count: initial_authorities.len() as u32,
253252
stakers: initial_authorities.iter().map(|x| {

bin/node/runtime/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ parameter_types! {
269269
pub const BondingDuration: pallet_staking::EraIndex = 24 * 28;
270270
pub const SlashDeferDuration: pallet_staking::EraIndex = 24 * 7; // 1/4 the bonding duration.
271271
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
272+
pub const MaxNominatorRewardedPerValidator: u32 = 64;
272273
}
273274

274275
impl pallet_staking::Trait for Runtime {
@@ -286,6 +287,7 @@ impl pallet_staking::Trait for Runtime {
286287
type SlashCancelOrigin = pallet_collective::EnsureProportionAtLeast<_3, _4, AccountId, CouncilCollective>;
287288
type SessionInterface = Self;
288289
type RewardCurve = RewardCurve;
290+
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
289291
}
290292

291293
parameter_types! {

bin/node/testing/src/genesis.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ pub fn config_endowed(
8484
]
8585
}),
8686
pallet_staking: Some(StakingConfig {
87-
current_era: 0,
8887
stakers: vec![
8988
(dave(), alice(), 111 * DOLLARS, pallet_staking::StakerStatus::Validator),
9089
(eve(), bob(), 100 * DOLLARS, pallet_staking::StakerStatus::Validator),

frame/im-online/src/mock.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ impl pallet_session::SessionManager<u64> for TestSessionManager {
4949
VALIDATORS.with(|l| l.borrow_mut().take())
5050
}
5151
fn end_session(_: SessionIndex) {}
52+
fn start_session(_: SessionIndex) {}
5253
}
5354

5455
impl pallet_session::historical::SessionManager<u64, u64> for TestSessionManager {
@@ -62,6 +63,7 @@ impl pallet_session::historical::SessionManager<u64, u64> for TestSessionManager
6263
)
6364
}
6465
fn end_session(_: SessionIndex) {}
66+
fn start_session(_: SessionIndex) {}
6567
}
6668

6769
/// An extrinsic type used for tests.

frame/session/src/historical.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ pub trait SessionManager<ValidatorId, FullIdentification>: crate::SessionManager
108108
/// If there was a validator set change, its returns the set of new validators along with their
109109
/// full identifications.
110110
fn new_session(new_index: SessionIndex) -> Option<Vec<(ValidatorId, FullIdentification)>>;
111+
fn start_session(start_index: SessionIndex);
111112
fn end_session(end_index: SessionIndex);
112113
}
113114

@@ -146,6 +147,9 @@ impl<T: Trait, I> crate::SessionManager<T::ValidatorId> for NoteHistoricalRoot<T
146147

147148
new_validators
148149
}
150+
fn start_session(start_index: SessionIndex) {
151+
<I as SessionManager<_, _>>::start_session(start_index)
152+
}
149153
fn end_session(end_index: SessionIndex) {
150154
<I as SessionManager<_, _>>::end_session(end_index)
151155
}

frame/session/src/lib.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,15 @@ pub trait SessionManager<ValidatorId> {
162162
/// Because the session pallet can queue validator set the ending session can be lower than the
163163
/// last new session index.
164164
fn end_session(end_index: SessionIndex);
165+
/// Start the session.
166+
///
167+
/// The session start to be used for validation
168+
fn start_session(start_index: SessionIndex);
165169
}
166170

167171
impl<A> SessionManager<A> for () {
168172
fn new_session(_: SessionIndex) -> Option<Vec<A>> { None }
173+
fn start_session(_: SessionIndex) {}
169174
fn end_session(_: SessionIndex) {}
170175
}
171176

@@ -423,6 +428,8 @@ decl_storage! {
423428

424429
<Validators<T>>::put(initial_validators_0);
425430
<QueuedKeys<T>>::put(queued_keys);
431+
432+
T::SessionManager::start_session(0);
426433
});
427434
}
428435
}
@@ -520,6 +527,8 @@ impl<T: Trait> Module<T> {
520527
// Inform the session handlers that a session is going to end.
521528
T::SessionHandler::on_before_session_ending();
522529

530+
T::SessionManager::end_session(session_index);
531+
523532
// Get queued session keys and validators.
524533
let session_keys = <QueuedKeys<T>>::get();
525534
let validators = session_keys.iter()
@@ -532,12 +541,12 @@ impl<T: Trait> Module<T> {
532541
DisabledValidators::take();
533542
}
534543

535-
T::SessionManager::end_session(session_index);
536-
537544
// Increment session index.
538545
let session_index = session_index + 1;
539546
CurrentIndex::put(session_index);
540547

548+
T::SessionManager::start_session(session_index);
549+
541550
// Get next validator set.
542551
let maybe_next_validators = T::SessionManager::new_session(session_index + 1);
543552
let (next_validators, next_identities_changed)

frame/session/src/mock.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ impl SessionHandler<u64> for TestSessionHandler {
9292
pub struct TestSessionManager;
9393
impl SessionManager<u64> for TestSessionManager {
9494
fn end_session(_: SessionIndex) {}
95+
fn start_session(_: SessionIndex) {}
9596
fn new_session(_: SessionIndex) -> Option<Vec<u64>> {
9697
if !TEST_SESSION_CHANGED.with(|l| *l.borrow()) {
9798
VALIDATORS.with(|v| {
@@ -112,6 +113,7 @@ impl SessionManager<u64> for TestSessionManager {
112113
#[cfg(feature = "historical")]
113114
impl crate::historical::SessionManager<u64, u64> for TestSessionManager {
114115
fn end_session(_: SessionIndex) {}
116+
fn start_session(_: SessionIndex) {}
115117
fn new_session(new_index: SessionIndex)
116118
-> Option<Vec<(u64, u64)>>
117119
{

0 commit comments

Comments
 (0)