Unverified Commit d75d4e13 authored by Kian Paimani's avatar Kian Paimani Committed by GitHub
Browse files

Companion for substrate/pull/8113 (Unleash multi phase) (#2432)

* Almost make it work.

* Make the runtimes build

* Some fixes

* Make the whole thing compile

* Apply suggestions from code review

* Fix review comments

* remove unused.

* nit

* Fix

* "Update Substrate"

* bump tx-version

Co-authored-by: parity-processbot <>
parent 18946e8c
Pipeline #129667 passed with stages
in 36 minutes and 27 seconds
This diff is collapsed.
...@@ -96,7 +96,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { ...@@ -96,7 +96,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: RUNTIME_API_VERSIONS, apis: RUNTIME_API_VERSIONS,
#[cfg(feature = "disable-runtime-api")] #[cfg(feature = "disable-runtime-api")]
apis: version::create_apis_vec![[]], apis: version::create_apis_vec![[]],
transaction_version: 4, transaction_version: 5,
}; };
/// The BABE epoch configuration at genesis. /// The BABE epoch configuration at genesis.
...@@ -308,18 +308,14 @@ impl pallet_session::historical::Config for Runtime { ...@@ -308,18 +308,14 @@ impl pallet_session::historical::Config for Runtime {
parameter_types! { parameter_types! {
// no signed phase for now, just unsigned. // no signed phase for now, just unsigned.
pub const SignedPhase: u32 = 0; pub const SignedPhase: u32 = 0;
// NOTE: length of unsigned phase is, for now, different than `ElectionLookahead` to make sure pub const UnsignedPhase: u32 = EPOCH_DURATION_IN_BLOCKS / 4;
// that we won't run OCW threads at the same time with staking.
pub const UnsignedPhase: u32 = ElectionLookahead::get() / 2;
// fallback: no need to do on-chain phragmen while we re on a dry-run. // fallback: run election on-chain.
pub const Fallback: pallet_election_provider_multi_phase::FallbackStrategy = pub const Fallback: pallet_election_provider_multi_phase::FallbackStrategy =
pallet_election_provider_multi_phase::FallbackStrategy::Nothing; pallet_election_provider_multi_phase::FallbackStrategy::OnChain;
pub SolutionImprovementThreshold: Perbill = Perbill::from_rational(5u32, 10_000);
pub SolutionImprovementThreshold: Perbill = Perbill::from_rational(1u32, 10_000);
// miner configs // miner configs
pub MultiPhaseUnsignedPriority: TransactionPriority = StakingUnsignedPriority::get() - 1u64;
pub const MinerMaxIterations: u32 = 10; pub const MinerMaxIterations: u32 = 10;
} }
...@@ -328,10 +324,10 @@ impl pallet_election_provider_multi_phase::Config for Runtime { ...@@ -328,10 +324,10 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
type Currency = Balances; type Currency = Balances;
type SignedPhase = SignedPhase; type SignedPhase = SignedPhase;
type UnsignedPhase = UnsignedPhase; type UnsignedPhase = UnsignedPhase;
type SolutionImprovementThreshold = MinSolutionScoreBump; type SolutionImprovementThreshold = SolutionImprovementThreshold;
type MinerMaxIterations = MinerMaxIterations; type MinerMaxIterations = MinerMaxIterations;
type MinerMaxWeight = OffchainSolutionWeightLimit; // For now use the one from staking. type MinerMaxWeight = OffchainSolutionWeightLimit; // For now use the one from staking.
type MinerTxPriority = MultiPhaseUnsignedPriority; type MinerTxPriority = NposSolutionPriority;
type DataProvider = Staking; type DataProvider = Staking;
type OnChainAccuracy = Perbill; type OnChainAccuracy = Perbill;
type CompactSolution = pallet_staking::CompactAssignments; type CompactSolution = pallet_staking::CompactAssignments;
...@@ -365,10 +361,6 @@ parameter_types! { ...@@ -365,10 +361,6 @@ parameter_types! {
pub const SlashDeferDuration: pallet_staking::EraIndex = 27; pub const SlashDeferDuration: pallet_staking::EraIndex = 27;
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE; pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const MaxNominatorRewardedPerValidator: u32 = 128; pub const MaxNominatorRewardedPerValidator: u32 = 128;
// quarter of the last session will be for election.
pub const ElectionLookahead: BlockNumber = EPOCH_DURATION_IN_BLOCKS / 4;
pub const MaxIterations: u32 = 10;
pub MinSolutionScoreBump: Perbill = Perbill::from_rational(5u32, 10_000);
} }
type SlashCancelOrigin = EnsureOneOf< type SlashCancelOrigin = EnsureOneOf<
...@@ -394,14 +386,6 @@ impl pallet_staking::Config for Runtime { ...@@ -394,14 +386,6 @@ impl pallet_staking::Config for Runtime {
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>; type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator; type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type NextNewSession = Session; type NextNewSession = Session;
type ElectionLookahead = ElectionLookahead;
type Call = Call;
type UnsignedPriority = StakingUnsignedPriority;
type MaxIterations = MaxIterations;
type MinSolutionScoreBump = MinSolutionScoreBump;
// The unsigned solution weight targeted by the OCW. We set it to the maximum possible value of
// a single extrinsic.
type OffchainSolutionWeightLimit = OffchainSolutionWeightLimit;
type ElectionProvider = ElectionProviderMultiPhase; type ElectionProvider = ElectionProviderMultiPhase;
type WeightInfo = weights::pallet_staking::WeightInfo<Runtime>; type WeightInfo = weights::pallet_staking::WeightInfo<Runtime>;
} }
...@@ -633,7 +617,7 @@ parameter_types! { ...@@ -633,7 +617,7 @@ parameter_types! {
} }
parameter_types! { parameter_types! {
pub StakingUnsignedPriority: TransactionPriority = pub NposSolutionPriority: TransactionPriority =
Perbill::from_percent(90) * TransactionPriority::max_value(); Perbill::from_percent(90) * TransactionPriority::max_value();
pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value(); pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value();
} }
...@@ -981,7 +965,7 @@ construct_runtime! { ...@@ -981,7 +965,7 @@ construct_runtime! {
// Consensus support. // Consensus support.
Authorship: pallet_authorship::{Pallet, Call, Storage} = 5, Authorship: pallet_authorship::{Pallet, Call, Storage} = 5,
Staking: pallet_staking::{Pallet, Call, Storage, Config<T>, Event<T>, ValidateUnsigned} = 6, Staking: pallet_staking::{Pallet, Call, Storage, Config<T>, Event<T>} = 6,
Offences: pallet_offences::{Pallet, Call, Storage, Event} = 7, Offences: pallet_offences::{Pallet, Call, Storage, Event} = 7,
Historical: session_historical::{Pallet} = 34, Historical: session_historical::{Pallet} = 34,
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>} = 8, Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>} = 8,
...@@ -1084,11 +1068,24 @@ pub type Executive = frame_executive::Executive< ...@@ -1084,11 +1068,24 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>, frame_system::ChainContext<Runtime>,
Runtime, Runtime,
AllPallets, AllPallets,
BabeEpochConfigMigrations, (BabeEpochConfigMigrations, KillOffchainPhragmenStorageTest),
>; >;
/// The payload being signed in the transactions. /// The payload being signed in the transactions.
pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>; pub type SignedPayload = generic::SignedPayload<Call, SignedExtra>;
/// This is only for testing. The main migration is inside staking's `on_runtime_upgrade`.
pub struct KillOffchainPhragmenStorageTest;
impl frame_support::traits::OnRuntimeUpgrade for KillOffchainPhragmenStorageTest {
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
pallet_staking::migrations::v6::pre_migrate::<Runtime>()
}
fn on_runtime_upgrade() -> frame_support::weights::Weight {
0
}
}
#[cfg(not(feature = "disable-runtime-api"))] #[cfg(not(feature = "disable-runtime-api"))]
sp_api::impl_runtime_apis! { sp_api::impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime { impl sp_api::Core<Block> for Runtime {
...@@ -1336,6 +1333,7 @@ sp_api::impl_runtime_apis! { ...@@ -1336,6 +1333,7 @@ sp_api::impl_runtime_apis! {
#[cfg(feature = "try-runtime")] #[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime { impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade() -> Result<(Weight, Weight), sp_runtime::RuntimeString> { fn on_runtime_upgrade() -> Result<(Weight, Weight), sp_runtime::RuntimeString> {
log::info!("try-runtime::on_runtime_upgrade kusama.");
let weight = Executive::try_runtime_upgrade()?; let weight = Executive::try_runtime_upgrade()?;
Ok((weight, BlockWeights::get().max_block)) Ok((weight, BlockWeights::get().max_block))
} }
......
...@@ -199,21 +199,6 @@ impl<T: frame_system::Config> pallet_staking::WeightInfo for WeightInfo<T> { ...@@ -199,21 +199,6 @@ impl<T: frame_system::Config> pallet_staking::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().writes(13 as Weight)) .saturating_add(T::DbWeight::get().writes(13 as Weight))
.saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(v as Weight))) .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(v as Weight)))
} }
fn submit_solution_better(v: u32, n: u32, a: u32, w: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 53_000
.saturating_add((1_082_000 as Weight).saturating_mul(v as Weight))
// Standard Error: 21_000
.saturating_add((408_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 53_000
.saturating_add((72_582_000 as Weight).saturating_mul(a as Weight))
// Standard Error: 110_000
.saturating_add((7_046_000 as Weight).saturating_mul(w as Weight))
.saturating_add(T::DbWeight::get().reads(6 as Weight))
.saturating_add(T::DbWeight::get().reads((4 as Weight).saturating_mul(a as Weight)))
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(w as Weight)))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
fn get_npos_voters(v: u32, n: u32, s: u32, ) -> Weight { fn get_npos_voters(v: u32, n: u32, s: u32, ) -> Weight {
(0 as Weight) (0 as Weight)
// Standard Error: 111_000 // Standard Error: 111_000
......
...@@ -98,7 +98,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { ...@@ -98,7 +98,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: RUNTIME_API_VERSIONS, apis: RUNTIME_API_VERSIONS,
#[cfg(feature = "disable-runtime-api")] #[cfg(feature = "disable-runtime-api")]
apis: version::create_apis_vec![[]], apis: version::create_apis_vec![[]],
transaction_version: 6, transaction_version: 7,
}; };
/// The BABE epoch configuration at genesis. /// The BABE epoch configuration at genesis.
...@@ -318,18 +318,14 @@ impl pallet_session::historical::Config for Runtime { ...@@ -318,18 +318,14 @@ impl pallet_session::historical::Config for Runtime {
parameter_types! { parameter_types! {
// no signed phase for now, just unsigned. // no signed phase for now, just unsigned.
pub const SignedPhase: u32 = 0; pub const SignedPhase: u32 = 0;
// NOTE: length of unsigned phase is, for now, different than `ElectionLookahead` to make sure pub const UnsignedPhase: u32 = EPOCH_DURATION_IN_BLOCKS / 4;
// that we won't run OCW threads at the same time with staking.
pub const UnsignedPhase: u32 = ElectionLookahead::get() / 2;
// fallback: no need to do on-chain phragmen while we re on a dry-run. // fallback: run election on-chain.
pub const Fallback: pallet_election_provider_multi_phase::FallbackStrategy = pub const Fallback: pallet_election_provider_multi_phase::FallbackStrategy =
pallet_election_provider_multi_phase::FallbackStrategy::Nothing; pallet_election_provider_multi_phase::FallbackStrategy::OnChain;
pub SolutionImprovementThreshold: Perbill = Perbill::from_rational(5u32, 10_000);
pub SolutionImprovementThreshold: Perbill = Perbill::from_rational(1u32, 10_000);
// miner configs // miner configs
pub MultiPhaseUnsignedPriority: TransactionPriority = StakingUnsignedPriority::get() - 1u64;
pub const MinerMaxIterations: u32 = 10; pub const MinerMaxIterations: u32 = 10;
} }
...@@ -338,10 +334,10 @@ impl pallet_election_provider_multi_phase::Config for Runtime { ...@@ -338,10 +334,10 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
type Currency = Balances; type Currency = Balances;
type SignedPhase = SignedPhase; type SignedPhase = SignedPhase;
type UnsignedPhase = UnsignedPhase; type UnsignedPhase = UnsignedPhase;
type SolutionImprovementThreshold = MinSolutionScoreBump; type SolutionImprovementThreshold = SolutionImprovementThreshold;
type MinerMaxIterations = MinerMaxIterations; type MinerMaxIterations = MinerMaxIterations;
type MinerMaxWeight = OffchainSolutionWeightLimit; // For now use the one from staking. type MinerMaxWeight = OffchainSolutionWeightLimit; // For now use the one from staking.
type MinerTxPriority = MultiPhaseUnsignedPriority; type MinerTxPriority = NposSolutionPriority;
type DataProvider = Staking; type DataProvider = Staking;
type OnChainAccuracy = Perbill; type OnChainAccuracy = Perbill;
type CompactSolution = pallet_staking::CompactAssignments; type CompactSolution = pallet_staking::CompactAssignments;
...@@ -374,10 +370,6 @@ parameter_types! { ...@@ -374,10 +370,6 @@ parameter_types! {
pub const SlashDeferDuration: pallet_staking::EraIndex = 27; pub const SlashDeferDuration: pallet_staking::EraIndex = 27;
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE; pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const MaxNominatorRewardedPerValidator: u32 = 128; pub const MaxNominatorRewardedPerValidator: u32 = 128;
// last 15 minutes of the last session will be for election.
pub const ElectionLookahead: BlockNumber = EPOCH_DURATION_IN_BLOCKS / 16;
pub const MaxIterations: u32 = 10;
pub MinSolutionScoreBump: Perbill = Perbill::from_rational(5u32, 10_000);
} }
type SlashCancelOrigin = EnsureOneOf< type SlashCancelOrigin = EnsureOneOf<
...@@ -403,14 +395,6 @@ impl pallet_staking::Config for Runtime { ...@@ -403,14 +395,6 @@ impl pallet_staking::Config for Runtime {
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>; type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator; type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type NextNewSession = Session; type NextNewSession = Session;
type ElectionLookahead = ElectionLookahead;
type Call = Call;
type UnsignedPriority = StakingUnsignedPriority;
type MaxIterations = MaxIterations;
type MinSolutionScoreBump = MinSolutionScoreBump;
// The unsigned solution weight targeted by the OCW. We set it to the maximum possible value of
// a single extrinsic.
type OffchainSolutionWeightLimit = OffchainSolutionWeightLimit;
type ElectionProvider = ElectionProviderMultiPhase; type ElectionProvider = ElectionProviderMultiPhase;
type WeightInfo = weights::pallet_staking::WeightInfo<Runtime>; type WeightInfo = weights::pallet_staking::WeightInfo<Runtime>;
} }
...@@ -679,7 +663,7 @@ parameter_types! { ...@@ -679,7 +663,7 @@ parameter_types! {
} }
parameter_types! { parameter_types! {
pub StakingUnsignedPriority: TransactionPriority = pub NposSolutionPriority: TransactionPriority =
Perbill::from_percent(90) * TransactionPriority::max_value(); Perbill::from_percent(90) * TransactionPriority::max_value();
pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value(); pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value();
} }
...@@ -987,7 +971,7 @@ construct_runtime! { ...@@ -987,7 +971,7 @@ construct_runtime! {
// Consensus support. // Consensus support.
Authorship: pallet_authorship::{Pallet, Call, Storage} = 6, Authorship: pallet_authorship::{Pallet, Call, Storage} = 6,
Staking: pallet_staking::{Pallet, Call, Storage, Config<T>, Event<T>, ValidateUnsigned} = 7, Staking: pallet_staking::{Pallet, Call, Storage, Config<T>, Event<T>} = 7,
Offences: pallet_offences::{Pallet, Call, Storage, Event} = 8, Offences: pallet_offences::{Pallet, Call, Storage, Event} = 8,
Historical: session_historical::{Pallet} = 33, Historical: session_historical::{Pallet} = 33,
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>} = 9, Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>} = 9,
...@@ -1377,6 +1361,7 @@ sp_api::impl_runtime_apis! { ...@@ -1377,6 +1361,7 @@ sp_api::impl_runtime_apis! {
#[cfg(feature = "try-runtime")] #[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime { impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade() -> Result<(Weight, Weight), sp_runtime::RuntimeString> { fn on_runtime_upgrade() -> Result<(Weight, Weight), sp_runtime::RuntimeString> {
log::info!("try-runtime::on_runtime_upgrade polkadot.");
let weight = Executive::try_runtime_upgrade()?; let weight = Executive::try_runtime_upgrade()?;
Ok((weight, BlockWeights::get().max_block)) Ok((weight, BlockWeights::get().max_block))
} }
......
...@@ -199,21 +199,6 @@ impl<T: frame_system::Config> pallet_staking::WeightInfo for WeightInfo<T> { ...@@ -199,21 +199,6 @@ impl<T: frame_system::Config> pallet_staking::WeightInfo for WeightInfo<T> {
.saturating_add(T::DbWeight::get().writes(13 as Weight)) .saturating_add(T::DbWeight::get().writes(13 as Weight))
.saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(v as Weight))) .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(v as Weight)))
} }
fn submit_solution_better(v: u32, n: u32, a: u32, w: u32, ) -> Weight {
(0 as Weight)
// Standard Error: 46_000
.saturating_add((1_236_000 as Weight).saturating_mul(v as Weight))
// Standard Error: 18_000
.saturating_add((549_000 as Weight).saturating_mul(n as Weight))
// Standard Error: 46_000
.saturating_add((75_697_000 as Weight).saturating_mul(a as Weight))
// Standard Error: 96_000
.saturating_add((6_459_000 as Weight).saturating_mul(w as Weight))
.saturating_add(T::DbWeight::get().reads(6 as Weight))
.saturating_add(T::DbWeight::get().reads((4 as Weight).saturating_mul(a as Weight)))
.saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(w as Weight)))
.saturating_add(T::DbWeight::get().writes(2 as Weight))
}
fn get_npos_voters(v: u32, n: u32, s: u32, ) -> Weight { fn get_npos_voters(v: u32, n: u32, s: u32, ) -> Weight {
(0 as Weight) (0 as Weight)
// Standard Error: 102_000 // Standard Error: 102_000
......
...@@ -328,7 +328,6 @@ parameter_types! { ...@@ -328,7 +328,6 @@ parameter_types! {
} }
parameter_types! { parameter_types! {
pub const StakingUnsignedPriority: TransactionPriority = TransactionPriority::max_value() / 2;
pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value(); pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value();
} }
...@@ -338,7 +337,7 @@ impl pallet_im_online::Config for Runtime { ...@@ -338,7 +337,7 @@ impl pallet_im_online::Config for Runtime {
type ValidatorSet = Historical; type ValidatorSet = Historical;
type NextSessionRotation = Babe; type NextSessionRotation = Babe;
type ReportUnresponsiveness = Offences; type ReportUnresponsiveness = Offences;
type UnsignedPriority = StakingUnsignedPriority; type UnsignedPriority = ImOnlineUnsignedPriority;
type WeightInfo = (); type WeightInfo = ();
} }
......
...@@ -51,9 +51,7 @@ use runtime_common::{ ...@@ -51,9 +51,7 @@ use runtime_common::{
use sp_runtime::{ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys, create_runtime_str, generic, impl_opaque_keys,
ApplyExtrinsicResult, Perbill, KeyTypeId, ApplyExtrinsicResult, Perbill, KeyTypeId,
transaction_validity::{ transaction_validity::{TransactionValidity, TransactionSource},
TransactionValidity, TransactionSource, TransactionPriority,
},
curve::PiecewiseLinear, curve::PiecewiseLinear,
traits::{ traits::{
BlakeTwo256, Block as BlockT, StaticLookup, OpaqueKeys, ConvertInto, BlakeTwo256, Block as BlockT, StaticLookup, OpaqueKeys, ConvertInto,
...@@ -306,10 +304,6 @@ parameter_types! { ...@@ -306,10 +304,6 @@ parameter_types! {
pub storage SlashDeferDuration: pallet_staking::EraIndex = 27; pub storage SlashDeferDuration: pallet_staking::EraIndex = 27;
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE; pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub storage MaxNominatorRewardedPerValidator: u32 = 64; pub storage MaxNominatorRewardedPerValidator: u32 = 64;
pub storage ElectionLookahead: BlockNumber = 0;
pub storage StakingUnsignedPriority: TransactionPriority = TransactionPriority::max_value() / 2;
pub storage MaxIterations: u32 = 10;
pub MinSolutionScoreBump: Perbill = Perbill::from_rational(5u32, 10_000);
} }
impl frame_election_provider_support::onchain::Config for Runtime { impl frame_election_provider_support::onchain::Config for Runtime {
...@@ -337,15 +331,8 @@ impl pallet_staking::Config for Runtime { ...@@ -337,15 +331,8 @@ impl pallet_staking::Config for Runtime {
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>; type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator; type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type NextNewSession = Session; type NextNewSession = Session;
type ElectionLookahead = ElectionLookahead;
type Call = Call;
type UnsignedPriority = StakingUnsignedPriority;
type MaxIterations = MaxIterations;
type OffchainSolutionWeightLimit = ();
type MinSolutionScoreBump = MinSolutionScoreBump;
type ElectionProvider = frame_election_provider_support::onchain::OnChainSequentialPhragmen<Self>; type ElectionProvider = frame_election_provider_support::onchain::OnChainSequentialPhragmen<Self>;
type WeightInfo = (); type WeightInfo = ();
} }
impl pallet_grandpa::Config for Runtime { impl pallet_grandpa::Config for Runtime {
...@@ -515,7 +502,7 @@ construct_runtime! { ...@@ -515,7 +502,7 @@ construct_runtime! {
// Consensus support. // Consensus support.
Authorship: pallet_authorship::{Pallet, Call, Storage}, Authorship: pallet_authorship::{Pallet, Call, Storage},
Staking: pallet_staking::{Pallet, Call, Storage, Config<T>, Event<T>, ValidateUnsigned}, Staking: pallet_staking::{Pallet, Call, Storage, Config<T>, Event<T>},
Offences: pallet_offences::{Pallet, Call, Storage, Event}, Offences: pallet_offences::{Pallet, Call, Storage, Event},
Historical: session_historical::{Pallet}, Historical: session_historical::{Pallet},
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>}, Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>},
......
...@@ -106,7 +106,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { ...@@ -106,7 +106,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: RUNTIME_API_VERSIONS, apis: RUNTIME_API_VERSIONS,
#[cfg(feature = "disable-runtime-api")] #[cfg(feature = "disable-runtime-api")]
apis: version::create_apis_vec![[]], apis: version::create_apis_vec![[]],
transaction_version: 4, transaction_version: 5,
}; };
/// The BABE epoch configuration at genesis. /// The BABE epoch configuration at genesis.
...@@ -312,18 +312,15 @@ impl pallet_session::historical::Config for Runtime { ...@@ -312,18 +312,15 @@ impl pallet_session::historical::Config for Runtime {
parameter_types! { parameter_types! {
// no signed phase for now, just unsigned. // no signed phase for now, just unsigned.
pub const SignedPhase: u32 = 0; pub const SignedPhase: u32 = 0;
// NOTE: length of unsigned phase is, for now, different than `ElectionLookahead` to make sure pub const UnsignedPhase: u32 = EPOCH_DURATION_IN_BLOCKS / 4;
// that we won't run OCW threads at the same time with staking.
pub const UnsignedPhase: u32 = ElectionLookahead::get() / 2;
// fallback: no need to do on-chain phragmen while we re on a dry-run. // fallback: run election on-chain.
pub const Fallback: pallet_election_provider_multi_phase::FallbackStrategy = pub const Fallback: pallet_election_provider_multi_phase::FallbackStrategy =
pallet_election_provider_multi_phase::FallbackStrategy::Nothing; pallet_election_provider_multi_phase::FallbackStrategy::OnChain;
pub SolutionImprovementThreshold: Perbill = Perbill::from_rational(1u32, 10_000); pub SolutionImprovementThreshold: Perbill = Perbill::from_rational(5u32, 10_000);
// miner configs // miner configs
pub const MultiPhaseUnsignedPriority: TransactionPriority = StakingUnsignedPriority::get() - 1u64;
pub const MinerMaxIterations: u32 = 10; pub const MinerMaxIterations: u32 = 10;
} }
...@@ -332,10 +329,10 @@ impl pallet_election_provider_multi_phase::Config for Runtime { ...@@ -332,10 +329,10 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
type Currency = Balances; type Currency = Balances;
type SignedPhase = SignedPhase; type SignedPhase = SignedPhase;
type UnsignedPhase = UnsignedPhase; type UnsignedPhase = UnsignedPhase;
type SolutionImprovementThreshold = MinSolutionScoreBump; type SolutionImprovementThreshold = SolutionImprovementThreshold;
type MinerMaxIterations = MinerMaxIterations; type MinerMaxIterations = MinerMaxIterations;
type MinerMaxWeight = OffchainSolutionWeightLimit; // For now use the one from staking. type MinerMaxWeight = OffchainSolutionWeightLimit; // For now use the one from staking.
type MinerTxPriority = MultiPhaseUnsignedPriority; type MinerTxPriority = NposSolutionPriority;
type DataProvider = Staking; type DataProvider = Staking;
type OnChainAccuracy = Perbill; type OnChainAccuracy = Perbill;
type CompactSolution = pallet_staking::CompactAssignments; type CompactSolution = pallet_staking::CompactAssignments;
...@@ -364,10 +361,6 @@ parameter_types! { ...@@ -364,10 +361,6 @@ parameter_types! {
pub const SlashDeferDuration: pallet_staking::EraIndex = 27; pub const SlashDeferDuration: pallet_staking::EraIndex = 27;
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE; pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
pub const MaxNominatorRewardedPerValidator: u32 = 64; pub const MaxNominatorRewardedPerValidator: u32 = 64;
// quarter of the last session will be for election.
pub const ElectionLookahead: BlockNumber = EPOCH_DURATION_IN_BLOCKS / 4;
pub const MaxIterations: u32 = 10;
pub MinSolutionScoreBump: Perbill = Perbill::from_rational(5u32, 10_000);
} }
impl pallet_staking::Config for Runtime { impl pallet_staking::Config for Runtime {
...@@ -387,12 +380,6 @@ impl pallet_staking::Config for Runtime { ...@@ -387,12 +380,6 @@ impl pallet_staking::Config for Runtime {
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>; type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator; type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
type NextNewSession = Session; type NextNewSession = Session;
type ElectionLookahead = ElectionLookahead;
type Call = Call;
type UnsignedPriority = StakingUnsignedPriority;
type MaxIterations = MaxIterations;
type MinSolutionScoreBump = MinSolutionScoreBump;
type OffchainSolutionWeightLimit = OffchainSolutionWeightLimit;
type ElectionProvider = ElectionProviderMultiPhase; type ElectionProvider = ElectionProviderMultiPhase;
type WeightInfo = weights::pallet_staking::WeightInfo<Runtime>; type WeightInfo = weights::pallet_staking::WeightInfo<Runtime>;
} }
...@@ -427,7 +414,7 @@ parameter_types! { ...@@ -427,7 +414,7 @@ parameter_types! {
} }
parameter_types! { parameter_types! {
pub const StakingUnsignedPriority: TransactionPriority = TransactionPriority::max_value() / 2; pub const NposSolutionPriority: TransactionPriority = TransactionPriority::max_value() / 2;
pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value(); pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value();
} }
...@@ -437,7 +424,7 @@ impl pallet_im_online::Config for Runtime { ...@@ -437,7 +424,7 @@ impl pallet_im_online::Config for Runtime {
type ValidatorSet = Historical; type ValidatorSet = Historical;
type NextSessionRotation = Babe; type NextSessionRotation = Babe;
type ReportUnresponsiveness = Offences; type ReportUnresponsiveness = Offences;
type UnsignedPriority = StakingUnsignedPriority; type UnsignedPriority = ImOnlineUnsignedPriority;
type WeightInfo = weights::pallet_im_online::WeightInfo<Runtime>; type WeightInfo = weights::pallet_im_online::WeightInfo<Runtime>;
} }
...@@ -837,7 +824,7 @@ construct_runtime! { ...@@ -837,7 +824,7 @@ construct_runtime! {
// Consensus support. // Consensus support.
Authorship: pallet_authorship::{Pallet, Call, Storage} = 5, Authorship: pallet_authorship::{Pallet, Call, Storage} = 5,
Staking: pallet_staking::{Pallet, Call, Storage, Config<T>, Event<T>, ValidateUnsigned} = 6, Staking: pallet_staking::{Pallet, Call, Storage, Config<T>, Event<T>} = 6,
Offences: pallet_offences::{Pallet, Call, Storage, Event} = 7, Offences: pallet_offences::{Pallet, Call, Storage, Event} = 7,
Historical: session_historical::{Pallet} = 27, Historical: session_historical::{Pallet} = 27,
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>} = 8, Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>} = 8,
...@@ -940,7 +927,7 @@ pub type Executive = frame_executive::Executive< ...@@ -940,7 +927,7 @@ pub type Executive = frame_executive::Executive<<