From 7feaf9e3d0d5cd9fee12709c124e53b132b6e80a Mon Sep 17 00:00:00 2001 From: akildemir Date: Fri, 17 Nov 2023 11:52:44 +0300 Subject: [PATCH] remove pallet-session & authority discovery from runtime --- Cargo.lock | 18 -------------- substrate/node/src/chain_spec.rs | 18 ++------------ substrate/runtime/Cargo.toml | 6 ----- substrate/runtime/src/lib.rs | 40 ++++++-------------------------- 4 files changed, 9 insertions(+), 73 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 393c31f7f..93bd55bbd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4988,22 +4988,6 @@ dependencies = [ "group", ] -[[package]] -name = "pallet-authority-discovery" -version = "4.0.0-dev" -source = "git+https://github.com/serai-dex/substrate#8729593b37454fa4b9d03900e95da8c55ddfa878" -dependencies = [ - "frame-support", - "frame-system", - "pallet-session", - "parity-scale-codec", - "scale-info", - "sp-application-crypto", - "sp-authority-discovery", - "sp-runtime", - "sp-std", -] - [[package]] name = "pallet-authorship" version = "4.0.0-dev" @@ -8006,9 +7990,7 @@ dependencies = [ "frame-support", "frame-system", "frame-system-rpc-runtime-api", - "pallet-authority-discovery", "pallet-babe", - "pallet-session", "pallet-timestamp", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", diff --git a/substrate/node/src/chain_spec.rs b/substrate/node/src/chain_spec.rs index 1c0e4f659..3c5a3cdd1 100644 --- a/substrate/node/src/chain_spec.rs +++ b/substrate/node/src/chain_spec.rs @@ -5,9 +5,8 @@ use sp_core::Pair as PairTrait; use sc_service::ChainType; use serai_runtime::{ - primitives::*, WASM_BINARY, opaque::SessionKeys, BABE_GENESIS_EPOCH_CONFIG, RuntimeGenesisConfig, - SystemConfig, CoinsConfig, DexConfig, ValidatorSetsConfig, SessionConfig, BabeConfig, - GrandpaConfig, AuthorityDiscoveryConfig, + primitives::*, WASM_BINARY, BABE_GENESIS_EPOCH_CONFIG, RuntimeGenesisConfig, SystemConfig, + CoinsConfig, DexConfig, ValidatorSetsConfig, BabeConfig, GrandpaConfig, }; pub type ChainSpec = sc_service::GenericChainSpec; @@ -21,16 +20,6 @@ fn testnet_genesis( validators: &[&'static str], endowed_accounts: Vec, ) -> RuntimeGenesisConfig { - let session_key = |name| { - let key = account_from_name(name); - ( - key, - key, - // TODO: Properly diversify these? - SessionKeys { babe: key.into(), grandpa: key.into(), authority_discovery: key.into() }, - ) - }; - RuntimeGenesisConfig { system: SystemConfig { code: wasm_binary.to_vec(), _config: PhantomData }, @@ -61,15 +50,12 @@ fn testnet_genesis( .collect(), participants: validators.iter().map(|name| account_from_name(name)).collect(), }, - session: SessionConfig { keys: validators.iter().map(|name| session_key(*name)).collect() }, babe: BabeConfig { authorities: vec![], epoch_config: Some(BABE_GENESIS_EPOCH_CONFIG), _config: PhantomData, }, grandpa: GrandpaConfig { authorities: vec![], _config: PhantomData }, - - authority_discovery: AuthorityDiscoveryConfig { keys: vec![], _config: PhantomData }, } } diff --git a/substrate/runtime/Cargo.toml b/substrate/runtime/Cargo.toml index 74fd6a386..064ac2ab3 100644 --- a/substrate/runtime/Cargo.toml +++ b/substrate/runtime/Cargo.toml @@ -49,7 +49,6 @@ coins-pallet = { package = "serai-coins-pallet", path = "../coins/pallet", defau dex-pallet = { package = "serai-dex-pallet", path = "../dex/pallet", default-features = false } validator-sets-pallet = { package = "serai-validator-sets-pallet", path = "../validator-sets/pallet", default-features = false } -pallet-session = { git = "https://github.com/serai-dex/substrate", default-features = false } in-instructions-pallet = { package = "serai-in-instructions-pallet", path = "../in-instructions/pallet", default-features = false } @@ -58,8 +57,6 @@ signals-pallet = { package = "serai-signals-pallet", path = "../signals/pallet", pallet-babe = { git = "https://github.com/serai-dex/substrate", default-features = false } grandpa-pallet = { package = "serai-grandpa-pallet", path = "../grandpa/pallet", default-features = false } -pallet-authority-discovery = { git = "https://github.com/serai-dex/substrate", default-features = false } - frame-system-rpc-runtime-api = { git = "https://github.com/serai-dex/substrate", default-features = false } pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/serai-dex/substrate", default-features = false } @@ -104,7 +101,6 @@ std = [ "dex-pallet/std", "validator-sets-pallet/std", - "pallet-session/std", "in-instructions-pallet/std", @@ -113,8 +109,6 @@ std = [ "pallet-babe/std", "grandpa-pallet/std", - "pallet-authority-discovery/std", - "frame-system-rpc-runtime-api/std", "pallet-transaction-payment-rpc-runtime-api/std", ] diff --git a/substrate/runtime/src/lib.rs b/substrate/runtime/src/lib.rs index 1be269070..13fed56d9 100644 --- a/substrate/runtime/src/lib.rs +++ b/substrate/runtime/src/lib.rs @@ -20,7 +20,6 @@ pub use coins_pallet as coins; pub use dex_pallet as dex; pub use validator_sets_pallet as validator_sets; -pub use pallet_session as session; pub use in_instructions_pallet as in_instructions; @@ -29,8 +28,6 @@ pub use signals_pallet as signals; pub use pallet_babe as babe; pub use grandpa_pallet as grandpa; -pub use pallet_authority_discovery as authority_discovery; - // Actually used by the runtime use sp_core::OpaqueMetadata; use sp_std::prelude::*; @@ -41,7 +38,7 @@ use sp_version::NativeVersion; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, KeyTypeId, - traits::{Convert, OpaqueKeys, BlakeTwo256, Block as BlockT}, + traits::{Convert, BlakeTwo256, Block as BlockT}, transaction_validity::{TransactionSource, TransactionValidity}, ApplyExtrinsicResult, Perbill, }; @@ -83,13 +80,10 @@ pub mod opaque { pub struct SessionKeys { pub babe: Babe, pub grandpa: Grandpa, - pub authority_discovery: AuthorityDiscovery, } } } -use opaque::SessionKeys; - #[sp_version::runtime_version] pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("serai"), @@ -167,12 +161,6 @@ impl Contains for CallFilter { RuntimeCall::InInstructions(call) => !matches!(call, in_instructions::Call::__Ignore(_, _)), RuntimeCall::Signals(call) => !matches!(call, signals::Call::__Ignore(_, _)), - RuntimeCall::Session(call) => match call { - session::Call::set_keys { .. } => true, - session::Call::purge_keys { .. } => false, - session::Call::__Ignore(_, _) => false, - }, - RuntimeCall::Babe(call) => match call { babe::Call::report_equivocation { .. } => true, babe::Call::report_equivocation_unsigned { .. } => true, @@ -267,18 +255,6 @@ impl Convert> for IdentityValidatorIdOf { } } -impl session::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type ValidatorId = PublicKey; - type ValidatorIdOf = IdentityValidatorIdOf; - type ShouldEndSession = Babe; - type NextSessionRotation = Babe; - type SessionManager = (); - type SessionHandler = ::KeyTypeIdProviders; - type Keys = SessionKeys; - type WeightInfo = session::weights::SubstrateWeight; -} - impl signals::Config for Runtime { type RuntimeEvent = RuntimeEvent; // 1 week @@ -319,10 +295,6 @@ impl grandpa::Config for Runtime { type EquivocationReportSystem = (); } -impl authority_discovery::Config for Runtime { - type MaxAuthorities = MaxAuthorities; -} - pub type Header = generic::Header; pub type Block = generic::Block; pub type SignedExtra = ( @@ -359,7 +331,6 @@ construct_runtime!( Dex: dex, ValidatorSets: validator_sets, - Session: session, InInstructions: in_instructions, @@ -367,8 +338,6 @@ construct_runtime!( Babe: babe, Grandpa: grandpa, - - AuthorityDiscovery: authority_discovery, } ); @@ -460,6 +429,7 @@ sp_api::impl_runtime_apis! { impl sp_session::SessionKeys for Runtime { fn generate_session_keys(seed: Option>) -> Vec { + // TODO: Do we still need this opaque::SessionKeys? if not, what do we use here? opaque::SessionKeys::generate(seed) } @@ -571,7 +541,11 @@ sp_api::impl_runtime_apis! { impl sp_authority_discovery::AuthorityDiscoveryApi for Runtime { fn authorities() -> Vec { - AuthorityDiscovery::authorities() + ValidatorSets::serai_validators() + .to_vec() + .iter() + .map(|(id, _)| AuthorityDiscoveryId::from(*id)) + .collect() } } }