From 66886ca46fd42eeb29cc19318b5351888224312b Mon Sep 17 00:00:00 2001 From: William Freudenberger Date: Tue, 4 Jun 2024 16:32:58 +0200 Subject: [PATCH 1/9] feat: add pre + post-upgrade --- runtime/centrifuge/src/migrations.rs | 16 + .../src/migrations/restricted_location.rs | 178 ++++-- runtime/development/Cargo.toml | 563 +++++++++--------- 3 files changed, 420 insertions(+), 337 deletions(-) diff --git a/runtime/centrifuge/src/migrations.rs b/runtime/centrifuge/src/migrations.rs index 7bf4d05d88..d42b428a98 100644 --- a/runtime/centrifuge/src/migrations.rs +++ b/runtime/centrifuge/src/migrations.rs @@ -10,11 +10,26 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. +use cfg_primitives::AccountId; +use frame_support::parameter_types; +use sp_std::{vec, vec::Vec}; + use crate::{OraclePriceCollection, OraclePriceFeed}; // Number of identities on Centrifuge Chain on 29.05.2024 was 34 const IDENTITY_MIGRATION_KEY_LIMIT: u64 = 1000; +parameter_types! { + // Address used by Anemoy to withdraw in AssetHub + // 4dTeMxuPJCK7zQGhFcgCivSJqBs9Wo2SuMSQeYCCuVJ9xrE2 --> 5Fc9NzKzJZwZvgjQBmSKtvZmJ5oP6B49DFC5dXZhTETjrSzo + pub AccountMap: Vec<(AccountId, AccountId)> = vec![ + ( + AccountId::new(hex_literal::hex!("5dbb2cec05b6bda775f7945827b887b0e7b5245eae8b4ef266c60820c9377185")), + AccountId::new(hex_literal::hex!("10c03288a534d77418e3c19e745dfbc952423e179e1e3baa89e287092fc7802f")) + ) + ]; +} + /// The migration set for Centrifuge @ Polkadot. /// It includes all the migrations that have to be applied on that chain. pub type UpgradeCentrifuge1029 = ( @@ -33,5 +48,6 @@ pub type UpgradeCentrifuge1029 = ( pallet_uniques::migration::MigrateV0ToV1, runtime_common::migrations::restricted_location::MigrateRestrictedTransferLocation< crate::Runtime, + AccountMap, >, ); diff --git a/runtime/common/src/migrations/restricted_location.rs b/runtime/common/src/migrations/restricted_location.rs index 21ad8aa25c..d230193d8e 100644 --- a/runtime/common/src/migrations/restricted_location.rs +++ b/runtime/common/src/migrations/restricted_location.rs @@ -6,6 +6,7 @@ use frame_support::{ }; use pallet_transfer_allowlist::AccountCurrencyTransferAllowance; use parity_scale_codec::Encode; +use sp_arithmetic::traits::SaturatedConversion; use sp_core::H256; use sp_runtime::traits::{BlakeTwo256, Hash}; use sp_std::vec::Vec; @@ -16,13 +17,19 @@ mod old { use cfg_types::{domain_address::DomainAddress, tokens::FilterCurrency}; use frame_support::{pallet_prelude::*, storage_alias}; use frame_system::pallet_prelude::*; - use hex::FromHex; use pallet_transfer_allowlist::AllowanceDetails; use sp_core::H256; use staging_xcm::v3; #[derive( - Clone, RuntimeDebugNoBound, Encode, Decode, Eq, PartialEq, MaxEncodedLen, TypeInfo, + Clone, + RuntimeDebugNoBound, + Encode, + parity_scale_codec::Decode, + Eq, + PartialEq, + MaxEncodedLen, + TypeInfo, )] pub enum RestrictedTransferLocation { Local(AccountId), @@ -42,7 +49,7 @@ mod old { OptionQuery, >; - pub fn location_v3_created_by_apps(_account_id: &AccountId) -> v3::Location { + pub fn location_v3_created_by_apps(account_id: AccountId) -> v3::Location { // Ref: https://github.com/centrifuge/apps/blob/b59bdd34561a4ccd90e0d803c14a3729fc2f3a6d/centrifuge-app/src/utils/usePermissions.tsx#L386 // for account_id == "4dTeMxuPJCK7zQGhFcgCivSJqBs9Wo2SuMSQeYCCuVJ9xrE2" v3::Location::new( @@ -51,11 +58,7 @@ mod old { v3::Junction::Parachain(1000), // AssetHub v3::Junction::AccountId32 { network: None, - id: <[u8; 32]>::from_hex( - // Address used by Anemoy to withdraw in AssetHub - "10c03288a534d77418e3c19e745dfbc952423e179e1e3baa89e287092fc7802f", - ) - .expect("keep in the array"), + id: account_id.into(), }, ), ) @@ -64,64 +67,40 @@ mod old { const LOG_PREFIX: &str = "MigrateRestrictedTransferLocation:"; -fn migrate_location_key(account_id: &AccountId, hash: H256) -> Option { - let old_location = old::location_v3_created_by_apps(account_id); - if BlakeTwo256::hash(&old_location.encode()) == hash { - match v4::Location::try_from(old_location) { - Ok(location) => { - log::info!("{LOG_PREFIX} Hash: '{hash}' migrated!"); - let new_restricted_location = RestrictedTransferLocation::Xcm(location); - - Some(new_restricted_location) - } - Err(_) => { - log::error!("{LOG_PREFIX} Non isometric location v3 -> v4"); - None - } - } - } else { - log::error!("{LOG_PREFIX} Hash can not be recovered"); - None - } -} - -pub struct MigrateRestrictedTransferLocation(sp_std::marker::PhantomData); -impl OnRuntimeUpgrade for MigrateRestrictedTransferLocation +pub struct MigrateRestrictedTransferLocation( + sp_std::marker::PhantomData<(T, AccountMap)>, +); +impl OnRuntimeUpgrade for MigrateRestrictedTransferLocation where T: pallet_transfer_allowlist::Config< AccountId = AccountId, CurrencyId = FilterCurrency, Location = RestrictedTransferLocation, >, + AccountMap: Get>, { fn on_runtime_upgrade() -> Weight { log::info!("{LOG_PREFIX} Check keys to migrate..."); - let mut weight = Weight::zero(); + let mut weight = T::DbWeight::get().reads( + old::AccountCurrencyTransferAllowance::::iter_keys() + .count() + .saturated_into(), + ); - let key_translations = old::AccountCurrencyTransferAllowance::::iter_keys() - .filter_map(|(account_id, currency_id, old_restricted_location)| { - weight.saturating_accrue(T::DbWeight::get().reads(1)); - match old_restricted_location { - old::RestrictedTransferLocation::Xcm(hash) => { - migrate_location_key(&account_id, hash).map(|new_restricted_location| { - ( - (account_id.clone(), currency_id, old_restricted_location), - (account_id, currency_id, new_restricted_location), - ) - }) - } - _ => None, - } - }) - .collect::>(); - - for (old_key, new_key) in key_translations { - log::info!("{LOG_PREFIX} Remove {old_key:?} and add {new_key:?}"); + let key_translations = Self::get_key_translations(); - let value = old::AccountCurrencyTransferAllowance::::get(&old_key); + for (acc, currency, old_location, maybe_new_location) in key_translations { + let old_key = (&acc, ¤cy, &old_location); + log::info!("{LOG_PREFIX} Removing old key {old_key:?}"); + let value = old::AccountCurrencyTransferAllowance::::get(old_key); old::AccountCurrencyTransferAllowance::::remove(old_key); - AccountCurrencyTransferAllowance::::set(new_key, value); + + if let Some(new_location) = maybe_new_location { + let new_key = (&acc, ¤cy, &new_location); + log::info!("{LOG_PREFIX} Adding new key {new_key:?}"); + AccountCurrencyTransferAllowance::::set(new_key, value); + } weight.saturating_accrue(T::DbWeight::get().writes(2)); } @@ -131,11 +110,100 @@ where #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { - Ok(Vec::new()) + let key_translations = Self::get_key_translations(); + assert!( + key_translations + .iter() + .all(|(_, _, _, new_location)| new_location.is_some()), + "At least one XCM location could not be translated" + ); + + let count: u64 = old::AccountCurrencyTransferAllowance::::iter_keys() + .count() + .saturated_into(); + + log::info!("{LOG_PREFIX} Pre checks done!"); + Ok(count.encode()) } #[cfg(feature = "try-runtime")] - fn post_upgrade(_pre_state: Vec) -> Result<(), sp_runtime::TryRuntimeError> { + fn post_upgrade(pre_state: Vec) -> Result<(), sp_runtime::TryRuntimeError> { + let count_pre: u64 = parity_scale_codec::Decode::decode(&mut pre_state.as_slice()) + .expect("pre_upgrade provides a valid state; qed"); + let count_post: u64 = AccountCurrencyTransferAllowance::::iter_keys() + .count() + .saturated_into(); + assert_eq!(count_pre, count_post, "Number of keys in AccountCurrencyTransferAllowance changed during migration: pre {count_pre} vs post {count_post}"); + + log::info!("{LOG_PREFIX} Post checks done!"); Ok(()) } } + +impl MigrateRestrictedTransferLocation +where + T: pallet_transfer_allowlist::Config< + AccountId = AccountId, + CurrencyId = FilterCurrency, + Location = RestrictedTransferLocation, + >, + AccountMap: Get>, +{ + fn migrate_location_key( + account_id: AccountId, + hash: H256, + ) -> Option { + let old_location = old::location_v3_created_by_apps(account_id); + if BlakeTwo256::hash(&old_location.encode()) == hash { + match v4::Location::try_from(old_location) { + Ok(location) => { + log::info!("{LOG_PREFIX} Hash: '{hash}' migrated!"); + let new_restricted_location = RestrictedTransferLocation::Xcm(location); + + Some(new_restricted_location) + } + Err(_) => { + log::error!("{LOG_PREFIX} Non isometric location v3 -> v4"); + None + } + } + } else { + log::error!("{LOG_PREFIX} Hash can not be recovered"); + None + } + } + + fn get_key_translations() -> Vec<( + AccountId, + FilterCurrency, + old::RestrictedTransferLocation, + Option, + )> { + let accounts = AccountMap::get(); + + old::AccountCurrencyTransferAllowance::::iter_keys() + .filter_map(|(account_id, currency_id, old_restricted_location)| { + match (accounts.iter().find(|(key, _)| key == &account_id), old_restricted_location.clone()) { + (Some((_, transfer_address)), old::RestrictedTransferLocation::Xcm(hash)) => Some(( + account_id.clone(), + currency_id, + old_restricted_location, + Self::migrate_location_key(transfer_address.clone(), hash), + )), + (None, old::RestrictedTransferLocation::Xcm(_)) => { + log::warn!("{LOG_PREFIX} Account {account_id:?} missing in AccountMap despite old XCM location storage"); + Some(( + account_id.clone(), + currency_id, + old_restricted_location, + // Leads to storage entry removal + // TODO: Discuss whether we are fine with removing such storage entries or whether we want to keep the old undecodable ones or maybe just use same account id per default instead of removing? + None, + )) + } + _ => None, + } + }) + .collect::>() + } +} diff --git a/runtime/development/Cargo.toml b/runtime/development/Cargo.toml index 32e95f4c3d..2b9843f05a 100644 --- a/runtime/development/Cargo.toml +++ b/runtime/development/Cargo.toml @@ -12,7 +12,7 @@ documentation.workspace = true [dependencies] getrandom = { workspace = true } hex = { workspace = true } -hex-literal = { workspace = true, optional = true } +hex-literal = { workspace = true } log = { workspace = true } parity-scale-codec = { workspace = true } scale-info = { workspace = true } @@ -145,299 +145,298 @@ substrate-wasm-builder = { workspace = true } default = ["std"] std = [ - "parity-scale-codec/std", - "getrandom/std", - "hex/std", - "log/std", - "scale-info/std", - "serde/std", - # Substrate related - "sp-api/std", - "sp-runtime/std", - "sp-block-builder/std", - "sp-consensus-aura/std", - "sp-core/std", - "sp-genesis-builder/std", - "sp-inherents/std", - "sp-io/std", - "sp-offchain/std", - "sp-session/std", - "sp-std/std", - "sp-transaction-pool/std", - "sp-version/std", - "sp-staking/std", - "frame-support/std", - "frame-system/std", - "frame-system-rpc-runtime-api/std", - "frame-executive/std", - "frame-try-runtime?/std", - "frame-system-benchmarking?/std", - "frame-benchmarking?/std", - "cumulus-primitives-core/std", - "cumulus-primitives-timestamp/std", - "cumulus-primitives-utility/std", - "cumulus-pallet-session-benchmarking?/std", - "staging-xcm/std", - "staging-xcm-builder/std", - "staging-xcm-executor/std", - "xcm-primitives/std", - "orml-traits/std", - "orml-xcm-support/std", - "fp-rpc/std", - "fp-self-contained/std", - "pallet-transaction-payment-rpc-runtime-api/std", - "polkadot-runtime-common/std", - "polkadot-parachain-primitives/std", - # Locals - "cfg-primitives/std", - "cfg-traits/std", - "cfg-types/std", - "runtime-common/std", - "liquidity-pools-gateway-routers/std", - # Pallet list - "axelar-gateway-precompile/std", - "chainbridge/std", - "cumulus-pallet-aura-ext/std", - "cumulus-pallet-parachain-system/std", - "cumulus-pallet-xcm/std", - "cumulus-pallet-xcmp-queue/std", - "orml-asset-registry/std", - "orml-tokens/std", - "orml-xcm/std", - "orml-xtokens/std", - "pallet-anchors/std", - "pallet-aura/std", - "pallet-authorship/std", - "pallet-balances/std", - "pallet-base-fee/std", - "pallet-block-rewards/std", - "pallet-bridge/std", - "pallet-collator-allowlist/std", - "pallet-collator-selection/std", - "pallet-collective/std", - "pallet-democracy/std", - "pallet-elections-phragmen/std", - "pallet-ethereum/std", - "pallet-ethereum-transaction/std", - "pallet-evm/std", - "pallet-evm-chain-id/std", - "pallet-fees/std", - "pallet-foreign-investments/std", - "pallet-identity/std", - "pallet-interest-accrual/std", - "pallet-investments/std", - "pallet-keystore/std", - "pallet-liquidity-pools/std", - "pallet-liquidity-pools-gateway/std", - "pallet-liquidity-rewards/std", - "pallet-loans/std", - "pallet-membership/std", - "pallet-multisig/std", - "pallet-oracle-collection/std", - "pallet-oracle-feed/std", - "pallet-order-book/std", - "pallet-permissions/std", - "pallet-pool-fees/std", - "pallet-pool-registry/std", - "pallet-pool-system/std", - "pallet-preimage/std", - "pallet-proxy/std", - "pallet-remarks/std", - "pallet-restricted-tokens/std", - "pallet-restricted-xtokens/std", - "pallet-rewards/std", - "pallet-scheduler/std", - "pallet-session/std", - "pallet-sudo/std", - "pallet-swaps/std", - "pallet-timestamp/std", - "pallet-token-mux/std", - "pallet-transaction-payment/std", - "pallet-transfer-allowlist/std", - "pallet-treasury/std", - "pallet-uniques/std", - "pallet-utility/std", - "pallet-vesting/std", - "pallet-xcm/std", - "pallet-xcm-transactor/std", - "pallet-message-queue/std", - "staging-parachain-info/std", + "parity-scale-codec/std", + "getrandom/std", + "hex/std", + "log/std", + "scale-info/std", + "serde/std", + # Substrate related + "sp-api/std", + "sp-runtime/std", + "sp-block-builder/std", + "sp-consensus-aura/std", + "sp-core/std", + "sp-genesis-builder/std", + "sp-inherents/std", + "sp-io/std", + "sp-offchain/std", + "sp-session/std", + "sp-std/std", + "sp-transaction-pool/std", + "sp-version/std", + "sp-staking/std", + "frame-support/std", + "frame-system/std", + "frame-system-rpc-runtime-api/std", + "frame-executive/std", + "frame-try-runtime?/std", + "frame-system-benchmarking?/std", + "frame-benchmarking?/std", + "cumulus-primitives-core/std", + "cumulus-primitives-timestamp/std", + "cumulus-primitives-utility/std", + "cumulus-pallet-session-benchmarking?/std", + "staging-xcm/std", + "staging-xcm-builder/std", + "staging-xcm-executor/std", + "xcm-primitives/std", + "orml-traits/std", + "orml-xcm-support/std", + "fp-rpc/std", + "fp-self-contained/std", + "pallet-transaction-payment-rpc-runtime-api/std", + "polkadot-runtime-common/std", + "polkadot-parachain-primitives/std", + # Locals + "cfg-primitives/std", + "cfg-traits/std", + "cfg-types/std", + "runtime-common/std", + "liquidity-pools-gateway-routers/std", + # Pallet list + "axelar-gateway-precompile/std", + "chainbridge/std", + "cumulus-pallet-aura-ext/std", + "cumulus-pallet-parachain-system/std", + "cumulus-pallet-xcm/std", + "cumulus-pallet-xcmp-queue/std", + "orml-asset-registry/std", + "orml-tokens/std", + "orml-xcm/std", + "orml-xtokens/std", + "pallet-anchors/std", + "pallet-aura/std", + "pallet-authorship/std", + "pallet-balances/std", + "pallet-base-fee/std", + "pallet-block-rewards/std", + "pallet-bridge/std", + "pallet-collator-allowlist/std", + "pallet-collator-selection/std", + "pallet-collective/std", + "pallet-democracy/std", + "pallet-elections-phragmen/std", + "pallet-ethereum/std", + "pallet-ethereum-transaction/std", + "pallet-evm/std", + "pallet-evm-chain-id/std", + "pallet-fees/std", + "pallet-foreign-investments/std", + "pallet-identity/std", + "pallet-interest-accrual/std", + "pallet-investments/std", + "pallet-keystore/std", + "pallet-liquidity-pools/std", + "pallet-liquidity-pools-gateway/std", + "pallet-liquidity-rewards/std", + "pallet-loans/std", + "pallet-membership/std", + "pallet-multisig/std", + "pallet-oracle-collection/std", + "pallet-oracle-feed/std", + "pallet-order-book/std", + "pallet-permissions/std", + "pallet-pool-fees/std", + "pallet-pool-registry/std", + "pallet-pool-system/std", + "pallet-preimage/std", + "pallet-proxy/std", + "pallet-remarks/std", + "pallet-restricted-tokens/std", + "pallet-restricted-xtokens/std", + "pallet-rewards/std", + "pallet-scheduler/std", + "pallet-session/std", + "pallet-sudo/std", + "pallet-swaps/std", + "pallet-timestamp/std", + "pallet-token-mux/std", + "pallet-transaction-payment/std", + "pallet-transfer-allowlist/std", + "pallet-treasury/std", + "pallet-uniques/std", + "pallet-utility/std", + "pallet-vesting/std", + "pallet-xcm/std", + "pallet-xcm-transactor/std", + "pallet-message-queue/std", + "staging-parachain-info/std", ] runtime-benchmarks = [ - # Enabling optional - "hex-literal", - "frame-system-benchmarking/runtime-benchmarks", - "frame-benchmarking/runtime-benchmarks", - "cumulus-pallet-session-benchmarking/runtime-benchmarks", - # Substrate related - "sp-runtime/runtime-benchmarks", - "sp-staking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "staging-xcm-builder/runtime-benchmarks", - "staging-xcm-executor/runtime-benchmarks", - "xcm-primitives/runtime-benchmarks", - "polkadot-runtime-common/runtime-benchmarks", - "polkadot-parachain-primitives/runtime-benchmarks", - # Locals - "cfg-primitives/runtime-benchmarks", - "cfg-traits/runtime-benchmarks", - "cfg-types/runtime-benchmarks", - "runtime-common/runtime-benchmarks", - "liquidity-pools-gateway-routers/runtime-benchmarks", - # Pallet list - "axelar-gateway-precompile/runtime-benchmarks", - "chainbridge/runtime-benchmarks", - "cumulus-pallet-parachain-system/runtime-benchmarks", - "cumulus-pallet-xcmp-queue/runtime-benchmarks", - "orml-asset-registry/runtime-benchmarks", - "orml-tokens/runtime-benchmarks", - "orml-xtokens/runtime-benchmarks", - "pallet-anchors/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "pallet-block-rewards/runtime-benchmarks", - "pallet-bridge/runtime-benchmarks", - "pallet-collator-allowlist/runtime-benchmarks", - "pallet-collator-selection/runtime-benchmarks", - "pallet-collective/runtime-benchmarks", - "pallet-democracy/runtime-benchmarks", - "pallet-elections-phragmen/runtime-benchmarks", - "pallet-ethereum/runtime-benchmarks", - "pallet-ethereum-transaction/runtime-benchmarks", - "pallet-evm/runtime-benchmarks", - "pallet-fees/runtime-benchmarks", - "pallet-foreign-investments/runtime-benchmarks", - "pallet-identity/runtime-benchmarks", - "pallet-interest-accrual/runtime-benchmarks", - "pallet-investments/runtime-benchmarks", - "pallet-keystore/runtime-benchmarks", - "pallet-liquidity-pools/runtime-benchmarks", - "pallet-liquidity-pools-gateway/runtime-benchmarks", - "pallet-liquidity-rewards/runtime-benchmarks", - "pallet-loans/runtime-benchmarks", - "pallet-membership/runtime-benchmarks", - "pallet-multisig/runtime-benchmarks", - "pallet-oracle-collection/runtime-benchmarks", - "pallet-oracle-feed/runtime-benchmarks", - "pallet-order-book/runtime-benchmarks", - "pallet-permissions/runtime-benchmarks", - "pallet-pool-fees/runtime-benchmarks", - "pallet-pool-registry/runtime-benchmarks", - "pallet-pool-system/runtime-benchmarks", - "pallet-preimage/runtime-benchmarks", - "pallet-proxy/runtime-benchmarks", - "pallet-remarks/runtime-benchmarks", - "pallet-restricted-tokens/runtime-benchmarks", - "pallet-restricted-xtokens/runtime-benchmarks", - "pallet-rewards/runtime-benchmarks", - "pallet-scheduler/runtime-benchmarks", - "pallet-sudo/runtime-benchmarks", - "pallet-swaps/runtime-benchmarks", - "pallet-timestamp/runtime-benchmarks", - "pallet-token-mux/runtime-benchmarks", - "pallet-transfer-allowlist/runtime-benchmarks", - "pallet-treasury/runtime-benchmarks", - "pallet-uniques/runtime-benchmarks", - "pallet-utility/runtime-benchmarks", - "pallet-vesting/runtime-benchmarks", - "pallet-xcm/runtime-benchmarks", - "pallet-xcm-transactor/runtime-benchmarks", - "pallet-message-queue/runtime-benchmarks", + # Enabling optional + "frame-system-benchmarking/runtime-benchmarks", + "frame-benchmarking/runtime-benchmarks", + "cumulus-pallet-session-benchmarking/runtime-benchmarks", + # Substrate related + "sp-runtime/runtime-benchmarks", + "sp-staking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "staging-xcm-builder/runtime-benchmarks", + "staging-xcm-executor/runtime-benchmarks", + "xcm-primitives/runtime-benchmarks", + "polkadot-runtime-common/runtime-benchmarks", + "polkadot-parachain-primitives/runtime-benchmarks", + # Locals + "cfg-primitives/runtime-benchmarks", + "cfg-traits/runtime-benchmarks", + "cfg-types/runtime-benchmarks", + "runtime-common/runtime-benchmarks", + "liquidity-pools-gateway-routers/runtime-benchmarks", + # Pallet list + "axelar-gateway-precompile/runtime-benchmarks", + "chainbridge/runtime-benchmarks", + "cumulus-pallet-parachain-system/runtime-benchmarks", + "cumulus-pallet-xcmp-queue/runtime-benchmarks", + "orml-asset-registry/runtime-benchmarks", + "orml-tokens/runtime-benchmarks", + "orml-xtokens/runtime-benchmarks", + "pallet-anchors/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-block-rewards/runtime-benchmarks", + "pallet-bridge/runtime-benchmarks", + "pallet-collator-allowlist/runtime-benchmarks", + "pallet-collator-selection/runtime-benchmarks", + "pallet-collective/runtime-benchmarks", + "pallet-democracy/runtime-benchmarks", + "pallet-elections-phragmen/runtime-benchmarks", + "pallet-ethereum/runtime-benchmarks", + "pallet-ethereum-transaction/runtime-benchmarks", + "pallet-evm/runtime-benchmarks", + "pallet-fees/runtime-benchmarks", + "pallet-foreign-investments/runtime-benchmarks", + "pallet-identity/runtime-benchmarks", + "pallet-interest-accrual/runtime-benchmarks", + "pallet-investments/runtime-benchmarks", + "pallet-keystore/runtime-benchmarks", + "pallet-liquidity-pools/runtime-benchmarks", + "pallet-liquidity-pools-gateway/runtime-benchmarks", + "pallet-liquidity-rewards/runtime-benchmarks", + "pallet-loans/runtime-benchmarks", + "pallet-membership/runtime-benchmarks", + "pallet-multisig/runtime-benchmarks", + "pallet-oracle-collection/runtime-benchmarks", + "pallet-oracle-feed/runtime-benchmarks", + "pallet-order-book/runtime-benchmarks", + "pallet-permissions/runtime-benchmarks", + "pallet-pool-fees/runtime-benchmarks", + "pallet-pool-registry/runtime-benchmarks", + "pallet-pool-system/runtime-benchmarks", + "pallet-preimage/runtime-benchmarks", + "pallet-proxy/runtime-benchmarks", + "pallet-remarks/runtime-benchmarks", + "pallet-restricted-tokens/runtime-benchmarks", + "pallet-restricted-xtokens/runtime-benchmarks", + "pallet-rewards/runtime-benchmarks", + "pallet-scheduler/runtime-benchmarks", + "pallet-sudo/runtime-benchmarks", + "pallet-swaps/runtime-benchmarks", + "pallet-timestamp/runtime-benchmarks", + "pallet-token-mux/runtime-benchmarks", + "pallet-transfer-allowlist/runtime-benchmarks", + "pallet-treasury/runtime-benchmarks", + "pallet-uniques/runtime-benchmarks", + "pallet-utility/runtime-benchmarks", + "pallet-vesting/runtime-benchmarks", + "pallet-xcm/runtime-benchmarks", + "pallet-xcm-transactor/runtime-benchmarks", + "pallet-message-queue/runtime-benchmarks", ] try-runtime = [ - # Enabling optional - "frame-try-runtime/try-runtime", - # Substrate related - "sp-runtime/try-runtime", - "frame-support/try-runtime", - "frame-system/try-runtime", - "frame-executive/try-runtime", - "fp-self-contained/try-runtime", - "polkadot-runtime-common/try-runtime", - # Locals - "cfg-primitives/try-runtime", - "cfg-traits/try-runtime", - "cfg-types/try-runtime", - "runtime-common/try-runtime", - "liquidity-pools-gateway-routers/try-runtime", - # Pallet list - "axelar-gateway-precompile/try-runtime", - "chainbridge/try-runtime", - "cumulus-pallet-aura-ext/try-runtime", - "cumulus-pallet-parachain-system/try-runtime", - "cumulus-pallet-xcm/try-runtime", - "cumulus-pallet-xcmp-queue/try-runtime", - "orml-asset-registry/try-runtime", - "orml-tokens/try-runtime", - "orml-xcm/try-runtime", - "orml-xtokens/try-runtime", - "pallet-anchors/try-runtime", - "pallet-aura/try-runtime", - "pallet-authorship/try-runtime", - "pallet-balances/try-runtime", - "pallet-base-fee/try-runtime", - "pallet-block-rewards/try-runtime", - "pallet-bridge/try-runtime", - "pallet-collator-allowlist/try-runtime", - "pallet-collator-selection/try-runtime", - "pallet-collective/try-runtime", - "pallet-democracy/try-runtime", - "pallet-elections-phragmen/try-runtime", - "pallet-ethereum/try-runtime", - "pallet-ethereum-transaction/try-runtime", - "pallet-evm/try-runtime", - "pallet-evm-chain-id/try-runtime", - "pallet-fees/try-runtime", - "pallet-foreign-investments/try-runtime", - "pallet-identity/try-runtime", - "pallet-interest-accrual/try-runtime", - "pallet-investments/try-runtime", - "pallet-keystore/try-runtime", - "pallet-liquidity-pools/try-runtime", - "pallet-liquidity-pools-gateway/try-runtime", - "pallet-liquidity-rewards/try-runtime", - "pallet-loans/try-runtime", - "pallet-membership/try-runtime", - "pallet-multisig/try-runtime", - "pallet-oracle-collection/try-runtime", - "pallet-oracle-feed/try-runtime", - "pallet-order-book/try-runtime", - "pallet-permissions/try-runtime", - "pallet-pool-fees/try-runtime", - "pallet-pool-registry/try-runtime", - "pallet-pool-system/try-runtime", - "pallet-preimage/try-runtime", - "pallet-proxy/try-runtime", - "pallet-remarks/try-runtime", - "pallet-restricted-tokens/try-runtime", - "pallet-restricted-xtokens/try-runtime", - "pallet-rewards/try-runtime", - "pallet-scheduler/try-runtime", - "pallet-session/try-runtime", - "pallet-sudo/try-runtime", - "pallet-swaps/try-runtime", - "pallet-timestamp/try-runtime", - "pallet-token-mux/try-runtime", - "pallet-transaction-payment/try-runtime", - "pallet-transfer-allowlist/try-runtime", - "pallet-treasury/try-runtime", - "pallet-uniques/try-runtime", - "pallet-utility/try-runtime", - "pallet-vesting/try-runtime", - "pallet-xcm/try-runtime", - "pallet-xcm-transactor/try-runtime", - "pallet-message-queue/try-runtime", - "staging-parachain-info/try-runtime", + # Enabling optional + "frame-try-runtime/try-runtime", + # Substrate related + "sp-runtime/try-runtime", + "frame-support/try-runtime", + "frame-system/try-runtime", + "frame-executive/try-runtime", + "fp-self-contained/try-runtime", + "polkadot-runtime-common/try-runtime", + # Locals + "cfg-primitives/try-runtime", + "cfg-traits/try-runtime", + "cfg-types/try-runtime", + "runtime-common/try-runtime", + "liquidity-pools-gateway-routers/try-runtime", + # Pallet list + "axelar-gateway-precompile/try-runtime", + "chainbridge/try-runtime", + "cumulus-pallet-aura-ext/try-runtime", + "cumulus-pallet-parachain-system/try-runtime", + "cumulus-pallet-xcm/try-runtime", + "cumulus-pallet-xcmp-queue/try-runtime", + "orml-asset-registry/try-runtime", + "orml-tokens/try-runtime", + "orml-xcm/try-runtime", + "orml-xtokens/try-runtime", + "pallet-anchors/try-runtime", + "pallet-aura/try-runtime", + "pallet-authorship/try-runtime", + "pallet-balances/try-runtime", + "pallet-base-fee/try-runtime", + "pallet-block-rewards/try-runtime", + "pallet-bridge/try-runtime", + "pallet-collator-allowlist/try-runtime", + "pallet-collator-selection/try-runtime", + "pallet-collective/try-runtime", + "pallet-democracy/try-runtime", + "pallet-elections-phragmen/try-runtime", + "pallet-ethereum/try-runtime", + "pallet-ethereum-transaction/try-runtime", + "pallet-evm/try-runtime", + "pallet-evm-chain-id/try-runtime", + "pallet-fees/try-runtime", + "pallet-foreign-investments/try-runtime", + "pallet-identity/try-runtime", + "pallet-interest-accrual/try-runtime", + "pallet-investments/try-runtime", + "pallet-keystore/try-runtime", + "pallet-liquidity-pools/try-runtime", + "pallet-liquidity-pools-gateway/try-runtime", + "pallet-liquidity-rewards/try-runtime", + "pallet-loans/try-runtime", + "pallet-membership/try-runtime", + "pallet-multisig/try-runtime", + "pallet-oracle-collection/try-runtime", + "pallet-oracle-feed/try-runtime", + "pallet-order-book/try-runtime", + "pallet-permissions/try-runtime", + "pallet-pool-fees/try-runtime", + "pallet-pool-registry/try-runtime", + "pallet-pool-system/try-runtime", + "pallet-preimage/try-runtime", + "pallet-proxy/try-runtime", + "pallet-remarks/try-runtime", + "pallet-restricted-tokens/try-runtime", + "pallet-restricted-xtokens/try-runtime", + "pallet-rewards/try-runtime", + "pallet-scheduler/try-runtime", + "pallet-session/try-runtime", + "pallet-sudo/try-runtime", + "pallet-swaps/try-runtime", + "pallet-timestamp/try-runtime", + "pallet-token-mux/try-runtime", + "pallet-transaction-payment/try-runtime", + "pallet-transfer-allowlist/try-runtime", + "pallet-treasury/try-runtime", + "pallet-uniques/try-runtime", + "pallet-utility/try-runtime", + "pallet-vesting/try-runtime", + "pallet-xcm/try-runtime", + "pallet-xcm-transactor/try-runtime", + "pallet-message-queue/try-runtime", + "staging-parachain-info/try-runtime", ] # A feature that should be enabled when the runtime should be build for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller like logging for example. on-chain-release-build = [ - "sp-api/disable-logging", - "runtime-common/on-chain-release-build", + "sp-api/disable-logging", + "runtime-common/on-chain-release-build", ] # Used by integration testing From 8242a0866953c92274abdfc3df86295852e39f01 Mon Sep 17 00:00:00 2001 From: William Freudenberger Date: Tue, 4 Jun 2024 16:33:19 +0200 Subject: [PATCH 2/9] feat: add nuking migration for dev and demo --- runtime/development/Cargo.toml | 560 +++++++++++++------------- runtime/development/src/migrations.rs | 20 + 2 files changed, 300 insertions(+), 280 deletions(-) diff --git a/runtime/development/Cargo.toml b/runtime/development/Cargo.toml index 2b9843f05a..4dc8d84597 100644 --- a/runtime/development/Cargo.toml +++ b/runtime/development/Cargo.toml @@ -145,298 +145,298 @@ substrate-wasm-builder = { workspace = true } default = ["std"] std = [ - "parity-scale-codec/std", - "getrandom/std", - "hex/std", - "log/std", - "scale-info/std", - "serde/std", - # Substrate related - "sp-api/std", - "sp-runtime/std", - "sp-block-builder/std", - "sp-consensus-aura/std", - "sp-core/std", - "sp-genesis-builder/std", - "sp-inherents/std", - "sp-io/std", - "sp-offchain/std", - "sp-session/std", - "sp-std/std", - "sp-transaction-pool/std", - "sp-version/std", - "sp-staking/std", - "frame-support/std", - "frame-system/std", - "frame-system-rpc-runtime-api/std", - "frame-executive/std", - "frame-try-runtime?/std", - "frame-system-benchmarking?/std", - "frame-benchmarking?/std", - "cumulus-primitives-core/std", - "cumulus-primitives-timestamp/std", - "cumulus-primitives-utility/std", - "cumulus-pallet-session-benchmarking?/std", - "staging-xcm/std", - "staging-xcm-builder/std", - "staging-xcm-executor/std", - "xcm-primitives/std", - "orml-traits/std", - "orml-xcm-support/std", - "fp-rpc/std", - "fp-self-contained/std", - "pallet-transaction-payment-rpc-runtime-api/std", - "polkadot-runtime-common/std", - "polkadot-parachain-primitives/std", - # Locals - "cfg-primitives/std", - "cfg-traits/std", - "cfg-types/std", - "runtime-common/std", - "liquidity-pools-gateway-routers/std", - # Pallet list - "axelar-gateway-precompile/std", - "chainbridge/std", - "cumulus-pallet-aura-ext/std", - "cumulus-pallet-parachain-system/std", - "cumulus-pallet-xcm/std", - "cumulus-pallet-xcmp-queue/std", - "orml-asset-registry/std", - "orml-tokens/std", - "orml-xcm/std", - "orml-xtokens/std", - "pallet-anchors/std", - "pallet-aura/std", - "pallet-authorship/std", - "pallet-balances/std", - "pallet-base-fee/std", - "pallet-block-rewards/std", - "pallet-bridge/std", - "pallet-collator-allowlist/std", - "pallet-collator-selection/std", - "pallet-collective/std", - "pallet-democracy/std", - "pallet-elections-phragmen/std", - "pallet-ethereum/std", - "pallet-ethereum-transaction/std", - "pallet-evm/std", - "pallet-evm-chain-id/std", - "pallet-fees/std", - "pallet-foreign-investments/std", - "pallet-identity/std", - "pallet-interest-accrual/std", - "pallet-investments/std", - "pallet-keystore/std", - "pallet-liquidity-pools/std", - "pallet-liquidity-pools-gateway/std", - "pallet-liquidity-rewards/std", - "pallet-loans/std", - "pallet-membership/std", - "pallet-multisig/std", - "pallet-oracle-collection/std", - "pallet-oracle-feed/std", - "pallet-order-book/std", - "pallet-permissions/std", - "pallet-pool-fees/std", - "pallet-pool-registry/std", - "pallet-pool-system/std", - "pallet-preimage/std", - "pallet-proxy/std", - "pallet-remarks/std", - "pallet-restricted-tokens/std", - "pallet-restricted-xtokens/std", - "pallet-rewards/std", - "pallet-scheduler/std", - "pallet-session/std", - "pallet-sudo/std", - "pallet-swaps/std", - "pallet-timestamp/std", - "pallet-token-mux/std", - "pallet-transaction-payment/std", - "pallet-transfer-allowlist/std", - "pallet-treasury/std", - "pallet-uniques/std", - "pallet-utility/std", - "pallet-vesting/std", - "pallet-xcm/std", - "pallet-xcm-transactor/std", - "pallet-message-queue/std", - "staging-parachain-info/std", + "parity-scale-codec/std", + "getrandom/std", + "hex/std", + "log/std", + "scale-info/std", + "serde/std", + # Substrate related + "sp-api/std", + "sp-runtime/std", + "sp-block-builder/std", + "sp-consensus-aura/std", + "sp-core/std", + "sp-genesis-builder/std", + "sp-inherents/std", + "sp-io/std", + "sp-offchain/std", + "sp-session/std", + "sp-std/std", + "sp-transaction-pool/std", + "sp-version/std", + "sp-staking/std", + "frame-support/std", + "frame-system/std", + "frame-system-rpc-runtime-api/std", + "frame-executive/std", + "frame-try-runtime?/std", + "frame-system-benchmarking?/std", + "frame-benchmarking?/std", + "cumulus-primitives-core/std", + "cumulus-primitives-timestamp/std", + "cumulus-primitives-utility/std", + "cumulus-pallet-session-benchmarking?/std", + "staging-xcm/std", + "staging-xcm-builder/std", + "staging-xcm-executor/std", + "xcm-primitives/std", + "orml-traits/std", + "orml-xcm-support/std", + "fp-rpc/std", + "fp-self-contained/std", + "pallet-transaction-payment-rpc-runtime-api/std", + "polkadot-runtime-common/std", + "polkadot-parachain-primitives/std", + # Locals + "cfg-primitives/std", + "cfg-traits/std", + "cfg-types/std", + "runtime-common/std", + "liquidity-pools-gateway-routers/std", + # Pallet list + "axelar-gateway-precompile/std", + "chainbridge/std", + "cumulus-pallet-aura-ext/std", + "cumulus-pallet-parachain-system/std", + "cumulus-pallet-xcm/std", + "cumulus-pallet-xcmp-queue/std", + "orml-asset-registry/std", + "orml-tokens/std", + "orml-xcm/std", + "orml-xtokens/std", + "pallet-anchors/std", + "pallet-aura/std", + "pallet-authorship/std", + "pallet-balances/std", + "pallet-base-fee/std", + "pallet-block-rewards/std", + "pallet-bridge/std", + "pallet-collator-allowlist/std", + "pallet-collator-selection/std", + "pallet-collective/std", + "pallet-democracy/std", + "pallet-elections-phragmen/std", + "pallet-ethereum/std", + "pallet-ethereum-transaction/std", + "pallet-evm/std", + "pallet-evm-chain-id/std", + "pallet-fees/std", + "pallet-foreign-investments/std", + "pallet-identity/std", + "pallet-interest-accrual/std", + "pallet-investments/std", + "pallet-keystore/std", + "pallet-liquidity-pools/std", + "pallet-liquidity-pools-gateway/std", + "pallet-liquidity-rewards/std", + "pallet-loans/std", + "pallet-membership/std", + "pallet-multisig/std", + "pallet-oracle-collection/std", + "pallet-oracle-feed/std", + "pallet-order-book/std", + "pallet-permissions/std", + "pallet-pool-fees/std", + "pallet-pool-registry/std", + "pallet-pool-system/std", + "pallet-preimage/std", + "pallet-proxy/std", + "pallet-remarks/std", + "pallet-restricted-tokens/std", + "pallet-restricted-xtokens/std", + "pallet-rewards/std", + "pallet-scheduler/std", + "pallet-session/std", + "pallet-sudo/std", + "pallet-swaps/std", + "pallet-timestamp/std", + "pallet-token-mux/std", + "pallet-transaction-payment/std", + "pallet-transfer-allowlist/std", + "pallet-treasury/std", + "pallet-uniques/std", + "pallet-utility/std", + "pallet-vesting/std", + "pallet-xcm/std", + "pallet-xcm-transactor/std", + "pallet-message-queue/std", + "staging-parachain-info/std", ] runtime-benchmarks = [ - # Enabling optional - "frame-system-benchmarking/runtime-benchmarks", - "frame-benchmarking/runtime-benchmarks", - "cumulus-pallet-session-benchmarking/runtime-benchmarks", - # Substrate related - "sp-runtime/runtime-benchmarks", - "sp-staking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "staging-xcm-builder/runtime-benchmarks", - "staging-xcm-executor/runtime-benchmarks", - "xcm-primitives/runtime-benchmarks", - "polkadot-runtime-common/runtime-benchmarks", - "polkadot-parachain-primitives/runtime-benchmarks", - # Locals - "cfg-primitives/runtime-benchmarks", - "cfg-traits/runtime-benchmarks", - "cfg-types/runtime-benchmarks", - "runtime-common/runtime-benchmarks", - "liquidity-pools-gateway-routers/runtime-benchmarks", - # Pallet list - "axelar-gateway-precompile/runtime-benchmarks", - "chainbridge/runtime-benchmarks", - "cumulus-pallet-parachain-system/runtime-benchmarks", - "cumulus-pallet-xcmp-queue/runtime-benchmarks", - "orml-asset-registry/runtime-benchmarks", - "orml-tokens/runtime-benchmarks", - "orml-xtokens/runtime-benchmarks", - "pallet-anchors/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "pallet-block-rewards/runtime-benchmarks", - "pallet-bridge/runtime-benchmarks", - "pallet-collator-allowlist/runtime-benchmarks", - "pallet-collator-selection/runtime-benchmarks", - "pallet-collective/runtime-benchmarks", - "pallet-democracy/runtime-benchmarks", - "pallet-elections-phragmen/runtime-benchmarks", - "pallet-ethereum/runtime-benchmarks", - "pallet-ethereum-transaction/runtime-benchmarks", - "pallet-evm/runtime-benchmarks", - "pallet-fees/runtime-benchmarks", - "pallet-foreign-investments/runtime-benchmarks", - "pallet-identity/runtime-benchmarks", - "pallet-interest-accrual/runtime-benchmarks", - "pallet-investments/runtime-benchmarks", - "pallet-keystore/runtime-benchmarks", - "pallet-liquidity-pools/runtime-benchmarks", - "pallet-liquidity-pools-gateway/runtime-benchmarks", - "pallet-liquidity-rewards/runtime-benchmarks", - "pallet-loans/runtime-benchmarks", - "pallet-membership/runtime-benchmarks", - "pallet-multisig/runtime-benchmarks", - "pallet-oracle-collection/runtime-benchmarks", - "pallet-oracle-feed/runtime-benchmarks", - "pallet-order-book/runtime-benchmarks", - "pallet-permissions/runtime-benchmarks", - "pallet-pool-fees/runtime-benchmarks", - "pallet-pool-registry/runtime-benchmarks", - "pallet-pool-system/runtime-benchmarks", - "pallet-preimage/runtime-benchmarks", - "pallet-proxy/runtime-benchmarks", - "pallet-remarks/runtime-benchmarks", - "pallet-restricted-tokens/runtime-benchmarks", - "pallet-restricted-xtokens/runtime-benchmarks", - "pallet-rewards/runtime-benchmarks", - "pallet-scheduler/runtime-benchmarks", - "pallet-sudo/runtime-benchmarks", - "pallet-swaps/runtime-benchmarks", - "pallet-timestamp/runtime-benchmarks", - "pallet-token-mux/runtime-benchmarks", - "pallet-transfer-allowlist/runtime-benchmarks", - "pallet-treasury/runtime-benchmarks", - "pallet-uniques/runtime-benchmarks", - "pallet-utility/runtime-benchmarks", - "pallet-vesting/runtime-benchmarks", - "pallet-xcm/runtime-benchmarks", - "pallet-xcm-transactor/runtime-benchmarks", - "pallet-message-queue/runtime-benchmarks", + # Enabling optional + "frame-system-benchmarking/runtime-benchmarks", + "frame-benchmarking/runtime-benchmarks", + "cumulus-pallet-session-benchmarking/runtime-benchmarks", + # Substrate related + "sp-runtime/runtime-benchmarks", + "sp-staking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "staging-xcm-builder/runtime-benchmarks", + "staging-xcm-executor/runtime-benchmarks", + "xcm-primitives/runtime-benchmarks", + "polkadot-runtime-common/runtime-benchmarks", + "polkadot-parachain-primitives/runtime-benchmarks", + # Locals + "cfg-primitives/runtime-benchmarks", + "cfg-traits/runtime-benchmarks", + "cfg-types/runtime-benchmarks", + "runtime-common/runtime-benchmarks", + "liquidity-pools-gateway-routers/runtime-benchmarks", + # Pallet list + "axelar-gateway-precompile/runtime-benchmarks", + "chainbridge/runtime-benchmarks", + "cumulus-pallet-parachain-system/runtime-benchmarks", + "cumulus-pallet-xcmp-queue/runtime-benchmarks", + "orml-asset-registry/runtime-benchmarks", + "orml-tokens/runtime-benchmarks", + "orml-xtokens/runtime-benchmarks", + "pallet-anchors/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-block-rewards/runtime-benchmarks", + "pallet-bridge/runtime-benchmarks", + "pallet-collator-allowlist/runtime-benchmarks", + "pallet-collator-selection/runtime-benchmarks", + "pallet-collective/runtime-benchmarks", + "pallet-democracy/runtime-benchmarks", + "pallet-elections-phragmen/runtime-benchmarks", + "pallet-ethereum/runtime-benchmarks", + "pallet-ethereum-transaction/runtime-benchmarks", + "pallet-evm/runtime-benchmarks", + "pallet-fees/runtime-benchmarks", + "pallet-foreign-investments/runtime-benchmarks", + "pallet-identity/runtime-benchmarks", + "pallet-interest-accrual/runtime-benchmarks", + "pallet-investments/runtime-benchmarks", + "pallet-keystore/runtime-benchmarks", + "pallet-liquidity-pools/runtime-benchmarks", + "pallet-liquidity-pools-gateway/runtime-benchmarks", + "pallet-liquidity-rewards/runtime-benchmarks", + "pallet-loans/runtime-benchmarks", + "pallet-membership/runtime-benchmarks", + "pallet-multisig/runtime-benchmarks", + "pallet-oracle-collection/runtime-benchmarks", + "pallet-oracle-feed/runtime-benchmarks", + "pallet-order-book/runtime-benchmarks", + "pallet-permissions/runtime-benchmarks", + "pallet-pool-fees/runtime-benchmarks", + "pallet-pool-registry/runtime-benchmarks", + "pallet-pool-system/runtime-benchmarks", + "pallet-preimage/runtime-benchmarks", + "pallet-proxy/runtime-benchmarks", + "pallet-remarks/runtime-benchmarks", + "pallet-restricted-tokens/runtime-benchmarks", + "pallet-restricted-xtokens/runtime-benchmarks", + "pallet-rewards/runtime-benchmarks", + "pallet-scheduler/runtime-benchmarks", + "pallet-sudo/runtime-benchmarks", + "pallet-swaps/runtime-benchmarks", + "pallet-timestamp/runtime-benchmarks", + "pallet-token-mux/runtime-benchmarks", + "pallet-transfer-allowlist/runtime-benchmarks", + "pallet-treasury/runtime-benchmarks", + "pallet-uniques/runtime-benchmarks", + "pallet-utility/runtime-benchmarks", + "pallet-vesting/runtime-benchmarks", + "pallet-xcm/runtime-benchmarks", + "pallet-xcm-transactor/runtime-benchmarks", + "pallet-message-queue/runtime-benchmarks", ] try-runtime = [ - # Enabling optional - "frame-try-runtime/try-runtime", - # Substrate related - "sp-runtime/try-runtime", - "frame-support/try-runtime", - "frame-system/try-runtime", - "frame-executive/try-runtime", - "fp-self-contained/try-runtime", - "polkadot-runtime-common/try-runtime", - # Locals - "cfg-primitives/try-runtime", - "cfg-traits/try-runtime", - "cfg-types/try-runtime", - "runtime-common/try-runtime", - "liquidity-pools-gateway-routers/try-runtime", - # Pallet list - "axelar-gateway-precompile/try-runtime", - "chainbridge/try-runtime", - "cumulus-pallet-aura-ext/try-runtime", - "cumulus-pallet-parachain-system/try-runtime", - "cumulus-pallet-xcm/try-runtime", - "cumulus-pallet-xcmp-queue/try-runtime", - "orml-asset-registry/try-runtime", - "orml-tokens/try-runtime", - "orml-xcm/try-runtime", - "orml-xtokens/try-runtime", - "pallet-anchors/try-runtime", - "pallet-aura/try-runtime", - "pallet-authorship/try-runtime", - "pallet-balances/try-runtime", - "pallet-base-fee/try-runtime", - "pallet-block-rewards/try-runtime", - "pallet-bridge/try-runtime", - "pallet-collator-allowlist/try-runtime", - "pallet-collator-selection/try-runtime", - "pallet-collective/try-runtime", - "pallet-democracy/try-runtime", - "pallet-elections-phragmen/try-runtime", - "pallet-ethereum/try-runtime", - "pallet-ethereum-transaction/try-runtime", - "pallet-evm/try-runtime", - "pallet-evm-chain-id/try-runtime", - "pallet-fees/try-runtime", - "pallet-foreign-investments/try-runtime", - "pallet-identity/try-runtime", - "pallet-interest-accrual/try-runtime", - "pallet-investments/try-runtime", - "pallet-keystore/try-runtime", - "pallet-liquidity-pools/try-runtime", - "pallet-liquidity-pools-gateway/try-runtime", - "pallet-liquidity-rewards/try-runtime", - "pallet-loans/try-runtime", - "pallet-membership/try-runtime", - "pallet-multisig/try-runtime", - "pallet-oracle-collection/try-runtime", - "pallet-oracle-feed/try-runtime", - "pallet-order-book/try-runtime", - "pallet-permissions/try-runtime", - "pallet-pool-fees/try-runtime", - "pallet-pool-registry/try-runtime", - "pallet-pool-system/try-runtime", - "pallet-preimage/try-runtime", - "pallet-proxy/try-runtime", - "pallet-remarks/try-runtime", - "pallet-restricted-tokens/try-runtime", - "pallet-restricted-xtokens/try-runtime", - "pallet-rewards/try-runtime", - "pallet-scheduler/try-runtime", - "pallet-session/try-runtime", - "pallet-sudo/try-runtime", - "pallet-swaps/try-runtime", - "pallet-timestamp/try-runtime", - "pallet-token-mux/try-runtime", - "pallet-transaction-payment/try-runtime", - "pallet-transfer-allowlist/try-runtime", - "pallet-treasury/try-runtime", - "pallet-uniques/try-runtime", - "pallet-utility/try-runtime", - "pallet-vesting/try-runtime", - "pallet-xcm/try-runtime", - "pallet-xcm-transactor/try-runtime", - "pallet-message-queue/try-runtime", - "staging-parachain-info/try-runtime", + # Enabling optional + "frame-try-runtime/try-runtime", + # Substrate related + "sp-runtime/try-runtime", + "frame-support/try-runtime", + "frame-system/try-runtime", + "frame-executive/try-runtime", + "fp-self-contained/try-runtime", + "polkadot-runtime-common/try-runtime", + # Locals + "cfg-primitives/try-runtime", + "cfg-traits/try-runtime", + "cfg-types/try-runtime", + "runtime-common/try-runtime", + "liquidity-pools-gateway-routers/try-runtime", + # Pallet list + "axelar-gateway-precompile/try-runtime", + "chainbridge/try-runtime", + "cumulus-pallet-aura-ext/try-runtime", + "cumulus-pallet-parachain-system/try-runtime", + "cumulus-pallet-xcm/try-runtime", + "cumulus-pallet-xcmp-queue/try-runtime", + "orml-asset-registry/try-runtime", + "orml-tokens/try-runtime", + "orml-xcm/try-runtime", + "orml-xtokens/try-runtime", + "pallet-anchors/try-runtime", + "pallet-aura/try-runtime", + "pallet-authorship/try-runtime", + "pallet-balances/try-runtime", + "pallet-base-fee/try-runtime", + "pallet-block-rewards/try-runtime", + "pallet-bridge/try-runtime", + "pallet-collator-allowlist/try-runtime", + "pallet-collator-selection/try-runtime", + "pallet-collective/try-runtime", + "pallet-democracy/try-runtime", + "pallet-elections-phragmen/try-runtime", + "pallet-ethereum/try-runtime", + "pallet-ethereum-transaction/try-runtime", + "pallet-evm/try-runtime", + "pallet-evm-chain-id/try-runtime", + "pallet-fees/try-runtime", + "pallet-foreign-investments/try-runtime", + "pallet-identity/try-runtime", + "pallet-interest-accrual/try-runtime", + "pallet-investments/try-runtime", + "pallet-keystore/try-runtime", + "pallet-liquidity-pools/try-runtime", + "pallet-liquidity-pools-gateway/try-runtime", + "pallet-liquidity-rewards/try-runtime", + "pallet-loans/try-runtime", + "pallet-membership/try-runtime", + "pallet-multisig/try-runtime", + "pallet-oracle-collection/try-runtime", + "pallet-oracle-feed/try-runtime", + "pallet-order-book/try-runtime", + "pallet-permissions/try-runtime", + "pallet-pool-fees/try-runtime", + "pallet-pool-registry/try-runtime", + "pallet-pool-system/try-runtime", + "pallet-preimage/try-runtime", + "pallet-proxy/try-runtime", + "pallet-remarks/try-runtime", + "pallet-restricted-tokens/try-runtime", + "pallet-restricted-xtokens/try-runtime", + "pallet-rewards/try-runtime", + "pallet-scheduler/try-runtime", + "pallet-session/try-runtime", + "pallet-sudo/try-runtime", + "pallet-swaps/try-runtime", + "pallet-timestamp/try-runtime", + "pallet-token-mux/try-runtime", + "pallet-transaction-payment/try-runtime", + "pallet-transfer-allowlist/try-runtime", + "pallet-treasury/try-runtime", + "pallet-uniques/try-runtime", + "pallet-utility/try-runtime", + "pallet-vesting/try-runtime", + "pallet-xcm/try-runtime", + "pallet-xcm-transactor/try-runtime", + "pallet-message-queue/try-runtime", + "staging-parachain-info/try-runtime", ] # A feature that should be enabled when the runtime should be build for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller like logging for example. on-chain-release-build = [ - "sp-api/disable-logging", - "runtime-common/on-chain-release-build", + "sp-api/disable-logging", + "runtime-common/on-chain-release-build", ] # Used by integration testing diff --git a/runtime/development/src/migrations.rs b/runtime/development/src/migrations.rs index 87e8267783..77d1d0b7ca 100644 --- a/runtime/development/src/migrations.rs +++ b/runtime/development/src/migrations.rs @@ -10,10 +10,26 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. +use cfg_primitives::AccountId; use sp_core::parameter_types; +use sp_std::{vec, vec::Vec}; + parameter_types! { pub const CollatorReward: cfg_primitives::Balance = cfg_primitives::constants::CFG; pub const AnnualTreasuryInflationPercent: u32 = 3; + pub AccountMap: Vec<(AccountId, AccountId)> = vec![ + // // Dev + // ( + // AccountId::new(hex_literal::hex!("31c983bbe38c0210b0186b10e034445d581e2e402d89bb7b56f6469f9766436e")), + // AccountId::new(hex_literal::hex!("31c983bbe38c0210b0186b10e034445d581e2e402d89bb7b56f6469f9766436e")) + // ), + // // Demo + // ( + // AccountId::new(hex_literal::hex!("0d6df5ab3f582f317b4ac3646f0dd4559a6d2de99a739eb5b172d50deb78270a")), + // AccountId::new(hex_literal::hex!("0d6df5ab3f582f317b4ac3646f0dd4559a6d2de99a739eb5b172d50deb78270a")) + // ), + ]; + } // Number of identities on Dev and Demo Chain on 30.05.2024 was both 0 @@ -53,6 +69,10 @@ pub type UpgradeDevelopment1047 = ( CollatorReward, AnnualTreasuryInflationPercent, >, + runtime_common::migrations::restricted_location::MigrateRestrictedTransferLocation< + crate::Runtime, + AccountMap, + >, runtime_common::migrations::loans::AddWithLinearPricing, runtime_common::migrations::hold_reason::MigrateTransferAllowListHolds< crate::Runtime, From 995887e307113c802045f014af23ce4393f8fdae Mon Sep 17 00:00:00 2001 From: William Freudenberger Date: Tue, 4 Jun 2024 16:44:57 +0200 Subject: [PATCH 3/9] fix: remove account list for demo --- runtime/development/src/migrations.rs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/runtime/development/src/migrations.rs b/runtime/development/src/migrations.rs index 77d1d0b7ca..928710c7d7 100644 --- a/runtime/development/src/migrations.rs +++ b/runtime/development/src/migrations.rs @@ -17,18 +17,7 @@ use sp_std::{vec, vec::Vec}; parameter_types! { pub const CollatorReward: cfg_primitives::Balance = cfg_primitives::constants::CFG; pub const AnnualTreasuryInflationPercent: u32 = 3; - pub AccountMap: Vec<(AccountId, AccountId)> = vec![ - // // Dev - // ( - // AccountId::new(hex_literal::hex!("31c983bbe38c0210b0186b10e034445d581e2e402d89bb7b56f6469f9766436e")), - // AccountId::new(hex_literal::hex!("31c983bbe38c0210b0186b10e034445d581e2e402d89bb7b56f6469f9766436e")) - // ), - // // Demo - // ( - // AccountId::new(hex_literal::hex!("0d6df5ab3f582f317b4ac3646f0dd4559a6d2de99a739eb5b172d50deb78270a")), - // AccountId::new(hex_literal::hex!("0d6df5ab3f582f317b4ac3646f0dd4559a6d2de99a739eb5b172d50deb78270a")) - // ), - ]; + pub AccountMap: Vec<(AccountId, AccountId)> = vec![]; } From 8e5c8d57ce5a7a38179164a6c3dd4b48baab2a92 Mon Sep 17 00:00:00 2001 From: William Freudenberger Date: Wed, 5 Jun 2024 14:59:49 +0200 Subject: [PATCH 4/9] refactor: use VersionedLocation --- libs/types/src/locations.rs | 7 +--- pallets/restricted-xtokens/src/lib.rs | 42 ++++++------------- .../src/migrations/restricted_location.rs | 5 ++- runtime/common/src/transfer_filter.rs | 7 ++-- .../src/generic/cases/liquidity_pools.rs | 27 ++++++------ 5 files changed, 33 insertions(+), 55 deletions(-) diff --git a/libs/types/src/locations.rs b/libs/types/src/locations.rs index 5058f52ebd..a5afa93a22 100644 --- a/libs/types/src/locations.rs +++ b/libs/types/src/locations.rs @@ -14,10 +14,7 @@ use cfg_primitives::AccountId; use frame_support::RuntimeDebugNoBound; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; -// Please note that if this version change, -// a migration could be required in those places where -// RestrictedTransferLocation is stored -use staging_xcm::v4::Location; +use staging_xcm::VersionedLocation; use crate::domain_address::DomainAddress; /// Location types for destinations that can receive restricted transfers @@ -26,7 +23,7 @@ pub enum RestrictedTransferLocation { /// Local chain account sending destination. Local(AccountId), /// XCM Location sending destinations. - Xcm(Location), + Xcm(VersionedLocation), /// DomainAddress sending location from a liquidity pools' instance Address(DomainAddress), } diff --git a/pallets/restricted-xtokens/src/lib.rs b/pallets/restricted-xtokens/src/lib.rs index 8ee5e897a0..15f4c1e6ad 100644 --- a/pallets/restricted-xtokens/src/lib.rs +++ b/pallets/restricted-xtokens/src/lib.rs @@ -51,37 +51,37 @@ use staging_xcm::{v4::prelude::*, VersionedAsset, VersionedAssets, VersionedLoca pub enum TransferEffects { Transfer { sender: AccountId, - destination: Location, + destination: VersionedLocation, currency_id: CurrencyId, amount: Balance, }, TransferMultiAsset { sender: AccountId, - destination: Location, + destination: VersionedLocation, asset: Asset, }, TransferWithFee { sender: AccountId, - destination: Location, + destination: VersionedLocation, currency_id: CurrencyId, amount: Balance, fee: Balance, }, TransferMultiAssetWithFee { sender: AccountId, - destination: Location, + destination: VersionedLocation, asset: Asset, fee_asset: Asset, }, TransferMultiCurrencies { sender: AccountId, - destination: Location, + destination: VersionedLocation, currencies: Vec<(CurrencyId, Balance)>, fee: (CurrencyId, Balance), }, TransferMultiAssets { sender: AccountId, - destination: Location, + destination: VersionedLocation, assets: Assets, fee_asset: Asset, }, @@ -130,14 +130,11 @@ pub mod pallet { dest: Box, dest_weight_limit: WeightLimit, ) -> DispatchResult { - let destination: Location = (*dest.clone()) - .try_into() - .map_err(|()| Error::::BadVersion)?; let sender = ensure_signed(origin.clone())?; T::PreTransfer::check(TransferEffects::Transfer { sender, - destination, + destination: (*dest.clone()), currency_id: currency_id.clone(), amount, })?; @@ -175,13 +172,10 @@ pub mod pallet { let multi_asset: Asset = (*asset.clone()) .try_into() .map_err(|()| Error::::BadVersion)?; - let destination: Location = (*dest.clone()) - .try_into() - .map_err(|()| Error::::BadVersion)?; T::PreTransfer::check(TransferEffects::TransferMultiAsset { sender, - destination, + destination: (*dest.clone()), asset: multi_asset, })?; @@ -220,13 +214,10 @@ pub mod pallet { dest_weight_limit: WeightLimit, ) -> DispatchResult { let sender = ensure_signed(origin.clone())?; - let destination: Location = (*dest.clone()) - .try_into() - .map_err(|()| Error::::BadVersion)?; T::PreTransfer::check(TransferEffects::TransferWithFee { sender, - destination, + destination: (*dest.clone()), currency_id: currency_id.clone(), amount, fee, @@ -279,13 +270,10 @@ pub mod pallet { let fee_asset: Asset = (*fee.clone()) .try_into() .map_err(|()| Error::::BadVersion)?; - let destination: Location = (*dest.clone()) - .try_into() - .map_err(|()| Error::::BadVersion)?; T::PreTransfer::check(TransferEffects::TransferMultiAssetWithFee { sender, - destination, + destination: (*dest.clone()), asset: multi_asset, fee_asset, })?; @@ -324,16 +312,13 @@ pub mod pallet { dest_weight_limit: WeightLimit, ) -> DispatchResult { let sender = ensure_signed(origin.clone())?; - let destination: Location = (*dest.clone()) - .try_into() - .map_err(|()| Error::::BadVersion)?; let fee = currencies .get(fee_item as usize) .ok_or(orml_xtokens::Error::::AssetIndexNonExistent)?; T::PreTransfer::check(TransferEffects::TransferMultiCurrencies { sender, - destination, + destination: (*dest.clone()), currencies: currencies.clone(), fee: fee.clone(), })?; @@ -375,16 +360,13 @@ pub mod pallet { let multi_assets: Assets = (*assets.clone()) .try_into() .map_err(|()| Error::::BadVersion)?; - let destination: Location = (*dest.clone()) - .try_into() - .map_err(|()| Error::::BadVersion)?; let fee_asset: &Asset = multi_assets .get(fee_item as usize) .ok_or(orml_xtokens::Error::::AssetIndexNonExistent)?; T::PreTransfer::check(TransferEffects::TransferMultiAssets { sender, - destination, + destination: (*dest.clone()), assets: multi_assets.clone(), fee_asset: fee_asset.clone(), })?; diff --git a/runtime/common/src/migrations/restricted_location.rs b/runtime/common/src/migrations/restricted_location.rs index d230193d8e..26c594c9b4 100644 --- a/runtime/common/src/migrations/restricted_location.rs +++ b/runtime/common/src/migrations/restricted_location.rs @@ -10,7 +10,7 @@ use sp_arithmetic::traits::SaturatedConversion; use sp_core::H256; use sp_runtime::traits::{BlakeTwo256, Hash}; use sp_std::vec::Vec; -use staging_xcm::v4; +use staging_xcm::{v4, VersionedLocation}; mod old { use cfg_primitives::AccountId; @@ -158,7 +158,8 @@ where match v4::Location::try_from(old_location) { Ok(location) => { log::info!("{LOG_PREFIX} Hash: '{hash}' migrated!"); - let new_restricted_location = RestrictedTransferLocation::Xcm(location); + let new_restricted_location = + RestrictedTransferLocation::Xcm(VersionedLocation::V4(location)); Some(new_restricted_location) } diff --git a/runtime/common/src/transfer_filter.rs b/runtime/common/src/transfer_filter.rs index 8fbded3a47..ee497e492e 100644 --- a/runtime/common/src/transfer_filter.rs +++ b/runtime/common/src/transfer_filter.rs @@ -29,6 +29,7 @@ use sp_runtime::{ }; use sp_std::vec::Vec; use staging_xcm::v4::{Asset, Location}; +use staging_xcm::VersionedLocation; pub struct PreXcmTransfer(sp_std::marker::PhantomData<(T, C)>); @@ -44,7 +45,7 @@ impl< type Result = DispatchResult; fn check(t: TransferEffects) -> Self::Result { - let currency_based_check = |sender: AccountId, destination: Location, currency| { + let currency_based_check = |sender: AccountId, destination: VersionedLocation, currency| { amalgamate_allowance( T::allowance( sender.clone(), @@ -60,8 +61,8 @@ impl< }; let asset_based_check = |sender, destination, asset: Asset| { - let currency = - C::convert(asset.id.0).ok_or(DispatchError::Token(TokenError::UnknownAsset))?; + let currency = C::convert(asset.id.0.into()) + .ok_or(DispatchError::Token(TokenError::UnknownAsset))?; currency_based_check(sender, destination, currency) }; diff --git a/runtime/integration-tests/src/generic/cases/liquidity_pools.rs b/runtime/integration-tests/src/generic/cases/liquidity_pools.rs index 7ec36fb6c1..286b2d8ae6 100644 --- a/runtime/integration-tests/src/generic/cases/liquidity_pools.rs +++ b/runtime/integration-tests/src/generic/cases/liquidity_pools.rs @@ -6689,8 +6689,8 @@ mod centrifuge { const TRANSFER_AMOUNT: u128 = 10; - fn xcm_location() -> Location { - Location::new( + fn xcm_location() -> VersionedLocation { + VersionedLocation::v4::new( 1, AccountId32 { id: Keyring::Alice.into(), @@ -6700,7 +6700,7 @@ mod centrifuge { } fn allowed_xcm_location() -> RestrictedTransferLocation { - RestrictedTransferLocation::Xcm(BlakeTwo256::hash(&xcm_location().encode())) + RestrictedTransferLocation::Xcm(xcm_location()) } fn add_allowance( @@ -7220,18 +7220,15 @@ mod centrifuge { pallet_transfer_allowlist::Pallet::::add_transfer_allowance( RawOrigin::Signed(Keyring::Alice.into()).into(), FilterCurrency::Specific(USDC), - RestrictedTransferLocation::Xcm(BlakeTwo256::hash( - &Location::new( - 1, - [ - Parachain(T::FudgeHandle::SIBLING_ID), - Junction::AccountId32 { - id: Keyring::Alice.into(), - network: None, - } - ] - ) - .encode() + RestrictedTransferLocation::Xcm(VersionedLocation::v4::new( + 1, + [ + Parachain(T::FudgeHandle::SIBLING_ID), + Junction::AccountId32 { + id: Keyring::Alice.into(), + network: None, + } + ] )) ) ); From 1f4c2d7dc88694212405b2deb6b8f58fd7a95b66 Mon Sep 17 00:00:00 2001 From: William Freudenberger Date: Wed, 5 Jun 2024 17:43:42 +0200 Subject: [PATCH 5/9] fix: transfer allowlist benchmarks + tests --- .../transfer-allowlist/src/benchmarking.rs | 317 ++++++++++++++---- pallets/transfer-allowlist/src/mock.rs | 51 +-- pallets/transfer-allowlist/src/tests.rs | 84 +++-- 3 files changed, 319 insertions(+), 133 deletions(-) diff --git a/pallets/transfer-allowlist/src/benchmarking.rs b/pallets/transfer-allowlist/src/benchmarking.rs index 724b692198..81ccb725ec 100644 --- a/pallets/transfer-allowlist/src/benchmarking.rs +++ b/pallets/transfer-allowlist/src/benchmarking.rs @@ -12,14 +12,17 @@ #![cfg(feature = "runtime-benchmarks")] -use cfg_types::tokens::{CurrencyId, FilterCurrency}; -use frame_benchmarking::*; +use cfg_types::{ + locations::RestrictedTransferLocation, + tokens::{CurrencyId, FilterCurrency}, +}; +use frame_benchmarking::{account, v2::*}; use frame_support::{ pallet_prelude::Get, traits::{fungible::Unbalanced, tokens::Precision, Currency, ReservableCurrency}, }; use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin}; -use parity_scale_codec::EncodeLike; +use sp_core::crypto::AccountId32; use sp_runtime::{ traits::{CheckedAdd, One}, Saturating, @@ -29,105 +32,282 @@ use super::*; const BENCHMARK_CURRENCY_ID: FilterCurrency = FilterCurrency::Specific(CurrencyId::ForeignAsset(1)); -benchmarks! { - where_clause { - where - ::AccountId: Into<::Location>, - ::Location: From<::AccountId> + EncodeLike<::Location>, - ::ReserveCurrency: Currency<::AccountId> + ReservableCurrency<::AccountId>, - T: pallet::Config, - BlockNumberFor: One, - <::ReserveCurrency as frame_support::traits::fungible::Inspect<::AccountId,>>::Balance: From - } +#[benchmarks( +where + T: Config, + ::AccountId: Into, + T::ReserveCurrency: Currency<::AccountId> + ReservableCurrency<::AccountId>, + BlockNumberFor: One, + <::ReserveCurrency as frame_support::traits::fungible::Inspect<::AccountId,>>::Balance: From +)] +mod benchmarks { + use super::*; - add_transfer_allowance_no_existing_metadata { + #[benchmark] + fn add_transfer_allowance_no_existing_metadata() -> Result<(), BenchmarkError> { let (sender, receiver) = set_up_users::(); - }:add_transfer_allowance(RawOrigin::Signed(sender.clone()), BENCHMARK_CURRENCY_ID, receiver.clone().into()) + #[extrinsic_call] + add_transfer_allowance( + RawOrigin::Signed(sender), + BENCHMARK_CURRENCY_ID, + default_location::(receiver), + ); - add_transfer_allowance_existing_metadata { - let (sender, receiver) = set_up_users::(); - Pallet::::add_allowance_delay(RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID, 200u32.into())?; - }:add_transfer_allowance(RawOrigin::Signed(sender.clone()), BENCHMARK_CURRENCY_ID, receiver.clone().into()) + Ok(()) + } - add_allowance_delay_no_existing_metadata { + #[benchmark] + fn add_transfer_allowance_existing_metadata() -> Result<(), BenchmarkError> { let (sender, receiver) = set_up_users::(); - }:add_allowance_delay(RawOrigin::Signed(sender.clone()), BENCHMARK_CURRENCY_ID, 200u32.into()) + Pallet::::add_allowance_delay( + RawOrigin::Signed(sender.clone()).into(), + BENCHMARK_CURRENCY_ID, + 200u32.into(), + )?; - add_allowance_delay_existing_metadata { - let (sender, receiver) = set_up_users::(); - Pallet::::add_transfer_allowance(RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID, receiver.clone().into())?; - }:add_allowance_delay(RawOrigin::Signed(sender.clone()), BENCHMARK_CURRENCY_ID, 200u32.into()) + #[extrinsic_call] + add_transfer_allowance( + RawOrigin::Signed(sender), + BENCHMARK_CURRENCY_ID, + default_location::(receiver), + ); + Ok(()) + } + #[benchmark] + fn add_allowance_delay_no_existing_metadata() -> Result<(), BenchmarkError> { + let (sender, _) = set_up_users::(); - toggle_allowance_delay_once_future_modifiable { - let (sender, receiver) = set_up_users::(); - Pallet::::add_allowance_delay(RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID, 1u32.into())?; - }:toggle_allowance_delay_once_future_modifiable(RawOrigin::Signed(sender.clone()), BENCHMARK_CURRENCY_ID) + #[extrinsic_call] + add_allowance_delay( + RawOrigin::Signed(sender), + BENCHMARK_CURRENCY_ID, + 200u32.into(), + ); - update_allowance_delay { + Ok(()) + } + #[benchmark] + fn add_allowance_delay_existing_metadata() -> Result<(), BenchmarkError> { let (sender, receiver) = set_up_users::(); - Pallet::::add_allowance_delay(RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID, 1u32.into())?; - Pallet::::toggle_allowance_delay_once_future_modifiable(RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID)?; + Pallet::::add_transfer_allowance( + RawOrigin::Signed(sender.clone()).into(), + BENCHMARK_CURRENCY_ID, + default_location::(receiver), + )?; + + #[extrinsic_call] + add_allowance_delay( + RawOrigin::Signed(sender), + BENCHMARK_CURRENCY_ID, + 200u32.into(), + ); + + Ok(()) + } + + #[benchmark] + fn toggle_allowance_delay_once_future_modifiable() -> Result<(), BenchmarkError> { + let (sender, _) = set_up_users::(); + Pallet::::add_allowance_delay( + RawOrigin::Signed(sender.clone()).into(), + BENCHMARK_CURRENCY_ID, + 1u32.into(), + )?; + + #[extrinsic_call] + toggle_allowance_delay_once_future_modifiable( + RawOrigin::Signed(sender), + BENCHMARK_CURRENCY_ID, + ); + + Ok(()) + } + + #[benchmark] + fn update_allowance_delay() -> Result<(), BenchmarkError> { + let (sender, _) = set_up_users::(); + Pallet::::add_allowance_delay( + RawOrigin::Signed(sender.clone()).into(), + BENCHMARK_CURRENCY_ID, + 1u32.into(), + )?; + Pallet::::toggle_allowance_delay_once_future_modifiable( + RawOrigin::Signed(sender.clone()).into(), + BENCHMARK_CURRENCY_ID, + )?; let b = frame_system::Pallet::::block_number() - .checked_add(&1u32.into()) - .expect("Mock block advancement failed."); + .checked_add(&1u32.into()) + .expect("Mock block advancement failed."); frame_system::Pallet::::set_block_number(b); - }:update_allowance_delay(RawOrigin::Signed(sender.clone()), BENCHMARK_CURRENCY_ID, 200u32.into()) - purge_allowance_delay_no_remaining_metadata { - let (sender, receiver) = set_up_users::(); - Pallet::::add_allowance_delay(RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID, 1u32.into())?; - Pallet::::toggle_allowance_delay_once_future_modifiable(RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID)?; + #[extrinsic_call] + update_allowance_delay( + RawOrigin::Signed(sender), + BENCHMARK_CURRENCY_ID, + 200u32.into(), + ); + + Ok(()) + } + + #[benchmark] + fn purge_allowance_delay_no_remaining_metadata() -> Result<(), BenchmarkError> { + let (sender, _) = set_up_users::(); + Pallet::::add_allowance_delay( + RawOrigin::Signed(sender.clone()).into(), + BENCHMARK_CURRENCY_ID, + 1u32.into(), + )?; + Pallet::::toggle_allowance_delay_once_future_modifiable( + RawOrigin::Signed(sender.clone()).into(), + BENCHMARK_CURRENCY_ID, + )?; let b = frame_system::Pallet::::block_number() - .checked_add(&2u32.into()) - .expect("Mock block advancement failed."); + .checked_add(&2u32.into()) + .expect("Mock block advancement failed."); frame_system::Pallet::::set_block_number(b); - }:purge_allowance_delay(RawOrigin::Signed(sender.clone()), BENCHMARK_CURRENCY_ID) - purge_allowance_delay_remaining_metadata { + #[extrinsic_call] + purge_allowance_delay(RawOrigin::Signed(sender), BENCHMARK_CURRENCY_ID); + + Ok(()) + } + + #[benchmark] + fn purge_allowance_delay_remaining_metadata() -> Result<(), BenchmarkError> { let (sender, receiver) = set_up_users::(); - Pallet::::add_allowance_delay(RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID, 1u32.into())?; - Pallet::::add_transfer_allowance(RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID, receiver.clone().into())?; - Pallet::::toggle_allowance_delay_once_future_modifiable(RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID)?; + Pallet::::add_allowance_delay( + RawOrigin::Signed(sender.clone()).into(), + BENCHMARK_CURRENCY_ID, + 1u32.into(), + )?; + Pallet::::add_transfer_allowance( + RawOrigin::Signed(sender.clone()).into(), + BENCHMARK_CURRENCY_ID, + default_location::(receiver), + )?; + Pallet::::toggle_allowance_delay_once_future_modifiable( + RawOrigin::Signed(sender.clone()).into(), + BENCHMARK_CURRENCY_ID, + )?; let b = frame_system::Pallet::::block_number() - .checked_add(&2u32.into()) - .expect("Mock block advancement failed."); + .checked_add(&2u32.into()) + .expect("Mock block advancement failed."); frame_system::Pallet::::set_block_number(b); - }:purge_allowance_delay(RawOrigin::Signed(sender.clone()), BENCHMARK_CURRENCY_ID) + #[extrinsic_call] + purge_allowance_delay(RawOrigin::Signed(sender), BENCHMARK_CURRENCY_ID); + + Ok(()) + } - remove_transfer_allowance_delay_present { + #[benchmark] + fn remove_transfer_allowance_delay_present() -> Result<(), BenchmarkError> { let (sender, receiver) = set_up_users::(); let delay = BlockNumberFor::::one(); - Pallet::::add_allowance_delay(RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID, delay.clone())?; - Pallet::::add_transfer_allowance(RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID, receiver.clone().into())?; + Pallet::::add_allowance_delay( + RawOrigin::Signed(sender.clone()).into(), + BENCHMARK_CURRENCY_ID, + delay.clone(), + )?; + Pallet::::add_transfer_allowance( + RawOrigin::Signed(sender.clone()).into(), + BENCHMARK_CURRENCY_ID, + default_location::(receiver.clone()), + )?; let b = frame_system::Pallet::::block_number() .checked_add(&1u32.into()) .expect("Mock block advancement failed."); frame_system::Pallet::::set_block_number(b); - }:remove_transfer_allowance(RawOrigin::Signed(sender.clone()), BENCHMARK_CURRENCY_ID, receiver.clone().into()) - remove_transfer_allowance_no_delay { + #[extrinsic_call] + remove_transfer_allowance( + RawOrigin::Signed(sender), + BENCHMARK_CURRENCY_ID, + default_location::(receiver), + ); + + Ok(()) + } + + #[benchmark] + fn remove_transfer_allowance_no_delay() -> Result<(), BenchmarkError> { let (sender, receiver) = set_up_users::(); - Pallet::::add_transfer_allowance(RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID, receiver.clone().into())?; - }:remove_transfer_allowance(RawOrigin::Signed(sender.clone()), BENCHMARK_CURRENCY_ID, receiver.clone().into()) + Pallet::::add_transfer_allowance( + RawOrigin::Signed(sender.clone()).into(), + BENCHMARK_CURRENCY_ID, + default_location::(receiver.clone()), + )?; + + #[extrinsic_call] + remove_transfer_allowance( + RawOrigin::Signed(sender), + BENCHMARK_CURRENCY_ID, + default_location::(receiver), + ); - purge_transfer_allowance_no_remaining_metadata { + Ok(()) + } + + #[benchmark] + fn purge_transfer_allowance_no_remaining_metadata() -> Result<(), BenchmarkError> { let (sender, receiver) = set_up_users::(); - Pallet::::add_transfer_allowance(RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID, receiver.clone().into())?; - Pallet::::remove_transfer_allowance(RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID, receiver.clone().into())?; - }:purge_transfer_allowance(RawOrigin::Signed(sender.clone()), BENCHMARK_CURRENCY_ID, receiver.clone().into()) + Pallet::::add_transfer_allowance( + RawOrigin::Signed(sender.clone()).into(), + BENCHMARK_CURRENCY_ID, + default_location::(receiver.clone()), + )?; + Pallet::::remove_transfer_allowance( + RawOrigin::Signed(sender.clone()).into(), + BENCHMARK_CURRENCY_ID, + default_location::(receiver.clone()), + )?; + + #[extrinsic_call] + purge_transfer_allowance( + RawOrigin::Signed(sender), + BENCHMARK_CURRENCY_ID, + default_location::(receiver.clone()), + ); + + Ok(()) + } - purge_transfer_allowance_remaining_metadata { + #[benchmark] + fn purge_transfer_allowance_remaining_metadata() -> Result<(), BenchmarkError> { let (sender, receiver) = set_up_users::(); let receiver_1 = set_up_second_receiver::(); - Pallet::::add_transfer_allowance(RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID, receiver.clone().into())?; - Pallet::::add_transfer_allowance(RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID, receiver_1.clone().into())?; - Pallet::::remove_transfer_allowance(RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID, receiver.clone().into())?; - }:purge_transfer_allowance(RawOrigin::Signed(sender.clone()), BENCHMARK_CURRENCY_ID, receiver.clone().into()) + Pallet::::add_transfer_allowance( + RawOrigin::Signed(sender.clone()).into(), + BENCHMARK_CURRENCY_ID, + default_location::(receiver.clone()), + )?; + Pallet::::add_transfer_allowance( + RawOrigin::Signed(sender.clone()).into(), + BENCHMARK_CURRENCY_ID, + default_location::(receiver_1.clone()), + )?; + Pallet::::remove_transfer_allowance( + RawOrigin::Signed(sender.clone()).into(), + BENCHMARK_CURRENCY_ID, + default_location::(receiver.clone()), + )?; + + #[extrinsic_call] + purge_transfer_allowance( + RawOrigin::Signed(sender), + BENCHMARK_CURRENCY_ID, + default_location::(receiver), + ); + + Ok(()) + } + + impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Runtime); } fn set_up_users() -> (T::AccountId, T::AccountId) @@ -153,4 +333,9 @@ fn set_up_second_receiver() -> T::AccountId { account::("Receiver_1", 3, 0) } -impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Runtime); +fn default_location(receiver: T::AccountId) -> RestrictedTransferLocation +where + ::AccountId: Into, +{ + RestrictedTransferLocation::Local(receiver.into()) +} diff --git a/pallets/transfer-allowlist/src/mock.rs b/pallets/transfer-allowlist/src/mock.rs index 4838949396..22fb0a0785 100644 --- a/pallets/transfer-allowlist/src/mock.rs +++ b/pallets/transfer-allowlist/src/mock.rs @@ -10,19 +10,22 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -use cfg_types::tokens::FilterCurrency; -use frame_support::{derive_impl, traits::ConstU64, Deserialize, Serialize}; +use cfg_types::{locations::RestrictedTransferLocation, tokens::FilterCurrency}; +use frame_support::{derive_impl, traits::ConstU64}; use frame_system::pallet_prelude::BlockNumberFor; -use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; -use scale_info::TypeInfo; -use sp_runtime::{traits::CheckedAdd, BuildStorage}; +use sp_core::crypto::AccountId32; +use sp_runtime::{ + traits::{CheckedAdd, IdentityLookup}, + BuildStorage, +}; use crate as transfer_allowlist; pub(crate) const STARTING_BLOCK: u64 = 50; -pub(crate) const SENDER: u64 = 0x1; -pub(crate) const ACCOUNT_RECEIVER: u64 = 0x2; -pub(crate) const FEE_DEFICIENT_SENDER: u64 = 0x3; +pub(crate) const SENDER: AccountId32 = AccountId32::new([1u8; 32]); +pub(crate) const ACCOUNT_RECEIVER: AccountId32 = AccountId32::new([2u8; 32]); +pub(crate) const FEE_DEFICIENT_SENDER: AccountId32 = AccountId32::new([3u8; 32]); +pub(crate) const OTHER_RECEIVER: AccountId32 = AccountId32::new([100u8; 32]); type Balance = u64; @@ -37,31 +40,9 @@ frame_support::construct_runtime!( #[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] impl frame_system::Config for Runtime { type AccountData = pallet_balances::AccountData; + type AccountId = AccountId32; type Block = frame_system::mocking::MockBlock; -} - -#[derive( - Clone, - Debug, - PartialOrd, - Ord, - Encode, - Decode, - Eq, - PartialEq, - MaxEncodedLen, - TypeInfo, - Deserialize, - Serialize, -)] -pub enum Location { - TestLocal(u64), -} - -impl From for Location { - fn from(a: u64) -> Self { - Self::TestLocal(a) - } + type Lookup = IdentityLookup; } #[derive_impl(pallet_balances::config_preludes::TestDefaultConfig as pallet_balances::DefaultConfig)] @@ -72,13 +53,17 @@ impl pallet_balances::Config for Runtime { impl transfer_allowlist::Config for Runtime { type CurrencyId = FilterCurrency; type Deposit = ConstU64<10>; - type Location = Location; + type Location = RestrictedTransferLocation; type ReserveCurrency = Balances; type RuntimeEvent = RuntimeEvent; type RuntimeHoldReason = RuntimeHoldReason; type WeightInfo = (); } +pub(crate) fn local_location(receiver: AccountId32) -> RestrictedTransferLocation { + RestrictedTransferLocation::Local(receiver) +} + pub fn new_test_ext() -> sp_io::TestExternalities { let mut t = frame_system::GenesisConfig::::default() .build_storage() diff --git a/pallets/transfer-allowlist/src/tests.rs b/pallets/transfer-allowlist/src/tests.rs index dfd603a641..c6e4eb0eb1 100644 --- a/pallets/transfer-allowlist/src/tests.rs +++ b/pallets/transfer-allowlist/src/tests.rs @@ -12,13 +12,13 @@ fn add_transfer_allowance_works() { assert_ok!(TransferAllowList::add_transfer_allowance( RuntimeOrigin::signed(SENDER), TEST_CURRENCY_ID, - ACCOUNT_RECEIVER.into(), + local_location(ACCOUNT_RECEIVER) )); assert_eq!( TransferAllowList::get_account_currency_transfer_allowance(( SENDER, TEST_CURRENCY_ID, - ::Location::from(ACCOUNT_RECEIVER) + local_location(ACCOUNT_RECEIVER) )) .unwrap(), AllowanceDetails { @@ -48,7 +48,7 @@ fn add_transfer_allowance_updates_with_delay_set() { assert_ok!(TransferAllowList::add_transfer_allowance( RuntimeOrigin::signed(SENDER), TEST_CURRENCY_ID, - ACCOUNT_RECEIVER.into(), + local_location(ACCOUNT_RECEIVER) )); assert_ok!(TransferAllowList::add_allowance_delay( RuntimeOrigin::signed(SENDER), @@ -58,7 +58,7 @@ fn add_transfer_allowance_updates_with_delay_set() { assert_ok!(TransferAllowList::add_transfer_allowance( RuntimeOrigin::signed(SENDER), TEST_CURRENCY_ID, - ACCOUNT_RECEIVER.into(), + local_location(ACCOUNT_RECEIVER) ),); // only one allowance has been created, should still only have 1 reserve @@ -67,7 +67,7 @@ fn add_transfer_allowance_updates_with_delay_set() { TransferAllowList::get_account_currency_transfer_allowance(( SENDER, TEST_CURRENCY_ID, - ::Location::from(ACCOUNT_RECEIVER) + local_location(ACCOUNT_RECEIVER) )) .unwrap(), AllowanceDetails { @@ -98,13 +98,13 @@ fn add_transfer_allowance_multiple_dests_increments_correctly() { assert_ok!(TransferAllowList::add_transfer_allowance( RuntimeOrigin::signed(SENDER), TEST_CURRENCY_ID, - ACCOUNT_RECEIVER.into(), + local_location(ACCOUNT_RECEIVER) )); assert_eq!(Balances::reserved_balance(&SENDER), 10); assert_ok!(TransferAllowList::add_transfer_allowance( RuntimeOrigin::signed(SENDER), TEST_CURRENCY_ID, - 100u64.into(), + local_location(OTHER_RECEIVER), )); // verify reserve incremented for second allowance assert_eq!(Balances::reserved_balance(&SENDER), 20); @@ -128,11 +128,15 @@ fn transfer_allowance_allows_correctly_with_allowance_set() { assert_ok!(TransferAllowList::add_transfer_allowance( RuntimeOrigin::signed(SENDER), TEST_CURRENCY_ID, - ACCOUNT_RECEIVER.into(), + local_location(ACCOUNT_RECEIVER) )); assert_eq!( - TransferAllowList::allowance(SENDER.into(), ACCOUNT_RECEIVER.into(), TEST_CURRENCY_ID), - Ok(Some(ACCOUNT_RECEIVER.into())) + TransferAllowList::allowance( + SENDER.into(), + local_location(ACCOUNT_RECEIVER), + TEST_CURRENCY_ID + ), + Ok(Some(local_location(ACCOUNT_RECEIVER))) ) }) } @@ -143,10 +147,14 @@ fn transfer_allowance_blocks_when_account_not_allowed() { assert_ok!(TransferAllowList::add_transfer_allowance( RuntimeOrigin::signed(SENDER), TEST_CURRENCY_ID, - ACCOUNT_RECEIVER.into(), + local_location(ACCOUNT_RECEIVER) )); assert_err!( - TransferAllowList::allowance(SENDER.into(), 55u64.into(), TEST_CURRENCY_ID), + TransferAllowList::allowance( + SENDER.into(), + local_location(OTHER_RECEIVER), + TEST_CURRENCY_ID + ), Error::::NoAllowanceForDestination, ) }) @@ -164,10 +172,14 @@ fn transfer_allowance_blocks_correctly_when_before_start_block() { assert_ok!(TransferAllowList::add_transfer_allowance( RuntimeOrigin::signed(SENDER), TEST_CURRENCY_ID, - ACCOUNT_RECEIVER.into(), + local_location(ACCOUNT_RECEIVER) )); assert_err!( - TransferAllowList::allowance(SENDER.into(), ACCOUNT_RECEIVER.into(), TEST_CURRENCY_ID), + TransferAllowList::allowance( + SENDER.into(), + local_location(ACCOUNT_RECEIVER), + TEST_CURRENCY_ID + ), Error::::NoAllowanceForDestination, ) }) @@ -179,11 +191,15 @@ fn transfer_allowance_blocks_correctly_when_after_blocked_at_block() { assert_ok!(TransferAllowList::add_transfer_allowance( RuntimeOrigin::signed(SENDER), TEST_CURRENCY_ID, - ACCOUNT_RECEIVER.into(), + local_location(ACCOUNT_RECEIVER) )); assert_eq!( - TransferAllowList::allowance(SENDER.into(), ACCOUNT_RECEIVER.into(), TEST_CURRENCY_ID), - Ok(Some(ACCOUNT_RECEIVER.into())) + TransferAllowList::allowance( + SENDER.into(), + local_location(ACCOUNT_RECEIVER), + TEST_CURRENCY_ID + ), + Ok(Some(local_location(ACCOUNT_RECEIVER))) ) }) } @@ -194,19 +210,19 @@ fn remove_transfer_allowance_works() { assert_ok!(TransferAllowList::add_transfer_allowance( RuntimeOrigin::signed(SENDER), TEST_CURRENCY_ID, - ACCOUNT_RECEIVER.into(), + local_location(ACCOUNT_RECEIVER) )); assert_ok!(TransferAllowList::remove_transfer_allowance( RuntimeOrigin::signed(SENDER), TEST_CURRENCY_ID, - ACCOUNT_RECEIVER.into(), + local_location(ACCOUNT_RECEIVER) )); // ensure blocked at set to restrict transfers assert_eq!( TransferAllowList::get_account_currency_transfer_allowance(( SENDER, TEST_CURRENCY_ID, - ::Location::from(ACCOUNT_RECEIVER) + local_location(ACCOUNT_RECEIVER) )) .unwrap(), AllowanceDetails { @@ -241,7 +257,7 @@ fn remove_transfer_allowance_with_delay_works() { assert_ok!(TransferAllowList::add_transfer_allowance( RuntimeOrigin::signed(SENDER), TEST_CURRENCY_ID, - ACCOUNT_RECEIVER.into(), + local_location(ACCOUNT_RECEIVER) )); assert_ok!(TransferAllowList::add_allowance_delay( RuntimeOrigin::signed(SENDER), @@ -251,13 +267,13 @@ fn remove_transfer_allowance_with_delay_works() { assert_ok!(TransferAllowList::remove_transfer_allowance( RuntimeOrigin::signed(SENDER), TEST_CURRENCY_ID, - ACCOUNT_RECEIVER.into(), + local_location(ACCOUNT_RECEIVER) )); assert_eq!( TransferAllowList::get_account_currency_transfer_allowance(( SENDER, TEST_CURRENCY_ID, - ::Location::from(ACCOUNT_RECEIVER) + local_location(ACCOUNT_RECEIVER) )) .unwrap(), AllowanceDetails { @@ -298,12 +314,12 @@ fn purge_transfer_allowance_works() { assert_ok!(TransferAllowList::add_transfer_allowance( RuntimeOrigin::signed(SENDER), TEST_CURRENCY_ID, - ACCOUNT_RECEIVER.into(), + local_location(ACCOUNT_RECEIVER) )); assert_ok!(TransferAllowList::remove_transfer_allowance( RuntimeOrigin::signed(SENDER), TEST_CURRENCY_ID, - ACCOUNT_RECEIVER.into(), + local_location(ACCOUNT_RECEIVER) )); assert_eq!(Balances::reserved_balance(&SENDER), 10); advance_n_blocks::(6u64); @@ -312,14 +328,14 @@ fn purge_transfer_allowance_works() { assert_ok!(TransferAllowList::purge_transfer_allowance( RuntimeOrigin::signed(SENDER), TEST_CURRENCY_ID, - ACCOUNT_RECEIVER.into(), + local_location(ACCOUNT_RECEIVER) )); // verify removed assert_eq!( TransferAllowList::get_account_currency_transfer_allowance(( SENDER, TEST_CURRENCY_ID, - ::Location::from(ACCOUNT_RECEIVER) + local_location(ACCOUNT_RECEIVER) )), None ); @@ -349,7 +365,7 @@ fn purge_transfer_allowance_non_existant_transfer_allowance() { TransferAllowList::purge_transfer_allowance( RuntimeOrigin::signed(SENDER), TEST_CURRENCY_ID, - ACCOUNT_RECEIVER.into(), + local_location(ACCOUNT_RECEIVER) ), Error::::NoMatchingAllowance ); @@ -369,20 +385,20 @@ fn purge_transfer_allowance_when_multiple_present_for_sender_currency_properly_d assert_ok!(TransferAllowList::add_transfer_allowance( RuntimeOrigin::signed(SENDER), TEST_CURRENCY_ID, - ACCOUNT_RECEIVER.into(), + local_location(ACCOUNT_RECEIVER) )); assert_eq!(Balances::reserved_balance(&SENDER), 10); assert_ok!(TransferAllowList::add_transfer_allowance( RuntimeOrigin::signed(SENDER), TEST_CURRENCY_ID, - 100u64.into(), + local_location(OTHER_RECEIVER), )); assert_eq!(Balances::reserved_balance(&SENDER), 20); assert_ok!(TransferAllowList::remove_transfer_allowance( RuntimeOrigin::signed(SENDER), TEST_CURRENCY_ID, - ACCOUNT_RECEIVER.into(), + local_location(ACCOUNT_RECEIVER) )); advance_n_blocks::(6u64); @@ -391,7 +407,7 @@ fn purge_transfer_allowance_when_multiple_present_for_sender_currency_properly_d assert_ok!(TransferAllowList::purge_transfer_allowance( RuntimeOrigin::signed(SENDER), TEST_CURRENCY_ID, - ACCOUNT_RECEIVER.into(), + local_location(ACCOUNT_RECEIVER) )); // verify correct reserve decrement @@ -402,7 +418,7 @@ fn purge_transfer_allowance_when_multiple_present_for_sender_currency_properly_d TransferAllowList::get_account_currency_transfer_allowance(( SENDER, TEST_CURRENCY_ID, - ::Location::from(ACCOUNT_RECEIVER) + local_location(ACCOUNT_RECEIVER) )), None ); @@ -412,7 +428,7 @@ fn purge_transfer_allowance_when_multiple_present_for_sender_currency_properly_d TransferAllowList::get_account_currency_transfer_allowance(( SENDER, TEST_CURRENCY_ID, - ::Location::from(100u64) + local_location(OTHER_RECEIVER) )) .unwrap(), AllowanceDetails { From 0c0d53d19f741a247652d145b68bdf53c7b89a8c Mon Sep 17 00:00:00 2001 From: William Freudenberger Date: Wed, 5 Jun 2024 17:44:03 +0200 Subject: [PATCH 6/9] fix: clippy --- libs/types/src/locations.rs | 3 ++- .../common/src/migrations/restricted_location.rs | 2 +- runtime/common/src/transfer_filter.rs | 14 ++++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/libs/types/src/locations.rs b/libs/types/src/locations.rs index a5afa93a22..3030d3011e 100644 --- a/libs/types/src/locations.rs +++ b/libs/types/src/locations.rs @@ -17,13 +17,14 @@ use scale_info::TypeInfo; use staging_xcm::VersionedLocation; use crate::domain_address::DomainAddress; + /// Location types for destinations that can receive restricted transfers #[derive(Clone, RuntimeDebugNoBound, Encode, Decode, Eq, PartialEq, MaxEncodedLen, TypeInfo)] pub enum RestrictedTransferLocation { /// Local chain account sending destination. Local(AccountId), /// XCM Location sending destinations. - Xcm(VersionedLocation), + Xcm(Box), /// DomainAddress sending location from a liquidity pools' instance Address(DomainAddress), } diff --git a/runtime/common/src/migrations/restricted_location.rs b/runtime/common/src/migrations/restricted_location.rs index 26c594c9b4..1f78a34e62 100644 --- a/runtime/common/src/migrations/restricted_location.rs +++ b/runtime/common/src/migrations/restricted_location.rs @@ -159,7 +159,7 @@ where Ok(location) => { log::info!("{LOG_PREFIX} Hash: '{hash}' migrated!"); let new_restricted_location = - RestrictedTransferLocation::Xcm(VersionedLocation::V4(location)); + RestrictedTransferLocation::Xcm(Box::new(VersionedLocation::V4(location))); Some(new_restricted_location) } diff --git a/runtime/common/src/transfer_filter.rs b/runtime/common/src/transfer_filter.rs index ee497e492e..b9603a17d0 100644 --- a/runtime/common/src/transfer_filter.rs +++ b/runtime/common/src/transfer_filter.rs @@ -28,8 +28,10 @@ use sp_runtime::{ DispatchError, DispatchResult, TokenError, }; use sp_std::vec::Vec; -use staging_xcm::v4::{Asset, Location}; -use staging_xcm::VersionedLocation; +use staging_xcm::{ + v4::{Asset, Location}, + VersionedLocation, +}; pub struct PreXcmTransfer(sp_std::marker::PhantomData<(T, C)>); @@ -49,20 +51,20 @@ impl< amalgamate_allowance( T::allowance( sender.clone(), - RestrictedTransferLocation::Xcm(destination.clone()), + RestrictedTransferLocation::Xcm(Box::new(destination.clone())), FilterCurrency::Specific(currency), ), T::allowance( sender, - RestrictedTransferLocation::Xcm(destination), + RestrictedTransferLocation::Xcm(Box::new(destination)), FilterCurrency::All, ), ) }; let asset_based_check = |sender, destination, asset: Asset| { - let currency = C::convert(asset.id.0.into()) - .ok_or(DispatchError::Token(TokenError::UnknownAsset))?; + let currency = + C::convert(asset.id.0).ok_or(DispatchError::Token(TokenError::UnknownAsset))?; currency_based_check(sender, destination, currency) }; From 6b97978207b7344729a2b1fb1b7bb24ed73633ba Mon Sep 17 00:00:00 2001 From: William Freudenberger Date: Wed, 5 Jun 2024 17:44:19 +0200 Subject: [PATCH 7/9] fix: benchmark cli --- scripts/runtime_benchmarks.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/runtime_benchmarks.sh b/scripts/runtime_benchmarks.sh index ba363a395a..06eff7e9df 100755 --- a/scripts/runtime_benchmarks.sh +++ b/scripts/runtime_benchmarks.sh @@ -41,7 +41,7 @@ echo "Benchmarking pallets for runtime ${runtime}..." if [[ $runtime == "development" ]]; then runtime_path="runtime/development" - chain="development-local" + chain="development" elif [[ $runtime == "centrifuge" ]]; then runtime_path="runtime/centrifuge" From a7cf00f269ca79c562a91b7d36ebc0f625716fa5 Mon Sep 17 00:00:00 2001 From: William Freudenberger Date: Thu, 6 Jun 2024 11:35:37 +0200 Subject: [PATCH 8/9] fix: revert tight coupling --- libs/types/src/locations.rs | 8 ++++ .../transfer-allowlist/src/benchmarking.rs | 45 ++++++++----------- pallets/transfer-allowlist/src/mock.rs | 36 ++++++++++++--- .../src/migrations/restricted_location.rs | 1 + runtime/common/src/transfer_filter.rs | 1 + 5 files changed, 59 insertions(+), 32 deletions(-) diff --git a/libs/types/src/locations.rs b/libs/types/src/locations.rs index 3030d3011e..5427e1d5c8 100644 --- a/libs/types/src/locations.rs +++ b/libs/types/src/locations.rs @@ -14,6 +14,8 @@ use cfg_primitives::AccountId; use frame_support::RuntimeDebugNoBound; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; +use sp_core::crypto::AccountId32; +use sp_std::boxed::Box; use staging_xcm::VersionedLocation; use crate::domain_address::DomainAddress; @@ -28,3 +30,9 @@ pub enum RestrictedTransferLocation { /// DomainAddress sending location from a liquidity pools' instance Address(DomainAddress), } + +impl From for RestrictedTransferLocation { + fn from(value: AccountId32) -> Self { + Self::Local(value) + } +} diff --git a/pallets/transfer-allowlist/src/benchmarking.rs b/pallets/transfer-allowlist/src/benchmarking.rs index 81ccb725ec..6a2e4c6b82 100644 --- a/pallets/transfer-allowlist/src/benchmarking.rs +++ b/pallets/transfer-allowlist/src/benchmarking.rs @@ -12,10 +12,7 @@ #![cfg(feature = "runtime-benchmarks")] -use cfg_types::{ - locations::RestrictedTransferLocation, - tokens::{CurrencyId, FilterCurrency}, -}; +use cfg_types::tokens::{CurrencyId, FilterCurrency}; use frame_benchmarking::{account, v2::*}; use frame_support::{ pallet_prelude::Get, @@ -34,8 +31,9 @@ const BENCHMARK_CURRENCY_ID: FilterCurrency = FilterCurrency::Specific(CurrencyI #[benchmarks( where - T: Config, + T: Config, ::AccountId: Into, + T::Location: From<::AccountId>, T::ReserveCurrency: Currency<::AccountId> + ReservableCurrency<::AccountId>, BlockNumberFor: One, <::ReserveCurrency as frame_support::traits::fungible::Inspect<::AccountId,>>::Balance: From @@ -51,7 +49,7 @@ mod benchmarks { add_transfer_allowance( RawOrigin::Signed(sender), BENCHMARK_CURRENCY_ID, - default_location::(receiver), + T::Location::from(receiver), ); Ok(()) @@ -70,7 +68,7 @@ mod benchmarks { add_transfer_allowance( RawOrigin::Signed(sender), BENCHMARK_CURRENCY_ID, - default_location::(receiver), + T::Location::from(receiver), ); Ok(()) @@ -94,7 +92,7 @@ mod benchmarks { Pallet::::add_transfer_allowance( RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID, - default_location::(receiver), + T::Location::from(receiver), )?; #[extrinsic_call] @@ -186,7 +184,7 @@ mod benchmarks { Pallet::::add_transfer_allowance( RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID, - default_location::(receiver), + T::Location::from(receiver), )?; Pallet::::toggle_allowance_delay_once_future_modifiable( RawOrigin::Signed(sender.clone()).into(), @@ -216,7 +214,7 @@ mod benchmarks { Pallet::::add_transfer_allowance( RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID, - default_location::(receiver.clone()), + T::Location::from(receiver.clone()), )?; let b = frame_system::Pallet::::block_number() @@ -228,7 +226,7 @@ mod benchmarks { remove_transfer_allowance( RawOrigin::Signed(sender), BENCHMARK_CURRENCY_ID, - default_location::(receiver), + T::Location::from(receiver), ); Ok(()) @@ -240,14 +238,14 @@ mod benchmarks { Pallet::::add_transfer_allowance( RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID, - default_location::(receiver.clone()), + T::Location::from(receiver.clone()), )?; #[extrinsic_call] remove_transfer_allowance( RawOrigin::Signed(sender), BENCHMARK_CURRENCY_ID, - default_location::(receiver), + T::Location::from(receiver), ); Ok(()) @@ -259,19 +257,19 @@ mod benchmarks { Pallet::::add_transfer_allowance( RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID, - default_location::(receiver.clone()), + T::Location::from(receiver.clone()), )?; Pallet::::remove_transfer_allowance( RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID, - default_location::(receiver.clone()), + T::Location::from(receiver.clone()), )?; #[extrinsic_call] purge_transfer_allowance( RawOrigin::Signed(sender), BENCHMARK_CURRENCY_ID, - default_location::(receiver.clone()), + T::Location::from(receiver.clone()), ); Ok(()) @@ -284,24 +282,24 @@ mod benchmarks { Pallet::::add_transfer_allowance( RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID, - default_location::(receiver.clone()), + T::Location::from(receiver.clone()), )?; Pallet::::add_transfer_allowance( RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID, - default_location::(receiver_1.clone()), + T::Location::from(receiver_1.clone()), )?; Pallet::::remove_transfer_allowance( RawOrigin::Signed(sender.clone()).into(), BENCHMARK_CURRENCY_ID, - default_location::(receiver.clone()), + T::Location::from(receiver.clone()), )?; #[extrinsic_call] purge_transfer_allowance( RawOrigin::Signed(sender), BENCHMARK_CURRENCY_ID, - default_location::(receiver), + T::Location::from(receiver), ); Ok(()) @@ -332,10 +330,3 @@ where fn set_up_second_receiver() -> T::AccountId { account::("Receiver_1", 3, 0) } - -fn default_location(receiver: T::AccountId) -> RestrictedTransferLocation -where - ::AccountId: Into, -{ - RestrictedTransferLocation::Local(receiver.into()) -} diff --git a/pallets/transfer-allowlist/src/mock.rs b/pallets/transfer-allowlist/src/mock.rs index 22fb0a0785..de6868e9cf 100644 --- a/pallets/transfer-allowlist/src/mock.rs +++ b/pallets/transfer-allowlist/src/mock.rs @@ -10,9 +10,11 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -use cfg_types::{locations::RestrictedTransferLocation, tokens::FilterCurrency}; -use frame_support::{derive_impl, traits::ConstU64}; +use cfg_types::tokens::FilterCurrency; +use frame_support::{derive_impl, traits::ConstU64, Deserialize, Serialize}; use frame_system::pallet_prelude::BlockNumberFor; +use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; +use scale_info::TypeInfo; use sp_core::crypto::AccountId32; use sp_runtime::{ traits::{CheckedAdd, IdentityLookup}, @@ -53,15 +55,39 @@ impl pallet_balances::Config for Runtime { impl transfer_allowlist::Config for Runtime { type CurrencyId = FilterCurrency; type Deposit = ConstU64<10>; - type Location = RestrictedTransferLocation; + type Location = Location; type ReserveCurrency = Balances; type RuntimeEvent = RuntimeEvent; type RuntimeHoldReason = RuntimeHoldReason; type WeightInfo = (); } -pub(crate) fn local_location(receiver: AccountId32) -> RestrictedTransferLocation { - RestrictedTransferLocation::Local(receiver) +#[derive( + Clone, + Debug, + PartialOrd, + Ord, + Encode, + Decode, + Eq, + PartialEq, + MaxEncodedLen, + TypeInfo, + Deserialize, + Serialize, +)] +pub enum Location { + TestLocal(AccountId32), +} + +impl From for Location { + fn from(a: AccountId32) -> Self { + Self::TestLocal(a) + } +} + +pub(crate) fn local_location(receiver: AccountId32) -> Location { + receiver.into() } pub fn new_test_ext() -> sp_io::TestExternalities { diff --git a/runtime/common/src/migrations/restricted_location.rs b/runtime/common/src/migrations/restricted_location.rs index 1f78a34e62..8d21f3961e 100644 --- a/runtime/common/src/migrations/restricted_location.rs +++ b/runtime/common/src/migrations/restricted_location.rs @@ -9,6 +9,7 @@ use parity_scale_codec::Encode; use sp_arithmetic::traits::SaturatedConversion; use sp_core::H256; use sp_runtime::traits::{BlakeTwo256, Hash}; +use sp_std::boxed::Box; use sp_std::vec::Vec; use staging_xcm::{v4, VersionedLocation}; diff --git a/runtime/common/src/transfer_filter.rs b/runtime/common/src/transfer_filter.rs index b9603a17d0..2c3f4927bc 100644 --- a/runtime/common/src/transfer_filter.rs +++ b/runtime/common/src/transfer_filter.rs @@ -27,6 +27,7 @@ use sp_runtime::{ transaction_validity::{InvalidTransaction, TransactionValidityError}, DispatchError, DispatchResult, TokenError, }; +use sp_std::boxed::Box; use sp_std::vec::Vec; use staging_xcm::{ v4::{Asset, Location}, From 15a3f2a41c22122a9e6f19f4e3d47717f8a9c99e Mon Sep 17 00:00:00 2001 From: William Freudenberger Date: Thu, 6 Jun 2024 12:42:40 +0200 Subject: [PATCH 9/9] fmt --- runtime/common/src/migrations/restricted_location.rs | 3 +-- runtime/common/src/transfer_filter.rs | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/runtime/common/src/migrations/restricted_location.rs b/runtime/common/src/migrations/restricted_location.rs index 8d21f3961e..21aded9f1b 100644 --- a/runtime/common/src/migrations/restricted_location.rs +++ b/runtime/common/src/migrations/restricted_location.rs @@ -9,8 +9,7 @@ use parity_scale_codec::Encode; use sp_arithmetic::traits::SaturatedConversion; use sp_core::H256; use sp_runtime::traits::{BlakeTwo256, Hash}; -use sp_std::boxed::Box; -use sp_std::vec::Vec; +use sp_std::{boxed::Box, vec::Vec}; use staging_xcm::{v4, VersionedLocation}; mod old { diff --git a/runtime/common/src/transfer_filter.rs b/runtime/common/src/transfer_filter.rs index 2c3f4927bc..35da08e366 100644 --- a/runtime/common/src/transfer_filter.rs +++ b/runtime/common/src/transfer_filter.rs @@ -27,8 +27,7 @@ use sp_runtime::{ transaction_validity::{InvalidTransaction, TransactionValidityError}, DispatchError, DispatchResult, TokenError, }; -use sp_std::boxed::Box; -use sp_std::vec::Vec; +use sp_std::{boxed::Box, vec::Vec}; use staging_xcm::{ v4::{Asset, Location}, VersionedLocation,