Skip to content

Commit

Permalink
refactor: remove next compatibility version (#4098)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylezs authored Oct 10, 2023
1 parent c7e75b7 commit b1093cd
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 120 deletions.
9 changes: 0 additions & 9 deletions state-chain/pallets/cf-environment/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,5 @@ benchmarks! {
verify {
assert_eq!(RuntimeSafeMode::<T>::get(), SafeMode::CODE_RED);
}

set_next_compatibility_version {
let origin = T::EnsureGovernance::try_successful_origin().unwrap();
let version = SemVer { major: 1u8, minor: 1u8, patch: 1u8 };
let call = Call::<T>::set_next_compatibility_version { version: Some(version) };
}: { call.dispatch_bypass_filter(origin)? }
verify {
assert_eq!(NextCompatibilityVersion::<T>::get(), Some(version));
}
impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test);
}
50 changes: 1 addition & 49 deletions state-chain/pallets/cf-environment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,6 @@ pub mod pallet {
/// Stores the current safe mode state for the runtime.
pub type RuntimeSafeMode<T> = StorageValue<_, <T as Config>::RuntimeSafeMode, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn next_compatibility_version)]
/// If this storage is set, a new version of Chainflip is available for upgrade.
pub type NextCompatibilityVersion<T> = StorageValue<_, Option<SemVer>, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn network_environment)]
/// Contains the network environment for this runtime.
Expand All @@ -176,27 +171,16 @@ pub mod pallet {
BitcoinBlockNumberSetForVault { block_number: cf_chains::btc::BlockNumber },
/// The Safe Mode settings for the chain has been updated
RuntimeSafeModeUpdated { safe_mode: SafeModeUpdate<T> },
/// A new Chainflip runtime will soon be deployed at this version.
NextCompatibilityVersionSet { version: Option<SemVer> },
}

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_runtime_upgrade() -> Weight {
let weight = migrations::PalletMigration::<T>::on_runtime_upgrade();
NextCompatibilityVersion::<T>::kill();
weight
migrations::PalletMigration::<T>::on_runtime_upgrade()
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, DispatchError> {
if let Some(next_version) = NextCompatibilityVersion::<T>::get() {
if next_version != T::CurrentCompatibilityVersion::get() {
return Err("NextCompatibilityVersion does not match the current runtime".into())
}
} else {
return Err("NextCompatibilityVersion is not set".into())
}
migrations::PalletMigration::<T>::pre_upgrade()
}

Expand Down Expand Up @@ -304,35 +288,6 @@ pub mod pallet {

Ok(())
}

/// Sets the next Chainflip compatiblity version.
///
/// This is used to signal to CFE operators that a new version of the runtime will soon be
/// deployed.
///
/// Requires governance origin.
///
/// ## Events
///
/// - [Success](Event::NextCompatibilityVersionSet)
///
/// ## Errors
///
/// - [BadOrigin](frame_support::error::BadOrigin)
#[pallet::call_index(4)]
#[pallet::weight(T::WeightInfo::set_next_compatibility_version())]
pub fn set_next_compatibility_version(
origin: OriginFor<T>,
version: Option<SemVer>,
) -> DispatchResult {
T::EnsureGovernance::ensure_origin(origin)?;

NextCompatibilityVersion::<T>::put(version);

Self::deposit_event(Event::<T>::NextCompatibilityVersionSet { version });

Ok(())
}
}

#[pallet::genesis_config]
Expand Down Expand Up @@ -473,7 +428,4 @@ impl<T: Config> CompatibleCfeVersions for Pallet<T> {
fn current_compatibility_version() -> SemVer {
<T as Config>::CurrentCompatibilityVersion::get()
}
fn next_compatibility_version() -> Option<SemVer> {
NextCompatibilityVersion::<T>::get()
}
}
23 changes: 0 additions & 23 deletions state-chain/pallets/cf-environment/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![cfg(test)]
use cf_chains::btc::{api::UtxoSelectionType, deposit_address::DepositAddress, Utxo};
use cf_primitives::SemVer;
use cf_traits::SafeMode;
use frame_support::{assert_ok, traits::OriginTrait};

Expand Down Expand Up @@ -123,25 +122,3 @@ fn update_safe_mode() {
));
});
}

#[test]
fn can_set_next_compatibility_version() {
new_test_ext().execute_with(|| {
assert!(Environment::next_compatibility_version().is_none());

// Set the next cfe version
let version = Some(SemVer { major: 1u8, minor: 3u8, patch: 10u8 });
assert_ok!(Environment::set_next_compatibility_version(RuntimeOrigin::root(), version));
assert_eq!(Environment::next_compatibility_version(), version);
System::assert_last_event(RuntimeEvent::Environment(
crate::Event::<Test>::NextCompatibilityVersionSet { version },
));

// Unset the net cfe version
assert_ok!(Environment::set_next_compatibility_version(RuntimeOrigin::root(), None));
assert!(Environment::next_compatibility_version().is_none());
System::assert_last_event(RuntimeEvent::Environment(
crate::Event::<Test>::NextCompatibilityVersionSet { version: None },
));
});
}
8 changes: 0 additions & 8 deletions state-chain/pallets/cf-environment/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub trait WeightInfo {
fn update_supported_eth_assets() -> Weight;
fn update_polkadot_runtime_version() -> Weight;
fn update_safe_mode() -> Weight;
fn set_next_compatibility_version() -> Weight;
}

/// Weights for pallet_cf_environment using the Substrate node and recommended hardware.
Expand Down Expand Up @@ -67,9 +66,6 @@ impl<T: frame_system::Config> WeightInfo for PalletWeight<T> {
.saturating_add(T::DbWeight::get().reads(1))
.saturating_add(T::DbWeight::get().writes(1))
}
fn set_next_compatibility_version() -> Weight {
Weight::from_parts(1_000, 0)
}
}

// For backwards compatibility and tests
Expand Down Expand Up @@ -101,8 +97,4 @@ impl WeightInfo for () {
.saturating_add(RocksDbWeight::get().reads(1))
.saturating_add(RocksDbWeight::get().writes(1))
}

fn set_next_compatibility_version() -> Weight {
Weight::from_parts(1_000, 0)
}
}
13 changes: 6 additions & 7 deletions state-chain/pallets/cf-governance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub mod pallet {

use super::*;

use cf_primitives::SemVer;
use cf_traits::{Chainflip, ExecutionCondition, RuntimeUpgrade};
use codec::Encode;
use frame_support::{
Expand Down Expand Up @@ -230,8 +231,6 @@ pub mod pallet {
CallHashNotWhitelisted,
/// Insufficient number of CFEs are at the target version to receive the runtime upgrade.
NotEnoughAuthoritiesCfesAtTargetVersion,
/// The target CFE version required for the runtime upgrade is not set.
TargetCfeVersionNotSet,
}

#[pallet::call]
Expand Down Expand Up @@ -303,17 +302,17 @@ pub mod pallet {
#[pallet::weight((T::BlockWeights::get().max_block, DispatchClass::Operational))]
pub fn chainflip_runtime_upgrade(
origin: OriginFor<T>,
required_up_to_date_cfes: Option<Percent>,
// The version that the percent of nodes need to be compatible with in order for the
// runtime upgrade to go through.
cfe_version_restriction: Option<(SemVer, Percent)>,
code: Vec<u8>,
) -> DispatchResultWithPostInfo {
T::EnsureGovernance::ensure_origin(origin)?;
ensure!(T::UpgradeCondition::is_satisfied(), Error::<T>::UpgradeConditionsNotMet);

if let Some(percent) = required_up_to_date_cfes {
let next_version = T::CompatibleCfeVersions::next_compatibility_version()
.ok_or(Error::<T>::TargetCfeVersionNotSet)?;
if let Some((required_version, percent)) = cfe_version_restriction {
ensure!(
T::AuthoritiesCfeVersions::precent_authorities_at_version(next_version) >=
T::AuthoritiesCfeVersions::precent_authorities_at_version(required_version) >=
percent,
Error::<T>::NotEnoughAuthoritiesCfesAtTargetVersion,
);
Expand Down
4 changes: 0 additions & 4 deletions state-chain/pallets/cf-governance/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ impl RuntimeUpgradeMock {
cf_traits::impl_mock_ensure_witnessed_for_origin!(RuntimeOrigin);

parameter_types! {
pub static NextCfeVersion: Option<SemVer> = Some(SemVer{major: 1, minor: 2, patch: 3});
pub static PercentCfeAtTargetVersion: Percent = Percent::from_percent(100);
}

Expand All @@ -115,9 +114,6 @@ impl CompatibleCfeVersions for MockCompatibleCfeVersions {
fn current_compatibility_version() -> SemVer {
SemVer { major: 1, minor: 0, patch: 0 }
}
fn next_compatibility_version() -> Option<SemVer> {
NextCfeVersion::get()
}
}

impl pallet_cf_governance::Config for Test {
Expand Down
24 changes: 5 additions & 19 deletions state-chain/pallets/cf-governance/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{
mock::*, ActiveProposals, Error, ExecutionMode, ExecutionPipeline, ExpiryTime, Members,
PreAuthorisedGovCalls, ProposalIdCounter,
};
use cf_primitives::SemVer;
use cf_test_utilities::last_event;
use cf_traits::mocks::time_source;
use frame_support::{assert_err, assert_noop, assert_ok};
Expand Down Expand Up @@ -271,32 +272,24 @@ fn error_during_runtime_upgrade() {
fn runtime_upgrade_requires_up_to_date_authorities_cfes() {
RuntimeUpgradeMock::upgrade_success(true);
UpgradeConditionMock::set(true);
const DESIRED_CFE_VERSION: SemVer = SemVer { major: 1, minor: 2, patch: 3 };
new_test_ext().execute_with(|| {
// This is how many nodes are *at* the required version.
PercentCfeAtTargetVersion::set(Percent::from_percent(50));
assert_ok!(Governance::chainflip_runtime_upgrade(
pallet_cf_governance::RawOrigin::GovernanceApproval.into(),
Some(Percent::from_percent(50)),
Some((DESIRED_CFE_VERSION, Percent::from_percent(50))),
DUMMY_WASM_BLOB,
));

assert_noop!(
Governance::chainflip_runtime_upgrade(
pallet_cf_governance::RawOrigin::GovernanceApproval.into(),
Some(Percent::from_percent(51)),
Some((DESIRED_CFE_VERSION, Percent::from_percent(51))),
DUMMY_WASM_BLOB,
),
crate::Error::<Test>::NotEnoughAuthoritiesCfesAtTargetVersion
);

NextCfeVersion::set(None);
assert_noop!(
Governance::chainflip_runtime_upgrade(
pallet_cf_governance::RawOrigin::GovernanceApproval.into(),
Some(Percent::from_percent(50)),
DUMMY_WASM_BLOB,
),
crate::Error::<Test>::TargetCfeVersionNotSet
);
});
}

Expand All @@ -312,13 +305,6 @@ fn runtime_upgrade_can_have_no_cfes_version_requirement() {
None,
DUMMY_WASM_BLOB,
));

NextCfeVersion::set(None);
assert_ok!(Governance::chainflip_runtime_upgrade(
pallet_cf_governance::RawOrigin::GovernanceApproval.into(),
None,
DUMMY_WASM_BLOB,
));
});
}

Expand Down
1 change: 0 additions & 1 deletion state-chain/traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,6 @@ pub trait GetBlockHeight<C: Chain> {
}
pub trait CompatibleCfeVersions {
fn current_compatibility_version() -> SemVer;
fn next_compatibility_version() -> Option<SemVer>;
}

pub trait AuthoritiesCfeVersions {
Expand Down

0 comments on commit b1093cd

Please sign in to comment.