Skip to content

Commit

Permalink
fix: gateway migration et al. (#1950)
Browse files Browse the repository at this point in the history
* chore: remove deprecated DMP Queue

* chore: remove deprecated custom migrations

* fix: gateway migration

* fix: rm FI v1 storage entries

* ci: fix try-runtime cli by adding install
  • Loading branch information
wischli authored Aug 8, 2024
1 parent 33f81d6 commit ebd3e08
Show file tree
Hide file tree
Showing 18 changed files with 185 additions and 464 deletions.
21 changes: 0 additions & 21 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ chrono = { version = "0.4", default-features = false }

# Cumulus
cumulus-pallet-aura-ext = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" }
cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" }
cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" }
cumulus-pallet-session-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" }
cumulus-pallet-xcm = { git = "https://github.com/paritytech/polkadot-sdk", default-features = false, branch = "release-polkadot-v1.7.2" }
Expand Down
5 changes: 3 additions & 2 deletions ci/run-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,19 @@ case $TARGET in

try-runtime)
cargo build -p centrifuge-chain --release --features try-runtime
cargo install --git https://github.com/paritytech/try-runtime-cli --tag v0.7.0 --locked
if [ "$1" == "altair" ]; then
echo "Running try-runtime for altair"
RUST_LOG=runtime=trace,try-runtime::cli=trace,executor=trace \
try-runtime \
--runtime target/release/wbuild/altair-runtime/altair_runtime.wasm \
on-runtime-upgrade live --uri wss://fullnode.altair.centrifuge.io:443
on-runtime-upgrade --disable-spec-version-check --checks=all live --uri wss://fullnode.altair.centrifuge.io:443
elif [ "$1" == "centrifuge" ]; then
echo "Running try-runtime for centrifuge"
RUST_LOG=runtime=trace,try-runtime::cli=trace,executor=trace \
try-runtime \
--runtime target/release/wbuild/centrifuge-runtime/centrifuge_runtime.wasm \
on-runtime-upgrade live --uri wss://fullnode.centrifuge.io:443
on-runtime-upgrade --disable-spec-version-check --checks=all live --uri wss://fullnode.centrifuge.io:443
else
echo "Invalid argument. Please specify 'altair' or 'centrifuge'."
exit 1
Expand Down
3 changes: 3 additions & 0 deletions pallets/liquidity-pools-gateway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ pub mod pallet {
MalformedSourceChain, MalformedSourceChainLength,
};

const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T>(_);

#[pallet::origin]
Expand Down
3 changes: 0 additions & 3 deletions runtime/altair/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ runtime-common = { workspace = true }
axelar-gateway-precompile = { workspace = true }
chainbridge = { workspace = true }
cumulus-pallet-aura-ext = { workspace = true }
cumulus-pallet-dmp-queue = { workspace = true }
cumulus-pallet-parachain-system = { workspace = true }
cumulus-pallet-xcm = { workspace = true }
cumulus-pallet-xcmp-queue = { workspace = true }
Expand Down Expand Up @@ -206,7 +205,6 @@ std = [
"axelar-gateway-precompile/std",
"chainbridge/std",
"cumulus-pallet-aura-ext/std",
"cumulus-pallet-dmp-queue/std",
"cumulus-pallet-parachain-system/std",
"cumulus-pallet-xcm/std",
"cumulus-pallet-xcmp-queue/std",
Expand Down Expand Up @@ -382,7 +380,6 @@ try-runtime = [
"axelar-gateway-precompile/try-runtime",
"chainbridge/try-runtime",
"cumulus-pallet-aura-ext/try-runtime",
"cumulus-pallet-dmp-queue/try-runtime",
"cumulus-pallet-parachain-system/try-runtime",
"cumulus-pallet-xcm/try-runtime",
"cumulus-pallet-xcmp-queue/try-runtime",
Expand Down
8 changes: 1 addition & 7 deletions runtime/altair/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,12 +357,6 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime {
type XcmpQueue = TransformOrigin<MessageQueue, AggregateMessageOrigin, ParaId, ParaIdToSibling>;
}

impl cumulus_pallet_dmp_queue::Config for Runtime {
type DmpSink = frame_support::traits::EnqueueWithOrigin<MessageQueue, RelayOrigin>;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = cumulus_pallet_dmp_queue::weights::SubstrateWeight<Runtime>;
}

parameter_types! {
pub const MinimumPeriod: Millis = SLOT_DURATION / 2;
}
Expand Down Expand Up @@ -2149,7 +2143,7 @@ construct_runtime!(
XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 120,
PolkadotXcm: pallet_xcm::{Pallet, Call, Storage, Config<T>, Event<T>, Origin} = 121,
CumulusXcm: cumulus_pallet_xcm::{Pallet, Event<T>, Origin} = 122,
DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 123,
// Removed: DmpQueue = 123
XTokens: pallet_restricted_xtokens::{Pallet, Call} = 124,
XcmTransactor: pallet_xcm_transactor::{Pallet, Call, Storage, Event<T>} = 125,
OrmlXTokens: orml_xtokens::{Pallet, Event<T>} = 126,
Expand Down
20 changes: 18 additions & 2 deletions runtime/altair/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,21 @@ use crate::Runtime;

/// The migration set for Altair @ Kusama.
/// It includes all the migrations that have to be applied on that chain.
pub type UpgradeAltair1401 =
runtime_common::migrations::liquidity_pools_gateway::Migration<Runtime>;
pub type UpgradeAltair1401 = (
// Clear OutboundMessageNonceStore
frame_support::migrations::VersionedMigration<
0,
1,
runtime_common::migrations::liquidity_pools_gateway::Migration<Runtime>,
pallet_liquidity_pools_gateway::Pallet<Runtime>,
<Runtime as frame_system::Config>::DbWeight,
>,
// Remove undecodable ForeignInvestmentInfo v0 entries
runtime_common::migrations::foreign_investments_v2::Migration<Runtime>,
// Bump to v1
runtime_common::migrations::increase_storage_version::Migration<
pallet_foreign_investments::Pallet<Runtime>,
1,
2,
>,
);
3 changes: 0 additions & 3 deletions runtime/centrifuge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ runtime-common = { workspace = true }
axelar-gateway-precompile = { workspace = true }
chainbridge = { workspace = true }
cumulus-pallet-aura-ext = { workspace = true }
cumulus-pallet-dmp-queue = { workspace = true }
cumulus-pallet-parachain-system = { workspace = true }
cumulus-pallet-xcm = { workspace = true }
cumulus-pallet-xcmp-queue = { workspace = true }
Expand Down Expand Up @@ -199,7 +198,6 @@ std = [
"axelar-gateway-precompile/std",
"chainbridge/std",
"cumulus-pallet-aura-ext/std",
"cumulus-pallet-dmp-queue/std",
"cumulus-pallet-parachain-system/std",
"cumulus-pallet-xcm/std",
"cumulus-pallet-xcmp-queue/std",
Expand Down Expand Up @@ -367,7 +365,6 @@ try-runtime = [
"axelar-gateway-precompile/try-runtime",
"chainbridge/try-runtime",
"cumulus-pallet-aura-ext/try-runtime",
"cumulus-pallet-dmp-queue/try-runtime",
"cumulus-pallet-parachain-system/try-runtime",
"cumulus-pallet-xcm/try-runtime",
"cumulus-pallet-xcmp-queue/try-runtime",
Expand Down
8 changes: 1 addition & 7 deletions runtime/centrifuge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,6 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime {
type XcmpQueue = TransformOrigin<MessageQueue, AggregateMessageOrigin, ParaId, ParaIdToSibling>;
}

impl cumulus_pallet_dmp_queue::Config for Runtime {
type DmpSink = frame_support::traits::EnqueueWithOrigin<MessageQueue, RelayOrigin>;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = cumulus_pallet_dmp_queue::weights::SubstrateWeight<Runtime>;
}

parameter_types! {
pub const NativeToken: CurrencyId = CurrencyId::Native;
}
Expand Down Expand Up @@ -2147,7 +2141,7 @@ construct_runtime!(
XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 120,
PolkadotXcm: pallet_xcm::{Pallet, Call, Storage, Config<T>, Event<T>, Origin} = 121,
CumulusXcm: cumulus_pallet_xcm::{Pallet, Event<T>, Origin} = 122,
DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 123,
// Removed: DmpQueue = 123
XTokens: pallet_restricted_xtokens::{Pallet, Call} = 124,
XcmTransactor: pallet_xcm_transactor::{Pallet, Call, Storage, Event<T>} = 125,
OrmlXTokens: orml_xtokens::{Pallet, Event<T>} = 126,
Expand Down
20 changes: 18 additions & 2 deletions runtime/centrifuge/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,21 @@ use crate::Runtime;

/// The migration set for Centrifuge @ Polkadot.
/// It includes all the migrations that have to be applied on that chain.
pub type UpgradeCentrifuge1401 =
runtime_common::migrations::liquidity_pools_gateway::Migration<Runtime>;
pub type UpgradeCentrifuge1401 = (
// Clear OutboundMessageNonceStore
frame_support::migrations::VersionedMigration<
0,
1,
runtime_common::migrations::liquidity_pools_gateway::Migration<Runtime>,
pallet_liquidity_pools_gateway::Pallet<Runtime>,
<Runtime as frame_system::Config>::DbWeight,
>,
// Remove undecodable ForeignInvestmentInfo v0 entries
runtime_common::migrations::foreign_investments_v2::Migration<Runtime>,
// Bump to v1
runtime_common::migrations::increase_storage_version::Migration<
pallet_foreign_investments::Pallet<Runtime>,
1,
2,
>,
);
69 changes: 69 additions & 0 deletions runtime/common/src/migrations/foreign_investments_v2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright 2024 Centrifuge Foundation (centrifuge.io).
//
// This file is part of the Centrifuge chain project.
// Centrifuge is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version (see http://www.gnu.org/licenses).
// Centrifuge is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

use frame_support::traits::{Get, OnRuntimeUpgrade};
use pallet_order_book::weights::Weight;
use sp_io::{storage::clear_prefix, KillStorageResult};
use sp_std::vec::Vec;

pub struct Migration<T>(sp_std::marker::PhantomData<T>);

const REMOVAL_LIMIT: u32 = 10u32;
const LOG_PREFIX: &str = "LiquidityPoolsGatewayV1";

impl<T> OnRuntimeUpgrade for Migration<T>
where
T: frame_system::Config,
{
fn on_runtime_upgrade() -> Weight {
let mut weight = Weight::zero();

match clear_prefix(&get_storage_prefix(), Some(REMOVAL_LIMIT)) {
KillStorageResult::AllRemoved(n) => {
log::info!("{LOG_PREFIX}: Removed {n} ForeignInvestmentInfo V1 keys");
weight.saturating_accrue(T::DbWeight::get().writes(n.into()));
}
KillStorageResult::SomeRemaining(n) => {
log::warn!("{LOG_PREFIX}: There are {n} remaining ForeignInvestmentInfo V1 keys!");
weight.saturating_accrue(T::DbWeight::get().writes(REMOVAL_LIMIT.into()));
}
}

log::info!("{LOG_PREFIX}: Migration done!");

weight
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
log::info!("{LOG_PREFIX}: Pre checks done!");

Ok(Vec::new())
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
assert!(
!sp_io::storage::exists(&get_storage_prefix()),
"{LOG_PREFIX}: ForeignInvestmentV0 keys remaining!"
);

log::info!("{LOG_PREFIX}: Post checks done!");

Ok(())
}
}

/// Returns final storage key prefix of `ForeignInvestmentInfo` in v0
fn get_storage_prefix() -> Vec<u8> {
hex_literal::hex!("464aed913919bab92f79f3c7b79d28f7efbac15e93f37811895e260605cdc487").to_vec()
}
Loading

0 comments on commit ebd3e08

Please sign in to comment.