referrerpolicy=no-referrer-when-downgrade
pallet_staking_async

Module session_rotation

Source
Expand description

Manages all era rotation logic based on session increments.

§Lifecycle:

When a session ends in RC, a session report is sent to AH with the ending session index. Given there are 6 sessions per Era, and we configure the PlanningEraOffset to be 1, the following happens.

§Idle Sessions

In the happy path, first 3 sessions are idle. Nothing much happens in these sessions.

§Planning New Era Session

In the happy path, planning new era session is initiated when 3rd session ends and the 4th starts in the active era.

Triggers

  1. SessionProgress == SessionsPerEra - PlanningEraOffset
  2. Forcing is set to ForceNew or ForceAlways

Actions

  1. Triggers the election process,
  2. Updates the CurrentEra.

SkipIf CurrentEra = ActiveEra + 1 // this implies planning session has already been triggered.

FollowUp When the election process is over, we send the new validator set, with the CurrentEra index as the id of the validator set.

§Era Rotation Session

In the happy path, this happens when the 5th session ends and the 6th starts in the active era.

Triggers When we receive an activation timestamp from RC.

Assertions

  1. CurrentEra must be ActiveEra + 1.
  2. Id of the activation timestamp same as CurrentEra.

Actions

  • Finalize the currently active era.
  • Increment ActiveEra by 1.
  • Cleanup the old era information.

Exceptional Scenarios

  • Delay in exporting validator set: Triggered in a session later than 7th.
  • Forcing Era: May triggered in a session earlier than 7th.

§Example Flow of a happy path

  • end 0, start 1, plan 2
  • end 1, start 2, plan 3
  • end 2, start 3, plan 4
  • end 3, start 4, plan 5 // Plan new era session. Current Era++. Trigger Election.
  • **** Somewhere here: Election set is sent to RC, keyed with Current Era
  • end 4, start 5, plan 6 // RC::session receives and queues this set.
  • end 5, start 6, plan 7 // Session report contains activation timestamp with Current Era.

Structs§

  • A handler for all era-based storage items.
  • Manages session rotation logic.