Add fast-runtime Cargo Feature for Quick Test Runs (#4332)

* add fast-runtime feature for reduced session times

* make democracy periods fast on fast-runtime

* propagate fast-runtime feature through cargo.toml files

* add fast motion and term durations to Kusama

* Update runtime/westend/Cargo.toml

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* set session time to 2 minutes to avoid block production issues

* formatting

* update Substrate

* set democracy fast periods back to 1min

* set launch period and enactment period to 1 block in fast-runtime

* remove unnecessary westend period configs

* add prod_or_test macro to allow specifying prod, test and env values for parameter types

* move prod_or_test macro into common module and use it consistently

* rename macro to prod_or_fast

* cargo +nightly fmt

* bump impl_versions

* newline

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* add note that env variable is evaluated at compile time

* newline

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* newline

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* cargo fmt

* impl_version: 0

* impl_version: 0

* use prod_or_fast macro for LeasePeriod and LeaseOffset

* use prod_or_fast macro in WND and ROC constants

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: Giles Cope <gilescope@gmail.com>
This commit is contained in:
Alexander Popiak
2022-01-13 21:08:24 +01:00
committed by GitHub
parent 21419a81d0
commit 401540eefc
13 changed files with 116 additions and 40 deletions
+1 -1
View File
@@ -139,9 +139,9 @@ overflow-checks = true
[features] [features]
runtime-benchmarks= [ "polkadot-cli/runtime-benchmarks" ] runtime-benchmarks= [ "polkadot-cli/runtime-benchmarks" ]
try-runtime = [ "polkadot-cli/try-runtime" ] try-runtime = [ "polkadot-cli/try-runtime" ]
fast-runtime = [ "polkadot-cli/fast-runtime" ]
runtime-metrics = [ "polkadot-cli/runtime-metrics" ] runtime-metrics = [ "polkadot-cli/runtime-metrics" ]
# Configuration for building a .deb package - for use with `cargo-deb` # Configuration for building a .deb package - for use with `cargo-deb`
[package.metadata.deb] [package.metadata.deb]
name = "polkadot" name = "polkadot"
+1
View File
@@ -56,6 +56,7 @@ runtime-benchmarks = [ "service/runtime-benchmarks", "polkadot-node-metrics/runt
trie-memory-tracker = [ "sp-trie/memory-tracker" ] trie-memory-tracker = [ "sp-trie/memory-tracker" ]
full-node = [ "service/full-node" ] full-node = [ "service/full-node" ]
try-runtime = [ "service/try-runtime" ] try-runtime = [ "service/try-runtime" ]
fast-runtime = [ "service/fast-runtime" ]
# Configure the native runtimes to use. Polkadot is enabled by default. # Configure the native runtimes to use. Polkadot is enabled by default.
# #
+7
View File
@@ -179,6 +179,13 @@ try-runtime = [
"westend-runtime/try-runtime", "westend-runtime/try-runtime",
"rococo-runtime/try-runtime", "rococo-runtime/try-runtime",
] ]
fast-runtime = [
"polkadot-runtime/fast-runtime",
"kusama-runtime/fast-runtime",
"westend-runtime/fast-runtime",
"rococo-runtime/fast-runtime",
]
malus = ["full-node"] malus = ["full-node"]
runtime-metrics = [ runtime-metrics = [
"polkadot-client/runtime-metrics", "polkadot-client/runtime-metrics",
+29
View File
@@ -190,6 +190,35 @@ impl pallet_staking::BenchmarkingConfig for StakingBenchmarkingConfig {
type MaxNominators = ConstU32<1000>; type MaxNominators = ConstU32<1000>;
} }
/// Macro to set a value (e.g. when using the `parameter_types` macro) to either a production value
/// or to an environment variable or testing value (in case the `fast-runtime` feature is selected).
/// Note that the environment variable is evaluated _at compile time_.
///
/// Usage:
/// ```Rust
/// parameter_types! {
/// // Note that the env variable version parameter cannot be const.
/// pub LaunchPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 1, "KSM_LAUNCH_PERIOD");
/// pub const VotingPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 1 * MINUTES);
/// }
#[macro_export]
macro_rules! prod_or_fast {
($prod:expr, $test:expr) => {
if cfg!(feature = "fast-runtime") {
$test
} else {
$prod
}
};
($prod:expr, $test:expr, $env:expr) => {
if cfg!(feature = "fast-runtime") {
core::option_env!($env).map(|s| s.parse().ok()).flatten().unwrap_or($test)
} else {
$prod
}
};
}
#[cfg(test)] #[cfg(test)]
mod multiplier_tests { mod multiplier_tests {
use super::*; use super::*;
+4
View File
@@ -270,4 +270,8 @@ disable-runtime-api = []
on-chain-release-build = [ on-chain-release-build = [
"sp-api/disable-logging", "sp-api/disable-logging",
] ]
# Set timing constants (e.g. session period) to faster versions to speed up testing.
fast-runtime = []
runtime-metrics = ["runtime-parachains/runtime-metrics", "sp-io/with-tracing"] runtime-metrics = ["runtime-parachains/runtime-metrics", "sp-io/with-tracing"]
+28 -15
View File
@@ -33,8 +33,8 @@ use primitives::{
v2::SessionInfo, v2::SessionInfo,
}; };
use runtime_common::{ use runtime_common::{
auctions, claims, crowdloan, impls::DealWithFees, paras_registrar, slots, BlockHashCount, auctions, claims, crowdloan, impls::DealWithFees, paras_registrar, prod_or_fast, slots,
BlockLength, BlockWeights, CurrencyToVote, OffchainSolutionLengthLimit, BlockHashCount, BlockLength, BlockWeights, CurrencyToVote, OffchainSolutionLengthLimit,
OffchainSolutionWeightLimit, RocksDbWeight, SlowAdjustingFeeUpdate, OffchainSolutionWeightLimit, RocksDbWeight, SlowAdjustingFeeUpdate,
}; };
use sp_core::u32_trait::{_1, _2, _3, _5}; use sp_core::u32_trait::{_1, _2, _3, _5};
@@ -249,9 +249,13 @@ impl pallet_preimage::Config for Runtime {
} }
parameter_types! { parameter_types! {
pub const EpochDuration: u64 = EPOCH_DURATION_IN_SLOTS as u64; pub EpochDuration: u64 = prod_or_fast!(
EPOCH_DURATION_IN_SLOTS as u64,
2 * MINUTES as u64,
"KSM_EPOCH_DURATION"
);
pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK; pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK;
pub const ReportLongevity: u64 = pub ReportLongevity: u64 =
BondingDuration::get() as u64 * SessionsPerEra::get() as u64 * EpochDuration::get(); BondingDuration::get() as u64 * SessionsPerEra::get() as u64 * EpochDuration::get();
} }
@@ -385,8 +389,17 @@ impl pallet_session::historical::Config for Runtime {
parameter_types! { parameter_types! {
// phase durations. 1/4 of the last session for each. // phase durations. 1/4 of the last session for each.
pub const SignedPhase: u32 = EPOCH_DURATION_IN_SLOTS / 4; // in testing: 1min or half of the session for each
pub const UnsignedPhase: u32 = EPOCH_DURATION_IN_SLOTS / 4; pub SignedPhase: u32 = prod_or_fast!(
EPOCH_DURATION_IN_SLOTS / 4,
(1 * MINUTES).min(EpochDuration::get().saturated_into::<u32>() / 2),
"KSM_SIGNED_PHASE"
);
pub UnsignedPhase: u32 = prod_or_fast!(
EPOCH_DURATION_IN_SLOTS / 4,
(1 * MINUTES).min(EpochDuration::get().saturated_into::<u32>() / 2),
"KSM_UNSIGNED_PHASE"
);
// signed config // signed config
pub const SignedMaxSubmissions: u32 = 16; pub const SignedMaxSubmissions: u32 = 16;
@@ -572,12 +585,12 @@ impl pallet_staking::Config for Runtime {
} }
parameter_types! { parameter_types! {
pub const LaunchPeriod: BlockNumber = 7 * DAYS; pub LaunchPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 1, "KSM_LAUNCH_PERIOD");
pub const VotingPeriod: BlockNumber = 7 * DAYS; pub VotingPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 1 * MINUTES, "KSM_VOTING_PERIOD");
pub const FastTrackVotingPeriod: BlockNumber = 3 * HOURS; pub FastTrackVotingPeriod: BlockNumber = prod_or_fast!(3 * HOURS, 1 * MINUTES, "KSM_FAST_TRACK_VOTING_PERIOD");
pub const MinimumDeposit: Balance = 100 * CENTS; pub const MinimumDeposit: Balance = 100 * CENTS;
pub const EnactmentPeriod: BlockNumber = 8 * DAYS; pub EnactmentPeriod: BlockNumber = prod_or_fast!(8 * DAYS, 1, "KSM_ENACTMENT_PERIOD");
pub const CooloffPeriod: BlockNumber = 7 * DAYS; pub CooloffPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 1 * MINUTES, "KSM_COOLOFF_PERIOD");
pub const InstantAllowed: bool = true; pub const InstantAllowed: bool = true;
pub const MaxVotes: u32 = 100; pub const MaxVotes: u32 = 100;
pub const MaxProposals: u32 = 100; pub const MaxProposals: u32 = 100;
@@ -637,7 +650,7 @@ impl pallet_democracy::Config for Runtime {
} }
parameter_types! { parameter_types! {
pub const CouncilMotionDuration: BlockNumber = 3 * DAYS; pub CouncilMotionDuration: BlockNumber = prod_or_fast!(3 * DAYS, 2 * MINUTES, "KSM_MOTION_DURATION");
pub const CouncilMaxProposals: u32 = 100; pub const CouncilMaxProposals: u32 = 100;
pub const CouncilMaxMembers: u32 = 100; pub const CouncilMaxMembers: u32 = 100;
} }
@@ -661,7 +674,7 @@ parameter_types! {
// additional data per vote is 32 bytes (account id). // additional data per vote is 32 bytes (account id).
pub const VotingBondFactor: Balance = deposit(0, 32); pub const VotingBondFactor: Balance = deposit(0, 32);
/// Daily council elections /// Daily council elections
pub const TermDuration: BlockNumber = 24 * HOURS; pub TermDuration: BlockNumber = prod_or_fast!(24 * HOURS, 2 * MINUTES, "KSM_TERM_DURATION");
pub const DesiredMembers: u32 = 19; pub const DesiredMembers: u32 = 19;
pub const DesiredRunnersUp: u32 = 19; pub const DesiredRunnersUp: u32 = 19;
pub const PhragmenElectionPalletId: LockIdentifier = *b"phrelect"; pub const PhragmenElectionPalletId: LockIdentifier = *b"phrelect";
@@ -689,7 +702,7 @@ impl pallet_elections_phragmen::Config for Runtime {
} }
parameter_types! { parameter_types! {
pub const TechnicalMotionDuration: BlockNumber = 3 * DAYS; pub TechnicalMotionDuration: BlockNumber = prod_or_fast!(3 * DAYS, 2 * MINUTES, "KSM_MOTION_DURATION");
pub const TechnicalMaxProposals: u32 = 100; pub const TechnicalMaxProposals: u32 = 100;
pub const TechnicalMaxMembers: u32 = 100; pub const TechnicalMaxMembers: u32 = 100;
} }
@@ -1252,7 +1265,7 @@ impl paras_registrar::Config for Runtime {
parameter_types! { parameter_types! {
// 6 weeks // 6 weeks
pub const LeasePeriod: BlockNumber = 6 * WEEKS; pub LeasePeriod: BlockNumber = prod_or_fast!(6 * WEEKS, 6 * WEEKS, "KSM_LEASE_PERIOD");
} }
impl slots::Config for Runtime { impl slots::Config for Runtime {
+4
View File
@@ -257,4 +257,8 @@ disable-runtime-api = []
on-chain-release-build = [ on-chain-release-build = [
"sp-api/disable-logging", "sp-api/disable-logging",
] ]
# Set timing constants (e.g. session period) to faster versions to speed up testing.
fast-runtime = []
runtime-metrics = ["runtime-parachains/runtime-metrics", "sp-io/with-tracing"] runtime-metrics = ["runtime-parachains/runtime-metrics", "sp-io/with-tracing"]
+28 -15
View File
@@ -22,8 +22,8 @@
use pallet_transaction_payment::CurrencyAdapter; use pallet_transaction_payment::CurrencyAdapter;
use runtime_common::{ use runtime_common::{
auctions, claims, crowdloan, impls::DealWithFees, paras_registrar, slots, BlockHashCount, auctions, claims, crowdloan, impls::DealWithFees, paras_registrar, prod_or_fast, slots,
BlockLength, BlockWeights, CurrencyToVote, OffchainSolutionLengthLimit, BlockHashCount, BlockLength, BlockWeights, CurrencyToVote, OffchainSolutionLengthLimit,
OffchainSolutionWeightLimit, RocksDbWeight, SlowAdjustingFeeUpdate, OffchainSolutionWeightLimit, RocksDbWeight, SlowAdjustingFeeUpdate,
}; };
@@ -293,9 +293,13 @@ impl pallet_preimage::Config for Runtime {
} }
parameter_types! { parameter_types! {
pub const EpochDuration: u64 = EPOCH_DURATION_IN_SLOTS as u64; pub EpochDuration: u64 = prod_or_fast!(
EPOCH_DURATION_IN_SLOTS as u64,
2 * MINUTES as u64,
"KSM_EPOCH_DURATION"
);
pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK; pub const ExpectedBlockTime: Moment = MILLISECS_PER_BLOCK;
pub const ReportLongevity: u64 = pub ReportLongevity: u64 =
BondingDuration::get() as u64 * SessionsPerEra::get() as u64 * EpochDuration::get(); BondingDuration::get() as u64 * SessionsPerEra::get() as u64 * EpochDuration::get();
} }
@@ -425,8 +429,17 @@ impl pallet_session::historical::Config for Runtime {
parameter_types! { parameter_types! {
// phase durations. 1/4 of the last session for each. // phase durations. 1/4 of the last session for each.
pub const SignedPhase: u32 = EPOCH_DURATION_IN_SLOTS / 4; // in testing: 1min or half of the session for each
pub const UnsignedPhase: u32 = EPOCH_DURATION_IN_SLOTS / 4; pub SignedPhase: u32 = prod_or_fast!(
EPOCH_DURATION_IN_SLOTS / 4,
(1 * MINUTES).min(EpochDuration::get().saturated_into::<u32>() / 2),
"DOT_SIGNED_PHASE"
);
pub UnsignedPhase: u32 = prod_or_fast!(
EPOCH_DURATION_IN_SLOTS / 4,
(1 * MINUTES).min(EpochDuration::get().saturated_into::<u32>() / 2),
"DOT_UNSIGNED_PHASE"
);
// signed config // signed config
pub const SignedMaxSubmissions: u32 = 16; pub const SignedMaxSubmissions: u32 = 16;
@@ -593,12 +606,12 @@ impl pallet_identity::Config for Runtime {
} }
parameter_types! { parameter_types! {
pub const LaunchPeriod: BlockNumber = 28 * DAYS; pub LaunchPeriod: BlockNumber = prod_or_fast!(28 * DAYS, 1, "DOT_LAUNCH_PERIOD");
pub const VotingPeriod: BlockNumber = 28 * DAYS; pub VotingPeriod: BlockNumber = prod_or_fast!(28 * DAYS, 1 * MINUTES, "DOT_VOTING_PERIOD");
pub const FastTrackVotingPeriod: BlockNumber = 3 * HOURS; pub FastTrackVotingPeriod: BlockNumber = prod_or_fast!(3 * HOURS, 1 * MINUTES, "DOT_FAST_TRACK_VOTING_PERIOD");
pub const MinimumDeposit: Balance = 100 * DOLLARS; pub const MinimumDeposit: Balance = 100 * DOLLARS;
pub const EnactmentPeriod: BlockNumber = 28 * DAYS; pub EnactmentPeriod: BlockNumber = prod_or_fast!(28 * DAYS, 1, "DOT_ENACTMENT_PERIOD");
pub const CooloffPeriod: BlockNumber = 7 * DAYS; pub CooloffPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 1, "DOT_COOLOFF_PERIOD");
pub const InstantAllowed: bool = true; pub const InstantAllowed: bool = true;
pub const MaxVotes: u32 = 100; pub const MaxVotes: u32 = 100;
pub const MaxProposals: u32 = 100; pub const MaxProposals: u32 = 100;
@@ -668,7 +681,7 @@ impl pallet_democracy::Config for Runtime {
} }
parameter_types! { parameter_types! {
pub const CouncilMotionDuration: BlockNumber = 7 * DAYS; pub CouncilMotionDuration: BlockNumber = prod_or_fast!(7 * DAYS, 2 * MINUTES, "DOT_MOTION_DURATION");
pub const CouncilMaxProposals: u32 = 100; pub const CouncilMaxProposals: u32 = 100;
pub const CouncilMaxMembers: u32 = 100; pub const CouncilMaxMembers: u32 = 100;
} }
@@ -692,7 +705,7 @@ parameter_types! {
// additional data per vote is 32 bytes (account id). // additional data per vote is 32 bytes (account id).
pub const VotingBondFactor: Balance = deposit(0, 32); pub const VotingBondFactor: Balance = deposit(0, 32);
/// Weekly council elections; scaling up to monthly eventually. /// Weekly council elections; scaling up to monthly eventually.
pub const TermDuration: BlockNumber = 7 * DAYS; pub TermDuration: BlockNumber = prod_or_fast!(7 * DAYS, 2 * MINUTES, "DOT_TERM_DURATION");
/// 13 members initially, to be increased to 23 eventually. /// 13 members initially, to be increased to 23 eventually.
pub const DesiredMembers: u32 = 13; pub const DesiredMembers: u32 = 13;
pub const DesiredRunnersUp: u32 = 20; pub const DesiredRunnersUp: u32 = 20;
@@ -1236,13 +1249,13 @@ impl paras_registrar::Config for Runtime {
parameter_types! { parameter_types! {
// 12 weeks = 3 months per lease period -> 8 lease periods ~ 2 years // 12 weeks = 3 months per lease period -> 8 lease periods ~ 2 years
pub const LeasePeriod: BlockNumber = 12 * WEEKS; pub LeasePeriod: BlockNumber = prod_or_fast!(12 * WEEKS, 12 * WEEKS, "DOT_LEASE_PERIOD");
// Polkadot Genesis was on May 26, 2020. // Polkadot Genesis was on May 26, 2020.
// Target Parachain Onboarding Date: Dec 15, 2021. // Target Parachain Onboarding Date: Dec 15, 2021.
// Difference is 568 days. // Difference is 568 days.
// We want a lease period to start on the target onboarding date. // We want a lease period to start on the target onboarding date.
// 568 % (12 * 7) = 64 day offset // 568 % (12 * 7) = 64 day offset
pub const LeaseOffset: BlockNumber = 64 * DAYS; pub LeaseOffset: BlockNumber = prod_or_fast!(64 * DAYS, 0, "DOT_LEASE_OFFSET");
} }
impl slots::Config for Runtime { impl slots::Config for Runtime {
+3
View File
@@ -205,4 +205,7 @@ try-runtime = [
"pallet-multisig/try-runtime", "pallet-multisig/try-runtime",
] ]
# Set timing constants (e.g. session period) to faster versions to speed up testing.
fast-runtime = []
runtime-metrics = ["runtime-parachains/runtime-metrics", "sp-io/with-tracing"] runtime-metrics = ["runtime-parachains/runtime-metrics", "sp-io/with-tracing"]
+4 -1
View File
@@ -33,10 +33,13 @@ pub mod currency {
/// Time and blocks. /// Time and blocks.
pub mod time { pub mod time {
use primitives::v0::{BlockNumber, Moment}; use primitives::v0::{BlockNumber, Moment};
use runtime_common::prod_or_fast;
pub const MILLISECS_PER_BLOCK: Moment = 6000; pub const MILLISECS_PER_BLOCK: Moment = 6000;
pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK;
pub const DEFAULT_EPOCH_DURATION: BlockNumber = prod_or_fast!(1 * HOURS, 1 * MINUTES);
frame_support::parameter_types! { frame_support::parameter_types! {
pub storage EpochDurationInBlocks: BlockNumber = 1 * HOURS; pub storage EpochDurationInBlocks: BlockNumber = DEFAULT_EPOCH_DURATION;
} }
// These time units are defined in number of blocks. // These time units are defined in number of blocks.
+4
View File
@@ -254,4 +254,8 @@ try-runtime = [
# runtime without clashing with the runtime API exported functions # runtime without clashing with the runtime API exported functions
# in WASM. # in WASM.
disable-runtime-api = [] disable-runtime-api = []
# Set timing constants (e.g. session period) to faster versions to speed up testing.
fast-runtime = []
runtime-metrics = ["runtime-parachains/runtime-metrics", "sp-io/with-tracing"] runtime-metrics = ["runtime-parachains/runtime-metrics", "sp-io/with-tracing"]
@@ -36,9 +36,11 @@ pub mod currency {
/// Time and blocks. /// Time and blocks.
pub mod time { pub mod time {
use primitives::v0::{BlockNumber, Moment}; use primitives::v0::{BlockNumber, Moment};
use runtime_common::prod_or_fast;
pub const MILLISECS_PER_BLOCK: Moment = 6000; pub const MILLISECS_PER_BLOCK: Moment = 6000;
pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK; pub const SLOT_DURATION: Moment = MILLISECS_PER_BLOCK;
pub const EPOCH_DURATION_IN_SLOTS: BlockNumber = 1 * HOURS; pub const EPOCH_DURATION_IN_SLOTS: BlockNumber = prod_or_fast!(1 * HOURS, 1 * MINUTES);
// These time units are defined in number of blocks. // These time units are defined in number of blocks.
pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
-7
View File
@@ -477,13 +477,6 @@ impl pallet_staking::Config for Runtime {
} }
parameter_types! { parameter_types! {
pub const LaunchPeriod: BlockNumber = 7 * DAYS;
pub const VotingPeriod: BlockNumber = 7 * DAYS;
pub const FastTrackVotingPeriod: BlockNumber = 3 * HOURS;
pub const MinimumDeposit: Balance = 100 * CENTS;
pub const EnactmentPeriod: BlockNumber = 8 * DAYS;
pub const CooloffPeriod: BlockNumber = 7 * DAYS;
pub const InstantAllowed: bool = true;
pub const MaxAuthorities: u32 = 100_000; pub const MaxAuthorities: u32 = 100_000;
} }