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

Commit

Permalink
configuration: validation_upgrade_delay consistency
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pepyakin committed Dec 27, 2021
1 parent 8990811 commit 3a94ef4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions runtime/parachains/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ impl<BlockNumber: Default + From<u32>> Default for HostConfiguration<BlockNumber
thread_availability_period: 1u32.into(),
no_show_slots: 1u32.into(),
validation_upgrade_frequency: Default::default(),
validation_upgrade_delay: Default::default(),
validation_upgrade_delay: 2u32.into(),
code_retention_period: Default::default(),
max_code_size: Default::default(),
max_pov_size: Default::default(),
Expand Down Expand Up @@ -288,9 +288,14 @@ pub enum InconsistentError<BlockNumber> {
minimum_validation_upgrade_delay: BlockNumber,
thread_availability_period: BlockNumber,
},
/// `validation_upgrade_delay` is less than or equal 1.
ValidationUpgradeDelayIsTooLow { validation_upgrade_delay: BlockNumber },
}

impl<BlockNumber: Zero + PartialOrd + sp_std::fmt::Debug + Clone> HostConfiguration<BlockNumber> {
impl<BlockNumber> HostConfiguration<BlockNumber>
where
BlockNumber: Zero + PartialOrd + sp_std::fmt::Debug + Clone + From<u32>,
{
/// Checks that this instance is consistent with the requirements on each individual member.
///
/// # Errors
Expand Down Expand Up @@ -341,6 +346,12 @@ impl<BlockNumber: Zero + PartialOrd + sp_std::fmt::Debug + Clone> HostConfigurat
})
}

if self.validation_upgrade_delay <= 1.into() {
return Err(ValidationUpgradeDelayIsTooLow {
validation_upgrade_delay: self.validation_upgrade_delay.clone(),
})
}

Ok(())
}

Expand Down Expand Up @@ -1499,6 +1510,11 @@ mod tests {
Configuration::set_minimum_validation_upgrade_delay(Origin::root(), 9),
Error::<Test>::InvalidNewValue
);

assert_err!(
Configuration::set_validation_upgrade_delay(Origin::root(), 0),
Error::<Test>::InvalidNewValue
);
});
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/parachains/src/inclusion/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 3a94ef4

Please sign in to comment.