-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add assignment keys to session keys, no separate approvals key #2092
Changes from 15 commits
c8b3f64
9217b8f
de24f2c
4a68f4b
e01081d
faaad1c
3b5a55f
3eaded6
d54864b
a4f2d26
7ea8630
1e3c315
93618d2
43a6161
89f3f31
8b8db9d
57e3661
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,12 +8,13 @@ Helper structs: | |
|
||
```rust | ||
struct SessionInfo { | ||
// validators in canonical ordering. | ||
// validators in canonical ordering. These are the public keys used for backing, | ||
// dispute participation, and approvals. | ||
validators: Vec<ValidatorId>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes exactly. |
||
// validators' authority discovery keys for the session in canonical ordering. | ||
discovery_keys: Vec<DiscoveryId>, | ||
// The assignment and approval keys for validators. | ||
approval_keys: Vec<(AssignmentId, ApprovalId)>, | ||
// The assignment keys for validators. | ||
assignment_keys: Vec<AssignmentId>, | ||
// validators in shuffled ordering - these are the validator groups as produced | ||
// by the `Scheduler` module for the session and are typically referred to by | ||
// `GroupIndex`. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ pub mod impls; | |
pub mod paras_sudo_wrapper; | ||
pub mod paras_registrar; | ||
|
||
use primitives::v1::{BlockNumber, ValidatorId}; | ||
use primitives::v1::{BlockNumber, ValidatorId, AssignmentId}; | ||
use sp_runtime::{Perquintill, Perbill, FixedPointNumber}; | ||
use frame_system::limits; | ||
use frame_support::{ | ||
|
@@ -158,6 +158,35 @@ impl<T: pallet_session::Config> | |
fn on_disabled(_: usize) { } | ||
} | ||
|
||
/// A placeholder since there is currently no provided session key handler for parachain validator | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be replaced by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not yet everywhere, but in the long term. This struct is used in the polkadot, kusama, westend runtimes where we don't yet enable parachain runtime modules. |
||
/// keys. | ||
pub struct AssignmentSessionKeyPlaceholder<T>(sp_std::marker::PhantomData<T>); | ||
impl<T> sp_runtime::BoundToRuntimeAppPublic for AssignmentSessionKeyPlaceholder<T> { | ||
type Public = AssignmentId; | ||
} | ||
|
||
impl<T: pallet_session::Config> | ||
pallet_session::OneSessionHandler<T::AccountId> for AssignmentSessionKeyPlaceholder<T> | ||
{ | ||
type Key = AssignmentId; | ||
|
||
fn on_genesis_session<'a, I: 'a>(_validators: I) where | ||
I: Iterator<Item = (&'a T::AccountId, AssignmentId)>, | ||
T::AccountId: 'a | ||
{ | ||
|
||
} | ||
|
||
fn on_new_session<'a, I: 'a>(_changed: bool, _v: I, _q: I) where | ||
I: Iterator<Item = (&'a T::AccountId, AssignmentId)>, | ||
T::AccountId: 'a | ||
{ | ||
|
||
} | ||
|
||
fn on_disabled(_: usize) { } | ||
} | ||
|
||
#[cfg(test)] | ||
mod multiplier_tests { | ||
use super::*; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,13 +29,13 @@ use primitives::v1::{ | |
AccountId, AccountIndex, Balance, BlockNumber, CandidateEvent, CommittedCandidateReceipt, | ||
CoreState, GroupRotationInfo, Hash, Id, Moment, Nonce, OccupiedCoreAssumption, | ||
PersistedValidationData, Signature, ValidationCode, ValidationData, ValidatorId, ValidatorIndex, | ||
InboundDownwardMessage, InboundHrmpMessage, SessionInfo, | ||
InboundDownwardMessage, InboundHrmpMessage, SessionInfo, AssignmentId, | ||
}; | ||
use runtime_common::{ | ||
claims, SlowAdjustingFeeUpdate, CurrencyToVote, | ||
impls::DealWithFees, | ||
BlockHashCount, RocksDbWeight, BlockWeights, BlockLength, OffchainSolutionWeightLimit, | ||
ParachainSessionKeyPlaceholder, | ||
ParachainSessionKeyPlaceholder, AssignmentSessionKeyPlaceholder, | ||
}; | ||
use sp_runtime::{ | ||
create_runtime_str, generic, impl_opaque_keys, ModuleId, | ||
|
@@ -90,7 +90,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { | |
spec_name: create_runtime_str!("kusama"), | ||
impl_name: create_runtime_str!("parity-kusama"), | ||
authoring_version: 2, | ||
spec_version: 2027, | ||
spec_version: 2028, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the latest released version is on 2026, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @s3krit - I believe there's a release queued up currently and we want this to go into the next one. Let me know what I should be doing with the version numbers here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. We have already branched off for v0.8.27, so if your intent is for this change to go into v0.8.28 (i.e., the release after v0.8.27, barring any security releases), this looks right |
||
impl_version: 0, | ||
#[cfg(not(feature = "disable-runtime-api"))] | ||
apis: RUNTIME_API_VERSIONS, | ||
|
@@ -262,16 +262,46 @@ parameter_types! { | |
pub const Offset: BlockNumber = 0; | ||
} | ||
|
||
impl_opaque_keys! { | ||
pub struct OldSessionKeys { | ||
pub grandpa: Grandpa, | ||
pub babe: Babe, | ||
pub im_online: ImOnline, | ||
pub para_validator: ParachainSessionKeyPlaceholder<Runtime>, | ||
pub authority_discovery: AuthorityDiscovery, | ||
} | ||
} | ||
|
||
impl_opaque_keys! { | ||
pub struct SessionKeys { | ||
pub grandpa: Grandpa, | ||
pub babe: Babe, | ||
pub im_online: ImOnline, | ||
pub parachain_validator: ParachainSessionKeyPlaceholder<Runtime>, | ||
pub para_validator: ParachainSessionKeyPlaceholder<Runtime>, | ||
pub para_assignment: AssignmentSessionKeyPlaceholder<Runtime>, | ||
pub authority_discovery: AuthorityDiscovery, | ||
} | ||
} | ||
|
||
fn transform_session_keys(v: AccountId, old: OldSessionKeys) -> SessionKeys { | ||
SessionKeys { | ||
grandpa: old.grandpa, | ||
babe: old.babe, | ||
im_online: old.im_online, | ||
para_validator: old.para_validator, | ||
para_assignment: { | ||
// We need to produce a dummy value that's unique for the validator. | ||
let mut id = AssignmentId::default(); | ||
let id_raw: &mut [u8] = id.as_mut(); | ||
id_raw.copy_from_slice(v.as_ref()); | ||
id_raw[0..4].copy_from_slice(b"asgn"); | ||
|
||
id | ||
}, | ||
authority_discovery: old.authority_discovery, | ||
} | ||
} | ||
|
||
parameter_types! { | ||
pub const DisabledValidatorsThreshold: Perbill = Perbill::from_percent(17); | ||
} | ||
|
@@ -1105,6 +1135,15 @@ impl frame_support::traits::OnRuntimeUpgrade for FixCouncilHistoricalVotes { | |
} | ||
} | ||
|
||
// When this is removed, should also remove `OldSessionKeys`. | ||
pub struct UpgradeSessionKeys; | ||
impl frame_support::traits::OnRuntimeUpgrade for UpgradeSessionKeys { | ||
fn on_runtime_upgrade() -> frame_support::weights::Weight { | ||
Session::upgrade_keys::<OldSessionKeys, _>(transform_session_keys); | ||
Perbill::from_percent(50) * BlockWeights::get().max_block | ||
} | ||
} | ||
|
||
pub struct CustomOnRuntimeUpgrade; | ||
impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { | ||
fn on_runtime_upgrade() -> frame_support::weights::Weight { | ||
|
@@ -1208,7 +1247,7 @@ pub type Executive = frame_executive::Executive< | |
frame_system::ChainContext<Runtime>, | ||
Runtime, | ||
AllModules, | ||
FixCouncilHistoricalVotes, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR has mistakenly removed this migration from the next release, while it has not be applied yet. Should have used a tuple of both. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh or we already have branched v27? then it is okay. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay -- sorry, it is in the 27 release. Then there are two questions:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, let's add it to the v28 release notes. "Includes a runtime migration to update session key types to be used for parachain validation and approval. All validators are encouraged to rotate their session keys following the upgrade." There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
UpgradeSessionKeys, | ||
>; | ||
/// The payload being signed in the transactions. | ||
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assignments and approvals need separate keys so that assignments keys can stay on the machine while approvals keys might live on a remote signer.
We employ the same keys for all candidate validity and invalidity statements (approvals, backing, and disputes) because logically these incur similar risks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a change in the text you want me to make? I agree with everything you just said
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine I guess. It just confused me on a first reading. What should we actually call them? (candidate) validation keys?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I called them
para_validation
keys in the runtime description.