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",
"frame-support",
"frame-system",
"pallet-babe",
"pallet-grandpa",
"pallet-session",
"parity-scale-codec",
"rand_core 0.6.4",
"serai-abi",

View File

@@ -136,7 +136,9 @@ impl serai_coins_pallet::Config<CoinsInstance> for Runtime {
impl serai_coins_pallet::Config<LiquidityTokensInstance> for Runtime {
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 {
type RetirementValidityDuration = sp_core::ConstU64<0>; // TODO
type RetirementLockInDuration = sp_core::ConstU64<0>; // TODO
@@ -424,28 +426,11 @@ impl timestamp::Config for Runtime {
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 {
type RuntimeEvent = RuntimeEvent;
type AllowMint = ValidatorSets;
}
impl coins::Config<coins::Instance1> for Runtime {
type RuntimeEvent = RuntimeEvent;
type AllowMint = ();
}
impl dex::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type LPFee = ConstU32<3>; // 0.3%
type MintMinLiquidity = ConstU64<10000>;
@@ -456,12 +441,6 @@ impl dex::Config for Runtime {
type WeightInfo = dex::weights::SubstrateWeight<Runtime>;
}
impl validator_sets::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type ShouldEndSession = Babe;
}
pub struct IdentityValidatorIdOf;
impl Convert<PublicKey, Option<PublicKey>> for IdentityValidatorIdOf {
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-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"] }
@@ -55,6 +56,7 @@ std = [
"pallet-session/std",
"pallet-babe/std",
"pallet-grandpa/std",
"serai-abi/std",
@@ -69,6 +71,7 @@ try-runtime = [
"pallet-session/try-runtime",
"pallet-babe/try-runtime",
"pallet-grandpa/try-runtime",
]
runtime-benchmarks = [
@@ -76,6 +79,7 @@ runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"pallet-babe/runtime-benchmarks",
"pallet-grandpa/runtime-benchmarks",
]
default = ["std"]

View File

@@ -49,6 +49,7 @@ mod pallet {
use pallet_session::ShouldEndSession;
use pallet_babe::Pallet as Babe;
use pallet_grandpa::Pallet as Grandpa;
use serai_abi::primitives::{
crypto::SignedEmbeddedEllipticCurveKeys,
@@ -68,6 +69,7 @@ mod pallet {
frame_system::Config
+ pallet_session::Config
+ pallet_babe::Config
+ pallet_grandpa::Config
+ serai_coins_pallet::Config<serai_coins_pallet::CoinsInstance>
{
type ShouldEndSession: ShouldEndSession<BlockNumberFor<Self>>;
@@ -245,11 +247,17 @@ mod pallet {
"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(
Abstractions::<T>::serai_validators(Session(0))
genesis_serai_validators
.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);
}
/* TODO
Dex::<T>::on_new_session(network);
Grandpa::new_session
*/
// TODO Dex::<T>::on_new_session(network);
}
/*
@@ -421,15 +426,6 @@ mod pallet {
pub(crate) fn rotate_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
// First drain so we don't mutate as we iterate
let mut disabled = vec![];
@@ -566,6 +562,7 @@ mod pallet {
fn on_initialize(n: BlockNumberFor<T>) -> Weight {
if <T as Config>::ShouldEndSession::should_end_session(n) {
Babe::<T>::on_before_session_ending();
Grandpa::<T>::on_before_session_ending();
{
// 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 weren't able to be fetched from storage",
);
let serai_validators = Abstractions::<T>::serai_validators(current_serai_session);
let validators_changed = prior_serai_validators != serai_validators;
let queued_serai_validators =
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())
}
Babe::<T>::on_new_session(
prior_serai_validators != serai_validators,
serai_validators.iter().map(map),
queued_serai_validators.iter().map(map),
validators_changed,
serai_validators.iter().map(map_babe),
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),
);
}