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

Enable changing executor params through governance #6934

Merged
merged 17 commits into from
Apr 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions primitives/src/v4/executor_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use sp_std::{ops::Deref, time::Duration, vec, vec::Vec};

/// The different executor parameters for changing the execution environment semantics.
#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq, TypeInfo)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub enum ExecutorParam {
/// Maximum number of memory pages (64KiB bytes per page) the executor can allocate.
#[codec(index = 1)]
Expand Down Expand Up @@ -93,6 +94,7 @@ impl sp_std::fmt::LowerHex for ExecutorParamsHash {
// new entries and removing old ones. At the moment, there's no mandatory parameters defined. If
// they show up, they must be clearly documented as mandatory ones.
#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq, TypeInfo)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub struct ExecutorParams(Vec<ExecutorParam>);

impl ExecutorParams {
Expand Down
2 changes: 2 additions & 0 deletions primitives/src/v4/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,7 @@ impl PvfCheckStatement {

/// Type discriminator for PVF preparation timeouts
#[derive(Encode, Decode, TypeInfo, Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub enum PvfPrepTimeoutKind {
/// For prechecking requests, the time period after which the preparation worker is considered
/// unresponsive and will be killed.
Expand All @@ -1721,6 +1722,7 @@ pub enum PvfPrepTimeoutKind {

/// Type discriminator for PVF execution timeouts
#[derive(Encode, Decode, TypeInfo, Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))]
pub enum PvfExecTimeoutKind {
/// The amount of time to spend on execution during backing.
Backing,
Expand Down
50 changes: 34 additions & 16 deletions runtime/kusama/src/weights/runtime_parachains_configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,26 @@
//! Autogenerated weights for `runtime_parachains::configuration`
//!
//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
//! DATE: 2023-03-16, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! DATE: 2023-04-07, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]`
//! WORST CASE MAP SIZE: `1000000`
//! HOSTNAME: `bm5`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz`
//! HOSTNAME: `bm3`, CPU: `Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz`
//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("kusama-dev"), DB CACHE: 1024

// Executed Command:
// ./target/production/polkadot
// target/production/polkadot
// benchmark
// pallet
// --chain=kusama-dev
// --steps=50
// --repeat=20
// --pallet=runtime_parachains::configuration
// --extrinsic=*
// --execution=wasm
// --wasm-execution=compiled
// --heap-pages=4096
// --json-file=/var/lib/gitlab-runner/builds/zyw4fam_/0/parity/mirrors/polkadot/.git/.artifacts/bench.json
// --pallet=runtime_parachains::configuration
// --chain=kusama-dev
// --header=./file_header.txt
// --output=./runtime/kusama/src/weights/runtime_parachains_configuration.rs
// --output=./runtime/kusama/src/weights/

#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
Expand All @@ -55,8 +57,8 @@ impl<T: frame_system::Config> runtime_parachains::configuration::WeightInfo for
// Proof Size summary in bytes:
// Measured: `90`
// Estimated: `4725`
// Minimum execution time: 8_970_000 picoseconds.
Weight::from_parts(9_143_000, 0)
// Minimum execution time: 9_394_000 picoseconds.
Weight::from_parts(9_686_000, 0)
.saturating_add(Weight::from_parts(0, 4725))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
Expand All @@ -71,8 +73,8 @@ impl<T: frame_system::Config> runtime_parachains::configuration::WeightInfo for
// Proof Size summary in bytes:
// Measured: `90`
// Estimated: `4725`
// Minimum execution time: 9_192_000 picoseconds.
Weight::from_parts(9_475_000, 0)
// Minimum execution time: 9_379_000 picoseconds.
Weight::from_parts(9_700_000, 0)
.saturating_add(Weight::from_parts(0, 4725))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
Expand All @@ -87,8 +89,8 @@ impl<T: frame_system::Config> runtime_parachains::configuration::WeightInfo for
// Proof Size summary in bytes:
// Measured: `90`
// Estimated: `4725`
// Minimum execution time: 9_259_000 picoseconds.
Weight::from_parts(9_499_000, 0)
// Minimum execution time: 9_612_000 picoseconds.
Weight::from_parts(16_194_000, 0)
.saturating_add(Weight::from_parts(0, 4725))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
Expand All @@ -103,8 +105,8 @@ impl<T: frame_system::Config> runtime_parachains::configuration::WeightInfo for
// Proof Size summary in bytes:
// Measured: `90`
// Estimated: `4725`
// Minimum execution time: 9_323_000 picoseconds.
Weight::from_parts(9_697_000, 0)
// Minimum execution time: 9_533_000 picoseconds.
Weight::from_parts(9_745_000, 0)
.saturating_add(Weight::from_parts(0, 4725))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
Expand All @@ -129,8 +131,24 @@ impl<T: frame_system::Config> runtime_parachains::configuration::WeightInfo for
// Proof Size summary in bytes:
// Measured: `90`
// Estimated: `4725`
// Minimum execution time: 9_270_000 picoseconds.
Weight::from_parts(9_527_000, 0)
// Minimum execution time: 9_463_000 picoseconds.
Weight::from_parts(9_852_000, 0)
.saturating_add(Weight::from_parts(0, 4725))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
}
/// Storage: Configuration PendingConfigs (r:1 w:1)
/// Proof Skipped: Configuration PendingConfigs (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: Configuration BypassConsistencyCheck (r:1 w:0)
/// Proof Skipped: Configuration BypassConsistencyCheck (max_values: Some(1), max_size: None, mode: Measured)
/// Storage: ParasShared CurrentSessionIndex (r:1 w:0)
/// Proof Skipped: ParasShared CurrentSessionIndex (max_values: Some(1), max_size: None, mode: Measured)
fn set_config_with_executor_params() -> Weight {
// Proof Size summary in bytes:
// Measured: `90`
// Estimated: `4725`
// Minimum execution time: 10_405_000 picoseconds.
Weight::from_parts(10_693_000, 0)
.saturating_add(Weight::from_parts(0, 4725))
.saturating_add(T::DbWeight::get().reads(3))
.saturating_add(T::DbWeight::get().writes(1))
Expand Down
24 changes: 22 additions & 2 deletions runtime/parachains/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ use frame_system::pallet_prelude::*;
use parity_scale_codec::{Decode, Encode};
use polkadot_parachain::primitives::{MAX_HORIZONTAL_MESSAGE_NUM, MAX_UPWARD_MESSAGE_NUM};
use primitives::{
vstaging::AsyncBackingParams, Balance, SessionIndex, MAX_CODE_SIZE, MAX_HEAD_DATA_SIZE,
MAX_POV_SIZE,
vstaging::AsyncBackingParams, Balance, ExecutorParams, SessionIndex, MAX_CODE_SIZE,
MAX_HEAD_DATA_SIZE, MAX_POV_SIZE,
};
use sp_runtime::traits::Zero;
use sp_std::prelude::*;
Expand Down Expand Up @@ -157,6 +157,8 @@ pub struct HostConfiguration<BlockNumber> {
///
/// This parameter affects the upper bound of size of `CandidateCommitments`.
pub hrmp_channel_max_message_size: u32,
/// The executor environment parameters
pub executor_params: ExecutorParams,

/**
* Parameters that will unlikely be needed by parachains.
Expand Down Expand Up @@ -296,6 +298,7 @@ impl<BlockNumber: Default + From<u32>> Default for HostConfiguration<BlockNumber
pvf_checking_enabled: false,
pvf_voting_ttl: 2u32.into(),
minimum_validation_upgrade_delay: 2.into(),
executor_params: Default::default(),
}
}
}
Expand Down Expand Up @@ -450,6 +453,7 @@ pub trait WeightInfo {
fn set_config_with_weight() -> Weight;
fn set_config_with_balance() -> Weight;
fn set_hrmp_open_request_ttl() -> Weight;
fn set_config_with_executor_params() -> Weight;
}

pub struct TestWeightInfo;
Expand All @@ -472,6 +476,9 @@ impl WeightInfo for TestWeightInfo {
fn set_hrmp_open_request_ttl() -> Weight {
Weight::MAX
}
fn set_config_with_executor_params() -> Weight {
Weight::MAX
}
}

#[frame_support::pallet]
Expand Down Expand Up @@ -1163,6 +1170,19 @@ pub mod pallet {
config.async_backing_params = new;
})
}

/// Set PVF executor parameters.
#[pallet::call_index(46)]
#[pallet::weight((
T::WeightInfo::set_config_with_executor_params(),
DispatchClass::Operational,
))]
pub fn set_executor_params(origin: OriginFor<T>, new: ExecutorParams) -> DispatchResult {
ensure_root(origin)?;
Self::schedule_config_update(|config| {
config.executor_params = new;
})
}
}

#[pallet::hooks]
Expand Down
13 changes: 13 additions & 0 deletions runtime/parachains/src/configuration/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use crate::configuration::*;
use frame_benchmarking::{benchmarks, BenchmarkError, BenchmarkResult};
use frame_system::RawOrigin;
use primitives::{ExecutorParam, ExecutorParams, PvfExecTimeoutKind, PvfPrepTimeoutKind};
use sp_runtime::traits::One;

benchmarks! {
Expand All @@ -36,6 +37,18 @@ benchmarks! {

set_config_with_balance {}: set_hrmp_sender_deposit(RawOrigin::Root, 100_000_000_000)

set_config_with_executor_params {}: set_executor_params(RawOrigin::Root, ExecutorParams::from(&[
ExecutorParam::MaxMemoryPages(2080),
ExecutorParam::StackLogicalMax(65536),
ExecutorParam::StackNativeMax(256 * 1024 * 1024),
ExecutorParam::WasmExtBulkMemory,
ExecutorParam::PrecheckingMaxMemory(2 * 1024 * 1024 * 1024),
ExecutorParam::PvfPrepTimeout(PvfPrepTimeoutKind::Precheck, 60_000),
ExecutorParam::PvfPrepTimeout(PvfPrepTimeoutKind::Lenient, 360_000),
ExecutorParam::PvfExecTimeout(PvfExecTimeoutKind::Backing, 2_000),
ExecutorParam::PvfExecTimeout(PvfExecTimeoutKind::Approval, 12_000),
][..]))

impl_benchmark_test_suite!(
Pallet,
crate::mock::new_test_ext(Default::default()),
Expand Down
9 changes: 8 additions & 1 deletion runtime/parachains/src/configuration/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ use sp_std::vec::Vec;
/// v1-v2: <https://github.com/paritytech/polkadot/pull/4420>
/// v2-v3: <https://github.com/paritytech/polkadot/pull/6091>
/// v3-v4: <https://github.com/paritytech/polkadot/pull/6345>
/// v4-v5: <https://github.com/paritytech/polkadot/pull/6937> + <https://github.com/paritytech/polkadot/pull/6961>
/// v4-v5: <https://github.com/paritytech/polkadot/pull/6937>
/// + <https://github.com/paritytech/polkadot/pull/6961>
/// + <https://github.com/paritytech/polkadot/pull/6934>
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(5);

pub mod v5 {
Expand Down Expand Up @@ -230,6 +232,9 @@ minimum_validation_upgrade_delay : pre.minimum_validation_upgrade_delay,

// Default values are zeroes, thus it's ensured allowed ancestry never crosses the upgrade block.
async_backing_params : AsyncBackingParams { max_candidate_depth: 0, allowed_ancestry_len: 0 },

// Default executor parameters set is empty
executor_params : Default::default(),
}
};

Expand Down Expand Up @@ -268,6 +273,7 @@ async_backing_params : AsyncBackingParams { max_candidate_de
mod tests {
use super::*;
use crate::mock::{new_test_ext, Test};
use primitives::ExecutorParams;

#[test]
fn v4_deserialized_from_actual_data() {
Expand Down Expand Up @@ -391,6 +397,7 @@ mod tests {
// additional checks for async backing.
assert_eq!(v5.async_backing_params.allowed_ancestry_len, 0);
assert_eq!(v5.async_backing_params.max_candidate_depth, 0);
assert_eq!(v5.executor_params, ExecutorParams::new());
}
});
}
Expand Down
1 change: 1 addition & 0 deletions runtime/parachains/src/configuration/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ fn setting_pending_config_members() {
pvf_checking_enabled: true,
pvf_voting_ttl: 3,
minimum_validation_upgrade_delay: 20,
executor_params: Default::default(),
};

Configuration::set_validation_upgrade_cooldown(
Expand Down
14 changes: 3 additions & 11 deletions runtime/parachains/src/session_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ use frame_support::{
pallet_prelude::*,
traits::{OneSessionHandler, ValidatorSet, ValidatorSetWithIdentification},
};
use primitives::{
AssignmentId, AuthorityDiscoveryId, ExecutorParam, ExecutorParams, SessionIndex, SessionInfo,
};
use primitives::{AssignmentId, AuthorityDiscoveryId, ExecutorParams, SessionIndex, SessionInfo};
use sp_std::vec::Vec;

pub use pallet::*;
Expand All @@ -39,10 +37,6 @@ pub mod migration;
#[cfg(test)]
mod tests;

// The order of parameters should be deterministic, that is, one should not reorder them when
// changing the array contents to avoid creating excessive pressure to PVF execution subsys.
const EXECUTOR_PARAMS: [ExecutorParam; 0] = [];

/// A type for representing the validator account id in a session.
pub type AccountId<T> = <<T as Config>::ValidatorSet as ValidatorSet<
<T as frame_system::Config>::AccountId,
Expand Down Expand Up @@ -196,10 +190,8 @@ impl<T: Config> Pallet<T> {
dispute_period,
};
Sessions::<T>::insert(&new_session_index, &new_session_info);
SessionExecutorParams::<T>::insert(
&new_session_index,
ExecutorParams::from(&EXECUTOR_PARAMS[..]),
);

SessionExecutorParams::<T>::insert(&new_session_index, config.executor_params);
}

/// Called by the initializer to initialize the session info pallet.
Expand Down
Loading