1
1
#![ cfg_attr( not( feature = "std" ) , no_std) ]
2
2
3
+ // extern crate alloc;
4
+
3
5
pub use pallet:: * ;
4
6
pub mod weights;
5
7
pub use weights:: WeightInfo ;
6
8
7
9
use frame_system:: pallet_prelude:: BlockNumberFor ;
8
- use sp_runtime:: { traits:: Member , RuntimeAppPublic } ;
10
+ // - we could replace it with Vec<(AuthorityId, u64)>, but we would need
11
+ // `sp_consensus_grandpa` for `AuthorityId` anyway
12
+ // - we could use a type parameter for `AuthorityId`, but there is
13
+ // no sense for this as GRANDPA's `AuthorityId` is not a parameter -- it's always the same
14
+ use sp_consensus_grandpa:: AuthorityList ;
15
+ use sp_runtime:: { traits:: Member , DispatchResult , RuntimeAppPublic } ;
9
16
10
17
mod benchmarking;
11
18
@@ -41,6 +48,9 @@ pub mod pallet {
41
48
/// Implementation of the AuraInterface
42
49
type Aura : crate :: AuraInterface < <Self as Config >:: AuthorityId , Self :: MaxAuthorities > ;
43
50
51
+ /// Implementation of [`GrandpaInterface`]
52
+ type Grandpa : crate :: GrandpaInterface < Self > ;
53
+
44
54
/// The identifier type for an authority.
45
55
type AuthorityId : Member
46
56
+ Parameter
@@ -1238,6 +1248,34 @@ pub mod pallet {
1238
1248
ChainId :: < T > :: set ( chain_id) ;
1239
1249
Ok ( ( ) )
1240
1250
}
1251
+
1252
+ /// A public interface for `pallet_grandpa::Pallet::schedule_grandpa_change`.
1253
+ ///
1254
+ /// Schedule a change in the authorities.
1255
+ ///
1256
+ /// The change will be applied at the end of execution of the block `in_blocks` after the
1257
+ /// current block. This value may be 0, in which case the change is applied at the end of
1258
+ /// the current block.
1259
+ ///
1260
+ /// If the `forced` parameter is defined, this indicates that the current set has been
1261
+ /// synchronously determined to be offline and that after `in_blocks` the given change
1262
+ /// should be applied. The given block number indicates the median last finalized block
1263
+ /// number and it should be used as the canon block when starting the new grandpa voter.
1264
+ ///
1265
+ /// No change should be signaled while any change is pending. Returns an error if a change
1266
+ /// is already pending.
1267
+ #[ pallet:: call_index( 59 ) ]
1268
+ #[ pallet:: weight( <T as Config >:: WeightInfo :: swap_authorities( next_authorities. len( ) as u32 ) ) ]
1269
+ pub fn schedule_grandpa_change (
1270
+ origin : OriginFor < T > ,
1271
+ // grandpa ID is always the same type, so we don't need to parametrize it via `Config`
1272
+ next_authorities : AuthorityList ,
1273
+ in_blocks : BlockNumberFor < T > ,
1274
+ forced : Option < BlockNumberFor < T > > ,
1275
+ ) -> DispatchResult {
1276
+ ensure_root ( origin) ?;
1277
+ T :: Grandpa :: schedule_change ( next_authorities, in_blocks, forced)
1278
+ }
1241
1279
}
1242
1280
}
1243
1281
@@ -1255,3 +1293,27 @@ pub trait AuraInterface<AuthorityId, MaxAuthorities> {
1255
1293
impl < A , M > AuraInterface < A , M > for ( ) {
1256
1294
fn change_authorities ( _: BoundedVec < A , M > ) { }
1257
1295
}
1296
+
1297
+ pub trait GrandpaInterface < Runtime >
1298
+ where
1299
+ Runtime : frame_system:: Config ,
1300
+ {
1301
+ fn schedule_change (
1302
+ next_authorities : AuthorityList ,
1303
+ in_blocks : BlockNumberFor < Runtime > ,
1304
+ forced : Option < BlockNumberFor < Runtime > > ,
1305
+ ) -> DispatchResult ;
1306
+ }
1307
+
1308
+ impl < R > GrandpaInterface < R > for ( )
1309
+ where
1310
+ R : frame_system:: Config ,
1311
+ {
1312
+ fn schedule_change (
1313
+ _next_authorities : AuthorityList ,
1314
+ _in_blocks : BlockNumberFor < R > ,
1315
+ _forced : Option < BlockNumberFor < R > > ,
1316
+ ) -> DispatchResult {
1317
+ Ok ( ( ) )
1318
+ }
1319
+ }
0 commit comments