Skip to content

Commit

Permalink
Remove AssignmentProviderConfig and use parameters from `HostConfig…
Browse files Browse the repository at this point in the history
…uration` instead (#3181)

This PR removes `AssignmentProviderConfig` and uses the corresponding
ondemand parameters from `HostConfiguration` instead. Additionally
`scheduling_lookahead` and all coretime/ondemand related parameters are
extracted in a separate struct - `SchedulerParams`.

The most relevant commit from the PR is [this
one](830bc0f).

Fixes #2268

---------

Co-authored-by: command-bot <>
  • Loading branch information
tdimitrov authored Feb 29, 2024
1 parent a22319c commit a035dc9
Show file tree
Hide file tree
Showing 43 changed files with 901 additions and 439 deletions.
2 changes: 1 addition & 1 deletion cumulus/zombienet/tests/0002-pov_recovery.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 12 additions & 4 deletions polkadot/node/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ 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")]
Expand Down Expand Up @@ -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,
Expand All @@ -151,11 +151,16 @@ fn default_parachains_host_configuration(
relay_vrf_modulo_samples: 2,
zeroth_delay_tranche_width: 0,
minimum_validation_upgrade_delay: 5,
scheduling_lookahead: 2,
async_backing_params: AsyncBackingParams {
max_candidate_depth: 3,
allowed_ancestry_len: 2,
},
scheduler_params: SchedulerParams {
lookahead: 2,
group_rotation_frequency: 20,
paras_availability_period: 4,
..Default::default()
},
..Default::default()
}
}
Expand Down Expand Up @@ -891,7 +896,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()
},
},
Expand Down
11 changes: 8 additions & 3 deletions polkadot/node/test/service/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -165,11 +167,14 @@ 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,
max_downward_message_size: 1024,
scheduler_params: SchedulerParams {
group_rotation_frequency: 20,
paras_availability_period: 4,
..Default::default()
},
..Default::default()
},
}
Expand Down
76 changes: 76 additions & 0 deletions polkadot/primitives/src/vstaging/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -50,6 +51,81 @@ impl Default for ApprovalVotingParams {
}
}

/// Scheduler configuration parameters. All coretime/ondemand parameters are here.
#[derive(
RuntimeDebug,
Copy,
Clone,
PartialEq,
Encode,
Decode,
TypeInfo,
serde::Serialize,
serde::Deserialize,
)]
pub struct SchedulerParams<BlockNumber> {
/// How often parachain groups should be rotated across parachains.
///
/// Must be non-zero.
pub group_rotation_frequency: BlockNumber,
/// Availability timeout for a block on a core, measured in blocks.
///
/// 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
/// 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<u32>,
/// The amount of blocks ahead to schedule paras.
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.
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.
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 # 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 ttl: BlockNumber,
}

impl<BlockNumber: Default + From<u32>> Default for SchedulerParams<BlockNumber> {
fn default() -> Self {
Self {
group_rotation_frequency: 1u32.into(),
paras_availability_period: 1u32.into(),
max_validators_per_core: Default::default(),
lookahead: 1,
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),
on_demand_fee_variability: Perbill::from_percent(3),
on_demand_base_fee: 10_000_000u128,
ttl: 5u32.into(),
}
}
}

use bitvec::vec::BitVec;

/// Bit indices in the `HostConfiguration.node_features` that correspond to different node features.
Expand Down
118 changes: 18 additions & 100 deletions polkadot/roadmap/implementers-guide/src/types/runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32>,
/// The maximum number of validators to use for parachains, in total. `None` means no maximum.
pub max_validators: Option<u32>,
/// 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.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;
config.scheduler_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 {
Expand Down
16 changes: 4 additions & 12 deletions polkadot/runtime/parachains/src/assigner_coretime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mod tests;
use crate::{
assigner_on_demand, configuration,
paras::AssignCoretime,
scheduler::common::{Assignment, AssignmentProvider, AssignmentProviderConfig},
scheduler::common::{Assignment, AssignmentProvider},
ParaId,
};

Expand Down Expand Up @@ -316,14 +316,6 @@ impl<T: Config> AssignmentProvider<BlockNumberFor<T>> for Pallet<T> {
}
}

fn get_provider_config(_core_idx: CoreIndex) -> AssignmentProviderConfig<BlockNumberFor<T>> {
let config = <configuration::Pallet<T>>::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
Expand All @@ -333,7 +325,7 @@ impl<T: Config> AssignmentProvider<BlockNumberFor<T>> for Pallet<T> {

fn session_core_count() -> u32 {
let config = <configuration::Pallet<T>>::config();
config.coretime_cores
config.scheduler_params.num_cores
}
}

Expand Down Expand Up @@ -482,8 +474,8 @@ impl<T: Config> AssignCoretime for Pallet<T> {

// Add a new core and assign the para to it.
let mut config = <configuration::Pallet<T>>::config();
let core = config.coretime_cores;
config.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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ where
{
ParasShared::<T>::set_session_index(SESSION_INDEX);
let mut config = HostConfiguration::default();
config.coretime_cores = 1;
config.scheduler_params.num_cores = 1;
ConfigurationPallet::<T>::force_set_active_config(config);
let mut parachains = ParachainsCache::new();
ParasPallet::<T>::initialize_para_now(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.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;
config.scheduler_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 {
Expand Down
Loading

0 comments on commit a035dc9

Please # to comment.