Skip to content

Commit

Permalink
feat: add allowlist removal
Browse files Browse the repository at this point in the history
  • Loading branch information
wischli committed Jan 13, 2025
1 parent fd7fcd1 commit 74e095f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 4 deletions.
6 changes: 3 additions & 3 deletions runtime/centrifuge/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::Runtime;
/// The migration set for Centrifuge @ Polkadot.
/// It includes all the migrations that have to be applied on that chain.
pub type UpgradeCentrifuge1403 = (
// Clear v0 RelayerList storage
// Remove deprecated LiquidityPoolsGateway::{v0, v1, v2}::RelayerList storage
runtime_common::migrations::liquidity_pools_v2::kill_relayer_list::Migration<Runtime>,
// Clear OutboundMessageNonceStore and migrate outbound storage to LP queue
runtime_common::migrations::liquidity_pools_v2::v0_init_message_queue::Migration<Runtime>,
Expand All @@ -29,8 +29,8 @@ pub type UpgradeCentrifuge1403 = (
pallet_liquidity_pools_gateway::Pallet<Runtime>,
<Runtime as frame_system::Config>::DbWeight,
>,
// Remove deprecated RelayerList storage
runtime_common::migrations::liquidity_pools_v2::kill_relayer_list::Migration<Runtime>,
// Remove deprecated LiquidityPoolsGateway::{v0, v1, v2}::Allowlist storage
runtime_common::migrations::liquidity_pools_v2::kill_allowlist::Migration<Runtime, 20>,
// Remove undecodable ForeignInvestmentInfo v0 entries
runtime_common::migrations::foreign_investments_v2::Migration<Runtime>,
// Bump to v1
Expand Down
57 changes: 57 additions & 0 deletions runtime/common/src/migrations/liquidity_pools_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,63 @@ pub mod kill_relayer_list {
}
}

pub mod kill_allowlist {
use frame_support::traits::OnRuntimeUpgrade;
#[cfg(feature = "try-runtime")]
use frame_support::{dispatch::DispatchResult, storage::with_storage_layer};
#[cfg(feature = "try-runtime")]
use sp_arithmetic::traits::Zero;
#[cfg(feature = "try-runtime")]
use sp_std::vec;

use super::{types::v0, *};
use crate::migrations::nuke::storage_clean_res_log;

const LOG_PREFIX: &str = "ClearAllowlist";

pub struct Migration<T, const REMOVAL_ITEM_LIMIT: u32>(PhantomData<T>);

impl<T, const REMOVAL_ITEM_LIMIT: u32> OnRuntimeUpgrade for Migration<T, REMOVAL_ITEM_LIMIT>
where
T: pallet_liquidity_pools_gateway::Config,
{
fn on_runtime_upgrade() -> Weight {
let res = v0::Allowlist::<T>::clear(REMOVAL_ITEM_LIMIT, None);
storage_clean_res_log(&res, "Allowlist", LOG_PREFIX);

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

T::DbWeight::get().reads_writes(res.loops.into(), res.unique.into())
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::TryRuntimeError> {
let mut cleared: bool = false;

// Need to rollback in order to be NOOP
let _ = with_storage_layer(|| -> DispatchResult {
cleared = v0::Allowlist::<T>::clear(REMOVAL_ITEM_LIMIT, None)
.maybe_cursor
.is_none();
Err(DispatchError::Other("Reverting on purpose"))
});
assert!(cleared);

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

Ok(vec![])
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_: Vec<u8>) -> Result<(), sp_runtime::TryRuntimeError> {
assert!(v0::Allowlist::<T>::iter_keys().count().is_zero());
log::info!("{LOG_PREFIX}: Post checks done!");

Ok(())
}
}
}

pub mod v2_update_message_queue {
use pallet_liquidity_pools::Message;
use pallet_liquidity_pools_gateway::message::GatewayMessage;
Expand Down
7 changes: 6 additions & 1 deletion runtime/development/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ use frame_support::migrations::VersionedMigration;
use crate::Runtime;

pub type UpgradeDevelopment1403 = (
runtime_common::migrations::liquidity_pools_v2::kill_relayer_list::Migration<Runtime>,
// Clear OutboundMessageNonceStore and migrate outbound storage to LP queue
runtime_common::migrations::liquidity_pools_v2::v2_update_message_queue::Migration<Runtime>,
// Remove deprecated DomainRouters entries and migrate relevant ones to Axelar Router Config
VersionedMigration<
2,
3,
runtime_common::migrations::liquidity_pools_v2::init_axelar_router::Migration<Runtime>,
pallet_liquidity_pools_gateway::Pallet<Runtime>,
<Runtime as frame_system::Config>::DbWeight,
>,
// Remove deprecated LiquidityPoolsGateway::{v0, v1, v2}::RelayerList storage
runtime_common::migrations::liquidity_pools_v2::kill_relayer_list::Migration<Runtime>,
// Remove deprecated LiquidityPoolsGateway::{v0, v1, v2}::Allowlist storage
runtime_common::migrations::liquidity_pools_v2::kill_allowlist::Migration<Runtime, 40>,
);

0 comments on commit 74e095f

Please sign in to comment.