mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 09:21:04 +00:00
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:
+1
-1
@@ -139,9 +139,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"
|
||||
|
||||
@@ -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.
|
||||
#
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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).
|
||||
/// 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::*;
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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};
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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");
|
||||
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");
|
||||
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;
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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";
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user