From 3a94ef480bf5da913b3900bfc58dc15ad4472b74 Mon Sep 17 00:00:00 2001 From: Sergey Shulepov Date: Wed, 22 Dec 2021 15:05:05 +0000 Subject: [PATCH] configuration: validation_upgrade_delay consistency Closes #4248 Impose additional constraint on configuration consistency: `validation_upgrade_delay` should not be less than or equal to 1. See the original issue for more details. --- runtime/parachains/src/configuration.rs | 20 ++++++++++++++++++-- runtime/parachains/src/inclusion/tests.rs | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/runtime/parachains/src/configuration.rs b/runtime/parachains/src/configuration.rs index 11c257bea433..dc303ef40672 100644 --- a/runtime/parachains/src/configuration.rs +++ b/runtime/parachains/src/configuration.rs @@ -219,7 +219,7 @@ impl> Default for HostConfiguration { minimum_validation_upgrade_delay: BlockNumber, thread_availability_period: BlockNumber, }, + /// `validation_upgrade_delay` is less than or equal 1. + ValidationUpgradeDelayIsTooLow { validation_upgrade_delay: BlockNumber }, } -impl HostConfiguration { +impl HostConfiguration +where + BlockNumber: Zero + PartialOrd + sp_std::fmt::Debug + Clone + From, +{ /// Checks that this instance is consistent with the requirements on each individual member. /// /// # Errors @@ -341,6 +346,12 @@ impl HostConfigurat }) } + if self.validation_upgrade_delay <= 1.into() { + return Err(ValidationUpgradeDelayIsTooLow { + validation_upgrade_delay: self.validation_upgrade_delay.clone(), + }) + } + Ok(()) } @@ -1499,6 +1510,11 @@ mod tests { Configuration::set_minimum_validation_upgrade_delay(Origin::root(), 9), Error::::InvalidNewValue ); + + assert_err!( + Configuration::set_validation_upgrade_delay(Origin::root(), 0), + Error::::InvalidNewValue + ); }); } diff --git a/runtime/parachains/src/inclusion/tests.rs b/runtime/parachains/src/inclusion/tests.rs index 12dbb7664074..4f727348d22f 100644 --- a/runtime/parachains/src/inclusion/tests.rs +++ b/runtime/parachains/src/inclusion/tests.rs @@ -1307,7 +1307,7 @@ fn candidate_checks() { { let cfg = Configuration::config(); let expected_at = 10 + cfg.validation_upgrade_delay; - assert_eq!(expected_at, 10); + assert_eq!(expected_at, 12); Paras::schedule_code_upgrade(chain_a, vec![1, 2, 3, 4].into(), expected_at, &cfg); }