Skip to content

Commit 54aa126

Browse files
committed
feat: Draft of pallet_session_keys_registration
1 parent 30f6e5e commit 54aa126

File tree

6 files changed

+99
-1
lines changed

6 files changed

+99
-1
lines changed

Cargo.lock

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ members = [
5757
"toolkit/governed-map/primitives",
5858
"toolkit/governed-map/pallet",
5959
"toolkit/committee-selection/selection-simulator",
60+
"toolkit/session_keys_registration",
6061
]
6162
resolver = "2"
6263

@@ -330,5 +331,8 @@ partner-chains-mock-data-sources = { path = "toolkit/data-sources/mock", default
330331
sp-governed-map = { path = "toolkit/governed-map/primitives", default-features = false }
331332
pallet-governed-map = { path = "toolkit/governed-map/pallet", default-features = false }
332333

334+
# Session Keys Registration
335+
pallet-session-keys-registration = { path = "toolkit/session_keys_registration", default-features = false }
336+
333337
# demo node
334338
partner-chains-demo-runtime = { path = "demo/runtime" }

demo/runtime/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ pallet-governed-map = { workspace = true }
9393
sp-governed-map = { workspace = true }
9494
sp-block-producer-fees = { workspace = true }
9595
pallet-block-producer-fees = { workspace = true }
96+
pallet-session-keys-registration = { workspace = true }
9697

9798
[dev-dependencies]
9899
sp-io = { workspace = true }
@@ -139,6 +140,7 @@ std = [
139140
"pallet-transaction-payment/std",
140141
"pallet-address-associations/std",
141142
"pallet-block-producer-metadata/std",
143+
"pallet-session-keys-registration/std",
142144
"sp-block-producer-metadata/std",
143145
"sp-api/std",
144146
"sp-block-builder/std",

demo/runtime/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,10 @@ impl pallet_governed_map::Config for Runtime {
681681
type BenchmarkHelper = ();
682682
}
683683

684+
impl pallet_session_keys_registration::Config for Runtime {
685+
type PalletsOrigin = OriginCaller;
686+
}
687+
684688
impl crate::test_helper_pallet::Config for Runtime {}
685689

686690
// Create the runtime by composing the FRAME pallets that were previously configured.
@@ -702,7 +706,8 @@ construct_runtime!(
702706
BlockProducerMetadata: pallet_block_producer_metadata,
703707
BlockProductionLog: pallet_block_production_log,
704708
BlockParticipation: pallet_block_participation,
705-
Session: pallet_session,
709+
Session: pallet_session exclude_parts { Call },
710+
SessionKeysRegistration: pallet_session_keys_registration,
706711
// Historical: pallet_session::historical,
707712
NativeTokenManagement: pallet_native_token_management,
708713
GovernedMap: pallet_governed_map,
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[package]
2+
name = "pallet-session-keys-registration"
3+
authors.workspace = true
4+
edition.workspace = true
5+
homepage.workspace = true
6+
repository.workspace = true
7+
version.workspace = true
8+
license = "Apache-2.0"
9+
description = "Pallet for tracking the governed key-value store on main chain"
10+
11+
[lints]
12+
workspace = true
13+
14+
[dependencies]
15+
frame-support = { workspace = true, default-features = false }
16+
frame-system = { workspace = true, default-features = false }
17+
parity-scale-codec = { workspace = true }
18+
scale-info = { workspace = true, default-features = false, features = [
19+
"derive",
20+
] }
21+
sp-runtime = { workspace = true, default-features = false }
22+
pallet-session = { workspace = true }
23+
24+
[features]
25+
default = ["std"]
26+
std = [
27+
"frame-support/std",
28+
"frame-system/std",
29+
"parity-scale-codec/std",
30+
"scale-info/std",
31+
"sp-runtime/std",
32+
"pallet-session/std",
33+
]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#![cfg_attr(not(feature = "std"), no_std)]
2+
3+
pub use pallet::*;
4+
5+
#[frame_support::pallet]
6+
pub mod pallet {
7+
use frame_support::{dispatch::DispatchResultWithPostInfo, pallet_prelude::*};
8+
use scale_info::prelude::boxed::Box;
9+
use sp_runtime::Vec;
10+
11+
#[pallet::pallet]
12+
pub struct Pallet<T>(_);
13+
14+
#[pallet::config]
15+
pub trait Config: frame_system::Config + pallet_session::Config {
16+
/// The caller origin, overarching type of all pallets origins.
17+
type PalletsOrigin: Parameter +
18+
Into<<Self as frame_system::Config>::RuntimeOrigin> +
19+
IsType<<<Self as frame_system::Config>::RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin>;
20+
}
21+
22+
impl<T: Config> Pallet<T> {
23+
/// Invokes the `pallet_session::Call::set_keys` function to set the session keys.
24+
///
25+
/// Allows the caller to set the session keys for the next session for particular user.
26+
///
27+
/// ## Complexity
28+
/// - `O(1)`. Actual cost depends on the number of length of `T::Keys::key_ids()` which is
29+
/// fixed.
30+
pub fn set_keys(
31+
as_origin: Box<T::PalletsOrigin>,
32+
keys: <T as pallet_session::Config>::Keys,
33+
proof: Vec<u8>,
34+
) -> DispatchResultWithPostInfo {
35+
let call = pallet_session::Call::<T>::set_keys { keys, proof };
36+
37+
use frame_support::traits::UnfilteredDispatchable;
38+
call.dispatch_bypass_filter((*as_origin).into())
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)