Skip to content

Commit

Permalink
remove pallet-session & authority discovery from runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
akildemir committed Nov 17, 2023
1 parent 26c26b1 commit 7feaf9e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 73 deletions.
18 changes: 0 additions & 18 deletions Cargo.lock

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

18 changes: 2 additions & 16 deletions substrate/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RuntimeGenesisConfig>;
Expand All @@ -21,16 +20,6 @@ fn testnet_genesis(
validators: &[&'static str],
endowed_accounts: Vec<PublicKey>,
) -> 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 },

Expand Down Expand Up @@ -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 },
}
}

Expand Down
6 changes: 0 additions & 6 deletions substrate/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand All @@ -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 }

Expand Down Expand Up @@ -104,7 +101,6 @@ std = [
"dex-pallet/std",

"validator-sets-pallet/std",
"pallet-session/std",

"in-instructions-pallet/std",

Expand All @@ -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",
]
Expand Down
40 changes: 7 additions & 33 deletions substrate/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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::*;
Expand All @@ -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,
};
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -167,12 +161,6 @@ impl Contains<RuntimeCall> 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,
Expand Down Expand Up @@ -267,18 +255,6 @@ impl Convert<PublicKey, Option<PublicKey>> 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 = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
type Keys = SessionKeys;
type WeightInfo = session::weights::SubstrateWeight<Runtime>;
}

impl signals::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
// 1 week
Expand Down Expand Up @@ -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<BlockNumber, BlakeTwo256>;
pub type Block = generic::Block<Header, UncheckedExtrinsic>;
pub type SignedExtra = (
Expand Down Expand Up @@ -359,16 +331,13 @@ construct_runtime!(
Dex: dex,

ValidatorSets: validator_sets,
Session: session,

InInstructions: in_instructions,

Signals: signals,

Babe: babe,
Grandpa: grandpa,

AuthorityDiscovery: authority_discovery,
}
);

Expand Down Expand Up @@ -460,6 +429,7 @@ sp_api::impl_runtime_apis! {

impl sp_session::SessionKeys<Block> for Runtime {
fn generate_session_keys(seed: Option<Vec<u8>>) -> Vec<u8> {
// TODO: Do we still need this opaque::SessionKeys? if not, what do we use here?
opaque::SessionKeys::generate(seed)
}

Expand Down Expand Up @@ -571,7 +541,11 @@ sp_api::impl_runtime_apis! {

impl sp_authority_discovery::AuthorityDiscoveryApi<Block> for Runtime {
fn authorities() -> Vec<AuthorityDiscoveryId> {
AuthorityDiscovery::authorities()
ValidatorSets::serai_validators()
.to_vec()
.iter()
.map(|(id, _)| AuthorityDiscoveryId::from(*id))
.collect()
}
}
}

0 comments on commit 7feaf9e

Please sign in to comment.