Skip to content

Commit

Permalink
chore: Use Parity's VersionedMigration (#5364)
Browse files Browse the repository at this point in the history
Re-commit of (due to unverified commit blocking CI merge):
* Use Parity's VersionedMigration.
* Merged Runtime-upgrade-utility crate into Runtime-utility crate
  • Loading branch information
syan095 authored Nov 4, 2024
1 parent fe65398 commit 5180af2
Show file tree
Hide file tree
Showing 57 changed files with 464 additions and 682 deletions.
45 changes: 13 additions & 32 deletions Cargo.lock

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

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ members = [
"state-chain/pallets/cf-witnesser",
"state-chain/primitives",
"state-chain/runtime",
"state-chain/runtime-upgrade-utilities",
"state-chain/runtime-utilities",
"state-chain/runtime-utilities/macros",
"state-chain/test-utilities",
Expand Down Expand Up @@ -274,7 +273,6 @@ engine-proc-macros = { path = "engine-proc-macros" }

# Chainflip utilities and others
cf-runtime-macros = { path = "state-chain/runtime-utilities/macros", default-features = false }
cf-runtime-upgrade-utilities = { path = "state-chain/runtime-upgrade-utilities", default-features = false }
cf-runtime-utilities = { path = "state-chain/runtime-utilities", default-features = false }
cf-test-utilities = { path = "state-chain/test-utilities" }
cf-utilities = { package = "utilities", path = "utilities", default-features = false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use cf_chains::sol::{SolHash, SolanaTransactionData};
use genesis::with_test_defaults;
use sp_runtime::AccountId32;

use frame_support::traits::OnRuntimeUpgrade;
use frame_support::traits::UncheckedOnRuntimeUpgrade;
use pallet_cf_broadcast::BroadcastData;
use state_chain_runtime::{
migrations::serialize_solana_broadcast::{self, old, SerializeSolanaBroadcastMigration},
Expand Down
7 changes: 6 additions & 1 deletion state-chain/chains/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ std = [
runtime-benchmarks = [
"frame-support/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"cf-runtime-utilities/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"sp-runtime/try-runtime",
"cf-runtime-utilities/try-runtime",
]
try-runtime = ["frame-support/try-runtime", "sp-runtime/try-runtime"]

runtime-integration-tests = ["std", "dep:rand", "ed25519-dalek/rand_core"]
7 changes: 4 additions & 3 deletions state-chain/pallets/cf-account-roles/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ workspace = true
# Chainflip
cf-primitives = { workspace = true }
cf-traits = { workspace = true }
cf-runtime-upgrade-utilities = { workspace = true }
cf-runtime-utilities = { workspace = true }

log = { workspace = true }

Expand All @@ -44,7 +44,7 @@ default = ["std"]
std = [
"cf-primitives/std",
"cf-traits/std",
"cf-runtime-upgrade-utilities/std",
"cf-runtime-utilities/std",
"codec/std",
"scale-info/std",
"frame-benchmarking?/std",
Expand All @@ -59,9 +59,10 @@ runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"cf-runtime-utilities/runtime-benchmarks",
]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"cf-runtime-upgrade-utilities/try-runtime",
"cf-runtime-utilities/try-runtime",
]
4 changes: 2 additions & 2 deletions state-chain/pallets/cf-account-roles/src/migrations.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::Pallet;
use cf_runtime_upgrade_utilities::PlaceholderMigration;
use cf_runtime_utilities::PlaceholderMigration;

pub type PalletMigration<T> = PlaceholderMigration<Pallet<T>, 2>;
pub type PalletMigration<T> = PlaceholderMigration<2, Pallet<T>>;
5 changes: 2 additions & 3 deletions state-chain/pallets/cf-asset-balances/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ workspace = true
cf-chains = { workspace = true }
cf-primitives = { workspace = true }
cf-traits = { workspace = true }
cf-runtime-upgrade-utilities = { workspace = true }
cf-runtime-utilities = { workspace = true }
cf-utilities = { workspace = true }

Expand Down Expand Up @@ -49,7 +48,6 @@ std = [
"cf-chains/std",
"cf-primitives/std",
"cf-traits/std",
"cf-runtime-upgrade-utilities/std",
"cf-runtime-utilities/std",
"cf-utilities/std",
"codec/std",
Expand All @@ -67,9 +65,10 @@ runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"cf-runtime-utilities/runtime-benchmarks",
]
try-runtime = [
"cf-runtime-upgrade-utilities/try-runtime",
"cf-runtime-utilities/try-runtime",
"cf-traits/try-runtime",
"frame-support/try-runtime",
"frame-system/try-runtime",
Expand Down
7 changes: 2 additions & 5 deletions state-chain/pallets/cf-broadcast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ workspace = true
# Chainflip
cf-chains = { workspace = true }
cf-primitives = { workspace = true }
cf-runtime-upgrade-utilities = { workspace = true }
cf-traits = { workspace = true }
cfe-events = { workspace = true }
cf-runtime-utilities = { workspace = true }
Expand Down Expand Up @@ -47,8 +46,6 @@ std = [
"cf-chains/std",
"cfe-events/std",
"cf-primitives/std",
"cf-runtime-upgrade-utilities/std",
"cf-runtime-utilities/std",
"cf-traits/std",
"codec/std",
"frame-benchmarking?/std",
Expand All @@ -61,7 +58,6 @@ std = [
"cf-chains/std",
"cfe-events/std",
"cf-primitives/std",
"cf-runtime-upgrade-utilities/std",
"cf-runtime-utilities/std",
"cf-traits/std",
"codec/std",
Expand All @@ -79,9 +75,10 @@ runtime-benchmarks = [
"frame-benchmarking/runtime-benchmarks",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"cf-runtime-utilities/runtime-benchmarks",
]
try-runtime = [
"cf-runtime-upgrade-utilities/try-runtime",
"cf-runtime-utilities/try-runtime",
"cf-traits/try-runtime",
"frame-support/try-runtime",
"frame-system/try-runtime",
Expand Down
21 changes: 17 additions & 4 deletions state-chain/pallets/cf-broadcast/src/migrations.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
use crate::Pallet;
use cf_runtime_upgrade_utilities::{PlaceholderMigration, VersionedMigration};
use cf_runtime_utilities::PlaceholderMigration;
use frame_support::migrations::VersionedMigration;

mod initialize_broadcast_timeout_storage;
mod migrate_timeouts;
pub mod remove_aborted_broadcasts;

pub type PalletMigration<T, I> = (
VersionedMigration<Pallet<T, I>, initialize_broadcast_timeout_storage::Migration<T, I>, 6, 7>,
VersionedMigration<Pallet<T, I>, migrate_timeouts::Migration<T, I>, 7, 8>,
PlaceholderMigration<Pallet<T, I>, 8>,
VersionedMigration<
6,
7,
initialize_broadcast_timeout_storage::Migration<T, I>,
Pallet<T, I>,
<T as frame_system::Config>::DbWeight,
>,
VersionedMigration<
7,
8,
migrate_timeouts::Migration<T, I>,
Pallet<T, I>,
<T as frame_system::Config>::DbWeight,
>,
PlaceholderMigration<8, Pallet<T, I>>,
// Migration 8->9 is SerializeSolanaBroadcastMigration in runtime lib.
// Migration 9->10 is SolanaEgressSuccessWitnessMigration in runtime lib.
);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use frame_support::{traits::OnRuntimeUpgrade, weights::Weight};
use frame_support::{traits::UncheckedOnRuntimeUpgrade, weights::Weight};
use old::maybe_get_timeout_for_type;

use crate::*;
Expand Down Expand Up @@ -52,7 +52,7 @@ mod old {

pub struct Migration<T: Config<I>, I: 'static>(PhantomData<(T, I)>);

impl<T: Config<I>, I: 'static> OnRuntimeUpgrade for Migration<T, I> {
impl<T: Config<I>, I: 'static> UncheckedOnRuntimeUpgrade for Migration<T, I> {
fn on_runtime_upgrade() -> Weight {
if let Some(timeout) = maybe_get_timeout_for_type::<T, I>() {
BroadcastTimeout::<T, I>::set(timeout);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use frame_support::{pallet_prelude::ValueQuery, traits::OnRuntimeUpgrade, weights::Weight};
use frame_support::{
pallet_prelude::ValueQuery, traits::UncheckedOnRuntimeUpgrade, weights::Weight,
};

use crate::*;

Expand All @@ -17,7 +19,7 @@ mod old {

pub struct Migration<T: Config<I>, I: 'static>(PhantomData<(T, I)>);

impl<T: Config<I>, I: 'static> OnRuntimeUpgrade for Migration<T, I> {
impl<T: Config<I>, I: 'static> UncheckedOnRuntimeUpgrade for Migration<T, I> {
fn on_runtime_upgrade() -> Weight {
// Instead of trying to translate the previous timeout into external chain blocks,
// we simply reset the remaining timeout duration to the new `BroadcastTimeout` value.
Expand Down
Loading

0 comments on commit 5180af2

Please sign in to comment.