Integrate session pallet into validator-sets pallet (#440)

* remove pallet-session

* Store key shares in InSet

* integrate grandpa to vs-pallet

* integrate pallet babe

* remove pallet-session & authority discovery from runtime

* update the grandpa pallet path

* cargo update grandpa

* cargo update substrate

* Misc tweaks

Sets validators for BABE/GRANDPA in chain_spec, per Akil's realization that was
the missing piece.

* fix pr comments

* bug fix & tidy up

---------

Co-authored-by: Luke Parker <lukeparker5132@gmail.com>
This commit is contained in:
akildemir
2023-11-22 14:22:46 +03:00
committed by GitHub
parent 07c657306b
commit fcfdadc791
9 changed files with 238 additions and 254 deletions

View File

@@ -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 pallet_grandpa 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<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,
@@ -256,6 +244,8 @@ impl dex::Config for Runtime {
impl validator_sets::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type ShouldEndSession = Babe;
}
pub struct IdentityValidatorIdOf;
@@ -265,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 = ValidatorSets;
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
@@ -294,7 +272,7 @@ impl babe::Config for Runtime {
type EpochDuration = ConstU64<{ 1 * DAYS }>;
type ExpectedBlockTime = ConstU64<{ TARGET_BLOCK_TIME * 1000 }>;
type EpochChangeTrigger = pallet_babe::ExternalTrigger;
type DisabledValidators = Session;
type DisabledValidators = ValidatorSets;
type WeightInfo = ();
@@ -317,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 = (
@@ -357,7 +331,6 @@ construct_runtime!(
Dex: dex,
ValidatorSets: validator_sets,
Session: session,
InInstructions: in_instructions,
@@ -365,8 +338,6 @@ construct_runtime!(
Babe: babe,
Grandpa: grandpa,
AuthorityDiscovery: authority_discovery,
}
);
@@ -569,7 +540,10 @@ sp_api::impl_runtime_apis! {
impl sp_authority_discovery::AuthorityDiscoveryApi<Block> for Runtime {
fn authorities() -> Vec<AuthorityDiscoveryId> {
AuthorityDiscovery::authorities()
Babe::authorities()
.into_iter()
.map(|(id, _)| AuthorityDiscoveryId::from(id.into_inner()))
.collect()
}
}
}