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 <>
This commit is contained in:
Kian Paimani
2021-03-20 13:13:14 +01:00
committed by GitHub
parent df3fef3fd9
commit 6435296cc5
9 changed files with 195 additions and 282 deletions
+24 -26
View File
@@ -96,7 +96,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
apis: RUNTIME_API_VERSIONS,
#[cfg(feature = "disable-runtime-api")]
apis: version::create_apis_vec![[]],
transaction_version: 4,
transaction_version: 5,
};
/// The BABE epoch configuration at genesis.
@@ -308,18 +308,14 @@ impl pallet_session::historical::Config for Runtime {
parameter_types! {
// no signed phase for now, just unsigned.
pub const SignedPhase: u32 = 0;
// NOTE: length of unsigned phase is, for now, different than `ElectionLookahead` to make sure
// that we won't run OCW threads at the same time with staking.
pub const UnsignedPhase: u32 = ElectionLookahead::get() / 2;
pub const UnsignedPhase: u32 = EPOCH_DURATION_IN_BLOCKS / 4;
// 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 =
pallet_election_provider_multi_phase::FallbackStrategy::Nothing;
pub SolutionImprovementThreshold: Perbill = Perbill::from_rational(1u32, 10_000);
pallet_election_provider_multi_phase::FallbackStrategy::OnChain;
pub SolutionImprovementThreshold: Perbill = Perbill::from_rational(5u32, 10_000);
// miner configs
pub MultiPhaseUnsignedPriority: TransactionPriority = StakingUnsignedPriority::get() - 1u64;
pub const MinerMaxIterations: u32 = 10;
}
@@ -328,10 +324,10 @@ impl pallet_election_provider_multi_phase::Config for Runtime {
type Currency = Balances;
type SignedPhase = SignedPhase;
type UnsignedPhase = UnsignedPhase;
type SolutionImprovementThreshold = MinSolutionScoreBump;
type SolutionImprovementThreshold = SolutionImprovementThreshold;
type MinerMaxIterations = MinerMaxIterations;
type MinerMaxWeight = OffchainSolutionWeightLimit; // For now use the one from staking.
type MinerTxPriority = MultiPhaseUnsignedPriority;
type MinerTxPriority = NposSolutionPriority;
type DataProvider = Staking;
type OnChainAccuracy = Perbill;
type CompactSolution = pallet_staking::CompactAssignments;
@@ -365,10 +361,6 @@ parameter_types! {
pub const SlashDeferDuration: pallet_staking::EraIndex = 27;
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
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<
@@ -394,14 +386,6 @@ impl pallet_staking::Config for Runtime {
type EraPayout = pallet_staking::ConvertCurve<RewardCurve>;
type MaxNominatorRewardedPerValidator = MaxNominatorRewardedPerValidator;
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 WeightInfo = weights::pallet_staking::WeightInfo<Runtime>;
}
@@ -633,7 +617,7 @@ parameter_types! {
}
parameter_types! {
pub StakingUnsignedPriority: TransactionPriority =
pub NposSolutionPriority: TransactionPriority =
Perbill::from_percent(90) * TransactionPriority::max_value();
pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value();
}
@@ -981,7 +965,7 @@ construct_runtime! {
// Consensus support.
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,
Historical: session_historical::{Pallet} = 34,
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>} = 8,
@@ -1084,11 +1068,24 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPallets,
BabeEpochConfigMigrations,
(BabeEpochConfigMigrations, KillOffchainPhragmenStorageTest),
>;
/// The payload being signed in the transactions.
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"))]
sp_api::impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
@@ -1336,6 +1333,7 @@ sp_api::impl_runtime_apis! {
#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade() -> Result<(Weight, Weight), sp_runtime::RuntimeString> {
log::info!("try-runtime::on_runtime_upgrade kusama.");
let weight = Executive::try_runtime_upgrade()?;
Ok((weight, BlockWeights::get().max_block))
}
@@ -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((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 {
(0 as Weight)
// Standard Error: 111_000