Restore usage of pallet-grandpa to serai-validator-sets-pallet

This commit is contained in:
Luke Parker
2025-09-20 01:36:11 -04:00
parent a2d8d0fd13
commit e62b62ddfb
4 changed files with 42 additions and 44 deletions

3
Cargo.lock generated
View File

@@ -9740,6 +9740,9 @@ dependencies = [
"borsh", "borsh",
"frame-support", "frame-support",
"frame-system", "frame-system",
"pallet-babe",
"pallet-grandpa",
"pallet-session",
"parity-scale-codec", "parity-scale-codec",
"rand_core 0.6.4", "rand_core 0.6.4",
"serai-abi", "serai-abi",

View File

@@ -136,7 +136,9 @@ impl serai_coins_pallet::Config<CoinsInstance> for Runtime {
impl serai_coins_pallet::Config<LiquidityTokensInstance> for Runtime { impl serai_coins_pallet::Config<LiquidityTokensInstance> for Runtime {
type AllowMint = serai_coins_pallet::AlwaysAllowMint; type AllowMint = serai_coins_pallet::AlwaysAllowMint;
} }
impl serai_validator_sets_pallet::Config for Runtime {} impl serai_validator_sets_pallet::Config for Runtime {
type ShouldEndSession = Babe;
}
impl serai_signals_pallet::Config for Runtime { impl serai_signals_pallet::Config for Runtime {
type RetirementValidityDuration = sp_core::ConstU64<0>; // TODO type RetirementValidityDuration = sp_core::ConstU64<0>; // TODO
type RetirementLockInDuration = sp_core::ConstU64<0>; // TODO type RetirementLockInDuration = sp_core::ConstU64<0>; // TODO
@@ -424,28 +426,11 @@ impl timestamp::Config for Runtime {
type WeightInfo = (); type WeightInfo = ();
} }
impl transaction_payment::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OnChargeTransaction = Coins;
type OperationalFeeMultiplier = ConstU8<5>;
type WeightToFee = IdentityFee<SubstrateAmount>;
type LengthToFee = IdentityFee<SubstrateAmount>;
type FeeMultiplierUpdate = ();
}
impl coins::Config for Runtime { impl coins::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type AllowMint = ValidatorSets; type AllowMint = ValidatorSets;
} }
impl coins::Config<coins::Instance1> for Runtime {
type RuntimeEvent = RuntimeEvent;
type AllowMint = ();
}
impl dex::Config for Runtime { impl dex::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type LPFee = ConstU32<3>; // 0.3% type LPFee = ConstU32<3>; // 0.3%
type MintMinLiquidity = ConstU64<10000>; type MintMinLiquidity = ConstU64<10000>;
@@ -456,12 +441,6 @@ impl dex::Config for Runtime {
type WeightInfo = dex::weights::SubstrateWeight<Runtime>; type WeightInfo = dex::weights::SubstrateWeight<Runtime>;
} }
impl validator_sets::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type ShouldEndSession = Babe;
}
pub struct IdentityValidatorIdOf; pub struct IdentityValidatorIdOf;
impl Convert<PublicKey, Option<PublicKey>> for IdentityValidatorIdOf { impl Convert<PublicKey, Option<PublicKey>> for IdentityValidatorIdOf {
fn convert(key: PublicKey) -> Option<PublicKey> { fn convert(key: PublicKey) -> Option<PublicKey> {

View File

@@ -29,6 +29,7 @@ frame-support = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev =
pallet-session = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "16336c737dbe833e9d138a256af99698aba637c7", default-features = false } pallet-session = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "16336c737dbe833e9d138a256af99698aba637c7", default-features = false }
pallet-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "16336c737dbe833e9d138a256af99698aba637c7", default-features = false } pallet-babe = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "16336c737dbe833e9d138a256af99698aba637c7", default-features = false }
pallet-grandpa = { git = "https://github.com/serai-dex/patch-polkadot-sdk", rev = "16336c737dbe833e9d138a256af99698aba637c7", default-features = false }
serai-abi = { path = "../abi", default-features = false, features = ["substrate"] } serai-abi = { path = "../abi", default-features = false, features = ["substrate"] }
@@ -55,6 +56,7 @@ std = [
"pallet-session/std", "pallet-session/std",
"pallet-babe/std", "pallet-babe/std",
"pallet-grandpa/std",
"serai-abi/std", "serai-abi/std",
@@ -69,6 +71,7 @@ try-runtime = [
"pallet-session/try-runtime", "pallet-session/try-runtime",
"pallet-babe/try-runtime", "pallet-babe/try-runtime",
"pallet-grandpa/try-runtime",
] ]
runtime-benchmarks = [ runtime-benchmarks = [
@@ -76,6 +79,7 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks", "frame-support/runtime-benchmarks",
"pallet-babe/runtime-benchmarks", "pallet-babe/runtime-benchmarks",
"pallet-grandpa/runtime-benchmarks",
] ]
default = ["std"] default = ["std"]

View File

@@ -49,6 +49,7 @@ mod pallet {
use pallet_session::ShouldEndSession; use pallet_session::ShouldEndSession;
use pallet_babe::Pallet as Babe; use pallet_babe::Pallet as Babe;
use pallet_grandpa::Pallet as Grandpa;
use serai_abi::primitives::{ use serai_abi::primitives::{
crypto::SignedEmbeddedEllipticCurveKeys, crypto::SignedEmbeddedEllipticCurveKeys,
@@ -68,6 +69,7 @@ mod pallet {
frame_system::Config frame_system::Config
+ pallet_session::Config + pallet_session::Config
+ pallet_babe::Config + pallet_babe::Config
+ pallet_grandpa::Config
+ serai_coins_pallet::Config<serai_coins_pallet::CoinsInstance> + serai_coins_pallet::Config<serai_coins_pallet::CoinsInstance>
{ {
type ShouldEndSession: ShouldEndSession<BlockNumberFor<Self>>; type ShouldEndSession: ShouldEndSession<BlockNumberFor<Self>>;
@@ -245,11 +247,17 @@ mod pallet {
"failed to attempt the next session for the Serai network on genesis" "failed to attempt the next session for the Serai network on genesis"
); );
// Spawn BABE's genesis session // Spawn BABE's, GRANDPA's genesis session
let genesis_serai_validators = Abstractions::<T>::serai_validators(Session(0));
Babe::<T>::on_genesis_session( Babe::<T>::on_genesis_session(
Abstractions::<T>::serai_validators(Session(0)) genesis_serai_validators
.iter() .iter()
.map(|(validator, key)| (validator, pallet_babe::AuthorityId::from(*key))), .map(|(validator, key)| (validator, (*key).into())),
);
Grandpa::<T>::on_genesis_session(
genesis_serai_validators
.iter()
.map(|(validator, key)| (validator, (*key).into())),
); );
} }
} }
@@ -304,10 +312,7 @@ mod pallet {
Abstractions::<T>::attempt_new_session(network.into(), include_genesis_validators); Abstractions::<T>::attempt_new_session(network.into(), include_genesis_validators);
} }
/* TODO // TODO Dex::<T>::on_new_session(network);
Dex::<T>::on_new_session(network);
Grandpa::new_session
*/
} }
/* /*
@@ -421,15 +426,6 @@ mod pallet {
pub(crate) fn rotate_session() { pub(crate) fn rotate_session() {
Self::retire_set(ValidatorSet { network: NetworkId::Serai, session: prior_serai_session }); Self::retire_set(ValidatorSet { network: NetworkId::Serai, session: prior_serai_session });
// make a new session and get the next validator set.
Self::new_session();
Grandpa::<T>::new_session(
true,
session,
now_validators.into_iter().map(|(id, w)| (GrandpaAuthorityId::from(id), w)).collect(),
);
// Clear SeraiDisabledIndices, only preserving keys still present in the new session // Clear SeraiDisabledIndices, only preserving keys still present in the new session
// First drain so we don't mutate as we iterate // First drain so we don't mutate as we iterate
let mut disabled = vec![]; let mut disabled = vec![];
@@ -566,6 +562,7 @@ mod pallet {
fn on_initialize(n: BlockNumberFor<T>) -> Weight { fn on_initialize(n: BlockNumberFor<T>) -> Weight {
if <T as Config>::ShouldEndSession::should_end_session(n) { if <T as Config>::ShouldEndSession::should_end_session(n) {
Babe::<T>::on_before_session_ending(); Babe::<T>::on_before_session_ending();
Grandpa::<T>::on_before_session_ending();
{ {
// Accept the hand-over to the next session for the Serai network // Accept the hand-over to the next session for the Serai network
@@ -598,17 +595,32 @@ mod pallet {
!prior_serai_validators.is_empty(), !prior_serai_validators.is_empty(),
"prior Serai validators weren't able to be fetched from storage", "prior Serai validators weren't able to be fetched from storage",
); );
let serai_validators = Abstractions::<T>::serai_validators(current_serai_session); let serai_validators = Abstractions::<T>::serai_validators(current_serai_session);
let validators_changed = prior_serai_validators != serai_validators;
let queued_serai_validators = let queued_serai_validators =
Abstractions::<T>::serai_validators(latest_decided_serai_session); Abstractions::<T>::serai_validators(latest_decided_serai_session);
fn map((validator, key): &(Public, Public)) -> (&Public, pallet_babe::AuthorityId) { fn map_babe((validator, key): &(Public, Public)) -> (&Public, pallet_babe::AuthorityId) {
(validator, (*key).into()) (validator, (*key).into())
} }
Babe::<T>::on_new_session( Babe::<T>::on_new_session(
prior_serai_validators != serai_validators, validators_changed,
serai_validators.iter().map(map), serai_validators.iter().map(map_babe),
queued_serai_validators.iter().map(map), queued_serai_validators.iter().map(map_babe),
);
fn map_grandpa(
(validator, key): &(Public, Public),
) -> (&Public, pallet_grandpa::AuthorityId) {
(validator, (*key).into())
}
Grandpa::<T>::on_new_session(
validators_changed,
serai_validators.iter().map(map_grandpa),
queued_serai_validators.iter().map(map_grandpa),
); );
} }