@@ -28,7 +28,8 @@ use frame_support::{
2828 construct_runtime, parameter_types, debug, RuntimeDebug ,
2929 weights:: {
3030 Weight , IdentityFee ,
31- constants:: { BlockExecutionWeight , ExtrinsicBaseWeight , RocksDbWeight , WEIGHT_PER_SECOND } , DispatchClass ,
31+ constants:: { BlockExecutionWeight , ExtrinsicBaseWeight , RocksDbWeight , WEIGHT_PER_SECOND } ,
32+ DispatchClass ,
3233 } ,
3334 traits:: {
3435 Currency , Imbalance , KeyOwnerProofSystem , OnUnbalanced , Randomness , LockIdentifier ,
@@ -50,14 +51,14 @@ pub use node_primitives::{AccountId, Signature};
5051use node_primitives:: { AccountIndex , Balance , BlockNumber , Hash , Index , Moment } ;
5152use sp_api:: impl_runtime_apis;
5253use sp_runtime:: {
53- Permill , Perbill , Perquintill , Percent , ApplyExtrinsicResult ,
54- impl_opaque_keys , generic , create_runtime_str, ModuleId , FixedPointNumber ,
54+ Permill , Perbill , Perquintill , Percent , ApplyExtrinsicResult , impl_opaque_keys , generic ,
55+ create_runtime_str, ModuleId , FixedPointNumber ,
5556} ;
5657use sp_runtime:: curve:: PiecewiseLinear ;
5758use sp_runtime:: transaction_validity:: { TransactionValidity , TransactionSource , TransactionPriority } ;
5859use sp_runtime:: traits:: {
59- self , BlakeTwo256 , Block as BlockT , StaticLookup , SaturatedConversion ,
60- ConvertInto , OpaqueKeys , NumberFor ,
60+ self , BlakeTwo256 , Block as BlockT , StaticLookup , SaturatedConversion , ConvertInto , OpaqueKeys ,
61+ NumberFor ,
6162} ;
6263use sp_version:: RuntimeVersion ;
6364#[ cfg( any( feature = "std" , test) ) ]
@@ -145,7 +146,7 @@ impl OnUnbalanced<NegativeImbalance> for DealWithFees {
145146 }
146147}
147148
148- /// We assume that ~10% of the block weight is consumed by `on_initalize ` handlers.
149+ /// We assume that ~10% of the block weight is consumed by `on_initialize ` handlers.
149150/// This is used to limit the maximal weight of a single extrinsic.
150151const AVERAGE_ON_INITIALIZE_RATIO : Perbill = Perbill :: from_percent ( 10 ) ;
151152/// We allow `Normal` extrinsics to fill up the block up to 75%, the rest can be used
@@ -490,18 +491,56 @@ impl pallet_staking::Config for Runtime {
490491 type SessionInterface = Self ;
491492 type RewardCurve = RewardCurve ;
492493 type NextNewSession = Session ;
494+ type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator ;
493495 type ElectionLookahead = ElectionLookahead ;
494496 type Call = Call ;
495497 type MaxIterations = MaxIterations ;
496498 type MinSolutionScoreBump = MinSolutionScoreBump ;
497- type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator ;
498499 type UnsignedPriority = StakingUnsignedPriority ;
499500 // The unsigned solution weight targeted by the OCW. We set it to the maximum possible value of
500501 // a single extrinsic.
501502 type OffchainSolutionWeightLimit = OffchainSolutionWeightLimit ;
503+ type ElectionProvider = ElectionProviderMultiPhase ;
502504 type WeightInfo = pallet_staking:: weights:: SubstrateWeight < Runtime > ;
503505}
504506
507+ parameter_types ! {
508+ // phase durations. 1/4 of the last session for each.
509+ pub const SignedPhase : u32 = EPOCH_DURATION_IN_BLOCKS / 4 ;
510+ pub const UnsignedPhase : u32 = EPOCH_DURATION_IN_BLOCKS / 4 ;
511+
512+ // fallback: no need to do on-chain phragmen initially.
513+ pub const Fallback : pallet_election_provider_multi_phase:: FallbackStrategy =
514+ pallet_election_provider_multi_phase:: FallbackStrategy :: Nothing ;
515+
516+ pub SolutionImprovementThreshold : Perbill = Perbill :: from_rational_approximation( 1u32 , 10_000 ) ;
517+
518+ // miner configs
519+ pub const MultiPhaseUnsignedPriority : TransactionPriority = StakingUnsignedPriority :: get( ) - 1u64 ;
520+ pub const MinerMaxIterations : u32 = 10 ;
521+ pub MinerMaxWeight : Weight = RuntimeBlockWeights :: get( )
522+ . get( DispatchClass :: Normal )
523+ . max_extrinsic. expect( "Normal extrinsics have a weight limit configured; qed" )
524+ . saturating_sub( BlockExecutionWeight :: get( ) ) ;
525+ }
526+
527+ impl pallet_election_provider_multi_phase:: Config for Runtime {
528+ type Event = Event ;
529+ type Currency = Balances ;
530+ type SignedPhase = SignedPhase ;
531+ type UnsignedPhase = UnsignedPhase ;
532+ type SolutionImprovementThreshold = MinSolutionScoreBump ;
533+ type MinerMaxIterations = MinerMaxIterations ;
534+ type MinerMaxWeight = MinerMaxWeight ;
535+ type MinerTxPriority = MultiPhaseUnsignedPriority ;
536+ type DataProvider = Staking ;
537+ type OnChainAccuracy = Perbill ;
538+ type CompactSolution = pallet_staking:: CompactAssignments ;
539+ type Fallback = Fallback ;
540+ type WeightInfo = pallet_election_provider_multi_phase:: weights:: SubstrateWeight < Runtime > ;
541+ type BenchmarkingConfig = ( ) ;
542+ }
543+
505544parameter_types ! {
506545 pub const LaunchPeriod : BlockNumber = 28 * 24 * 60 * MINUTES ;
507546 pub const VotingPeriod : BlockNumber = 28 * 24 * 60 * MINUTES ;
@@ -548,7 +587,7 @@ impl pallet_democracy::Config for Runtime {
548587 > ;
549588 type BlacklistOrigin = EnsureRoot < AccountId > ;
550589 // Any single technical committee member may veto a coming council proposal, however they can
551- // only do it once and it lasts only for the cooloff period.
590+ // only do it once and it lasts only for the cool-off period.
552591 type VetoOrigin = pallet_collective:: EnsureMember < AccountId , TechnicalCollective > ;
553592 type CooloffPeriod = CooloffPeriod ;
554593 type PreimageByteDeposit = PreimageByteDeposit ;
@@ -1020,6 +1059,7 @@ construct_runtime!(
10201059 Indices : pallet_indices:: { Module , Call , Storage , Config <T >, Event <T >} ,
10211060 Balances : pallet_balances:: { Module , Call , Storage , Config <T >, Event <T >} ,
10221061 TransactionPayment : pallet_transaction_payment:: { Module , Storage } ,
1062+ ElectionProviderMultiPhase : pallet_election_provider_multi_phase:: { Module , Call , Storage , Event <T >, ValidateUnsigned } ,
10231063 Staking : pallet_staking:: { Module , Call , Config <T >, Storage , Event <T >, ValidateUnsigned } ,
10241064 Session : pallet_session:: { Module , Call , Storage , Event , Config <T >} ,
10251065 Democracy : pallet_democracy:: { Module , Call , Storage , Config , Event <T >} ,
@@ -1386,6 +1426,7 @@ impl_runtime_apis! {
13861426 add_benchmark!( params, batches, pallet_contracts, Contracts ) ;
13871427 add_benchmark!( params, batches, pallet_democracy, Democracy ) ;
13881428 add_benchmark!( params, batches, pallet_elections_phragmen, Elections ) ;
1429+ add_benchmark!( params, batches, pallet_election_provider_multi_phase, ElectionProviderMultiPhase ) ;
13891430 add_benchmark!( params, batches, pallet_grandpa, Grandpa ) ;
13901431 add_benchmark!( params, batches, pallet_identity, Identity ) ;
13911432 add_benchmark!( params, batches, pallet_im_online, ImOnline ) ;
0 commit comments