From da6d8befcf8c5b49a6614249655c02ca02d9a966 Mon Sep 17 00:00:00 2001 From: Agusrodri Date: Wed, 25 Oct 2023 02:34:13 -0700 Subject: [PATCH 1/2] allow to set zero as rotation period --- pallets/configuration/src/lib.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/pallets/configuration/src/lib.rs b/pallets/configuration/src/lib.rs index 867a0240a..ebc2465d6 100644 --- a/pallets/configuration/src/lib.rs +++ b/pallets/configuration/src/lib.rs @@ -69,6 +69,7 @@ pub struct HostConfiguration { pub min_orchestrator_collators: u32, pub max_orchestrator_collators: u32, pub collators_per_container: u32, + // If this value is 0 means that there is no rotation pub full_rotation_period: u32, } @@ -94,8 +95,6 @@ pub enum InconsistentError { MinOrchestratorCollatorsTooLow, /// `max_collators` must be at least 1 MaxCollatorsTooLow, - /// `full_rotation_period` must be at least 1 - FullRotationPeriodTooLow, } impl HostConfiguration { @@ -114,9 +113,6 @@ impl HostConfiguration { if self.max_orchestrator_collators < self.min_orchestrator_collators { return Err(InconsistentError::MaxCollatorsLowerThanMinCollators); } - if self.full_rotation_period < 1 { - return Err(InconsistentError::FullRotationPeriodTooLow); - } Ok(()) } From c2328855f629f4913af871ba107591d64a2eb7e1 Mon Sep 17 00:00:00 2001 From: Agusrodri Date: Wed, 25 Oct 2023 02:47:43 -0700 Subject: [PATCH 2/2] add test --- pallets/configuration/src/tests.rs | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/pallets/configuration/src/tests.rs b/pallets/configuration/src/tests.rs index 9ba88a7fb..54883d949 100644 --- a/pallets/configuration/src/tests.rs +++ b/pallets/configuration/src/tests.rs @@ -97,6 +97,53 @@ fn config_set_value() { }); } +#[test] +fn config_set_full_rotation_period_to_zero_works() { + new_test_ext_with_genesis(HostConfiguration { + max_collators: 100, + min_orchestrator_collators: 2, + max_orchestrator_collators: 5, + collators_per_container: 2, + full_rotation_period: 24, + }) + .execute_with(|| { + run_to_block(1); + assert_eq!(Configuration::config().full_rotation_period, 24); + assert_ok!( + Configuration::set_full_rotation_period(RuntimeOrigin::root(), 0), + () + ); + + assert_eq!( + PendingConfigs::::get(), + vec![( + 2, + HostConfiguration { + max_collators: 100, + min_orchestrator_collators: 2, + max_orchestrator_collators: 5, + collators_per_container: 2, + full_rotation_period: 0, + } + )] + ); + + // The session delay is set to 2, and one session is 5 blocks, + // so the change should not happen until block 11 + assert_eq!(Configuration::config().full_rotation_period, 24); + run_to_block(2); + assert_eq!(Configuration::config().full_rotation_period, 24); + // First block of session 1 + run_to_block(6); + assert_eq!(Configuration::config().full_rotation_period, 24); + run_to_block(10); + assert_eq!(Configuration::config().full_rotation_period, 24); + // First block of session 2 + run_to_block(11); + assert_eq!(Configuration::config().full_rotation_period, 0); + }); +} + #[test] fn config_set_many_values_same_block() { new_test_ext_with_genesis(HostConfiguration {