From 73247c545adff6bfad363ad6db4e41ae42f21666 Mon Sep 17 00:00:00 2001 From: Chris Sosnin Date: Mon, 27 Mar 2023 19:06:35 +0400 Subject: [PATCH 1/5] Backport async backing params primitive --- primitives/src/vstaging/mod.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/primitives/src/vstaging/mod.rs b/primitives/src/vstaging/mod.rs index 64671bd48a60..c6b2755a5636 100644 --- a/primitives/src/vstaging/mod.rs +++ b/primitives/src/vstaging/mod.rs @@ -17,3 +17,26 @@ //! Staging Primitives. // Put any primitives used by staging APIs functions here +pub use crate::v4::*; +use sp_std::prelude::*; + +use parity_scale_codec::{Decode, Encode}; +use primitives::RuntimeDebug; +use scale_info::TypeInfo; + +/// Candidate's acceptance limitations for asynchronous backing per relay parent. +#[derive(RuntimeDebug, Copy, Clone, PartialEq, Encode, Decode, TypeInfo)] +#[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] +pub struct AsyncBackingParameters { + /// The maximum number of para blocks between the para head in a relay parent + /// and a new candidate. Restricts nodes from building arbitrary long chains + /// and spamming other validators. + /// + /// When async backing is disabled, the only valid value is 0. + pub max_candidate_depth: u32, + /// How many ancestors of a relay parent are allowed to build candidates on top + /// of. + /// + /// When async backing is disabled, the only valid value is 0. + pub allowed_ancestry_len: u32, +} From 352a607af5cec59e8d7fba9b2dca2eb677ef61bd Mon Sep 17 00:00:00 2001 From: Chris Sosnin Date: Mon, 27 Mar 2023 19:32:27 +0400 Subject: [PATCH 2/5] migration follow-up --- runtime/parachains/src/configuration.rs | 27 ++++++++++++++++++- .../parachains/src/configuration/migration.rs | 8 ++++++ runtime/parachains/src/configuration/tests.rs | 4 +++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/runtime/parachains/src/configuration.rs b/runtime/parachains/src/configuration.rs index 0e8420f51374..e6ca9558eb04 100644 --- a/runtime/parachains/src/configuration.rs +++ b/runtime/parachains/src/configuration.rs @@ -23,7 +23,10 @@ use frame_support::{pallet_prelude::*, weights::constants::WEIGHT_REF_TIME_PER_M 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::{Balance, SessionIndex, MAX_CODE_SIZE, MAX_HEAD_DATA_SIZE, MAX_POV_SIZE}; +use primitives::{ + vstaging::AsyncBackingParameters, Balance, SessionIndex, MAX_CODE_SIZE, MAX_HEAD_DATA_SIZE, + MAX_POV_SIZE, +}; use sp_runtime::traits::Zero; use sp_std::prelude::*; @@ -118,6 +121,8 @@ pub struct HostConfiguration { * The parameters that are not essential, but still may be of interest for parachains. */ + /// Asynchronous backing parameters. + pub async_backing_parameters: AsyncBackingParameters, /// The maximum POV block size, in bytes. pub max_pov_size: u32, /// The maximum size of a message that can be put in a downward message queue. @@ -243,6 +248,10 @@ pub struct HostConfiguration { impl> Default for HostConfiguration { fn default() -> Self { Self { + async_backing_parameters: AsyncBackingParameters { + max_candidate_depth: 0, + allowed_ancestry_len: 0, + }, group_rotation_frequency: 1u32.into(), chain_availability_period: 1u32.into(), thread_availability_period: 1u32.into(), @@ -1138,6 +1147,22 @@ pub mod pallet { BypassConsistencyCheck::::put(new); Ok(()) } + + /// Set the asynchronous backing parameters. + #[pallet::call_index(45)] + #[pallet::weight(( + T::WeightInfo::set_config_with_option_u32(), // The same size in bytes. + DispatchClass::Operational, + ))] + pub fn set_async_backing_parameters( + origin: OriginFor, + new: AsyncBackingParameters, + ) -> DispatchResult { + ensure_root(origin)?; + Self::schedule_config_update(|config| { + config.async_backing_parameters = new; + }) + } } #[pallet::hooks] diff --git a/runtime/parachains/src/configuration/migration.rs b/runtime/parachains/src/configuration/migration.rs index f38450a70d40..db044ab067e8 100644 --- a/runtime/parachains/src/configuration/migration.rs +++ b/runtime/parachains/src/configuration/migration.rs @@ -19,6 +19,7 @@ use crate::configuration::{self, ActiveConfig, Config, Pallet, PendingConfigs, MAX_POV_SIZE}; use frame_support::{pallet_prelude::*, traits::StorageVersion, weights::Weight}; use frame_system::pallet_prelude::BlockNumberFor; +use primitives::vstaging::AsyncBackingParameters; use sp_std::vec::Vec; /// The current storage version. @@ -226,6 +227,9 @@ ump_max_individual_weight : pre.ump_max_individual_weight, pvf_checking_enabled : pre.pvf_checking_enabled, pvf_voting_ttl : pre.pvf_voting_ttl, 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_parameters : AsyncBackingParameters { max_candidate_depth: 0, allowed_ancestry_len: 0 }, } }; @@ -383,6 +387,10 @@ mod tests { assert_eq!(v4.pvf_voting_ttl , v5.pvf_voting_ttl); assert_eq!(v4.minimum_validation_upgrade_delay , v5.minimum_validation_upgrade_delay); }; // ; makes this a statement. `rustfmt::skip` cannot be put on an expression. + + // additional checks for async backing. + assert_eq!(v5.async_backing_parameters.allowed_ancestry_len, 0); + assert_eq!(v5.async_backing_parameters.max_candidate_depth, 0); } }); } diff --git a/runtime/parachains/src/configuration/tests.rs b/runtime/parachains/src/configuration/tests.rs index eb29200a12c7..bd786767705f 100644 --- a/runtime/parachains/src/configuration/tests.rs +++ b/runtime/parachains/src/configuration/tests.rs @@ -281,6 +281,10 @@ fn consistency_bypass_works() { fn setting_pending_config_members() { new_test_ext(Default::default()).execute_with(|| { let new_config = HostConfiguration { + async_backing_parameters: primitives::vstaging::AsyncBackingParameters { + allowed_ancestry_len: 0, + max_candidate_depth: 0, + }, validation_upgrade_cooldown: 100, validation_upgrade_delay: 10, code_retention_period: 5, From c7b0d39967f427812d53d314953568b3f6021ca2 Mon Sep 17 00:00:00 2001 From: Chris Sosnin Date: Mon, 27 Mar 2023 19:53:51 +0400 Subject: [PATCH 3/5] link pr --- runtime/parachains/src/configuration/migration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/parachains/src/configuration/migration.rs b/runtime/parachains/src/configuration/migration.rs index db044ab067e8..480abb865f25 100644 --- a/runtime/parachains/src/configuration/migration.rs +++ b/runtime/parachains/src/configuration/migration.rs @@ -28,7 +28,7 @@ use sp_std::vec::Vec; /// v1-v2: /// v2-v3: /// v3-v4: -/// v4-v5: +/// v4-v5: + pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(5); pub mod v5 { From 5cfc79bacae8200a13bd59b9297bef869563dfd3 Mon Sep 17 00:00:00 2001 From: Chris Sosnin Date: Tue, 28 Mar 2023 18:11:36 +0400 Subject: [PATCH 4/5] parameters -> params --- primitives/src/vstaging/mod.rs | 2 +- runtime/parachains/src/configuration.rs | 12 ++++++------ runtime/parachains/src/configuration/migration.rs | 8 ++++---- runtime/parachains/src/configuration/tests.rs | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/primitives/src/vstaging/mod.rs b/primitives/src/vstaging/mod.rs index c6b2755a5636..9f5a99852e37 100644 --- a/primitives/src/vstaging/mod.rs +++ b/primitives/src/vstaging/mod.rs @@ -27,7 +27,7 @@ use scale_info::TypeInfo; /// Candidate's acceptance limitations for asynchronous backing per relay parent. #[derive(RuntimeDebug, Copy, Clone, PartialEq, Encode, Decode, TypeInfo)] #[cfg_attr(feature = "std", derive(serde::Serialize, serde::Deserialize))] -pub struct AsyncBackingParameters { +pub struct AsyncBackingParams { /// The maximum number of para blocks between the para head in a relay parent /// and a new candidate. Restricts nodes from building arbitrary long chains /// and spamming other validators. diff --git a/runtime/parachains/src/configuration.rs b/runtime/parachains/src/configuration.rs index e6ca9558eb04..b314e47202e9 100644 --- a/runtime/parachains/src/configuration.rs +++ b/runtime/parachains/src/configuration.rs @@ -24,7 +24,7 @@ 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::AsyncBackingParameters, Balance, SessionIndex, MAX_CODE_SIZE, MAX_HEAD_DATA_SIZE, + vstaging::AsyncBackingParams, Balance, SessionIndex, MAX_CODE_SIZE, MAX_HEAD_DATA_SIZE, MAX_POV_SIZE, }; use sp_runtime::traits::Zero; @@ -122,7 +122,7 @@ pub struct HostConfiguration { */ /// Asynchronous backing parameters. - pub async_backing_parameters: AsyncBackingParameters, + pub async_backing_params: AsyncBackingParams, /// The maximum POV block size, in bytes. pub max_pov_size: u32, /// The maximum size of a message that can be put in a downward message queue. @@ -248,7 +248,7 @@ pub struct HostConfiguration { impl> Default for HostConfiguration { fn default() -> Self { Self { - async_backing_parameters: AsyncBackingParameters { + async_backing_params: AsyncBackingParams { max_candidate_depth: 0, allowed_ancestry_len: 0, }, @@ -1154,13 +1154,13 @@ pub mod pallet { T::WeightInfo::set_config_with_option_u32(), // The same size in bytes. DispatchClass::Operational, ))] - pub fn set_async_backing_parameters( + pub fn set_async_backing_params( origin: OriginFor, - new: AsyncBackingParameters, + new: AsyncBackingParams, ) -> DispatchResult { ensure_root(origin)?; Self::schedule_config_update(|config| { - config.async_backing_parameters = new; + config.async_backing_params = new; }) } } diff --git a/runtime/parachains/src/configuration/migration.rs b/runtime/parachains/src/configuration/migration.rs index 480abb865f25..7a41c08dc175 100644 --- a/runtime/parachains/src/configuration/migration.rs +++ b/runtime/parachains/src/configuration/migration.rs @@ -19,7 +19,7 @@ use crate::configuration::{self, ActiveConfig, Config, Pallet, PendingConfigs, MAX_POV_SIZE}; use frame_support::{pallet_prelude::*, traits::StorageVersion, weights::Weight}; use frame_system::pallet_prelude::BlockNumberFor; -use primitives::vstaging::AsyncBackingParameters; +use primitives::vstaging::AsyncBackingParams; use sp_std::vec::Vec; /// The current storage version. @@ -229,7 +229,7 @@ pvf_voting_ttl : pre.pvf_voting_ttl, 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_parameters : AsyncBackingParameters { max_candidate_depth: 0, allowed_ancestry_len: 0 }, +async_backing_params : AsyncBackingParams { max_candidate_depth: 0, allowed_ancestry_len: 0 }, } }; @@ -389,8 +389,8 @@ mod tests { }; // ; makes this a statement. `rustfmt::skip` cannot be put on an expression. // additional checks for async backing. - assert_eq!(v5.async_backing_parameters.allowed_ancestry_len, 0); - assert_eq!(v5.async_backing_parameters.max_candidate_depth, 0); + assert_eq!(v5.async_backing_params.allowed_ancestry_len, 0); + assert_eq!(v5.async_backing_params.max_candidate_depth, 0); } }); } diff --git a/runtime/parachains/src/configuration/tests.rs b/runtime/parachains/src/configuration/tests.rs index bd786767705f..76c46e1f704b 100644 --- a/runtime/parachains/src/configuration/tests.rs +++ b/runtime/parachains/src/configuration/tests.rs @@ -281,7 +281,7 @@ fn consistency_bypass_works() { fn setting_pending_config_members() { new_test_ext(Default::default()).execute_with(|| { let new_config = HostConfiguration { - async_backing_parameters: primitives::vstaging::AsyncBackingParameters { + async_backing_params: primitives::vstaging::AsyncBackingParams { allowed_ancestry_len: 0, max_candidate_depth: 0, }, From a7d4e10d63f0d6f9981d6704002576cfb7fc843c Mon Sep 17 00:00:00 2001 From: Chris Sosnin Date: Tue, 28 Mar 2023 18:15:04 +0400 Subject: [PATCH 5/5] rustfmt::skip block ident --- runtime/parachains/src/configuration/migration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/parachains/src/configuration/migration.rs b/runtime/parachains/src/configuration/migration.rs index 7a41c08dc175..9f2ebd25c84f 100644 --- a/runtime/parachains/src/configuration/migration.rs +++ b/runtime/parachains/src/configuration/migration.rs @@ -229,7 +229,7 @@ pvf_voting_ttl : pre.pvf_voting_ttl, 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 }, +async_backing_params : AsyncBackingParams { max_candidate_depth: 0, allowed_ancestry_len: 0 }, } };