@@ -5,7 +5,8 @@ pub mod weights;
5
5
pub use weights:: WeightInfo ;
6
6
7
7
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 } ;
9
10
10
11
mod benchmarking;
11
12
@@ -41,6 +42,9 @@ pub mod pallet {
41
42
/// Implementation of the AuraInterface
42
43
type Aura : crate :: AuraInterface < <Self as Config >:: AuthorityId , Self :: MaxAuthorities > ;
43
44
45
+ /// Implementation of [`GrandpaInterface`]
46
+ type Grandpa : crate :: GrandpaInterface < Self > ;
47
+
44
48
/// The identifier type for an authority.
45
49
type AuthorityId : Member
46
50
+ Parameter
@@ -1238,6 +1242,20 @@ pub mod pallet {
1238
1242
ChainId :: < T > :: set ( chain_id) ;
1239
1243
Ok ( ( ) )
1240
1244
}
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
+ }
1241
1259
}
1242
1260
}
1243
1261
@@ -1255,3 +1273,27 @@ pub trait AuraInterface<AuthorityId, MaxAuthorities> {
1255
1273
impl < A , M > AuraInterface < A , M > for ( ) {
1256
1274
fn change_authorities ( _: BoundedVec < A , M > ) { }
1257
1275
}
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