Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

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

Merged
merged 31 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
20f3a9d
add fast-runtime feature for reduced session times
apopiak Nov 18, 2021
9189262
make democracy periods fast on fast-runtime
apopiak Nov 18, 2021
9795b54
propagate fast-runtime feature through cargo.toml files
apopiak Nov 19, 2021
75e71d7
add fast motion and term durations to Kusama
apopiak Nov 19, 2021
19ca36c
Merge branch 'master' of github.com:paritytech/polkadot into apopiak/…
apopiak Nov 22, 2021
086cd67
Update runtime/westend/Cargo.toml
apopiak Nov 22, 2021
36725cb
set session time to 2 minutes to avoid block production issues
apopiak Nov 22, 2021
a69ae5d
Merge branch 'apopiak/fast-runtime' of github.com:paritytech/polkadot…
apopiak Nov 23, 2021
6d41bec
formatting
apopiak Nov 23, 2021
d617030
update Substrate
apopiak Nov 23, 2021
67618ae
Merge branch 'master' of github.com:paritytech/polkadot into apopiak/…
apopiak Nov 24, 2021
4a7b933
set democracy fast periods back to 1min
apopiak Nov 25, 2021
bce8a7e
set launch period and enactment period to 1 block in fast-runtime
apopiak Nov 26, 2021
2c19ea5
remove unnecessary westend period configs
apopiak Nov 26, 2021
031f6c4
add prod_or_test macro to allow specifying prod, test and env values …
apopiak Nov 30, 2021
cf59a6c
move prod_or_test macro into common module and use it consistently
apopiak Dec 2, 2021
46661db
Merge branch 'master' of github.com:paritytech/polkadot into apopiak/…
apopiak Dec 2, 2021
fe0dd26
Merge branch 'apopiak/fast-runtime' of github.com:paritytech/polkadot…
apopiak Dec 2, 2021
349b4a6
rename macro to prod_or_fast
apopiak Dec 2, 2021
ce12e4e
cargo +nightly fmt
apopiak Dec 2, 2021
98a38e8
bump impl_versions
apopiak Dec 2, 2021
7682fba
newline
apopiak Dec 4, 2021
ab3858e
add note that env variable is evaluated at compile time
apopiak Dec 4, 2021
f75db21
newline
apopiak Dec 4, 2021
669f655
newline
apopiak Dec 4, 2021
974fdb5
Merge branch 'master' into apopiak/fast-runtime
gilescope Jan 12, 2022
9b81985
cargo fmt
gilescope Jan 12, 2022
38e9852
impl_version: 0
gilescope Jan 12, 2022
f47cd2c
impl_version: 0
gilescope Jan 12, 2022
144ac94
use prod_or_fast macro for LeasePeriod and LeaseOffset
apopiak Jan 12, 2022
12db559
use prod_or_fast macro in WND and ROC constants
apopiak Jan 13, 2022
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ overflow-checks = true
[features]
runtime-benchmarks= [ "polkadot-cli/runtime-benchmarks" ]
try-runtime = [ "polkadot-cli/try-runtime" ]
fast-runtime = [ "polkadot-cli/fast-runtime" ]
runtime-metrics = [ "polkadot-cli/runtime-metrics" ]


# Configuration for building a .deb package - for use with `cargo-deb`
[package.metadata.deb]
name = "polkadot"
Expand Down
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ runtime-benchmarks = [ "service/runtime-benchmarks", "polkadot-node-metrics/runt
trie-memory-tracker = [ "sp-trie/memory-tracker" ]
full-node = [ "service/full-node" ]
try-runtime = [ "service/try-runtime" ]
fast-runtime = [ "service/fast-runtime" ]

# Configure the native runtimes to use. Polkadot is enabled by default.
#
Expand Down
7 changes: 7 additions & 0 deletions node/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ try-runtime = [
"westend-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"]
runtime-metrics = [
"polkadot-client/runtime-metrics",
Expand Down
29 changes: 29 additions & 0 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,35 @@ impl pallet_staking::BenchmarkingConfig for StakingBenchmarkingConfig {
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).
gilescope marked this conversation as resolved.
Show resolved Hide resolved
apopiak marked this conversation as resolved.
Show resolved Hide resolved
/// 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)]
mod multiplier_tests {
use super::*;
Expand Down
4 changes: 4 additions & 0 deletions runtime/kusama/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,8 @@ disable-runtime-api = []
on-chain-release-build = [
"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"]
43 changes: 28 additions & 15 deletions runtime/kusama/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ use primitives::{
v2::SessionInfo,
};
use runtime_common::{
auctions, claims, crowdloan, impls::DealWithFees, paras_registrar, slots, BlockHashCount,
BlockLength, BlockWeights, CurrencyToVote, OffchainSolutionLengthLimit,
auctions, claims, crowdloan, impls::DealWithFees, paras_registrar, prod_or_fast, slots,
BlockHashCount, BlockLength, BlockWeights, CurrencyToVote, OffchainSolutionLengthLimit,
OffchainSolutionWeightLimit, RocksDbWeight, SlowAdjustingFeeUpdate,
};
use sp_core::u32_trait::{_1, _2, _3, _5};
Expand Down Expand Up @@ -249,9 +249,13 @@ impl pallet_preimage::Config for Runtime {
}

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 ReportLongevity: u64 =
pub ReportLongevity: u64 =
BondingDuration::get() as u64 * SessionsPerEra::get() as u64 * EpochDuration::get();
}

Expand Down Expand Up @@ -385,8 +389,17 @@ impl pallet_session::historical::Config for Runtime {

parameter_types! {
// phase durations. 1/4 of the last session for each.
pub const SignedPhase: u32 = EPOCH_DURATION_IN_SLOTS / 4;
pub const UnsignedPhase: u32 = EPOCH_DURATION_IN_SLOTS / 4;
// in testing: 1min or half of the session for each
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
pub const SignedMaxSubmissions: u32 = 16;
Expand Down Expand Up @@ -572,12 +585,12 @@ impl pallet_staking::Config for Runtime {
}

parameter_types! {
pub const LaunchPeriod: BlockNumber = 7 * DAYS;
pub const VotingPeriod: BlockNumber = 7 * DAYS;
pub const FastTrackVotingPeriod: BlockNumber = 3 * HOURS;
pub LaunchPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 1, "KSM_LAUNCH_PERIOD");
gilescope marked this conversation as resolved.
Show resolved Hide resolved
pub VotingPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 1 * MINUTES, "KSM_VOTING_PERIOD");
pub FastTrackVotingPeriod: BlockNumber = prod_or_fast!(3 * HOURS, 1 * MINUTES, "KSM_FAST_TRACK_VOTING_PERIOD");
pub const MinimumDeposit: Balance = 100 * CENTS;
pub const EnactmentPeriod: BlockNumber = 8 * DAYS;
pub const CooloffPeriod: BlockNumber = 7 * DAYS;
pub EnactmentPeriod: BlockNumber = prod_or_fast!(8 * DAYS, 1, "KSM_ENACTMENT_PERIOD");
gilescope marked this conversation as resolved.
Show resolved Hide resolved
pub CooloffPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 1 * MINUTES, "KSM_COOLOFF_PERIOD");
pub const InstantAllowed: bool = true;
pub const MaxVotes: u32 = 100;
pub const MaxProposals: u32 = 100;
Expand Down Expand Up @@ -637,7 +650,7 @@ impl pallet_democracy::Config for Runtime {
}

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 CouncilMaxMembers: u32 = 100;
}
Expand All @@ -661,7 +674,7 @@ parameter_types! {
// additional data per vote is 32 bytes (account id).
pub const VotingBondFactor: Balance = deposit(0, 32);
/// 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 DesiredRunnersUp: u32 = 19;
pub const PhragmenElectionPalletId: LockIdentifier = *b"phrelect";
Expand Down Expand Up @@ -689,7 +702,7 @@ impl pallet_elections_phragmen::Config for Runtime {
}

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 TechnicalMaxMembers: u32 = 100;
}
Expand Down Expand Up @@ -1252,7 +1265,7 @@ impl paras_registrar::Config for Runtime {

parameter_types! {
// 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 {
Expand Down
4 changes: 4 additions & 0 deletions runtime/polkadot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,8 @@ disable-runtime-api = []
on-chain-release-build = [
"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"]
43 changes: 28 additions & 15 deletions runtime/polkadot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

use pallet_transaction_payment::CurrencyAdapter;
use runtime_common::{
auctions, claims, crowdloan, impls::DealWithFees, paras_registrar, slots, BlockHashCount,
BlockLength, BlockWeights, CurrencyToVote, OffchainSolutionLengthLimit,
auctions, claims, crowdloan, impls::DealWithFees, paras_registrar, prod_or_fast, slots,
BlockHashCount, BlockLength, BlockWeights, CurrencyToVote, OffchainSolutionLengthLimit,
OffchainSolutionWeightLimit, RocksDbWeight, SlowAdjustingFeeUpdate,
};

Expand Down Expand Up @@ -293,9 +293,13 @@ impl pallet_preimage::Config for Runtime {
}

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 ReportLongevity: u64 =
pub ReportLongevity: u64 =
BondingDuration::get() as u64 * SessionsPerEra::get() as u64 * EpochDuration::get();
}

Expand Down Expand Up @@ -425,8 +429,17 @@ impl pallet_session::historical::Config for Runtime {

parameter_types! {
// phase durations. 1/4 of the last session for each.
pub const SignedPhase: u32 = EPOCH_DURATION_IN_SLOTS / 4;
pub const UnsignedPhase: u32 = EPOCH_DURATION_IN_SLOTS / 4;
// in testing: 1min or half of the session for each
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
pub const SignedMaxSubmissions: u32 = 16;
Expand Down Expand Up @@ -593,12 +606,12 @@ impl pallet_identity::Config for Runtime {
}

parameter_types! {
pub const LaunchPeriod: BlockNumber = 28 * DAYS;
pub const VotingPeriod: BlockNumber = 28 * DAYS;
pub const FastTrackVotingPeriod: BlockNumber = 3 * HOURS;
pub LaunchPeriod: BlockNumber = prod_or_fast!(28 * DAYS, 1, "DOT_LAUNCH_PERIOD");
pub VotingPeriod: BlockNumber = prod_or_fast!(28 * DAYS, 1 * MINUTES, "DOT_VOTING_PERIOD");
pub FastTrackVotingPeriod: BlockNumber = prod_or_fast!(3 * HOURS, 1 * MINUTES, "DOT_FAST_TRACK_VOTING_PERIOD");
pub const MinimumDeposit: Balance = 100 * DOLLARS;
pub const EnactmentPeriod: BlockNumber = 28 * DAYS;
pub const CooloffPeriod: BlockNumber = 7 * DAYS;
pub EnactmentPeriod: BlockNumber = prod_or_fast!(28 * DAYS, 1, "DOT_ENACTMENT_PERIOD");
pub CooloffPeriod: BlockNumber = prod_or_fast!(7 * DAYS, 1, "DOT_COOLOFF_PERIOD");
pub const InstantAllowed: bool = true;
pub const MaxVotes: u32 = 100;
pub const MaxProposals: u32 = 100;
Expand Down Expand Up @@ -668,7 +681,7 @@ impl pallet_democracy::Config for Runtime {
}

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 CouncilMaxMembers: u32 = 100;
}
Expand All @@ -692,7 +705,7 @@ parameter_types! {
// additional data per vote is 32 bytes (account id).
pub const VotingBondFactor: Balance = deposit(0, 32);
/// 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.
pub const DesiredMembers: u32 = 13;
pub const DesiredRunnersUp: u32 = 20;
Expand Down Expand Up @@ -1236,13 +1249,13 @@ impl paras_registrar::Config for Runtime {

parameter_types! {
// 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.
// Target Parachain Onboarding Date: Dec 15, 2021.
// Difference is 568 days.
// We want a lease period to start on the target onboarding date.
// 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 {
Expand Down
3 changes: 3 additions & 0 deletions runtime/rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,7 @@ 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"]
5 changes: 4 additions & 1 deletion runtime/rococo/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@ pub mod currency {
/// Time and blocks.
pub mod time {
use primitives::v0::{BlockNumber, Moment};
use runtime_common::prod_or_fast;

pub const MILLISECS_PER_BLOCK: Moment = 6000;
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! {
pub storage EpochDurationInBlocks: BlockNumber = 1 * HOURS;
pub storage EpochDurationInBlocks: BlockNumber = DEFAULT_EPOCH_DURATION;
}

// These time units are defined in number of blocks.
Expand Down
4 changes: 4 additions & 0 deletions runtime/westend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,8 @@ try-runtime = [
# runtime without clashing with the runtime API exported functions
# in WASM.
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"]
4 changes: 3 additions & 1 deletion runtime/westend/constants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ pub mod currency {
/// Time and blocks.
pub mod time {
use primitives::v0::{BlockNumber, Moment};
use runtime_common::prod_or_fast;

pub const MILLISECS_PER_BLOCK: Moment = 6000;
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.
pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
Expand Down
7 changes: 0 additions & 7 deletions runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,13 +477,6 @@ impl pallet_staking::Config for Runtime {
}

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;
}

Expand Down