Skip to content

Commit 772fffd

Browse files
committed
Add grandpa interface to pallet-admin-utils
1 parent b139ec3 commit 772fffd

File tree

3 files changed

+56
-11
lines changed

3 files changed

+56
-11
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pallets/admin-utils/Cargo.toml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ sp-weights = { workspace = true }
3131
substrate-fixed = { workspace = true }
3232
pallet-evm-chain-id = { workspace = true }
3333
pallet-drand = { workspace = true, default-features = false }
34+
sp-consensus-grandpa = { workspace = true }
3435

3536
[dev-dependencies]
3637
sp-core = { workspace = true }
@@ -48,21 +49,22 @@ std = [
4849
"frame-benchmarking?/std",
4950
"frame-support/std",
5051
"frame-system/std",
51-
"scale-info/std",
52-
"pallet-subtensor/std",
53-
"sp-consensus-aura/std",
52+
"log/std",
5453
"pallet-balances/std",
54+
"pallet-drand/std",
5555
"pallet-evm-chain-id/std",
5656
"pallet-scheduler/std",
57-
"sp-runtime/std",
58-
"sp-tracing/std",
59-
"sp-weights/std",
60-
"log/std",
57+
"pallet-subtensor/std",
58+
"scale-info/std",
59+
"sp-consensus-aura/std",
60+
"sp-consensus-grandpa/std",
6161
"sp-core/std",
6262
"sp-io/std",
63+
"sp-runtime/std",
6364
"sp-std/std",
65+
"sp-tracing/std",
66+
"sp-weights/std",
6467
"substrate-fixed/std",
65-
"pallet-drand/std"
6668
]
6769
runtime-benchmarks = [
6870
"frame-benchmarking/runtime-benchmarks",
@@ -72,7 +74,7 @@ runtime-benchmarks = [
7274
"sp-runtime/runtime-benchmarks",
7375
"pallet-subtensor/runtime-benchmarks",
7476
"pallet-scheduler/runtime-benchmarks",
75-
"pallet-drand/runtime-benchmarks"
77+
"pallet-drand/runtime-benchmarks",
7678
]
7779
try-runtime = [
7880
"frame-support/try-runtime",
@@ -82,5 +84,5 @@ try-runtime = [
8284
"pallet-scheduler/try-runtime",
8385
"sp-runtime/try-runtime",
8486
"pallet-subtensor/try-runtime",
85-
"pallet-drand/try-runtime"
87+
"pallet-drand/try-runtime",
8688
]

pallets/admin-utils/src/lib.rs

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ pub mod weights;
55
pub use weights::WeightInfo;
66

77
use frame_system::pallet_prelude::BlockNumberFor;
8-
use sp_runtime::{traits::Member, RuntimeAppPublic};
8+
use sp_consensus_grandpa::AuthorityId as GrandpaId;
9+
use sp_runtime::{traits::Member, DispatchResult, RuntimeAppPublic};
910

1011
mod benchmarking;
1112

@@ -41,6 +42,9 @@ pub mod pallet {
4142
/// Implementation of the AuraInterface
4243
type Aura: crate::AuraInterface<<Self as Config>::AuthorityId, Self::MaxAuthorities>;
4344

45+
/// Implementation of [`GrandpaInterface`]
46+
type Grandpa: crate::GrandpaInterface<Self>;
47+
4448
/// The identifier type for an authority.
4549
type AuthorityId: Member
4650
+ Parameter
@@ -1238,6 +1242,20 @@ pub mod pallet {
12381242
ChainId::<T>::set(chain_id);
12391243
Ok(())
12401244
}
1245+
1246+
/// A public interface for `pallet_grandpa::Pallet::schedule_grandpa_change`.
1247+
#[pallet::call_index(59)]
1248+
#[pallet::weight(<T as Config>::WeightInfo::swap_authorities(next_authorities.len() as u32))]
1249+
pub fn schedule_grandpa_change(
1250+
origin: OriginFor<T>,
1251+
// grandpa ID is always the same type, so we don't need to parametrize it via `Config`
1252+
next_authorities: Vec<(GrandpaId, u64)>,
1253+
in_blocks: BlockNumberFor<T>,
1254+
forced: Option<BlockNumberFor<T>>,
1255+
) -> DispatchResult {
1256+
ensure_root(origin)?;
1257+
T::Grandpa::schedule_change(next_authorities, in_blocks, forced)
1258+
}
12411259
}
12421260
}
12431261

@@ -1255,3 +1273,27 @@ pub trait AuraInterface<AuthorityId, MaxAuthorities> {
12551273
impl<A, M> AuraInterface<A, M> for () {
12561274
fn change_authorities(_: BoundedVec<A, M>) {}
12571275
}
1276+
1277+
pub trait GrandpaInterface<Runtime>
1278+
where
1279+
Runtime: frame_system::Config,
1280+
{
1281+
fn schedule_change(
1282+
next_authorities: Vec<(GrandpaId, u64)>,
1283+
in_blocks: BlockNumberFor<Runtime>,
1284+
forced: Option<BlockNumberFor<Runtime>>,
1285+
) -> DispatchResult;
1286+
}
1287+
1288+
impl<R> GrandpaInterface<R> for ()
1289+
where
1290+
R: frame_system::Config,
1291+
{
1292+
fn schedule_change(
1293+
_next_authorities: Vec<(GrandpaId, u64)>,
1294+
_in_blocks: BlockNumberFor<R>,
1295+
_forced: Option<BlockNumberFor<R>>,
1296+
) -> DispatchResult {
1297+
Ok(())
1298+
}
1299+
}

0 commit comments

Comments
 (0)