diff --git a/cumulus/pallets/collator-selection/src/benchmarking.rs b/cumulus/pallets/collator-selection/src/benchmarking.rs index 3cf7ff3095051..7a6315ef231df 100644 --- a/cumulus/pallets/collator-selection/src/benchmarking.rs +++ b/cumulus/pallets/collator-selection/src/benchmarking.rs @@ -22,7 +22,6 @@ 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}; diff --git a/cumulus/pallets/collator-selection/src/tests.rs b/cumulus/pallets/collator-selection/src/tests.rs index 3ef5f45ff243f..a9c6fe56b192e 100644 --- a/cumulus/pallets/collator-selection/src/tests.rs +++ b/cumulus/pallets/collator-selection/src/tests.rs @@ -124,7 +124,7 @@ 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) }; + let mut key = MockSessionKeys { aura: UintAuthorityId(ii) }; Session::set_keys( RuntimeOrigin::signed(ii).into(), key.clone(), @@ -488,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 { @@ -771,8 +776,13 @@ fn take_candidate_slot_works() { assert_eq!(CandidateList::::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), diff --git a/cumulus/pallets/session-benchmarking/src/inner.rs b/cumulus/pallets/session-benchmarking/src/inner.rs index 52b8649a0000e..fe8b37050593e 100644 --- a/cumulus/pallets/session-benchmarking/src/inner.rs +++ b/cumulus/pallets/session-benchmarking/src/inner.rs @@ -18,7 +18,6 @@ use alloc::vec::Vec; -use codec::Decode; use frame_benchmarking::v2::*; use frame_system::RawOrigin; use pallet_session::*; diff --git a/docs/sdk/packages/guides/first-runtime/src/lib.rs b/docs/sdk/packages/guides/first-runtime/src/lib.rs index 2ab060c8c43fe..9266ab40ea76b 100644 --- a/docs/sdk/packages/guides/first-runtime/src/lib.rs +++ b/docs/sdk/packages/guides/first-runtime/src/lib.rs @@ -235,7 +235,7 @@ impl_runtime_apis! { } impl apis::SessionKeys for Runtime { - fn generate_session_keys(_seed: Option>) -> Vec { + fn generate_session_keys(_owner: Vec, _seed: Option>) -> apis::OpaqueGeneratedSessionKeys { Default::default() } diff --git a/substrate/frame/revive/dev-node/runtime/src/lib.rs b/substrate/frame/revive/dev-node/runtime/src/lib.rs index d9636d5627e7a..fbeeec1269be5 100644 --- a/substrate/frame/revive/dev-node/runtime/src/lib.rs +++ b/substrate/frame/revive/dev-node/runtime/src/lib.rs @@ -39,7 +39,6 @@ use polkadot_sdk::{ }, *, }; -use sp_session::OpaqueGeneratedSessionKeys; use sp_weights::{ConstantMultiplier, IdentityFee}; pub use polkadot_sdk::{ @@ -403,8 +402,8 @@ pallet_revive::impl_runtime_apis_plus_revive!( } impl apis::SessionKeys for Runtime { - fn generate_session_keys(owner: Vec, seed: Option>) -> OpaqueGeneratedSessionKeys { - SessionKeys::generate(&owner, seed).into() + fn generate_session_keys(_owner: Vec, _seed: Option>) -> apis::OpaqueGeneratedSessionKeys { + Default::default() } diff --git a/substrate/frame/staking-async/runtimes/parachain/src/lib.rs b/substrate/frame/staking-async/runtimes/parachain/src/lib.rs index 4a6084c62ef80..90ecf0d9fa0fe 100644 --- a/substrate/frame/staking-async/runtimes/parachain/src/lib.rs +++ b/substrate/frame/staking-async/runtimes/parachain/src/lib.rs @@ -1460,8 +1460,8 @@ impl_runtime_apis! { } impl sp_session::SessionKeys for Runtime { - fn generate_session_keys(seed: Option>) -> Vec { - SessionKeys::generate(seed) + fn generate_session_keys(owner: Vec, seed: Option>) -> sp_session::OpaqueGeneratedSessionKeys { + SessionKeys::generate(&owner, seed).into() } fn decode_session_keys( diff --git a/substrate/frame/staking-async/runtimes/rc/src/lib.rs b/substrate/frame/staking-async/runtimes/rc/src/lib.rs index c7136f81e8338..1581e3ebb43be 100644 --- a/substrate/frame/staking-async/runtimes/rc/src/lib.rs +++ b/substrate/frame/staking-async/runtimes/rc/src/lib.rs @@ -2595,8 +2595,8 @@ sp_api::impl_runtime_apis! { } impl sp_session::SessionKeys for Runtime { - fn generate_session_keys(seed: Option>) -> Vec { - SessionKeys::generate(seed) + fn generate_session_keys(owner: Vec, seed: Option>) -> sp_session::OpaqueGeneratedSessionKeys { + SessionKeys::generate(&owner, seed).into() } fn decode_session_keys( diff --git a/substrate/primitives/runtime/src/testing.rs b/substrate/primitives/runtime/src/testing.rs index 1d3459337b4f1..515e40c4c1ab9 100644 --- a/substrate/primitives/runtime/src/testing.rs +++ b/substrate/primitives/runtime/src/testing.rs @@ -125,12 +125,12 @@ impl sp_application_crypto::RuntimeAppPublic for UintAuthorityId { traits::Verify::verify(signature, msg.as_ref(), &self.0) } - fn generate_proof_of_possession(&mut self, _owner: &[u8]) -> Option { - None + fn generate_proof_of_possession(&mut self, owner: &[u8]) -> Option { + Some(TestSignature(self.0, owner.to_vec())) } - fn verify_proof_of_possession(&self, _owner: &[u8], _pop: &Self::Signature) -> bool { - false + fn verify_proof_of_possession(&self, owner: &[u8], pop: &Self::Signature) -> bool { + traits::Verify::verify(pop, owner, &self.0) } fn to_raw_vec(&self) -> Vec { diff --git a/substrate/primitives/session/src/runtime_api.rs b/substrate/primitives/session/src/runtime_api.rs index 2a67fa73e5699..237e977048505 100644 --- a/substrate/primitives/session/src/runtime_api.rs +++ b/substrate/primitives/session/src/runtime_api.rs @@ -21,7 +21,7 @@ pub use sp_core::crypto::KeyTypeId; use sp_runtime::traits::GeneratedSessionKeys; /// Opaque [`GeneratedSessionKeys`](sp_runtime::traits::GeneratedSessionKeys). -#[derive(Debug, Decode, Encode, scale_info::TypeInfo)] +#[derive(Debug, Default, Decode, Encode, scale_info::TypeInfo)] pub struct OpaqueGeneratedSessionKeys { /// The public session keys. pub keys: Vec, diff --git a/templates/minimal/runtime/src/lib.rs b/templates/minimal/runtime/src/lib.rs index 321b31ac88b24..4bf93bd5c39d5 100644 --- a/templates/minimal/runtime/src/lib.rs +++ b/templates/minimal/runtime/src/lib.rs @@ -282,8 +282,8 @@ impl_runtime_apis! { } impl apis::SessionKeys for Runtime { - fn generate_session_keys(_owner: Vec, _seed: Option>) -> OpaqueGeneratedSessionKeys { - OpaqueGeneratedSessionKeys { keys: Default::default(), proof: Default::default() } + fn generate_session_keys(_owner: Vec, _seed: Option>) -> apis::OpaqueGeneratedSessionKeys { + apis::OpaqueGeneratedSessionKeys { keys: Default::default(), proof: Default::default() } } fn decode_session_keys(