From 4e0f65b6a8572b90b0c0cc360dc91dc4f59fa2b1 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Wed, 22 Mar 2023 13:01:39 +0000 Subject: [PATCH 01/14] Limit disputes weight and remove initializer code Signed-off-by: Andrei Sandu --- Cargo.lock | 1 + runtime/parachains/Cargo.toml | 1 + runtime/parachains/src/disputes.rs | 27 ++----------- runtime/parachains/src/paras_inherent/mod.rs | 41 ++++++++++---------- 4 files changed, 26 insertions(+), 44 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 399fe4e71d7d..e00268b43882 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7717,6 +7717,7 @@ dependencies = [ "serde_json", "sp-api", "sp-application-crypto", + "sp-arithmetic", "sp-core", "sp-inherents", "sp-io", diff --git a/runtime/parachains/Cargo.toml b/runtime/parachains/Cargo.toml index 2bd485c7fa55..0c86f5741301 100644 --- a/runtime/parachains/Cargo.toml +++ b/runtime/parachains/Cargo.toml @@ -25,6 +25,7 @@ sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true } sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } +sp-arithmetic = { package = "sp-arithmetic", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-authority-discovery = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-authorship = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } diff --git a/runtime/parachains/src/disputes.rs b/runtime/parachains/src/disputes.rs index a0e4ff9e7a96..6350361816f6 100644 --- a/runtime/parachains/src/disputes.rs +++ b/runtime/parachains/src/disputes.rs @@ -18,7 +18,7 @@ use crate::{configuration, initializer::SessionChangeNotification, session_info}; use bitvec::{bitvec, order::Lsb0 as BitOrderLsb0}; -use frame_support::{ensure, traits::Get, weights::Weight}; +use frame_support::{ensure, weights::Weight}; use frame_system::pallet_prelude::*; use parity_scale_codec::{Decode, Encode}; use primitives::{ @@ -503,9 +503,6 @@ pub mod pallet { /// A dispute has concluded for or against a candidate. /// `\[para id, candidate hash, dispute result\]` DisputeConcluded(CandidateHash, DisputeResult), - /// A dispute has timed out due to insufficient participation. - /// `\[para id, candidate hash\]` - DisputeTimedOut(CandidateHash), /// A dispute has concluded with supermajority against a candidate. /// Block authors should no longer build on top of this head and should /// instead revert the block at the given height. This should be the @@ -911,26 +908,8 @@ impl StatementSetFilter { impl Pallet { /// Called by the initializer to initialize the disputes module. - pub(crate) fn initializer_initialize(now: T::BlockNumber) -> Weight { - let config = >::config(); - - let mut weight = Weight::zero(); - for (session_index, candidate_hash, mut dispute) in >::iter() { - weight += T::DbWeight::get().reads_writes(1, 0); - - if dispute.concluded_at.is_none() && - dispute.start + config.dispute_conclusion_by_time_out_period < now - { - Self::deposit_event(Event::DisputeTimedOut(candidate_hash)); - - dispute.concluded_at = Some(now); - >::insert(session_index, candidate_hash, &dispute); - - weight += T::DbWeight::get().writes(1); - } - } - - weight + pub(crate) fn initializer_initialize(_now: T::BlockNumber) -> Weight { + Weight::zero() } /// Called by the initializer to finalize the disputes pallet. diff --git a/runtime/parachains/src/paras_inherent/mod.rs b/runtime/parachains/src/paras_inherent/mod.rs index c2dff1e16487..a4069edf6c4b 100644 --- a/runtime/parachains/src/paras_inherent/mod.rs +++ b/runtime/parachains/src/paras_inherent/mod.rs @@ -50,6 +50,7 @@ use primitives::{ use rand::{seq::SliceRandom, SeedableRng}; use scale_info::TypeInfo; +use sp_arithmetic::Percent; use sp_runtime::traits::{Header as HeaderT, One}; use sp_std::{ cmp::Ordering, @@ -305,8 +306,8 @@ impl Pallet { full_check: FullCheck, ) -> DispatchResultWithPostInfo { let ParachainsInherentData { - bitfields: mut signed_bitfields, - mut backed_candidates, + bitfields: signed_bitfields, + backed_candidates, parent_header, mut disputes, } = data; @@ -331,14 +332,29 @@ impl Pallet { let now = >::block_number(); - let mut candidates_weight = backed_candidates_weight::(&backed_candidates); - let mut bitfields_weight = signed_bitfields_weight::(signed_bitfields.len()); + let candidates_weight = backed_candidates_weight::(&backed_candidates); + let bitfields_weight = signed_bitfields_weight::(signed_bitfields.len()); let disputes_weight = multi_dispute_statement_sets_weight::(&disputes); let current_session = >::session_index(); let max_block_weight = ::BlockWeights::get().max_block; + // At most 60% of total block space will be dispute votes. + let mut max_disputes_weight = Weight::from_parts( + Percent::from_percent(60).mul_floor(max_block_weight.ref_time()), + max_block_weight.proof_size(), + ); + + // Compute the excess weight value. + let spill = candidates_weight + .saturating_add(bitfields_weight) + .saturating_add(disputes_weight) + .saturating_sub(max_block_weight); + + // Constrain max dispute weight to ensure block will not be overweight. + max_disputes_weight -= spill; + METRICS .on_before_filter((candidates_weight + bitfields_weight + disputes_weight).ref_time()); @@ -366,28 +382,13 @@ impl Pallet { ) }; - // In case of an overweight block, consume up to the entire block weight - // in disputes, since we will never process anything else, but invalidate - // the block. It's still reasonable to protect against a massive amount of disputes. - if candidates_weight - .saturating_add(bitfields_weight) - .saturating_add(disputes_weight) - .any_gt(max_block_weight) - { - log::warn!("Overweight para inherent data reached the runtime {:?}", parent_hash); - backed_candidates.clear(); - candidates_weight = Weight::zero(); - signed_bitfields.clear(); - bitfields_weight = Weight::zero(); - } - let entropy = compute_entropy::(parent_hash); let mut rng = rand_chacha::ChaChaRng::from_seed(entropy.into()); let (checked_disputes, checked_disputes_weight) = limit_and_sanitize_disputes::( disputes, &dispute_set_validity_check, - max_block_weight, + max_disputes_weight, &mut rng, ); ( From de17b483eae859329d0c375d824f6042f9ce4d53 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Wed, 22 Mar 2023 13:35:51 +0000 Subject: [PATCH 02/14] const Signed-off-by: Andrei Sandu --- runtime/parachains/src/paras_inherent/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/parachains/src/paras_inherent/mod.rs b/runtime/parachains/src/paras_inherent/mod.rs index a4069edf6c4b..d8163bd5afa6 100644 --- a/runtime/parachains/src/paras_inherent/mod.rs +++ b/runtime/parachains/src/paras_inherent/mod.rs @@ -78,6 +78,7 @@ mod benchmarking; mod tests; const LOG_TARGET: &str = "runtime::inclusion-inherent"; +const MAX_DISPUTES_WEIGHT_PERCENT: Percent = Percent::from_percent(70); /// A bitfield concerning concluded disputes for candidates /// associated to the core index equivalent to the bit position. @@ -342,7 +343,7 @@ impl Pallet { // At most 60% of total block space will be dispute votes. let mut max_disputes_weight = Weight::from_parts( - Percent::from_percent(60).mul_floor(max_block_weight.ref_time()), + MAX_DISPUTES_WEIGHT_PERCENT.mul_floor(max_block_weight.ref_time()), max_block_weight.proof_size(), ); From 882e7d37970a6f8b10cd13d5f9d6ae6dffdcbd9a Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Wed, 22 Mar 2023 13:36:05 +0000 Subject: [PATCH 03/14] remove timeout test Signed-off-by: Andrei Sandu --- runtime/parachains/src/disputes/tests.rs | 125 ----------------------- 1 file changed, 125 deletions(-) diff --git a/runtime/parachains/src/disputes/tests.rs b/runtime/parachains/src/disputes/tests.rs index b12814fd72be..afbfa4bc603f 100644 --- a/runtime/parachains/src/disputes/tests.rs +++ b/runtime/parachains/src/disputes/tests.rs @@ -329,131 +329,6 @@ fn test_import_backing_votes() { ); } -// Test that dispute timeout is handled correctly. -#[test] -fn test_dispute_timeout() { - let dispute_conclusion_by_time_out_period = 3; - let start = 10; - - let mock_genesis_config = MockGenesisConfig { - configuration: crate::configuration::GenesisConfig { - config: HostConfiguration { - dispute_conclusion_by_time_out_period, - ..Default::default() - }, - ..Default::default() - }, - ..Default::default() - }; - - new_test_ext(mock_genesis_config).execute_with(|| { - // We need 7 validators for the byzantine threshold to be 2 - let v0 = ::Pair::generate().0; - let v1 = ::Pair::generate().0; - let v2 = ::Pair::generate().0; - let v3 = ::Pair::generate().0; - let v4 = ::Pair::generate().0; - let v5 = ::Pair::generate().0; - let v6 = ::Pair::generate().0; - - run_to_block(start, |b| { - // a new session at each block - Some(( - true, - b, - vec![ - (&0, v0.public()), - (&1, v1.public()), - (&2, v2.public()), - (&3, v3.public()), - (&4, v4.public()), - (&5, v5.public()), - (&6, v6.public()), - ], - Some(vec![ - (&0, v0.public()), - (&1, v1.public()), - (&2, v2.public()), - (&3, v3.public()), - (&4, v4.public()), - (&5, v5.public()), - (&6, v6.public()), - ]), - )) - }); - - let candidate_hash = CandidateHash(sp_core::H256::repeat_byte(1)); - let inclusion_parent = sp_core::H256::repeat_byte(0xff); - - // v0 and v1 vote for 3, v2 against. We need f+1 votes (3) so that the dispute is - // confirmed. Otherwise It will be filtered out. - let session = start - 1; - let stmts = vec![DisputeStatementSet { - candidate_hash: candidate_hash.clone(), - session, - statements: vec![ - ( - DisputeStatement::Valid(ValidDisputeStatementKind::BackingValid( - inclusion_parent, - )), - ValidatorIndex(0), - v0.sign(&CompactStatement::Valid(candidate_hash).signing_payload( - &SigningContext { session_index: start - 1, parent_hash: inclusion_parent }, - )), - ), - ( - DisputeStatement::Valid(ValidDisputeStatementKind::Explicit), - ValidatorIndex(1), - v1.sign( - &ExplicitDisputeStatement { - valid: true, - candidate_hash: candidate_hash.clone(), - session: start - 1, - } - .signing_payload(), - ), - ), - ( - DisputeStatement::Invalid(InvalidDisputeStatementKind::Explicit), - ValidatorIndex(6), - v2.sign( - &ExplicitDisputeStatement { - valid: false, - candidate_hash: candidate_hash.clone(), - session: start - 1, - } - .signing_payload(), - ), - ), - ], - }]; - - let stmts = filter_dispute_set(stmts); - - assert_ok!( - Pallet::::process_checked_multi_dispute_data(&stmts), - vec![(9, candidate_hash.clone())], - ); - - // Run to timeout period - run_to_block(start + dispute_conclusion_by_time_out_period, |_| None); - assert!(>::get(&session, &candidate_hash) - .expect("dispute should exist") - .concluded_at - .is_none()); - - // Run to timeout + 1 in order to executive on_finalize(timeout) - run_to_block(start + dispute_conclusion_by_time_out_period + 1, |_| None); - assert_eq!( - >::get(&session, &candidate_hash) - .expect("dispute should exist") - .concluded_at - .expect("dispute should have concluded"), - start + dispute_conclusion_by_time_out_period + 1 - ); - }); -} - // Test pruning works #[test] fn test_initializer_on_new_session() { From a5ba76417d0253836263756e7a5040b20d972ee4 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Wed, 22 Mar 2023 15:10:19 +0000 Subject: [PATCH 04/14] review feedback #1 Signed-off-by: Andrei Sandu --- runtime/parachains/src/paras_inherent/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/parachains/src/paras_inherent/mod.rs b/runtime/parachains/src/paras_inherent/mod.rs index d8163bd5afa6..9294ab88e4fa 100644 --- a/runtime/parachains/src/paras_inherent/mod.rs +++ b/runtime/parachains/src/paras_inherent/mod.rs @@ -341,7 +341,7 @@ impl Pallet { let max_block_weight = ::BlockWeights::get().max_block; - // At most 60% of total block space will be dispute votes. + // At most `MAX_DISPUTES_WEIGHT_PERCENT` of total block space will be dispute votes. let mut max_disputes_weight = Weight::from_parts( MAX_DISPUTES_WEIGHT_PERCENT.mul_floor(max_block_weight.ref_time()), max_block_weight.proof_size(), @@ -354,7 +354,7 @@ impl Pallet { .saturating_sub(max_block_weight); // Constrain max dispute weight to ensure block will not be overweight. - max_disputes_weight -= spill; + max_disputes_weight = max_disputes_weight.saturating_sub(spill); METRICS .on_before_filter((candidates_weight + bitfields_weight + disputes_weight).ref_time()); From 91efd2b50d1d1a1b8f0a897ad8101bab32be9f20 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Thu, 23 Mar 2023 10:53:30 +0000 Subject: [PATCH 05/14] Remove the new weight limiting for disputes Signed-off-by: Andrei Sandu --- runtime/parachains/Cargo.toml | 1 - runtime/parachains/src/paras_inherent/mod.rs | 42 ++++++++++---------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/runtime/parachains/Cargo.toml b/runtime/parachains/Cargo.toml index 0c86f5741301..2bd485c7fa55 100644 --- a/runtime/parachains/Cargo.toml +++ b/runtime/parachains/Cargo.toml @@ -25,7 +25,6 @@ sp-core = { git = "https://github.com/paritytech/substrate", branch = "master", sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "master", optional = true } sp-application-crypto = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } sp-tracing = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false, optional = true } -sp-arithmetic = { package = "sp-arithmetic", git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-authority-discovery = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } pallet-authorship = { git = "https://github.com/paritytech/substrate", branch = "master", default-features = false } diff --git a/runtime/parachains/src/paras_inherent/mod.rs b/runtime/parachains/src/paras_inherent/mod.rs index 9294ab88e4fa..c2dff1e16487 100644 --- a/runtime/parachains/src/paras_inherent/mod.rs +++ b/runtime/parachains/src/paras_inherent/mod.rs @@ -50,7 +50,6 @@ use primitives::{ use rand::{seq::SliceRandom, SeedableRng}; use scale_info::TypeInfo; -use sp_arithmetic::Percent; use sp_runtime::traits::{Header as HeaderT, One}; use sp_std::{ cmp::Ordering, @@ -78,7 +77,6 @@ mod benchmarking; mod tests; const LOG_TARGET: &str = "runtime::inclusion-inherent"; -const MAX_DISPUTES_WEIGHT_PERCENT: Percent = Percent::from_percent(70); /// A bitfield concerning concluded disputes for candidates /// associated to the core index equivalent to the bit position. @@ -307,8 +305,8 @@ impl Pallet { full_check: FullCheck, ) -> DispatchResultWithPostInfo { let ParachainsInherentData { - bitfields: signed_bitfields, - backed_candidates, + bitfields: mut signed_bitfields, + mut backed_candidates, parent_header, mut disputes, } = data; @@ -333,29 +331,14 @@ impl Pallet { let now = >::block_number(); - let candidates_weight = backed_candidates_weight::(&backed_candidates); - let bitfields_weight = signed_bitfields_weight::(signed_bitfields.len()); + let mut candidates_weight = backed_candidates_weight::(&backed_candidates); + let mut bitfields_weight = signed_bitfields_weight::(signed_bitfields.len()); let disputes_weight = multi_dispute_statement_sets_weight::(&disputes); let current_session = >::session_index(); let max_block_weight = ::BlockWeights::get().max_block; - // At most `MAX_DISPUTES_WEIGHT_PERCENT` of total block space will be dispute votes. - let mut max_disputes_weight = Weight::from_parts( - MAX_DISPUTES_WEIGHT_PERCENT.mul_floor(max_block_weight.ref_time()), - max_block_weight.proof_size(), - ); - - // Compute the excess weight value. - let spill = candidates_weight - .saturating_add(bitfields_weight) - .saturating_add(disputes_weight) - .saturating_sub(max_block_weight); - - // Constrain max dispute weight to ensure block will not be overweight. - max_disputes_weight = max_disputes_weight.saturating_sub(spill); - METRICS .on_before_filter((candidates_weight + bitfields_weight + disputes_weight).ref_time()); @@ -383,13 +366,28 @@ impl Pallet { ) }; + // In case of an overweight block, consume up to the entire block weight + // in disputes, since we will never process anything else, but invalidate + // the block. It's still reasonable to protect against a massive amount of disputes. + if candidates_weight + .saturating_add(bitfields_weight) + .saturating_add(disputes_weight) + .any_gt(max_block_weight) + { + log::warn!("Overweight para inherent data reached the runtime {:?}", parent_hash); + backed_candidates.clear(); + candidates_weight = Weight::zero(); + signed_bitfields.clear(); + bitfields_weight = Weight::zero(); + } + let entropy = compute_entropy::(parent_hash); let mut rng = rand_chacha::ChaChaRng::from_seed(entropy.into()); let (checked_disputes, checked_disputes_weight) = limit_and_sanitize_disputes::( disputes, &dispute_set_validity_check, - max_disputes_weight, + max_block_weight, &mut rng, ); ( From 4790096b2162fe00fdf10014d36d64715864fac9 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Thu, 23 Mar 2023 11:16:08 +0000 Subject: [PATCH 06/14] cargo lock Signed-off-by: Andrei Sandu --- Cargo.lock | 1 - 1 file changed, 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index e00268b43882..399fe4e71d7d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7717,7 +7717,6 @@ dependencies = [ "serde_json", "sp-api", "sp-application-crypto", - "sp-arithmetic", "sp-core", "sp-inherents", "sp-io", From 96a580410bf20447b3022f452cc19cb14a288410 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Thu, 23 Mar 2023 11:19:45 +0000 Subject: [PATCH 07/14] Remove dispute_conclusion_by_time_out_period Signed-off-by: Andrei Sandu --- .../implementers-guide/src/types/runtime.md | 2 - runtime/parachains/src/configuration.rs | 19 --- .../parachains/src/configuration/migration.rs | 145 +++++++++--------- runtime/parachains/src/configuration/tests.rs | 6 - 4 files changed, 69 insertions(+), 103 deletions(-) diff --git a/roadmap/implementers-guide/src/types/runtime.md b/roadmap/implementers-guide/src/types/runtime.md index d3d00d5163b3..e3fc3f0a6527 100644 --- a/roadmap/implementers-guide/src/types/runtime.md +++ b/roadmap/implementers-guide/src/types/runtime.md @@ -44,8 +44,6 @@ struct HostConfiguration { pub dispute_post_conclusion_acceptance_period: BlockNumber, /// The maximum number of dispute spam slots pub dispute_max_spam_slots: u32, - /// How long it takes for a dispute to conclude by time-out, if no supermajority is reached. - pub dispute_conclusion_by_time_out_period: BlockNumber, /// 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. diff --git a/runtime/parachains/src/configuration.rs b/runtime/parachains/src/configuration.rs index baeb31ef501a..0e8420f51374 100644 --- a/runtime/parachains/src/configuration.rs +++ b/runtime/parachains/src/configuration.rs @@ -193,8 +193,6 @@ pub struct HostConfiguration { pub dispute_period: SessionIndex, /// How long after dispute conclusion to accept statements. pub dispute_post_conclusion_acceptance_period: BlockNumber, - /// How long it takes for a dispute to conclude by time-out, if no supermajority is reached. - pub dispute_conclusion_by_time_out_period: BlockNumber, /// 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. /// @@ -262,7 +260,6 @@ impl> Default for HostConfiguration, - new: T::BlockNumber, - ) -> DispatchResult { - ensure_root(origin)?; - Self::schedule_config_update(|config| { - config.dispute_conclusion_by_time_out_period = new; - }) - } - /// Set the no show slots, in number of number of consensus slots. /// Must be at least 1. #[pallet::call_index(18)] diff --git a/runtime/parachains/src/configuration/migration.rs b/runtime/parachains/src/configuration/migration.rs index 7b2092cfc2c1..071a4ef95eb3 100644 --- a/runtime/parachains/src/configuration/migration.rs +++ b/runtime/parachains/src/configuration/migration.rs @@ -26,9 +26,10 @@ use frame_system::pallet_prelude::BlockNumberFor; /// v1-v2: /// v2-v3: /// v3-v4: -pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(4); +/// v4-v5: +pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(5); -pub mod v4 { +pub mod v5 { use super::*; use frame_support::{traits::OnRuntimeUpgrade, weights::constants::WEIGHT_REF_TIME_PER_MILLIS}; use primitives::{Balance, SessionIndex}; @@ -71,7 +72,6 @@ pub mod v4 { pub max_validators: Option, pub dispute_period: SessionIndex, pub dispute_post_conclusion_acceptance_period: BlockNumber, - pub dispute_max_spam_slots: u32, pub dispute_conclusion_by_time_out_period: BlockNumber, pub no_show_slots: u32, pub n_delay_tranches: u32, @@ -104,7 +104,6 @@ pub mod v4 { max_validators: None, dispute_period: 6, dispute_post_conclusion_acceptance_period: 100.into(), - dispute_max_spam_slots: 2, dispute_conclusion_by_time_out_period: 200.into(), n_delay_tranches: Default::default(), zeroth_delay_tranche_width: Default::default(), @@ -137,8 +136,8 @@ pub mod v4 { } } - pub struct MigrateToV4(sp_std::marker::PhantomData); - impl OnRuntimeUpgrade for MigrateToV4 { + pub struct MigrateToV5(sp_std::marker::PhantomData); + impl OnRuntimeUpgrade for MigrateToV5 { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, &'static str> { log::trace!(target: crate::configuration::LOG_TARGET, "Running pre_upgrade()"); @@ -148,15 +147,15 @@ pub mod v4 { } fn on_runtime_upgrade() -> Weight { - if StorageVersion::get::>() == 3 { - let weight_consumed = migrate_to_v4::(); + if StorageVersion::get::>() == 4 { + let weight_consumed = migrate_to_v5::(); - log::info!(target: configuration::LOG_TARGET, "MigrateToV4 executed successfully"); + log::info!(target: configuration::LOG_TARGET, "MigrateToV5 executed successfully"); STORAGE_VERSION.put::>(); weight_consumed } else { - log::warn!(target: configuration::LOG_TARGET, "MigrateToV4 should be removed."); + log::warn!(target: configuration::LOG_TARGET, "MigrateToV5 should be removed."); T::DbWeight::get().reads(1) } } @@ -166,7 +165,7 @@ pub mod v4 { log::trace!(target: crate::configuration::LOG_TARGET, "Running post_upgrade()"); ensure!( StorageVersion::get::>() == STORAGE_VERSION, - "Storage version should be 4 after the migration" + "Storage version should be 5 after the migration" ); Ok(()) @@ -174,14 +173,14 @@ pub mod v4 { } } -fn migrate_to_v4() -> Weight { +fn migrate_to_v5() -> 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: v4::OldHostConfiguration>| -> + |pre: v5::OldHostConfiguration>| -> configuration::HostConfiguration> { super::HostConfiguration { @@ -217,7 +216,6 @@ 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, -dispute_conclusion_by_time_out_period : pre.dispute_conclusion_by_time_out_period, no_show_slots : pre.no_show_slots, n_delay_tranches : pre.n_delay_tranches, zeroth_delay_tranche_width : pre.zeroth_delay_tranche_width, @@ -251,10 +249,9 @@ mod tests { use crate::mock::{new_test_ext, Test}; #[test] - fn v3_deserialized_from_actual_data() { + fn v4_deserialized_from_actual_data() { // Example how to get new `raw_config`: - // We'll obtain the raw_config hes for block - // 15,772,152 (0xf89d3ab5312c5f70d396dc59612f0aa65806c798346f9db4b35278baed2e0e53) on Kusama. + // 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: @@ -265,28 +262,26 @@ mod tests { // 3. Go to Polkadot.js -> Developer -> Chain state -> Raw storage // 3.1 Enter the encoded storage key and you get the raw config. - // Fetched at Kusama 15,772,152 (0xf89d3ab5312c5f70d396dc59612f0aa65806c798346f9db4b35278baed2e0e53) - // // 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!["0000a000005000000a00000000c8000000c800000a0000000a000000100e0000580200000000500000c800000700e8764817020040011e00000000000000005039278c0400000000000000000000005039278c0400000000000000000000e8030000009001001e00000000000000009001008070000000000000000000000a0000000a0000000a00000001000000010500000001c8000000060000005802000002000000580200000200000059000000000000001e000000280000000700c817a80402004001000200000014000000"]; + let raw_config = hex_literal::hex!["0000a000005000000a00000000c8000000c800000a0000000a000000100e0000580200000000500000c800000700e8764817020040011e00000000000000005039278c0400000000000000000000005039278c0400000000000000000000e8030000009001001e00000000000000009001008070000000000000000000000a0000000a0000000a00000001000000010500000001c80000000600000058020000580200000200000059000000000000001e000000280000000700c817a80402004001010200000014000000"]; - let v3 = v4::OldHostConfiguration::::decode(&mut &raw_config[..]) + let v4 = v5::OldHostConfiguration::::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!(v3.max_code_size, 10_485_760); - assert_eq!(v3.validation_upgrade_cooldown, 3600); - assert_eq!(v3.max_pov_size, 5_242_880); - assert_eq!(v3.hrmp_channel_max_message_size, 102_400); - assert_eq!(v3.n_delay_tranches, 89); - assert_eq!(v3.ump_max_individual_weight, Weight::from_parts(20_000_000_000, 5_242_880)); - assert_eq!(v3.minimum_validation_upgrade_delay, 20); + assert_eq!(v4.max_code_size, 10_485_760); + assert_eq!(v4.validation_upgrade_cooldown, 3600); + assert_eq!(v4.max_pov_size, 5_242_880); + assert_eq!(v4.hrmp_channel_max_message_size, 102_400); + assert_eq!(v4.n_delay_tranches, 89); + assert_eq!(v4.ump_max_individual_weight, Weight::from_parts(20_000_000_000, 5_242_880)); + assert_eq!(v4.minimum_validation_upgrade_delay, 20); } #[test] - fn test_migrate_to_v4() { + fn test_migrate_to_v5() { // Host configuration has lots of fields. However, in this migration we add only a couple of // fields. 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 @@ -295,7 +290,7 @@ mod tests { // 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 v3 = v4::OldHostConfiguration:: { + let v4 = v5::OldHostConfiguration:: { ump_max_individual_weight: Weight::from_parts(0x71616e6f6e0au64, 0x71616e6f6e0au64), needed_approvals: 69, thread_availability_period: 55, @@ -307,60 +302,58 @@ mod tests { }; new_test_ext(Default::default()).execute_with(|| { - // Implant the v3 version in the state. + // Implant the v4 version in the state. frame_support::storage::unhashed::put_raw( &configuration::ActiveConfig::::hashed_key(), - &v3.encode(), + &v4.encode(), ); - migrate_to_v4::(); + migrate_to_v5::(); - let v4 = configuration::ActiveConfig::::get(); + let v5 = configuration::ActiveConfig::::get(); #[rustfmt::skip] { - assert_eq!(v3.max_code_size , v4.max_code_size); - assert_eq!(v3.max_head_data_size , v4.max_head_data_size); - assert_eq!(v3.max_upward_queue_count , v4.max_upward_queue_count); - assert_eq!(v3.max_upward_queue_size , v4.max_upward_queue_size); - assert_eq!(v3.max_upward_message_size , v4.max_upward_message_size); - assert_eq!(v3.max_upward_message_num_per_candidate , v4.max_upward_message_num_per_candidate); - assert_eq!(v3.hrmp_max_message_num_per_candidate , v4.hrmp_max_message_num_per_candidate); - assert_eq!(v3.validation_upgrade_cooldown , v4.validation_upgrade_cooldown); - assert_eq!(v3.validation_upgrade_delay , v4.validation_upgrade_delay); - assert_eq!(v3.max_pov_size , v4.max_pov_size); - assert_eq!(v3.max_downward_message_size , v4.max_downward_message_size); - assert_eq!(v3.ump_service_total_weight , v4.ump_service_total_weight); - assert_eq!(v3.hrmp_max_parachain_outbound_channels , v4.hrmp_max_parachain_outbound_channels); - assert_eq!(v3.hrmp_max_parathread_outbound_channels , v4.hrmp_max_parathread_outbound_channels); - assert_eq!(v3.hrmp_sender_deposit , v4.hrmp_sender_deposit); - assert_eq!(v3.hrmp_recipient_deposit , v4.hrmp_recipient_deposit); - assert_eq!(v3.hrmp_channel_max_capacity , v4.hrmp_channel_max_capacity); - assert_eq!(v3.hrmp_channel_max_total_size , v4.hrmp_channel_max_total_size); - assert_eq!(v3.hrmp_max_parachain_inbound_channels , v4.hrmp_max_parachain_inbound_channels); - assert_eq!(v3.hrmp_max_parathread_inbound_channels , v4.hrmp_max_parathread_inbound_channels); - assert_eq!(v3.hrmp_channel_max_message_size , v4.hrmp_channel_max_message_size); - assert_eq!(v3.code_retention_period , v4.code_retention_period); - assert_eq!(v3.parathread_cores , v4.parathread_cores); - assert_eq!(v3.parathread_retries , v4.parathread_retries); - assert_eq!(v3.group_rotation_frequency , v4.group_rotation_frequency); - assert_eq!(v3.chain_availability_period , v4.chain_availability_period); - assert_eq!(v3.thread_availability_period , v4.thread_availability_period); - assert_eq!(v3.scheduling_lookahead , v4.scheduling_lookahead); - assert_eq!(v3.max_validators_per_core , v4.max_validators_per_core); - assert_eq!(v3.max_validators , v4.max_validators); - assert_eq!(v3.dispute_period , v4.dispute_period); - assert_eq!(v3.dispute_post_conclusion_acceptance_period, v4.dispute_post_conclusion_acceptance_period); - assert_eq!(v3.dispute_conclusion_by_time_out_period , v4.dispute_conclusion_by_time_out_period); - assert_eq!(v3.no_show_slots , v4.no_show_slots); - assert_eq!(v3.n_delay_tranches , v4.n_delay_tranches); - assert_eq!(v3.zeroth_delay_tranche_width , v4.zeroth_delay_tranche_width); - assert_eq!(v3.needed_approvals , v4.needed_approvals); - assert_eq!(v3.relay_vrf_modulo_samples , v4.relay_vrf_modulo_samples); - assert_eq!(v3.ump_max_individual_weight , v4.ump_max_individual_weight); - assert_eq!(v3.pvf_checking_enabled , v4.pvf_checking_enabled); - assert_eq!(v3.pvf_voting_ttl , v4.pvf_voting_ttl); - assert_eq!(v3.minimum_validation_upgrade_delay , v4.minimum_validation_upgrade_delay); + assert_eq!(v4.max_code_size , v5.max_code_size); + assert_eq!(v4.max_head_data_size , v5.max_head_data_size); + assert_eq!(v4.max_upward_queue_count , v5.max_upward_queue_count); + assert_eq!(v4.max_upward_queue_size , v5.max_upward_queue_size); + assert_eq!(v4.max_upward_message_size , v5.max_upward_message_size); + assert_eq!(v4.max_upward_message_num_per_candidate , v5.max_upward_message_num_per_candidate); + assert_eq!(v4.hrmp_max_message_num_per_candidate , v5.hrmp_max_message_num_per_candidate); + assert_eq!(v4.validation_upgrade_cooldown , v5.validation_upgrade_cooldown); + assert_eq!(v4.validation_upgrade_delay , v5.validation_upgrade_delay); + assert_eq!(v4.max_pov_size , v5.max_pov_size); + assert_eq!(v4.max_downward_message_size , v5.max_downward_message_size); + assert_eq!(v4.ump_service_total_weight , v5.ump_service_total_weight); + assert_eq!(v4.hrmp_max_parachain_outbound_channels , v5.hrmp_max_parachain_outbound_channels); + assert_eq!(v4.hrmp_max_parathread_outbound_channels , v5.hrmp_max_parathread_outbound_channels); + assert_eq!(v4.hrmp_sender_deposit , v5.hrmp_sender_deposit); + assert_eq!(v4.hrmp_recipient_deposit , v5.hrmp_recipient_deposit); + assert_eq!(v4.hrmp_channel_max_capacity , v5.hrmp_channel_max_capacity); + assert_eq!(v4.hrmp_channel_max_total_size , v5.hrmp_channel_max_total_size); + assert_eq!(v4.hrmp_max_parachain_inbound_channels , v5.hrmp_max_parachain_inbound_channels); + assert_eq!(v4.hrmp_max_parathread_inbound_channels , v5.hrmp_max_parathread_inbound_channels); + assert_eq!(v4.hrmp_channel_max_message_size , v5.hrmp_channel_max_message_size); + assert_eq!(v4.code_retention_period , v5.code_retention_period); + assert_eq!(v4.parathread_cores , v5.parathread_cores); + assert_eq!(v4.parathread_retries , v5.parathread_retries); + assert_eq!(v4.group_rotation_frequency , v5.group_rotation_frequency); + assert_eq!(v4.chain_availability_period , v5.chain_availability_period); + assert_eq!(v4.thread_availability_period , v5.thread_availability_period); + assert_eq!(v4.scheduling_lookahead , v5.scheduling_lookahead); + assert_eq!(v4.max_validators_per_core , v5.max_validators_per_core); + assert_eq!(v4.max_validators , v5.max_validators); + assert_eq!(v4.dispute_period , v5.dispute_period); + assert_eq!(v4.no_show_slots , v5.no_show_slots); + assert_eq!(v4.n_delay_tranches , v5.n_delay_tranches); + assert_eq!(v4.zeroth_delay_tranche_width , v5.zeroth_delay_tranche_width); + assert_eq!(v4.needed_approvals , v5.needed_approvals); + assert_eq!(v4.relay_vrf_modulo_samples , v5.relay_vrf_modulo_samples); + assert_eq!(v4.ump_max_individual_weight , v5.ump_max_individual_weight); + assert_eq!(v4.pvf_checking_enabled , v5.pvf_checking_enabled); + 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. }); diff --git a/runtime/parachains/src/configuration/tests.rs b/runtime/parachains/src/configuration/tests.rs index 2d89aebc19d3..eb29200a12c7 100644 --- a/runtime/parachains/src/configuration/tests.rs +++ b/runtime/parachains/src/configuration/tests.rs @@ -297,7 +297,6 @@ fn setting_pending_config_members() { max_validators: None, dispute_period: 239, dispute_post_conclusion_acceptance_period: 10, - dispute_conclusion_by_time_out_period: 512, no_show_slots: 240, n_delay_tranches: 241, zeroth_delay_tranche_width: 242, @@ -389,11 +388,6 @@ fn setting_pending_config_members() { new_config.dispute_post_conclusion_acceptance_period, ) .unwrap(); - Configuration::set_dispute_conclusion_by_time_out_period( - RuntimeOrigin::root(), - new_config.dispute_conclusion_by_time_out_period, - ) - .unwrap(); Configuration::set_no_show_slots(RuntimeOrigin::root(), new_config.no_show_slots).unwrap(); Configuration::set_n_delay_tranches(RuntimeOrigin::root(), new_config.n_delay_tranches) .unwrap(); From 4aa017064c5bf2ab33154356d7afef0ba1b74b84 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Thu, 23 Mar 2023 11:29:38 +0000 Subject: [PATCH 08/14] Enable migrations Signed-off-by: Andrei Sandu --- runtime/kusama/src/lib.rs | 1 + runtime/polkadot/src/lib.rs | 1 + runtime/rococo/src/lib.rs | 2 +- runtime/westend/src/lib.rs | 1 + 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/runtime/kusama/src/lib.rs b/runtime/kusama/src/lib.rs index 3101feb24483..79ce15634d84 100644 --- a/runtime/kusama/src/lib.rs +++ b/runtime/kusama/src/lib.rs @@ -1481,6 +1481,7 @@ pub type Migrations = ( Runtime, NominationPoolsMigrationV4OldPallet, >, + parachains_configuration::migration::v5::MigrateToV5, ); /// Unchecked extrinsic type as expected by this runtime. diff --git a/runtime/polkadot/src/lib.rs b/runtime/polkadot/src/lib.rs index cf1bb606fcac..3b307e2d2da1 100644 --- a/runtime/polkadot/src/lib.rs +++ b/runtime/polkadot/src/lib.rs @@ -1418,6 +1418,7 @@ pub type Migrations = ( Runtime, NominationPoolsMigrationV4OldPallet, >, + parachains_configuration::migration::v5::MigrateToV5, ); /// Unchecked extrinsic type as expected by this runtime. diff --git a/runtime/rococo/src/lib.rs b/runtime/rococo/src/lib.rs index 0d5f9a74a603..a0e2f25243f6 100644 --- a/runtime/rococo/src/lib.rs +++ b/runtime/rococo/src/lib.rs @@ -1494,7 +1494,7 @@ pub type UncheckedExtrinsic = /// All migrations that will run on the next runtime upgrade. /// /// Should be cleared after every release. -pub type Migrations = (); +pub type Migrations = parachains_configuration::migration::v5::MigrateToV5; /// Executive: handles dispatch to the various modules. pub type Executive = frame_executive::Executive< diff --git a/runtime/westend/src/lib.rs b/runtime/westend/src/lib.rs index 9b213e00786a..9f72b5686525 100644 --- a/runtime/westend/src/lib.rs +++ b/runtime/westend/src/lib.rs @@ -1214,6 +1214,7 @@ pub type Migrations = ( Runtime, NominationPoolsMigrationV4OldPallet, >, + parachains_configuration::migration::v5::MigrateToV5, ); /// Unchecked extrinsic type as expected by this runtime. From 0c52e6bd21762061e5e9b7c7e847deb84d4455db Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Thu, 23 Mar 2023 14:10:55 +0000 Subject: [PATCH 09/14] Update guide Signed-off-by: Andrei Sandu --- roadmap/implementers-guide/src/runtime/disputes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roadmap/implementers-guide/src/runtime/disputes.md b/roadmap/implementers-guide/src/runtime/disputes.md index b775bfbfcf0e..1d3e3f62dc01 100644 --- a/roadmap/implementers-guide/src/runtime/disputes.md +++ b/roadmap/implementers-guide/src/runtime/disputes.md @@ -56,7 +56,7 @@ Frozen: Option, ## Block Initialization -1. Iterate through all disputes. If any have not concluded and started more than `config.dispute_conclusion_by_timeout_period` blocks ago, set them to `Concluded` and mildly punish all validators associated, as they have failed to distribute available data. +This is currently a `no op`. ## Routines From 0b98d33b9cc0bae5b803b120b709c9cd2a3442e2 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Thu, 23 Mar 2023 17:23:11 +0000 Subject: [PATCH 10/14] Fix comment Signed-off-by: Andrei Sandu --- runtime/parachains/src/configuration/migration.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/parachains/src/configuration/migration.rs b/runtime/parachains/src/configuration/migration.rs index 071a4ef95eb3..a08b9894fe17 100644 --- a/runtime/parachains/src/configuration/migration.rs +++ b/runtime/parachains/src/configuration/migration.rs @@ -282,8 +282,8 @@ mod tests { #[test] fn test_migrate_to_v5() { - // Host configuration has lots of fields. However, in this migration we add only a couple of - // fields. The most important part to check are a couple of the last fields. We also pick + // Host configuration has lots of fields. However, in this migration we only remove 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. // From 2cc257491a40bc5c4cbe9dc9c4c5f3b873a9e91c Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Thu, 23 Mar 2023 17:30:53 +0000 Subject: [PATCH 11/14] More guide fixes Signed-off-by: Andrei Sandu --- roadmap/implementers-guide/src/disputes-flow.md | 1 - roadmap/implementers-guide/src/protocol-disputes.md | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/roadmap/implementers-guide/src/disputes-flow.md b/roadmap/implementers-guide/src/disputes-flow.md index 053bcfd3f2a4..a325b2ce7272 100644 --- a/roadmap/implementers-guide/src/disputes-flow.md +++ b/roadmap/implementers-guide/src/disputes-flow.md @@ -8,7 +8,6 @@ stateDiagram-v2 [*] --> WaitForDisputeVote: backing Vote received WaitForBackingVote --> Open: negative Vote received WaitForDisputeVote --> Open: backing Vote received - Open --> Concluded: Timeout without supermajority Open --> Concluded: Incoming Vote via Gossip Open --> Open: No ⅔ supermajority Open --> [*] diff --git a/roadmap/implementers-guide/src/protocol-disputes.md b/roadmap/implementers-guide/src/protocol-disputes.md index 76791ac16a4e..ebbc534f1992 100644 --- a/roadmap/implementers-guide/src/protocol-disputes.md +++ b/roadmap/implementers-guide/src/protocol-disputes.md @@ -62,6 +62,6 @@ Validators are rewarded for providing statements to the chain as well as for par ## Dispute Conclusion -Disputes, roughly, are over when one side reaches a ⅔ supermajority. They may also conclude after a timeout, without either side witnessing supermajority, which will only happen if the majority of validators are unable to vote for some reason. Furthermore, disputes on-chain will stay open for some fixed amount of time even after concluding, to accept new votes. +Disputes, roughly, are over when one side reaches a ⅔ supermajority. They may also never conclude without either side witnessing supermajority, which will only happen if the majority of validators are unable to vote for some reason. Furthermore, disputes on-chain will stay open for some fixed amount of time even after concluding, to accept new votes. Late votes, after the dispute already reached a ⅔ supermajority, must be rewarded (albeit a smaller amount) as well. From 3abaf1f256b2c4844f6a3dc90ed7af25541c4aa1 Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Fri, 24 Mar 2023 09:18:19 +0000 Subject: [PATCH 12/14] Also migrate pending configs Signed-off-by: Andrei Sandu --- .../parachains/src/configuration/migration.rs | 123 +++++++++++------- 1 file changed, 76 insertions(+), 47 deletions(-) diff --git a/runtime/parachains/src/configuration/migration.rs b/runtime/parachains/src/configuration/migration.rs index a08b9894fe17..1d090cf4ee77 100644 --- a/runtime/parachains/src/configuration/migration.rs +++ b/runtime/parachains/src/configuration/migration.rs @@ -20,6 +20,8 @@ use crate::configuration::{self, ActiveConfig, Config, Pallet, MAX_POV_SIZE}; use frame_support::{pallet_prelude::*, traits::StorageVersion, weights::Weight}; use frame_system::pallet_prelude::BlockNumberFor; +use super::PendingConfigs; + /// The current storage version. /// /// v0-v1: @@ -38,7 +40,7 @@ pub mod v5 { // Copied over from configuration.rs @ de9e147695b9f1be8bd44e07861a31e483c8343a and removed // all the comments, and changed the Weight struct to OldWeight - #[derive(parity_scale_codec::Encode, parity_scale_codec::Decode, Debug)] + #[derive(parity_scale_codec::Encode, parity_scale_codec::Decode, Debug, Clone)] pub struct OldHostConfiguration { pub max_code_size: u32, pub max_head_data_size: u32, @@ -236,11 +238,27 @@ minimum_validation_upgrade_delay : pre.minimum_validation_upgrade_delay, // to be unlikely to be caused by this. So we just log. Maybe it'll work out still? log::error!( target: configuration::LOG_TARGET, - "unexpected error when performing translation of the configuration type during storage upgrade to v4." + "unexpected error when performing translation of the active configuration during storage upgrade to v5." + ); + } + + if let Err(_) = PendingConfigs::::translate(|pre| { + pre.map( + |v: Vec<(primitives::SessionIndex, v5::OldHostConfiguration>)>| { + v.into_iter() + .map(|(session, config)| (session, translate(config))) + .collect::>() + }, + ) + }) { + log::error!( + target: configuration::LOG_TARGET, + "unexpected error when performing translation of the pending configuration during storage upgrade to v5." ); } - T::DbWeight::get().reads_writes(1, 1) + let num_configs = (PendingConfigs::::get().len() + 1) as u64; + T::DbWeight::get().reads_writes(num_configs, num_configs) } #[cfg(test)] @@ -301,61 +319,72 @@ mod tests { ..Default::default() }; + let mut pending_configs = Vec::new(); + pending_configs.push((100, v4.clone())); + pending_configs.push((300, v4.clone())); + new_test_ext(Default::default()).execute_with(|| { // Implant the v4 version in the state. frame_support::storage::unhashed::put_raw( &configuration::ActiveConfig::::hashed_key(), &v4.encode(), ); + frame_support::storage::unhashed::put_raw( + &configuration::PendingConfigs::::hashed_key(), + &pending_configs.encode(), + ); migrate_to_v5::(); let v5 = configuration::ActiveConfig::::get(); + let mut configs_to_check = configuration::PendingConfigs::::get(); + configs_to_check.push((0, v5.clone())); - #[rustfmt::skip] - { - assert_eq!(v4.max_code_size , v5.max_code_size); - assert_eq!(v4.max_head_data_size , v5.max_head_data_size); - assert_eq!(v4.max_upward_queue_count , v5.max_upward_queue_count); - assert_eq!(v4.max_upward_queue_size , v5.max_upward_queue_size); - assert_eq!(v4.max_upward_message_size , v5.max_upward_message_size); - assert_eq!(v4.max_upward_message_num_per_candidate , v5.max_upward_message_num_per_candidate); - assert_eq!(v4.hrmp_max_message_num_per_candidate , v5.hrmp_max_message_num_per_candidate); - assert_eq!(v4.validation_upgrade_cooldown , v5.validation_upgrade_cooldown); - assert_eq!(v4.validation_upgrade_delay , v5.validation_upgrade_delay); - assert_eq!(v4.max_pov_size , v5.max_pov_size); - assert_eq!(v4.max_downward_message_size , v5.max_downward_message_size); - assert_eq!(v4.ump_service_total_weight , v5.ump_service_total_weight); - assert_eq!(v4.hrmp_max_parachain_outbound_channels , v5.hrmp_max_parachain_outbound_channels); - assert_eq!(v4.hrmp_max_parathread_outbound_channels , v5.hrmp_max_parathread_outbound_channels); - assert_eq!(v4.hrmp_sender_deposit , v5.hrmp_sender_deposit); - assert_eq!(v4.hrmp_recipient_deposit , v5.hrmp_recipient_deposit); - assert_eq!(v4.hrmp_channel_max_capacity , v5.hrmp_channel_max_capacity); - assert_eq!(v4.hrmp_channel_max_total_size , v5.hrmp_channel_max_total_size); - assert_eq!(v4.hrmp_max_parachain_inbound_channels , v5.hrmp_max_parachain_inbound_channels); - assert_eq!(v4.hrmp_max_parathread_inbound_channels , v5.hrmp_max_parathread_inbound_channels); - assert_eq!(v4.hrmp_channel_max_message_size , v5.hrmp_channel_max_message_size); - assert_eq!(v4.code_retention_period , v5.code_retention_period); - assert_eq!(v4.parathread_cores , v5.parathread_cores); - assert_eq!(v4.parathread_retries , v5.parathread_retries); - assert_eq!(v4.group_rotation_frequency , v5.group_rotation_frequency); - assert_eq!(v4.chain_availability_period , v5.chain_availability_period); - assert_eq!(v4.thread_availability_period , v5.thread_availability_period); - assert_eq!(v4.scheduling_lookahead , v5.scheduling_lookahead); - assert_eq!(v4.max_validators_per_core , v5.max_validators_per_core); - assert_eq!(v4.max_validators , v5.max_validators); - assert_eq!(v4.dispute_period , v5.dispute_period); - assert_eq!(v4.no_show_slots , v5.no_show_slots); - assert_eq!(v4.n_delay_tranches , v5.n_delay_tranches); - assert_eq!(v4.zeroth_delay_tranche_width , v5.zeroth_delay_tranche_width); - assert_eq!(v4.needed_approvals , v5.needed_approvals); - assert_eq!(v4.relay_vrf_modulo_samples , v5.relay_vrf_modulo_samples); - assert_eq!(v4.ump_max_individual_weight , v5.ump_max_individual_weight); - assert_eq!(v4.pvf_checking_enabled , v5.pvf_checking_enabled); - 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. + for (session, v4) in configs_to_check { + #[rustfmt::skip] + { + assert_eq!(v4.max_code_size , v5.max_code_size); + assert_eq!(v4.max_head_data_size , v5.max_head_data_size); + assert_eq!(v4.max_upward_queue_count , v5.max_upward_queue_count); + assert_eq!(v4.max_upward_queue_size , v5.max_upward_queue_size); + assert_eq!(v4.max_upward_message_size , v5.max_upward_message_size); + assert_eq!(v4.max_upward_message_num_per_candidate , v5.max_upward_message_num_per_candidate); + assert_eq!(v4.hrmp_max_message_num_per_candidate , v5.hrmp_max_message_num_per_candidate); + assert_eq!(v4.validation_upgrade_cooldown , v5.validation_upgrade_cooldown); + assert_eq!(v4.validation_upgrade_delay , v5.validation_upgrade_delay); + assert_eq!(v4.max_pov_size , v5.max_pov_size); + assert_eq!(v4.max_downward_message_size , v5.max_downward_message_size); + assert_eq!(v4.ump_service_total_weight , v5.ump_service_total_weight); + assert_eq!(v4.hrmp_max_parachain_outbound_channels , v5.hrmp_max_parachain_outbound_channels); + assert_eq!(v4.hrmp_max_parathread_outbound_channels , v5.hrmp_max_parathread_outbound_channels); + assert_eq!(v4.hrmp_sender_deposit , v5.hrmp_sender_deposit); + assert_eq!(v4.hrmp_recipient_deposit , v5.hrmp_recipient_deposit); + assert_eq!(v4.hrmp_channel_max_capacity , v5.hrmp_channel_max_capacity); + assert_eq!(v4.hrmp_channel_max_total_size , v5.hrmp_channel_max_total_size); + assert_eq!(v4.hrmp_max_parachain_inbound_channels , v5.hrmp_max_parachain_inbound_channels); + assert_eq!(v4.hrmp_max_parathread_inbound_channels , v5.hrmp_max_parathread_inbound_channels); + assert_eq!(v4.hrmp_channel_max_message_size , v5.hrmp_channel_max_message_size); + assert_eq!(v4.code_retention_period , v5.code_retention_period); + assert_eq!(v4.parathread_cores , v5.parathread_cores); + assert_eq!(v4.parathread_retries , v5.parathread_retries); + assert_eq!(v4.group_rotation_frequency , v5.group_rotation_frequency); + assert_eq!(v4.chain_availability_period , v5.chain_availability_period); + assert_eq!(v4.thread_availability_period , v5.thread_availability_period); + assert_eq!(v4.scheduling_lookahead , v5.scheduling_lookahead); + assert_eq!(v4.max_validators_per_core , v5.max_validators_per_core); + assert_eq!(v4.max_validators , v5.max_validators); + assert_eq!(v4.dispute_period , v5.dispute_period); + assert_eq!(v4.no_show_slots , v5.no_show_slots); + assert_eq!(v4.n_delay_tranches , v5.n_delay_tranches); + assert_eq!(v4.zeroth_delay_tranche_width , v5.zeroth_delay_tranche_width); + assert_eq!(v4.needed_approvals , v5.needed_approvals); + assert_eq!(v4.relay_vrf_modulo_samples , v5.relay_vrf_modulo_samples); + assert_eq!(v4.ump_max_individual_weight , v5.ump_max_individual_weight); + assert_eq!(v4.pvf_checking_enabled , v5.pvf_checking_enabled); + 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. + } }); } } From eb00f897ad4229ed98d787172cb726416484486d Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Fri, 24 Mar 2023 09:29:14 +0000 Subject: [PATCH 13/14] fix build Signed-off-by: Andrei Sandu --- runtime/parachains/src/configuration/migration.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/runtime/parachains/src/configuration/migration.rs b/runtime/parachains/src/configuration/migration.rs index 1d090cf4ee77..802bea11974b 100644 --- a/runtime/parachains/src/configuration/migration.rs +++ b/runtime/parachains/src/configuration/migration.rs @@ -16,11 +16,10 @@ //! A module that is responsible for migration of storage. -use crate::configuration::{self, ActiveConfig, Config, Pallet, MAX_POV_SIZE}; +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 super::PendingConfigs; +use sp_std::vec::Vec; /// The current storage version. /// From 589733c898565d9b479468127285c2ddf261c00d Mon Sep 17 00:00:00 2001 From: Andrei Sandu Date: Fri, 24 Mar 2023 11:15:12 +0000 Subject: [PATCH 14/14] fix test Signed-off-by: Andrei Sandu --- 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 802bea11974b..f38450a70d40 100644 --- a/runtime/parachains/src/configuration/migration.rs +++ b/runtime/parachains/src/configuration/migration.rs @@ -339,7 +339,7 @@ mod tests { let mut configs_to_check = configuration::PendingConfigs::::get(); configs_to_check.push((0, v5.clone())); - for (session, v4) in configs_to_check { + for (_, v4) in configs_to_check { #[rustfmt::skip] { assert_eq!(v4.max_code_size , v5.max_code_size);