- 
                Notifications
    
You must be signed in to change notification settings  - Fork 2.7k
 
Lazy payouts #4407
Description
Currently, all payouts from an era are made actively at the end of the era. This is a big task and will only get worse as time goes on and the validator/nominator sets grow. Right now it takes so long that it's stalling the Kusama chain (#4313). It is also problematic as the immediacy conflicts with the fact that the session keys lag one session behind the actual staking selection, leading to the wrong validators being paid for one session in every era where the validation set changes (#4331, #4346 and #4220).
Instead, payouts should happen lazily/passively.
The Session module should, at the end of a session, report the accrued points of each validator together with the era number that the validator set is from back up to the Staking module, giving it full information about which validators should be rewarded. (It should explicitly report so that the number of sessions that the validator set lags behind continues to be immaterial for the Staking module.)
The Staking module should should retain a last_payout_era value for all staked accounts, and should keep a number of past instances of the exposure information on-chain (e.g. last 100 eras) as well as the historical validator points for each session.
There should then be an explicit payout function which pays out any balance owed, taking into account all of the above information. Stakers would need to call it occasionally (at least once every 100 eras =~ 2 weeks on Kusama) to avoid missing out on their rewards.
This will fix #4121, #4331, and #4220 as well as help with #4313 . This fix will supersede #4346.