Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
4a45248
Start
bkchr Sep 17, 2023
7f9a455
Merge remote-tracking branch 'origin/master' into bkchr-set-keys-proof
bkchr Sep 25, 2023
2ecdeb3
Fixes
bkchr Sep 25, 2023
d004457
Fix more tests
bkchr Sep 25, 2023
cca49bf
Remove new RPC and fix up some comments
bkchr Sep 28, 2023
69fa5fc
Merge remote-tracking branch 'origin/master' into bkchr-set-keys-proof
bkchr Sep 28, 2023
11d5099
Remove unused type.
bkchr Sep 28, 2023
654dec7
".git/.scripts/commands/fmt/fmt.sh"
Sep 28, 2023
da937d9
Fix compilation
bkchr Sep 28, 2023
eda0139
Revert "Remove new RPC and fix up some comments"
bkchr Oct 2, 2023
412e63b
Revert "Remove unused type."
bkchr Oct 2, 2023
bfba5cd
Merge remote-tracking branch 'origin/master' into bkchr-set-keys-proof
bkchr Oct 3, 2023
5a2c397
Update docs
bkchr Oct 3, 2023
c52c6c3
Fix tests
bkchr Oct 4, 2023
59f6886
Fix docs
bkchr Oct 4, 2023
371b1cb
Fixes
bkchr Oct 10, 2023
cdf9887
Fix compilation
bkchr Oct 11, 2023
a33ab45
FMT
bkchr Oct 11, 2023
b14b399
Make clippy happy..
bkchr Oct 11, 2023
0d30e18
CLIPPY
bkchr Oct 11, 2023
a6c5d25
Merge remote-tracking branch 'origin/master' into bkchr-set-keys-proof
bkchr Oct 11, 2023
b361b48
Fix collator selection benchmarking
bkchr Oct 11, 2023
ceb2add
Fix warning
bkchr Oct 11, 2023
b219dc8
Format features
bkchr Oct 11, 2023
1c3c8c5
Merge remote-tracking branch 'refs/remotes/origin/master'
bkchr Jul 30, 2024
3fc2ea5
Fix error
bkchr Aug 14, 2024
0479cd0
Merge remote-tracking branch 'origin/master' into bkchr-set-keys-proof
bkchr Aug 14, 2024
770b471
Remove old files
bkchr Aug 14, 2024
1cd8589
Fix issues
bkchr Aug 15, 2024
165eadb
Fix warning
bkchr Aug 15, 2024
0e8af35
More warnings..
bkchr Aug 15, 2024
28b4b8c
Merge remote-tracking branch 'origin/master' into bkchr-set-keys-proof
bkchr Sep 19, 2025
43f3684
Some fixes
bkchr Sep 19, 2025
acdd645
Use ProofOfPossession intead of Signature for owneship proof
drskalman Oct 6, 2025
b308ab8
Use ProofOfPossession intead of Signature for owneship proof (#9949)
drskalman Oct 6, 2025
f5dcd15
make `generate_session_keys` in new test parachain to receive owner
drskalman Oct 9, 2025
17f6a7c
Merge branch 'bkchr-set-keys-proof' of https://github.com/paritytech/…
drskalman Oct 12, 2025
1aef35b
Upgrade `generate_session_key` in newer test runtimes to accept owner…
drskalman Oct 13, 2025
9616e79
Implement and use verifiable key proof for test runtime
drskalman Oct 15, 2025
08927f8
fix errors in staking-async revive and minminal runtime
drskalman Oct 15, 2025
56e5bd6
Merge branches 'bkchr-set-keys-proof' and 'bkchr-set-keys-proof' of h…
drskalman Oct 15, 2025
e7e328e
migrate first-runtime and staking-async/runtimes/parachain to
drskalman Oct 16, 2025
1b4583c
Derive Default for `OpaqueGeneratedSessionKeys`
drskalman Oct 16, 2025
d4821bb
add `bls-experimental` feature to substrate/primitives/runtime/src/tr…
drskalman Oct 21, 2025
00aa57b
Implement missing trait for `ecdsa_bls381` in `substrate/primitives/r…
drskalman Oct 27, 2025
f5296a4
deal with unused import and vars
drskalman Oct 27, 2025
12e185e
Implement `generate_session_keys_and_proof` for Runtimes in staking-a…
drskalman Oct 28, 2025
dfe539e
Fix test runtime proof and verify function to call sign and verify (…
drskalman Nov 12, 2025
6220ec2
Merge branch 'bkchr-set-keys-proof' of https://github.com/paritytech/…
drskalman Nov 18, 2025
1e67763
Merge branch 'master' of https://github.com/w3f/polkadot-sdk into ska…
drskalman Nov 18, 2025
9f145e9
apply basti's beautification
drskalman Nov 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions cumulus/pallets/collator-selection/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ sp-runtime = { workspace = true }
sp-staking = { workspace = true }

frame-benchmarking = { optional = true, workspace = true }
cumulus-pallet-session-benchmarking = { default-features = false, optional = true, workspace = true }

[dev-dependencies]
pallet-aura = { workspace = true, default-features = true }
Expand All @@ -42,6 +43,7 @@ sp-tracing = { workspace = true, default-features = true }
[features]
default = ["std"]
runtime-benchmarks = [
"cumulus-pallet-session-benchmarking/runtime-benchmarks",
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
Expand All @@ -53,6 +55,7 @@ runtime-benchmarks = [
]
std = [
"codec/std",
"cumulus-pallet-session-benchmarking?/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
Expand Down
70 changes: 26 additions & 44 deletions cumulus/pallets/collator-selection/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ use super::*;
#[allow(unused)]
use crate::Pallet as CollatorSelection;
use alloc::vec::Vec;
use codec::Decode;
use core::cmp;
use cumulus_pallet_session_benchmarking as session_benchmarking;
use frame_benchmarking::{account, v2::*, whitelisted_caller, BenchmarkError};
use frame_support::traits::{Currency, EnsureOrigin, Get, ReservableCurrency};
use frame_system::{pallet_prelude::BlockNumberFor, EventRecord, RawOrigin};
use pallet_authorship::EventHandler;
use pallet_session::{self as session, SessionManager};

pub type BalanceOf<T> =
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
<<T as super::Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;

const SEED: u32 = 0;

fn assert_last_event<T: Config>(generic_event: <T as Config>::RuntimeEvent) {
fn assert_last_event<T: Config>(generic_event: <T as super::Config>::RuntimeEvent) {
let events = frame_system::Pallet::<T>::events();
let system_event: <T as frame_system::Config>::RuntimeEvent = generic_event.into();
// compare to the last event record
Expand All @@ -54,36 +54,24 @@ fn create_funded_user<T: Config>(
user
}

fn keys<T: Config + session::Config>(c: u32) -> <T as session::Config>::Keys {
use rand::{RngCore, SeedableRng};
fn validator<T: Config + session_benchmarking::Config>(
c: u32,
) -> (T::AccountId, <T as session::Config>::Keys, Vec<u8>) {
let validator = create_funded_user::<T>("candidate", c, 1000);
let (keys, proof) = T::generate_session_keys_and_proof(validator.clone());

let keys = {
let mut keys = [0u8; 128];

if c > 0 {
let mut rng = rand::rngs::StdRng::seed_from_u64(c as u64);
rng.fill_bytes(&mut keys);
}

keys
};

Decode::decode(&mut &keys[..]).unwrap()
(validator, keys, proof)
}

fn validator<T: Config + session::Config>(c: u32) -> (T::AccountId, <T as session::Config>::Keys) {
(create_funded_user::<T>("candidate", c, 1000), keys::<T>(c))
}

fn register_validators<T: Config + session::Config>(count: u32) -> Vec<T::AccountId> {
fn register_validators<T: Config + session_benchmarking::Config>(count: u32) -> Vec<T::AccountId> {
let validators = (0..count).map(|c| validator::<T>(c)).collect::<Vec<_>>();

for (who, keys) in validators.clone() {
for (who, keys, proof) in validators.clone() {
<session::Pallet<T>>::ensure_can_pay_key_deposit(&who).unwrap();
<session::Pallet<T>>::set_keys(RawOrigin::Signed(who).into(), keys, Vec::new()).unwrap();
<session::Pallet<T>>::set_keys(RawOrigin::Signed(who).into(), keys, proof).unwrap();
}

validators.into_iter().map(|(who, _)| who).collect()
validators.into_iter().map(|(who, _, _)| who).collect()
}

fn register_candidates<T: Config>(count: u32) {
Expand Down Expand Up @@ -114,7 +102,7 @@ fn min_invulnerables<T: Config>() -> u32 {
min_collators.saturating_sub(candidates_length)
}

#[benchmarks(where T: pallet_authorship::Config + session::Config)]
#[benchmarks(where T: pallet_authorship::Config + session_benchmarking::Config)]
mod benchmarks {
use super::*;

Expand Down Expand Up @@ -155,16 +143,15 @@ mod benchmarks {
// add one more to the list. should not be in `b` (invulnerables) because it's the account
// we will _add_ to invulnerables. we want it to be in `candidates` because we need the
// weight associated with removing it.
let (new_invulnerable, new_invulnerable_keys) = validator::<T>(b.max(c) + 1);
candidates.push((new_invulnerable.clone(), new_invulnerable_keys));
let (new_invulnerable, new_invulnerable_keys, new_proof) = validator::<T>(b.max(c) + 1);
candidates.push((new_invulnerable.clone(), new_invulnerable_keys, new_proof));
// set their keys ...
for (who, keys) in candidates.clone() {
for (who, keys, proof) in candidates.clone() {
<session::Pallet<T>>::ensure_can_pay_key_deposit(&who).unwrap();
<session::Pallet<T>>::set_keys(RawOrigin::Signed(who).into(), keys, Vec::new())
.unwrap();
<session::Pallet<T>>::set_keys(RawOrigin::Signed(who).into(), keys, proof).unwrap();
}
// ... and register them.
for (who, _) in candidates.iter() {
for (who, _, _) in candidates.iter() {
let deposit = CandidacyBond::<T>::get();
<T as pallet::Config>::Currency::make_free_balance_be(who, deposit * 1000_u32.into());
CandidateList::<T>::try_mutate(|list| {
Expand Down Expand Up @@ -299,14 +286,11 @@ mod benchmarks {
let caller: T::AccountId = whitelisted_caller();
let bond: BalanceOf<T> = <T as pallet::Config>::Currency::minimum_balance() * 2u32.into();
<T as pallet::Config>::Currency::make_free_balance_be(&caller, bond);
let (keys, proof) = T::generate_session_keys_and_proof(caller.clone());

<session::Pallet<T>>::ensure_can_pay_key_deposit(&caller).unwrap();
<session::Pallet<T>>::set_keys(
RawOrigin::Signed(caller.clone()).into(),
keys::<T>(c + 1),
Vec::new(),
)
.unwrap();
<session::Pallet<T>>::set_keys(RawOrigin::Signed(caller.clone()).into(), keys, proof)
.unwrap();

#[extrinsic_call]
_(RawOrigin::Signed(caller.clone()));
Expand All @@ -328,13 +312,11 @@ mod benchmarks {
let bond: BalanceOf<T> = <T as pallet::Config>::Currency::minimum_balance() * 10u32.into();
<T as pallet::Config>::Currency::make_free_balance_be(&caller, bond);

let (keys, proof) = T::generate_session_keys_and_proof(caller.clone());

<session::Pallet<T>>::ensure_can_pay_key_deposit(&caller).unwrap();
<session::Pallet<T>>::set_keys(
RawOrigin::Signed(caller.clone()).into(),
keys::<T>(c + 1),
Vec::new(),
)
.unwrap();
<session::Pallet<T>>::set_keys(RawOrigin::Signed(caller.clone()).into(), keys, proof)
.unwrap();

let target = CandidateList::<T>::get().iter().last().unwrap().who.clone();

Expand Down
11 changes: 11 additions & 0 deletions cumulus/pallets/collator-selection/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ impl Config for Test {
type WeightInfo = ();
}

#[cfg(feature = "runtime-benchmarks")]
impl cumulus_pallet_session_benchmarking::Config for Test {
fn generate_session_keys_and_proof(owner: Self::AccountId) -> (Self::Keys, Vec<u8>) {
use codec::Encode;

let keys = MockSessionKeys::generate(&owner.encode(), None);

(keys.keys, keys.proof.encode())
}
}

pub fn new_test_ext() -> sp_io::TestExternalities {
sp_tracing::try_init_simple();
let mut t = frame_system::GenesisConfig::<Test>::default().build_storage().unwrap();
Expand Down
28 changes: 22 additions & 6 deletions cumulus/pallets/collator-selection/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{
mock::*, CandidacyBond, CandidateInfo, CandidateList, DesiredCandidates, Error, Invulnerables,
LastAuthoredBlock,
};
use codec::Encode;
use frame_support::{
assert_noop, assert_ok,
traits::{Currency, OnInitialize},
Expand Down Expand Up @@ -123,8 +124,13 @@ fn invulnerable_limit_works() {
// only keys were registered in mock for 1 to 5
if ii > 5 {
Balances::make_free_balance_be(&ii, 100);
let key = MockSessionKeys { aura: UintAuthorityId(ii) };
Session::set_keys(RuntimeOrigin::signed(ii).into(), key, Vec::new()).unwrap();
let mut key = MockSessionKeys { aura: UintAuthorityId(ii) };
Session::set_keys(
RuntimeOrigin::signed(ii).into(),
key.clone(),
key.create_ownership_proof(&ii.encode()).unwrap().encode(),
)
.unwrap();
}
assert_eq!(Balances::free_balance(ii), 100);
if ii < 21 {
Expand Down Expand Up @@ -482,8 +488,13 @@ fn cannot_register_candidate_if_too_many() {
// candidates.
for i in 6..=23 {
Balances::make_free_balance_be(&i, 100);
let key = MockSessionKeys { aura: UintAuthorityId(i) };
Session::set_keys(RuntimeOrigin::signed(i).into(), key, Vec::new()).unwrap();
let mut key = MockSessionKeys { aura: UintAuthorityId(i) };
Session::set_keys(
RuntimeOrigin::signed(i).into(),
key.clone(),
key.create_ownership_proof(&i.encode()).unwrap().encode(),
)
.unwrap();
}

for c in 3..=22 {
Expand Down Expand Up @@ -765,8 +776,13 @@ fn take_candidate_slot_works() {
assert_eq!(CandidateList::<Test>::get().iter().count(), 3);

Balances::make_free_balance_be(&6, 100);
let key = MockSessionKeys { aura: UintAuthorityId(6) };
Session::set_keys(RuntimeOrigin::signed(6).into(), key, Vec::new()).unwrap();
let mut key = MockSessionKeys { aura: UintAuthorityId(6) };
Session::set_keys(
RuntimeOrigin::signed(6).into(),
key.clone(),
key.create_ownership_proof(&6u64.encode()).unwrap().encode(),
)
.unwrap();

assert_ok!(CollatorSelection::take_candidate_slot(
RuntimeOrigin::signed(6),
Expand Down
20 changes: 13 additions & 7 deletions cumulus/pallets/session-benchmarking/src/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@
//! Benchmarking setup for pallet-session.
#![cfg(feature = "runtime-benchmarks")]

use alloc::{vec, vec::Vec};
use alloc::vec::Vec;

use codec::Decode;
use frame_benchmarking::v2::*;
use frame_system::RawOrigin;
use pallet_session::*;
pub struct Pallet<T: Config>(pallet_session::Pallet<T>);
pub trait Config: pallet_session::Config {}
pub trait Config: pallet_session::Config {
/// Generate a session key and a proof of ownership.
///
/// The given `owner` is the account that will call `set_keys` using the returned session keys
/// and proof. This means that the proof should prove the ownership of `owner` over the private
/// keys associated to the session keys.
fn generate_session_keys_and_proof(owner: Self::AccountId) -> (Self::Keys, Vec<u8>);
}

#[benchmarks]
mod benchmarks {
Expand All @@ -33,8 +39,8 @@ mod benchmarks {
fn set_keys() -> Result<(), BenchmarkError> {
let caller: T::AccountId = whitelisted_caller();
frame_system::Pallet::<T>::inc_providers(&caller);
let keys = T::Keys::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()).unwrap();
let proof: Vec<u8> = vec![0, 1, 2, 3];
let (keys, proof) = T::generate_session_keys_and_proof(caller.clone());

<pallet_session::Pallet<T>>::ensure_can_pay_key_deposit(&caller).unwrap();

#[extrinsic_call]
Expand All @@ -47,9 +53,9 @@ mod benchmarks {
fn purge_keys() -> Result<(), BenchmarkError> {
let caller: T::AccountId = whitelisted_caller();
frame_system::Pallet::<T>::inc_providers(&caller);
let keys = T::Keys::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()).unwrap();
let proof: Vec<u8> = vec![0, 1, 2, 3];
let (keys, proof) = T::generate_session_keys_and_proof(caller.clone());
<pallet_session::Pallet<T>>::ensure_can_pay_key_deposit(&caller).unwrap();

let _t = pallet_session::Pallet::<T>::set_keys(
RawOrigin::Signed(caller.clone()).into(),
keys,
Expand Down
12 changes: 9 additions & 3 deletions cumulus/parachains/runtimes/assets/asset-hub-rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ use sp_runtime::{
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, Permill,
};
use sp_session::OpaqueGeneratedSessionKeys;
use testnet_parachains_constants::rococo::snowbridge::EthereumNetwork;

#[cfg(feature = "std")]
Expand Down Expand Up @@ -1437,8 +1438,8 @@ impl_runtime_apis! {
}

impl sp_session::SessionKeys<Block> for Runtime {
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
SessionKeys::generate(seed)
fn generate_session_keys(owner: Vec<u8>, seed: Option<Vec<u8>>) -> OpaqueGeneratedSessionKeys {
SessionKeys::generate(&owner, seed).into()
}

fn decode_session_keys(
Expand Down Expand Up @@ -1695,7 +1696,12 @@ impl_runtime_apis! {
}

use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
impl cumulus_pallet_session_benchmarking::Config for Runtime {}
impl cumulus_pallet_session_benchmarking::Config for Runtime {
fn generate_session_keys_and_proof(owner: Self::AccountId) -> (Self::Keys, Vec<u8>) {
let keys = SessionKeys::generate(&owner.encode(), None);
(keys.keys, keys.proof.encode())
}
}

use pallet_xcm_bridge_hub_router::benchmarking::{
Pallet as XcmBridgeHubRouterBench,
Expand Down
17 changes: 14 additions & 3 deletions cumulus/parachains/runtimes/assets/asset-hub-westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1836,8 +1836,8 @@ pallet_revive::impl_runtime_apis_plus_revive_traits!(
}

impl sp_session::SessionKeys<Block> for Runtime {
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
SessionKeys::generate(seed)
fn generate_session_keys(owner: Vec<u8>, seed: Option<Vec<u8>>) -> sp_session::OpaqueGeneratedSessionKeys {
SessionKeys::generate(&owner, seed).into()
}

fn decode_session_keys(
Expand Down Expand Up @@ -2224,9 +2224,20 @@ pallet_revive::impl_runtime_apis_plus_revive_traits!(
}

use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
impl cumulus_pallet_session_benchmarking::Config for Runtime {
fn generate_session_keys_and_proof(owner: Self::AccountId) -> (Self::Keys, Vec<u8>) {
let keys = SessionKeys::generate(&owner.encode(), None);
(keys.keys, keys.proof.encode())
}
}
use xcm_config::{MaxAssetsIntoHolding, WestendLocation};

impl cumulus_pallet_session_benchmarking::Config for Runtime {}
impl cumulus_pallet_session_benchmarking::Config for Runtime {
fn generate_session_keys_and_proof(owner: Self::AccountId) -> (Self::Keys, Vec<u8>) {
let keys = SessionKeys::generate(&owner.encode(), None);
(keys.keys, keys.proof.encode())
}
}
use testnet_parachains_constants::westend::locations::{PeopleParaId, PeopleLocation};
parameter_types! {
pub ExistentialDepositAsset: Option<Asset> = Some((
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -806,8 +806,8 @@ impl_runtime_apis! {
}

impl sp_session::SessionKeys<Block> for Runtime {
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
SessionKeys::generate(seed)
fn generate_session_keys(owner: Vec<u8>, seed: Option<Vec<u8>>) -> sp_session::OpaqueGeneratedSessionKeys {
SessionKeys::generate(&owner, seed).into()
}

fn decode_session_keys(
Expand Down Expand Up @@ -1088,6 +1088,7 @@ impl_runtime_apis! {
) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, alloc::string::String> {
use frame_benchmarking::{BenchmarkBatch, BenchmarkError};
use sp_storage::TrackedStorageKey;
use codec::Encode;

use frame_system_benchmarking::Pallet as SystemBench;
use frame_system_benchmarking::extensions::Pallet as SystemExtensionsBench;
Expand All @@ -1103,7 +1104,12 @@ impl_runtime_apis! {
}

use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
impl cumulus_pallet_session_benchmarking::Config for Runtime {}
impl cumulus_pallet_session_benchmarking::Config for Runtime {
fn generate_session_keys_and_proof(owner: Self::AccountId) -> (Self::Keys, Vec<u8>) {
let keys = SessionKeys::generate(&owner.encode(), None);
(keys.keys, keys.proof.encode())
}
}

use xcm::latest::prelude::*;
use xcm_config::TokenLocation;
Expand Down
Loading
Loading