From 261063e228bf97440d18d0dd2c59b238bfdaafce Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Wed, 31 Jan 2024 16:23:54 +0200 Subject: [PATCH 01/40] Fix some typos --- polkadot/runtime/parachains/src/scheduler/common.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/polkadot/runtime/parachains/src/scheduler/common.rs b/polkadot/runtime/parachains/src/scheduler/common.rs index 2eb73385803c..9fc708549967 100644 --- a/polkadot/runtime/parachains/src/scheduler/common.rs +++ b/polkadot/runtime/parachains/src/scheduler/common.rs @@ -63,7 +63,7 @@ pub struct AssignmentProviderConfig { pub trait AssignmentProvider { /// Pops an [`Assignment`] from the provider for a specified [`CoreIndex`]. /// - /// This is where assignments come into existance. + /// This is where assignments come into existence. fn pop_assignment_for_core(core_idx: CoreIndex) -> Option; /// A previously popped `Assignment` has been fully processed. @@ -77,7 +77,7 @@ pub trait AssignmentProvider { /// Push back a previously popped assignment. /// /// If the assignment could not be processed within the current session, it can be pushed back - /// to the assignment provider in order to be poppped again later. + /// to the assignment provider in order to be popped again later. /// /// This is the second way the life of an assignment can come to an end. fn push_back_assignment(assignment: Assignment); From a7e27bc6732cc89d9691a6858fa7f29e174c846c Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Thu, 1 Feb 2024 10:51:12 +0200 Subject: [PATCH 02/40] Replace calls to `AssignmentProviderConfig` with reads from `HostConfiguration` --- .../parachains/src/assigner_coretime/mod.rs | 10 +------ .../parachains/src/assigner_parachains.rs | 12 +-------- polkadot/runtime/parachains/src/builder.rs | 12 +++------ polkadot/runtime/parachains/src/mock.rs | 23 +--------------- polkadot/runtime/parachains/src/scheduler.rs | 27 ++++++------------- .../parachains/src/scheduler/common.rs | 15 ----------- .../runtime/parachains/src/scheduler/tests.rs | 19 +++++++------ 7 files changed, 23 insertions(+), 95 deletions(-) diff --git a/polkadot/runtime/parachains/src/assigner_coretime/mod.rs b/polkadot/runtime/parachains/src/assigner_coretime/mod.rs index 9da81dc816ca..4b703c703c1c 100644 --- a/polkadot/runtime/parachains/src/assigner_coretime/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_coretime/mod.rs @@ -30,7 +30,7 @@ mod tests; use crate::{ assigner_on_demand, configuration, paras::AssignCoretime, - scheduler::common::{Assignment, AssignmentProvider, AssignmentProviderConfig}, + scheduler::common::{Assignment, AssignmentProvider}, ParaId, }; @@ -316,14 +316,6 @@ impl AssignmentProvider> for Pallet { } } - fn get_provider_config(_core_idx: CoreIndex) -> AssignmentProviderConfig> { - let config = >::config(); - AssignmentProviderConfig { - max_availability_timeouts: config.on_demand_retries, - ttl: config.on_demand_ttl, - } - } - #[cfg(any(feature = "runtime-benchmarks", test))] fn get_mock_assignment(_: CoreIndex, para_id: primitives::Id) -> Assignment { // Given that we are not tracking anything in `Bulk` assignments, it is safe to always diff --git a/polkadot/runtime/parachains/src/assigner_parachains.rs b/polkadot/runtime/parachains/src/assigner_parachains.rs index 34b5d3c1ec51..b5f342563e97 100644 --- a/polkadot/runtime/parachains/src/assigner_parachains.rs +++ b/polkadot/runtime/parachains/src/assigner_parachains.rs @@ -27,7 +27,7 @@ use primitives::CoreIndex; use crate::{ configuration, paras, - scheduler::common::{Assignment, AssignmentProvider, AssignmentProviderConfig}, + scheduler::common::{Assignment, AssignmentProvider}, }; pub use pallet::*; @@ -58,16 +58,6 @@ impl AssignmentProvider> for Pallet { /// this is a no-op in the case of a bulk assignment slot. fn push_back_assignment(_: Assignment) {} - fn get_provider_config(_core_idx: CoreIndex) -> AssignmentProviderConfig> { - AssignmentProviderConfig { - // The next assignment already goes to the same [`ParaId`], no timeout tracking needed. - max_availability_timeouts: 0, - // The next assignment already goes to the same [`ParaId`], this can be any number - // that's high enough to clear the time it takes to clear backing/availability. - ttl: 10u32.into(), - } - } - #[cfg(any(feature = "runtime-benchmarks", test))] fn get_mock_assignment(_: CoreIndex, para_id: primitives::Id) -> Assignment { Assignment::Bulk(para_id) diff --git a/polkadot/runtime/parachains/src/builder.rs b/polkadot/runtime/parachains/src/builder.rs index 016b3fca589a..87a085fc8455 100644 --- a/polkadot/runtime/parachains/src/builder.rs +++ b/polkadot/runtime/parachains/src/builder.rs @@ -18,11 +18,7 @@ use crate::{ configuration, inclusion, initializer, paras, paras::ParaKind, paras_inherent, - scheduler::{ - self, - common::{AssignmentProvider, AssignmentProviderConfig}, - CoreOccupied, ParasEntry, - }, + scheduler::{self, common::AssignmentProvider, CoreOccupied, ParasEntry}, session_info, shared, }; use bitvec::{order::Lsb0 as BitOrderLsb0, vec::BitVec}; @@ -714,8 +710,7 @@ impl BenchBuilder { let cores = (0..used_cores) .into_iter() .map(|i| { - let AssignmentProviderConfig { ttl, .. } = - scheduler::Pallet::::assignment_provider_config(CoreIndex(i)); + let ttl = configuration::Pallet::::config().on_demand_ttl; // Load an assignment into provider so that one is present to pop let assignment = ::AssignmentProvider::get_mock_assignment( CoreIndex(i), @@ -730,8 +725,7 @@ impl BenchBuilder { let cores = (0..used_cores) .into_iter() .map(|i| { - let AssignmentProviderConfig { ttl, .. } = - scheduler::Pallet::::assignment_provider_config(CoreIndex(i)); + let ttl = configuration::Pallet::::config().on_demand_ttl; // Load an assignment into provider so that one is present to pop let assignment = ::AssignmentProvider::get_mock_assignment( diff --git a/polkadot/runtime/parachains/src/mock.rs b/polkadot/runtime/parachains/src/mock.rs index 1925ca19501a..e18be03bdeb2 100644 --- a/polkadot/runtime/parachains/src/mock.rs +++ b/polkadot/runtime/parachains/src/mock.rs @@ -23,7 +23,7 @@ use crate::{ initializer, origin, paras, paras::ParaKind, paras_inherent, scheduler, - scheduler::common::{AssignmentProvider, AssignmentProviderConfig}, + scheduler::common::AssignmentProvider, session_info, shared, ParaId, }; use frame_support::pallet_prelude::*; @@ -463,10 +463,6 @@ pub mod mock_assigner { pub(super) type MockAssignmentQueue = StorageValue<_, VecDeque, ValueQuery>; - #[pallet::storage] - pub(super) type MockProviderConfig = - StorageValue<_, AssignmentProviderConfig, OptionQuery>; - #[pallet::storage] pub(super) type MockCoreCount = StorageValue<_, u32, OptionQuery>; } @@ -478,12 +474,6 @@ pub mod mock_assigner { MockAssignmentQueue::::mutate(|queue| queue.push_back(assignment)); } - // This configuration needs to be customized to service `get_provider_config` in - // scheduler tests. - pub fn set_assignment_provider_config(config: AssignmentProviderConfig) { - MockProviderConfig::::set(Some(config)); - } - // Allows for customized core count in scheduler tests, rather than a core count // derived from on-demand config + parachain count. pub fn set_core_count(count: u32) { @@ -512,17 +502,6 @@ pub mod mock_assigner { // in the mock assigner. fn push_back_assignment(_assignment: Assignment) {} - // Gets the provider config we set earlier using `set_assignment_provider_config`, falling - // back to the on demand parachain configuration if none was set. - fn get_provider_config(_core_idx: CoreIndex) -> AssignmentProviderConfig { - match MockProviderConfig::::get() { - Some(config) => config, - None => AssignmentProviderConfig { - max_availability_timeouts: 1, - ttl: BlockNumber::from(5u32), - }, - } - } #[cfg(any(feature = "runtime-benchmarks", test))] fn get_mock_assignment(_: CoreIndex, para_id: ParaId) -> Assignment { Assignment::Bulk(para_id) diff --git a/polkadot/runtime/parachains/src/scheduler.rs b/polkadot/runtime/parachains/src/scheduler.rs index a666f5689089..747a05f24b95 100644 --- a/polkadot/runtime/parachains/src/scheduler.rs +++ b/polkadot/runtime/parachains/src/scheduler.rs @@ -51,7 +51,7 @@ use sp_std::{ pub mod common; -use common::{Assignment, AssignmentProvider, AssignmentProviderConfig}; +use common::{Assignment, AssignmentProvider}; pub use pallet::*; @@ -352,6 +352,7 @@ impl Pallet { fn drop_expired_claims_from_claimqueue() { let now = >::block_number(); let availability_cores = AvailabilityCores::::get(); + let ttl = >::config().on_demand_ttl; ClaimQueue::::mutate(|cq| { for (idx, _) in (0u32..).zip(availability_cores) { @@ -384,8 +385,6 @@ impl Pallet { if let Some(assignment) = T::AssignmentProvider::pop_assignment_for_core(core_idx) { - let AssignmentProviderConfig { ttl, .. } = - T::AssignmentProvider::get_provider_config(core_idx); core_claimqueue.push_back(ParasEntry::new(assignment, now + ttl)); } } @@ -510,6 +509,7 @@ impl Pallet { /// Return the next thing that will be scheduled on this core assuming it is currently /// occupied and the candidate occupying it times out. pub(crate) fn next_up_on_time_out(core: CoreIndex) -> Option { + let max_availability_timeouts = >::config().on_demand_retries; Self::next_up_on_available(core).or_else(|| { // Or, if none, the claim currently occupying the core, // as it would be put back on the queue after timing out if number of retries is not at @@ -517,16 +517,12 @@ impl Pallet { let cores = AvailabilityCores::::get(); cores.get(core.0 as usize).and_then(|c| match c { CoreOccupied::Free => None, - CoreOccupied::Paras(pe) => { - let AssignmentProviderConfig { max_availability_timeouts, .. } = - T::AssignmentProvider::get_provider_config(core); - + CoreOccupied::Paras(pe) => if pe.availability_timeouts < max_availability_timeouts { Some(Self::paras_entry_to_scheduled_core(pe)) } else { None - } - }, + }, }) }) } @@ -587,15 +583,15 @@ impl Pallet { let n_lookahead = Self::claimqueue_lookahead().max(1); let n_session_cores = T::AssignmentProvider::session_core_count(); let cq = ClaimQueue::::get(); - let ttl = >::config().on_demand_ttl; + let config = >::config(); + let max_availability_timeouts = config.on_demand_retries; + let ttl = config.on_demand_ttl; for core_idx in 0..n_session_cores { let core_idx = CoreIndex::from(core_idx); // add previously timedout paras back into the queue if let Some(mut entry) = timedout_paras.remove(&core_idx) { - let AssignmentProviderConfig { max_availability_timeouts, .. } = - T::AssignmentProvider::get_provider_config(core_idx); if entry.availability_timeouts < max_availability_timeouts { // Increment the timeout counter. entry.availability_timeouts += 1; @@ -670,13 +666,6 @@ impl Pallet { .filter_map(|(core_idx, v)| v.front().map(|e| (core_idx, e.assignment.para_id()))) } - #[cfg(any(feature = "runtime-benchmarks", test))] - pub(crate) fn assignment_provider_config( - core_idx: CoreIndex, - ) -> AssignmentProviderConfig> { - T::AssignmentProvider::get_provider_config(core_idx) - } - #[cfg(any(feature = "try-runtime", test))] fn claimqueue_len() -> usize { ClaimQueue::::get().iter().map(|la_vec| la_vec.1.len()).sum() diff --git a/polkadot/runtime/parachains/src/scheduler/common.rs b/polkadot/runtime/parachains/src/scheduler/common.rs index 9fc708549967..66a4e6d30be0 100644 --- a/polkadot/runtime/parachains/src/scheduler/common.rs +++ b/polkadot/runtime/parachains/src/scheduler/common.rs @@ -48,18 +48,6 @@ impl Assignment { } } -#[derive(Encode, Decode, TypeInfo)] -/// A set of variables required by the scheduler in order to operate. -pub struct AssignmentProviderConfig { - /// How many times a collation can time out on availability. - /// Zero timeouts still means that a collation can be provided as per the slot auction - /// assignment provider. - pub max_availability_timeouts: u32, - - /// How long the collator has to provide a collation to the backing group before being dropped. - pub ttl: BlockNumber, -} - pub trait AssignmentProvider { /// Pops an [`Assignment`] from the provider for a specified [`CoreIndex`]. /// @@ -82,9 +70,6 @@ pub trait AssignmentProvider { /// This is the second way the life of an assignment can come to an end. fn push_back_assignment(assignment: Assignment); - /// Returns a set of variables needed by the scheduler - fn get_provider_config(core_idx: CoreIndex) -> AssignmentProviderConfig; - /// Push some assignment for mocking/benchmarks purposes. /// /// Useful for benchmarks and testing. The returned assignment is "valid" and can if need be diff --git a/polkadot/runtime/parachains/src/scheduler/tests.rs b/polkadot/runtime/parachains/src/scheduler/tests.rs index 9af23ce64bd6..abe57efcc3be 100644 --- a/polkadot/runtime/parachains/src/scheduler/tests.rs +++ b/polkadot/runtime/parachains/src/scheduler/tests.rs @@ -112,6 +112,7 @@ fn default_config() -> HostConfiguration { // `minimum_validation_upgrade_delay` is greater than `chain_availability_period` and // `thread_availability_period`. minimum_validation_upgrade_delay: 6, + on_demand_retries: 1, ..Default::default() } } @@ -163,7 +164,7 @@ fn claimqueue_ttl_drop_fn_works() { let mut now = 10; new_test_ext(genesis_config).execute_with(|| { - let assignment_provider_ttl = MockAssigner::get_provider_config(CoreIndex::from(0)).ttl; + let assignment_provider_ttl = config.on_demand_ttl; assert!(assignment_provider_ttl == 5); // Register and run to a blockheight where the para is in a valid state. schedule_blank_para(para_id); @@ -330,7 +331,8 @@ fn session_change_takes_only_max_per_core() { #[test] fn fill_claimqueue_fills() { - let genesis_config = genesis_config(&default_config()); + let config = default_config(); + let genesis_config = genesis_config(&config); let para_a = ParaId::from(3_u32); let para_b = ParaId::from(4_u32); @@ -342,8 +344,7 @@ fn fill_claimqueue_fills() { new_test_ext(genesis_config).execute_with(|| { MockAssigner::set_core_count(2); - let AssignmentProviderConfig { ttl: config_ttl, .. } = - MockAssigner::get_provider_config(CoreIndex(0)); + let config_ttl = config.on_demand_ttl; // Add 3 paras schedule_blank_para(para_a); @@ -745,6 +746,9 @@ fn on_demand_claims_are_pruned_after_timing_out() { let max_retries = 20; let mut config = default_config(); config.scheduling_lookahead = 1; + // Need more timeouts for this test + config.on_demand_retries = max_retries; + config.on_demand_ttl = BlockNumber::from(5u32); let genesis_config = genesis_config(&config); let para_a = ParaId::from(1_u32); @@ -753,11 +757,6 @@ fn on_demand_claims_are_pruned_after_timing_out() { new_test_ext(genesis_config).execute_with(|| { MockAssigner::set_core_count(2); - // Need more timeouts for this test - MockAssigner::set_assignment_provider_config(AssignmentProviderConfig { - max_availability_timeouts: max_retries, - ttl: BlockNumber::from(5u32), - }); schedule_blank_para(para_a); // #1 @@ -1056,7 +1055,7 @@ fn session_change_requires_reschedule_dropping_removed_paras() { new_test_ext(genesis_config).execute_with(|| { // Setting explicit core count MockAssigner::set_core_count(5); - let assignment_provider_ttl = MockAssigner::get_provider_config(CoreIndex::from(0)).ttl; + let assignment_provider_ttl = >::config().on_demand_ttl; schedule_blank_para(para_a); schedule_blank_para(para_b); From 830bc0f5e858944474171bbe33382ad96040b535 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Thu, 1 Feb 2024 18:42:02 +0200 Subject: [PATCH 03/40] on_demand_retries -> coretime_max_availability_timeouts; on_demand_ttl -> coretime_ttl --- polkadot/runtime/parachains/src/builder.rs | 4 +-- .../runtime/parachains/src/configuration.rs | 20 +++++++-------- .../parachains/src/configuration/tests.rs | 11 +++++--- polkadot/runtime/parachains/src/scheduler.rs | 9 ++++--- .../runtime/parachains/src/scheduler/tests.rs | 25 +++++++++---------- 5 files changed, 36 insertions(+), 33 deletions(-) diff --git a/polkadot/runtime/parachains/src/builder.rs b/polkadot/runtime/parachains/src/builder.rs index 87a085fc8455..d153d864b4e2 100644 --- a/polkadot/runtime/parachains/src/builder.rs +++ b/polkadot/runtime/parachains/src/builder.rs @@ -710,7 +710,7 @@ impl BenchBuilder { let cores = (0..used_cores) .into_iter() .map(|i| { - let ttl = configuration::Pallet::::config().on_demand_ttl; + let ttl = configuration::Pallet::::config().coretime_ttl; // Load an assignment into provider so that one is present to pop let assignment = ::AssignmentProvider::get_mock_assignment( CoreIndex(i), @@ -725,7 +725,7 @@ impl BenchBuilder { let cores = (0..used_cores) .into_iter() .map(|i| { - let ttl = configuration::Pallet::::config().on_demand_ttl; + let ttl = configuration::Pallet::::config().coretime_ttl; // Load an assignment into provider so that one is present to pop let assignment = ::AssignmentProvider::get_mock_assignment( diff --git a/polkadot/runtime/parachains/src/configuration.rs b/polkadot/runtime/parachains/src/configuration.rs index 4619313590eb..93faced80538 100644 --- a/polkadot/runtime/parachains/src/configuration.rs +++ b/polkadot/runtime/parachains/src/configuration.rs @@ -174,8 +174,8 @@ pub struct HostConfiguration { pub code_retention_period: BlockNumber, /// How many cores are managed by the coretime chain. pub coretime_cores: u32, - /// The number of retries that a on demand author has to submit their block. - pub on_demand_retries: u32, + /// The max number of times a claim can time out in availability + pub coretime_max_availability_timeouts: u32, /// The maximum queue size of the pay as you go module. pub on_demand_queue_max_size: u32, /// The target utilization of the spot price queue in percentages. @@ -185,10 +185,10 @@ pub struct HostConfiguration { pub on_demand_fee_variability: Perbill, /// The minimum amount needed to claim a slot in the spot pricing queue. pub on_demand_base_fee: Balance, - /// The number of blocks an on demand claim stays in the scheduler's claimqueue before getting - /// cleared. This number should go reasonably higher than the number of blocks in the async - /// backing lookahead. - pub on_demand_ttl: BlockNumber, + /// The number of blocks a claim stays in the scheduler's claimqueue before getting cleared. + /// This number should go reasonably higher than the number of blocks in the async backing + /// lookahead. + pub coretime_ttl: BlockNumber, /// How often parachain groups should be rotated across parachains. /// /// Must be non-zero. @@ -285,7 +285,7 @@ impl> Default for HostConfiguration> Default for HostConfiguration, new: u32) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.on_demand_retries = new; + config.coretime_max_availability_timeouts = new; }) } @@ -1194,7 +1194,7 @@ pub mod pallet { pub fn set_on_demand_ttl(origin: OriginFor, new: BlockNumberFor) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.on_demand_ttl = new; + config.coretime_ttl = new; }) } diff --git a/polkadot/runtime/parachains/src/configuration/tests.rs b/polkadot/runtime/parachains/src/configuration/tests.rs index c915eb12a0ca..0a6cfa395a92 100644 --- a/polkadot/runtime/parachains/src/configuration/tests.rs +++ b/polkadot/runtime/parachains/src/configuration/tests.rs @@ -284,7 +284,7 @@ fn setting_pending_config_members() { max_pov_size: 1024, max_head_data_size: 1_000, coretime_cores: 2, - on_demand_retries: 5, + coretime_max_availability_timeouts: 5, group_rotation_frequency: 20, paras_availability_period: 10, scheduling_lookahead: 3, @@ -318,7 +318,7 @@ fn setting_pending_config_members() { on_demand_base_fee: 10_000_000u128, on_demand_fee_variability: Perbill::from_percent(3), on_demand_target_queue_utilization: Perbill::from_percent(25), - on_demand_ttl: 5u32, + coretime_ttl: 5u32, minimum_backing_votes: 5, node_features: bitvec![u8, Lsb0; 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1], }; @@ -344,8 +344,11 @@ fn setting_pending_config_members() { .unwrap(); Configuration::set_coretime_cores(RuntimeOrigin::root(), new_config.coretime_cores) .unwrap(); - Configuration::set_on_demand_retries(RuntimeOrigin::root(), new_config.on_demand_retries) - .unwrap(); + Configuration::set_on_demand_retries( + RuntimeOrigin::root(), + new_config.coretime_max_availability_timeouts, + ) + .unwrap(); Configuration::set_group_rotation_frequency( RuntimeOrigin::root(), new_config.group_rotation_frequency, diff --git a/polkadot/runtime/parachains/src/scheduler.rs b/polkadot/runtime/parachains/src/scheduler.rs index 747a05f24b95..8fc84b40f0cc 100644 --- a/polkadot/runtime/parachains/src/scheduler.rs +++ b/polkadot/runtime/parachains/src/scheduler.rs @@ -352,7 +352,7 @@ impl Pallet { fn drop_expired_claims_from_claimqueue() { let now = >::block_number(); let availability_cores = AvailabilityCores::::get(); - let ttl = >::config().on_demand_ttl; + let ttl = >::config().coretime_ttl; ClaimQueue::::mutate(|cq| { for (idx, _) in (0u32..).zip(availability_cores) { @@ -509,7 +509,8 @@ impl Pallet { /// Return the next thing that will be scheduled on this core assuming it is currently /// occupied and the candidate occupying it times out. pub(crate) fn next_up_on_time_out(core: CoreIndex) -> Option { - let max_availability_timeouts = >::config().on_demand_retries; + let max_availability_timeouts = + >::config().coretime_max_availability_timeouts; Self::next_up_on_available(core).or_else(|| { // Or, if none, the claim currently occupying the core, // as it would be put back on the queue after timing out if number of retries is not at @@ -584,8 +585,8 @@ impl Pallet { let n_session_cores = T::AssignmentProvider::session_core_count(); let cq = ClaimQueue::::get(); let config = >::config(); - let max_availability_timeouts = config.on_demand_retries; - let ttl = config.on_demand_ttl; + let max_availability_timeouts = config.coretime_max_availability_timeouts; + let ttl = config.coretime_ttl; for core_idx in 0..n_session_cores { let core_idx = CoreIndex::from(core_idx); diff --git a/polkadot/runtime/parachains/src/scheduler/tests.rs b/polkadot/runtime/parachains/src/scheduler/tests.rs index abe57efcc3be..d963d77a8ec0 100644 --- a/polkadot/runtime/parachains/src/scheduler/tests.rs +++ b/polkadot/runtime/parachains/src/scheduler/tests.rs @@ -112,7 +112,7 @@ fn default_config() -> HostConfiguration { // `minimum_validation_upgrade_delay` is greater than `chain_availability_period` and // `thread_availability_period`. minimum_validation_upgrade_delay: 6, - on_demand_retries: 1, + coretime_max_availability_timeouts: 1, ..Default::default() } } @@ -164,8 +164,7 @@ fn claimqueue_ttl_drop_fn_works() { let mut now = 10; new_test_ext(genesis_config).execute_with(|| { - let assignment_provider_ttl = config.on_demand_ttl; - assert!(assignment_provider_ttl == 5); + assert!(config.coretime_ttl == 5); // Register and run to a blockheight where the para is in a valid state. schedule_blank_para(para_id); run_to_block(now, |n| if n == now { Some(Default::default()) } else { None }); @@ -344,7 +343,7 @@ fn fill_claimqueue_fills() { new_test_ext(genesis_config).execute_with(|| { MockAssigner::set_core_count(2); - let config_ttl = config.on_demand_ttl; + let coretime_ttl = config.coretime_ttl; // Add 3 paras schedule_blank_para(para_a); @@ -382,7 +381,7 @@ fn fill_claimqueue_fills() { &ParasEntry { assignment: assignment_a.clone(), availability_timeouts: 0, - ttl: 2 + config_ttl + ttl: 2 + coretime_ttl }, ); // Sits on the same core as `para_a` @@ -391,7 +390,7 @@ fn fill_claimqueue_fills() { ParasEntry { assignment: assignment_b.clone(), availability_timeouts: 0, - ttl: 2 + config_ttl + ttl: 2 + coretime_ttl } ); assert_eq!( @@ -399,7 +398,7 @@ fn fill_claimqueue_fills() { &ParasEntry { assignment: assignment_c.clone(), availability_timeouts: 0, - ttl: 2 + config_ttl + ttl: 2 + coretime_ttl }, ); } @@ -747,8 +746,8 @@ fn on_demand_claims_are_pruned_after_timing_out() { let mut config = default_config(); config.scheduling_lookahead = 1; // Need more timeouts for this test - config.on_demand_retries = max_retries; - config.on_demand_ttl = BlockNumber::from(5u32); + config.coretime_max_availability_timeouts = max_retries; + config.coretime_ttl = BlockNumber::from(5u32); let genesis_config = genesis_config(&config); let para_a = ParaId::from(1_u32); @@ -1055,7 +1054,7 @@ fn session_change_requires_reschedule_dropping_removed_paras() { new_test_ext(genesis_config).execute_with(|| { // Setting explicit core count MockAssigner::set_core_count(5); - let assignment_provider_ttl = >::config().on_demand_ttl; + let coretime_ttl = >::config().coretime_ttl; schedule_blank_para(para_a); schedule_blank_para(para_b); @@ -1119,7 +1118,7 @@ fn session_change_requires_reschedule_dropping_removed_paras() { vec![ParasEntry::new( Assignment::Bulk(para_a), // At end of block 2 - assignment_provider_ttl + 2 + coretime_ttl + 2 )] .into_iter() .collect() @@ -1168,7 +1167,7 @@ fn session_change_requires_reschedule_dropping_removed_paras() { vec![ParasEntry::new( Assignment::Bulk(para_a), // At block 3 - assignment_provider_ttl + 3 + coretime_ttl + 3 )] .into_iter() .collect() @@ -1178,7 +1177,7 @@ fn session_change_requires_reschedule_dropping_removed_paras() { vec![ParasEntry::new( Assignment::Bulk(para_b), // At block 3 - assignment_provider_ttl + 3 + coretime_ttl + 3 )] .into_iter() .collect() From 6140dda4ff61071001f46528dd834c918d3f641f Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Thu, 1 Feb 2024 18:42:45 +0200 Subject: [PATCH 04/40] Storage migration --- .../parachains/src/configuration/migration.rs | 1 + .../src/configuration/migration/v11.rs | 115 +++++- .../src/configuration/migration/v12.rs | 329 ++++++++++++++++++ 3 files changed, 442 insertions(+), 3 deletions(-) create mode 100644 polkadot/runtime/parachains/src/configuration/migration/v12.rs diff --git a/polkadot/runtime/parachains/src/configuration/migration.rs b/polkadot/runtime/parachains/src/configuration/migration.rs index 2838b73092db..87b30b177e73 100644 --- a/polkadot/runtime/parachains/src/configuration/migration.rs +++ b/polkadot/runtime/parachains/src/configuration/migration.rs @@ -18,6 +18,7 @@ pub mod v10; pub mod v11; +pub mod v12; pub mod v6; pub mod v7; pub mod v8; diff --git a/polkadot/runtime/parachains/src/configuration/migration/v11.rs b/polkadot/runtime/parachains/src/configuration/migration/v11.rs index f4db9196b1a0..6fcd07ef6bc7 100644 --- a/polkadot/runtime/parachains/src/configuration/migration/v11.rs +++ b/polkadot/runtime/parachains/src/configuration/migration/v11.rs @@ -21,13 +21,122 @@ use frame_support::{ migrations::VersionedMigration, pallet_prelude::*, traits::Defensive, weights::Weight, }; use frame_system::pallet_prelude::BlockNumberFor; -use primitives::{vstaging::ApprovalVotingParams, SessionIndex}; +use primitives::{ + vstaging::ApprovalVotingParams, AsyncBackingParams, ExecutorParams, SessionIndex, + LEGACY_MIN_BACKING_VOTES, ON_DEMAND_DEFAULT_QUEUE_MAX_SIZE, +}; use sp_std::vec::Vec; use frame_support::traits::OnRuntimeUpgrade; +use polkadot_core_primitives::Balance; +use primitives::vstaging::NodeFeatures; +use sp_arithmetic::Perbill; use super::v10::V10HostConfiguration; -type V11HostConfiguration = configuration::HostConfiguration; + +#[derive(Clone, Encode, PartialEq, Decode, Debug)] +pub struct V11HostConfiguration { + pub max_code_size: u32, + pub max_head_data_size: u32, + pub max_upward_queue_count: u32, + pub max_upward_queue_size: u32, + pub max_upward_message_size: u32, + pub max_upward_message_num_per_candidate: u32, + pub hrmp_max_message_num_per_candidate: u32, + pub validation_upgrade_cooldown: BlockNumber, + pub validation_upgrade_delay: BlockNumber, + pub async_backing_params: AsyncBackingParams, + pub max_pov_size: u32, + pub max_downward_message_size: u32, + pub hrmp_max_parachain_outbound_channels: u32, + pub hrmp_sender_deposit: Balance, + pub hrmp_recipient_deposit: Balance, + pub hrmp_channel_max_capacity: u32, + pub hrmp_channel_max_total_size: u32, + pub hrmp_max_parachain_inbound_channels: u32, + pub hrmp_channel_max_message_size: u32, + pub executor_params: ExecutorParams, + pub code_retention_period: BlockNumber, + pub coretime_cores: u32, + pub on_demand_retries: u32, + pub on_demand_queue_max_size: u32, + pub on_demand_target_queue_utilization: Perbill, + pub on_demand_fee_variability: Perbill, + pub on_demand_base_fee: Balance, + pub on_demand_ttl: BlockNumber, + pub group_rotation_frequency: BlockNumber, + pub paras_availability_period: BlockNumber, + pub scheduling_lookahead: u32, + pub max_validators_per_core: Option, + pub max_validators: Option, + pub dispute_period: SessionIndex, + pub dispute_post_conclusion_acceptance_period: BlockNumber, + pub no_show_slots: u32, + pub n_delay_tranches: u32, + pub zeroth_delay_tranche_width: u32, + pub needed_approvals: u32, + pub relay_vrf_modulo_samples: u32, + pub pvf_voting_ttl: SessionIndex, + pub minimum_validation_upgrade_delay: BlockNumber, + pub minimum_backing_votes: u32, + pub node_features: NodeFeatures, + pub approval_voting_params: ApprovalVotingParams, +} + +impl> Default for V11HostConfiguration { + fn default() -> Self { + Self { + async_backing_params: AsyncBackingParams { + max_candidate_depth: 0, + allowed_ancestry_len: 0, + }, + group_rotation_frequency: 1u32.into(), + paras_availability_period: 1u32.into(), + no_show_slots: 1u32.into(), + validation_upgrade_cooldown: Default::default(), + validation_upgrade_delay: 2u32.into(), + code_retention_period: Default::default(), + max_code_size: Default::default(), + max_pov_size: Default::default(), + max_head_data_size: Default::default(), + coretime_cores: Default::default(), + on_demand_retries: Default::default(), + scheduling_lookahead: 1, + max_validators_per_core: Default::default(), + max_validators: None, + dispute_period: 6, + dispute_post_conclusion_acceptance_period: 100.into(), + n_delay_tranches: Default::default(), + zeroth_delay_tranche_width: Default::default(), + needed_approvals: Default::default(), + relay_vrf_modulo_samples: Default::default(), + max_upward_queue_count: Default::default(), + max_upward_queue_size: Default::default(), + max_downward_message_size: Default::default(), + max_upward_message_size: Default::default(), + max_upward_message_num_per_candidate: Default::default(), + hrmp_sender_deposit: Default::default(), + hrmp_recipient_deposit: Default::default(), + hrmp_channel_max_capacity: Default::default(), + hrmp_channel_max_total_size: Default::default(), + hrmp_max_parachain_inbound_channels: Default::default(), + hrmp_channel_max_message_size: Default::default(), + hrmp_max_parachain_outbound_channels: Default::default(), + hrmp_max_message_num_per_candidate: Default::default(), + pvf_voting_ttl: 2u32.into(), + minimum_validation_upgrade_delay: 2.into(), + executor_params: Default::default(), + approval_voting_params: ApprovalVotingParams { max_approval_coalesce_count: 1 }, + on_demand_queue_max_size: ON_DEMAND_DEFAULT_QUEUE_MAX_SIZE, + on_demand_base_fee: 10_000_000u128, + on_demand_fee_variability: Perbill::from_percent(3), + on_demand_target_queue_utilization: Perbill::from_percent(25), + on_demand_ttl: 5u32.into(), + minimum_backing_votes: LEGACY_MIN_BACKING_VOTES, + node_features: NodeFeatures::EMPTY, + } + } +} mod v10 { use super::*; @@ -287,7 +396,7 @@ mod tests { assert_eq!(v10.hrmp_channel_max_message_size , v11.hrmp_channel_max_message_size); assert_eq!(v10.code_retention_period , v11.code_retention_period); assert_eq!(v10.coretime_cores , v11.coretime_cores); - assert_eq!(v10.on_demand_retries , v11.on_demand_retries); + assert_eq!(v10.coretime_max_availability_timeouts, v11.coretime_max_availability_timeouts); assert_eq!(v10.group_rotation_frequency , v11.group_rotation_frequency); assert_eq!(v10.paras_availability_period , v11.paras_availability_period); assert_eq!(v10.scheduling_lookahead , v11.scheduling_lookahead); diff --git a/polkadot/runtime/parachains/src/configuration/migration/v12.rs b/polkadot/runtime/parachains/src/configuration/migration/v12.rs new file mode 100644 index 000000000000..58c933965234 --- /dev/null +++ b/polkadot/runtime/parachains/src/configuration/migration/v12.rs @@ -0,0 +1,329 @@ +// Copyright (C) Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Polkadot is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Polkadot. If not, see . + +//! A module that is responsible for migration of storage. + +use crate::configuration::{self, migration::v11::V11HostConfiguration, Config, Pallet}; +use frame_support::{ + migrations::VersionedMigration, + pallet_prelude::*, + traits::{Defensive, OnRuntimeUpgrade}, +}; +use frame_system::pallet_prelude::BlockNumberFor; +use sp_core::Get; +use sp_staking::SessionIndex; + +type V12HostConfiguration = configuration::HostConfiguration; +mod v11 { + use super::*; + + #[frame_support::storage_alias] + pub(crate) type ActiveConfig = + StorageValue, V11HostConfiguration>, OptionQuery>; + + #[frame_support::storage_alias] + pub(crate) type PendingConfigs = StorageValue< + Pallet, + Vec<(SessionIndex, V11HostConfiguration>)>, + OptionQuery, + >; +} + +mod v12 { + use super::*; + + #[frame_support::storage_alias] + pub(crate) type ActiveConfig = + StorageValue, V12HostConfiguration>, OptionQuery>; + + #[frame_support::storage_alias] + pub(crate) type PendingConfigs = StorageValue< + Pallet, + Vec<(SessionIndex, V12HostConfiguration>)>, + OptionQuery, + >; +} + +pub type MigrateToV12 = VersionedMigration< + 11, + 12, + UncheckedMigrateToV12, + Pallet, + ::DbWeight, +>; + +pub struct UncheckedMigrateToV12(sp_std::marker::PhantomData); + +impl OnRuntimeUpgrade for UncheckedMigrateToV12 { + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { + log::trace!(target: crate::configuration::LOG_TARGET, "Running pre_upgrade() for HostConfiguration MigrateToV12"); + Ok(Vec::new()) + } + + fn on_runtime_upgrade() -> Weight { + log::info!(target: configuration::LOG_TARGET, "HostConfiguration MigrateToV12 started"); + let weight_consumed = migrate_to_v12::(); + + log::info!(target: configuration::LOG_TARGET, "HostConfiguration MigrateToV12 executed successfully"); + + weight_consumed + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_state: Vec) -> Result<(), sp_runtime::TryRuntimeError> { + log::trace!(target: crate::configuration::LOG_TARGET, "Running post_upgrade() for HostConfiguration MigrateToV12"); + ensure!( + StorageVersion::get::>() >= 12, + "Storage version should be >= 12 after the migration" + ); + + Ok(()) + } +} + +fn migrate_to_v12() -> Weight { + // Unusual formatting is justified: + // - make it easier to verify that fields assign what they supposed to assign. + // - this code is transient and will be removed after all migrations are done. + // - this code is important enough to optimize for legibility sacrificing consistency. + #[rustfmt::skip] + let translate = + |pre: V11HostConfiguration>| -> + V12HostConfiguration> + { + V12HostConfiguration { + max_code_size : pre.max_code_size, + max_head_data_size : pre.max_head_data_size, + max_upward_queue_count : pre.max_upward_queue_count, + max_upward_queue_size : pre.max_upward_queue_size, + max_upward_message_size : pre.max_upward_message_size, + max_upward_message_num_per_candidate : pre.max_upward_message_num_per_candidate, + hrmp_max_message_num_per_candidate : pre.hrmp_max_message_num_per_candidate, + validation_upgrade_cooldown : pre.validation_upgrade_cooldown, + validation_upgrade_delay : pre.validation_upgrade_delay, + max_pov_size : pre.max_pov_size, + max_downward_message_size : pre.max_downward_message_size, + hrmp_sender_deposit : pre.hrmp_sender_deposit, + hrmp_recipient_deposit : pre.hrmp_recipient_deposit, + hrmp_channel_max_capacity : pre.hrmp_channel_max_capacity, + hrmp_channel_max_total_size : pre.hrmp_channel_max_total_size, + hrmp_max_parachain_inbound_channels : pre.hrmp_max_parachain_inbound_channels, + hrmp_max_parachain_outbound_channels : pre.hrmp_max_parachain_outbound_channels, + hrmp_channel_max_message_size : pre.hrmp_channel_max_message_size, + code_retention_period : pre.code_retention_period, + coretime_cores : pre.coretime_cores, + coretime_max_availability_timeouts : pre.on_demand_retries, + group_rotation_frequency : pre.group_rotation_frequency, + paras_availability_period : pre.paras_availability_period, + scheduling_lookahead : pre.scheduling_lookahead, + max_validators_per_core : pre.max_validators_per_core, + max_validators : pre.max_validators, + dispute_period : pre.dispute_period, + dispute_post_conclusion_acceptance_period: pre.dispute_post_conclusion_acceptance_period, + no_show_slots : pre.no_show_slots, + n_delay_tranches : pre.n_delay_tranches, + zeroth_delay_tranche_width : pre.zeroth_delay_tranche_width, + needed_approvals : pre.needed_approvals, + relay_vrf_modulo_samples : pre.relay_vrf_modulo_samples, + pvf_voting_ttl : pre.pvf_voting_ttl, + minimum_validation_upgrade_delay : pre.minimum_validation_upgrade_delay, + async_backing_params : pre.async_backing_params, + executor_params : pre.executor_params, + on_demand_queue_max_size : pre.on_demand_queue_max_size, + on_demand_base_fee : pre.on_demand_base_fee, + on_demand_fee_variability : pre.on_demand_fee_variability, + on_demand_target_queue_utilization : pre.on_demand_target_queue_utilization, + coretime_ttl : pre.on_demand_ttl, + minimum_backing_votes : pre.minimum_backing_votes, + node_features : pre.node_features, + approval_voting_params : pre.approval_voting_params, + } + }; + + let v11 = v11::ActiveConfig::::get() + .defensive_proof("Could not decode old config") + .unwrap_or_default(); + let v12 = translate(v11); + v12::ActiveConfig::::set(Some(v12)); + + // Allowed to be empty. + let pending_v11 = v11::PendingConfigs::::get().unwrap_or_default(); + let mut pending_v12 = Vec::new(); + + for (session, v11) in pending_v11.into_iter() { + let v12 = translate(v11); + pending_v12.push((session, v12)); + } + v12::PendingConfigs::::set(Some(pending_v12.clone())); + + let num_configs = (pending_v12.len() + 1) as u64; + T::DbWeight::get().reads_writes(num_configs, num_configs) +} + +#[cfg(test)] +mod tests { + use primitives::LEGACY_MIN_BACKING_VOTES; + + use super::*; + use crate::mock::{new_test_ext, Test}; + + #[test] + fn v12_deserialized_from_actual_data() { + // Example how to get new `raw_config`: + // We'll obtain the raw_config at a specified a block + // Steps: + // 1. Go to Polkadot.js -> Developer -> Chain state -> Storage: https://polkadot.js.org/apps/#/chainstate + // 2. Set these parameters: + // 2.1. selected state query: configuration; activeConfig(): + // PolkadotRuntimeParachainsConfigurationHostConfiguration + // 2.2. blockhash to query at: + // 0xf89d3ab5312c5f70d396dc59612f0aa65806c798346f9db4b35278baed2e0e53 (the hash of + // the block) + // 2.3. Note the value of encoded storage key -> + // 0x06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385 for the + // referenced block. + // 2.4. You'll also need the decoded values to update the test. + // 3. Go to Polkadot.js -> Developer -> Chain state -> Raw storage + // 3.1 Enter the encoded storage key and you get the raw config. + + // This exceeds the maximal line width length, but that's fine, since this is not code and + // doesn't need to be read and also leaving it as one line allows to easily copy it. + let raw_config = + hex_literal::hex![" + 0000300000800000080000000000100000c8000005000000050000000200000002000000000000000000000000005000000010000400000000000000000000000000000000000000000000000000000000000000000000000800000000200000040000000000100000b004000000000000000000001027000080b2e60e80c3c9018096980000000000000000000000000005000000140000000400000001000000010100000000060000006400000002000000190000000000000002000000020000000200000005000000020000000001000000" + ]; + + let v11 = + V11HostConfiguration::::decode(&mut &raw_config[..]).unwrap(); + + // We check only a sample of the values here. If we missed any fields or messed up data + // types that would skew all the fields coming after. + assert_eq!(v11.max_code_size, 3_145_728); + assert_eq!(v11.validation_upgrade_cooldown, 2); + assert_eq!(v11.max_pov_size, 5_242_880); + assert_eq!(v11.hrmp_channel_max_message_size, 1_048_576); + assert_eq!(v11.n_delay_tranches, 25); + assert_eq!(v11.minimum_validation_upgrade_delay, 5); + assert_eq!(v11.group_rotation_frequency, 20); + assert_eq!(v11.coretime_cores, 0); + assert_eq!(v11.on_demand_base_fee, 10_000_000); + assert_eq!(v11.minimum_backing_votes, LEGACY_MIN_BACKING_VOTES); + assert_eq!(v11.approval_voting_params.max_approval_coalesce_count, 1); + } + + #[test] + fn test_migrate_to_v12() { + // Host configuration has lots of fields. However, in this migration we only add one + // field. The most important part to check are a couple of the last fields. We also pick + // extra fields to check arbitrarily, e.g. depending on their position (i.e. the middle) and + // also their type. + // + // We specify only the picked fields and the rest should be provided by the `Default` + // implementation. That implementation is copied over between the two types and should work + // fine. + let v11 = V11HostConfiguration:: { + needed_approvals: 69, + paras_availability_period: 55, + hrmp_recipient_deposit: 1337, + max_pov_size: 1111, + minimum_validation_upgrade_delay: 20, + on_demand_ttl: 3, + on_demand_retries: 10, + ..Default::default() + }; + + let mut pending_configs = Vec::new(); + pending_configs.push((100, v11.clone())); + pending_configs.push((300, v11.clone())); + + new_test_ext(Default::default()).execute_with(|| { + // Implant the v10 version in the state. + v11::ActiveConfig::::set(Some(v11)); + v11::PendingConfigs::::set(Some(pending_configs)); + + migrate_to_v12::(); + + let v12 = v12::ActiveConfig::::get().unwrap(); + assert_eq!(v12.approval_voting_params.max_approval_coalesce_count, 1); + + let mut configs_to_check = v12::PendingConfigs::::get().unwrap(); + configs_to_check.push((0, v12.clone())); + + for (_, v12) in configs_to_check { + #[rustfmt::skip] + { + assert_eq!(v11.max_code_size , v12.max_code_size); + assert_eq!(v11.max_head_data_size , v12.max_head_data_size); + assert_eq!(v11.max_upward_queue_count , v12.max_upward_queue_count); + assert_eq!(v11.max_upward_queue_size , v12.max_upward_queue_size); + assert_eq!(v11.max_upward_message_size , v12.max_upward_message_size); + assert_eq!(v11.max_upward_message_num_per_candidate , v12.max_upward_message_num_per_candidate); + assert_eq!(v11.hrmp_max_message_num_per_candidate , v12.hrmp_max_message_num_per_candidate); + assert_eq!(v11.validation_upgrade_cooldown , v12.validation_upgrade_cooldown); + assert_eq!(v11.validation_upgrade_delay , v12.validation_upgrade_delay); + assert_eq!(v11.max_pov_size , v12.max_pov_size); + assert_eq!(v11.max_downward_message_size , v12.max_downward_message_size); + assert_eq!(v11.hrmp_max_parachain_outbound_channels , v12.hrmp_max_parachain_outbound_channels); + assert_eq!(v11.hrmp_sender_deposit , v12.hrmp_sender_deposit); + assert_eq!(v11.hrmp_recipient_deposit , v12.hrmp_recipient_deposit); + assert_eq!(v11.hrmp_channel_max_capacity , v12.hrmp_channel_max_capacity); + assert_eq!(v11.hrmp_channel_max_total_size , v12.hrmp_channel_max_total_size); + assert_eq!(v11.hrmp_max_parachain_inbound_channels , v12.hrmp_max_parachain_inbound_channels); + assert_eq!(v11.hrmp_channel_max_message_size , v12.hrmp_channel_max_message_size); + assert_eq!(v11.code_retention_period , v12.code_retention_period); + assert_eq!(v11.coretime_cores , v12.coretime_cores); + assert_eq!(v11.on_demand_retries , v12.coretime_max_availability_timeouts); + assert_eq!(v11.group_rotation_frequency , v12.group_rotation_frequency); + assert_eq!(v11.paras_availability_period , v12.paras_availability_period); + assert_eq!(v11.scheduling_lookahead , v12.scheduling_lookahead); + assert_eq!(v11.max_validators_per_core , v12.max_validators_per_core); + assert_eq!(v11.max_validators , v12.max_validators); + assert_eq!(v11.dispute_period , v12.dispute_period); + assert_eq!(v11.no_show_slots , v12.no_show_slots); + assert_eq!(v11.n_delay_tranches , v12.n_delay_tranches); + assert_eq!(v11.zeroth_delay_tranche_width , v12.zeroth_delay_tranche_width); + assert_eq!(v11.needed_approvals , v12.needed_approvals); + assert_eq!(v11.relay_vrf_modulo_samples , v12.relay_vrf_modulo_samples); + assert_eq!(v11.pvf_voting_ttl , v12.pvf_voting_ttl); + assert_eq!(v11.minimum_validation_upgrade_delay , v12.minimum_validation_upgrade_delay); + assert_eq!(v11.async_backing_params.allowed_ancestry_len, v12.async_backing_params.allowed_ancestry_len); + assert_eq!(v11.async_backing_params.max_candidate_depth , v12.async_backing_params.max_candidate_depth); + assert_eq!(v11.executor_params , v12.executor_params); + assert_eq!(v11.minimum_backing_votes , v12.minimum_backing_votes); + assert_eq!(v11.on_demand_ttl , v12.coretime_ttl); + }; // ; makes this a statement. `rustfmt::skip` cannot be put on an expression. + } + }); + } + + // Test that migration doesn't panic in case there are no pending configurations upgrades in + // pallet's storage. + #[test] + fn test_migrate_to_v12_no_pending() { + let v11 = V11HostConfiguration::::default(); + + new_test_ext(Default::default()).execute_with(|| { + // Implant the v10 version in the state. + v11::ActiveConfig::::set(Some(v11)); + // Ensure there are no pending configs. + v12::PendingConfigs::::set(None); + + // Shouldn't fail. + migrate_to_v12::(); + }); + } +} From fc591067fa75e6f1b0ab5b86e41f7cd6a04db4ba Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Fri, 2 Feb 2024 10:51:28 +0200 Subject: [PATCH 05/40] Extract coretime related config params to `struct CoretimeParams` --- polkadot/primitives/src/vstaging/mod.rs | 47 +++++++++++++++++++ .../src/assigner_coretime/mock_helpers.rs | 11 +++-- .../parachains/src/assigner_coretime/mod.rs | 6 +-- .../src/assigner_on_demand/mock_helpers.rs | 11 +++-- .../parachains/src/assigner_on_demand/mod.rs | 18 ++++--- .../src/assigner_parachains/mock_helpers.rs | 11 +++-- polkadot/runtime/parachains/src/builder.rs | 6 +-- .../runtime/parachains/src/configuration.rs | 47 ++++++------------- .../src/configuration/migration/v11.rs | 2 +- .../src/configuration/migration/v12.rs | 29 +++++++----- .../parachains/src/configuration/tests.rs | 25 ++++++---- .../parachains/src/coretime/migration.rs | 15 ++++-- .../runtime/parachains/src/coretime/mod.rs | 4 +- .../runtime/parachains/src/inclusion/tests.rs | 4 +- polkadot/runtime/parachains/src/scheduler.rs | 11 +++-- .../runtime/parachains/src/scheduler/tests.rs | 23 +++++---- .../parachains/src/session_info/tests.rs | 4 +- 17 files changed, 166 insertions(+), 108 deletions(-) diff --git a/polkadot/primitives/src/vstaging/mod.rs b/polkadot/primitives/src/vstaging/mod.rs index 630bcf8679ad..4ca3c472722f 100644 --- a/polkadot/primitives/src/vstaging/mod.rs +++ b/polkadot/primitives/src/vstaging/mod.rs @@ -23,6 +23,7 @@ use sp_std::prelude::*; use parity_scale_codec::{Decode, Encode}; use primitives::RuntimeDebug; use scale_info::TypeInfo; +use sp_arithmetic::Perbill; /// Approval voting configuration parameters #[derive( @@ -50,6 +51,52 @@ impl Default for ApprovalVotingParams { } } +/// Coretime configuration parameters +#[derive( + RuntimeDebug, + Copy, + Clone, + PartialEq, + Encode, + Decode, + TypeInfo, + serde::Serialize, + serde::Deserialize, +)] +pub struct CoretimeParams { + /// How many cores are managed by the coretime chain. + pub coretime_cores: u32, + /// The max number of times a claim can time out in availability + pub coretime_max_availability_timeouts: u32, + /// The maximum queue size of the pay as you go module. + pub on_demand_queue_max_size: u32, + /// The target utilization of the spot price queue in percentages. + pub on_demand_target_queue_utilization: Perbill, + /// How quickly the fee rises in reaction to increased utilization. + /// The lower the number the slower the increase. + pub on_demand_fee_variability: Perbill, + /// The minimum amount needed to claim a slot in the spot pricing queue. + pub on_demand_base_fee: Balance, + /// The number of blocks a claim stays in the scheduler's claimqueue before getting cleared. + /// This number should go reasonably higher than the number of blocks in the async backing + /// lookahead. + pub coretime_ttl: BlockNumber, +} + +impl> Default for CoretimeParams { + fn default() -> Self { + Self { + coretime_cores: Default::default(), + coretime_max_availability_timeouts: Default::default(), + on_demand_queue_max_size: ON_DEMAND_DEFAULT_QUEUE_MAX_SIZE, + on_demand_target_queue_utilization: Perbill::from_percent(25), + on_demand_fee_variability: Perbill::from_percent(3), + on_demand_base_fee: 10_000_000u128, + coretime_ttl: 5u32.into(), + } + } +} + use bitvec::vec::BitVec; /// Bit indices in the `HostConfiguration.node_features` that correspond to different node features. diff --git a/polkadot/runtime/parachains/src/assigner_coretime/mock_helpers.rs b/polkadot/runtime/parachains/src/assigner_coretime/mock_helpers.rs index 71c3f1fa39f7..ef7e66662684 100644 --- a/polkadot/runtime/parachains/src/assigner_coretime/mock_helpers.rs +++ b/polkadot/runtime/parachains/src/assigner_coretime/mock_helpers.rs @@ -64,11 +64,12 @@ impl GenesisConfigBuilder { pub(super) fn build(self) -> MockGenesisConfig { let mut genesis = default_genesis_config(); let config = &mut genesis.configuration.config; - config.coretime_cores = self.on_demand_cores; - config.on_demand_base_fee = self.on_demand_base_fee; - config.on_demand_fee_variability = self.on_demand_fee_variability; - config.on_demand_queue_max_size = self.on_demand_max_queue_size; - config.on_demand_target_queue_utilization = self.on_demand_target_queue_utilization; + config.coretime_params.coretime_cores = self.on_demand_cores; + config.coretime_params.on_demand_base_fee = self.on_demand_base_fee; + config.coretime_params.on_demand_fee_variability = self.on_demand_fee_variability; + config.coretime_params.on_demand_queue_max_size = self.on_demand_max_queue_size; + config.coretime_params.on_demand_target_queue_utilization = + self.on_demand_target_queue_utilization; let paras = &mut genesis.paras.paras; for para_id in self.onboarded_on_demand_chains { diff --git a/polkadot/runtime/parachains/src/assigner_coretime/mod.rs b/polkadot/runtime/parachains/src/assigner_coretime/mod.rs index 4b703c703c1c..7e998243c717 100644 --- a/polkadot/runtime/parachains/src/assigner_coretime/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_coretime/mod.rs @@ -325,7 +325,7 @@ impl AssignmentProvider> for Pallet { fn session_core_count() -> u32 { let config = >::config(); - config.coretime_cores + config.coretime_params.coretime_cores } } @@ -474,8 +474,8 @@ impl AssignCoretime for Pallet { // Add a new core and assign the para to it. let mut config = >::config(); - let core = config.coretime_cores; - config.coretime_cores.saturating_inc(); + let core = config.coretime_params.coretime_cores; + config.coretime_params.coretime_cores.saturating_inc(); // `assign_coretime` is only called at genesis or by root, so setting the active // config here is fine. diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mock_helpers.rs b/polkadot/runtime/parachains/src/assigner_on_demand/mock_helpers.rs index de30330ac84e..74e86a49b946 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mock_helpers.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/mock_helpers.rs @@ -63,11 +63,12 @@ impl GenesisConfigBuilder { pub(super) fn build(self) -> MockGenesisConfig { let mut genesis = default_genesis_config(); let config = &mut genesis.configuration.config; - config.coretime_cores = self.on_demand_cores; - config.on_demand_base_fee = self.on_demand_base_fee; - config.on_demand_fee_variability = self.on_demand_fee_variability; - config.on_demand_queue_max_size = self.on_demand_max_queue_size; - config.on_demand_target_queue_utilization = self.on_demand_target_queue_utilization; + config.coretime_params.coretime_cores = self.on_demand_cores; + config.coretime_params.on_demand_base_fee = self.on_demand_base_fee; + config.coretime_params.on_demand_fee_variability = self.on_demand_fee_variability; + config.coretime_params.on_demand_queue_max_size = self.on_demand_max_queue_size; + config.coretime_params.on_demand_target_queue_utilization = + self.on_demand_target_queue_utilization; let paras = &mut genesis.paras.paras; for para_id in self.onboarded_on_demand_chains { diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs index 1b746e88694c..676a4a4988bc 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs @@ -201,10 +201,10 @@ pub mod pallet { let old_traffic = SpotTraffic::::get(); match Self::calculate_spot_traffic( old_traffic, - config.on_demand_queue_max_size, + config.coretime_params.on_demand_queue_max_size, Self::queue_size(), - config.on_demand_target_queue_utilization, - config.on_demand_fee_variability, + config.coretime_params.on_demand_target_queue_utilization, + config.coretime_params.on_demand_fee_variability, ) { Ok(new_traffic) => { // Only update storage on change @@ -330,8 +330,9 @@ where let traffic = SpotTraffic::::get(); // Calculate spot price - let spot_price: BalanceOf = - traffic.saturating_mul_int(config.on_demand_base_fee.saturated_into::>()); + let spot_price: BalanceOf = traffic.saturating_mul_int( + config.coretime_params.on_demand_base_fee.saturated_into::>(), + ); // Is the current price higher than `max_amount` ensure!(spot_price.le(&max_amount), Error::::SpotPriceHigherThanMaxAmount); @@ -450,7 +451,10 @@ where OnDemandQueue::::try_mutate(|queue| { // Abort transaction if queue is too large - ensure!(Self::queue_size() < config.on_demand_queue_max_size, Error::::QueueFull); + ensure!( + Self::queue_size() < config.coretime_params.on_demand_queue_max_size, + Error::::QueueFull + ); match location { QueuePushDirection::Back => queue.push_back(order), QueuePushDirection::Front => queue.push_front(order), @@ -472,7 +476,7 @@ where target: LOG_TARGET, "Failed to fetch the on demand queue size, returning the max size." ); - return config.on_demand_queue_max_size + return config.coretime_params.on_demand_queue_max_size }, } } diff --git a/polkadot/runtime/parachains/src/assigner_parachains/mock_helpers.rs b/polkadot/runtime/parachains/src/assigner_parachains/mock_helpers.rs index e6e9fb074aa9..adde113d1876 100644 --- a/polkadot/runtime/parachains/src/assigner_parachains/mock_helpers.rs +++ b/polkadot/runtime/parachains/src/assigner_parachains/mock_helpers.rs @@ -60,11 +60,12 @@ impl GenesisConfigBuilder { pub(super) fn build(self) -> MockGenesisConfig { let mut genesis = default_genesis_config(); let config = &mut genesis.configuration.config; - config.coretime_cores = self.on_demand_cores; - config.on_demand_base_fee = self.on_demand_base_fee; - config.on_demand_fee_variability = self.on_demand_fee_variability; - config.on_demand_queue_max_size = self.on_demand_max_queue_size; - config.on_demand_target_queue_utilization = self.on_demand_target_queue_utilization; + config.coretime_params.coretime_cores = self.on_demand_cores; + config.coretime_params.on_demand_base_fee = self.on_demand_base_fee; + config.coretime_params.on_demand_fee_variability = self.on_demand_fee_variability; + config.coretime_params.on_demand_queue_max_size = self.on_demand_max_queue_size; + config.coretime_params.on_demand_target_queue_utilization = + self.on_demand_target_queue_utilization; let paras = &mut genesis.paras.paras; for para_id in self.onboarded_on_demand_chains { diff --git a/polkadot/runtime/parachains/src/builder.rs b/polkadot/runtime/parachains/src/builder.rs index d153d864b4e2..d3461ba7725b 100644 --- a/polkadot/runtime/parachains/src/builder.rs +++ b/polkadot/runtime/parachains/src/builder.rs @@ -679,7 +679,7 @@ impl BenchBuilder { // We are currently in Session 0, so these changes will take effect in Session 2. Self::setup_para_ids(used_cores); configuration::ActiveConfig::::mutate(|c| { - c.coretime_cores = used_cores; + c.coretime_params.coretime_cores = used_cores; }); let validator_ids = Self::generate_validator_pairs(self.max_validators()); @@ -710,7 +710,7 @@ impl BenchBuilder { let cores = (0..used_cores) .into_iter() .map(|i| { - let ttl = configuration::Pallet::::config().coretime_ttl; + let ttl = configuration::Pallet::::config().coretime_params.coretime_ttl; // Load an assignment into provider so that one is present to pop let assignment = ::AssignmentProvider::get_mock_assignment( CoreIndex(i), @@ -725,7 +725,7 @@ impl BenchBuilder { let cores = (0..used_cores) .into_iter() .map(|i| { - let ttl = configuration::Pallet::::config().coretime_ttl; + let ttl = configuration::Pallet::::config().coretime_params.coretime_ttl; // Load an assignment into provider so that one is present to pop let assignment = ::AssignmentProvider::get_mock_assignment( diff --git a/polkadot/runtime/parachains/src/configuration.rs b/polkadot/runtime/parachains/src/configuration.rs index 93faced80538..d626c981e2b0 100644 --- a/polkadot/runtime/parachains/src/configuration.rs +++ b/polkadot/runtime/parachains/src/configuration.rs @@ -29,7 +29,6 @@ use primitives::{ vstaging::{ApprovalVotingParams, NodeFeatures}, AsyncBackingParams, Balance, ExecutorParamError, ExecutorParams, SessionIndex, LEGACY_MIN_BACKING_VOTES, MAX_CODE_SIZE, MAX_HEAD_DATA_SIZE, MAX_POV_SIZE, - ON_DEMAND_DEFAULT_QUEUE_MAX_SIZE, }; use sp_runtime::{traits::Zero, Perbill}; use sp_std::prelude::*; @@ -43,6 +42,7 @@ mod benchmarking; pub mod migration; pub use pallet::*; +use primitives::vstaging::CoretimeParams; const LOG_TARGET: &str = "runtime::configuration"; @@ -172,23 +172,7 @@ pub struct HostConfiguration { /// How long to keep code on-chain, in blocks. This should be sufficiently long that disputes /// have concluded. pub code_retention_period: BlockNumber, - /// How many cores are managed by the coretime chain. - pub coretime_cores: u32, - /// The max number of times a claim can time out in availability - pub coretime_max_availability_timeouts: u32, - /// The maximum queue size of the pay as you go module. - pub on_demand_queue_max_size: u32, - /// The target utilization of the spot price queue in percentages. - pub on_demand_target_queue_utilization: Perbill, - /// How quickly the fee rises in reaction to increased utilization. - /// The lower the number the slower the increase. - pub on_demand_fee_variability: Perbill, - /// The minimum amount needed to claim a slot in the spot pricing queue. - pub on_demand_base_fee: Balance, - /// The number of blocks a claim stays in the scheduler's claimqueue before getting cleared. - /// This number should go reasonably higher than the number of blocks in the async backing - /// lookahead. - pub coretime_ttl: BlockNumber, + /// How often parachain groups should be rotated across parachains. /// /// Must be non-zero. @@ -266,6 +250,8 @@ pub struct HostConfiguration { pub node_features: NodeFeatures, /// Params used by approval-voting pub approval_voting_params: ApprovalVotingParams, + /// Core time parameters + pub coretime_params: CoretimeParams, } impl> Default for HostConfiguration { @@ -284,8 +270,6 @@ impl> Default for HostConfiguration> Default for HostConfiguration /// v9-v10: /// v10-11: - const STORAGE_VERSION: StorageVersion = StorageVersion::new(11); + /// v11-12: + const STORAGE_VERSION: StorageVersion = StorageVersion::new(12); #[pallet::pallet] #[pallet::storage_version(STORAGE_VERSION)] @@ -688,7 +669,7 @@ pub mod pallet { pub fn set_on_demand_retries(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.coretime_max_availability_timeouts = new; + config.coretime_params.coretime_max_availability_timeouts = new; }) } @@ -1141,7 +1122,7 @@ pub mod pallet { pub fn set_on_demand_base_fee(origin: OriginFor, new: Balance) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.on_demand_base_fee = new; + config.coretime_params.on_demand_base_fee = new; }) } @@ -1154,7 +1135,7 @@ pub mod pallet { pub fn set_on_demand_fee_variability(origin: OriginFor, new: Perbill) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.on_demand_fee_variability = new; + config.coretime_params.on_demand_fee_variability = new; }) } @@ -1167,7 +1148,7 @@ pub mod pallet { pub fn set_on_demand_queue_max_size(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.on_demand_queue_max_size = new; + config.coretime_params.on_demand_queue_max_size = new; }) } /// Set the on demand (parathreads) fee variability. @@ -1182,7 +1163,7 @@ pub mod pallet { ) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.on_demand_target_queue_utilization = new; + config.coretime_params.on_demand_target_queue_utilization = new; }) } /// Set the on demand (parathreads) ttl in the claimqueue. @@ -1194,7 +1175,7 @@ pub mod pallet { pub fn set_on_demand_ttl(origin: OriginFor, new: BlockNumberFor) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.coretime_ttl = new; + config.coretime_params.coretime_ttl = new; }) } @@ -1252,7 +1233,7 @@ pub mod pallet { /// To be used if authorization is checked otherwise. pub fn set_coretime_cores_unchecked(new: u32) -> DispatchResult { Self::schedule_config_update(|config| { - config.coretime_cores = new; + config.coretime_params.coretime_cores = new; }) } } diff --git a/polkadot/runtime/parachains/src/configuration/migration/v11.rs b/polkadot/runtime/parachains/src/configuration/migration/v11.rs index 6fcd07ef6bc7..fba1b483bad7 100644 --- a/polkadot/runtime/parachains/src/configuration/migration/v11.rs +++ b/polkadot/runtime/parachains/src/configuration/migration/v11.rs @@ -396,7 +396,7 @@ mod tests { assert_eq!(v10.hrmp_channel_max_message_size , v11.hrmp_channel_max_message_size); assert_eq!(v10.code_retention_period , v11.code_retention_period); assert_eq!(v10.coretime_cores , v11.coretime_cores); - assert_eq!(v10.coretime_max_availability_timeouts, v11.coretime_max_availability_timeouts); + assert_eq!(v10.on_demand_retries , v11.on_demand_retries); assert_eq!(v10.group_rotation_frequency , v11.group_rotation_frequency); assert_eq!(v10.paras_availability_period , v11.paras_availability_period); assert_eq!(v10.scheduling_lookahead , v11.scheduling_lookahead); diff --git a/polkadot/runtime/parachains/src/configuration/migration/v12.rs b/polkadot/runtime/parachains/src/configuration/migration/v12.rs index 58c933965234..57abfa0c2bb7 100644 --- a/polkadot/runtime/parachains/src/configuration/migration/v12.rs +++ b/polkadot/runtime/parachains/src/configuration/migration/v12.rs @@ -23,6 +23,7 @@ use frame_support::{ traits::{Defensive, OnRuntimeUpgrade}, }; use frame_system::pallet_prelude::BlockNumberFor; +use primitives::vstaging::CoretimeParams; use sp_core::Get; use sp_staking::SessionIndex; @@ -125,8 +126,6 @@ fn migrate_to_v12() -> Weight { hrmp_max_parachain_outbound_channels : pre.hrmp_max_parachain_outbound_channels, hrmp_channel_max_message_size : pre.hrmp_channel_max_message_size, code_retention_period : pre.code_retention_period, - coretime_cores : pre.coretime_cores, - coretime_max_availability_timeouts : pre.on_demand_retries, group_rotation_frequency : pre.group_rotation_frequency, paras_availability_period : pre.paras_availability_period, scheduling_lookahead : pre.scheduling_lookahead, @@ -143,14 +142,18 @@ fn migrate_to_v12() -> Weight { minimum_validation_upgrade_delay : pre.minimum_validation_upgrade_delay, async_backing_params : pre.async_backing_params, executor_params : pre.executor_params, - on_demand_queue_max_size : pre.on_demand_queue_max_size, - on_demand_base_fee : pre.on_demand_base_fee, - on_demand_fee_variability : pre.on_demand_fee_variability, - on_demand_target_queue_utilization : pre.on_demand_target_queue_utilization, - coretime_ttl : pre.on_demand_ttl, minimum_backing_votes : pre.minimum_backing_votes, node_features : pre.node_features, approval_voting_params : pre.approval_voting_params, + coretime_params: CoretimeParams { + coretime_cores : pre.coretime_cores, + coretime_max_availability_timeouts : pre.on_demand_retries, + on_demand_queue_max_size : pre.on_demand_queue_max_size, + on_demand_target_queue_utilization : pre.on_demand_target_queue_utilization, + on_demand_fee_variability : pre.on_demand_fee_variability, + on_demand_base_fee : pre.on_demand_base_fee, + coretime_ttl : pre.on_demand_ttl, + } } }; @@ -252,7 +255,7 @@ mod tests { new_test_ext(Default::default()).execute_with(|| { // Implant the v10 version in the state. - v11::ActiveConfig::::set(Some(v11)); + v11::ActiveConfig::::set(Some(v11.clone())); v11::PendingConfigs::::set(Some(pending_configs)); migrate_to_v12::(); @@ -285,8 +288,6 @@ mod tests { assert_eq!(v11.hrmp_max_parachain_inbound_channels , v12.hrmp_max_parachain_inbound_channels); assert_eq!(v11.hrmp_channel_max_message_size , v12.hrmp_channel_max_message_size); assert_eq!(v11.code_retention_period , v12.code_retention_period); - assert_eq!(v11.coretime_cores , v12.coretime_cores); - assert_eq!(v11.on_demand_retries , v12.coretime_max_availability_timeouts); assert_eq!(v11.group_rotation_frequency , v12.group_rotation_frequency); assert_eq!(v11.paras_availability_period , v12.paras_availability_period); assert_eq!(v11.scheduling_lookahead , v12.scheduling_lookahead); @@ -304,7 +305,13 @@ mod tests { assert_eq!(v11.async_backing_params.max_candidate_depth , v12.async_backing_params.max_candidate_depth); assert_eq!(v11.executor_params , v12.executor_params); assert_eq!(v11.minimum_backing_votes , v12.minimum_backing_votes); - assert_eq!(v11.on_demand_ttl , v12.coretime_ttl); + assert_eq!(v11.coretime_cores , v12.coretime_params.coretime_cores); + assert_eq!(v11.on_demand_retries , v12.coretime_params.coretime_max_availability_timeouts); + assert_eq!(v11.on_demand_queue_max_size , v12.coretime_params.on_demand_queue_max_size); + assert_eq!(v11.on_demand_target_queue_utilization , v12.coretime_params.on_demand_target_queue_utilization); + assert_eq!(v11.on_demand_fee_variability , v12.coretime_params.on_demand_fee_variability); + assert_eq!(v11.on_demand_base_fee , v12.coretime_params.on_demand_base_fee); + assert_eq!(v11.on_demand_ttl , v12.coretime_params.coretime_ttl); }; // ; makes this a statement. `rustfmt::skip` cannot be put on an expression. } }); diff --git a/polkadot/runtime/parachains/src/configuration/tests.rs b/polkadot/runtime/parachains/src/configuration/tests.rs index 0a6cfa395a92..f8b6dcf257e7 100644 --- a/polkadot/runtime/parachains/src/configuration/tests.rs +++ b/polkadot/runtime/parachains/src/configuration/tests.rs @@ -283,8 +283,6 @@ fn setting_pending_config_members() { max_code_size: 100_000, max_pov_size: 1024, max_head_data_size: 1_000, - coretime_cores: 2, - coretime_max_availability_timeouts: 5, group_rotation_frequency: 20, paras_availability_period: 10, scheduling_lookahead: 3, @@ -314,13 +312,17 @@ fn setting_pending_config_members() { minimum_validation_upgrade_delay: 20, executor_params: Default::default(), approval_voting_params: ApprovalVotingParams { max_approval_coalesce_count: 1 }, - on_demand_queue_max_size: 10_000u32, - on_demand_base_fee: 10_000_000u128, - on_demand_fee_variability: Perbill::from_percent(3), - on_demand_target_queue_utilization: Perbill::from_percent(25), - coretime_ttl: 5u32, minimum_backing_votes: 5, node_features: bitvec![u8, Lsb0; 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1], + coretime_params: CoretimeParams { + coretime_cores: 2, + coretime_max_availability_timeouts: 5, + on_demand_queue_max_size: 10_000u32, + on_demand_base_fee: 10_000_000u128, + on_demand_fee_variability: Perbill::from_percent(3), + on_demand_target_queue_utilization: Perbill::from_percent(25), + coretime_ttl: 5u32, + }, }; Configuration::set_validation_upgrade_cooldown( @@ -342,11 +344,14 @@ fn setting_pending_config_members() { Configuration::set_max_pov_size(RuntimeOrigin::root(), new_config.max_pov_size).unwrap(); Configuration::set_max_head_data_size(RuntimeOrigin::root(), new_config.max_head_data_size) .unwrap(); - Configuration::set_coretime_cores(RuntimeOrigin::root(), new_config.coretime_cores) - .unwrap(); + Configuration::set_coretime_cores( + RuntimeOrigin::root(), + new_config.coretime_params.coretime_cores, + ) + .unwrap(); Configuration::set_on_demand_retries( RuntimeOrigin::root(), - new_config.coretime_max_availability_timeouts, + new_config.coretime_params.coretime_max_availability_timeouts, ) .unwrap(); Configuration::set_group_rotation_frequency( diff --git a/polkadot/runtime/parachains/src/coretime/migration.rs b/polkadot/runtime/parachains/src/coretime/migration.rs index e64d3fbd6a9e..363dcba24ceb 100644 --- a/polkadot/runtime/parachains/src/coretime/migration.rs +++ b/polkadot/runtime/parachains/src/coretime/migration.rs @@ -177,7 +177,7 @@ mod v_coretime { let config = >::config(); // coretime_cores was on_demand_cores until now: - for on_demand in 0..config.coretime_cores { + for on_demand in 0..config.coretime_params.coretime_cores { let core = CoreIndex(legacy_count.saturating_add(on_demand as _)); let r = assigner_coretime::Pallet::::assign_core( core, @@ -189,9 +189,9 @@ mod v_coretime { log::error!("Creating assignment for existing on-demand core, failed: {:?}", err); } } - let total_cores = config.coretime_cores + legacy_count; + let total_cores = config.coretime_params.coretime_cores + legacy_count; configuration::ActiveConfig::::mutate(|c| { - c.coretime_cores = total_cores; + c.coretime_params.coretime_cores = total_cores; }); if let Err(err) = migrate_send_assignments_to_coretime_chain::() { @@ -200,7 +200,9 @@ mod v_coretime { let single_weight = ::WeightInfo::assign_core(1); single_weight - .saturating_mul(u64::from(legacy_count.saturating_add(config.coretime_cores))) + .saturating_mul(u64::from( + legacy_count.saturating_add(config.coretime_params.coretime_cores), + )) // Second read from sending assignments to the coretime chain. .saturating_add(T::DbWeight::get().reads_writes(2, 1)) } @@ -244,7 +246,10 @@ mod v_coretime { Some(mk_coretime_call(crate::coretime::CoretimeCalls::SetLease(p.into(), time_slice))) }); - let core_count: u16 = configuration::Pallet::::config().coretime_cores.saturated_into(); + let core_count: u16 = configuration::Pallet::::config() + .coretime_params + .coretime_cores + .saturated_into(); let set_core_count = iter::once(mk_coretime_call( crate::coretime::CoretimeCalls::NotifyCoreCount(core_count), )); diff --git a/polkadot/runtime/parachains/src/coretime/mod.rs b/polkadot/runtime/parachains/src/coretime/mod.rs index 531f5c2e4e47..c422c385c0d0 100644 --- a/polkadot/runtime/parachains/src/coretime/mod.rs +++ b/polkadot/runtime/parachains/src/coretime/mod.rs @@ -214,8 +214,8 @@ impl Pallet { } pub fn initializer_on_new_session(notification: &SessionChangeNotification>) { - let old_core_count = notification.prev_config.coretime_cores; - let new_core_count = notification.new_config.coretime_cores; + let old_core_count = notification.prev_config.coretime_params.coretime_cores; + let new_core_count = notification.new_config.coretime_params.coretime_cores; if new_core_count != old_core_count { let core_count: u16 = new_core_count.saturated_into(); let message = Xcm(vec![ diff --git a/polkadot/runtime/parachains/src/inclusion/tests.rs b/polkadot/runtime/parachains/src/inclusion/tests.rs index 232e65d78ed2..d9256586d4b1 100644 --- a/polkadot/runtime/parachains/src/inclusion/tests.rs +++ b/polkadot/runtime/parachains/src/inclusion/tests.rs @@ -47,7 +47,7 @@ use test_helpers::{dummy_collator, dummy_collator_signature, dummy_validation_co fn default_config() -> HostConfiguration { let mut config = HostConfiguration::default(); - config.coretime_cores = 1; + config.coretime_params.coretime_cores = 1; config.max_code_size = 0b100000; config.max_head_data_size = 0b100000; config.group_rotation_frequency = u32::MAX; @@ -218,7 +218,7 @@ pub(crate) fn run_to_block( } pub(crate) fn expected_bits() -> usize { - Paras::parachains().len() + Configuration::config().coretime_cores as usize + Paras::parachains().len() + Configuration::config().coretime_params.coretime_cores as usize } fn default_bitfield() -> AvailabilityBitfield { diff --git a/polkadot/runtime/parachains/src/scheduler.rs b/polkadot/runtime/parachains/src/scheduler.rs index 8fc84b40f0cc..b3f6fcb78993 100644 --- a/polkadot/runtime/parachains/src/scheduler.rs +++ b/polkadot/runtime/parachains/src/scheduler.rs @@ -352,7 +352,7 @@ impl Pallet { fn drop_expired_claims_from_claimqueue() { let now = >::block_number(); let availability_cores = AvailabilityCores::::get(); - let ttl = >::config().coretime_ttl; + let ttl = >::config().coretime_params.coretime_ttl; ClaimQueue::::mutate(|cq| { for (idx, _) in (0u32..).zip(availability_cores) { @@ -509,8 +509,9 @@ impl Pallet { /// Return the next thing that will be scheduled on this core assuming it is currently /// occupied and the candidate occupying it times out. pub(crate) fn next_up_on_time_out(core: CoreIndex) -> Option { - let max_availability_timeouts = - >::config().coretime_max_availability_timeouts; + let max_availability_timeouts = >::config() + .coretime_params + .coretime_max_availability_timeouts; Self::next_up_on_available(core).or_else(|| { // Or, if none, the claim currently occupying the core, // as it would be put back on the queue after timing out if number of retries is not at @@ -585,8 +586,8 @@ impl Pallet { let n_session_cores = T::AssignmentProvider::session_core_count(); let cq = ClaimQueue::::get(); let config = >::config(); - let max_availability_timeouts = config.coretime_max_availability_timeouts; - let ttl = config.coretime_ttl; + let max_availability_timeouts = config.coretime_params.coretime_max_availability_timeouts; + let ttl = config.coretime_params.coretime_ttl; for core_idx in 0..n_session_cores { let core_idx = CoreIndex::from(core_idx); diff --git a/polkadot/runtime/parachains/src/scheduler/tests.rs b/polkadot/runtime/parachains/src/scheduler/tests.rs index d963d77a8ec0..3ed25fa85cab 100644 --- a/polkadot/runtime/parachains/src/scheduler/tests.rs +++ b/polkadot/runtime/parachains/src/scheduler/tests.rs @@ -18,7 +18,9 @@ use super::*; use frame_support::assert_ok; use keyring::Sr25519Keyring; -use primitives::{BlockNumber, SessionIndex, ValidationCode, ValidatorId}; +use primitives::{ + vstaging::CoretimeParams, BlockNumber, SessionIndex, ValidationCode, ValidatorId, +}; use sp_std::collections::{btree_map::BTreeMap, btree_set::BTreeSet}; use crate::{ @@ -103,7 +105,6 @@ fn run_to_end_of_block( fn default_config() -> HostConfiguration { HostConfiguration { - coretime_cores: 3, group_rotation_frequency: 10, paras_availability_period: 3, scheduling_lookahead: 2, @@ -112,7 +113,11 @@ fn default_config() -> HostConfiguration { // `minimum_validation_upgrade_delay` is greater than `chain_availability_period` and // `thread_availability_period`. minimum_validation_upgrade_delay: 6, - coretime_max_availability_timeouts: 1, + coretime_params: CoretimeParams { + coretime_cores: 3, + coretime_max_availability_timeouts: 1, + ..Default::default() + }, ..Default::default() } } @@ -164,7 +169,7 @@ fn claimqueue_ttl_drop_fn_works() { let mut now = 10; new_test_ext(genesis_config).execute_with(|| { - assert!(config.coretime_ttl == 5); + assert!(config.coretime_params.coretime_ttl == 5); // Register and run to a blockheight where the para is in a valid state. schedule_blank_para(para_id); run_to_block(now, |n| if n == now { Some(Default::default()) } else { None }); @@ -343,7 +348,7 @@ fn fill_claimqueue_fills() { new_test_ext(genesis_config).execute_with(|| { MockAssigner::set_core_count(2); - let coretime_ttl = config.coretime_ttl; + let coretime_ttl = config.coretime_params.coretime_ttl; // Add 3 paras schedule_blank_para(para_a); @@ -479,7 +484,7 @@ fn schedule_schedules_including_just_freed() { // All `core_queue`s should be empty Scheduler::claimqueue() .iter() - .for_each(|(_core_idx, core_queue)| assert!(core_queue.len() == 0)) + .for_each(|(_core_idx, core_queue)| assert_eq!(core_queue.len(), 0)) } // add a couple more para claims - the claim on `b` will go to the 3rd core @@ -746,8 +751,8 @@ fn on_demand_claims_are_pruned_after_timing_out() { let mut config = default_config(); config.scheduling_lookahead = 1; // Need more timeouts for this test - config.coretime_max_availability_timeouts = max_retries; - config.coretime_ttl = BlockNumber::from(5u32); + config.coretime_params.coretime_max_availability_timeouts = max_retries; + config.coretime_params.coretime_ttl = BlockNumber::from(5u32); let genesis_config = genesis_config(&config); let para_a = ParaId::from(1_u32); @@ -1054,7 +1059,7 @@ fn session_change_requires_reschedule_dropping_removed_paras() { new_test_ext(genesis_config).execute_with(|| { // Setting explicit core count MockAssigner::set_core_count(5); - let coretime_ttl = >::config().coretime_ttl; + let coretime_ttl = >::config().coretime_params.coretime_ttl; schedule_blank_para(para_a); schedule_blank_para(para_b); diff --git a/polkadot/runtime/parachains/src/session_info/tests.rs b/polkadot/runtime/parachains/src/session_info/tests.rs index 92a50575deda..34281bc06ce4 100644 --- a/polkadot/runtime/parachains/src/session_info/tests.rs +++ b/polkadot/runtime/parachains/src/session_info/tests.rs @@ -25,7 +25,7 @@ use crate::{ util::take_active_subset, }; use keyring::Sr25519Keyring; -use primitives::{BlockNumber, ValidatorId, ValidatorIndex}; +use primitives::{vstaging::CoretimeParams, BlockNumber, ValidatorId, ValidatorIndex}; fn run_to_block( to: BlockNumber, @@ -62,9 +62,9 @@ fn run_to_block( fn default_config() -> HostConfiguration { HostConfiguration { - coretime_cores: 1, dispute_period: 2, needed_approvals: 3, + coretime_params: CoretimeParams { coretime_cores: 1, ..Default::default() }, ..Default::default() } } From e8d179cdfe569e573477ce92c70b9c777b26dd7f Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Fri, 2 Feb 2024 10:54:18 +0200 Subject: [PATCH 06/40] Remove `coretime_` prefix from config params --- polkadot/runtime/parachains/src/builder.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/polkadot/runtime/parachains/src/builder.rs b/polkadot/runtime/parachains/src/builder.rs index d3461ba7725b..c5e0b0c1db3a 100644 --- a/polkadot/runtime/parachains/src/builder.rs +++ b/polkadot/runtime/parachains/src/builder.rs @@ -679,7 +679,7 @@ impl BenchBuilder { // We are currently in Session 0, so these changes will take effect in Session 2. Self::setup_para_ids(used_cores); configuration::ActiveConfig::::mutate(|c| { - c.coretime_params.coretime_cores = used_cores; + c.coretime_params.cores = used_cores; }); let validator_ids = Self::generate_validator_pairs(self.max_validators()); @@ -710,7 +710,7 @@ impl BenchBuilder { let cores = (0..used_cores) .into_iter() .map(|i| { - let ttl = configuration::Pallet::::config().coretime_params.coretime_ttl; + let ttl = configuration::Pallet::::config().coretime_params.ttl; // Load an assignment into provider so that one is present to pop let assignment = ::AssignmentProvider::get_mock_assignment( CoreIndex(i), @@ -725,7 +725,7 @@ impl BenchBuilder { let cores = (0..used_cores) .into_iter() .map(|i| { - let ttl = configuration::Pallet::::config().coretime_params.coretime_ttl; + let ttl = configuration::Pallet::::config().coretime_params.ttl; // Load an assignment into provider so that one is present to pop let assignment = ::AssignmentProvider::get_mock_assignment( From 135e05755b59e44c68c0a9b6484c2022ec053651 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Fri, 2 Feb 2024 11:00:49 +0200 Subject: [PATCH 07/40] Remove `coretime_` prefix from config params - part 2 --- polkadot/primitives/src/vstaging/mod.rs | 18 +++++++++--------- .../src/assigner_coretime/mock_helpers.rs | 2 +- .../parachains/src/assigner_coretime/mod.rs | 6 +++--- .../src/assigner_on_demand/mock_helpers.rs | 2 +- .../src/assigner_parachains/mock_helpers.rs | 2 +- .../runtime/parachains/src/configuration.rs | 6 +++--- .../src/configuration/migration/v12.rs | 12 ++++++------ .../parachains/src/configuration/tests.rs | 15 ++++++--------- .../parachains/src/coretime/migration.rs | 16 ++++++---------- .../runtime/parachains/src/coretime/mod.rs | 4 ++-- .../runtime/parachains/src/inclusion/tests.rs | 4 ++-- polkadot/runtime/parachains/src/scheduler.rs | 11 +++++------ .../runtime/parachains/src/scheduler/tests.rs | 14 +++++++------- .../parachains/src/session_info/tests.rs | 2 +- 14 files changed, 53 insertions(+), 61 deletions(-) diff --git a/polkadot/primitives/src/vstaging/mod.rs b/polkadot/primitives/src/vstaging/mod.rs index 4ca3c472722f..85cc65cab33e 100644 --- a/polkadot/primitives/src/vstaging/mod.rs +++ b/polkadot/primitives/src/vstaging/mod.rs @@ -65,9 +65,13 @@ impl Default for ApprovalVotingParams { )] pub struct CoretimeParams { /// How many cores are managed by the coretime chain. - pub coretime_cores: u32, + pub cores: u32, /// The max number of times a claim can time out in availability - pub coretime_max_availability_timeouts: u32, + pub max_availability_timeouts: u32, + /// The number of blocks a claim stays in the scheduler's claimqueue before getting cleared. + /// This number should go reasonably higher than the number of blocks in the async backing + /// lookahead. + pub ttl: BlockNumber, /// The maximum queue size of the pay as you go module. pub on_demand_queue_max_size: u32, /// The target utilization of the spot price queue in percentages. @@ -77,22 +81,18 @@ pub struct CoretimeParams { pub on_demand_fee_variability: Perbill, /// The minimum amount needed to claim a slot in the spot pricing queue. pub on_demand_base_fee: Balance, - /// The number of blocks a claim stays in the scheduler's claimqueue before getting cleared. - /// This number should go reasonably higher than the number of blocks in the async backing - /// lookahead. - pub coretime_ttl: BlockNumber, } impl> Default for CoretimeParams { fn default() -> Self { Self { - coretime_cores: Default::default(), - coretime_max_availability_timeouts: Default::default(), + cores: Default::default(), + max_availability_timeouts: Default::default(), + ttl: 5u32.into(), on_demand_queue_max_size: ON_DEMAND_DEFAULT_QUEUE_MAX_SIZE, on_demand_target_queue_utilization: Perbill::from_percent(25), on_demand_fee_variability: Perbill::from_percent(3), on_demand_base_fee: 10_000_000u128, - coretime_ttl: 5u32.into(), } } } diff --git a/polkadot/runtime/parachains/src/assigner_coretime/mock_helpers.rs b/polkadot/runtime/parachains/src/assigner_coretime/mock_helpers.rs index ef7e66662684..cf97c3e913e3 100644 --- a/polkadot/runtime/parachains/src/assigner_coretime/mock_helpers.rs +++ b/polkadot/runtime/parachains/src/assigner_coretime/mock_helpers.rs @@ -64,7 +64,7 @@ impl GenesisConfigBuilder { pub(super) fn build(self) -> MockGenesisConfig { let mut genesis = default_genesis_config(); let config = &mut genesis.configuration.config; - config.coretime_params.coretime_cores = self.on_demand_cores; + config.coretime_params.cores = self.on_demand_cores; config.coretime_params.on_demand_base_fee = self.on_demand_base_fee; config.coretime_params.on_demand_fee_variability = self.on_demand_fee_variability; config.coretime_params.on_demand_queue_max_size = self.on_demand_max_queue_size; diff --git a/polkadot/runtime/parachains/src/assigner_coretime/mod.rs b/polkadot/runtime/parachains/src/assigner_coretime/mod.rs index 7e998243c717..b0a9d60f8e6b 100644 --- a/polkadot/runtime/parachains/src/assigner_coretime/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_coretime/mod.rs @@ -325,7 +325,7 @@ impl AssignmentProvider> for Pallet { fn session_core_count() -> u32 { let config = >::config(); - config.coretime_params.coretime_cores + config.coretime_params.cores } } @@ -474,8 +474,8 @@ impl AssignCoretime for Pallet { // Add a new core and assign the para to it. let mut config = >::config(); - let core = config.coretime_params.coretime_cores; - config.coretime_params.coretime_cores.saturating_inc(); + let core = config.coretime_params.cores; + config.coretime_params.cores.saturating_inc(); // `assign_coretime` is only called at genesis or by root, so setting the active // config here is fine. diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mock_helpers.rs b/polkadot/runtime/parachains/src/assigner_on_demand/mock_helpers.rs index 74e86a49b946..5653c5f3d6b6 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mock_helpers.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/mock_helpers.rs @@ -63,7 +63,7 @@ impl GenesisConfigBuilder { pub(super) fn build(self) -> MockGenesisConfig { let mut genesis = default_genesis_config(); let config = &mut genesis.configuration.config; - config.coretime_params.coretime_cores = self.on_demand_cores; + config.coretime_params.cores = self.on_demand_cores; config.coretime_params.on_demand_base_fee = self.on_demand_base_fee; config.coretime_params.on_demand_fee_variability = self.on_demand_fee_variability; config.coretime_params.on_demand_queue_max_size = self.on_demand_max_queue_size; diff --git a/polkadot/runtime/parachains/src/assigner_parachains/mock_helpers.rs b/polkadot/runtime/parachains/src/assigner_parachains/mock_helpers.rs index adde113d1876..f3b521c6a491 100644 --- a/polkadot/runtime/parachains/src/assigner_parachains/mock_helpers.rs +++ b/polkadot/runtime/parachains/src/assigner_parachains/mock_helpers.rs @@ -60,7 +60,7 @@ impl GenesisConfigBuilder { pub(super) fn build(self) -> MockGenesisConfig { let mut genesis = default_genesis_config(); let config = &mut genesis.configuration.config; - config.coretime_params.coretime_cores = self.on_demand_cores; + config.coretime_params.cores = self.on_demand_cores; config.coretime_params.on_demand_base_fee = self.on_demand_base_fee; config.coretime_params.on_demand_fee_variability = self.on_demand_fee_variability; config.coretime_params.on_demand_queue_max_size = self.on_demand_max_queue_size; diff --git a/polkadot/runtime/parachains/src/configuration.rs b/polkadot/runtime/parachains/src/configuration.rs index d626c981e2b0..3facf7487ed4 100644 --- a/polkadot/runtime/parachains/src/configuration.rs +++ b/polkadot/runtime/parachains/src/configuration.rs @@ -669,7 +669,7 @@ pub mod pallet { pub fn set_on_demand_retries(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.coretime_params.coretime_max_availability_timeouts = new; + config.coretime_params.max_availability_timeouts = new; }) } @@ -1175,7 +1175,7 @@ pub mod pallet { pub fn set_on_demand_ttl(origin: OriginFor, new: BlockNumberFor) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.coretime_params.coretime_ttl = new; + config.coretime_params.ttl = new; }) } @@ -1233,7 +1233,7 @@ pub mod pallet { /// To be used if authorization is checked otherwise. pub fn set_coretime_cores_unchecked(new: u32) -> DispatchResult { Self::schedule_config_update(|config| { - config.coretime_params.coretime_cores = new; + config.coretime_params.cores = new; }) } } diff --git a/polkadot/runtime/parachains/src/configuration/migration/v12.rs b/polkadot/runtime/parachains/src/configuration/migration/v12.rs index 57abfa0c2bb7..454aa7c27842 100644 --- a/polkadot/runtime/parachains/src/configuration/migration/v12.rs +++ b/polkadot/runtime/parachains/src/configuration/migration/v12.rs @@ -146,13 +146,13 @@ fn migrate_to_v12() -> Weight { node_features : pre.node_features, approval_voting_params : pre.approval_voting_params, coretime_params: CoretimeParams { - coretime_cores : pre.coretime_cores, - coretime_max_availability_timeouts : pre.on_demand_retries, + cores: pre.coretime_cores, + max_availability_timeouts: pre.on_demand_retries, on_demand_queue_max_size : pre.on_demand_queue_max_size, on_demand_target_queue_utilization : pre.on_demand_target_queue_utilization, on_demand_fee_variability : pre.on_demand_fee_variability, on_demand_base_fee : pre.on_demand_base_fee, - coretime_ttl : pre.on_demand_ttl, + ttl: pre.on_demand_ttl, } } }; @@ -305,13 +305,13 @@ mod tests { assert_eq!(v11.async_backing_params.max_candidate_depth , v12.async_backing_params.max_candidate_depth); assert_eq!(v11.executor_params , v12.executor_params); assert_eq!(v11.minimum_backing_votes , v12.minimum_backing_votes); - assert_eq!(v11.coretime_cores , v12.coretime_params.coretime_cores); - assert_eq!(v11.on_demand_retries , v12.coretime_params.coretime_max_availability_timeouts); + assert_eq!(v11.coretime_cores , v12.coretime_params.cores); + assert_eq!(v11.on_demand_retries , v12.coretime_params.max_availability_timeouts); assert_eq!(v11.on_demand_queue_max_size , v12.coretime_params.on_demand_queue_max_size); assert_eq!(v11.on_demand_target_queue_utilization , v12.coretime_params.on_demand_target_queue_utilization); assert_eq!(v11.on_demand_fee_variability , v12.coretime_params.on_demand_fee_variability); assert_eq!(v11.on_demand_base_fee , v12.coretime_params.on_demand_base_fee); - assert_eq!(v11.on_demand_ttl , v12.coretime_params.coretime_ttl); + assert_eq!(v11.on_demand_ttl , v12.coretime_params.ttl); }; // ; makes this a statement. `rustfmt::skip` cannot be put on an expression. } }); diff --git a/polkadot/runtime/parachains/src/configuration/tests.rs b/polkadot/runtime/parachains/src/configuration/tests.rs index f8b6dcf257e7..b3871d297f6c 100644 --- a/polkadot/runtime/parachains/src/configuration/tests.rs +++ b/polkadot/runtime/parachains/src/configuration/tests.rs @@ -315,13 +315,13 @@ fn setting_pending_config_members() { minimum_backing_votes: 5, node_features: bitvec![u8, Lsb0; 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1], coretime_params: CoretimeParams { - coretime_cores: 2, - coretime_max_availability_timeouts: 5, + cores: 2, + max_availability_timeouts: 5, on_demand_queue_max_size: 10_000u32, on_demand_base_fee: 10_000_000u128, on_demand_fee_variability: Perbill::from_percent(3), on_demand_target_queue_utilization: Perbill::from_percent(25), - coretime_ttl: 5u32, + ttl: 5u32, }, }; @@ -344,14 +344,11 @@ fn setting_pending_config_members() { Configuration::set_max_pov_size(RuntimeOrigin::root(), new_config.max_pov_size).unwrap(); Configuration::set_max_head_data_size(RuntimeOrigin::root(), new_config.max_head_data_size) .unwrap(); - Configuration::set_coretime_cores( - RuntimeOrigin::root(), - new_config.coretime_params.coretime_cores, - ) - .unwrap(); + Configuration::set_coretime_cores(RuntimeOrigin::root(), new_config.coretime_params.cores) + .unwrap(); Configuration::set_on_demand_retries( RuntimeOrigin::root(), - new_config.coretime_params.coretime_max_availability_timeouts, + new_config.coretime_params.max_availability_timeouts, ) .unwrap(); Configuration::set_group_rotation_frequency( diff --git a/polkadot/runtime/parachains/src/coretime/migration.rs b/polkadot/runtime/parachains/src/coretime/migration.rs index 363dcba24ceb..b89786bb1ca8 100644 --- a/polkadot/runtime/parachains/src/coretime/migration.rs +++ b/polkadot/runtime/parachains/src/coretime/migration.rs @@ -177,7 +177,7 @@ mod v_coretime { let config = >::config(); // coretime_cores was on_demand_cores until now: - for on_demand in 0..config.coretime_params.coretime_cores { + for on_demand in 0..config.coretime_params.cores { let core = CoreIndex(legacy_count.saturating_add(on_demand as _)); let r = assigner_coretime::Pallet::::assign_core( core, @@ -189,9 +189,9 @@ mod v_coretime { log::error!("Creating assignment for existing on-demand core, failed: {:?}", err); } } - let total_cores = config.coretime_params.coretime_cores + legacy_count; + let total_cores = config.coretime_params.cores + legacy_count; configuration::ActiveConfig::::mutate(|c| { - c.coretime_params.coretime_cores = total_cores; + c.coretime_params.cores = total_cores; }); if let Err(err) = migrate_send_assignments_to_coretime_chain::() { @@ -200,9 +200,7 @@ mod v_coretime { let single_weight = ::WeightInfo::assign_core(1); single_weight - .saturating_mul(u64::from( - legacy_count.saturating_add(config.coretime_params.coretime_cores), - )) + .saturating_mul(u64::from(legacy_count.saturating_add(config.coretime_params.cores))) // Second read from sending assignments to the coretime chain. .saturating_add(T::DbWeight::get().reads_writes(2, 1)) } @@ -246,10 +244,8 @@ mod v_coretime { Some(mk_coretime_call(crate::coretime::CoretimeCalls::SetLease(p.into(), time_slice))) }); - let core_count: u16 = configuration::Pallet::::config() - .coretime_params - .coretime_cores - .saturated_into(); + let core_count: u16 = + configuration::Pallet::::config().coretime_params.cores.saturated_into(); let set_core_count = iter::once(mk_coretime_call( crate::coretime::CoretimeCalls::NotifyCoreCount(core_count), )); diff --git a/polkadot/runtime/parachains/src/coretime/mod.rs b/polkadot/runtime/parachains/src/coretime/mod.rs index c422c385c0d0..96842c770365 100644 --- a/polkadot/runtime/parachains/src/coretime/mod.rs +++ b/polkadot/runtime/parachains/src/coretime/mod.rs @@ -214,8 +214,8 @@ impl Pallet { } pub fn initializer_on_new_session(notification: &SessionChangeNotification>) { - let old_core_count = notification.prev_config.coretime_params.coretime_cores; - let new_core_count = notification.new_config.coretime_params.coretime_cores; + let old_core_count = notification.prev_config.coretime_params.cores; + let new_core_count = notification.new_config.coretime_params.cores; if new_core_count != old_core_count { let core_count: u16 = new_core_count.saturated_into(); let message = Xcm(vec![ diff --git a/polkadot/runtime/parachains/src/inclusion/tests.rs b/polkadot/runtime/parachains/src/inclusion/tests.rs index d9256586d4b1..c5bfd45f061a 100644 --- a/polkadot/runtime/parachains/src/inclusion/tests.rs +++ b/polkadot/runtime/parachains/src/inclusion/tests.rs @@ -47,7 +47,7 @@ use test_helpers::{dummy_collator, dummy_collator_signature, dummy_validation_co fn default_config() -> HostConfiguration { let mut config = HostConfiguration::default(); - config.coretime_params.coretime_cores = 1; + config.coretime_params.cores = 1; config.max_code_size = 0b100000; config.max_head_data_size = 0b100000; config.group_rotation_frequency = u32::MAX; @@ -218,7 +218,7 @@ pub(crate) fn run_to_block( } pub(crate) fn expected_bits() -> usize { - Paras::parachains().len() + Configuration::config().coretime_params.coretime_cores as usize + Paras::parachains().len() + Configuration::config().coretime_params.cores as usize } fn default_bitfield() -> AvailabilityBitfield { diff --git a/polkadot/runtime/parachains/src/scheduler.rs b/polkadot/runtime/parachains/src/scheduler.rs index b3f6fcb78993..dc2335f02ad4 100644 --- a/polkadot/runtime/parachains/src/scheduler.rs +++ b/polkadot/runtime/parachains/src/scheduler.rs @@ -352,7 +352,7 @@ impl Pallet { fn drop_expired_claims_from_claimqueue() { let now = >::block_number(); let availability_cores = AvailabilityCores::::get(); - let ttl = >::config().coretime_params.coretime_ttl; + let ttl = >::config().coretime_params.ttl; ClaimQueue::::mutate(|cq| { for (idx, _) in (0u32..).zip(availability_cores) { @@ -509,9 +509,8 @@ impl Pallet { /// Return the next thing that will be scheduled on this core assuming it is currently /// occupied and the candidate occupying it times out. pub(crate) fn next_up_on_time_out(core: CoreIndex) -> Option { - let max_availability_timeouts = >::config() - .coretime_params - .coretime_max_availability_timeouts; + let max_availability_timeouts = + >::config().coretime_params.max_availability_timeouts; Self::next_up_on_available(core).or_else(|| { // Or, if none, the claim currently occupying the core, // as it would be put back on the queue after timing out if number of retries is not at @@ -586,8 +585,8 @@ impl Pallet { let n_session_cores = T::AssignmentProvider::session_core_count(); let cq = ClaimQueue::::get(); let config = >::config(); - let max_availability_timeouts = config.coretime_params.coretime_max_availability_timeouts; - let ttl = config.coretime_params.coretime_ttl; + let max_availability_timeouts = config.coretime_params.max_availability_timeouts; + let ttl = config.coretime_params.ttl; for core_idx in 0..n_session_cores { let core_idx = CoreIndex::from(core_idx); diff --git a/polkadot/runtime/parachains/src/scheduler/tests.rs b/polkadot/runtime/parachains/src/scheduler/tests.rs index 3ed25fa85cab..954fb51c4d6a 100644 --- a/polkadot/runtime/parachains/src/scheduler/tests.rs +++ b/polkadot/runtime/parachains/src/scheduler/tests.rs @@ -114,8 +114,8 @@ fn default_config() -> HostConfiguration { // `thread_availability_period`. minimum_validation_upgrade_delay: 6, coretime_params: CoretimeParams { - coretime_cores: 3, - coretime_max_availability_timeouts: 1, + cores: 3, + max_availability_timeouts: 1, ..Default::default() }, ..Default::default() @@ -169,7 +169,7 @@ fn claimqueue_ttl_drop_fn_works() { let mut now = 10; new_test_ext(genesis_config).execute_with(|| { - assert!(config.coretime_params.coretime_ttl == 5); + assert!(config.coretime_params.ttl == 5); // Register and run to a blockheight where the para is in a valid state. schedule_blank_para(para_id); run_to_block(now, |n| if n == now { Some(Default::default()) } else { None }); @@ -348,7 +348,7 @@ fn fill_claimqueue_fills() { new_test_ext(genesis_config).execute_with(|| { MockAssigner::set_core_count(2); - let coretime_ttl = config.coretime_params.coretime_ttl; + let coretime_ttl = config.coretime_params.ttl; // Add 3 paras schedule_blank_para(para_a); @@ -751,8 +751,8 @@ fn on_demand_claims_are_pruned_after_timing_out() { let mut config = default_config(); config.scheduling_lookahead = 1; // Need more timeouts for this test - config.coretime_params.coretime_max_availability_timeouts = max_retries; - config.coretime_params.coretime_ttl = BlockNumber::from(5u32); + config.coretime_params.max_availability_timeouts = max_retries; + config.coretime_params.ttl = BlockNumber::from(5u32); let genesis_config = genesis_config(&config); let para_a = ParaId::from(1_u32); @@ -1059,7 +1059,7 @@ fn session_change_requires_reschedule_dropping_removed_paras() { new_test_ext(genesis_config).execute_with(|| { // Setting explicit core count MockAssigner::set_core_count(5); - let coretime_ttl = >::config().coretime_params.coretime_ttl; + let coretime_ttl = >::config().coretime_params.ttl; schedule_blank_para(para_a); schedule_blank_para(para_b); diff --git a/polkadot/runtime/parachains/src/session_info/tests.rs b/polkadot/runtime/parachains/src/session_info/tests.rs index 34281bc06ce4..764c80456619 100644 --- a/polkadot/runtime/parachains/src/session_info/tests.rs +++ b/polkadot/runtime/parachains/src/session_info/tests.rs @@ -64,7 +64,7 @@ fn default_config() -> HostConfiguration { HostConfiguration { dispute_period: 2, needed_approvals: 3, - coretime_params: CoretimeParams { coretime_cores: 1, ..Default::default() }, + coretime_params: CoretimeParams { cores: 1, ..Default::default() }, ..Default::default() } } From 8f8863494b49dac86f1acbca71595c2541b433e5 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Fri, 2 Feb 2024 13:38:57 +0200 Subject: [PATCH 08/40] Remove `coretime_` prefix from config params - part 3 --- .../runtime/parachains/src/assigner_on_demand/benchmarking.rs | 2 +- polkadot/runtime/parachains/src/coretime/migration.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/benchmarking.rs b/polkadot/runtime/parachains/src/assigner_on_demand/benchmarking.rs index 5a6060cd2b4e..e5bd7ef0f21b 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/benchmarking.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/benchmarking.rs @@ -43,7 +43,7 @@ where { ParasShared::::set_session_index(SESSION_INDEX); let mut config = HostConfiguration::default(); - config.coretime_cores = 1; + config.coretime_params.cores = 1; ConfigurationPallet::::force_set_active_config(config); let mut parachains = ParachainsCache::new(); ParasPallet::::initialize_para_now( diff --git a/polkadot/runtime/parachains/src/coretime/migration.rs b/polkadot/runtime/parachains/src/coretime/migration.rs index b89786bb1ca8..bf6cd804d29e 100644 --- a/polkadot/runtime/parachains/src/coretime/migration.rs +++ b/polkadot/runtime/parachains/src/coretime/migration.rs @@ -114,7 +114,7 @@ mod v_coretime { let legacy_paras = paras::Parachains::::get(); let config = >::config(); - let total_core_count = config.coretime_cores + legacy_paras.len() as u32; + let total_core_count = config.coretime_params.cores + legacy_paras.len() as u32; let dmp_queue_size = crate::dmp::Pallet::::dmq_contents(T::BrokerId::get().into()).len() as u32; From dd3a56c98ad50ac42b4b4bda1d539c9a795706c3 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Fri, 2 Feb 2024 15:53:41 +0200 Subject: [PATCH 09/40] Remove `coretime_` prefix from config params - part 4Remove `coretime_` prefix from config params - part 4 --- polkadot/runtime/parachains/src/configuration/migration/v12.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/polkadot/runtime/parachains/src/configuration/migration/v12.rs b/polkadot/runtime/parachains/src/configuration/migration/v12.rs index 454aa7c27842..add18e13e7b4 100644 --- a/polkadot/runtime/parachains/src/configuration/migration/v12.rs +++ b/polkadot/runtime/parachains/src/configuration/migration/v12.rs @@ -26,6 +26,7 @@ use frame_system::pallet_prelude::BlockNumberFor; use primitives::vstaging::CoretimeParams; use sp_core::Get; use sp_staking::SessionIndex; +use sp_std::vec::Vec; type V12HostConfiguration = configuration::HostConfiguration; mod v11 { From 743abe7e17ddc41a5bd5c0aa657b1284de7513db Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Mon, 5 Feb 2024 10:25:54 +0200 Subject: [PATCH 10/40] Revert "Remove `coretime_` prefix from config params - part 4Remove `coretime_` prefix from config params - part 4" This reverts commit dd3a56c98ad50ac42b4b4bda1d539c9a795706c3. --- polkadot/runtime/parachains/src/configuration/migration/v12.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/polkadot/runtime/parachains/src/configuration/migration/v12.rs b/polkadot/runtime/parachains/src/configuration/migration/v12.rs index add18e13e7b4..454aa7c27842 100644 --- a/polkadot/runtime/parachains/src/configuration/migration/v12.rs +++ b/polkadot/runtime/parachains/src/configuration/migration/v12.rs @@ -26,7 +26,6 @@ use frame_system::pallet_prelude::BlockNumberFor; use primitives::vstaging::CoretimeParams; use sp_core::Get; use sp_staking::SessionIndex; -use sp_std::vec::Vec; type V12HostConfiguration = configuration::HostConfiguration; mod v11 { From a2ddeabf651c36b016b757451b97496e9aee3453 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Mon, 5 Feb 2024 10:26:01 +0200 Subject: [PATCH 11/40] Revert "Remove `coretime_` prefix from config params - part 3" This reverts commit 8f8863494b49dac86f1acbca71595c2541b433e5. --- .../runtime/parachains/src/assigner_on_demand/benchmarking.rs | 2 +- polkadot/runtime/parachains/src/coretime/migration.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/benchmarking.rs b/polkadot/runtime/parachains/src/assigner_on_demand/benchmarking.rs index e5bd7ef0f21b..5a6060cd2b4e 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/benchmarking.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/benchmarking.rs @@ -43,7 +43,7 @@ where { ParasShared::::set_session_index(SESSION_INDEX); let mut config = HostConfiguration::default(); - config.coretime_params.cores = 1; + config.coretime_cores = 1; ConfigurationPallet::::force_set_active_config(config); let mut parachains = ParachainsCache::new(); ParasPallet::::initialize_para_now( diff --git a/polkadot/runtime/parachains/src/coretime/migration.rs b/polkadot/runtime/parachains/src/coretime/migration.rs index bf6cd804d29e..b89786bb1ca8 100644 --- a/polkadot/runtime/parachains/src/coretime/migration.rs +++ b/polkadot/runtime/parachains/src/coretime/migration.rs @@ -114,7 +114,7 @@ mod v_coretime { let legacy_paras = paras::Parachains::::get(); let config = >::config(); - let total_core_count = config.coretime_params.cores + legacy_paras.len() as u32; + let total_core_count = config.coretime_cores + legacy_paras.len() as u32; let dmp_queue_size = crate::dmp::Pallet::::dmq_contents(T::BrokerId::get().into()).len() as u32; From 79d637cdfdc4c22a549b5b561d25ff0c748e3640 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Mon, 5 Feb 2024 10:26:09 +0200 Subject: [PATCH 12/40] Revert "Remove `coretime_` prefix from config params - part 2" This reverts commit 135e05755b59e44c68c0a9b6484c2022ec053651. --- polkadot/primitives/src/vstaging/mod.rs | 18 +++++++++--------- .../src/assigner_coretime/mock_helpers.rs | 2 +- .../parachains/src/assigner_coretime/mod.rs | 6 +++--- .../src/assigner_on_demand/mock_helpers.rs | 2 +- .../src/assigner_parachains/mock_helpers.rs | 2 +- .../runtime/parachains/src/configuration.rs | 6 +++--- .../src/configuration/migration/v12.rs | 12 ++++++------ .../parachains/src/configuration/tests.rs | 15 +++++++++------ .../parachains/src/coretime/migration.rs | 16 ++++++++++------ .../runtime/parachains/src/coretime/mod.rs | 4 ++-- .../runtime/parachains/src/inclusion/tests.rs | 4 ++-- polkadot/runtime/parachains/src/scheduler.rs | 11 ++++++----- .../runtime/parachains/src/scheduler/tests.rs | 14 +++++++------- .../parachains/src/session_info/tests.rs | 2 +- 14 files changed, 61 insertions(+), 53 deletions(-) diff --git a/polkadot/primitives/src/vstaging/mod.rs b/polkadot/primitives/src/vstaging/mod.rs index 85cc65cab33e..4ca3c472722f 100644 --- a/polkadot/primitives/src/vstaging/mod.rs +++ b/polkadot/primitives/src/vstaging/mod.rs @@ -65,13 +65,9 @@ impl Default for ApprovalVotingParams { )] pub struct CoretimeParams { /// How many cores are managed by the coretime chain. - pub cores: u32, + pub coretime_cores: u32, /// The max number of times a claim can time out in availability - pub max_availability_timeouts: u32, - /// The number of blocks a claim stays in the scheduler's claimqueue before getting cleared. - /// This number should go reasonably higher than the number of blocks in the async backing - /// lookahead. - pub ttl: BlockNumber, + pub coretime_max_availability_timeouts: u32, /// The maximum queue size of the pay as you go module. pub on_demand_queue_max_size: u32, /// The target utilization of the spot price queue in percentages. @@ -81,18 +77,22 @@ pub struct CoretimeParams { pub on_demand_fee_variability: Perbill, /// The minimum amount needed to claim a slot in the spot pricing queue. pub on_demand_base_fee: Balance, + /// The number of blocks a claim stays in the scheduler's claimqueue before getting cleared. + /// This number should go reasonably higher than the number of blocks in the async backing + /// lookahead. + pub coretime_ttl: BlockNumber, } impl> Default for CoretimeParams { fn default() -> Self { Self { - cores: Default::default(), - max_availability_timeouts: Default::default(), - ttl: 5u32.into(), + coretime_cores: Default::default(), + coretime_max_availability_timeouts: Default::default(), on_demand_queue_max_size: ON_DEMAND_DEFAULT_QUEUE_MAX_SIZE, on_demand_target_queue_utilization: Perbill::from_percent(25), on_demand_fee_variability: Perbill::from_percent(3), on_demand_base_fee: 10_000_000u128, + coretime_ttl: 5u32.into(), } } } diff --git a/polkadot/runtime/parachains/src/assigner_coretime/mock_helpers.rs b/polkadot/runtime/parachains/src/assigner_coretime/mock_helpers.rs index cf97c3e913e3..ef7e66662684 100644 --- a/polkadot/runtime/parachains/src/assigner_coretime/mock_helpers.rs +++ b/polkadot/runtime/parachains/src/assigner_coretime/mock_helpers.rs @@ -64,7 +64,7 @@ impl GenesisConfigBuilder { pub(super) fn build(self) -> MockGenesisConfig { let mut genesis = default_genesis_config(); let config = &mut genesis.configuration.config; - config.coretime_params.cores = self.on_demand_cores; + config.coretime_params.coretime_cores = self.on_demand_cores; config.coretime_params.on_demand_base_fee = self.on_demand_base_fee; config.coretime_params.on_demand_fee_variability = self.on_demand_fee_variability; config.coretime_params.on_demand_queue_max_size = self.on_demand_max_queue_size; diff --git a/polkadot/runtime/parachains/src/assigner_coretime/mod.rs b/polkadot/runtime/parachains/src/assigner_coretime/mod.rs index b0a9d60f8e6b..7e998243c717 100644 --- a/polkadot/runtime/parachains/src/assigner_coretime/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_coretime/mod.rs @@ -325,7 +325,7 @@ impl AssignmentProvider> for Pallet { fn session_core_count() -> u32 { let config = >::config(); - config.coretime_params.cores + config.coretime_params.coretime_cores } } @@ -474,8 +474,8 @@ impl AssignCoretime for Pallet { // Add a new core and assign the para to it. let mut config = >::config(); - let core = config.coretime_params.cores; - config.coretime_params.cores.saturating_inc(); + let core = config.coretime_params.coretime_cores; + config.coretime_params.coretime_cores.saturating_inc(); // `assign_coretime` is only called at genesis or by root, so setting the active // config here is fine. diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mock_helpers.rs b/polkadot/runtime/parachains/src/assigner_on_demand/mock_helpers.rs index 5653c5f3d6b6..74e86a49b946 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mock_helpers.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/mock_helpers.rs @@ -63,7 +63,7 @@ impl GenesisConfigBuilder { pub(super) fn build(self) -> MockGenesisConfig { let mut genesis = default_genesis_config(); let config = &mut genesis.configuration.config; - config.coretime_params.cores = self.on_demand_cores; + config.coretime_params.coretime_cores = self.on_demand_cores; config.coretime_params.on_demand_base_fee = self.on_demand_base_fee; config.coretime_params.on_demand_fee_variability = self.on_demand_fee_variability; config.coretime_params.on_demand_queue_max_size = self.on_demand_max_queue_size; diff --git a/polkadot/runtime/parachains/src/assigner_parachains/mock_helpers.rs b/polkadot/runtime/parachains/src/assigner_parachains/mock_helpers.rs index f3b521c6a491..adde113d1876 100644 --- a/polkadot/runtime/parachains/src/assigner_parachains/mock_helpers.rs +++ b/polkadot/runtime/parachains/src/assigner_parachains/mock_helpers.rs @@ -60,7 +60,7 @@ impl GenesisConfigBuilder { pub(super) fn build(self) -> MockGenesisConfig { let mut genesis = default_genesis_config(); let config = &mut genesis.configuration.config; - config.coretime_params.cores = self.on_demand_cores; + config.coretime_params.coretime_cores = self.on_demand_cores; config.coretime_params.on_demand_base_fee = self.on_demand_base_fee; config.coretime_params.on_demand_fee_variability = self.on_demand_fee_variability; config.coretime_params.on_demand_queue_max_size = self.on_demand_max_queue_size; diff --git a/polkadot/runtime/parachains/src/configuration.rs b/polkadot/runtime/parachains/src/configuration.rs index 3facf7487ed4..d626c981e2b0 100644 --- a/polkadot/runtime/parachains/src/configuration.rs +++ b/polkadot/runtime/parachains/src/configuration.rs @@ -669,7 +669,7 @@ pub mod pallet { pub fn set_on_demand_retries(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.coretime_params.max_availability_timeouts = new; + config.coretime_params.coretime_max_availability_timeouts = new; }) } @@ -1175,7 +1175,7 @@ pub mod pallet { pub fn set_on_demand_ttl(origin: OriginFor, new: BlockNumberFor) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.coretime_params.ttl = new; + config.coretime_params.coretime_ttl = new; }) } @@ -1233,7 +1233,7 @@ pub mod pallet { /// To be used if authorization is checked otherwise. pub fn set_coretime_cores_unchecked(new: u32) -> DispatchResult { Self::schedule_config_update(|config| { - config.coretime_params.cores = new; + config.coretime_params.coretime_cores = new; }) } } diff --git a/polkadot/runtime/parachains/src/configuration/migration/v12.rs b/polkadot/runtime/parachains/src/configuration/migration/v12.rs index 454aa7c27842..57abfa0c2bb7 100644 --- a/polkadot/runtime/parachains/src/configuration/migration/v12.rs +++ b/polkadot/runtime/parachains/src/configuration/migration/v12.rs @@ -146,13 +146,13 @@ fn migrate_to_v12() -> Weight { node_features : pre.node_features, approval_voting_params : pre.approval_voting_params, coretime_params: CoretimeParams { - cores: pre.coretime_cores, - max_availability_timeouts: pre.on_demand_retries, + coretime_cores : pre.coretime_cores, + coretime_max_availability_timeouts : pre.on_demand_retries, on_demand_queue_max_size : pre.on_demand_queue_max_size, on_demand_target_queue_utilization : pre.on_demand_target_queue_utilization, on_demand_fee_variability : pre.on_demand_fee_variability, on_demand_base_fee : pre.on_demand_base_fee, - ttl: pre.on_demand_ttl, + coretime_ttl : pre.on_demand_ttl, } } }; @@ -305,13 +305,13 @@ mod tests { assert_eq!(v11.async_backing_params.max_candidate_depth , v12.async_backing_params.max_candidate_depth); assert_eq!(v11.executor_params , v12.executor_params); assert_eq!(v11.minimum_backing_votes , v12.minimum_backing_votes); - assert_eq!(v11.coretime_cores , v12.coretime_params.cores); - assert_eq!(v11.on_demand_retries , v12.coretime_params.max_availability_timeouts); + assert_eq!(v11.coretime_cores , v12.coretime_params.coretime_cores); + assert_eq!(v11.on_demand_retries , v12.coretime_params.coretime_max_availability_timeouts); assert_eq!(v11.on_demand_queue_max_size , v12.coretime_params.on_demand_queue_max_size); assert_eq!(v11.on_demand_target_queue_utilization , v12.coretime_params.on_demand_target_queue_utilization); assert_eq!(v11.on_demand_fee_variability , v12.coretime_params.on_demand_fee_variability); assert_eq!(v11.on_demand_base_fee , v12.coretime_params.on_demand_base_fee); - assert_eq!(v11.on_demand_ttl , v12.coretime_params.ttl); + assert_eq!(v11.on_demand_ttl , v12.coretime_params.coretime_ttl); }; // ; makes this a statement. `rustfmt::skip` cannot be put on an expression. } }); diff --git a/polkadot/runtime/parachains/src/configuration/tests.rs b/polkadot/runtime/parachains/src/configuration/tests.rs index b3871d297f6c..f8b6dcf257e7 100644 --- a/polkadot/runtime/parachains/src/configuration/tests.rs +++ b/polkadot/runtime/parachains/src/configuration/tests.rs @@ -315,13 +315,13 @@ fn setting_pending_config_members() { minimum_backing_votes: 5, node_features: bitvec![u8, Lsb0; 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1], coretime_params: CoretimeParams { - cores: 2, - max_availability_timeouts: 5, + coretime_cores: 2, + coretime_max_availability_timeouts: 5, on_demand_queue_max_size: 10_000u32, on_demand_base_fee: 10_000_000u128, on_demand_fee_variability: Perbill::from_percent(3), on_demand_target_queue_utilization: Perbill::from_percent(25), - ttl: 5u32, + coretime_ttl: 5u32, }, }; @@ -344,11 +344,14 @@ fn setting_pending_config_members() { Configuration::set_max_pov_size(RuntimeOrigin::root(), new_config.max_pov_size).unwrap(); Configuration::set_max_head_data_size(RuntimeOrigin::root(), new_config.max_head_data_size) .unwrap(); - Configuration::set_coretime_cores(RuntimeOrigin::root(), new_config.coretime_params.cores) - .unwrap(); + Configuration::set_coretime_cores( + RuntimeOrigin::root(), + new_config.coretime_params.coretime_cores, + ) + .unwrap(); Configuration::set_on_demand_retries( RuntimeOrigin::root(), - new_config.coretime_params.max_availability_timeouts, + new_config.coretime_params.coretime_max_availability_timeouts, ) .unwrap(); Configuration::set_group_rotation_frequency( diff --git a/polkadot/runtime/parachains/src/coretime/migration.rs b/polkadot/runtime/parachains/src/coretime/migration.rs index b89786bb1ca8..363dcba24ceb 100644 --- a/polkadot/runtime/parachains/src/coretime/migration.rs +++ b/polkadot/runtime/parachains/src/coretime/migration.rs @@ -177,7 +177,7 @@ mod v_coretime { let config = >::config(); // coretime_cores was on_demand_cores until now: - for on_demand in 0..config.coretime_params.cores { + for on_demand in 0..config.coretime_params.coretime_cores { let core = CoreIndex(legacy_count.saturating_add(on_demand as _)); let r = assigner_coretime::Pallet::::assign_core( core, @@ -189,9 +189,9 @@ mod v_coretime { log::error!("Creating assignment for existing on-demand core, failed: {:?}", err); } } - let total_cores = config.coretime_params.cores + legacy_count; + let total_cores = config.coretime_params.coretime_cores + legacy_count; configuration::ActiveConfig::::mutate(|c| { - c.coretime_params.cores = total_cores; + c.coretime_params.coretime_cores = total_cores; }); if let Err(err) = migrate_send_assignments_to_coretime_chain::() { @@ -200,7 +200,9 @@ mod v_coretime { let single_weight = ::WeightInfo::assign_core(1); single_weight - .saturating_mul(u64::from(legacy_count.saturating_add(config.coretime_params.cores))) + .saturating_mul(u64::from( + legacy_count.saturating_add(config.coretime_params.coretime_cores), + )) // Second read from sending assignments to the coretime chain. .saturating_add(T::DbWeight::get().reads_writes(2, 1)) } @@ -244,8 +246,10 @@ mod v_coretime { Some(mk_coretime_call(crate::coretime::CoretimeCalls::SetLease(p.into(), time_slice))) }); - let core_count: u16 = - configuration::Pallet::::config().coretime_params.cores.saturated_into(); + let core_count: u16 = configuration::Pallet::::config() + .coretime_params + .coretime_cores + .saturated_into(); let set_core_count = iter::once(mk_coretime_call( crate::coretime::CoretimeCalls::NotifyCoreCount(core_count), )); diff --git a/polkadot/runtime/parachains/src/coretime/mod.rs b/polkadot/runtime/parachains/src/coretime/mod.rs index 96842c770365..c422c385c0d0 100644 --- a/polkadot/runtime/parachains/src/coretime/mod.rs +++ b/polkadot/runtime/parachains/src/coretime/mod.rs @@ -214,8 +214,8 @@ impl Pallet { } pub fn initializer_on_new_session(notification: &SessionChangeNotification>) { - let old_core_count = notification.prev_config.coretime_params.cores; - let new_core_count = notification.new_config.coretime_params.cores; + let old_core_count = notification.prev_config.coretime_params.coretime_cores; + let new_core_count = notification.new_config.coretime_params.coretime_cores; if new_core_count != old_core_count { let core_count: u16 = new_core_count.saturated_into(); let message = Xcm(vec![ diff --git a/polkadot/runtime/parachains/src/inclusion/tests.rs b/polkadot/runtime/parachains/src/inclusion/tests.rs index c5bfd45f061a..d9256586d4b1 100644 --- a/polkadot/runtime/parachains/src/inclusion/tests.rs +++ b/polkadot/runtime/parachains/src/inclusion/tests.rs @@ -47,7 +47,7 @@ use test_helpers::{dummy_collator, dummy_collator_signature, dummy_validation_co fn default_config() -> HostConfiguration { let mut config = HostConfiguration::default(); - config.coretime_params.cores = 1; + config.coretime_params.coretime_cores = 1; config.max_code_size = 0b100000; config.max_head_data_size = 0b100000; config.group_rotation_frequency = u32::MAX; @@ -218,7 +218,7 @@ pub(crate) fn run_to_block( } pub(crate) fn expected_bits() -> usize { - Paras::parachains().len() + Configuration::config().coretime_params.cores as usize + Paras::parachains().len() + Configuration::config().coretime_params.coretime_cores as usize } fn default_bitfield() -> AvailabilityBitfield { diff --git a/polkadot/runtime/parachains/src/scheduler.rs b/polkadot/runtime/parachains/src/scheduler.rs index dc2335f02ad4..b3f6fcb78993 100644 --- a/polkadot/runtime/parachains/src/scheduler.rs +++ b/polkadot/runtime/parachains/src/scheduler.rs @@ -352,7 +352,7 @@ impl Pallet { fn drop_expired_claims_from_claimqueue() { let now = >::block_number(); let availability_cores = AvailabilityCores::::get(); - let ttl = >::config().coretime_params.ttl; + let ttl = >::config().coretime_params.coretime_ttl; ClaimQueue::::mutate(|cq| { for (idx, _) in (0u32..).zip(availability_cores) { @@ -509,8 +509,9 @@ impl Pallet { /// Return the next thing that will be scheduled on this core assuming it is currently /// occupied and the candidate occupying it times out. pub(crate) fn next_up_on_time_out(core: CoreIndex) -> Option { - let max_availability_timeouts = - >::config().coretime_params.max_availability_timeouts; + let max_availability_timeouts = >::config() + .coretime_params + .coretime_max_availability_timeouts; Self::next_up_on_available(core).or_else(|| { // Or, if none, the claim currently occupying the core, // as it would be put back on the queue after timing out if number of retries is not at @@ -585,8 +586,8 @@ impl Pallet { let n_session_cores = T::AssignmentProvider::session_core_count(); let cq = ClaimQueue::::get(); let config = >::config(); - let max_availability_timeouts = config.coretime_params.max_availability_timeouts; - let ttl = config.coretime_params.ttl; + let max_availability_timeouts = config.coretime_params.coretime_max_availability_timeouts; + let ttl = config.coretime_params.coretime_ttl; for core_idx in 0..n_session_cores { let core_idx = CoreIndex::from(core_idx); diff --git a/polkadot/runtime/parachains/src/scheduler/tests.rs b/polkadot/runtime/parachains/src/scheduler/tests.rs index 954fb51c4d6a..3ed25fa85cab 100644 --- a/polkadot/runtime/parachains/src/scheduler/tests.rs +++ b/polkadot/runtime/parachains/src/scheduler/tests.rs @@ -114,8 +114,8 @@ fn default_config() -> HostConfiguration { // `thread_availability_period`. minimum_validation_upgrade_delay: 6, coretime_params: CoretimeParams { - cores: 3, - max_availability_timeouts: 1, + coretime_cores: 3, + coretime_max_availability_timeouts: 1, ..Default::default() }, ..Default::default() @@ -169,7 +169,7 @@ fn claimqueue_ttl_drop_fn_works() { let mut now = 10; new_test_ext(genesis_config).execute_with(|| { - assert!(config.coretime_params.ttl == 5); + assert!(config.coretime_params.coretime_ttl == 5); // Register and run to a blockheight where the para is in a valid state. schedule_blank_para(para_id); run_to_block(now, |n| if n == now { Some(Default::default()) } else { None }); @@ -348,7 +348,7 @@ fn fill_claimqueue_fills() { new_test_ext(genesis_config).execute_with(|| { MockAssigner::set_core_count(2); - let coretime_ttl = config.coretime_params.ttl; + let coretime_ttl = config.coretime_params.coretime_ttl; // Add 3 paras schedule_blank_para(para_a); @@ -751,8 +751,8 @@ fn on_demand_claims_are_pruned_after_timing_out() { let mut config = default_config(); config.scheduling_lookahead = 1; // Need more timeouts for this test - config.coretime_params.max_availability_timeouts = max_retries; - config.coretime_params.ttl = BlockNumber::from(5u32); + config.coretime_params.coretime_max_availability_timeouts = max_retries; + config.coretime_params.coretime_ttl = BlockNumber::from(5u32); let genesis_config = genesis_config(&config); let para_a = ParaId::from(1_u32); @@ -1059,7 +1059,7 @@ fn session_change_requires_reschedule_dropping_removed_paras() { new_test_ext(genesis_config).execute_with(|| { // Setting explicit core count MockAssigner::set_core_count(5); - let coretime_ttl = >::config().coretime_params.ttl; + let coretime_ttl = >::config().coretime_params.coretime_ttl; schedule_blank_para(para_a); schedule_blank_para(para_b); diff --git a/polkadot/runtime/parachains/src/session_info/tests.rs b/polkadot/runtime/parachains/src/session_info/tests.rs index 764c80456619..34281bc06ce4 100644 --- a/polkadot/runtime/parachains/src/session_info/tests.rs +++ b/polkadot/runtime/parachains/src/session_info/tests.rs @@ -64,7 +64,7 @@ fn default_config() -> HostConfiguration { HostConfiguration { dispute_period: 2, needed_approvals: 3, - coretime_params: CoretimeParams { cores: 1, ..Default::default() }, + coretime_params: CoretimeParams { coretime_cores: 1, ..Default::default() }, ..Default::default() } } From 2b0ba0d51f0f8de3de71d1654824ed0c3d2ef3e2 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Mon, 5 Feb 2024 10:26:15 +0200 Subject: [PATCH 13/40] Revert "Remove `coretime_` prefix from config params" This reverts commit e8d179cdfe569e573477ce92c70b9c777b26dd7f. --- polkadot/runtime/parachains/src/builder.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/polkadot/runtime/parachains/src/builder.rs b/polkadot/runtime/parachains/src/builder.rs index c5e0b0c1db3a..d3461ba7725b 100644 --- a/polkadot/runtime/parachains/src/builder.rs +++ b/polkadot/runtime/parachains/src/builder.rs @@ -679,7 +679,7 @@ impl BenchBuilder { // We are currently in Session 0, so these changes will take effect in Session 2. Self::setup_para_ids(used_cores); configuration::ActiveConfig::::mutate(|c| { - c.coretime_params.cores = used_cores; + c.coretime_params.coretime_cores = used_cores; }); let validator_ids = Self::generate_validator_pairs(self.max_validators()); @@ -710,7 +710,7 @@ impl BenchBuilder { let cores = (0..used_cores) .into_iter() .map(|i| { - let ttl = configuration::Pallet::::config().coretime_params.ttl; + let ttl = configuration::Pallet::::config().coretime_params.coretime_ttl; // Load an assignment into provider so that one is present to pop let assignment = ::AssignmentProvider::get_mock_assignment( CoreIndex(i), @@ -725,7 +725,7 @@ impl BenchBuilder { let cores = (0..used_cores) .into_iter() .map(|i| { - let ttl = configuration::Pallet::::config().coretime_params.ttl; + let ttl = configuration::Pallet::::config().coretime_params.coretime_ttl; // Load an assignment into provider so that one is present to pop let assignment = ::AssignmentProvider::get_mock_assignment( From 0c3ebc1cc3bbdddb21c5896851e56ea0d06c7c6f Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Mon, 5 Feb 2024 17:53:59 +0200 Subject: [PATCH 14/40] CoretimeParams -> SchedulerParams --- polkadot/primitives/src/vstaging/mod.rs | 7 +++-- .../src/assigner_coretime/mock_helpers.rs | 10 +++---- .../parachains/src/assigner_coretime/mod.rs | 6 ++-- .../src/assigner_on_demand/mock_helpers.rs | 10 +++---- .../parachains/src/assigner_on_demand/mod.rs | 12 ++++---- .../src/assigner_parachains/mock_helpers.rs | 10 +++---- polkadot/runtime/parachains/src/builder.rs | 6 ++-- .../runtime/parachains/src/configuration.rs | 25 ++++++++--------- .../src/configuration/migration/v12.rs | 26 +++++++++-------- .../parachains/src/configuration/tests.rs | 11 ++++---- .../parachains/src/coretime/migration.rs | 10 +++---- .../runtime/parachains/src/coretime/mod.rs | 4 +-- .../runtime/parachains/src/inclusion/tests.rs | 4 +-- .../parachains/src/paras_inherent/tests.rs | 4 +-- polkadot/runtime/parachains/src/scheduler.rs | 10 +++---- .../runtime/parachains/src/scheduler/tests.rs | 28 +++++++++---------- .../parachains/src/session_info/tests.rs | 4 +-- 17 files changed, 95 insertions(+), 92 deletions(-) diff --git a/polkadot/primitives/src/vstaging/mod.rs b/polkadot/primitives/src/vstaging/mod.rs index 4ca3c472722f..f66974f81adc 100644 --- a/polkadot/primitives/src/vstaging/mod.rs +++ b/polkadot/primitives/src/vstaging/mod.rs @@ -63,7 +63,9 @@ impl Default for ApprovalVotingParams { serde::Serialize, serde::Deserialize, )] -pub struct CoretimeParams { +pub struct SchedulerParams { + /// The amount of blocks ahead to schedule paras. + pub lookahead: u32, /// How many cores are managed by the coretime chain. pub coretime_cores: u32, /// The max number of times a claim can time out in availability @@ -83,9 +85,10 @@ pub struct CoretimeParams { pub coretime_ttl: BlockNumber, } -impl> Default for CoretimeParams { +impl> Default for SchedulerParams { fn default() -> Self { Self { + lookahead: 1, coretime_cores: Default::default(), coretime_max_availability_timeouts: Default::default(), on_demand_queue_max_size: ON_DEMAND_DEFAULT_QUEUE_MAX_SIZE, diff --git a/polkadot/runtime/parachains/src/assigner_coretime/mock_helpers.rs b/polkadot/runtime/parachains/src/assigner_coretime/mock_helpers.rs index ef7e66662684..87a8c6004831 100644 --- a/polkadot/runtime/parachains/src/assigner_coretime/mock_helpers.rs +++ b/polkadot/runtime/parachains/src/assigner_coretime/mock_helpers.rs @@ -64,11 +64,11 @@ impl GenesisConfigBuilder { pub(super) fn build(self) -> MockGenesisConfig { let mut genesis = default_genesis_config(); let config = &mut genesis.configuration.config; - config.coretime_params.coretime_cores = self.on_demand_cores; - config.coretime_params.on_demand_base_fee = self.on_demand_base_fee; - config.coretime_params.on_demand_fee_variability = self.on_demand_fee_variability; - config.coretime_params.on_demand_queue_max_size = self.on_demand_max_queue_size; - config.coretime_params.on_demand_target_queue_utilization = + config.scheduler_params.coretime_cores = self.on_demand_cores; + config.scheduler_params.on_demand_base_fee = self.on_demand_base_fee; + config.scheduler_params.on_demand_fee_variability = self.on_demand_fee_variability; + config.scheduler_params.on_demand_queue_max_size = self.on_demand_max_queue_size; + config.scheduler_params.on_demand_target_queue_utilization = self.on_demand_target_queue_utilization; let paras = &mut genesis.paras.paras; diff --git a/polkadot/runtime/parachains/src/assigner_coretime/mod.rs b/polkadot/runtime/parachains/src/assigner_coretime/mod.rs index 7e998243c717..2f343b30efa5 100644 --- a/polkadot/runtime/parachains/src/assigner_coretime/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_coretime/mod.rs @@ -325,7 +325,7 @@ impl AssignmentProvider> for Pallet { fn session_core_count() -> u32 { let config = >::config(); - config.coretime_params.coretime_cores + config.scheduler_params.coretime_cores } } @@ -474,8 +474,8 @@ impl AssignCoretime for Pallet { // Add a new core and assign the para to it. let mut config = >::config(); - let core = config.coretime_params.coretime_cores; - config.coretime_params.coretime_cores.saturating_inc(); + let core = config.scheduler_params.coretime_cores; + config.scheduler_params.coretime_cores.saturating_inc(); // `assign_coretime` is only called at genesis or by root, so setting the active // config here is fine. diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mock_helpers.rs b/polkadot/runtime/parachains/src/assigner_on_demand/mock_helpers.rs index 74e86a49b946..be86d098f3d4 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mock_helpers.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/mock_helpers.rs @@ -63,11 +63,11 @@ impl GenesisConfigBuilder { pub(super) fn build(self) -> MockGenesisConfig { let mut genesis = default_genesis_config(); let config = &mut genesis.configuration.config; - config.coretime_params.coretime_cores = self.on_demand_cores; - config.coretime_params.on_demand_base_fee = self.on_demand_base_fee; - config.coretime_params.on_demand_fee_variability = self.on_demand_fee_variability; - config.coretime_params.on_demand_queue_max_size = self.on_demand_max_queue_size; - config.coretime_params.on_demand_target_queue_utilization = + config.scheduler_params.coretime_cores = self.on_demand_cores; + config.scheduler_params.on_demand_base_fee = self.on_demand_base_fee; + config.scheduler_params.on_demand_fee_variability = self.on_demand_fee_variability; + config.scheduler_params.on_demand_queue_max_size = self.on_demand_max_queue_size; + config.scheduler_params.on_demand_target_queue_utilization = self.on_demand_target_queue_utilization; let paras = &mut genesis.paras.paras; diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs index 676a4a4988bc..bc450dc78129 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/mod.rs @@ -201,10 +201,10 @@ pub mod pallet { let old_traffic = SpotTraffic::::get(); match Self::calculate_spot_traffic( old_traffic, - config.coretime_params.on_demand_queue_max_size, + config.scheduler_params.on_demand_queue_max_size, Self::queue_size(), - config.coretime_params.on_demand_target_queue_utilization, - config.coretime_params.on_demand_fee_variability, + config.scheduler_params.on_demand_target_queue_utilization, + config.scheduler_params.on_demand_fee_variability, ) { Ok(new_traffic) => { // Only update storage on change @@ -331,7 +331,7 @@ where // Calculate spot price let spot_price: BalanceOf = traffic.saturating_mul_int( - config.coretime_params.on_demand_base_fee.saturated_into::>(), + config.scheduler_params.on_demand_base_fee.saturated_into::>(), ); // Is the current price higher than `max_amount` @@ -452,7 +452,7 @@ where OnDemandQueue::::try_mutate(|queue| { // Abort transaction if queue is too large ensure!( - Self::queue_size() < config.coretime_params.on_demand_queue_max_size, + Self::queue_size() < config.scheduler_params.on_demand_queue_max_size, Error::::QueueFull ); match location { @@ -476,7 +476,7 @@ where target: LOG_TARGET, "Failed to fetch the on demand queue size, returning the max size." ); - return config.coretime_params.on_demand_queue_max_size + return config.scheduler_params.on_demand_queue_max_size }, } } diff --git a/polkadot/runtime/parachains/src/assigner_parachains/mock_helpers.rs b/polkadot/runtime/parachains/src/assigner_parachains/mock_helpers.rs index adde113d1876..eacb74253a39 100644 --- a/polkadot/runtime/parachains/src/assigner_parachains/mock_helpers.rs +++ b/polkadot/runtime/parachains/src/assigner_parachains/mock_helpers.rs @@ -60,11 +60,11 @@ impl GenesisConfigBuilder { pub(super) fn build(self) -> MockGenesisConfig { let mut genesis = default_genesis_config(); let config = &mut genesis.configuration.config; - config.coretime_params.coretime_cores = self.on_demand_cores; - config.coretime_params.on_demand_base_fee = self.on_demand_base_fee; - config.coretime_params.on_demand_fee_variability = self.on_demand_fee_variability; - config.coretime_params.on_demand_queue_max_size = self.on_demand_max_queue_size; - config.coretime_params.on_demand_target_queue_utilization = + config.scheduler_params.coretime_cores = self.on_demand_cores; + config.scheduler_params.on_demand_base_fee = self.on_demand_base_fee; + config.scheduler_params.on_demand_fee_variability = self.on_demand_fee_variability; + config.scheduler_params.on_demand_queue_max_size = self.on_demand_max_queue_size; + config.scheduler_params.on_demand_target_queue_utilization = self.on_demand_target_queue_utilization; let paras = &mut genesis.paras.paras; diff --git a/polkadot/runtime/parachains/src/builder.rs b/polkadot/runtime/parachains/src/builder.rs index d3461ba7725b..5bf7b90eb92b 100644 --- a/polkadot/runtime/parachains/src/builder.rs +++ b/polkadot/runtime/parachains/src/builder.rs @@ -679,7 +679,7 @@ impl BenchBuilder { // We are currently in Session 0, so these changes will take effect in Session 2. Self::setup_para_ids(used_cores); configuration::ActiveConfig::::mutate(|c| { - c.coretime_params.coretime_cores = used_cores; + c.scheduler_params.coretime_cores = used_cores; }); let validator_ids = Self::generate_validator_pairs(self.max_validators()); @@ -710,7 +710,7 @@ impl BenchBuilder { let cores = (0..used_cores) .into_iter() .map(|i| { - let ttl = configuration::Pallet::::config().coretime_params.coretime_ttl; + let ttl = configuration::Pallet::::config().scheduler_params.coretime_ttl; // Load an assignment into provider so that one is present to pop let assignment = ::AssignmentProvider::get_mock_assignment( CoreIndex(i), @@ -725,7 +725,7 @@ impl BenchBuilder { let cores = (0..used_cores) .into_iter() .map(|i| { - let ttl = configuration::Pallet::::config().coretime_params.coretime_ttl; + let ttl = configuration::Pallet::::config().scheduler_params.coretime_ttl; // Load an assignment into provider so that one is present to pop let assignment = ::AssignmentProvider::get_mock_assignment( diff --git a/polkadot/runtime/parachains/src/configuration.rs b/polkadot/runtime/parachains/src/configuration.rs index d626c981e2b0..84f1ae46f865 100644 --- a/polkadot/runtime/parachains/src/configuration.rs +++ b/polkadot/runtime/parachains/src/configuration.rs @@ -42,7 +42,7 @@ mod benchmarking; pub mod migration; pub use pallet::*; -use primitives::vstaging::CoretimeParams; +use primitives::vstaging::SchedulerParams; const LOG_TARGET: &str = "runtime::configuration"; @@ -192,8 +192,6 @@ pub struct HostConfiguration { /// affect the following group at the expense of a tight availability timeline at group /// rotation boundaries. pub paras_availability_period: BlockNumber, - /// The amount of blocks ahead to schedule paras. - pub scheduling_lookahead: u32, /// The maximum number of validators to have per core. /// /// `None` means no maximum. @@ -251,7 +249,7 @@ pub struct HostConfiguration { /// Params used by approval-voting pub approval_voting_params: ApprovalVotingParams, /// Core time parameters - pub coretime_params: CoretimeParams, + pub scheduler_params: SchedulerParams, } impl> Default for HostConfiguration { @@ -270,7 +268,6 @@ impl> Default for HostConfiguration> Default for HostConfiguration, new: u32) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.coretime_params.coretime_max_availability_timeouts = new; + config.scheduler_params.coretime_max_availability_timeouts = new; }) } @@ -714,7 +711,7 @@ pub mod pallet { pub fn set_scheduling_lookahead(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.scheduling_lookahead = new; + config.scheduler_params.lookahead = new; }) } @@ -1122,7 +1119,7 @@ pub mod pallet { pub fn set_on_demand_base_fee(origin: OriginFor, new: Balance) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.coretime_params.on_demand_base_fee = new; + config.scheduler_params.on_demand_base_fee = new; }) } @@ -1135,7 +1132,7 @@ pub mod pallet { pub fn set_on_demand_fee_variability(origin: OriginFor, new: Perbill) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.coretime_params.on_demand_fee_variability = new; + config.scheduler_params.on_demand_fee_variability = new; }) } @@ -1148,7 +1145,7 @@ pub mod pallet { pub fn set_on_demand_queue_max_size(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.coretime_params.on_demand_queue_max_size = new; + config.scheduler_params.on_demand_queue_max_size = new; }) } /// Set the on demand (parathreads) fee variability. @@ -1163,7 +1160,7 @@ pub mod pallet { ) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.coretime_params.on_demand_target_queue_utilization = new; + config.scheduler_params.on_demand_target_queue_utilization = new; }) } /// Set the on demand (parathreads) ttl in the claimqueue. @@ -1175,7 +1172,7 @@ pub mod pallet { pub fn set_on_demand_ttl(origin: OriginFor, new: BlockNumberFor) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.coretime_params.coretime_ttl = new; + config.scheduler_params.coretime_ttl = new; }) } @@ -1233,7 +1230,7 @@ pub mod pallet { /// To be used if authorization is checked otherwise. pub fn set_coretime_cores_unchecked(new: u32) -> DispatchResult { Self::schedule_config_update(|config| { - config.coretime_params.coretime_cores = new; + config.scheduler_params.coretime_cores = new; }) } } diff --git a/polkadot/runtime/parachains/src/configuration/migration/v12.rs b/polkadot/runtime/parachains/src/configuration/migration/v12.rs index 57abfa0c2bb7..fccf5942b76e 100644 --- a/polkadot/runtime/parachains/src/configuration/migration/v12.rs +++ b/polkadot/runtime/parachains/src/configuration/migration/v12.rs @@ -23,11 +23,13 @@ use frame_support::{ traits::{Defensive, OnRuntimeUpgrade}, }; use frame_system::pallet_prelude::BlockNumberFor; -use primitives::vstaging::CoretimeParams; +use primitives::vstaging::SchedulerParams; use sp_core::Get; use sp_staking::SessionIndex; +use sp_std::vec::Vec; type V12HostConfiguration = configuration::HostConfiguration; + mod v11 { use super::*; @@ -128,7 +130,6 @@ fn migrate_to_v12() -> Weight { code_retention_period : pre.code_retention_period, group_rotation_frequency : pre.group_rotation_frequency, paras_availability_period : pre.paras_availability_period, - scheduling_lookahead : pre.scheduling_lookahead, max_validators_per_core : pre.max_validators_per_core, max_validators : pre.max_validators, dispute_period : pre.dispute_period, @@ -145,7 +146,8 @@ fn migrate_to_v12() -> Weight { minimum_backing_votes : pre.minimum_backing_votes, node_features : pre.node_features, approval_voting_params : pre.approval_voting_params, - coretime_params: CoretimeParams { + scheduler_params: SchedulerParams { + lookahead : pre.scheduling_lookahead, coretime_cores : pre.coretime_cores, coretime_max_availability_timeouts : pre.on_demand_retries, on_demand_queue_max_size : pre.on_demand_queue_max_size, @@ -198,7 +200,7 @@ mod tests { // the block) // 2.3. Note the value of encoded storage key -> // 0x06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385 for the - // referenced block. + // referenced block. // 2.4. You'll also need the decoded values to update the test. // 3. Go to Polkadot.js -> Developer -> Chain state -> Raw storage // 3.1 Enter the encoded storage key and you get the raw config. @@ -290,7 +292,6 @@ mod tests { assert_eq!(v11.code_retention_period , v12.code_retention_period); assert_eq!(v11.group_rotation_frequency , v12.group_rotation_frequency); assert_eq!(v11.paras_availability_period , v12.paras_availability_period); - assert_eq!(v11.scheduling_lookahead , v12.scheduling_lookahead); assert_eq!(v11.max_validators_per_core , v12.max_validators_per_core); assert_eq!(v11.max_validators , v12.max_validators); assert_eq!(v11.dispute_period , v12.dispute_period); @@ -305,13 +306,14 @@ mod tests { assert_eq!(v11.async_backing_params.max_candidate_depth , v12.async_backing_params.max_candidate_depth); assert_eq!(v11.executor_params , v12.executor_params); assert_eq!(v11.minimum_backing_votes , v12.minimum_backing_votes); - assert_eq!(v11.coretime_cores , v12.coretime_params.coretime_cores); - assert_eq!(v11.on_demand_retries , v12.coretime_params.coretime_max_availability_timeouts); - assert_eq!(v11.on_demand_queue_max_size , v12.coretime_params.on_demand_queue_max_size); - assert_eq!(v11.on_demand_target_queue_utilization , v12.coretime_params.on_demand_target_queue_utilization); - assert_eq!(v11.on_demand_fee_variability , v12.coretime_params.on_demand_fee_variability); - assert_eq!(v11.on_demand_base_fee , v12.coretime_params.on_demand_base_fee); - assert_eq!(v11.on_demand_ttl , v12.coretime_params.coretime_ttl); + assert_eq!(v11.scheduling_lookahead , v12.scheduler_params.lookahead); + assert_eq!(v11.coretime_cores , v12.scheduler_params.coretime_cores); + assert_eq!(v11.on_demand_retries , v12.scheduler_params.coretime_max_availability_timeouts); + assert_eq!(v11.on_demand_queue_max_size , v12.scheduler_params.on_demand_queue_max_size); + assert_eq!(v11.on_demand_target_queue_utilization , v12.scheduler_params.on_demand_target_queue_utilization); + assert_eq!(v11.on_demand_fee_variability , v12.scheduler_params.on_demand_fee_variability); + assert_eq!(v11.on_demand_base_fee , v12.scheduler_params.on_demand_base_fee); + assert_eq!(v11.on_demand_ttl , v12.scheduler_params.coretime_ttl); }; // ; makes this a statement. `rustfmt::skip` cannot be put on an expression. } }); diff --git a/polkadot/runtime/parachains/src/configuration/tests.rs b/polkadot/runtime/parachains/src/configuration/tests.rs index f8b6dcf257e7..55955c61e658 100644 --- a/polkadot/runtime/parachains/src/configuration/tests.rs +++ b/polkadot/runtime/parachains/src/configuration/tests.rs @@ -285,7 +285,7 @@ fn setting_pending_config_members() { max_head_data_size: 1_000, group_rotation_frequency: 20, paras_availability_period: 10, - scheduling_lookahead: 3, + max_validators_per_core: None, max_validators: None, dispute_period: 239, @@ -314,7 +314,8 @@ fn setting_pending_config_members() { approval_voting_params: ApprovalVotingParams { max_approval_coalesce_count: 1 }, minimum_backing_votes: 5, node_features: bitvec![u8, Lsb0; 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1], - coretime_params: CoretimeParams { + scheduler_params: SchedulerParams { + lookahead: 3, coretime_cores: 2, coretime_max_availability_timeouts: 5, on_demand_queue_max_size: 10_000u32, @@ -346,12 +347,12 @@ fn setting_pending_config_members() { .unwrap(); Configuration::set_coretime_cores( RuntimeOrigin::root(), - new_config.coretime_params.coretime_cores, + new_config.scheduler_params.coretime_cores, ) .unwrap(); Configuration::set_on_demand_retries( RuntimeOrigin::root(), - new_config.coretime_params.coretime_max_availability_timeouts, + new_config.scheduler_params.coretime_max_availability_timeouts, ) .unwrap(); Configuration::set_group_rotation_frequency( @@ -373,7 +374,7 @@ fn setting_pending_config_members() { .unwrap(); Configuration::set_scheduling_lookahead( RuntimeOrigin::root(), - new_config.scheduling_lookahead, + new_config.scheduler_params.lookahead, ) .unwrap(); Configuration::set_max_validators_per_core( diff --git a/polkadot/runtime/parachains/src/coretime/migration.rs b/polkadot/runtime/parachains/src/coretime/migration.rs index 363dcba24ceb..c4cac731d772 100644 --- a/polkadot/runtime/parachains/src/coretime/migration.rs +++ b/polkadot/runtime/parachains/src/coretime/migration.rs @@ -177,7 +177,7 @@ mod v_coretime { let config = >::config(); // coretime_cores was on_demand_cores until now: - for on_demand in 0..config.coretime_params.coretime_cores { + for on_demand in 0..config.scheduler_params.coretime_cores { let core = CoreIndex(legacy_count.saturating_add(on_demand as _)); let r = assigner_coretime::Pallet::::assign_core( core, @@ -189,9 +189,9 @@ mod v_coretime { log::error!("Creating assignment for existing on-demand core, failed: {:?}", err); } } - let total_cores = config.coretime_params.coretime_cores + legacy_count; + let total_cores = config.scheduler_params.coretime_cores + legacy_count; configuration::ActiveConfig::::mutate(|c| { - c.coretime_params.coretime_cores = total_cores; + c.scheduler_params.coretime_cores = total_cores; }); if let Err(err) = migrate_send_assignments_to_coretime_chain::() { @@ -201,7 +201,7 @@ mod v_coretime { let single_weight = ::WeightInfo::assign_core(1); single_weight .saturating_mul(u64::from( - legacy_count.saturating_add(config.coretime_params.coretime_cores), + legacy_count.saturating_add(config.scheduler_params.coretime_cores), )) // Second read from sending assignments to the coretime chain. .saturating_add(T::DbWeight::get().reads_writes(2, 1)) @@ -247,7 +247,7 @@ mod v_coretime { }); let core_count: u16 = configuration::Pallet::::config() - .coretime_params + .scheduler_params .coretime_cores .saturated_into(); let set_core_count = iter::once(mk_coretime_call( diff --git a/polkadot/runtime/parachains/src/coretime/mod.rs b/polkadot/runtime/parachains/src/coretime/mod.rs index c422c385c0d0..68558df7c4fb 100644 --- a/polkadot/runtime/parachains/src/coretime/mod.rs +++ b/polkadot/runtime/parachains/src/coretime/mod.rs @@ -214,8 +214,8 @@ impl Pallet { } pub fn initializer_on_new_session(notification: &SessionChangeNotification>) { - let old_core_count = notification.prev_config.coretime_params.coretime_cores; - let new_core_count = notification.new_config.coretime_params.coretime_cores; + let old_core_count = notification.prev_config.scheduler_params.coretime_cores; + let new_core_count = notification.new_config.scheduler_params.coretime_cores; if new_core_count != old_core_count { let core_count: u16 = new_core_count.saturated_into(); let message = Xcm(vec![ diff --git a/polkadot/runtime/parachains/src/inclusion/tests.rs b/polkadot/runtime/parachains/src/inclusion/tests.rs index d9256586d4b1..1b101a28a130 100644 --- a/polkadot/runtime/parachains/src/inclusion/tests.rs +++ b/polkadot/runtime/parachains/src/inclusion/tests.rs @@ -47,7 +47,7 @@ use test_helpers::{dummy_collator, dummy_collator_signature, dummy_validation_co fn default_config() -> HostConfiguration { let mut config = HostConfiguration::default(); - config.coretime_params.coretime_cores = 1; + config.scheduler_params.coretime_cores = 1; config.max_code_size = 0b100000; config.max_head_data_size = 0b100000; config.group_rotation_frequency = u32::MAX; @@ -218,7 +218,7 @@ pub(crate) fn run_to_block( } pub(crate) fn expected_bits() -> usize { - Paras::parachains().len() + Configuration::config().coretime_params.coretime_cores as usize + Paras::parachains().len() + Configuration::config().scheduler_params.coretime_cores as usize } fn default_bitfield() -> AvailabilityBitfield { diff --git a/polkadot/runtime/parachains/src/paras_inherent/tests.rs b/polkadot/runtime/parachains/src/paras_inherent/tests.rs index 6f3eac35685a..1400a06ec3ce 100644 --- a/polkadot/runtime/parachains/src/paras_inherent/tests.rs +++ b/polkadot/runtime/parachains/src/paras_inherent/tests.rs @@ -84,7 +84,7 @@ mod enter { // `create_inherent` and will not cause `enter` to early. fn include_backed_candidates() { let config = MockGenesisConfig::default(); - assert!(config.configuration.config.scheduling_lookahead > 0); + assert!(config.configuration.config.scheduler_params.lookahead > 0); new_test_ext(config).execute_with(|| { let dispute_statements = BTreeMap::new(); @@ -622,7 +622,7 @@ mod enter { #[test] fn limit_candidates_over_weight_1() { let config = MockGenesisConfig::default(); - assert!(config.configuration.config.scheduling_lookahead > 0); + assert!(config.configuration.config.scheduler_params.lookahead > 0); new_test_ext(config).execute_with(|| { // Create the inherent data for this block diff --git a/polkadot/runtime/parachains/src/scheduler.rs b/polkadot/runtime/parachains/src/scheduler.rs index b3f6fcb78993..3c093d305e59 100644 --- a/polkadot/runtime/parachains/src/scheduler.rs +++ b/polkadot/runtime/parachains/src/scheduler.rs @@ -352,7 +352,7 @@ impl Pallet { fn drop_expired_claims_from_claimqueue() { let now = >::block_number(); let availability_cores = AvailabilityCores::::get(); - let ttl = >::config().coretime_params.coretime_ttl; + let ttl = >::config().scheduler_params.coretime_ttl; ClaimQueue::::mutate(|cq| { for (idx, _) in (0u32..).zip(availability_cores) { @@ -510,7 +510,7 @@ impl Pallet { /// occupied and the candidate occupying it times out. pub(crate) fn next_up_on_time_out(core: CoreIndex) -> Option { let max_availability_timeouts = >::config() - .coretime_params + .scheduler_params .coretime_max_availability_timeouts; Self::next_up_on_available(core).or_else(|| { // Or, if none, the claim currently occupying the core, @@ -566,7 +566,7 @@ impl Pallet { // ClaimQueue related functions // fn claimqueue_lookahead() -> u32 { - >::config().scheduling_lookahead + >::config().scheduler_params.lookahead } /// Frees cores and fills the free claimqueue spots by popping from the `AssignmentProvider`. @@ -586,8 +586,8 @@ impl Pallet { let n_session_cores = T::AssignmentProvider::session_core_count(); let cq = ClaimQueue::::get(); let config = >::config(); - let max_availability_timeouts = config.coretime_params.coretime_max_availability_timeouts; - let ttl = config.coretime_params.coretime_ttl; + let max_availability_timeouts = config.scheduler_params.coretime_max_availability_timeouts; + let ttl = config.scheduler_params.coretime_ttl; for core_idx in 0..n_session_cores { let core_idx = CoreIndex::from(core_idx); diff --git a/polkadot/runtime/parachains/src/scheduler/tests.rs b/polkadot/runtime/parachains/src/scheduler/tests.rs index 3ed25fa85cab..e74d4941c9e8 100644 --- a/polkadot/runtime/parachains/src/scheduler/tests.rs +++ b/polkadot/runtime/parachains/src/scheduler/tests.rs @@ -19,7 +19,7 @@ use super::*; use frame_support::assert_ok; use keyring::Sr25519Keyring; use primitives::{ - vstaging::CoretimeParams, BlockNumber, SessionIndex, ValidationCode, ValidatorId, + vstaging::SchedulerParams, BlockNumber, SessionIndex, ValidationCode, ValidatorId, }; use sp_std::collections::{btree_map::BTreeMap, btree_set::BTreeSet}; @@ -107,13 +107,13 @@ fn default_config() -> HostConfiguration { HostConfiguration { group_rotation_frequency: 10, paras_availability_period: 3, - scheduling_lookahead: 2, // This field does not affect anything that scheduler does. However, `HostConfiguration` // is still a subject to consistency test. It requires that // `minimum_validation_upgrade_delay` is greater than `chain_availability_period` and // `thread_availability_period`. minimum_validation_upgrade_delay: 6, - coretime_params: CoretimeParams { + scheduler_params: SchedulerParams { + lookahead: 2, coretime_cores: 3, coretime_max_availability_timeouts: 1, ..Default::default() @@ -161,7 +161,7 @@ fn scheduled_entries() -> impl Iterator>::config().coretime_params.coretime_ttl; + let coretime_ttl = >::config().scheduler_params.coretime_ttl; schedule_blank_para(para_a); schedule_blank_para(para_b); diff --git a/polkadot/runtime/parachains/src/session_info/tests.rs b/polkadot/runtime/parachains/src/session_info/tests.rs index 34281bc06ce4..68dd8ade60b4 100644 --- a/polkadot/runtime/parachains/src/session_info/tests.rs +++ b/polkadot/runtime/parachains/src/session_info/tests.rs @@ -25,7 +25,7 @@ use crate::{ util::take_active_subset, }; use keyring::Sr25519Keyring; -use primitives::{vstaging::CoretimeParams, BlockNumber, ValidatorId, ValidatorIndex}; +use primitives::{vstaging::SchedulerParams, BlockNumber, ValidatorId, ValidatorIndex}; fn run_to_block( to: BlockNumber, @@ -64,7 +64,7 @@ fn default_config() -> HostConfiguration { HostConfiguration { dispute_period: 2, needed_approvals: 3, - coretime_params: CoretimeParams { coretime_cores: 1, ..Default::default() }, + scheduler_params: SchedulerParams { coretime_cores: 1, ..Default::default() }, ..Default::default() } } From e42958247a3bba133eb5dd5023a306ecbdf52eef Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Mon, 5 Feb 2024 18:14:30 +0200 Subject: [PATCH 15/40] Fix migration test --- .../src/configuration/migration/v12.rs | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/polkadot/runtime/parachains/src/configuration/migration/v12.rs b/polkadot/runtime/parachains/src/configuration/migration/v12.rs index fccf5942b76e..c2ef00091fe4 100644 --- a/polkadot/runtime/parachains/src/configuration/migration/v12.rs +++ b/polkadot/runtime/parachains/src/configuration/migration/v12.rs @@ -182,6 +182,7 @@ fn migrate_to_v12() -> Weight { #[cfg(test)] mod tests { use primitives::LEGACY_MIN_BACKING_VOTES; + use sp_arithmetic::Perbill; use super::*; use crate::mock::{new_test_ext, Test}; @@ -209,25 +210,34 @@ mod tests { // doesn't need to be read and also leaving it as one line allows to easily copy it. let raw_config = hex_literal::hex![" - 0000300000800000080000000000100000c8000005000000050000000200000002000000000000000000000000005000000010000400000000000000000000000000000000000000000000000000000000000000000000000800000000200000040000000000100000b004000000000000000000001027000080b2e60e80c3c9018096980000000000000000000000000005000000140000000400000001000000010100000000060000006400000002000000190000000000000002000000020000000200000005000000020000000001000000" + 0000300000800000080000000000100000c8000005000000050000000200000002000000000000000000000000005000000010000400000000000000000000000000000000000000000000000000000000000000000000000800000000200000040000000000100000b004000014000000040000000101000000000600000064000000020000001900000000000000020000000200000002000000050000000200000000010000000100000001000000000000001027000080b2e60e80c3c9018096980000000000000000000000000005000000" ]; - let v11 = - V11HostConfiguration::::decode(&mut &raw_config[..]).unwrap(); + let v12 = + V12HostConfiguration::::decode(&mut &raw_config[..]).unwrap(); // We check only a sample of the values here. If we missed any fields or messed up data // types that would skew all the fields coming after. - assert_eq!(v11.max_code_size, 3_145_728); - assert_eq!(v11.validation_upgrade_cooldown, 2); - assert_eq!(v11.max_pov_size, 5_242_880); - assert_eq!(v11.hrmp_channel_max_message_size, 1_048_576); - assert_eq!(v11.n_delay_tranches, 25); - assert_eq!(v11.minimum_validation_upgrade_delay, 5); - assert_eq!(v11.group_rotation_frequency, 20); - assert_eq!(v11.coretime_cores, 0); - assert_eq!(v11.on_demand_base_fee, 10_000_000); - assert_eq!(v11.minimum_backing_votes, LEGACY_MIN_BACKING_VOTES); - assert_eq!(v11.approval_voting_params.max_approval_coalesce_count, 1); + assert_eq!(v12.max_code_size, 3_145_728); + assert_eq!(v12.validation_upgrade_cooldown, 2); + assert_eq!(v12.max_pov_size, 5_242_880); + assert_eq!(v12.hrmp_channel_max_message_size, 1_048_576); + assert_eq!(v12.n_delay_tranches, 25); + assert_eq!(v12.minimum_validation_upgrade_delay, 5); + assert_eq!(v12.group_rotation_frequency, 20); + assert_eq!(v12.minimum_backing_votes, LEGACY_MIN_BACKING_VOTES); + assert_eq!(v12.approval_voting_params.max_approval_coalesce_count, 1); + assert_eq!(v12.scheduler_params.lookahead, 1); + assert_eq!(v12.scheduler_params.coretime_cores, 1); + assert_eq!(v12.scheduler_params.coretime_max_availability_timeouts, 0); + assert_eq!(v12.scheduler_params.on_demand_queue_max_size, 10_000); + assert_eq!( + v12.scheduler_params.on_demand_target_queue_utilization, + Perbill::from_percent(25) + ); + assert_eq!(v12.scheduler_params.on_demand_fee_variability, Perbill::from_percent(3)); + assert_eq!(v12.scheduler_params.on_demand_base_fee, 10_000_000); + assert_eq!(v12.scheduler_params.coretime_ttl, 5); } #[test] From d4e0771507c69d4e5fe084f8111cd75b00d1a195 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Mon, 5 Feb 2024 18:59:14 +0200 Subject: [PATCH 16/40] Fix compilation errors --- .../runtime/parachains/src/assigner_on_demand/benchmarking.rs | 2 +- polkadot/runtime/parachains/src/coretime/migration.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/benchmarking.rs b/polkadot/runtime/parachains/src/assigner_on_demand/benchmarking.rs index 5a6060cd2b4e..9d50f2a4a15f 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/benchmarking.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/benchmarking.rs @@ -43,7 +43,7 @@ where { ParasShared::::set_session_index(SESSION_INDEX); let mut config = HostConfiguration::default(); - config.coretime_cores = 1; + config.scheduler_params.coretime_cores = 1; ConfigurationPallet::::force_set_active_config(config); let mut parachains = ParachainsCache::new(); ParasPallet::::initialize_para_now( diff --git a/polkadot/runtime/parachains/src/coretime/migration.rs b/polkadot/runtime/parachains/src/coretime/migration.rs index c4cac731d772..53a859b658f8 100644 --- a/polkadot/runtime/parachains/src/coretime/migration.rs +++ b/polkadot/runtime/parachains/src/coretime/migration.rs @@ -114,7 +114,8 @@ mod v_coretime { let legacy_paras = paras::Parachains::::get(); let config = >::config(); - let total_core_count = config.coretime_cores + legacy_paras.len() as u32; + let total_core_count = + config.scheduler_params.coretime_cores + legacy_paras.len() as u32; let dmp_queue_size = crate::dmp::Pallet::::dmq_contents(T::BrokerId::get().into()).len() as u32; From eac919524d9d692fd94924186f1337df965ef352 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Mon, 5 Feb 2024 19:18:53 +0200 Subject: [PATCH 17/40] Add `MigrateToV12` to `Unreleased` --- polkadot/runtime/rococo/src/lib.rs | 1 + polkadot/runtime/westend/src/lib.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/polkadot/runtime/rococo/src/lib.rs b/polkadot/runtime/rococo/src/lib.rs index 79c848221fbf..47cf8c110792 100644 --- a/polkadot/runtime/rococo/src/lib.rs +++ b/polkadot/runtime/rococo/src/lib.rs @@ -1662,6 +1662,7 @@ pub mod migrations { parachains_configuration::migration::v11::MigrateToV11, // This needs to come after the `parachains_configuration` above as we are reading the configuration. coretime::migration::MigrateToCoretime, + parachains_configuration::migration::v12::MigrateToV12, ); } diff --git a/polkadot/runtime/westend/src/lib.rs b/polkadot/runtime/westend/src/lib.rs index cd9e57a9bdf2..71df7725e87e 100644 --- a/polkadot/runtime/westend/src/lib.rs +++ b/polkadot/runtime/westend/src/lib.rs @@ -1656,6 +1656,7 @@ pub mod migrations { // Migrate Identity pallet for Usernames pallet_identity::migration::versioned::V0ToV1, parachains_configuration::migration::v11::MigrateToV11, + parachains_configuration::migration::v12::MigrateToV12, ); } From f7a8ceb00776646198391581eb59acdf23e72866 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Tue, 6 Feb 2024 09:42:09 +0200 Subject: [PATCH 18/40] Fix outdated comments and spacing --- polkadot/primitives/src/vstaging/mod.rs | 2 +- polkadot/runtime/parachains/src/configuration.rs | 2 +- .../parachains/src/configuration/migration/v12.rs | 12 ++++++------ .../runtime/parachains/src/configuration/tests.rs | 1 - 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/polkadot/primitives/src/vstaging/mod.rs b/polkadot/primitives/src/vstaging/mod.rs index f66974f81adc..22fc47727b6e 100644 --- a/polkadot/primitives/src/vstaging/mod.rs +++ b/polkadot/primitives/src/vstaging/mod.rs @@ -51,7 +51,7 @@ impl Default for ApprovalVotingParams { } } -/// Coretime configuration parameters +/// Scheduler configuration parameters. All coretime/ondemand parameters are here. #[derive( RuntimeDebug, Copy, diff --git a/polkadot/runtime/parachains/src/configuration.rs b/polkadot/runtime/parachains/src/configuration.rs index 84f1ae46f865..c713805771d1 100644 --- a/polkadot/runtime/parachains/src/configuration.rs +++ b/polkadot/runtime/parachains/src/configuration.rs @@ -248,7 +248,7 @@ pub struct HostConfiguration { pub node_features: NodeFeatures, /// Params used by approval-voting pub approval_voting_params: ApprovalVotingParams, - /// Core time parameters + /// Scheduler parameters pub scheduler_params: SchedulerParams, } diff --git a/polkadot/runtime/parachains/src/configuration/migration/v12.rs b/polkadot/runtime/parachains/src/configuration/migration/v12.rs index c2ef00091fe4..bd4f651fec55 100644 --- a/polkadot/runtime/parachains/src/configuration/migration/v12.rs +++ b/polkadot/runtime/parachains/src/configuration/migration/v12.rs @@ -144,7 +144,7 @@ fn migrate_to_v12() -> Weight { async_backing_params : pre.async_backing_params, executor_params : pre.executor_params, minimum_backing_votes : pre.minimum_backing_votes, - node_features : pre.node_features, + node_features : pre.node_features, approval_voting_params : pre.approval_voting_params, scheduler_params: SchedulerParams { lookahead : pre.scheduling_lookahead, @@ -314,16 +314,16 @@ mod tests { assert_eq!(v11.minimum_validation_upgrade_delay , v12.minimum_validation_upgrade_delay); assert_eq!(v11.async_backing_params.allowed_ancestry_len, v12.async_backing_params.allowed_ancestry_len); assert_eq!(v11.async_backing_params.max_candidate_depth , v12.async_backing_params.max_candidate_depth); - assert_eq!(v11.executor_params , v12.executor_params); - assert_eq!(v11.minimum_backing_votes , v12.minimum_backing_votes); + assert_eq!(v11.executor_params , v12.executor_params); + assert_eq!(v11.minimum_backing_votes , v12.minimum_backing_votes); assert_eq!(v11.scheduling_lookahead , v12.scheduler_params.lookahead); assert_eq!(v11.coretime_cores , v12.scheduler_params.coretime_cores); assert_eq!(v11.on_demand_retries , v12.scheduler_params.coretime_max_availability_timeouts); assert_eq!(v11.on_demand_queue_max_size , v12.scheduler_params.on_demand_queue_max_size); assert_eq!(v11.on_demand_target_queue_utilization , v12.scheduler_params.on_demand_target_queue_utilization); - assert_eq!(v11.on_demand_fee_variability , v12.scheduler_params.on_demand_fee_variability); - assert_eq!(v11.on_demand_base_fee , v12.scheduler_params.on_demand_base_fee); - assert_eq!(v11.on_demand_ttl , v12.scheduler_params.coretime_ttl); + assert_eq!(v11.on_demand_fee_variability , v12.scheduler_params.on_demand_fee_variability); + assert_eq!(v11.on_demand_base_fee , v12.scheduler_params.on_demand_base_fee); + assert_eq!(v11.on_demand_ttl , v12.scheduler_params.coretime_ttl); }; // ; makes this a statement. `rustfmt::skip` cannot be put on an expression. } }); diff --git a/polkadot/runtime/parachains/src/configuration/tests.rs b/polkadot/runtime/parachains/src/configuration/tests.rs index 55955c61e658..3412139eff98 100644 --- a/polkadot/runtime/parachains/src/configuration/tests.rs +++ b/polkadot/runtime/parachains/src/configuration/tests.rs @@ -285,7 +285,6 @@ fn setting_pending_config_members() { max_head_data_size: 1_000, group_rotation_frequency: 20, paras_availability_period: 10, - max_validators_per_core: None, max_validators: None, dispute_period: 239, From c8412d887a70f81179e4fd6fb00fc1afaa0093f0 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Tue, 6 Feb 2024 16:23:08 +0200 Subject: [PATCH 19/40] Move `group_rotation_frequency`, `paras_availability_period` and `max_validators_per_core` to `SchedulerParams` --- polkadot/node/service/src/chain_spec.rs | 16 ++++++-- polkadot/node/test/service/src/chain_spec.rs | 11 +++-- polkadot/primitives/src/vstaging/mod.rs | 26 ++++++++++++ polkadot/runtime/parachains/src/builder.rs | 5 ++- .../runtime/parachains/src/configuration.rs | 41 ++++--------------- .../src/configuration/migration/v12.rs | 19 +++++---- .../parachains/src/configuration/tests.rs | 17 ++++---- .../runtime/parachains/src/inclusion/tests.rs | 6 +-- .../runtime/parachains/src/paras/tests.rs | 7 +++- polkadot/runtime/parachains/src/scheduler.rs | 13 +++--- .../runtime/parachains/src/scheduler/tests.rs | 12 +++--- 11 files changed, 99 insertions(+), 74 deletions(-) diff --git a/polkadot/node/service/src/chain_spec.rs b/polkadot/node/service/src/chain_spec.rs index 1b4a97290c6a..50a0d50a70db 100644 --- a/polkadot/node/service/src/chain_spec.rs +++ b/polkadot/node/service/src/chain_spec.rs @@ -20,7 +20,9 @@ use beefy_primitives::ecdsa_crypto::AuthorityId as BeefyId; use grandpa::AuthorityId as GrandpaId; #[cfg(feature = "westend-native")] use pallet_staking::Forcing; -use polkadot_primitives::{AccountId, AccountPublic, AssignmentId, ValidatorId}; +use polkadot_primitives::{ + vstaging::SchedulerParams, AccountId, AccountPublic, AssignmentId, ValidatorId, +}; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; use sp_consensus_babe::AuthorityId as BabeId; @@ -129,8 +131,6 @@ fn default_parachains_host_configuration( max_code_size: MAX_CODE_SIZE, max_pov_size: MAX_POV_SIZE, max_head_data_size: 32 * 1024, - group_rotation_frequency: 20, - paras_availability_period: 4, max_upward_queue_count: 8, max_upward_queue_size: 1024 * 1024, max_downward_message_size: 1024 * 1024, @@ -151,6 +151,11 @@ fn default_parachains_host_configuration( relay_vrf_modulo_samples: 2, zeroth_delay_tranche_width: 0, minimum_validation_upgrade_delay: 5, + scheduler_params: SchedulerParams { + group_rotation_frequency: 20, + paras_availability_period: 4, + ..Default::default() + }, ..Default::default() } } @@ -886,7 +891,10 @@ pub fn rococo_testnet_genesis( "sudo": { "key": Some(root_key.clone()) }, "configuration": { "config": polkadot_runtime_parachains::configuration::HostConfiguration { - max_validators_per_core: Some(1), + scheduler_params: SchedulerParams { + max_validators_per_core: Some(1), + ..default_parachains_host_configuration().scheduler_params + }, ..default_parachains_host_configuration() }, }, diff --git a/polkadot/node/test/service/src/chain_spec.rs b/polkadot/node/test/service/src/chain_spec.rs index 0295090b9521..ad73e036eeb5 100644 --- a/polkadot/node/test/service/src/chain_spec.rs +++ b/polkadot/node/test/service/src/chain_spec.rs @@ -19,7 +19,9 @@ use babe_primitives::AuthorityId as BabeId; use grandpa::AuthorityId as GrandpaId; use pallet_staking::Forcing; -use polkadot_primitives::{AccountId, AssignmentId, ValidatorId, MAX_CODE_SIZE, MAX_POV_SIZE}; +use polkadot_primitives::{ + vstaging::SchedulerParams, AccountId, AssignmentId, ValidatorId, MAX_CODE_SIZE, MAX_POV_SIZE, +}; use polkadot_service::chain_spec::{get_account_id_from_seed, get_from_seed, Extensions}; use polkadot_test_runtime::BABE_GENESIS_EPOCH_CONFIG; use sc_chain_spec::{ChainSpec, ChainType}; @@ -165,10 +167,13 @@ fn polkadot_testnet_genesis( max_code_size: MAX_CODE_SIZE, max_pov_size: MAX_POV_SIZE, max_head_data_size: 32 * 1024, - group_rotation_frequency: 20, - paras_availability_period: 4, no_show_slots: 10, minimum_validation_upgrade_delay: 5, + scheduler_params: SchedulerParams { + group_rotation_frequency: 20, + paras_availability_period: 4, + ..Default::default() + }, ..Default::default() }, } diff --git a/polkadot/primitives/src/vstaging/mod.rs b/polkadot/primitives/src/vstaging/mod.rs index 22fc47727b6e..9cfc5d3f9721 100644 --- a/polkadot/primitives/src/vstaging/mod.rs +++ b/polkadot/primitives/src/vstaging/mod.rs @@ -64,6 +64,29 @@ impl Default for ApprovalVotingParams { serde::Deserialize, )] pub struct SchedulerParams { + /// How often parachain groups should be rotated across parachains. + /// + /// Must be non-zero. + pub group_rotation_frequency: BlockNumber, + /// The minimum availability period, in blocks. + /// + /// This is the minimum amount of blocks after a core became occupied that validators have time + /// to make the block available. + /// + /// This value only has effect on group rotations. If backers backed something at the end of + /// their rotation, the occupied core affects the backing group that comes afterwards. We limit + /// the effect one backing group can have on the next to `paras_availability_period` blocks. + /// + /// Within a group rotation there is no timeout as backers are only affecting themselves. + /// + /// Must be at least 1. With a value of 1, the previous group will not be able to negatively + /// affect the following group at the expense of a tight availability timeline at group + /// rotation boundaries. + pub paras_availability_period: BlockNumber, + /// The maximum number of validators to have per core. + /// + /// `None` means no maximum. + pub max_validators_per_core: Option, /// The amount of blocks ahead to schedule paras. pub lookahead: u32, /// How many cores are managed by the coretime chain. @@ -88,6 +111,9 @@ pub struct SchedulerParams { impl> Default for SchedulerParams { fn default() -> Self { Self { + group_rotation_frequency: 1u32.into(), + paras_availability_period: 1u32.into(), + max_validators_per_core: Default::default(), lookahead: 1, coretime_cores: Default::default(), coretime_max_availability_timeouts: Default::default(), diff --git a/polkadot/runtime/parachains/src/builder.rs b/polkadot/runtime/parachains/src/builder.rs index 5bf7b90eb92b..762c90bed831 100644 --- a/polkadot/runtime/parachains/src/builder.rs +++ b/polkadot/runtime/parachains/src/builder.rs @@ -193,7 +193,10 @@ impl BenchBuilder { /// Maximum number of validators per core (a.k.a. max validators per group). This value is used /// if none is explicitly set on the builder. pub(crate) fn fallback_max_validators_per_core() -> u32 { - configuration::Pallet::::config().max_validators_per_core.unwrap_or(5) + configuration::Pallet::::config() + .scheduler_params + .max_validators_per_core + .unwrap_or(5) } /// Specify a mapping of core index/ para id to the number of dispute statements for the diff --git a/polkadot/runtime/parachains/src/configuration.rs b/polkadot/runtime/parachains/src/configuration.rs index c713805771d1..9a46b6181662 100644 --- a/polkadot/runtime/parachains/src/configuration.rs +++ b/polkadot/runtime/parachains/src/configuration.rs @@ -173,29 +173,6 @@ pub struct HostConfiguration { /// have concluded. pub code_retention_period: BlockNumber, - /// How often parachain groups should be rotated across parachains. - /// - /// Must be non-zero. - pub group_rotation_frequency: BlockNumber, - /// The minimum availability period, in blocks. - /// - /// This is the minimum amount of blocks after a core became occupied that validators have time - /// to make the block available. - /// - /// This value only has effect on group rotations. If backers backed something at the end of - /// their rotation, the occupied core affects the backing group that comes afterwards. We limit - /// the effect one backing group can have on the next to `paras_availability_period` blocks. - /// - /// Within a group rotation there is no timeout as backers are only affecting themselves. - /// - /// Must be at least 1. With a value of 1, the previous group will not be able to negatively - /// affect the following group at the expense of a tight availability timeline at group - /// rotation boundaries. - pub paras_availability_period: BlockNumber, - /// The maximum number of validators to have per core. - /// - /// `None` means no maximum. - pub max_validators_per_core: Option, /// The maximum number of validators to use for parachain consensus, period. /// /// `None` means no maximum. @@ -259,8 +236,6 @@ impl> Default for HostConfiguration> Default for HostConfiguration Result<(), InconsistentError> { use InconsistentError::*; - if self.group_rotation_frequency.is_zero() { + if self.scheduler_params.group_rotation_frequency.is_zero() { return Err(ZeroGroupRotationFrequency) } - if self.paras_availability_period.is_zero() { + if self.scheduler_params.paras_availability_period.is_zero() { return Err(ZeroParasAvailabilityPeriod) } @@ -376,10 +350,11 @@ where return Err(MaxPovSizeExceedHardLimit { max_pov_size: self.max_pov_size }) } - if self.minimum_validation_upgrade_delay <= self.paras_availability_period { + if self.minimum_validation_upgrade_delay <= self.scheduler_params.paras_availability_period + { return Err(MinimumValidationUpgradeDelayLessThanChainAvailabilityPeriod { minimum_validation_upgrade_delay: self.minimum_validation_upgrade_delay.clone(), - paras_availability_period: self.paras_availability_period.clone(), + paras_availability_period: self.scheduler_params.paras_availability_period.clone(), }) } @@ -682,7 +657,7 @@ pub mod pallet { ) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.group_rotation_frequency = new; + config.scheduler_params.group_rotation_frequency = new; }) } @@ -698,7 +673,7 @@ pub mod pallet { ) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.paras_availability_period = new; + config.scheduler_params.paras_availability_period = new; }) } @@ -727,7 +702,7 @@ pub mod pallet { ) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.max_validators_per_core = new; + config.scheduler_params.max_validators_per_core = new; }) } diff --git a/polkadot/runtime/parachains/src/configuration/migration/v12.rs b/polkadot/runtime/parachains/src/configuration/migration/v12.rs index bd4f651fec55..4864f6c20cef 100644 --- a/polkadot/runtime/parachains/src/configuration/migration/v12.rs +++ b/polkadot/runtime/parachains/src/configuration/migration/v12.rs @@ -128,9 +128,6 @@ fn migrate_to_v12() -> Weight { hrmp_max_parachain_outbound_channels : pre.hrmp_max_parachain_outbound_channels, hrmp_channel_max_message_size : pre.hrmp_channel_max_message_size, code_retention_period : pre.code_retention_period, - group_rotation_frequency : pre.group_rotation_frequency, - paras_availability_period : pre.paras_availability_period, - max_validators_per_core : pre.max_validators_per_core, max_validators : pre.max_validators, dispute_period : pre.dispute_period, dispute_post_conclusion_acceptance_period: pre.dispute_post_conclusion_acceptance_period, @@ -147,6 +144,9 @@ fn migrate_to_v12() -> Weight { node_features : pre.node_features, approval_voting_params : pre.approval_voting_params, scheduler_params: SchedulerParams { + group_rotation_frequency : pre.group_rotation_frequency, + paras_availability_period : pre.paras_availability_period, + max_validators_per_core : pre.max_validators_per_core, lookahead : pre.scheduling_lookahead, coretime_cores : pre.coretime_cores, coretime_max_availability_timeouts : pre.on_demand_retries, @@ -209,8 +209,8 @@ mod tests { // This exceeds the maximal line width length, but that's fine, since this is not code and // doesn't need to be read and also leaving it as one line allows to easily copy it. let raw_config = - hex_literal::hex![" - 0000300000800000080000000000100000c8000005000000050000000200000002000000000000000000000000005000000010000400000000000000000000000000000000000000000000000000000000000000000000000800000000200000040000000000100000b004000014000000040000000101000000000600000064000000020000001900000000000000020000000200000002000000050000000200000000010000000100000001000000000000001027000080b2e60e80c3c9018096980000000000000000000000000005000000" + hex_literal::hex![ + "0000300000800000080000000000100000c8000005000000050000000200000002000000000000000000000000005000000010000400000000000000000000000000000000000000000000000000000000000000000000000800000000200000040000000000100000b004000000060000006400000002000000190000000000000002000000020000000200000005000000020000000001000000140000000400000001010000000100000001000000000000001027000080b2e60e80c3c9018096980000000000000000000000000005000000" ]; let v12 = @@ -224,9 +224,10 @@ mod tests { assert_eq!(v12.hrmp_channel_max_message_size, 1_048_576); assert_eq!(v12.n_delay_tranches, 25); assert_eq!(v12.minimum_validation_upgrade_delay, 5); - assert_eq!(v12.group_rotation_frequency, 20); assert_eq!(v12.minimum_backing_votes, LEGACY_MIN_BACKING_VOTES); assert_eq!(v12.approval_voting_params.max_approval_coalesce_count, 1); + assert_eq!(v12.scheduler_params.group_rotation_frequency, 20); + assert_eq!(v12.scheduler_params.paras_availability_period, 4); assert_eq!(v12.scheduler_params.lookahead, 1); assert_eq!(v12.scheduler_params.coretime_cores, 1); assert_eq!(v12.scheduler_params.coretime_max_availability_timeouts, 0); @@ -300,9 +301,6 @@ mod tests { assert_eq!(v11.hrmp_max_parachain_inbound_channels , v12.hrmp_max_parachain_inbound_channels); assert_eq!(v11.hrmp_channel_max_message_size , v12.hrmp_channel_max_message_size); assert_eq!(v11.code_retention_period , v12.code_retention_period); - assert_eq!(v11.group_rotation_frequency , v12.group_rotation_frequency); - assert_eq!(v11.paras_availability_period , v12.paras_availability_period); - assert_eq!(v11.max_validators_per_core , v12.max_validators_per_core); assert_eq!(v11.max_validators , v12.max_validators); assert_eq!(v11.dispute_period , v12.dispute_period); assert_eq!(v11.no_show_slots , v12.no_show_slots); @@ -316,6 +314,9 @@ mod tests { assert_eq!(v11.async_backing_params.max_candidate_depth , v12.async_backing_params.max_candidate_depth); assert_eq!(v11.executor_params , v12.executor_params); assert_eq!(v11.minimum_backing_votes , v12.minimum_backing_votes); + assert_eq!(v11.group_rotation_frequency , v12.scheduler_params.group_rotation_frequency); + assert_eq!(v11.paras_availability_period , v12.scheduler_params.paras_availability_period); + assert_eq!(v11.max_validators_per_core , v12.scheduler_params.max_validators_per_core); assert_eq!(v11.scheduling_lookahead , v12.scheduler_params.lookahead); assert_eq!(v11.coretime_cores , v12.scheduler_params.coretime_cores); assert_eq!(v11.on_demand_retries , v12.scheduler_params.coretime_max_availability_timeouts); diff --git a/polkadot/runtime/parachains/src/configuration/tests.rs b/polkadot/runtime/parachains/src/configuration/tests.rs index 3412139eff98..c17b599c6e56 100644 --- a/polkadot/runtime/parachains/src/configuration/tests.rs +++ b/polkadot/runtime/parachains/src/configuration/tests.rs @@ -226,8 +226,11 @@ fn invariants() { ); ActiveConfig::::put(HostConfiguration { - paras_availability_period: 10, minimum_validation_upgrade_delay: 11, + scheduler_params: SchedulerParams { + paras_availability_period: 10, + ..Default::default() + }, ..Default::default() }); assert_err!( @@ -283,9 +286,6 @@ fn setting_pending_config_members() { max_code_size: 100_000, max_pov_size: 1024, max_head_data_size: 1_000, - group_rotation_frequency: 20, - paras_availability_period: 10, - max_validators_per_core: None, max_validators: None, dispute_period: 239, dispute_post_conclusion_acceptance_period: 10, @@ -314,6 +314,9 @@ fn setting_pending_config_members() { minimum_backing_votes: 5, node_features: bitvec![u8, Lsb0; 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1], scheduler_params: SchedulerParams { + group_rotation_frequency: 20, + paras_availability_period: 10, + max_validators_per_core: None, lookahead: 3, coretime_cores: 2, coretime_max_availability_timeouts: 5, @@ -356,7 +359,7 @@ fn setting_pending_config_members() { .unwrap(); Configuration::set_group_rotation_frequency( RuntimeOrigin::root(), - new_config.group_rotation_frequency, + new_config.scheduler_params.group_rotation_frequency, ) .unwrap(); // This comes out of order to satisfy the validity criteria for the chain and thread @@ -368,7 +371,7 @@ fn setting_pending_config_members() { .unwrap(); Configuration::set_paras_availability_period( RuntimeOrigin::root(), - new_config.paras_availability_period, + new_config.scheduler_params.paras_availability_period, ) .unwrap(); Configuration::set_scheduling_lookahead( @@ -378,7 +381,7 @@ fn setting_pending_config_members() { .unwrap(); Configuration::set_max_validators_per_core( RuntimeOrigin::root(), - new_config.max_validators_per_core, + new_config.scheduler_params.max_validators_per_core, ) .unwrap(); Configuration::set_max_validators(RuntimeOrigin::root(), new_config.max_validators) diff --git a/polkadot/runtime/parachains/src/inclusion/tests.rs b/polkadot/runtime/parachains/src/inclusion/tests.rs index 1b101a28a130..a7c0f8396d9b 100644 --- a/polkadot/runtime/parachains/src/inclusion/tests.rs +++ b/polkadot/runtime/parachains/src/inclusion/tests.rs @@ -50,7 +50,7 @@ fn default_config() -> HostConfiguration { config.scheduler_params.coretime_cores = 1; config.max_code_size = 0b100000; config.max_head_data_size = 0b100000; - config.group_rotation_frequency = u32::MAX; + config.scheduler_params.group_rotation_frequency = u32::MAX; config } @@ -380,7 +380,7 @@ fn collect_pending_cleans_up_pending() { (thread_a, ParaKind::Parathread), ]; let mut config = genesis_config(paras); - config.configuration.config.group_rotation_frequency = 3; + config.configuration.config.scheduler_params.group_rotation_frequency = 3; new_test_ext(config).execute_with(|| { let default_candidate = TestCandidateBuilder::default().build(); >::insert( @@ -1809,7 +1809,7 @@ fn check_allowed_relay_parents() { } let validator_public = validator_pubkeys(&validators); let mut config = genesis_config(paras); - config.configuration.config.group_rotation_frequency = 1; + config.configuration.config.scheduler_params.group_rotation_frequency = 1; new_test_ext(config).execute_with(|| { shared::Pallet::::set_active_validators_ascending(validator_public.clone()); diff --git a/polkadot/runtime/parachains/src/paras/tests.rs b/polkadot/runtime/parachains/src/paras/tests.rs index cca200c2765e..2d0383d6ddfc 100644 --- a/polkadot/runtime/parachains/src/paras/tests.rs +++ b/polkadot/runtime/parachains/src/paras/tests.rs @@ -17,7 +17,7 @@ use super::*; use frame_support::{assert_err, assert_ok, assert_storage_noop}; use keyring::Sr25519Keyring; -use primitives::{BlockNumber, PARACHAIN_KEY_TYPE_ID}; +use primitives::{vstaging::SchedulerParams, BlockNumber, PARACHAIN_KEY_TYPE_ID}; use sc_keystore::LocalKeystore; use sp_keystore::{Keystore, KeystorePtr}; use std::sync::Arc; @@ -899,7 +899,10 @@ fn full_parachain_cleanup_storage() { minimum_validation_upgrade_delay: 2, // Those are not relevant to this test. However, HostConfiguration is still a // subject for the consistency check. - paras_availability_period: 1, + scheduler_params: SchedulerParams { + paras_availability_period: 1, + ..Default::default() + }, ..Default::default() }, }, diff --git a/polkadot/runtime/parachains/src/scheduler.rs b/polkadot/runtime/parachains/src/scheduler.rs index 3c093d305e59..dd16c81ef761 100644 --- a/polkadot/runtime/parachains/src/scheduler.rs +++ b/polkadot/runtime/parachains/src/scheduler.rs @@ -224,7 +224,7 @@ impl Pallet { let n_cores = core::cmp::max( T::AssignmentProvider::session_core_count(), - match config.max_validators_per_core { + match config.scheduler_params.max_validators_per_core { Some(x) if x != 0 => validators.len() as u32 / x, _ => 0, }, @@ -429,7 +429,7 @@ impl Pallet { } let rotations_since_session_start: BlockNumberFor = - (at - session_start_block) / config.group_rotation_frequency; + (at - session_start_block) / config.scheduler_params.group_rotation_frequency; let rotations_since_session_start = as TryInto>::try_into(rotations_since_session_start) @@ -461,9 +461,9 @@ impl Pallet { // Note: blocks backed in this rotation will never time out here as backed_in + // config.paras_availability_period will always be > now for these blocks, as // otherwise above condition would not be true. - pending_since + config.paras_availability_period + pending_since + config.scheduler_params.paras_availability_period } else { - next_rotation + config.paras_availability_period + next_rotation + config.scheduler_params.paras_availability_period }; AvailabilityTimeoutStatus { timed_out: time_out_at <= now, live_until: time_out_at } @@ -479,7 +479,8 @@ impl Pallet { let now = >::block_number() + One::one(); let rotation_info = Self::group_rotation_info(now); - let current_window = rotation_info.last_rotation_at() + config.paras_availability_period; + let current_window = + rotation_info.last_rotation_at() + config.scheduler_params.paras_availability_period; now < current_window } @@ -489,7 +490,7 @@ impl Pallet { ) -> GroupRotationInfo> { let session_start_block = Self::session_start_block(); let group_rotation_frequency = - >::config().group_rotation_frequency; + >::config().scheduler_params.group_rotation_frequency; GroupRotationInfo { session_start_block, now, group_rotation_frequency } } diff --git a/polkadot/runtime/parachains/src/scheduler/tests.rs b/polkadot/runtime/parachains/src/scheduler/tests.rs index e74d4941c9e8..b539c0a0e7ba 100644 --- a/polkadot/runtime/parachains/src/scheduler/tests.rs +++ b/polkadot/runtime/parachains/src/scheduler/tests.rs @@ -105,14 +105,14 @@ fn run_to_end_of_block( fn default_config() -> HostConfiguration { HostConfiguration { - group_rotation_frequency: 10, - paras_availability_period: 3, // This field does not affect anything that scheduler does. However, `HostConfiguration` // is still a subject to consistency test. It requires that // `minimum_validation_upgrade_delay` is greater than `chain_availability_period` and // `thread_availability_period`. minimum_validation_upgrade_delay: 6, scheduler_params: SchedulerParams { + group_rotation_frequency: 10, + paras_availability_period: 3, lookahead: 2, coretime_cores: 3, coretime_max_availability_timeouts: 1, @@ -295,7 +295,7 @@ fn session_change_shuffles_validators() { fn session_change_takes_only_max_per_core() { let config = { let mut config = default_config(); - config.max_validators_per_core = Some(1); + config.scheduler_params.max_validators_per_core = Some(1); config }; @@ -668,7 +668,7 @@ fn schedule_rotates_groups() { config }; - let rotation_frequency = config.group_rotation_frequency; + let rotation_frequency = config.scheduler_params.group_rotation_frequency; let on_demand_cores = 2; let genesis_config = genesis_config(&config); @@ -877,8 +877,8 @@ fn on_demand_claims_are_pruned_after_timing_out() { fn availability_predicate_works() { let genesis_config = genesis_config(&default_config()); - let HostConfiguration { group_rotation_frequency, paras_availability_period, .. } = - default_config(); + let SchedulerParams { group_rotation_frequency, paras_availability_period, .. } = + default_config().scheduler_params; assert!(paras_availability_period < group_rotation_frequency); From 9e31af747e3ed5d6b1f33ce8a10bab24651e3fae Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Tue, 6 Feb 2024 16:25:27 +0200 Subject: [PATCH 20/40] `coretime_max_availability_timeouts` -> `max_availability_timeouts`; `coretime_ttl` -> `ttl` --- polkadot/primitives/src/vstaging/mod.rs | 8 ++++---- polkadot/runtime/parachains/src/builder.rs | 4 ++-- polkadot/runtime/parachains/src/configuration.rs | 4 ++-- .../parachains/src/configuration/migration/v12.rs | 12 ++++++------ .../runtime/parachains/src/configuration/tests.rs | 6 +++--- polkadot/runtime/parachains/src/scheduler.rs | 11 +++++------ polkadot/runtime/parachains/src/scheduler/tests.rs | 12 ++++++------ 7 files changed, 28 insertions(+), 29 deletions(-) diff --git a/polkadot/primitives/src/vstaging/mod.rs b/polkadot/primitives/src/vstaging/mod.rs index 9cfc5d3f9721..df51301a25dd 100644 --- a/polkadot/primitives/src/vstaging/mod.rs +++ b/polkadot/primitives/src/vstaging/mod.rs @@ -92,7 +92,7 @@ pub struct SchedulerParams { /// How many cores are managed by the coretime chain. pub coretime_cores: u32, /// The max number of times a claim can time out in availability - pub coretime_max_availability_timeouts: u32, + pub max_availability_timeouts: u32, /// The maximum queue size of the pay as you go module. pub on_demand_queue_max_size: u32, /// The target utilization of the spot price queue in percentages. @@ -105,7 +105,7 @@ pub struct SchedulerParams { /// The number of blocks a claim stays in the scheduler's claimqueue before getting cleared. /// This number should go reasonably higher than the number of blocks in the async backing /// lookahead. - pub coretime_ttl: BlockNumber, + pub ttl: BlockNumber, } impl> Default for SchedulerParams { @@ -116,12 +116,12 @@ impl> Default for SchedulerParams max_validators_per_core: Default::default(), lookahead: 1, coretime_cores: Default::default(), - coretime_max_availability_timeouts: Default::default(), + max_availability_timeouts: Default::default(), on_demand_queue_max_size: ON_DEMAND_DEFAULT_QUEUE_MAX_SIZE, on_demand_target_queue_utilization: Perbill::from_percent(25), on_demand_fee_variability: Perbill::from_percent(3), on_demand_base_fee: 10_000_000u128, - coretime_ttl: 5u32.into(), + ttl: 5u32.into(), } } } diff --git a/polkadot/runtime/parachains/src/builder.rs b/polkadot/runtime/parachains/src/builder.rs index 762c90bed831..02ade20d3a84 100644 --- a/polkadot/runtime/parachains/src/builder.rs +++ b/polkadot/runtime/parachains/src/builder.rs @@ -713,7 +713,7 @@ impl BenchBuilder { let cores = (0..used_cores) .into_iter() .map(|i| { - let ttl = configuration::Pallet::::config().scheduler_params.coretime_ttl; + let ttl = configuration::Pallet::::config().scheduler_params.ttl; // Load an assignment into provider so that one is present to pop let assignment = ::AssignmentProvider::get_mock_assignment( CoreIndex(i), @@ -728,7 +728,7 @@ impl BenchBuilder { let cores = (0..used_cores) .into_iter() .map(|i| { - let ttl = configuration::Pallet::::config().scheduler_params.coretime_ttl; + let ttl = configuration::Pallet::::config().scheduler_params.ttl; // Load an assignment into provider so that one is present to pop let assignment = ::AssignmentProvider::get_mock_assignment( diff --git a/polkadot/runtime/parachains/src/configuration.rs b/polkadot/runtime/parachains/src/configuration.rs index 9a46b6181662..1a5db05690e3 100644 --- a/polkadot/runtime/parachains/src/configuration.rs +++ b/polkadot/runtime/parachains/src/configuration.rs @@ -641,7 +641,7 @@ pub mod pallet { pub fn set_on_demand_retries(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.scheduler_params.coretime_max_availability_timeouts = new; + config.scheduler_params.max_availability_timeouts = new; }) } @@ -1147,7 +1147,7 @@ pub mod pallet { pub fn set_on_demand_ttl(origin: OriginFor, new: BlockNumberFor) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.scheduler_params.coretime_ttl = new; + config.scheduler_params.ttl = new; }) } diff --git a/polkadot/runtime/parachains/src/configuration/migration/v12.rs b/polkadot/runtime/parachains/src/configuration/migration/v12.rs index 4864f6c20cef..b0bd56fdf419 100644 --- a/polkadot/runtime/parachains/src/configuration/migration/v12.rs +++ b/polkadot/runtime/parachains/src/configuration/migration/v12.rs @@ -149,12 +149,12 @@ fn migrate_to_v12() -> Weight { max_validators_per_core : pre.max_validators_per_core, lookahead : pre.scheduling_lookahead, coretime_cores : pre.coretime_cores, - coretime_max_availability_timeouts : pre.on_demand_retries, + max_availability_timeouts : pre.on_demand_retries, on_demand_queue_max_size : pre.on_demand_queue_max_size, on_demand_target_queue_utilization : pre.on_demand_target_queue_utilization, on_demand_fee_variability : pre.on_demand_fee_variability, on_demand_base_fee : pre.on_demand_base_fee, - coretime_ttl : pre.on_demand_ttl, + ttl : pre.on_demand_ttl, } } }; @@ -230,7 +230,7 @@ mod tests { assert_eq!(v12.scheduler_params.paras_availability_period, 4); assert_eq!(v12.scheduler_params.lookahead, 1); assert_eq!(v12.scheduler_params.coretime_cores, 1); - assert_eq!(v12.scheduler_params.coretime_max_availability_timeouts, 0); + assert_eq!(v12.scheduler_params.max_availability_timeouts, 0); assert_eq!(v12.scheduler_params.on_demand_queue_max_size, 10_000); assert_eq!( v12.scheduler_params.on_demand_target_queue_utilization, @@ -238,7 +238,7 @@ mod tests { ); assert_eq!(v12.scheduler_params.on_demand_fee_variability, Perbill::from_percent(3)); assert_eq!(v12.scheduler_params.on_demand_base_fee, 10_000_000); - assert_eq!(v12.scheduler_params.coretime_ttl, 5); + assert_eq!(v12.scheduler_params.ttl, 5); } #[test] @@ -319,12 +319,12 @@ mod tests { assert_eq!(v11.max_validators_per_core , v12.scheduler_params.max_validators_per_core); assert_eq!(v11.scheduling_lookahead , v12.scheduler_params.lookahead); assert_eq!(v11.coretime_cores , v12.scheduler_params.coretime_cores); - assert_eq!(v11.on_demand_retries , v12.scheduler_params.coretime_max_availability_timeouts); + assert_eq!(v11.on_demand_retries , v12.scheduler_params.max_availability_timeouts); assert_eq!(v11.on_demand_queue_max_size , v12.scheduler_params.on_demand_queue_max_size); assert_eq!(v11.on_demand_target_queue_utilization , v12.scheduler_params.on_demand_target_queue_utilization); assert_eq!(v11.on_demand_fee_variability , v12.scheduler_params.on_demand_fee_variability); assert_eq!(v11.on_demand_base_fee , v12.scheduler_params.on_demand_base_fee); - assert_eq!(v11.on_demand_ttl , v12.scheduler_params.coretime_ttl); + assert_eq!(v11.on_demand_ttl , v12.scheduler_params.ttl); }; // ; makes this a statement. `rustfmt::skip` cannot be put on an expression. } }); diff --git a/polkadot/runtime/parachains/src/configuration/tests.rs b/polkadot/runtime/parachains/src/configuration/tests.rs index c17b599c6e56..e9d0174fadfe 100644 --- a/polkadot/runtime/parachains/src/configuration/tests.rs +++ b/polkadot/runtime/parachains/src/configuration/tests.rs @@ -319,12 +319,12 @@ fn setting_pending_config_members() { max_validators_per_core: None, lookahead: 3, coretime_cores: 2, - coretime_max_availability_timeouts: 5, + max_availability_timeouts: 5, on_demand_queue_max_size: 10_000u32, on_demand_base_fee: 10_000_000u128, on_demand_fee_variability: Perbill::from_percent(3), on_demand_target_queue_utilization: Perbill::from_percent(25), - coretime_ttl: 5u32, + ttl: 5u32, }, }; @@ -354,7 +354,7 @@ fn setting_pending_config_members() { .unwrap(); Configuration::set_on_demand_retries( RuntimeOrigin::root(), - new_config.scheduler_params.coretime_max_availability_timeouts, + new_config.scheduler_params.max_availability_timeouts, ) .unwrap(); Configuration::set_group_rotation_frequency( diff --git a/polkadot/runtime/parachains/src/scheduler.rs b/polkadot/runtime/parachains/src/scheduler.rs index dd16c81ef761..c19dba78f7a4 100644 --- a/polkadot/runtime/parachains/src/scheduler.rs +++ b/polkadot/runtime/parachains/src/scheduler.rs @@ -352,7 +352,7 @@ impl Pallet { fn drop_expired_claims_from_claimqueue() { let now = >::block_number(); let availability_cores = AvailabilityCores::::get(); - let ttl = >::config().scheduler_params.coretime_ttl; + let ttl = >::config().scheduler_params.ttl; ClaimQueue::::mutate(|cq| { for (idx, _) in (0u32..).zip(availability_cores) { @@ -510,9 +510,8 @@ impl Pallet { /// Return the next thing that will be scheduled on this core assuming it is currently /// occupied and the candidate occupying it times out. pub(crate) fn next_up_on_time_out(core: CoreIndex) -> Option { - let max_availability_timeouts = >::config() - .scheduler_params - .coretime_max_availability_timeouts; + let max_availability_timeouts = + >::config().scheduler_params.max_availability_timeouts; Self::next_up_on_available(core).or_else(|| { // Or, if none, the claim currently occupying the core, // as it would be put back on the queue after timing out if number of retries is not at @@ -587,8 +586,8 @@ impl Pallet { let n_session_cores = T::AssignmentProvider::session_core_count(); let cq = ClaimQueue::::get(); let config = >::config(); - let max_availability_timeouts = config.scheduler_params.coretime_max_availability_timeouts; - let ttl = config.scheduler_params.coretime_ttl; + let max_availability_timeouts = config.scheduler_params.max_availability_timeouts; + let ttl = config.scheduler_params.ttl; for core_idx in 0..n_session_cores { let core_idx = CoreIndex::from(core_idx); diff --git a/polkadot/runtime/parachains/src/scheduler/tests.rs b/polkadot/runtime/parachains/src/scheduler/tests.rs index b539c0a0e7ba..1117d1ea7c25 100644 --- a/polkadot/runtime/parachains/src/scheduler/tests.rs +++ b/polkadot/runtime/parachains/src/scheduler/tests.rs @@ -115,7 +115,7 @@ fn default_config() -> HostConfiguration { paras_availability_period: 3, lookahead: 2, coretime_cores: 3, - coretime_max_availability_timeouts: 1, + max_availability_timeouts: 1, ..Default::default() }, ..Default::default() @@ -169,7 +169,7 @@ fn claimqueue_ttl_drop_fn_works() { let mut now = 10; new_test_ext(genesis_config).execute_with(|| { - assert!(config.scheduler_params.coretime_ttl == 5); + assert!(config.scheduler_params.ttl == 5); // Register and run to a blockheight where the para is in a valid state. schedule_blank_para(para_id); run_to_block(now, |n| if n == now { Some(Default::default()) } else { None }); @@ -348,7 +348,7 @@ fn fill_claimqueue_fills() { new_test_ext(genesis_config).execute_with(|| { MockAssigner::set_core_count(2); - let coretime_ttl = config.scheduler_params.coretime_ttl; + let coretime_ttl = config.scheduler_params.ttl; // Add 3 paras schedule_blank_para(para_a); @@ -751,8 +751,8 @@ fn on_demand_claims_are_pruned_after_timing_out() { let mut config = default_config(); config.scheduler_params.lookahead = 1; // Need more timeouts for this test - config.scheduler_params.coretime_max_availability_timeouts = max_retries; - config.scheduler_params.coretime_ttl = BlockNumber::from(5u32); + config.scheduler_params.max_availability_timeouts = max_retries; + config.scheduler_params.ttl = BlockNumber::from(5u32); let genesis_config = genesis_config(&config); let para_a = ParaId::from(1_u32); @@ -1059,7 +1059,7 @@ fn session_change_requires_reschedule_dropping_removed_paras() { new_test_ext(genesis_config).execute_with(|| { // Setting explicit core count MockAssigner::set_core_count(5); - let coretime_ttl = >::config().scheduler_params.coretime_ttl; + let coretime_ttl = >::config().scheduler_params.ttl; schedule_blank_para(para_a); schedule_blank_para(para_b); From 95641a3244f040a6362c5e3ece9523328210f79b Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Tue, 6 Feb 2024 16:48:10 +0200 Subject: [PATCH 21/40] Check `ttl` and `lookahead` in `check_consistency` --- polkadot/runtime/parachains/src/configuration.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/polkadot/runtime/parachains/src/configuration.rs b/polkadot/runtime/parachains/src/configuration.rs index 1a5db05690e3..6f1317f45a95 100644 --- a/polkadot/runtime/parachains/src/configuration.rs +++ b/polkadot/runtime/parachains/src/configuration.rs @@ -310,6 +310,8 @@ pub enum InconsistentError { ZeroMinimumBackingVotes, /// `executor_params` are inconsistent. InconsistentExecutorParams { inner: ExecutorParamError }, + /// TTL should be bigger than lookahead + LookaheadExceedsTTL, } impl HostConfiguration @@ -399,6 +401,10 @@ where return Err(InconsistentExecutorParams { inner }) } + if self.scheduler_params.ttl < self.scheduler_params.lookahead.into() { + return Err(LookaheadExceedsTTL) + } + Ok(()) } From 0c3a7d170702443f119296f2e6a17c7e59fdd115 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Wed, 7 Feb 2024 09:43:53 +0200 Subject: [PATCH 22/40] Fix a typo --- polkadot/runtime/parachains/src/configuration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/runtime/parachains/src/configuration.rs b/polkadot/runtime/parachains/src/configuration.rs index 6f1317f45a95..7cbb078137da 100644 --- a/polkadot/runtime/parachains/src/configuration.rs +++ b/polkadot/runtime/parachains/src/configuration.rs @@ -1352,7 +1352,7 @@ impl Pallet { let base_config_consistent = base_config.check_consistency().is_ok(); // Now, we need to decide what the new configuration should be. - // We also move the `base_config` to `new_config` to empahsize that the base config was + // We also move the `base_config` to `new_config` to emphasize that the base config was // destroyed by the `updater`. updater(&mut base_config); let new_config = base_config; From e8f3f156bc831a19a28a33f94de8fa6a02a3dda7 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Wed, 7 Feb 2024 11:17:54 +0200 Subject: [PATCH 23/40] Fix a warning --- polkadot/node/service/src/chain_spec.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/polkadot/node/service/src/chain_spec.rs b/polkadot/node/service/src/chain_spec.rs index e1de6be0faef..25815f6b9f54 100644 --- a/polkadot/node/service/src/chain_spec.rs +++ b/polkadot/node/service/src/chain_spec.rs @@ -20,9 +20,7 @@ use beefy_primitives::ecdsa_crypto::AuthorityId as BeefyId; use grandpa::AuthorityId as GrandpaId; #[cfg(feature = "westend-native")] use pallet_staking::Forcing; -use polkadot_primitives::{ - vstaging::SchedulerParams, AccountId, AccountPublic, AssignmentId, ValidatorId, -}; +use polkadot_primitives::{AccountId, AccountPublic, AssignmentId, ValidatorId}; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; use sp_consensus_babe::AuthorityId as BabeId; From 174d6f26fd6e1934b43c372420778f8a7c271fe5 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Wed, 7 Feb 2024 13:08:16 +0200 Subject: [PATCH 24/40] Fix doc comments and missing imports --- polkadot/node/service/src/chain_spec.rs | 4 +++- polkadot/runtime/parachains/src/configuration.rs | 8 ++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/polkadot/node/service/src/chain_spec.rs b/polkadot/node/service/src/chain_spec.rs index 25815f6b9f54..e1de6be0faef 100644 --- a/polkadot/node/service/src/chain_spec.rs +++ b/polkadot/node/service/src/chain_spec.rs @@ -20,7 +20,9 @@ use beefy_primitives::ecdsa_crypto::AuthorityId as BeefyId; use grandpa::AuthorityId as GrandpaId; #[cfg(feature = "westend-native")] use pallet_staking::Forcing; -use polkadot_primitives::{AccountId, AccountPublic, AssignmentId, ValidatorId}; +use polkadot_primitives::{ + vstaging::SchedulerParams, AccountId, AccountPublic, AssignmentId, ValidatorId, +}; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; use sp_consensus_babe::AuthorityId as BabeId; diff --git a/polkadot/runtime/parachains/src/configuration.rs b/polkadot/runtime/parachains/src/configuration.rs index 7cbb078137da..ed539def4f50 100644 --- a/polkadot/runtime/parachains/src/configuration.rs +++ b/polkadot/runtime/parachains/src/configuration.rs @@ -118,9 +118,9 @@ pub struct HostConfiguration { /// been completed. /// /// Note, there are situations in which `expected_at` in the past. For example, if - /// [`paras_availability_period`](Self::paras_availability_period) is less than the delay set - /// by this field or if PVF pre-check took more time than the delay. In such cases, the upgrade - /// is further at the earliest possible time determined by + /// [`paras_availability_period`](SchedulerParams::paras_availability_period) is less than the + /// delay set by this field or if PVF pre-check took more time than the delay. In such cases, + /// the upgrade is further at the earliest possible time determined by /// [`minimum_validation_upgrade_delay`](Self::minimum_validation_upgrade_delay). /// /// The rationale for this delay has to do with relay-chain reversions. In case there is an @@ -216,7 +216,7 @@ pub struct HostConfiguration { /// scheduled. This number is controlled by this field. /// /// This value should be greater than - /// [`paras_availability_period`](Self::paras_availability_period). + /// [`paras_availability_period`](SchedulerParams::paras_availability_period). pub minimum_validation_upgrade_delay: BlockNumber, /// The minimum number of valid backing statements required to consider a parachain candidate /// backable. From 7f68b9a28e3e950442222e769a6dd1a703c255fa Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Wed, 7 Feb 2024 14:17:03 +0200 Subject: [PATCH 25/40] Fix warnings again --- polkadot/node/service/src/chain_spec.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/polkadot/node/service/src/chain_spec.rs b/polkadot/node/service/src/chain_spec.rs index e1de6be0faef..af05af87a46b 100644 --- a/polkadot/node/service/src/chain_spec.rs +++ b/polkadot/node/service/src/chain_spec.rs @@ -20,12 +20,12 @@ use beefy_primitives::ecdsa_crypto::AuthorityId as BeefyId; use grandpa::AuthorityId as GrandpaId; #[cfg(feature = "westend-native")] use pallet_staking::Forcing; -use polkadot_primitives::{ - vstaging::SchedulerParams, AccountId, AccountPublic, AssignmentId, ValidatorId, -}; +use polkadot_primitives::{AccountId, AccountPublic, AssignmentId, ValidatorId}; use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; use sp_consensus_babe::AuthorityId as BabeId; +#[cfg(any(feature = "rococo-native", feature = "westend-native",))] +use polkadot_primitives::vstaging::SchedulerParams; #[cfg(feature = "rococo-native")] use rococo_runtime as rococo; #[cfg(feature = "rococo-native")] From 0b05200a006ff6ee083c649991443b953a98508c Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Thu, 8 Feb 2024 10:05:04 +0200 Subject: [PATCH 26/40] `set_scheduler_params` dispatchable and benchmark --- .../runtime/parachains/src/configuration.rs | 20 +++++++++++++++++++ .../src/configuration/benchmarking.rs | 2 ++ .../runtime_parachains_configuration.rs | 4 ++++ .../runtime_parachains_configuration.rs | 4 ++++ 4 files changed, 30 insertions(+) diff --git a/polkadot/runtime/parachains/src/configuration.rs b/polkadot/runtime/parachains/src/configuration.rs index ed539def4f50..9b4688da9712 100644 --- a/polkadot/runtime/parachains/src/configuration.rs +++ b/polkadot/runtime/parachains/src/configuration.rs @@ -429,6 +429,7 @@ pub trait WeightInfo { fn set_config_with_executor_params() -> Weight; fn set_config_with_perbill() -> Weight; fn set_node_feature() -> Weight; + fn set_config_with_scheduler_params() -> Weight; } pub struct TestWeightInfo; @@ -457,6 +458,9 @@ impl WeightInfo for TestWeightInfo { fn set_node_feature() -> Weight { Weight::MAX } + fn set_config_with_scheduler_params() -> Weight { + Weight::MAX + } } #[frame_support::pallet] @@ -1203,6 +1207,22 @@ pub mod pallet { config.approval_voting_params = new; }) } + + /// Set scheduler-params. + #[pallet::call_index(55)] + #[pallet::weight(( + T::WeightInfo::set_config_with_scheduler_params(), + DispatchClass::Operational, + ))] + pub fn set_scheduler_params( + origin: OriginFor, + new: SchedulerParams>, + ) -> DispatchResult { + ensure_root(origin)?; + Self::schedule_config_update(|config| { + config.scheduler_params = new; + }) + } } impl Pallet { diff --git a/polkadot/runtime/parachains/src/configuration/benchmarking.rs b/polkadot/runtime/parachains/src/configuration/benchmarking.rs index 67daf1c45988..882b5aab096a 100644 --- a/polkadot/runtime/parachains/src/configuration/benchmarking.rs +++ b/polkadot/runtime/parachains/src/configuration/benchmarking.rs @@ -51,6 +51,8 @@ benchmarks! { set_node_feature{}: set_node_feature(RawOrigin::Root, 255, true) + set_config_with_scheduler_params {} : set_scheduler_params(RawOrigin::Root, SchedulerParams::default()) + impl_benchmark_test_suite!( Pallet, crate::mock::new_test_ext(Default::default()), diff --git a/polkadot/runtime/rococo/src/weights/runtime_parachains_configuration.rs b/polkadot/runtime/rococo/src/weights/runtime_parachains_configuration.rs index 34541b83597e..a9c488c00a15 100644 --- a/polkadot/runtime/rococo/src/weights/runtime_parachains_configuration.rs +++ b/polkadot/runtime/rococo/src/weights/runtime_parachains_configuration.rs @@ -170,4 +170,8 @@ impl runtime_parachains::configuration::WeightInfo for .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) } + + fn set_config_with_scheduler_params() -> Weight { + Weight::zero() + } } diff --git a/polkadot/runtime/westend/src/weights/runtime_parachains_configuration.rs b/polkadot/runtime/westend/src/weights/runtime_parachains_configuration.rs index 3a4813b667c6..e049339a375b 100644 --- a/polkadot/runtime/westend/src/weights/runtime_parachains_configuration.rs +++ b/polkadot/runtime/westend/src/weights/runtime_parachains_configuration.rs @@ -170,4 +170,8 @@ impl runtime_parachains::configuration::WeightInfo for .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) } + + fn set_config_with_scheduler_params() -> Weight { + Weight::zero() + } } From 687bf01b481fe981bf73ec160800b3ccdbdf8f5f Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Thu, 8 Feb 2024 09:48:06 +0000 Subject: [PATCH 27/40] ".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime=rococo --target_dir=polkadot --pallet=runtime_parachains::configuration --- .../runtime_parachains_configuration.rs | 50 ++++++++++++------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/polkadot/runtime/rococo/src/weights/runtime_parachains_configuration.rs b/polkadot/runtime/rococo/src/weights/runtime_parachains_configuration.rs index a9c488c00a15..ca0575cb1b64 100644 --- a/polkadot/runtime/rococo/src/weights/runtime_parachains_configuration.rs +++ b/polkadot/runtime/rococo/src/weights/runtime_parachains_configuration.rs @@ -16,10 +16,10 @@ //! Autogenerated weights for `runtime_parachains::configuration` //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-11-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-02-08, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-yprdrvc7-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! HOSTNAME: `runner-bn-ce5rx-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("rococo-dev")`, DB CACHE: 1024 // Executed Command: @@ -58,8 +58,8 @@ impl runtime_parachains::configuration::WeightInfo for // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 7_793_000 picoseconds. - Weight::from_parts(8_192_000, 0) + // Minimum execution time: 7_789_000 picoseconds. + Weight::from_parts(8_269_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -74,8 +74,8 @@ impl runtime_parachains::configuration::WeightInfo for // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 7_819_000 picoseconds. - Weight::from_parts(8_004_000, 0) + // Minimum execution time: 7_851_000 picoseconds. + Weight::from_parts(8_152_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -90,8 +90,8 @@ impl runtime_parachains::configuration::WeightInfo for // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 7_760_000 picoseconds. - Weight::from_parts(8_174_000, 0) + // Minimum execution time: 7_960_000 picoseconds. + Weight::from_parts(8_276_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -116,8 +116,8 @@ impl runtime_parachains::configuration::WeightInfo for // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 7_814_000 picoseconds. - Weight::from_parts(8_098_000, 0) + // Minimum execution time: 7_912_000 picoseconds. + Weight::from_parts(8_164_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -132,8 +132,8 @@ impl runtime_parachains::configuration::WeightInfo for // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 10_028_000 picoseconds. - Weight::from_parts(10_386_000, 0) + // Minimum execution time: 9_782_000 picoseconds. + Weight::from_parts(10_373_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -148,8 +148,8 @@ impl runtime_parachains::configuration::WeightInfo for // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 7_867_000 picoseconds. - Weight::from_parts(8_191_000, 0) + // Minimum execution time: 7_870_000 picoseconds. + Weight::from_parts(8_274_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -164,14 +164,26 @@ impl runtime_parachains::configuration::WeightInfo for // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 10_158_000 picoseconds. - Weight::from_parts(10_430_000, 0) + // Minimum execution time: 9_960_000 picoseconds. + Weight::from_parts(10_514_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) } - + /// Storage: `Configuration::PendingConfigs` (r:1 w:1) + /// Proof: `Configuration::PendingConfigs` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Configuration::BypassConsistencyCheck` (r:1 w:0) + /// Proof: `Configuration::BypassConsistencyCheck` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParasShared::CurrentSessionIndex` (r:1 w:0) + /// Proof: `ParasShared::CurrentSessionIndex` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) fn set_config_with_scheduler_params() -> Weight { - Weight::zero() + // Proof Size summary in bytes: + // Measured: `151` + // Estimated: `1636` + // Minimum execution time: 7_913_000 picoseconds. + Weight::from_parts(8_338_000, 0) + .saturating_add(Weight::from_parts(0, 1636)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(1)) } } From 5af1f42cc594c77908942b00f900f3151737130b Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Thu, 8 Feb 2024 09:49:09 +0000 Subject: [PATCH 28/40] ".git/.scripts/commands/bench/bench.sh" --subcommand=pallet --runtime=westend --target_dir=polkadot --pallet=runtime_parachains::configuration --- .../runtime_parachains_configuration.rs | 50 ++++++++++++------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/polkadot/runtime/westend/src/weights/runtime_parachains_configuration.rs b/polkadot/runtime/westend/src/weights/runtime_parachains_configuration.rs index e049339a375b..8fa3207c6446 100644 --- a/polkadot/runtime/westend/src/weights/runtime_parachains_configuration.rs +++ b/polkadot/runtime/westend/src/weights/runtime_parachains_configuration.rs @@ -16,10 +16,10 @@ //! Autogenerated weights for `runtime_parachains::configuration` //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-11-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-02-08, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` //! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runner-yprdrvc7-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` +//! HOSTNAME: `runner-bn-ce5rx-project-674-concurrent-0`, CPU: `Intel(R) Xeon(R) CPU @ 2.60GHz` //! WASM-EXECUTION: `Compiled`, CHAIN: `Some("westend-dev")`, DB CACHE: 1024 // Executed Command: @@ -58,8 +58,8 @@ impl runtime_parachains::configuration::WeightInfo for // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 8_065_000 picoseconds. - Weight::from_parts(8_389_000, 0) + // Minimum execution time: 7_775_000 picoseconds. + Weight::from_parts(8_036_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -74,8 +74,8 @@ impl runtime_parachains::configuration::WeightInfo for // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 8_038_000 picoseconds. - Weight::from_parts(8_463_000, 0) + // Minimum execution time: 7_708_000 picoseconds. + Weight::from_parts(7_971_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -90,8 +90,8 @@ impl runtime_parachains::configuration::WeightInfo for // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 7_843_000 picoseconds. - Weight::from_parts(8_216_000, 0) + // Minimum execution time: 7_746_000 picoseconds. + Weight::from_parts(8_028_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -116,8 +116,8 @@ impl runtime_parachains::configuration::WeightInfo for // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 7_969_000 picoseconds. - Weight::from_parts(8_362_000, 0) + // Minimum execution time: 7_729_000 picoseconds. + Weight::from_parts(7_954_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -132,8 +132,8 @@ impl runtime_parachains::configuration::WeightInfo for // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 10_084_000 picoseconds. - Weight::from_parts(10_451_000, 0) + // Minimum execution time: 9_871_000 picoseconds. + Weight::from_parts(10_075_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -148,8 +148,8 @@ impl runtime_parachains::configuration::WeightInfo for // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 7_948_000 picoseconds. - Weight::from_parts(8_268_000, 0) + // Minimum execution time: 7_869_000 picoseconds. + Weight::from_parts(8_000_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) @@ -164,14 +164,26 @@ impl runtime_parachains::configuration::WeightInfo for // Proof Size summary in bytes: // Measured: `151` // Estimated: `1636` - // Minimum execution time: 10_257_000 picoseconds. - Weight::from_parts(10_584_000, 0) + // Minimum execution time: 9_797_000 picoseconds. + Weight::from_parts(10_373_000, 0) .saturating_add(Weight::from_parts(0, 1636)) .saturating_add(T::DbWeight::get().reads(3)) .saturating_add(T::DbWeight::get().writes(1)) } - + /// Storage: `Configuration::PendingConfigs` (r:1 w:1) + /// Proof: `Configuration::PendingConfigs` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Configuration::BypassConsistencyCheck` (r:1 w:0) + /// Proof: `Configuration::BypassConsistencyCheck` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParasShared::CurrentSessionIndex` (r:1 w:0) + /// Proof: `ParasShared::CurrentSessionIndex` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) fn set_config_with_scheduler_params() -> Weight { - Weight::zero() + // Proof Size summary in bytes: + // Measured: `151` + // Estimated: `1636` + // Minimum execution time: 7_718_000 picoseconds. + Weight::from_parts(7_984_000, 0) + .saturating_add(Weight::from_parts(0, 1636)) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(1)) } } From a4b7be8b678eeaed695faae0d5f1edc2e4ac26f3 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Thu, 8 Feb 2024 10:59:02 +0200 Subject: [PATCH 29/40] Fix zombienet tests --- cumulus/zombienet/tests/0002-pov_recovery.toml | 2 +- .../functional/0002-parachains-disputes.toml | 4 +++- .../functional/0004-parachains-garbage-candidate.toml | 4 +++- .../functional/0005-parachains-disputes-past-session.toml | 4 +++- .../functional/0006-parachains-max-tranche0.toml | 4 +++- .../functional/0007-dispute-freshly-finalized.toml | 4 +++- .../functional/0008-dispute-old-finalized.toml | 4 +++- .../functional/0010-validator-disabling.toml | 4 +++- .../functional/0011-async-backing-6-seconds-rate.toml | 7 +++++-- polkadot/zombienet_tests/misc/0001-paritydb.toml | 4 +++- 10 files changed, 30 insertions(+), 11 deletions(-) diff --git a/cumulus/zombienet/tests/0002-pov_recovery.toml b/cumulus/zombienet/tests/0002-pov_recovery.toml index fe42fd4b2f66..15a61eba2a03 100644 --- a/cumulus/zombienet/tests/0002-pov_recovery.toml +++ b/cumulus/zombienet/tests/0002-pov_recovery.toml @@ -4,7 +4,7 @@ default_command = "polkadot" chain = "rococo-local" -[relaychain.genesis.runtimeGenesis.patch.configuration.config] +[relaychain.genesis.runtimeGenesis.patch.configuration.config.scheduler_params] # set parameters such that collators only connect to 1 validator as a backing group max_validators_per_core = 1 group_rotation_frequency = 100 # 10 mins diff --git a/polkadot/zombienet_tests/functional/0002-parachains-disputes.toml b/polkadot/zombienet_tests/functional/0002-parachains-disputes.toml index f6bdfeb4877e..2561661de1f8 100644 --- a/polkadot/zombienet_tests/functional/0002-parachains-disputes.toml +++ b/polkadot/zombienet_tests/functional/0002-parachains-disputes.toml @@ -2,9 +2,11 @@ timeout = 1000 [relaychain.genesis.runtimeGenesis.patch.configuration.config] - max_validators_per_core = 5 needed_approvals = 8 +[relaychain.genesis.runtimeGenesis.patch.configuration.config.scheduler_params] + max_validators_per_core = 5 + [relaychain.genesis.runtimeGenesis.patch.configuration.config.approval_voting_params] max_approval_coalesce_count = 5 diff --git a/polkadot/zombienet_tests/functional/0004-parachains-garbage-candidate.toml b/polkadot/zombienet_tests/functional/0004-parachains-garbage-candidate.toml index 5d6f299d4613..a2a2621f8426 100644 --- a/polkadot/zombienet_tests/functional/0004-parachains-garbage-candidate.toml +++ b/polkadot/zombienet_tests/functional/0004-parachains-garbage-candidate.toml @@ -2,8 +2,10 @@ timeout = 1000 bootnode = true -[relaychain.genesis.runtimeGenesis.patch.configuration.config] +[relaychain.genesis.runtimeGenesis.patch.configuration.config.scheduler_params] max_validators_per_core = 1 + +[relaychain.genesis.runtimeGenesis.patch.configuration.config] needed_approvals = 2 [relaychain] diff --git a/polkadot/zombienet_tests/functional/0005-parachains-disputes-past-session.toml b/polkadot/zombienet_tests/functional/0005-parachains-disputes-past-session.toml index e2fbec079b1a..a3bbc82e74ba 100644 --- a/polkadot/zombienet_tests/functional/0005-parachains-disputes-past-session.toml +++ b/polkadot/zombienet_tests/functional/0005-parachains-disputes-past-session.toml @@ -3,8 +3,10 @@ timeout = 1000 bootnode = true [relaychain.genesis.runtimeGenesis.patch.configuration.config] - max_validators_per_core = 1 needed_approvals = 2 + +[relaychain.genesis.runtimeGenesis.patch.configuration.config.scheduler_params] + max_validators_per_core = 1 group_rotation_frequency = 2 [relaychain] diff --git a/polkadot/zombienet_tests/functional/0006-parachains-max-tranche0.toml b/polkadot/zombienet_tests/functional/0006-parachains-max-tranche0.toml index bef54cb8ca41..858f87b9cfe5 100644 --- a/polkadot/zombienet_tests/functional/0006-parachains-max-tranche0.toml +++ b/polkadot/zombienet_tests/functional/0006-parachains-max-tranche0.toml @@ -3,10 +3,12 @@ timeout = 1000 bootnode = true [relaychain.genesis.runtimeGenesis.patch.configuration.config] - max_validators_per_core = 1 needed_approvals = 7 relay_vrf_modulo_samples = 5 +[relaychain.genesis.runtimeGenesis.patch.configuration.config.scheduler_params] + max_validators_per_core = 1 + [relaychain] default_image = "{{ZOMBIENET_INTEGRATION_TEST_IMAGE}}" chain = "rococo-local" diff --git a/polkadot/zombienet_tests/functional/0007-dispute-freshly-finalized.toml b/polkadot/zombienet_tests/functional/0007-dispute-freshly-finalized.toml index 69eb0804d8cb..573ccf961385 100644 --- a/polkadot/zombienet_tests/functional/0007-dispute-freshly-finalized.toml +++ b/polkadot/zombienet_tests/functional/0007-dispute-freshly-finalized.toml @@ -2,9 +2,11 @@ timeout = 1000 [relaychain.genesis.runtimeGenesis.patch.configuration.config] - max_validators_per_core = 1 needed_approvals = 1 +[relaychain.genesis.runtimeGenesis.patch.configuration.config.scheduler_params] + max_validators_per_core = 1 + [relaychain] default_image = "{{ZOMBIENET_INTEGRATION_TEST_IMAGE}}" chain = "rococo-local" diff --git a/polkadot/zombienet_tests/functional/0008-dispute-old-finalized.toml b/polkadot/zombienet_tests/functional/0008-dispute-old-finalized.toml index 1ea385c3a42e..ea1c93a1403f 100644 --- a/polkadot/zombienet_tests/functional/0008-dispute-old-finalized.toml +++ b/polkadot/zombienet_tests/functional/0008-dispute-old-finalized.toml @@ -2,9 +2,11 @@ timeout = 1000 [relaychain.genesis.runtimeGenesis.patch.configuration.config] - max_validators_per_core = 1 needed_approvals = 1 +[relaychain.genesis.runtimeGenesis.patch.configuration.config.scheduler_params] + max_validators_per_core = 1 + [relaychain] default_image = "{{ZOMBIENET_INTEGRATION_TEST_IMAGE}}" chain = "rococo-local" diff --git a/polkadot/zombienet_tests/functional/0010-validator-disabling.toml b/polkadot/zombienet_tests/functional/0010-validator-disabling.toml index 6701d60d74d1..c9d79c5f8f23 100644 --- a/polkadot/zombienet_tests/functional/0010-validator-disabling.toml +++ b/polkadot/zombienet_tests/functional/0010-validator-disabling.toml @@ -3,8 +3,10 @@ timeout = 1000 bootnode = true [relaychain.genesis.runtimeGenesis.patch.configuration.config] - max_validators_per_core = 1 needed_approvals = 2 + +[relaychain.genesis.runtimeGenesis.patch.configuration.config.scheduler_params] + max_validators_per_core = 1 group_rotation_frequency = 10 [relaychain] diff --git a/polkadot/zombienet_tests/functional/0011-async-backing-6-seconds-rate.toml b/polkadot/zombienet_tests/functional/0011-async-backing-6-seconds-rate.toml index 5a6832b149be..b776622fdce3 100644 --- a/polkadot/zombienet_tests/functional/0011-async-backing-6-seconds-rate.toml +++ b/polkadot/zombienet_tests/functional/0011-async-backing-6-seconds-rate.toml @@ -8,13 +8,16 @@ chain = "rococo-local" [relaychain.genesis.runtimeGenesis.patch.configuration.config] needed_approvals = 4 relay_vrf_modulo_samples = 6 - scheduling_lookahead = 2 - group_rotation_frequency = 4 [relaychain.genesis.runtimeGenesis.patch.configuration.config.async_backing_params] max_candidate_depth = 3 allowed_ancestry_len = 2 +[relaychain.genesis.runtimeGenesis.patch.configuration.config.scheduler_params] + lookahead = 2 + group_rotation_frequency = 4 + + [relaychain.default_resources] limits = { memory = "4G", cpu = "2" } requests = { memory = "2G", cpu = "1" } diff --git a/polkadot/zombienet_tests/misc/0001-paritydb.toml b/polkadot/zombienet_tests/misc/0001-paritydb.toml index 399f848d3ac4..b3ce2081b111 100644 --- a/polkadot/zombienet_tests/misc/0001-paritydb.toml +++ b/polkadot/zombienet_tests/misc/0001-paritydb.toml @@ -3,9 +3,11 @@ timeout = 1000 bootnode = true [relaychain.genesis.runtimeGenesis.patch.configuration.config] - max_validators_per_core = 1 needed_approvals = 3 +[relaychain.genesis.runtimeGenesis.patch.configuration.config.scheduler_params] + max_validators_per_core = 1 + [relaychain] default_image = "{{ZOMBIENET_INTEGRATION_TEST_IMAGE}}" chain = "rococo-local" From 3f9ef1f070d342c2f5a2085b6e83b98cf29527ec Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Tue, 13 Feb 2024 10:04:44 +0200 Subject: [PATCH 30/40] Fix a dispatchable name: set_on_demand_retries -> set_max_availability_timeouts --- polkadot/runtime/parachains/src/configuration.rs | 2 +- polkadot/runtime/parachains/src/configuration/tests.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/polkadot/runtime/parachains/src/configuration.rs b/polkadot/runtime/parachains/src/configuration.rs index 9b4688da9712..394ed76858ec 100644 --- a/polkadot/runtime/parachains/src/configuration.rs +++ b/polkadot/runtime/parachains/src/configuration.rs @@ -648,7 +648,7 @@ pub mod pallet { T::WeightInfo::set_config_with_u32(), DispatchClass::Operational, ))] - pub fn set_on_demand_retries(origin: OriginFor, new: u32) -> DispatchResult { + pub fn set_max_availability_timeouts(origin: OriginFor, new: u32) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { config.scheduler_params.max_availability_timeouts = new; diff --git a/polkadot/runtime/parachains/src/configuration/tests.rs b/polkadot/runtime/parachains/src/configuration/tests.rs index 8896e72672dd..629697b8e96c 100644 --- a/polkadot/runtime/parachains/src/configuration/tests.rs +++ b/polkadot/runtime/parachains/src/configuration/tests.rs @@ -352,7 +352,7 @@ fn setting_pending_config_members() { new_config.scheduler_params.coretime_cores, ) .unwrap(); - Configuration::set_on_demand_retries( + Configuration::set_max_availability_timeouts( RuntimeOrigin::root(), new_config.scheduler_params.max_availability_timeouts, ) From e967b3aeab57a115fcbe64e4b17c4bd90238a315 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Tue, 13 Feb 2024 10:49:11 +0200 Subject: [PATCH 31/40] coretime_cores -> num_cores --- polkadot/primitives/src/vstaging/mod.rs | 4 ++-- .../src/assigner_coretime/mock_helpers.rs | 2 +- .../parachains/src/assigner_coretime/mod.rs | 6 +++--- .../src/assigner_on_demand/benchmarking.rs | 2 +- .../src/assigner_on_demand/mock_helpers.rs | 2 +- .../src/assigner_parachains/mock_helpers.rs | 2 +- polkadot/runtime/parachains/src/builder.rs | 2 +- .../runtime/parachains/src/configuration.rs | 2 +- .../src/configuration/migration/v12.rs | 8 +++---- .../parachains/src/configuration/tests.rs | 4 ++-- .../parachains/src/coretime/migration.rs | 21 ++++++++----------- .../runtime/parachains/src/coretime/mod.rs | 4 ++-- .../runtime/parachains/src/inclusion/tests.rs | 4 ++-- .../runtime/parachains/src/scheduler/tests.rs | 2 +- .../parachains/src/session_info/tests.rs | 2 +- 15 files changed, 32 insertions(+), 35 deletions(-) diff --git a/polkadot/primitives/src/vstaging/mod.rs b/polkadot/primitives/src/vstaging/mod.rs index df51301a25dd..5e7a890598cb 100644 --- a/polkadot/primitives/src/vstaging/mod.rs +++ b/polkadot/primitives/src/vstaging/mod.rs @@ -90,7 +90,7 @@ pub struct SchedulerParams { /// The amount of blocks ahead to schedule paras. pub lookahead: u32, /// How many cores are managed by the coretime chain. - pub coretime_cores: u32, + pub num_cores: u32, /// The max number of times a claim can time out in availability pub max_availability_timeouts: u32, /// The maximum queue size of the pay as you go module. @@ -115,7 +115,7 @@ impl> Default for SchedulerParams paras_availability_period: 1u32.into(), max_validators_per_core: Default::default(), lookahead: 1, - coretime_cores: Default::default(), + num_cores: Default::default(), max_availability_timeouts: Default::default(), on_demand_queue_max_size: ON_DEMAND_DEFAULT_QUEUE_MAX_SIZE, on_demand_target_queue_utilization: Perbill::from_percent(25), diff --git a/polkadot/runtime/parachains/src/assigner_coretime/mock_helpers.rs b/polkadot/runtime/parachains/src/assigner_coretime/mock_helpers.rs index 87a8c6004831..e2ba0b4f7ea5 100644 --- a/polkadot/runtime/parachains/src/assigner_coretime/mock_helpers.rs +++ b/polkadot/runtime/parachains/src/assigner_coretime/mock_helpers.rs @@ -64,7 +64,7 @@ impl GenesisConfigBuilder { pub(super) fn build(self) -> MockGenesisConfig { let mut genesis = default_genesis_config(); let config = &mut genesis.configuration.config; - config.scheduler_params.coretime_cores = self.on_demand_cores; + config.scheduler_params.num_cores = self.on_demand_cores; config.scheduler_params.on_demand_base_fee = self.on_demand_base_fee; config.scheduler_params.on_demand_fee_variability = self.on_demand_fee_variability; config.scheduler_params.on_demand_queue_max_size = self.on_demand_max_queue_size; diff --git a/polkadot/runtime/parachains/src/assigner_coretime/mod.rs b/polkadot/runtime/parachains/src/assigner_coretime/mod.rs index 2f343b30efa5..e2da89fadd48 100644 --- a/polkadot/runtime/parachains/src/assigner_coretime/mod.rs +++ b/polkadot/runtime/parachains/src/assigner_coretime/mod.rs @@ -325,7 +325,7 @@ impl AssignmentProvider> for Pallet { fn session_core_count() -> u32 { let config = >::config(); - config.scheduler_params.coretime_cores + config.scheduler_params.num_cores } } @@ -474,8 +474,8 @@ impl AssignCoretime for Pallet { // Add a new core and assign the para to it. let mut config = >::config(); - let core = config.scheduler_params.coretime_cores; - config.scheduler_params.coretime_cores.saturating_inc(); + let core = config.scheduler_params.num_cores; + config.scheduler_params.num_cores.saturating_inc(); // `assign_coretime` is only called at genesis or by root, so setting the active // config here is fine. diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/benchmarking.rs b/polkadot/runtime/parachains/src/assigner_on_demand/benchmarking.rs index 9d50f2a4a15f..8360e7a78d0a 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/benchmarking.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/benchmarking.rs @@ -43,7 +43,7 @@ where { ParasShared::::set_session_index(SESSION_INDEX); let mut config = HostConfiguration::default(); - config.scheduler_params.coretime_cores = 1; + config.scheduler_params.num_cores = 1; ConfigurationPallet::::force_set_active_config(config); let mut parachains = ParachainsCache::new(); ParasPallet::::initialize_para_now( diff --git a/polkadot/runtime/parachains/src/assigner_on_demand/mock_helpers.rs b/polkadot/runtime/parachains/src/assigner_on_demand/mock_helpers.rs index be86d098f3d4..f8d1a894f0e4 100644 --- a/polkadot/runtime/parachains/src/assigner_on_demand/mock_helpers.rs +++ b/polkadot/runtime/parachains/src/assigner_on_demand/mock_helpers.rs @@ -63,7 +63,7 @@ impl GenesisConfigBuilder { pub(super) fn build(self) -> MockGenesisConfig { let mut genesis = default_genesis_config(); let config = &mut genesis.configuration.config; - config.scheduler_params.coretime_cores = self.on_demand_cores; + config.scheduler_params.num_cores = self.on_demand_cores; config.scheduler_params.on_demand_base_fee = self.on_demand_base_fee; config.scheduler_params.on_demand_fee_variability = self.on_demand_fee_variability; config.scheduler_params.on_demand_queue_max_size = self.on_demand_max_queue_size; diff --git a/polkadot/runtime/parachains/src/assigner_parachains/mock_helpers.rs b/polkadot/runtime/parachains/src/assigner_parachains/mock_helpers.rs index eacb74253a39..a46e114daeaf 100644 --- a/polkadot/runtime/parachains/src/assigner_parachains/mock_helpers.rs +++ b/polkadot/runtime/parachains/src/assigner_parachains/mock_helpers.rs @@ -60,7 +60,7 @@ impl GenesisConfigBuilder { pub(super) fn build(self) -> MockGenesisConfig { let mut genesis = default_genesis_config(); let config = &mut genesis.configuration.config; - config.scheduler_params.coretime_cores = self.on_demand_cores; + config.scheduler_params.num_cores = self.on_demand_cores; config.scheduler_params.on_demand_base_fee = self.on_demand_base_fee; config.scheduler_params.on_demand_fee_variability = self.on_demand_fee_variability; config.scheduler_params.on_demand_queue_max_size = self.on_demand_max_queue_size; diff --git a/polkadot/runtime/parachains/src/builder.rs b/polkadot/runtime/parachains/src/builder.rs index 02ade20d3a84..e1a242c9eae7 100644 --- a/polkadot/runtime/parachains/src/builder.rs +++ b/polkadot/runtime/parachains/src/builder.rs @@ -682,7 +682,7 @@ impl BenchBuilder { // We are currently in Session 0, so these changes will take effect in Session 2. Self::setup_para_ids(used_cores); configuration::ActiveConfig::::mutate(|c| { - c.scheduler_params.coretime_cores = used_cores; + c.scheduler_params.num_cores = used_cores; }); let validator_ids = Self::generate_validator_pairs(self.max_validators()); diff --git a/polkadot/runtime/parachains/src/configuration.rs b/polkadot/runtime/parachains/src/configuration.rs index 394ed76858ec..4072cf5c80b8 100644 --- a/polkadot/runtime/parachains/src/configuration.rs +++ b/polkadot/runtime/parachains/src/configuration.rs @@ -1231,7 +1231,7 @@ pub mod pallet { /// To be used if authorization is checked otherwise. pub fn set_coretime_cores_unchecked(new: u32) -> DispatchResult { Self::schedule_config_update(|config| { - config.scheduler_params.coretime_cores = new; + config.scheduler_params.num_cores = new; }) } } diff --git a/polkadot/runtime/parachains/src/configuration/migration/v12.rs b/polkadot/runtime/parachains/src/configuration/migration/v12.rs index b0bd56fdf419..e485c97e0456 100644 --- a/polkadot/runtime/parachains/src/configuration/migration/v12.rs +++ b/polkadot/runtime/parachains/src/configuration/migration/v12.rs @@ -148,13 +148,13 @@ fn migrate_to_v12() -> Weight { paras_availability_period : pre.paras_availability_period, max_validators_per_core : pre.max_validators_per_core, lookahead : pre.scheduling_lookahead, - coretime_cores : pre.coretime_cores, + num_cores : pre.coretime_cores, max_availability_timeouts : pre.on_demand_retries, on_demand_queue_max_size : pre.on_demand_queue_max_size, on_demand_target_queue_utilization : pre.on_demand_target_queue_utilization, on_demand_fee_variability : pre.on_demand_fee_variability, on_demand_base_fee : pre.on_demand_base_fee, - ttl : pre.on_demand_ttl, + ttl : pre.on_demand_ttl, } } }; @@ -229,7 +229,7 @@ mod tests { assert_eq!(v12.scheduler_params.group_rotation_frequency, 20); assert_eq!(v12.scheduler_params.paras_availability_period, 4); assert_eq!(v12.scheduler_params.lookahead, 1); - assert_eq!(v12.scheduler_params.coretime_cores, 1); + assert_eq!(v12.scheduler_params.num_cores, 1); assert_eq!(v12.scheduler_params.max_availability_timeouts, 0); assert_eq!(v12.scheduler_params.on_demand_queue_max_size, 10_000); assert_eq!( @@ -318,7 +318,7 @@ mod tests { assert_eq!(v11.paras_availability_period , v12.scheduler_params.paras_availability_period); assert_eq!(v11.max_validators_per_core , v12.scheduler_params.max_validators_per_core); assert_eq!(v11.scheduling_lookahead , v12.scheduler_params.lookahead); - assert_eq!(v11.coretime_cores , v12.scheduler_params.coretime_cores); + assert_eq!(v11.coretime_cores , v12.scheduler_params.num_cores); assert_eq!(v11.on_demand_retries , v12.scheduler_params.max_availability_timeouts); assert_eq!(v11.on_demand_queue_max_size , v12.scheduler_params.on_demand_queue_max_size); assert_eq!(v11.on_demand_target_queue_utilization , v12.scheduler_params.on_demand_target_queue_utilization); diff --git a/polkadot/runtime/parachains/src/configuration/tests.rs b/polkadot/runtime/parachains/src/configuration/tests.rs index 629697b8e96c..254511231cac 100644 --- a/polkadot/runtime/parachains/src/configuration/tests.rs +++ b/polkadot/runtime/parachains/src/configuration/tests.rs @@ -318,7 +318,7 @@ fn setting_pending_config_members() { paras_availability_period: 10, max_validators_per_core: None, lookahead: 3, - coretime_cores: 2, + num_cores: 2, max_availability_timeouts: 5, on_demand_queue_max_size: 10_000u32, on_demand_base_fee: 10_000_000u128, @@ -349,7 +349,7 @@ fn setting_pending_config_members() { .unwrap(); Configuration::set_coretime_cores( RuntimeOrigin::root(), - new_config.scheduler_params.coretime_cores, + new_config.scheduler_params.num_cores, ) .unwrap(); Configuration::set_max_availability_timeouts( diff --git a/polkadot/runtime/parachains/src/coretime/migration.rs b/polkadot/runtime/parachains/src/coretime/migration.rs index a7d41fd29b82..03fecc58570f 100644 --- a/polkadot/runtime/parachains/src/coretime/migration.rs +++ b/polkadot/runtime/parachains/src/coretime/migration.rs @@ -114,8 +114,7 @@ mod v_coretime { let legacy_paras = paras::Parachains::::get(); let config = >::config(); - let total_core_count = - config.scheduler_params.coretime_cores + legacy_paras.len() as u32; + let total_core_count = config.scheduler_params.num_cores + legacy_paras.len() as u32; let dmp_queue_size = crate::dmp::Pallet::::dmq_contents(T::BrokerId::get().into()).len() as u32; @@ -151,7 +150,7 @@ mod v_coretime { // Migrate to Coretime. // - // NOTE: Also migrates coretime_cores config value in configuration::ActiveConfig. + // NOTE: Also migrates `num_cores` config value in configuration::ActiveConfig. fn migrate_to_coretime< T: Config, SendXcm: xcm::v4::SendXcm, @@ -177,8 +176,8 @@ mod v_coretime { } let config = >::config(); - // coretime_cores was on_demand_cores until now: - for on_demand in 0..config.scheduler_params.coretime_cores { + // num_cores was on_demand_cores until now: + for on_demand in 0..config.scheduler_params.num_cores { let core = CoreIndex(legacy_count.saturating_add(on_demand as _)); let r = assigner_coretime::Pallet::::assign_core( core, @@ -190,9 +189,9 @@ mod v_coretime { log::error!("Creating assignment for existing on-demand core, failed: {:?}", err); } } - let total_cores = config.scheduler_params.coretime_cores + legacy_count; + let total_cores = config.scheduler_params.num_cores + legacy_count; configuration::ActiveConfig::::mutate(|c| { - c.scheduler_params.coretime_cores = total_cores; + c.scheduler_params.num_cores = total_cores; }); if let Err(err) = migrate_send_assignments_to_coretime_chain::() { @@ -202,7 +201,7 @@ mod v_coretime { let single_weight = ::WeightInfo::assign_core(1); single_weight .saturating_mul(u64::from( - legacy_count.saturating_add(config.scheduler_params.coretime_cores), + legacy_count.saturating_add(config.scheduler_params.num_cores), )) // Second read from sending assignments to the coretime chain. .saturating_add(T::DbWeight::get().reads_writes(2, 1)) @@ -247,10 +246,8 @@ mod v_coretime { Some(mk_coretime_call(crate::coretime::CoretimeCalls::SetLease(p.into(), time_slice))) }); - let core_count: u16 = configuration::Pallet::::config() - .scheduler_params - .coretime_cores - .saturated_into(); + let core_count: u16 = + configuration::Pallet::::config().scheduler_params.num_cores.saturated_into(); let set_core_count = iter::once(mk_coretime_call( crate::coretime::CoretimeCalls::NotifyCoreCount(core_count), )); diff --git a/polkadot/runtime/parachains/src/coretime/mod.rs b/polkadot/runtime/parachains/src/coretime/mod.rs index 68558df7c4fb..eb9646d7e869 100644 --- a/polkadot/runtime/parachains/src/coretime/mod.rs +++ b/polkadot/runtime/parachains/src/coretime/mod.rs @@ -214,8 +214,8 @@ impl Pallet { } pub fn initializer_on_new_session(notification: &SessionChangeNotification>) { - let old_core_count = notification.prev_config.scheduler_params.coretime_cores; - let new_core_count = notification.new_config.scheduler_params.coretime_cores; + let old_core_count = notification.prev_config.scheduler_params.num_cores; + let new_core_count = notification.new_config.scheduler_params.num_cores; if new_core_count != old_core_count { let core_count: u16 = new_core_count.saturated_into(); let message = Xcm(vec![ diff --git a/polkadot/runtime/parachains/src/inclusion/tests.rs b/polkadot/runtime/parachains/src/inclusion/tests.rs index a7c0f8396d9b..b6e47d5b3f4c 100644 --- a/polkadot/runtime/parachains/src/inclusion/tests.rs +++ b/polkadot/runtime/parachains/src/inclusion/tests.rs @@ -47,7 +47,7 @@ use test_helpers::{dummy_collator, dummy_collator_signature, dummy_validation_co fn default_config() -> HostConfiguration { let mut config = HostConfiguration::default(); - config.scheduler_params.coretime_cores = 1; + config.scheduler_params.num_cores = 1; config.max_code_size = 0b100000; config.max_head_data_size = 0b100000; config.scheduler_params.group_rotation_frequency = u32::MAX; @@ -218,7 +218,7 @@ pub(crate) fn run_to_block( } pub(crate) fn expected_bits() -> usize { - Paras::parachains().len() + Configuration::config().scheduler_params.coretime_cores as usize + Paras::parachains().len() + Configuration::config().scheduler_params.num_cores as usize } fn default_bitfield() -> AvailabilityBitfield { diff --git a/polkadot/runtime/parachains/src/scheduler/tests.rs b/polkadot/runtime/parachains/src/scheduler/tests.rs index 1117d1ea7c25..c9a6c655aad7 100644 --- a/polkadot/runtime/parachains/src/scheduler/tests.rs +++ b/polkadot/runtime/parachains/src/scheduler/tests.rs @@ -114,7 +114,7 @@ fn default_config() -> HostConfiguration { group_rotation_frequency: 10, paras_availability_period: 3, lookahead: 2, - coretime_cores: 3, + num_cores: 3, max_availability_timeouts: 1, ..Default::default() }, diff --git a/polkadot/runtime/parachains/src/session_info/tests.rs b/polkadot/runtime/parachains/src/session_info/tests.rs index 68dd8ade60b4..a5bfeae07455 100644 --- a/polkadot/runtime/parachains/src/session_info/tests.rs +++ b/polkadot/runtime/parachains/src/session_info/tests.rs @@ -64,7 +64,7 @@ fn default_config() -> HostConfiguration { HostConfiguration { dispute_period: 2, needed_approvals: 3, - scheduler_params: SchedulerParams { coretime_cores: 1, ..Default::default() }, + scheduler_params: SchedulerParams { num_cores: 1, ..Default::default() }, ..Default::default() } } From 383748262e04b4355320024b5d9db9d4f7d41b73 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Tue, 13 Feb 2024 10:55:37 +0200 Subject: [PATCH 32/40] Spacing --- polkadot/runtime/parachains/src/configuration/migration/v12.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/runtime/parachains/src/configuration/migration/v12.rs b/polkadot/runtime/parachains/src/configuration/migration/v12.rs index e485c97e0456..4295a79893e8 100644 --- a/polkadot/runtime/parachains/src/configuration/migration/v12.rs +++ b/polkadot/runtime/parachains/src/configuration/migration/v12.rs @@ -149,7 +149,7 @@ fn migrate_to_v12() -> Weight { max_validators_per_core : pre.max_validators_per_core, lookahead : pre.scheduling_lookahead, num_cores : pre.coretime_cores, - max_availability_timeouts : pre.on_demand_retries, + max_availability_timeouts : pre.on_demand_retries, on_demand_queue_max_size : pre.on_demand_queue_max_size, on_demand_target_queue_utilization : pre.on_demand_target_queue_utilization, on_demand_fee_variability : pre.on_demand_fee_variability, From 8bc1e7afaca6dea2f347167d8bd72be05ef49ffe Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Tue, 13 Feb 2024 11:13:44 +0200 Subject: [PATCH 33/40] Fix a comment --- polkadot/runtime/parachains/src/configuration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polkadot/runtime/parachains/src/configuration.rs b/polkadot/runtime/parachains/src/configuration.rs index 4072cf5c80b8..b51489cc2b88 100644 --- a/polkadot/runtime/parachains/src/configuration.rs +++ b/polkadot/runtime/parachains/src/configuration.rs @@ -642,7 +642,7 @@ pub mod pallet { Self::set_coretime_cores_unchecked(new) } - /// Set the number of retries for a particular on demand. + /// Set the max number of times a claim may timeout on a core before it is abandoned #[pallet::call_index(7)] #[pallet::weight(( T::WeightInfo::set_config_with_u32(), From 3807465df57590d162f12de7247bf1ee4e572e48 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Tue, 13 Feb 2024 16:15:39 +0200 Subject: [PATCH 34/40] max_retries -> max_timeouts in `on_demand_claims_are_pruned_after_timing_out` --- polkadot/runtime/parachains/src/scheduler/tests.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/polkadot/runtime/parachains/src/scheduler/tests.rs b/polkadot/runtime/parachains/src/scheduler/tests.rs index c9a6c655aad7..9eb20796bc9c 100644 --- a/polkadot/runtime/parachains/src/scheduler/tests.rs +++ b/polkadot/runtime/parachains/src/scheduler/tests.rs @@ -747,11 +747,11 @@ fn schedule_rotates_groups() { #[test] fn on_demand_claims_are_pruned_after_timing_out() { - let max_retries = 20; + let max_timeouts = 20; let mut config = default_config(); config.scheduler_params.lookahead = 1; // Need more timeouts for this test - config.scheduler_params.max_availability_timeouts = max_retries; + config.scheduler_params.max_availability_timeouts = max_timeouts; config.scheduler_params.ttl = BlockNumber::from(5u32); let genesis_config = genesis_config(&config); @@ -797,7 +797,7 @@ fn on_demand_claims_are_pruned_after_timing_out() { // Run to block #n over the max_retries value. // In this case, both validator groups with time out on availability and // the assignment will be dropped. - for n in now..=(now + max_retries + 1) { + for n in now..=(now + max_timeouts + 1) { // #n run_to_block(n, |_| None); // Time out on core 0. @@ -809,7 +809,7 @@ fn on_demand_claims_are_pruned_after_timing_out() { Scheduler::free_cores_and_fill_claimqueue(just_updated, now); // ParaId a exists in the claim queue until max_retries is reached. - if n < max_retries + now { + if n < max_timeouts + now { assert!(claimqueue_contains_para_ids::(vec![para_a])); } else { assert!(!claimqueue_contains_para_ids::(vec![para_a])); @@ -825,7 +825,7 @@ fn on_demand_claims_are_pruned_after_timing_out() { assert!(!availability_cores_contains_para_ids::(vec![para_a])); // #25 - now += max_retries + 2; + now += max_timeouts + 2; // Add assignment back to the mix. MockAssigner::add_test_assignment(assignment_a.clone()); @@ -836,7 +836,7 @@ fn on_demand_claims_are_pruned_after_timing_out() { // #26 now += 1; // Run to block #n but this time have group 1 conclude the availabilty. - for n in now..=(now + max_retries + 1) { + for n in now..=(now + max_timeouts + 1) { // #n run_to_block(n, |_| None); // Time out core 0 if group 0 is assigned to it, if group 1 is assigned, conclude. From 22e2656210a653ac824ecc2dcecc4e26e8ad8ced Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Mon, 26 Feb 2024 11:27:18 +0200 Subject: [PATCH 35/40] Update doc comment --- polkadot/primitives/src/vstaging/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/polkadot/primitives/src/vstaging/mod.rs b/polkadot/primitives/src/vstaging/mod.rs index 5e7a890598cb..36922ee8797c 100644 --- a/polkadot/primitives/src/vstaging/mod.rs +++ b/polkadot/primitives/src/vstaging/mod.rs @@ -68,9 +68,9 @@ pub struct SchedulerParams { /// /// Must be non-zero. pub group_rotation_frequency: BlockNumber, - /// The minimum availability period, in blocks. + /// Availability timeout for a block on a core, measured in blocks. /// - /// This is the minimum amount of blocks after a core became occupied that validators have time + /// This is the maximum amount of blocks after a core became occupied that validators have time /// to make the block available. /// /// This value only has effect on group rotations. If backers backed something at the end of @@ -91,7 +91,7 @@ pub struct SchedulerParams { pub lookahead: u32, /// How many cores are managed by the coretime chain. pub num_cores: u32, - /// The max number of times a claim can time out in availability + /// The max number of times a claim can time out in availability. pub max_availability_timeouts: u32, /// The maximum queue size of the pay as you go module. pub on_demand_queue_max_size: u32, From 377218518fec5d548546aa3362c95c69b736e936 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Tue, 27 Feb 2024 14:28:30 +0200 Subject: [PATCH 36/40] Remove an assert in tests --- polkadot/runtime/parachains/src/scheduler/tests.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/polkadot/runtime/parachains/src/scheduler/tests.rs b/polkadot/runtime/parachains/src/scheduler/tests.rs index 9eb20796bc9c..28b3a6b4f5d6 100644 --- a/polkadot/runtime/parachains/src/scheduler/tests.rs +++ b/polkadot/runtime/parachains/src/scheduler/tests.rs @@ -880,8 +880,6 @@ fn availability_predicate_works() { let SchedulerParams { group_rotation_frequency, paras_availability_period, .. } = default_config().scheduler_params; - assert!(paras_availability_period < group_rotation_frequency); - new_test_ext(genesis_config).execute_with(|| { run_to_block(1 + paras_availability_period, |_| None); From 691427a044267c1341fc8b837b92c8ee51d32883 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Tue, 27 Feb 2024 14:28:59 +0200 Subject: [PATCH 37/40] Update runtime.md from the guide --- .../implementers-guide/src/types/runtime.md | 118 +++--------------- 1 file changed, 18 insertions(+), 100 deletions(-) diff --git a/polkadot/roadmap/implementers-guide/src/types/runtime.md b/polkadot/roadmap/implementers-guide/src/types/runtime.md index 4b97409f8df3..b297331005bf 100644 --- a/polkadot/roadmap/implementers-guide/src/types/runtime.md +++ b/polkadot/roadmap/implementers-guide/src/types/runtime.md @@ -4,106 +4,24 @@ Types used within the runtime exclusively and pervasively. ## Host Configuration -The internal-to-runtime configuration of the parachain host. This is expected to be altered only by governance procedures. - -```rust -struct HostConfiguration { - /// The minimum period, in blocks, between which parachains can update their validation code. - pub validation_upgrade_cooldown: BlockNumber, - /// The delay, in blocks, before a validation upgrade is applied. - pub validation_upgrade_delay: BlockNumber, - /// How long to keep code on-chain, in blocks. This should be sufficiently long that disputes - /// have concluded. - pub code_retention_period: BlockNumber, - /// The maximum validation code size, in bytes. - pub max_code_size: u32, - /// The maximum head-data size, in bytes. - pub max_head_data_size: u32, - /// The amount of availability cores to dedicate to parathreads (on-demand parachains). - pub parathread_cores: u32, - /// The number of retries that a parathread (on-demand parachain) author has to submit their block. - pub parathread_retries: u32, - /// How often parachain groups should be rotated across parachains. - pub group_rotation_frequency: BlockNumber, - /// The availability period, in blocks, for parachains. This is the amount of blocks - /// after inclusion that validators have to make the block available and signal its availability to - /// the chain. Must be at least 1. - pub chain_availability_period: BlockNumber, - /// The availability period, in blocks, for parathreads (on-demand parachains). Same as the `chain_availability_period`, - /// but a differing timeout due to differing requirements. Must be at least 1. - pub thread_availability_period: BlockNumber, - /// The amount of blocks ahead to schedule on-demand parachains. - pub scheduling_lookahead: u32, - /// The maximum number of validators to have per core. `None` means no maximum. - pub max_validators_per_core: Option, - /// The maximum number of validators to use for parachains, in total. `None` means no maximum. - pub max_validators: Option, - /// The amount of sessions to keep for disputes. - pub dispute_period: SessionIndex, - /// How long after dispute conclusion to accept statements. - pub dispute_post_conclusion_acceptance_period: BlockNumber, - /// The maximum number of dispute spam slots - pub dispute_max_spam_slots: u32, - /// The amount of consensus slots that must pass between submitting an assignment and - /// submitting an approval vote before a validator is considered a no-show. - /// Must be at least 1. - pub no_show_slots: u32, - /// The number of delay tranches in total. - pub n_delay_tranches: u32, - /// The width of the zeroth delay tranche for approval assignments. This many delay tranches - /// beyond 0 are all consolidated to form a wide 0 tranche. - pub zeroth_delay_tranche_width: u32, - /// The number of validators needed to approve a block. - pub needed_approvals: u32, - /// The number of samples to use in `RelayVRFModulo` or `RelayVRFModuloCompact` approval assignment criterions. - pub relay_vrf_modulo_samples: u32, - /// Total number of individual messages allowed in the parachain -> relay-chain message queue. - pub max_upward_queue_count: u32, - /// Total size of messages allowed in the parachain -> relay-chain message queue before which - /// no further messages may be added to it. If it exceeds this then the queue may contain only - /// a single message. - pub max_upward_queue_size: u32, - /// The maximum size of an upward message that can be sent by a candidate. - /// - /// This parameter affects the upper bound of size of `CandidateCommitments`. - pub max_upward_message_size: u32, - /// The maximum number of messages that a candidate can contain. - /// - /// This parameter affects the upper bound of size of `CandidateCommitments`. - pub max_upward_message_num_per_candidate: u32, - /// The maximum size of a message that can be put in a downward message queue. - /// - /// Since we require receiving at least one DMP message the obvious upper bound of the size is - /// the PoV size. Of course, there is a lot of other different things that a parachain may - /// decide to do with its PoV so this value in practice will be picked as a fraction of the PoV - /// size. - pub max_downward_message_size: u32, - /// The deposit that the sender should provide for opening an HRMP channel. - pub hrmp_sender_deposit: u32, - /// The deposit that the recipient should provide for accepting opening an HRMP channel. - pub hrmp_recipient_deposit: u32, - /// The maximum number of messages allowed in an HRMP channel at once. - pub hrmp_channel_max_capacity: u32, - /// The maximum total size of messages in bytes allowed in an HRMP channel at once. - pub hrmp_channel_max_total_size: u32, - /// The maximum number of inbound HRMP channels a parachain is allowed to accept. - pub hrmp_max_parachain_inbound_channels: u32, - /// The maximum number of inbound HRMP channels a parathread (on-demand parachain) is allowed to accept. - pub hrmp_max_parathread_inbound_channels: u32, - /// The maximum size of a message that could ever be put into an HRMP channel. - /// - /// This parameter affects the upper bound of size of `CandidateCommitments`. - pub hrmp_channel_max_message_size: u32, - /// The maximum number of outbound HRMP channels a parachain is allowed to open. - pub hrmp_max_parachain_outbound_channels: u32, - /// The maximum number of outbound HRMP channels a parathread (on-demand parachain) is allowed to open. - pub hrmp_max_parathread_outbound_channels: u32, - /// The maximum number of outbound HRMP messages can be sent by a candidate. - /// - /// This parameter affects the upper bound of size of `CandidateCommitments`. - pub hrmp_max_message_num_per_candidate: u32, -} -``` +The internal-to-runtime configuration of the parachain host is kept in `struct HostConfiguration`. This is expected to +be altered only by governance procedures or via migrations from the polkadot-sdk codebase. The latest definition of +`HostConfiguration` can be found in the project repo +[here](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/runtime/parachains/src/configuration.rs). Each +parameter has got a doc comment so for any details please refer to the code. + +Some related parameters in `HostConfiguration` are grouped together so that they can be managed easily. These are: +* `async_backing_params` in `struct AsyncBackingParams` +* `executor_params` in `struct ExecutorParams` +* `approval_voting_params` in `struct ApprovalVotingParams` +* `scheduler_params` in `struct SchedulerParams` + +Check the definitions of these structs for further details. + +### Configuration migrations +Modifying `HostConfiguration` requires a storage migration. These migrations are located in the +[`migrations`](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/runtime/parachains/src/configuration.rs) +subfolder of polkadot-sdk repo. ## ParaInherentData From e8618853bc1f29f8bbfff4b4286744eca90cd75a Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Wed, 28 Feb 2024 09:40:41 +0200 Subject: [PATCH 38/40] compilation errors --- polkadot/runtime/parachains/src/paras_inherent/tests.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/polkadot/runtime/parachains/src/paras_inherent/tests.rs b/polkadot/runtime/parachains/src/paras_inherent/tests.rs index 5d07270f2193..b7285ec884ad 100644 --- a/polkadot/runtime/parachains/src/paras_inherent/tests.rs +++ b/polkadot/runtime/parachains/src/paras_inherent/tests.rs @@ -27,13 +27,14 @@ mod enter { builder::{Bench, BenchBuilder}, mock::{mock_assigner, new_test_ext, BlockLength, BlockWeights, MockGenesisConfig, Test}, scheduler::{ - common::{Assignment, AssignmentProvider, AssignmentProviderConfig}, + common::{Assignment, AssignmentProvider}, ParasEntry, }, }; use assert_matches::assert_matches; use frame_support::assert_ok; use frame_system::limits; + use primitives::vstaging::SchedulerParams; use sp_runtime::Perbill; use sp_std::collections::btree_map::BTreeMap; @@ -706,8 +707,8 @@ mod enter { let cores = (0..used_cores) .into_iter() .map(|i| { - let AssignmentProviderConfig { ttl, .. } = - scheduler::Pallet::::assignment_provider_config(CoreIndex(i)); + let SchedulerParams { ttl, .. } = + >::config().scheduler_params; // Load an assignment into provider so that one is present to pop let assignment = ::AssignmentProvider::get_mock_assignment( From ce53717bd983146cc35cb976d86c2b65e2afc710 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Wed, 28 Feb 2024 11:51:17 +0200 Subject: [PATCH 39/40] Make lint-markdown happy --- polkadot/roadmap/implementers-guide/src/types/runtime.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/polkadot/roadmap/implementers-guide/src/types/runtime.md b/polkadot/roadmap/implementers-guide/src/types/runtime.md index b297331005bf..1dfabd96db7c 100644 --- a/polkadot/roadmap/implementers-guide/src/types/runtime.md +++ b/polkadot/roadmap/implementers-guide/src/types/runtime.md @@ -5,7 +5,7 @@ Types used within the runtime exclusively and pervasively. ## Host Configuration The internal-to-runtime configuration of the parachain host is kept in `struct HostConfiguration`. This is expected to -be altered only by governance procedures or via migrations from the polkadot-sdk codebase. The latest definition of +be altered only by governance procedures or via migrations from the Polkadot-SDK codebase. The latest definition of `HostConfiguration` can be found in the project repo [here](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/runtime/parachains/src/configuration.rs). Each parameter has got a doc comment so for any details please refer to the code. @@ -21,7 +21,7 @@ Check the definitions of these structs for further details. ### Configuration migrations Modifying `HostConfiguration` requires a storage migration. These migrations are located in the [`migrations`](https://github.com/paritytech/polkadot-sdk/blob/master/polkadot/runtime/parachains/src/configuration.rs) -subfolder of polkadot-sdk repo. +subfolder of Polkadot-SDK repo. ## ParaInherentData From 66401dd2d3bc00dc3493440f2a2e4a2e8a637ff9 Mon Sep 17 00:00:00 2001 From: Tsvetomir Dimitrov Date: Wed, 28 Feb 2024 14:24:05 +0200 Subject: [PATCH 40/40] Fix 0012-elastic-scaling-mvp.toml --- .../functional/0012-elastic-scaling-mvp.toml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/polkadot/zombienet_tests/functional/0012-elastic-scaling-mvp.toml b/polkadot/zombienet_tests/functional/0012-elastic-scaling-mvp.toml index 0dfd814e10a5..9b3576eaa3c2 100644 --- a/polkadot/zombienet_tests/functional/0012-elastic-scaling-mvp.toml +++ b/polkadot/zombienet_tests/functional/0012-elastic-scaling-mvp.toml @@ -3,9 +3,11 @@ timeout = 1000 bootnode = true [relaychain.genesis.runtimeGenesis.patch.configuration.config] - max_validators_per_core = 2 needed_approvals = 4 - coretime_cores = 2 + +[relaychain.genesis.runtimeGenesis.patch.configuration.config.scheduler_params] + max_validators_per_core = 2 + num_cores = 2 [relaychain] default_image = "{{ZOMBIENET_INTEGRATION_TEST_IMAGE}}"