17
17
18
18
//! # Session Module
19
19
//!
20
- //! The Session module allows validators to manage their session keys, provides a function for changing
21
- //! the session length, and handles session rotation.
20
+ //! The Session module allows validators to manage their session keys, provides a function for
21
+ //! changing the session length, and handles session rotation.
22
22
//!
23
23
//! - [`session::Config`](./trait.Config.html)
24
24
//! - [`Call`](./enum.Call.html)
29
29
//! ### Terminology
30
30
//! <!-- Original author of paragraph: @gavofyork -->
31
31
//!
32
- //! - **Session:** A session is a period of time that has a constant set of validators. Validators can only join
33
- //! or exit the validator set at a session change. It is measured in block numbers. The block where a session is
34
- //! ended is determined by the `ShouldEndSession` trait. When the session is ending, a new validator set
35
- //! can be chosen by `OnSessionEnding` implementations.
36
- //! - **Session key:** A session key is actually several keys kept together that provide the various signing
37
- //! functions required by network authorities/validators in pursuit of their duties.
38
- //! - **Validator ID:** Every account has an associated validator ID. For some simple staking systems, this
39
- //! may just be the same as the account ID. For staking systems using a stash/controller model,
40
- //! the validator ID would be the stash account ID of the controller.
32
+ //! - **Session:** A session is a period of time that has a constant set of validators. Validators
33
+ //! can only join or exit the validator set at a session change. It is measured in block numbers.
34
+ //! The block where a session is ended is determined by the `ShouldEndSession` trait. When the
35
+ //! session is ending, a new validator set can be chosen by `OnSessionEnding` implementations.
36
+ //!
37
+ //! - **Session key:** A session key is actually several keys kept together that provide the various
38
+ //! signing functions required by network authorities/validators in pursuit of their duties.
39
+ //! - **Validator ID:** Every account has an associated validator ID. For some simple staking
40
+ //! systems, this may just be the same as the account ID. For staking systems using a
41
+ //! stash/controller model, the validator ID would be the stash account ID of the controller.
42
+ //!
41
43
//! - **Session key configuration process:** Session keys are set using `set_keys` for use not in
42
- //! the next session, but the session after next. They are stored in `NextKeys`, a mapping between
43
- //! the caller's `ValidatorId` and the session keys provided. `set_keys` allows users to set their
44
- //! session key prior to being selected as validator.
45
- //! It is a public call since it uses `ensure_signed`, which checks that the origin is a signed account.
46
- //! As such, the account ID of the origin stored in `NextKeys` may not necessarily be associated with
47
- //! a block author or a validator. The session keys of accounts are removed once their account balance is zero.
44
+ //! the next session, but the session after next. They are stored in `NextKeys`, a mapping between
45
+ //! the caller's `ValidatorId` and the session keys provided. `set_keys` allows users to set their
46
+ //! session key prior to being selected as validator. It is a public call since it uses
47
+ //! `ensure_signed`, which checks that the origin is a signed account. As such, the account ID of
48
+ //! the origin stored in `NextKeys` may not necessarily be associated with a block author or a
49
+ //! validator. The session keys of accounts are removed once their account balance is zero.
50
+ //!
48
51
//! - **Session length:** This pallet does not assume anything about the length of each session.
49
- //! Rather, it relies on an implementation of `ShouldEndSession` to dictate a new session's start.
50
- //! This pallet provides the `PeriodicSessions` struct for simple periodic sessions.
51
- //! - **Session rotation configuration:** Configure as either a 'normal' (rewardable session where rewards are
52
- //! applied) or 'exceptional' (slashable) session rotation.
52
+ //! Rather, it relies on an implementation of `ShouldEndSession` to dictate a new session's start.
53
+ //! This pallet provides the `PeriodicSessions` struct for simple periodic sessions.
54
+ //!
55
+ //! - **Session rotation configuration:** Configure as either a 'normal' (rewardable session where
56
+ //! rewards are applied) or 'exceptional' (slashable) session rotation.
57
+ //!
53
58
//! - **Session rotation process:** At the beginning of each block, the `on_initialize` function
54
- //! queries the provided implementation of `ShouldEndSession`. If the session is to end the newly
55
- //! activated validator IDs and session keys are taken from storage and passed to the
56
- //! `SessionHandler`. The validator set supplied by `SessionManager::new_session` and the corresponding session
57
- //! keys, which may have been registered via `set_keys` during the previous session, are written
58
- //! to storage where they will wait one session before being passed to the `SessionHandler`
59
- //! themselves.
59
+ //! queries the provided implementation of `ShouldEndSession`. If the session is to end the newly
60
+ //! activated validator IDs and session keys are taken from storage and passed to the
61
+ //! `SessionHandler`. The validator set supplied by `SessionManager::new_session` and the
62
+ //! corresponding session keys, which may have been registered via `set_keys` during the previous
63
+ //! session, are written to storage where they will wait one session before being passed to the
64
+ //! `SessionHandler` themselves.
60
65
//!
61
66
//! ### Goals
62
67
//!
75
80
//! ### Public Functions
76
81
//!
77
82
//! - `rotate_session` - Change to the next session. Register the new authority set. Queue changes
78
- //! for next session rotation.
83
+ //! for next session rotation.
79
84
//! - `disable_index` - Disable a validator by index.
80
85
//! - `disable` - Disable a validator by Validator ID
81
86
//!
82
87
//! ## Usage
83
88
//!
84
89
//! ### Example from the FRAME
85
90
//!
86
- //! The [Staking pallet](../pallet_staking/index.html) uses the Session pallet to get the validator set.
91
+ //! The [Staking pallet](../pallet_staking/index.html) uses the Session pallet to get the validator
92
+ //! set.
87
93
//!
88
94
//! ```
89
95
//! use pallet_session as session;
90
96
//!
91
97
//! fn validators<T: pallet_session::Config>() -> Vec<<T as pallet_session::Config>::ValidatorId> {
92
- //! <pallet_session::Module<T>>::validators()
98
+ //! <pallet_session::Module<T>>::validators()
93
99
//! }
94
100
//! # fn main(){}
95
101
//! ```
@@ -166,18 +172,18 @@ impl<
166
172
period. saturating_sub ( block_after_last_session)
167
173
)
168
174
} else {
169
- Zero :: zero ( )
175
+ now
170
176
}
171
177
} else {
172
178
offset
173
179
} )
174
180
}
175
181
176
182
fn weight ( _now : BlockNumber ) -> Weight {
177
- // Weight note: `estimate_next_session_rotation` has no storage reads and trivial computational overhead.
178
- // There should be no risk to the chain having this weight value be zero for now.
179
- // However, this value of zero was not properly calculated, and so it would be reasonable
180
- // to come back here and properly calculate the weight of this function.
183
+ // Weight note: `estimate_next_session_rotation` has no storage reads and trivial
184
+ // computational overhead. There should be no risk to the chain having this weight value be
185
+ // zero for now. However, this value of zero was not properly calculated, and so it would be
186
+ // reasonable to come back here and properly calculate the weight of this function.
181
187
0
182
188
}
183
189
}
@@ -186,17 +192,17 @@ impl<
186
192
pub trait SessionManager < ValidatorId > {
187
193
/// Plan a new session, and optionally provide the new validator set.
188
194
///
189
- /// Even if the validator-set is the same as before, if any underlying economic
190
- /// conditions have changed (i.e. stake-weights), the new validator set must be returned.
191
- /// This is necessary for consensus engines making use of the session module to
192
- /// issue a validator-set change so misbehavior can be provably associated with the new
193
- /// economic conditions as opposed to the old.
194
- /// The returned validator set, if any, will not be applied until `new_index`.
195
- /// `new_index` is strictly greater than from previous call.
195
+ /// Even if the validator-set is the same as before, if any underlying economic conditions have
196
+ /// changed (i.e. stake-weights), the new validator set must be returned. This is necessary for
197
+ /// consensus engines making use of the session module to issue a validator-set change so
198
+ /// misbehavior can be provably associated with the new economic conditions as opposed to the
199
+ /// old. The returned validator set, if any, will not be applied until `new_index`. `new_index`
200
+ /// is strictly greater than from previous call.
196
201
///
197
202
/// The first session start at index 0.
198
203
///
199
- /// `new_session(session)` is guaranteed to be called before `end_session(session-1)`.
204
+ /// `new_session(session)` is guaranteed to be called before `end_session(session-1)`. In other
205
+ /// words, a new session must always be planned before an ongoing one can be finished.
200
206
fn new_session ( new_index : SessionIndex ) -> Option < Vec < ValidatorId > > ;
201
207
/// End the session.
202
208
///
@@ -205,7 +211,7 @@ pub trait SessionManager<ValidatorId> {
205
211
fn end_session ( end_index : SessionIndex ) ;
206
212
/// Start the session.
207
213
///
208
- /// The session start to be used for validation
214
+ /// The session start to be used for validation.
209
215
fn start_session ( start_index : SessionIndex ) ;
210
216
}
211
217
@@ -242,7 +248,7 @@ pub trait SessionHandler<ValidatorId> {
242
248
243
249
/// A notification for end of the session.
244
250
///
245
- /// Note it is triggered before any `SessionManager::end_session` handlers,
251
+ /// Note it is triggered before any [ `SessionManager::end_session`] handlers,
246
252
/// so we can still affect the validator set.
247
253
fn on_before_session_ending ( ) { }
248
254
0 commit comments