Skip to content

Commit

Permalink
fix: runtime upgrade utils and migrations (#4258)
Browse files Browse the repository at this point in the history
* fix: use executive pallet to run tuple migrations

chore: remove on_runtime_upgrade calls from pallets

fix: upgrade utils

clippy

* doc: update README

* fix: run try-runtime tests on CI
  • Loading branch information
kylezs authored Nov 20, 2023
1 parent 2064111 commit 4c804c7
Show file tree
Hide file tree
Showing 18 changed files with 145 additions and 373 deletions.
4 changes: 2 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ CF_TEST_CONFIG_ROOT = { value = "engine/config/testing", relative = true }
# `rustup completions --help` to find out how to set this up.

[alias]
cf-test = "test --lib --features runtime-benchmarks"
cf-test-ci = "test --lib --features runtime-benchmarks,slow-tests"
cf-test = "test --lib --features runtime-benchmarks,try-runtime"
cf-test-ci = "test --lib --features runtime-benchmarks,slow-tests,try-runtime"
cf-test-cfe = "test --lib --package chainflip-engine --package multisig"

cf-clippy = "clippy --all-targets --features runtime-benchmarks,try-runtime,runtime-integration-tests,slow-tests -- -D warnings"
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 1 addition & 15 deletions state-chain/pallets/cf-broadcast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use frame_support::{
dispatch::DispatchResultWithPostInfo,
pallet_prelude::DispatchResult,
sp_runtime::traits::Saturating,
traits::{Get, OnRuntimeUpgrade, StorageVersion, UnfilteredDispatchable},
traits::{Get, StorageVersion, UnfilteredDispatchable},
Twox64Concat,
};

Expand Down Expand Up @@ -414,20 +414,6 @@ pub mod pallet {
Weight::zero()
}
}

fn on_runtime_upgrade() -> Weight {
migrations::PalletMigration::<T, I>::on_runtime_upgrade()
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, DispatchError> {
migrations::PalletMigration::<T, I>::pre_upgrade()
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(state: sp_std::vec::Vec<u8>) -> Result<(), DispatchError> {
migrations::PalletMigration::<T, I>::post_upgrade(state)
}
}

#[pallet::call]
Expand Down
19 changes: 1 addition & 18 deletions state-chain/pallets/cf-chain-tracking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![doc = include_str!("../../cf-doc-head.md")]

mod benchmarking;
mod migrations;
pub mod migrations;
mod mock;
mod tests;

Expand Down Expand Up @@ -45,23 +45,6 @@ pub mod pallet {
#[pallet::storage_version(PALLET_VERSION)]
pub struct Pallet<T, I = ()>(PhantomData<(T, I)>);

#[pallet::hooks]
impl<T: Config<I>, I: 'static> Hooks<BlockNumberFor<T>> for Pallet<T, I> {
fn on_runtime_upgrade() -> Weight {
migrations::PalletMigration::<T, I>::on_runtime_upgrade()
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, DispatchError> {
migrations::PalletMigration::<T, I>::pre_upgrade()
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(state: sp_std::vec::Vec<u8>) -> Result<(), DispatchError> {
migrations::PalletMigration::<T, I>::post_upgrade(state)
}
}

/// The tracked state of the external chain.
/// It is safe to unwrap() this value. We set it at genesis and it is only ever updated
/// by chain tracking, never removed. We use OptionQuery here so we don't need to
Expand Down
20 changes: 1 addition & 19 deletions state-chain/pallets/cf-environment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mod tests;

pub mod weights;
pub use weights::WeightInfo;
mod migrations;
pub mod migrations;

pub const PALLET_VERSION: StorageVersion = StorageVersion::new(6);

Expand Down Expand Up @@ -181,24 +181,6 @@ pub mod pallet {
RuntimeSafeModeUpdated { safe_mode: SafeModeUpdate<T> },
}

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_runtime_upgrade() -> Weight {
Self::update_current_release_version();
migrations::PalletMigration::<T>::on_runtime_upgrade()
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, DispatchError> {
migrations::PalletMigration::<T>::pre_upgrade()
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(state: sp_std::vec::Vec<u8>) -> Result<(), DispatchError> {
migrations::PalletMigration::<T>::post_upgrade(state)
}
}

#[pallet::call]
impl<T: Config> Pallet<T> {
/// Manually initiates Polkadot vault key rotation completion steps so Epoch rotation can be
Expand Down
24 changes: 2 additions & 22 deletions state-chain/pallets/cf-funding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
mod mock;

mod benchmarking;
mod migrations;
pub mod migrations;

pub mod weights;
pub use weights::WeightInfo;
Expand All @@ -30,10 +30,7 @@ use frame_support::{
traits::{CheckedSub, UniqueSaturatedInto, Zero},
Saturating,
},
traits::{
EnsureOrigin, HandleLifetime, IsType, OnKilledAccount, OnRuntimeUpgrade, StorageVersion,
UnixTime,
},
traits::{EnsureOrigin, HandleLifetime, IsType, OnKilledAccount, StorageVersion, UnixTime},
};
use frame_system::pallet_prelude::OriginFor;
pub use pallet::*;
Expand Down Expand Up @@ -171,23 +168,6 @@ pub mod pallet {
#[pallet::storage]
pub type RedemptionTax<T: Config> = StorageValue<_, T::Amount, ValueQuery>;

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

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, DispatchError> {
migrations::PalletMigration::<T>::pre_upgrade()
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(state: Vec<u8>) -> Result<(), DispatchError> {
migrations::PalletMigration::<T>::post_upgrade(state)
}
}

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
Expand Down
16 changes: 1 addition & 15 deletions state-chain/pallets/cf-governance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![doc = include_str!("../README.md")]
#![doc = include_str!("../../cf-doc-head.md")]

mod migrations;
pub mod migrations;

use cf_traits::{AuthoritiesCfeVersions, CompatibleCfeVersions};
use codec::{Codec, Decode, Encode};
Expand Down Expand Up @@ -172,20 +172,6 @@ pub mod pallet {
let execution_weight = Self::execute_pending_proposals();
active_proposal_weight + execution_weight
}

fn on_runtime_upgrade() -> Weight {
migrations::PalletMigration::<T>::on_runtime_upgrade()
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, DispatchError> {
migrations::PalletMigration::<T>::pre_upgrade()
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(state: Vec<u8>) -> Result<(), DispatchError> {
migrations::PalletMigration::<T>::post_upgrade(state)
}
}

#[pallet::event]
Expand Down
15 changes: 1 addition & 14 deletions state-chain/pallets/cf-ingress-egress/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod mock;
mod tests;
pub mod weights;
use cf_runtime_utilities::log_or_panic;
use frame_support::{sp_runtime::SaturatedConversion, traits::OnRuntimeUpgrade, transactional};
use frame_support::{sp_runtime::SaturatedConversion, transactional};
pub use weights::WeightInfo;

use cf_chains::{
Expand Down Expand Up @@ -462,19 +462,6 @@ pub mod pallet {
// Egress all scheduled Cross chain messages
Self::do_egress_scheduled_ccm();
}

fn on_runtime_upgrade() -> Weight {
migrations::PalletMigration::<T, I>::on_runtime_upgrade()
}
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, DispatchError> {
migrations::PalletMigration::<T, I>::pre_upgrade()
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(state: sp_std::vec::Vec<u8>) -> Result<(), DispatchError> {
migrations::PalletMigration::<T, I>::post_upgrade(state)
}
}

#[pallet::call]
Expand Down
21 changes: 1 addition & 20 deletions state-chain/pallets/cf-lp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use cf_traits::{
EgressApi, PoolApi,
};

#[cfg(feature = "try-runtime")]
use frame_support::dispatch::Vec;
use frame_support::{pallet_prelude::*, sp_runtime::DispatchResult, traits::OnRuntimeUpgrade};
use frame_support::{pallet_prelude::*, sp_runtime::DispatchResult};
use frame_system::pallet_prelude::*;
pub use pallet::*;

Expand Down Expand Up @@ -142,23 +140,6 @@ pub mod pallet {
ForeignChainAddress,
>;

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

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, DispatchError> {
migrations::PalletMigration::<T>::pre_upgrade()
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(state: Vec<u8>) -> Result<(), DispatchError> {
migrations::PalletMigration::<T>::post_upgrade(state)
}
}

#[pallet::call]
impl<T: Config> Pallet<T> {
/// For when the user wants to deposit assets into the Chain.
Expand Down
15 changes: 0 additions & 15 deletions state-chain/pallets/cf-swapping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use frame_support::{
DispatchError, Permill,
},
storage::with_storage_layer,
traits::OnRuntimeUpgrade,
};
use frame_system::pallet_prelude::*;
pub use pallet::*;
Expand Down Expand Up @@ -488,20 +487,6 @@ pub mod pallet {
}
}
}

fn on_runtime_upgrade() -> Weight {
migrations::PalletMigration::<T>::on_runtime_upgrade()
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, DispatchError> {
migrations::PalletMigration::<T>::pre_upgrade()
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(state: Vec<u8>) -> Result<(), DispatchError> {
migrations::PalletMigration::<T>::post_upgrade(state)
}
}

#[pallet::call]
Expand Down
25 changes: 3 additions & 22 deletions state-chain/pallets/cf-threshold-signature/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub mod mock;
mod tests;

mod benchmarking;
mod migrations;
pub mod migrations;

pub mod weights;

Expand All @@ -30,10 +30,10 @@ use frame_support::{
dispatch::UnfilteredDispatchable,
ensure,
sp_runtime::{
traits::{BlockNumberProvider, Saturating, Zero},
traits::{BlockNumberProvider, Saturating},
RuntimeDebug,
},
traits::{DefensiveOption, EnsureOrigin, Get, OnRuntimeUpgrade, StorageVersion},
traits::{DefensiveOption, EnsureOrigin, Get, StorageVersion},
};
use frame_system::pallet_prelude::{BlockNumberFor, OriginFor};
pub use pallet::*;
Expand Down Expand Up @@ -457,25 +457,6 @@ pub mod pallet {
T::Weights::on_initialize(T::EpochInfo::current_authority_count(), num_retries) +
T::Weights::report_offenders(num_offenders as AuthorityCount)
}

fn on_runtime_upgrade() -> Weight {
// For new pallet instances, this always needs to be set.
ThresholdSignatureResponseTimeout::<T, I>::mutate(|timeout| {
if timeout.is_zero() {
*timeout = THRESHOLD_SIGNATURE_RESPONSE_TIMEOUT_DEFAULT.into();
}
});
migrations::PalletMigration::<T, I>::on_runtime_upgrade()
}
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<sp_std::vec::Vec<u8>, DispatchError> {
migrations::PalletMigration::<T, I>::pre_upgrade()
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(state: sp_std::vec::Vec<u8>) -> Result<(), DispatchError> {
migrations::PalletMigration::<T, I>::post_upgrade(state)
}
}

#[pallet::origin]
Expand Down
16 changes: 1 addition & 15 deletions state-chain/pallets/cf-tokenholder-governance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use sp_std::{cmp::PartialEq, vec, vec::Vec};
pub use pallet::*;

mod benchmarking;
mod migrations;
pub mod migrations;
#[cfg(test)]
mod mock;
#[cfg(test)]
Expand Down Expand Up @@ -171,20 +171,6 @@ pub mod pallet {
}
weight
}

fn on_runtime_upgrade() -> Weight {
migrations::PalletMigration::<T>::on_runtime_upgrade()
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, DispatchError> {
migrations::PalletMigration::<T>::pre_upgrade()
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(state: Vec<u8>) -> Result<(), DispatchError> {
migrations::PalletMigration::<T>::post_upgrade(state)
}
}

#[pallet::call]
Expand Down
Loading

0 comments on commit 4c804c7

Please sign in to comment.