Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 23 additions & 25 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down Expand Up @@ -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<
Expand All @@ -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>;
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just for testing, as the name suggests.

Copy link
Copy Markdown
Member

@shawntabrizi shawntabrizi Mar 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this mean it will be removed before merge?

if not maybe some extra module file would make sense

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove it later, since I will probably want to test this one last time before enactment.

The migration is noop, rest assured it won't cause any issues.

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 {
Expand Down Expand Up @@ -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))
}
Expand Down
15 changes: 0 additions & 15 deletions runtime/kusama/src/weights/pallet_staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 9 additions & 24 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,18 +318,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;
}

Expand All @@ -338,10 +334,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;
Expand Down Expand Up @@ -374,10 +370,6 @@ parameter_types! {
pub const SlashDeferDuration: pallet_staking::EraIndex = 27;
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
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<
Expand All @@ -403,14 +395,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>;
}
Expand Down Expand Up @@ -679,7 +663,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();
}
Expand Down Expand Up @@ -987,7 +971,7 @@ construct_runtime! {

// Consensus support.
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,
Historical: session_historical::{Pallet} = 33,
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>} = 9,
Expand Down Expand Up @@ -1377,6 +1361,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 polkadot.");
let weight = Executive::try_runtime_upgrade()?;
Ok((weight, BlockWeights::get().max_block))
}
Expand Down
15 changes: 0 additions & 15 deletions runtime/polkadot/src/weights/pallet_staking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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: 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 {
(0 as Weight)
// Standard Error: 102_000
Expand Down
3 changes: 1 addition & 2 deletions runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ parameter_types! {
}

parameter_types! {
pub const StakingUnsignedPriority: TransactionPriority = TransactionPriority::max_value() / 2;
pub const ImOnlineUnsignedPriority: TransactionPriority = TransactionPriority::max_value();
}

Expand All @@ -338,7 +337,7 @@ impl pallet_im_online::Config for Runtime {
type ValidatorSet = Historical;
type NextSessionRotation = Babe;
type ReportUnresponsiveness = Offences;
type UnsignedPriority = StakingUnsignedPriority;
type UnsignedPriority = ImOnlineUnsignedPriority;
Comment thread
kianenigma marked this conversation as resolved.
type WeightInfo = ();
}

Expand Down
17 changes: 2 additions & 15 deletions runtime/test-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,7 @@ use runtime_common::{
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
ApplyExtrinsicResult, Perbill, KeyTypeId,
transaction_validity::{
TransactionValidity, TransactionSource, TransactionPriority,
},
transaction_validity::{TransactionValidity, TransactionSource},
curve::PiecewiseLinear,
traits::{
BlakeTwo256, Block as BlockT, StaticLookup, OpaqueKeys, ConvertInto,
Expand Down Expand Up @@ -306,10 +304,6 @@ parameter_types! {
pub storage SlashDeferDuration: pallet_staking::EraIndex = 27;
pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE;
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 {
Expand Down Expand Up @@ -337,15 +331,8 @@ 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 OffchainSolutionWeightLimit = ();
type MinSolutionScoreBump = MinSolutionScoreBump;
type ElectionProvider = frame_election_provider_support::onchain::OnChainSequentialPhragmen<Self>;
type WeightInfo = ();

}

impl pallet_grandpa::Config for Runtime {
Expand Down Expand Up @@ -515,7 +502,7 @@ construct_runtime! {

// Consensus support.
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},
Historical: session_historical::{Pallet},
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>},
Expand Down
Loading