From e79b88c6fb55ba96e36373c8ddedf782e9b7f4e7 Mon Sep 17 00:00:00 2001 From: kylezs Date: Wed, 11 Oct 2023 18:32:20 +1100 Subject: [PATCH] chore: fix naming of compatible version methods (#4094) --- state-chain/pallets/cf-governance/src/lib.rs | 5 +++-- state-chain/pallets/cf-governance/src/mock.rs | 2 +- state-chain/pallets/cf-validator/src/lib.rs | 21 ++++++++++--------- state-chain/pallets/cf-validator/src/tests.rs | 14 ++++++------- state-chain/traits/src/lib.rs | 2 +- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/state-chain/pallets/cf-governance/src/lib.rs b/state-chain/pallets/cf-governance/src/lib.rs index 0c5daafc69..eed42bcac1 100644 --- a/state-chain/pallets/cf-governance/src/lib.rs +++ b/state-chain/pallets/cf-governance/src/lib.rs @@ -312,8 +312,9 @@ pub mod pallet { if let Some((required_version, percent)) = cfe_version_restriction { ensure!( - T::AuthoritiesCfeVersions::precent_authorities_at_version(required_version) >= - percent, + T::AuthoritiesCfeVersions::percent_authorities_compatible_with_version( + required_version + ) >= percent, Error::::NotEnoughAuthoritiesCfesAtTargetVersion, ); } diff --git a/state-chain/pallets/cf-governance/src/mock.rs b/state-chain/pallets/cf-governance/src/mock.rs index 6c6e67394b..b0f6a81c36 100644 --- a/state-chain/pallets/cf-governance/src/mock.rs +++ b/state-chain/pallets/cf-governance/src/mock.rs @@ -104,7 +104,7 @@ parameter_types! { pub struct MockAuthoritiesCfeVersions; impl AuthoritiesCfeVersions for MockAuthoritiesCfeVersions { - fn precent_authorities_at_version(_version: SemVer) -> Percent { + fn percent_authorities_compatible_with_version(_version: SemVer) -> Percent { PercentCfeAtTargetVersion::get() } } diff --git a/state-chain/pallets/cf-validator/src/lib.rs b/state-chain/pallets/cf-validator/src/lib.rs index 50dcbb1b18..87da67a09c 100644 --- a/state-chain/pallets/cf-validator/src/lib.rs +++ b/state-chain/pallets/cf-validator/src/lib.rs @@ -1351,19 +1351,20 @@ impl OnAccountFunded for UpdateBackupMapping { } impl AuthoritiesCfeVersions for Pallet { - /// Returns the percentage of current authorities with their CFEs at the given version. - fn precent_authorities_at_version(version: SemVer) -> Percent { + /// Returns the percentage of current authorities that are compatible with the provided version. + fn percent_authorities_compatible_with_version(version: SemVer) -> Percent { let current_authorities = CurrentAuthorities::::get(); let authorities_count = current_authorities.len() as u32; - let num_authorities_at_target_version = current_authorities - .into_iter() - .filter(|validator_id| { - NodeCFEVersion::::get(validator_id).is_compatible_with(version) - }) - .count() as u32; - - Percent::from_rational(num_authorities_at_target_version, authorities_count) + Percent::from_rational( + current_authorities + .into_iter() + .filter(|validator_id| { + NodeCFEVersion::::get(validator_id).is_compatible_with(version) + }) + .count() as u32, + authorities_count, + ) } } diff --git a/state-chain/pallets/cf-validator/src/tests.rs b/state-chain/pallets/cf-validator/src/tests.rs index 47a478708c..eb9bc0a36d 100644 --- a/state-chain/pallets/cf-validator/src/tests.rs +++ b/state-chain/pallets/cf-validator/src/tests.rs @@ -1001,11 +1001,11 @@ fn can_calculate_percentage_cfe_at_target_version() { CurrentAuthorities::::set(BTreeSet::from(authorities)); assert_eq!( - ValidatorPallet::precent_authorities_at_version(initial_version), + ValidatorPallet::percent_authorities_compatible_with_version(initial_version), Percent::from_percent(100) ); assert_eq!( - ValidatorPallet::precent_authorities_at_version(next_version), + ValidatorPallet::percent_authorities_compatible_with_version(next_version), Percent::from_percent(0) ); @@ -1015,29 +1015,29 @@ fn can_calculate_percentage_cfe_at_target_version() { assert_ok!(ValidatorPallet::cfe_version(RuntimeOrigin::signed(*id), next_version,)); }); assert_eq!( - ValidatorPallet::precent_authorities_at_version(initial_version), + ValidatorPallet::percent_authorities_compatible_with_version(initial_version), Percent::from_percent(40) ); assert_eq!( - ValidatorPallet::precent_authorities_at_version(next_version), + ValidatorPallet::percent_authorities_compatible_with_version(next_version), Percent::from_percent(60) ); // Change authorities CurrentAuthorities::::set(BTreeSet::from(authorities)); assert_eq!( - ValidatorPallet::precent_authorities_at_version(initial_version), + ValidatorPallet::percent_authorities_compatible_with_version(initial_version), Percent::from_percent(0) ); assert_eq!( - ValidatorPallet::precent_authorities_at_version(next_version), + ValidatorPallet::percent_authorities_compatible_with_version(next_version), Percent::from_percent(100) ); // Version checking ignores `patch`. let compatible_version = SemVer { major: 6, minor: 0, patch: 6 }; assert_eq!( - ValidatorPallet::precent_authorities_at_version(compatible_version), + ValidatorPallet::percent_authorities_compatible_with_version(compatible_version), Percent::from_percent(100) ); }); diff --git a/state-chain/traits/src/lib.rs b/state-chain/traits/src/lib.rs index 69422a86d9..da8554c99b 100644 --- a/state-chain/traits/src/lib.rs +++ b/state-chain/traits/src/lib.rs @@ -803,7 +803,7 @@ pub trait CompatibleCfeVersions { pub trait AuthoritiesCfeVersions { /// Returns the percentage of current authorities with their CFEs at the given version. - fn precent_authorities_at_version(version: SemVer) -> Percent; + fn percent_authorities_compatible_with_version(version: SemVer) -> Percent; } pub trait CallDispatchFilter {