@@ -27,7 +27,7 @@ use frame_system::EnsureRoot;
27
27
use opaque:: SessionKeys ;
28
28
use pallet_block_producer_metadata;
29
29
use pallet_grandpa:: AuthorityId as GrandpaId ;
30
- use pallet_session_validator_management:: session_manager :: ValidatorManagementSessionManager ;
30
+ use pallet_session_validator_management:: pallet_session_support :: PalletSessionSupport ;
31
31
use pallet_transaction_payment:: { ConstFeeMultiplier , FungibleAdapter , Multiplier } ;
32
32
use parity_scale_codec:: { Decode , DecodeWithMemTracking , Encode , MaxEncodedLen } ;
33
33
use scale_info:: TypeInfo ;
@@ -47,6 +47,7 @@ use sp_core::{OpaqueMetadata, crypto::KeyTypeId};
47
47
use sp_governed_map:: MainChainScriptsV1 ;
48
48
use sp_inherents:: InherentIdentifier ;
49
49
use sp_partner_chains_bridge:: { BridgeDataCheckpoint , MainChainScripts as BridgeMainChainScripts } ;
50
+ use sp_runtime:: traits:: ConvertInto ;
50
51
use sp_runtime:: {
51
52
ApplyExtrinsicResult , MultiSignature , Perbill , generic, impl_opaque_keys,
52
53
traits:: {
@@ -304,7 +305,19 @@ impl pallet_aura::Config for Runtime {
304
305
type SlotDuration = ConstU64 < SLOT_DURATION > ;
305
306
}
306
307
307
- pallet_partner_chains_session:: impl_pallet_session_config!( Runtime ) ;
308
+ impl pallet_session:: Config for Runtime {
309
+ type RuntimeEvent = RuntimeEvent ;
310
+ type ValidatorId = AccountId ;
311
+ type ValidatorIdOf = ConvertInto ;
312
+ type ShouldEndSession = PalletSessionSupport < Runtime > ;
313
+ type NextSessionRotation = ( ) ;
314
+ type SessionManager = PalletSessionSupport < Runtime > ;
315
+ type SessionHandler = <SessionKeys as OpaqueKeys >:: KeyTypeIdProviders ;
316
+ type Keys = SessionKeys ;
317
+ type DisablingStrategy = pallet_session:: disabling:: UpToLimitWithReEnablingDisablingStrategy ;
318
+
319
+ type WeightInfo = pallet_session:: weights:: SubstrateWeight < Runtime > ;
320
+ }
308
321
309
322
impl pallet_grandpa:: Config for Runtime {
310
323
type RuntimeEvent = RuntimeEvent ;
@@ -368,15 +381,6 @@ impl pallet_sudo::Config for Runtime {
368
381
type WeightInfo = pallet_sudo:: weights:: SubstrateWeight < Runtime > ;
369
382
}
370
383
371
- impl pallet_partner_chains_session:: Config for Runtime {
372
- type ValidatorId = <Self as frame_system:: Config >:: AccountId ;
373
- type ShouldEndSession = ValidatorManagementSessionManager < Runtime > ;
374
- type NextSessionRotation = ( ) ;
375
- type SessionManager = ValidatorManagementSessionManager < Runtime > ;
376
- type SessionHandler = <opaque:: SessionKeys as OpaqueKeys >:: KeyTypeIdProviders ;
377
- type Keys = opaque:: SessionKeys ;
378
- }
379
-
380
384
parameter_types ! {
381
385
pub const MaxValidators : u32 = 1024 ;
382
386
}
@@ -708,13 +712,11 @@ construct_runtime!(
708
712
BlockProducerMetadata : pallet_block_producer_metadata,
709
713
BlockProductionLog : pallet_block_production_log,
710
714
BlockParticipation : pallet_block_participation,
711
- // pallet_grandpa reads pallet_session::pallet::CurrentIndex storage.
712
- // Only stub implementation of pallet_session should be wired.
713
- // Partner Chains session_manager ValidatorManagementSessionManager writes to pallet_session::pallet::CurrentIndex.
714
- // ValidatorManagementSessionManager is wired in by pallet_partner_chains_session.
715
- PalletSession : pallet_session,
716
- // The order matters!! pallet_partner_chains_session needs to come last for correct initialization order
717
- Session : pallet_partner_chains_session,
715
+ // We exclude pallet's extrinsics to make them unavailable to users to submit.
716
+ // This is to ensure that registrations on Cardano coming in throught the
717
+ // `SessionCommitteeManagement` pallet are the only source of truth about keys
718
+ // and accounts of block producers.
719
+ Session : pallet_session exclude_parts { Call } ,
718
720
GovernedMap : pallet_governed_map,
719
721
Bridge : pallet_partner_chains_bridge,
720
722
TestHelperPallet : crate :: test_helper_pallet,
@@ -910,7 +912,6 @@ impl_runtime_apis! {
910
912
}
911
913
}
912
914
913
-
914
915
impl frame_system_rpc_runtime_api:: AccountNonceApi <Block , AccountId , Nonce > for Runtime {
915
916
fn account_nonce( account: AccountId ) -> Nonce {
916
917
System :: account_nonce( account)
@@ -1160,6 +1161,7 @@ mod tests {
1160
1161
inherent:: ProvideInherent ,
1161
1162
traits:: { UnfilteredDispatchable , WhitelistedStorageKeys } ,
1162
1163
} ;
1164
+ use pretty_assertions:: assert_eq;
1163
1165
use sp_core:: { Pair , hexdisplay:: HexDisplay } ;
1164
1166
use sp_inherents:: InherentData ;
1165
1167
use std:: collections:: HashSet ;
@@ -1199,6 +1201,8 @@ mod tests {
1199
1201
new_test_ext ( ) . execute_with ( || {
1200
1202
// Needs to be run to initialize first slot and epoch numbers;
1201
1203
advance_block ( ) ;
1204
+
1205
+ // Scheduled committee goes into effect after a 2-epoch delay
1202
1206
set_committee_through_inherent_data ( & [ alice ( ) ] ) ;
1203
1207
until_epoch_after_finalizing ( 1 , & || {
1204
1208
assert_current_epoch ! ( 0 ) ;
@@ -1210,30 +1214,37 @@ mod tests {
1210
1214
for_next_n_blocks_after_finalizing ( SLOTS_PER_EPOCH , & || {
1211
1215
assert_current_epoch ! ( 1 ) ;
1212
1216
assert_grandpa_weights ( ) ;
1213
- assert_grandpa_authorities ! ( [ alice( ) ] ) ;
1217
+ assert_grandpa_authorities ! ( [ alice( ) , bob ( ) ] ) ;
1214
1218
} ) ;
1215
-
1219
+ set_committee_through_inherent_data ( & [ alice ( ) ] ) ;
1216
1220
for_next_n_blocks_after_finalizing ( SLOTS_PER_EPOCH , & || {
1217
1221
assert_current_epoch ! ( 2 ) ;
1218
1222
assert_grandpa_weights ( ) ;
1219
- assert_grandpa_authorities ! ( [ bob ( ) ] ) ;
1223
+ assert_grandpa_authorities ! ( [ alice ( ) ] ) ;
1220
1224
} ) ;
1221
-
1222
- // Authorities can be set as late as in the first block of new epoch, but it makes session last 1 block longer
1223
- set_committee_through_inherent_data ( & [ alice ( ) ] ) ;
1224
- advance_block ( ) ;
1225
- assert_current_epoch ! ( 3 ) ;
1226
- assert_grandpa_authorities ! ( [ bob( ) ] ) ;
1227
1225
set_committee_through_inherent_data ( & [ alice ( ) , bob ( ) ] ) ;
1228
- for_next_n_blocks_after_finalizing ( SLOTS_PER_EPOCH - 1 , & || {
1226
+ for_next_n_blocks_after_finalizing ( SLOTS_PER_EPOCH , & || {
1229
1227
assert_current_epoch ! ( 3 ) ;
1230
1228
assert_grandpa_weights ( ) ;
1229
+ assert_grandpa_authorities ! ( [ bob( ) ] ) ;
1230
+ } ) ;
1231
+ set_committee_through_inherent_data ( & [ bob ( ) , alice ( ) ] ) ;
1232
+ for_next_n_blocks_after_finalizing ( SLOTS_PER_EPOCH , & || {
1233
+ assert_current_epoch ! ( 4 ) ;
1234
+ assert_grandpa_weights ( ) ;
1231
1235
assert_grandpa_authorities ! ( [ alice( ) ] ) ;
1232
1236
} ) ;
1237
+ set_committee_through_inherent_data ( & [ alice ( ) ] ) ;
1238
+ for_next_n_blocks_after_finalizing ( SLOTS_PER_EPOCH , & || {
1239
+ assert_current_epoch ! ( 5 ) ;
1240
+ assert_grandpa_weights ( ) ;
1241
+ assert_grandpa_authorities ! ( [ alice( ) , bob( ) ] ) ;
1242
+ } ) ;
1233
1243
1244
+ // When there's no new committees being scheduled, the last committee stays in power
1234
1245
for_next_n_blocks_after_finalizing ( SLOTS_PER_EPOCH * 3 , & || {
1235
1246
assert_grandpa_weights ( ) ;
1236
- assert_grandpa_authorities ! ( [ alice ( ) , bob ( ) ] ) ;
1247
+ assert_grandpa_authorities ! ( [ bob ( ) , alice ( ) ] ) ;
1237
1248
} ) ;
1238
1249
} ) ;
1239
1250
@@ -1248,33 +1259,46 @@ mod tests {
1248
1259
#[ test]
1249
1260
fn check_aura_authorities_rotation ( ) {
1250
1261
new_test_ext ( ) . execute_with ( || {
1262
+ // Needs to be run to initialize first slot and epoch numbers;
1251
1263
advance_block ( ) ;
1264
+
1265
+ // Scheduled committee goes into effect after a 2-epoch delay
1252
1266
set_committee_through_inherent_data ( & [ alice ( ) ] ) ;
1253
- until_epoch ( 1 , & || {
1267
+ until_epoch_after_finalizing ( 1 , & || {
1254
1268
assert_current_epoch ! ( 0 ) ;
1255
1269
assert_aura_authorities ! ( [ alice( ) , bob( ) ] ) ;
1256
1270
} ) ;
1257
1271
1258
- for_next_n_blocks ( SLOTS_PER_EPOCH , & || {
1272
+ set_committee_through_inherent_data ( & [ bob ( ) ] ) ;
1273
+ for_next_n_blocks_after_finalizing ( SLOTS_PER_EPOCH , & || {
1259
1274
assert_current_epoch ! ( 1 ) ;
1275
+ assert_aura_authorities ! ( [ alice( ) , bob( ) ] ) ;
1276
+ } ) ;
1277
+ set_committee_through_inherent_data ( & [ alice ( ) ] ) ;
1278
+ for_next_n_blocks_after_finalizing ( SLOTS_PER_EPOCH , & || {
1279
+ assert_current_epoch ! ( 2 ) ;
1260
1280
assert_aura_authorities ! ( [ alice( ) ] ) ;
1261
1281
} ) ;
1262
-
1263
- // Authorities can be set as late as in the first block of new epoch, but it makes session last 1 block longer
1264
- set_committee_through_inherent_data ( & [ bob ( ) ] ) ;
1265
- assert_current_epoch ! ( 2 ) ;
1266
- assert_aura_authorities ! ( [ alice( ) ] ) ;
1267
- advance_block ( ) ;
1268
1282
set_committee_through_inherent_data ( & [ alice ( ) , bob ( ) ] ) ;
1269
- for_next_n_blocks ( SLOTS_PER_EPOCH - 1 , & || {
1270
- assert_current_epoch ! ( 2 ) ;
1283
+ for_next_n_blocks_after_finalizing ( SLOTS_PER_EPOCH , & || {
1284
+ assert_current_epoch ! ( 3 ) ;
1271
1285
assert_aura_authorities ! ( [ bob( ) ] ) ;
1272
1286
} ) ;
1273
-
1274
- set_committee_through_inherent_data ( & [ alice ( ) , bob ( ) ] ) ;
1275
- for_next_n_blocks ( SLOTS_PER_EPOCH * 3 , & || {
1287
+ set_committee_through_inherent_data ( & [ bob ( ) , alice ( ) ] ) ;
1288
+ for_next_n_blocks_after_finalizing ( SLOTS_PER_EPOCH , & || {
1289
+ assert_current_epoch ! ( 4 ) ;
1290
+ assert_aura_authorities ! ( [ alice( ) ] ) ;
1291
+ } ) ;
1292
+ set_committee_through_inherent_data ( & [ alice ( ) ] ) ;
1293
+ for_next_n_blocks_after_finalizing ( SLOTS_PER_EPOCH , & || {
1294
+ assert_current_epoch ! ( 5 ) ;
1276
1295
assert_aura_authorities ! ( [ alice( ) , bob( ) ] ) ;
1277
1296
} ) ;
1297
+
1298
+ // When there's no new committees being scheduled, the last committee stays in power
1299
+ for_next_n_blocks_after_finalizing ( SLOTS_PER_EPOCH * 3 , & || {
1300
+ assert_aura_authorities ! ( [ bob( ) , alice( ) ] ) ;
1301
+ } ) ;
1278
1302
} ) ;
1279
1303
}
1280
1304
0 commit comments