From 798e47a755f9f16a980ab658dd9b4fb6de06bf36 Mon Sep 17 00:00:00 2001 From: zqh Date: Wed, 29 Dec 2021 11:37:10 +0800 Subject: [PATCH 01/12] xcm queue paused and resume --- Cargo.lock | 3 ++ modules/transaction-pause/src/lib.rs | 22 ++++++++++++++ runtime/acala/src/lib.rs | 4 +-- runtime/common/Cargo.toml | 6 ++++ runtime/common/src/lib.rs | 45 ++++++++++++++++++++++++++++ runtime/karura/src/lib.rs | 4 +-- runtime/mandala/src/lib.rs | 4 +-- 7 files changed, 82 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7a19b6fc0d..14fde1c399 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9808,6 +9808,7 @@ dependencies = [ "acala-primitives", "acala-service", "cumulus-pallet-parachain-system", + "cumulus-primitives-core", "ethabi", "frame-support", "frame-system", @@ -9823,6 +9824,7 @@ dependencies = [ "module-prices", "module-staking-pool", "module-support", + "module-transaction-pause", "module-transaction-payment", "num_enum", "orml-nft", @@ -9837,6 +9839,7 @@ dependencies = [ "pallet-timestamp", "pallet-utility", "parity-scale-codec", + "polkadot-core-primitives", "scale-info", "serde", "serde_json", diff --git a/modules/transaction-pause/src/lib.rs b/modules/transaction-pause/src/lib.rs index 83a5c8ef3f..9641f4cbb9 100644 --- a/modules/transaction-pause/src/lib.rs +++ b/modules/transaction-pause/src/lib.rs @@ -72,6 +72,8 @@ pub mod module { pallet_name_bytes: Vec, function_name_bytes: Vec, }, + XcmPaused, + XcmUnPaused, } /// The paused transaction map @@ -81,6 +83,10 @@ pub mod module { #[pallet::getter(fn paused_transactions)] pub type PausedTransactions = StorageMap<_, Twox64Concat, (Vec, Vec), (), OptionQuery>; + #[pallet::storage] + #[pallet::getter(fn xcm_paused)] + pub type XcmPaused = StorageValue<_, bool, ValueQuery>; + #[pallet::pallet] pub struct Pallet(_); @@ -129,6 +135,22 @@ pub mod module { }; Ok(()) } + + #[pallet::weight(T::WeightInfo::pause_transaction())] + pub fn pause_xcm(origin: OriginFor) -> DispatchResult { + T::UpdateOrigin::ensure_origin(origin)?; + XcmPaused::::set(true); + Self::deposit_event(Event::XcmPaused); + Ok(()) + } + + #[pallet::weight(T::WeightInfo::pause_transaction())] + pub fn unpause_xcm(origin: OriginFor) -> DispatchResult { + T::UpdateOrigin::ensure_origin(origin)?; + XcmPaused::::set(false); + Self::deposit_event(Event::XcmUnPaused); + Ok(()) + } } } diff --git a/runtime/acala/src/lib.rs b/runtime/acala/src/lib.rs index 6390c38a95..c588b3f93d 100644 --- a/runtime/acala/src/lib.rs +++ b/runtime/acala/src/lib.rs @@ -1366,10 +1366,10 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type Event = Event; type OnValidationData = (); type SelfParaId = ParachainInfo; - type DmpMessageHandler = DmpQueue; + type DmpMessageHandler = runtime_common::XcmMessageHandlerOrPaused; type ReservedDmpWeight = ReservedDmpWeight; type OutboundXcmpMessageSource = XcmpQueue; - type XcmpMessageHandler = XcmpQueue; + type XcmpMessageHandler = runtime_common::XcmMessageHandlerOrPaused; type ReservedXcmpWeight = ReservedXcmpWeight; } diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 0a924ccb1d..62d375fefc 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -21,6 +21,8 @@ sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot- sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } +polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.13", default-features = false } +cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.13", default-features = false } cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.13", default-features = false } orml-oracle = { path = "../../orml/oracle", default-features = false } @@ -35,6 +37,7 @@ primitives = { package = "acala-primitives", path = "../../primitives", default- module-prices = { path = "../../modules/prices", default-features = false } module-transaction-payment = { path = "../../modules/transaction-payment", default-features = false } +module-transaction-pause = { path = "../../modules/transaction-pause", default-features = false } module-nft = { path = "../../modules/nft", default-features = false } module-dex = { path = "../../modules/dex", default-features = false } @@ -77,6 +80,8 @@ std = [ "sp-runtime/std", "sp-std/std", + "polkadot-core-primitives/std", + "cumulus-primitives-core/std", "cumulus-pallet-parachain-system/std", "orml-oracle/std", @@ -89,6 +94,7 @@ std = [ "primitives/std", "module-prices/std", "module-transaction-payment/std", + "module-transaction-pause/std", "module-nft/std", "module-dex/std", diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index eda48b5804..7c4bc2d34d 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -64,6 +64,11 @@ pub use xcm::latest::prelude::*; pub use xcm_builder::TakeRevenue; pub use xcm_executor::{traits::DropAssets, Assets}; +use cumulus_primitives_core::relay_chain::v1::Id; +use cumulus_primitives_core::{DmpMessageHandler, XcmpMessageHandler}; +/// Block number type used by the relay chain. +pub use polkadot_core_primitives::BlockNumber as RelayChainBlockNumber; + pub type TimeStampedPrice = orml_oracle::TimestampedValue; // Priority of unsigned transactions @@ -420,6 +425,46 @@ where } } +/// XcmMessageHandler of `DmpMessageHandler` and `XcmpMessageHandler` implementations. +/// if xcm is paused, the `max_weight` of each handle method is set to `0`. +/// +/// Parameters type: +/// - `A`: `DmpMessageHandler` or `XcmpMessageHandler` +pub struct XcmMessageHandlerOrPaused(PhantomData<(Runtime, A)>); + +impl DmpMessageHandler for XcmMessageHandlerOrPaused +where + Runtime: module_transaction_pause::Config, + A: DmpMessageHandler, +{ + fn handle_dmp_messages(iter: impl Iterator)>, max_weight: Weight) -> Weight { + let xcm_paused: bool = module_transaction_pause::Pallet::::xcm_paused(); + if xcm_paused { + A::handle_dmp_messages(iter, 0) + } else { + A::handle_dmp_messages(iter, max_weight) + } + } +} + +impl XcmpMessageHandler for XcmMessageHandlerOrPaused +where + Runtime: module_transaction_pause::Config, + A: XcmpMessageHandler, +{ + fn handle_xcmp_messages<'a, I: Iterator>( + iter: I, + max_weight: Weight, + ) -> Weight { + let xcm_paused: bool = module_transaction_pause::Pallet::::xcm_paused(); + if xcm_paused { + A::handle_xcmp_messages(iter, 0) + } else { + A::handle_xcmp_messages(iter, max_weight) + } + } +} + #[cfg(test)] mod tests { use super::*; diff --git a/runtime/karura/src/lib.rs b/runtime/karura/src/lib.rs index 8bd794e1ae..21f5e64600 100644 --- a/runtime/karura/src/lib.rs +++ b/runtime/karura/src/lib.rs @@ -1381,10 +1381,10 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type Event = Event; type OnValidationData = (); type SelfParaId = ParachainInfo; - type DmpMessageHandler = DmpQueue; + type DmpMessageHandler = runtime_common::XcmMessageHandlerOrPaused; type ReservedDmpWeight = ReservedDmpWeight; type OutboundXcmpMessageSource = XcmpQueue; - type XcmpMessageHandler = XcmpQueue; + type XcmpMessageHandler = runtime_common::XcmMessageHandlerOrPaused; type ReservedXcmpWeight = ReservedXcmpWeight; } diff --git a/runtime/mandala/src/lib.rs b/runtime/mandala/src/lib.rs index a8b3b8c758..3bac3a58fa 100644 --- a/runtime/mandala/src/lib.rs +++ b/runtime/mandala/src/lib.rs @@ -1598,10 +1598,10 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type Event = Event; type OnValidationData = (); type SelfParaId = ParachainInfo; - type DmpMessageHandler = DmpQueue; + type DmpMessageHandler = runtime_common::XcmMessageHandlerOrPaused; type ReservedDmpWeight = ReservedDmpWeight; type OutboundXcmpMessageSource = XcmpQueue; - type XcmpMessageHandler = XcmpQueue; + type XcmpMessageHandler = runtime_common::XcmMessageHandlerOrPaused; type ReservedXcmpWeight = ReservedXcmpWeight; } From be26d0b29f714719cb477e9b51d1a024afc530d8 Mon Sep 17 00:00:00 2001 From: zqh Date: Thu, 30 Dec 2021 21:56:53 +0800 Subject: [PATCH 02/12] tests of dmp and xcmp --- Cargo.lock | 3 +- runtime/integration-tests/Cargo.toml | 5 +- .../relaychain/kusama_cross_chain_transfer.rs | 109 ++++++++++++++++++ .../src/relaychain/kusama_test_net.rs | 4 + runtime/integration-tests/src/setup.rs | 12 +- 5 files changed, 124 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 14fde1c399..076894b956 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9903,6 +9903,7 @@ dependencies = [ "module-relaychain", "module-session-manager", "module-support", + "module-transaction-pause", "module-transaction-payment", "orml-auction", "orml-authority", @@ -13807,7 +13808,7 @@ dependencies = [ [[package]] name = "xcm-emulator" version = "0.1.0" -source = "git+https://github.com/shaunxw/xcm-simulator?rev=4d3bb9dd4fa2cd554a9970ffff816d9346269eaa#4d3bb9dd4fa2cd554a9970ffff816d9346269eaa" +source = "git+https://github.com/zqhxuyuan/xcm-simulator?branch=handler#40bdf8a8168f29d3d2bd6766c6b1263eeec40f16" dependencies = [ "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", diff --git a/runtime/integration-tests/Cargo.toml b/runtime/integration-tests/Cargo.toml index 1c840fd2dd..1099e6ebf0 100644 --- a/runtime/integration-tests/Cargo.toml +++ b/runtime/integration-tests/Cargo.toml @@ -86,6 +86,7 @@ orml-unknown-tokens = { path = "../../orml/unknown-tokens" } orml-xcm = { path = "../../orml/xcm" } module-transaction-payment = { path = "../../modules/transaction-payment" } +module-transaction-pause = { path = "../../modules/transaction-pause" } module-asset-registry = { path = "../../modules/asset-registry" } module-auction-manager = { path = "../../modules/auction-manager" } module-cdp-engine = { path = "../../modules/cdp-engine" } @@ -131,12 +132,12 @@ polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.13" } kusama-runtime = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.13" } -xcm-emulator = { git = "https://github.com/shaunxw/xcm-simulator", rev = "4d3bb9dd4fa2cd554a9970ffff816d9346269eaa" } +xcm-emulator = { git = "https://github.com/zqhxuyuan/xcm-simulator", branch = "handler" } acala-service = { path = "../../node/service", features = ["with-all-runtime"] } [features] -default = ["std"] +default = ["std", "with-karura-runtime"] no_std = [] with-mandala-runtime = [ "acala-service/with-mandala-runtime", diff --git a/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs b/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs index 4110f80912..9b2673f9b1 100644 --- a/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs +++ b/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs @@ -768,3 +768,112 @@ fn sibling_trap_assets_works() { ); }); } + +#[test] +fn dmp_queue_pause_resume_works() { + Karura::execute_with(|| { + assert_ok!(module_transaction_pause::Pallet::::pause_xcm(Origin::root())); + assert!(module_transaction_pause::Pallet::::xcm_paused()); + }); + + let fee: u128 = 128_000_000; + + KusamaNet::execute_with(|| { + assert_ok!(kusama_runtime::XcmPallet::reserve_transfer_assets( + kusama_runtime::Origin::signed(ALICE.into()), + Box::new(Parachain(2000).into().into()), + Box::new( + Junction::AccountId32 { + id: BOB, + network: NetworkId::Any + } + .into() + .into() + ), + Box::new((Here, dollar(KSM)).into()), + 0 + )); + }); + + Karura::execute_with(|| { + // the first message is not processed but remain in dmq-queue + assert!(module_transaction_pause::Pallet::::xcm_paused()); + // Bob balance is 0 as the xcm message not executed + assert_eq!(Tokens::free_balance(KSM, &AccountId::from(BOB)), 0); + + // resume the dmp-queue working + assert_ok!(module_transaction_pause::Pallet::::unpause_xcm(Origin::root())); + assert!(!module_transaction_pause::Pallet::::xcm_paused()); + }); + + // the empty body implementation here is used to trigger send downward message to parachain, + // the previous message in the queue storage will be [first executed](https://github.com/paritytech/cumulus/blob/polkadot-v0.9.13/pallets/dmp-queue/src/lib.rs#L270). + // then the second message executed which is also get from storage by runtime.dmq_contents(). + KusamaNet::execute_with(|| {}); + + Karura::execute_with(|| { + assert!(!module_transaction_pause::Pallet::::xcm_paused()); + assert_eq!( + Tokens::free_balance(KSM, &AccountId::from(BOB)), + 2 * dollar(KSM) - fee * 2 + ); + }); +} + +#[test] +fn xcmp_queue_pause_resume_works() { + fn karura_reserve_account() -> AccountId { + use sp_runtime::traits::AccountIdConversion; + polkadot_parachain::primitives::Sibling::from(2000).into_account() + } + Karura::execute_with(|| { + assert_ok!(Tokens::deposit(BNC, &AccountId::from(ALICE), 100 * dollar(BNC))); + }); + + Sibling::execute_with(|| { + assert_ok!(Tokens::deposit(BNC, &karura_reserve_account(), 100 * dollar(BNC))); + assert_ok!(module_transaction_pause::Pallet::::pause_xcm(Origin::root())); + assert!(module_transaction_pause::Pallet::::xcm_paused()); + }); + + Karura::execute_with(|| { + assert_ok!(XTokens::transfer( + Origin::signed(ALICE.into()), + BNC, + 10 * dollar(BNC), + Box::new( + MultiLocation::new( + 1, + X2( + Parachain(2001), + Junction::AccountId32 { + network: NetworkId::Any, + id: BOB.into(), + } + ) + ) + .into() + ), + 1_000_000_000, + )); + + assert_eq!(Tokens::free_balance(BNC, &AccountId::from(ALICE)), 90 * dollar(BNC)); + }); + + Sibling::execute_with(|| { + assert_eq!(Tokens::free_balance(BNC, &karura_reserve_account()), 100 * dollar(BNC)); + assert_eq!(Tokens::free_balance(BNC, &AccountId::from(BOB)), 0); + + // resume the dmp-queue working + assert_ok!(module_transaction_pause::Pallet::::unpause_xcm(Origin::root())); + assert!(!module_transaction_pause::Pallet::::xcm_paused()); + + assert_eq!(Tokens::free_balance(BNC, &karura_reserve_account()), 100 * dollar(BNC)); + assert_eq!(Tokens::free_balance(BNC, &AccountId::from(BOB)), 0); + }); + + Sibling::execute_with(|| { + assert_eq!(Tokens::free_balance(BNC, &karura_reserve_account()), 90 * dollar(BNC)); + assert_eq!(Tokens::free_balance(BNC, &AccountId::from(BOB)), 9_989_760_000_000); + }); +} diff --git a/runtime/integration-tests/src/relaychain/kusama_test_net.rs b/runtime/integration-tests/src/relaychain/kusama_test_net.rs index 3ff38e63c9..648164be3b 100644 --- a/runtime/integration-tests/src/relaychain/kusama_test_net.rs +++ b/runtime/integration-tests/src/relaychain/kusama_test_net.rs @@ -40,6 +40,8 @@ decl_test_parachain! { pub struct Karura { Runtime = Runtime, Origin = Origin, + XcmpMessageHandler = runtime_common::XcmMessageHandlerOrPaused, + DmpMessageHandler = runtime_common::XcmMessageHandlerOrPaused, new_ext = para_ext(2000), } } @@ -48,6 +50,8 @@ decl_test_parachain! { pub struct Sibling { Runtime = Runtime, Origin = Origin, + XcmpMessageHandler = runtime_common::XcmMessageHandlerOrPaused, + DmpMessageHandler = runtime_common::XcmMessageHandlerOrPaused, new_ext = para_ext(2001), } } diff --git a/runtime/integration-tests/src/setup.rs b/runtime/integration-tests/src/setup.rs index 2e51b12c67..0ceb8ae08b 100644 --- a/runtime/integration-tests/src/setup.rs +++ b/runtime/integration-tests/src/setup.rs @@ -78,14 +78,14 @@ mod karura_imports { constants::parachains, create_x2_parachain_multilocation, get_all_module_accounts, AcalaOracle, AccountId, AssetRegistry, AuctionManager, Authority, AuthoritysOriginId, Balance, Balances, BlockNumber, Call, CdpEngine, CdpTreasury, CreateClassDeposit, CreateTokenDeposit, Currencies, CurrencyId, CurrencyIdConvert, - DataDepositPerByte, DefaultExchangeRate, Dex, EmergencyShutdown, Event, EvmAccounts, ExistentialDeposits, - FeePoolSize, FinancialCouncil, Get, GetNativeCurrencyId, HomaLite, Honzon, IdleScheduler, KarPerSecond, - KaruraFoundationAccounts, KsmPerSecond, KusdPerSecond, Loans, MaxTipsOfPriority, MinimumDebitValue, - MultiLocation, NativeTokenExistentialDeposit, NetworkId, NftPalletId, OneDay, Origin, OriginCaller, - ParachainAccount, ParachainInfo, ParachainSystem, PolkadotXcm, Proxy, ProxyType, Ratio, + DataDepositPerByte, DefaultExchangeRate, Dex, DmpQueue, EmergencyShutdown, Event, EvmAccounts, + ExistentialDeposits, FeePoolSize, FinancialCouncil, Get, GetNativeCurrencyId, HomaLite, Honzon, IdleScheduler, + KarPerSecond, KaruraFoundationAccounts, KsmPerSecond, KusdPerSecond, Loans, MaxTipsOfPriority, + MinimumDebitValue, MultiLocation, NativeTokenExistentialDeposit, NetworkId, NftPalletId, OneDay, Origin, + OriginCaller, ParachainAccount, ParachainInfo, ParachainSystem, PolkadotXcm, Proxy, ProxyType, Ratio, RelayChainBlockNumberProvider, RelayChainSovereignSubAccount, Runtime, Scheduler, Session, SessionManager, SevenDays, SwapBalanceThreshold, System, Timestamp, TipPerWeightStep, TokenSymbol, Tokens, TreasuryPalletId, - Utility, Vesting, XTokens, XcmConfig, XcmExecutor, XcmUnbondFee, EVM, NFT, + Utility, Vesting, XTokens, XcmConfig, XcmExecutor, XcmUnbondFee, XcmpQueue, EVM, NFT, }; pub use primitives::TradingPair; pub use runtime_common::{calculate_asset_ratio, cent, dollar, millicent, KAR, KSM, KUSD, LKSM}; From c0ccb33864521a0dac56806e9d1b3cf404f3b8fd Mon Sep 17 00:00:00 2001 From: zqh Date: Thu, 30 Dec 2021 22:11:05 +0800 Subject: [PATCH 03/12] weight --- modules/transaction-pause/src/lib.rs | 18 ++++++++++----- modules/transaction-pause/src/weights.rs | 22 +++++++++++++++++++ .../src/weights/module_transaction_pause.rs | 10 +++++++++ runtime/integration-tests/Cargo.toml | 2 +- .../src/weights/module_transaction_pause.rs | 10 +++++++++ .../src/weights/module_transaction_pause.rs | 10 +++++++++ 6 files changed, 65 insertions(+), 7 deletions(-) diff --git a/modules/transaction-pause/src/lib.rs b/modules/transaction-pause/src/lib.rs index 9641f4cbb9..594a26a71f 100644 --- a/modules/transaction-pause/src/lib.rs +++ b/modules/transaction-pause/src/lib.rs @@ -72,7 +72,9 @@ pub mod module { pallet_name_bytes: Vec, function_name_bytes: Vec, }, + /// Paused Xcm message XcmPaused, + /// Unpaused Xcm message XcmUnPaused, } @@ -136,19 +138,23 @@ pub mod module { Ok(()) } - #[pallet::weight(T::WeightInfo::pause_transaction())] + #[pallet::weight(T::WeightInfo::pause_xcm())] pub fn pause_xcm(origin: OriginFor) -> DispatchResult { T::UpdateOrigin::ensure_origin(origin)?; - XcmPaused::::set(true); - Self::deposit_event(Event::XcmPaused); + if !XcmPaused::::get() { + XcmPaused::::set(true); + Self::deposit_event(Event::XcmPaused); + } Ok(()) } - #[pallet::weight(T::WeightInfo::pause_transaction())] + #[pallet::weight(T::WeightInfo::unpause_xcm())] pub fn unpause_xcm(origin: OriginFor) -> DispatchResult { T::UpdateOrigin::ensure_origin(origin)?; - XcmPaused::::set(false); - Self::deposit_event(Event::XcmUnPaused); + if XcmPaused::::get() { + XcmPaused::::set(false); + Self::deposit_event(Event::XcmUnPaused); + } Ok(()) } } diff --git a/modules/transaction-pause/src/weights.rs b/modules/transaction-pause/src/weights.rs index 376a3e953e..4086800cab 100644 --- a/modules/transaction-pause/src/weights.rs +++ b/modules/transaction-pause/src/weights.rs @@ -49,6 +49,8 @@ use sp_std::marker::PhantomData; pub trait WeightInfo { fn pause_transaction() -> Weight; fn unpause_transaction() -> Weight; + fn pause_xcm() -> Weight; + fn unpause_xcm() -> Weight; } /// Weights for module_transaction_pause using the Acala node and recommended hardware. @@ -64,6 +66,16 @@ impl WeightInfo for AcalaWeight { .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } + fn pause_xcm() -> Weight { + (25_798_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn unpause_xcm() -> Weight { + (25_355_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } } // For backwards compatibility and tests @@ -78,4 +90,14 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } + fn pause_xcm() -> Weight { + (25_798_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(1 as Weight)) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } + fn unpause_xcm() -> Weight { + (25_355_000 as Weight) + .saturating_add(RocksDbWeight::get().reads(1 as Weight)) + .saturating_add(RocksDbWeight::get().writes(1 as Weight)) + } } diff --git a/runtime/acala/src/weights/module_transaction_pause.rs b/runtime/acala/src/weights/module_transaction_pause.rs index b3615b7a75..adfa5ad63d 100644 --- a/runtime/acala/src/weights/module_transaction_pause.rs +++ b/runtime/acala/src/weights/module_transaction_pause.rs @@ -57,4 +57,14 @@ impl module_transaction_pause::WeightInfo for WeightInf .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } + fn pause_xcm() -> Weight { + (23_319_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn unpause_xcm() -> Weight { + (23_899_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } } diff --git a/runtime/integration-tests/Cargo.toml b/runtime/integration-tests/Cargo.toml index 1099e6ebf0..9d42ae3736 100644 --- a/runtime/integration-tests/Cargo.toml +++ b/runtime/integration-tests/Cargo.toml @@ -137,7 +137,7 @@ xcm-emulator = { git = "https://github.com/zqhxuyuan/xcm-simulator", branch = "h acala-service = { path = "../../node/service", features = ["with-all-runtime"] } [features] -default = ["std", "with-karura-runtime"] +default = ["std"] no_std = [] with-mandala-runtime = [ "acala-service/with-mandala-runtime", diff --git a/runtime/karura/src/weights/module_transaction_pause.rs b/runtime/karura/src/weights/module_transaction_pause.rs index c7c82dab17..95a336ede7 100644 --- a/runtime/karura/src/weights/module_transaction_pause.rs +++ b/runtime/karura/src/weights/module_transaction_pause.rs @@ -57,4 +57,14 @@ impl module_transaction_pause::WeightInfo for WeightInf .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } + fn pause_xcm() -> Weight { + (22_667_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn unpause_xcm() -> Weight { + (22_608_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } } diff --git a/runtime/mandala/src/weights/module_transaction_pause.rs b/runtime/mandala/src/weights/module_transaction_pause.rs index a8be8ce093..ecb31987ac 100644 --- a/runtime/mandala/src/weights/module_transaction_pause.rs +++ b/runtime/mandala/src/weights/module_transaction_pause.rs @@ -57,4 +57,14 @@ impl module_transaction_pause::WeightInfo for WeightInf .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } + fn pause_xcm() -> Weight { + (22_667_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } + fn unpause_xcm() -> Weight { + (22_608_000 as Weight) + .saturating_add(T::DbWeight::get().reads(1 as Weight)) + .saturating_add(T::DbWeight::get().writes(1 as Weight)) + } } From 117c2a100d147aa130e23a0c3298a3307aa36746 Mon Sep 17 00:00:00 2001 From: zqh Date: Thu, 30 Dec 2021 22:21:03 +0800 Subject: [PATCH 04/12] minor typo --- .../relaychain/kusama_cross_chain_transfer.rs | 22 +++++-------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs b/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs index 9b2673f9b1..50e2d40218 100644 --- a/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs +++ b/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs @@ -83,15 +83,14 @@ fn transfer_to_relay_chain() { }); } +fn karura_reserve_account() -> AccountId { + polkadot_parachain::primitives::Sibling::from(2000).into_account() +} + #[test] fn transfer_to_sibling() { TestNet::reset(); - fn karura_reserve_account() -> AccountId { - use sp_runtime::traits::AccountIdConversion; - polkadot_parachain::primitives::Sibling::from(2000).into_account() - } - Karura::execute_with(|| { assert_ok!(Tokens::deposit(BNC, &AccountId::from(ALICE), 100_000_000_000_000)); }); @@ -325,11 +324,6 @@ fn subscribe_version_notify_works() { fn test_asset_registry_module() { TestNet::reset(); - fn karura_reserve_account() -> AccountId { - use sp_runtime::traits::AccountIdConversion; - polkadot_parachain::primitives::Sibling::from(2000).into_account() - } - Karura::execute_with(|| { // register foreign asset assert_ok!(AssetRegistry::register_foreign_asset( @@ -711,7 +705,6 @@ fn sibling_trap_assets_works() { let (bnc_asset_amount, kar_asset_amount) = (cent(BNC) / 10, cent(KAR)); fn sibling_account() -> AccountId { - use sp_runtime::traits::AccountIdConversion; polkadot_parachain::primitives::Sibling::from(2001).into_account() } @@ -822,10 +815,6 @@ fn dmp_queue_pause_resume_works() { #[test] fn xcmp_queue_pause_resume_works() { - fn karura_reserve_account() -> AccountId { - use sp_runtime::traits::AccountIdConversion; - polkadot_parachain::primitives::Sibling::from(2000).into_account() - } Karura::execute_with(|| { assert_ok!(Tokens::deposit(BNC, &AccountId::from(ALICE), 100 * dollar(BNC))); }); @@ -864,10 +853,11 @@ fn xcmp_queue_pause_resume_works() { assert_eq!(Tokens::free_balance(BNC, &karura_reserve_account()), 100 * dollar(BNC)); assert_eq!(Tokens::free_balance(BNC, &AccountId::from(BOB)), 0); - // resume the dmp-queue working + // resume the xcmp-queue working assert_ok!(module_transaction_pause::Pallet::::unpause_xcm(Origin::root())); assert!(!module_transaction_pause::Pallet::::xcm_paused()); + // in the same block, balance not changed assert_eq!(Tokens::free_balance(BNC, &karura_reserve_account()), 100 * dollar(BNC)); assert_eq!(Tokens::free_balance(BNC, &AccountId::from(BOB)), 0); }); From bef19b9f586af5c8b99e5f20996340233f29cf7d Mon Sep 17 00:00:00 2001 From: zqh Date: Mon, 3 Jan 2022 23:02:21 +0800 Subject: [PATCH 05/12] review fix --- modules/transaction-pause/src/lib.rs | 6 +++--- runtime/acala/src/lib.rs | 4 ++-- runtime/common/src/lib.rs | 18 ++++++++--------- .../relaychain/kusama_cross_chain_transfer.rs | 20 ++++++++++++++----- .../src/relaychain/kusama_test_net.rs | 8 ++++---- runtime/karura/src/lib.rs | 4 ++-- runtime/mandala/src/lib.rs | 4 ++-- 7 files changed, 37 insertions(+), 27 deletions(-) diff --git a/modules/transaction-pause/src/lib.rs b/modules/transaction-pause/src/lib.rs index 594a26a71f..c31f51eb25 100644 --- a/modules/transaction-pause/src/lib.rs +++ b/modules/transaction-pause/src/lib.rs @@ -74,8 +74,8 @@ pub mod module { }, /// Paused Xcm message XcmPaused, - /// Unpaused Xcm message - XcmUnPaused, + /// Resume Xcm message + XcmResumed, } /// The paused transaction map @@ -153,7 +153,7 @@ pub mod module { T::UpdateOrigin::ensure_origin(origin)?; if XcmPaused::::get() { XcmPaused::::set(false); - Self::deposit_event(Event::XcmUnPaused); + Self::deposit_event(Event::XcmResumed); } Ok(()) } diff --git a/runtime/acala/src/lib.rs b/runtime/acala/src/lib.rs index c588b3f93d..efa1358861 100644 --- a/runtime/acala/src/lib.rs +++ b/runtime/acala/src/lib.rs @@ -1366,10 +1366,10 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type Event = Event; type OnValidationData = (); type SelfParaId = ParachainInfo; - type DmpMessageHandler = runtime_common::XcmMessageHandlerOrPaused; + type DmpMessageHandler = runtime_common::XcmMessageHandler; type ReservedDmpWeight = ReservedDmpWeight; type OutboundXcmpMessageSource = XcmpQueue; - type XcmpMessageHandler = runtime_common::XcmMessageHandlerOrPaused; + type XcmpMessageHandler = runtime_common::XcmMessageHandler; type ReservedXcmpWeight = ReservedXcmpWeight; } diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 7c4bc2d34d..fa988d72bc 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -430,24 +430,24 @@ where /// /// Parameters type: /// - `A`: `DmpMessageHandler` or `XcmpMessageHandler` -pub struct XcmMessageHandlerOrPaused(PhantomData<(Runtime, A)>); +pub struct XcmMessageHandler(PhantomData<(Runtime, A)>); -impl DmpMessageHandler for XcmMessageHandlerOrPaused +impl DmpMessageHandler for XcmMessageHandler where Runtime: module_transaction_pause::Config, A: DmpMessageHandler, { fn handle_dmp_messages(iter: impl Iterator)>, max_weight: Weight) -> Weight { let xcm_paused: bool = module_transaction_pause::Pallet::::xcm_paused(); - if xcm_paused { - A::handle_dmp_messages(iter, 0) - } else { + if !xcm_paused { A::handle_dmp_messages(iter, max_weight) + } else { + A::handle_dmp_messages(iter, 0) } } } -impl XcmpMessageHandler for XcmMessageHandlerOrPaused +impl XcmpMessageHandler for XcmMessageHandler where Runtime: module_transaction_pause::Config, A: XcmpMessageHandler, @@ -457,10 +457,10 @@ where max_weight: Weight, ) -> Weight { let xcm_paused: bool = module_transaction_pause::Pallet::::xcm_paused(); - if xcm_paused { - A::handle_xcmp_messages(iter, 0) - } else { + if !xcm_paused { A::handle_xcmp_messages(iter, max_weight) + } else { + A::handle_xcmp_messages(iter, 0) } } } diff --git a/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs b/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs index 50e2d40218..7df3b6179d 100644 --- a/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs +++ b/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs @@ -764,6 +764,8 @@ fn sibling_trap_assets_works() { #[test] fn dmp_queue_pause_resume_works() { + use polkadot_primitives::v1::runtime_decl_for_ParachainHost::ParachainHost; + Karura::execute_with(|| { assert_ok!(module_transaction_pause::Pallet::::pause_xcm(Origin::root())); assert!(module_transaction_pause::Pallet::::xcm_paused()); @@ -786,6 +788,11 @@ fn dmp_queue_pause_resume_works() { Box::new((Here, dollar(KSM)).into()), 0 )); + + let downward_messages = ::dmq_contents(2000.into()) + .into_iter() + .map(|inbound| (inbound.sent_at, inbound.msg)); + assert_eq!(downward_messages.len(), 1); }); Karura::execute_with(|| { @@ -799,16 +806,19 @@ fn dmp_queue_pause_resume_works() { assert!(!module_transaction_pause::Pallet::::xcm_paused()); }); - // the empty body implementation here is used to trigger send downward message to parachain, - // the previous message in the queue storage will be [first executed](https://github.com/paritytech/cumulus/blob/polkadot-v0.9.13/pallets/dmp-queue/src/lib.rs#L270). - // then the second message executed which is also get from storage by runtime.dmq_contents(). - KusamaNet::execute_with(|| {}); + // the empty body implementation here is used to trigger send downward message to parachain + KusamaNet::execute_with(|| { + let downward_messages = ::dmq_contents(2000.into()) + .into_iter() + .map(|inbound| (inbound.sent_at, inbound.msg)); + assert_eq!(downward_messages.len(), 1); + }); Karura::execute_with(|| { assert!(!module_transaction_pause::Pallet::::xcm_paused()); assert_eq!( Tokens::free_balance(KSM, &AccountId::from(BOB)), - 2 * dollar(KSM) - fee * 2 + 2 * (dollar(KSM) - fee) ); }); } diff --git a/runtime/integration-tests/src/relaychain/kusama_test_net.rs b/runtime/integration-tests/src/relaychain/kusama_test_net.rs index 648164be3b..f31ecee7b9 100644 --- a/runtime/integration-tests/src/relaychain/kusama_test_net.rs +++ b/runtime/integration-tests/src/relaychain/kusama_test_net.rs @@ -40,8 +40,8 @@ decl_test_parachain! { pub struct Karura { Runtime = Runtime, Origin = Origin, - XcmpMessageHandler = runtime_common::XcmMessageHandlerOrPaused, - DmpMessageHandler = runtime_common::XcmMessageHandlerOrPaused, + XcmpMessageHandler = runtime_common::XcmMessageHandler, + DmpMessageHandler = runtime_common::XcmMessageHandler, new_ext = para_ext(2000), } } @@ -50,8 +50,8 @@ decl_test_parachain! { pub struct Sibling { Runtime = Runtime, Origin = Origin, - XcmpMessageHandler = runtime_common::XcmMessageHandlerOrPaused, - DmpMessageHandler = runtime_common::XcmMessageHandlerOrPaused, + XcmpMessageHandler = runtime_common::XcmMessageHandler, + DmpMessageHandler = runtime_common::XcmMessageHandler, new_ext = para_ext(2001), } } diff --git a/runtime/karura/src/lib.rs b/runtime/karura/src/lib.rs index 21f5e64600..bde7de455a 100644 --- a/runtime/karura/src/lib.rs +++ b/runtime/karura/src/lib.rs @@ -1381,10 +1381,10 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type Event = Event; type OnValidationData = (); type SelfParaId = ParachainInfo; - type DmpMessageHandler = runtime_common::XcmMessageHandlerOrPaused; + type DmpMessageHandler = runtime_common::XcmMessageHandler; type ReservedDmpWeight = ReservedDmpWeight; type OutboundXcmpMessageSource = XcmpQueue; - type XcmpMessageHandler = runtime_common::XcmMessageHandlerOrPaused; + type XcmpMessageHandler = runtime_common::XcmMessageHandler; type ReservedXcmpWeight = ReservedXcmpWeight; } diff --git a/runtime/mandala/src/lib.rs b/runtime/mandala/src/lib.rs index 3bac3a58fa..fd32202692 100644 --- a/runtime/mandala/src/lib.rs +++ b/runtime/mandala/src/lib.rs @@ -1598,10 +1598,10 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type Event = Event; type OnValidationData = (); type SelfParaId = ParachainInfo; - type DmpMessageHandler = runtime_common::XcmMessageHandlerOrPaused; + type DmpMessageHandler = runtime_common::XcmMessageHandler; type ReservedDmpWeight = ReservedDmpWeight; type OutboundXcmpMessageSource = XcmpQueue; - type XcmpMessageHandler = runtime_common::XcmMessageHandlerOrPaused; + type XcmpMessageHandler = runtime_common::XcmMessageHandler; type ReservedXcmpWeight = ReservedXcmpWeight; } From 4ef73513c65af6282b659e6838a04f6e54d12ed3 Mon Sep 17 00:00:00 2001 From: zqh Date: Wed, 5 Jan 2022 00:14:01 +0800 Subject: [PATCH 06/12] unpause_xcm to resume_xcm --- modules/transaction-pause/src/lib.rs | 4 ++-- modules/transaction-pause/src/weights.rs | 6 +++--- .../src/weights/module_transaction_pause.rs | 2 +- runtime/integration-tests/Cargo.toml | 2 +- .../relaychain/kusama_cross_chain_transfer.rs | 14 ++++---------- runtime/integration-tests/src/setup.rs | 16 ++++++++-------- .../src/weights/module_transaction_pause.rs | 2 +- .../src/weights/module_transaction_pause.rs | 2 +- 8 files changed, 21 insertions(+), 27 deletions(-) diff --git a/modules/transaction-pause/src/lib.rs b/modules/transaction-pause/src/lib.rs index c31f51eb25..c7225b8da6 100644 --- a/modules/transaction-pause/src/lib.rs +++ b/modules/transaction-pause/src/lib.rs @@ -148,8 +148,8 @@ pub mod module { Ok(()) } - #[pallet::weight(T::WeightInfo::unpause_xcm())] - pub fn unpause_xcm(origin: OriginFor) -> DispatchResult { + #[pallet::weight(T::WeightInfo::resume_xcm())] + pub fn resume_xcm(origin: OriginFor) -> DispatchResult { T::UpdateOrigin::ensure_origin(origin)?; if XcmPaused::::get() { XcmPaused::::set(false); diff --git a/modules/transaction-pause/src/weights.rs b/modules/transaction-pause/src/weights.rs index 4086800cab..fa22ec8438 100644 --- a/modules/transaction-pause/src/weights.rs +++ b/modules/transaction-pause/src/weights.rs @@ -50,7 +50,7 @@ pub trait WeightInfo { fn pause_transaction() -> Weight; fn unpause_transaction() -> Weight; fn pause_xcm() -> Weight; - fn unpause_xcm() -> Weight; + fn resume_xcm() -> Weight; } /// Weights for module_transaction_pause using the Acala node and recommended hardware. @@ -71,7 +71,7 @@ impl WeightInfo for AcalaWeight { .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } - fn unpause_xcm() -> Weight { + fn resume_xcm() -> Weight { (25_355_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) @@ -95,7 +95,7 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) } - fn unpause_xcm() -> Weight { + fn resume_xcm() -> Weight { (25_355_000 as Weight) .saturating_add(RocksDbWeight::get().reads(1 as Weight)) .saturating_add(RocksDbWeight::get().writes(1 as Weight)) diff --git a/runtime/acala/src/weights/module_transaction_pause.rs b/runtime/acala/src/weights/module_transaction_pause.rs index adfa5ad63d..4805a2845f 100644 --- a/runtime/acala/src/weights/module_transaction_pause.rs +++ b/runtime/acala/src/weights/module_transaction_pause.rs @@ -62,7 +62,7 @@ impl module_transaction_pause::WeightInfo for WeightInf .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } - fn unpause_xcm() -> Weight { + fn resume_xcm() -> Weight { (23_899_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) diff --git a/runtime/integration-tests/Cargo.toml b/runtime/integration-tests/Cargo.toml index 53939a52db..a5c0472561 100644 --- a/runtime/integration-tests/Cargo.toml +++ b/runtime/integration-tests/Cargo.toml @@ -139,7 +139,7 @@ xcm-emulator = { git = "https://github.com/zqhxuyuan/xcm-simulator", branch = "h acala-service = { path = "../../node/service", features = ["with-all-runtime"] } [features] -default = ["std"] +default = ["std", "with-karura-runtime"] no_std = [] with-mandala-runtime = [ "acala-service/with-mandala-runtime", diff --git a/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs b/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs index 7df3b6179d..0d5670488f 100644 --- a/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs +++ b/runtime/integration-tests/src/relaychain/kusama_cross_chain_transfer.rs @@ -789,10 +789,7 @@ fn dmp_queue_pause_resume_works() { 0 )); - let downward_messages = ::dmq_contents(2000.into()) - .into_iter() - .map(|inbound| (inbound.sent_at, inbound.msg)); - assert_eq!(downward_messages.len(), 1); + assert_eq!(::dmq_contents(2000.into()).len(), 1); }); Karura::execute_with(|| { @@ -802,16 +799,13 @@ fn dmp_queue_pause_resume_works() { assert_eq!(Tokens::free_balance(KSM, &AccountId::from(BOB)), 0); // resume the dmp-queue working - assert_ok!(module_transaction_pause::Pallet::::unpause_xcm(Origin::root())); + assert_ok!(module_transaction_pause::Pallet::::resume_xcm(Origin::root())); assert!(!module_transaction_pause::Pallet::::xcm_paused()); }); // the empty body implementation here is used to trigger send downward message to parachain KusamaNet::execute_with(|| { - let downward_messages = ::dmq_contents(2000.into()) - .into_iter() - .map(|inbound| (inbound.sent_at, inbound.msg)); - assert_eq!(downward_messages.len(), 1); + assert_eq!(::dmq_contents(2000.into()).len(), 1); }); Karura::execute_with(|| { @@ -864,7 +858,7 @@ fn xcmp_queue_pause_resume_works() { assert_eq!(Tokens::free_balance(BNC, &AccountId::from(BOB)), 0); // resume the xcmp-queue working - assert_ok!(module_transaction_pause::Pallet::::unpause_xcm(Origin::root())); + assert_ok!(module_transaction_pause::Pallet::::resume_xcm(Origin::root())); assert!(!module_transaction_pause::Pallet::::xcm_paused()); // in the same block, balance not changed diff --git a/runtime/integration-tests/src/setup.rs b/runtime/integration-tests/src/setup.rs index 2606f52a19..6ca5d21924 100644 --- a/runtime/integration-tests/src/setup.rs +++ b/runtime/integration-tests/src/setup.rs @@ -77,14 +77,14 @@ mod karura_imports { constants::parachains, create_x2_parachain_multilocation, get_all_module_accounts, AcalaOracle, AccountId, AssetRegistry, AuctionManager, Authority, AuthoritysOriginId, Balance, Balances, BlockNumber, Call, CdpEngine, CdpTreasury, CreateClassDeposit, CreateTokenDeposit, Currencies, CurrencyId, CurrencyIdConvert, - DataDepositPerByte, DefaultExchangeRate, Dex, DmpQueue, EmergencyShutdown, Event, EvmAccounts, ExistentialDeposits, - FeePoolSize, FinancialCouncil, Get, GetNativeCurrencyId, Homa, HomaLite, HomaXcm, Honzon, IdleScheduler, - KarPerSecond, KaruraFoundationAccounts, KsmPerSecond, KusamaBondingDuration, KusdPerSecond, Loans, - MaxTipsOfPriority, MinimumDebitValue, MultiLocation, NativeTokenExistentialDeposit, NetworkId, NftPalletId, - OneDay, Origin, OriginCaller, ParachainAccount, ParachainInfo, ParachainSystem, PolkadotXcm, Proxy, ProxyType, - Ratio, RelayChainBlockNumberProvider, RelayChainSovereignSubAccount, Runtime, Scheduler, Session, - SessionManager, SevenDays, SwapBalanceThreshold, System, Timestamp, TipPerWeightStep, TokenSymbol, Tokens, - TreasuryPalletId, Utility, Vesting, XTokens, XcmConfig, XcmExecutor, XcmUnbondFee, XcmpQueue, EVM, NFT, + DataDepositPerByte, DefaultExchangeRate, Dex, DmpQueue, EmergencyShutdown, Event, EvmAccounts, + ExistentialDeposits, FeePoolSize, FinancialCouncil, Get, GetNativeCurrencyId, Homa, HomaLite, HomaXcm, Honzon, + IdleScheduler, KarPerSecond, KaruraFoundationAccounts, KsmPerSecond, KusamaBondingDuration, KusdPerSecond, + Loans, MaxTipsOfPriority, MinimumDebitValue, MultiLocation, NativeTokenExistentialDeposit, NetworkId, + NftPalletId, OneDay, Origin, OriginCaller, ParachainAccount, ParachainInfo, ParachainSystem, PolkadotXcm, + Proxy, ProxyType, Ratio, RelayChainBlockNumberProvider, RelayChainSovereignSubAccount, Runtime, Scheduler, + Session, SessionManager, SevenDays, SwapBalanceThreshold, System, Timestamp, TipPerWeightStep, TokenSymbol, + Tokens, TreasuryPalletId, Utility, Vesting, XTokens, XcmConfig, XcmExecutor, XcmUnbondFee, XcmpQueue, EVM, NFT, }; pub use primitives::TradingPair; pub use runtime_common::{calculate_asset_ratio, cent, dollar, millicent, KAR, KSM, KUSD, LKSM}; diff --git a/runtime/karura/src/weights/module_transaction_pause.rs b/runtime/karura/src/weights/module_transaction_pause.rs index 95a336ede7..a19b8a140a 100644 --- a/runtime/karura/src/weights/module_transaction_pause.rs +++ b/runtime/karura/src/weights/module_transaction_pause.rs @@ -62,7 +62,7 @@ impl module_transaction_pause::WeightInfo for WeightInf .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } - fn unpause_xcm() -> Weight { + fn resume_xcm() -> Weight { (22_608_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) diff --git a/runtime/mandala/src/weights/module_transaction_pause.rs b/runtime/mandala/src/weights/module_transaction_pause.rs index ecb31987ac..50a98d718a 100644 --- a/runtime/mandala/src/weights/module_transaction_pause.rs +++ b/runtime/mandala/src/weights/module_transaction_pause.rs @@ -62,7 +62,7 @@ impl module_transaction_pause::WeightInfo for WeightInf .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } - fn unpause_xcm() -> Weight { + fn resume_xcm() -> Weight { (22_608_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) From cc3b1f0158245d42c115eed7bafe6bae719a5bba Mon Sep 17 00:00:00 2001 From: zqh Date: Wed, 5 Jan 2022 10:27:33 +0800 Subject: [PATCH 07/12] move to transaction-pause --- Cargo.lock | 7 ++- modules/transaction-pause/Cargo.toml | 8 ++- modules/transaction-pause/src/lib.rs | 51 ++++++++++++++++++- runtime/acala/src/lib.rs | 5 +- runtime/common/Cargo.toml | 6 --- runtime/common/src/lib.rs | 45 ---------------- runtime/integration-tests/Cargo.toml | 4 +- .../src/relaychain/kusama_test_net.rs | 9 ++-- runtime/karura/src/lib.rs | 5 +- runtime/mandala/src/lib.rs | 5 +- 10 files changed, 76 insertions(+), 69 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 27cf2f375e..80b402d47d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5821,12 +5821,14 @@ name = "module-transaction-pause" version = "2.1.2" dependencies = [ "acala-primitives", + "cumulus-primitives-core", "frame-support", "frame-system", "orml-tokens", "orml-traits", "pallet-balances", "parity-scale-codec", + "polkadot-core-primitives", "scale-info", "smallvec", "sp-core", @@ -9787,7 +9789,6 @@ dependencies = [ "acala-primitives", "acala-service", "cumulus-pallet-parachain-system", - "cumulus-primitives-core", "ethabi", "frame-support", "frame-system", @@ -9802,7 +9803,6 @@ dependencies = [ "module-nft", "module-prices", "module-support", - "module-transaction-pause", "module-transaction-payment", "num_enum", "orml-nft", @@ -9817,7 +9817,6 @@ dependencies = [ "pallet-timestamp", "pallet-utility", "parity-scale-codec", - "polkadot-core-primitives", "scale-info", "serde", "serde_json", @@ -13788,7 +13787,7 @@ dependencies = [ [[package]] name = "xcm-emulator" version = "0.1.0" -source = "git+https://github.com/zqhxuyuan/xcm-simulator?branch=handler#40bdf8a8168f29d3d2bd6766c6b1263eeec40f16" +source = "git+https://github.com/shaunxw/xcm-simulator?rev=87af52d07fc742cc9220bab6acb9afa061d09fd3#87af52d07fc742cc9220bab6acb9afa061d09fd3" dependencies = [ "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", diff --git a/modules/transaction-pause/Cargo.toml b/modules/transaction-pause/Cargo.toml index 7379b43f06..782bd0af1a 100644 --- a/modules/transaction-pause/Cargo.toml +++ b/modules/transaction-pause/Cargo.toml @@ -12,13 +12,16 @@ frame-support = { git = "https://github.com/paritytech/substrate", branch = "pol frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } +primitives = { package = "acala-primitives", path = "../../primitives", default-features = false} +polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.13", default-features = false } +cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.13", default-features = false } + [dev-dependencies] sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" } sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" } pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13" } orml-tokens = { path = "../../orml/tokens" } orml-traits = { path = "../../orml/traits" } -primitives = { package = "acala-primitives", path = "../../primitives" } smallvec = "1.4.1" [features] @@ -29,5 +32,8 @@ std = [ "frame-support/std", "frame-system/std", "sp-std/std", + "primitives/std", + "polkadot-core-primitives/std", + "cumulus-primitives-core/std", ] try-runtime = ["frame-support/try-runtime"] diff --git a/modules/transaction-pause/src/lib.rs b/modules/transaction-pause/src/lib.rs index c7225b8da6..0f5f53b941 100644 --- a/modules/transaction-pause/src/lib.rs +++ b/modules/transaction-pause/src/lib.rs @@ -26,9 +26,15 @@ use frame_support::{ transactional, }; use frame_system::pallet_prelude::*; +use primitives::BlockNumber; use sp_runtime::DispatchResult; use sp_std::{prelude::*, vec::Vec}; +use cumulus_primitives_core::relay_chain::v1::Id; +use cumulus_primitives_core::{DmpMessageHandler, XcmpMessageHandler}; +/// Block number type used by the relay chain. +pub use polkadot_core_primitives::BlockNumber as RelayChainBlockNumber; + mod mock; mod tests; pub mod weights; @@ -74,7 +80,7 @@ pub mod module { }, /// Paused Xcm message XcmPaused, - /// Resume Xcm message + /// Resumed Xcm message XcmResumed, } @@ -173,3 +179,46 @@ where PausedTransactions::::contains_key((pallet_name.as_bytes(), function_name.as_bytes())) } } + +/// Dmp and Xcmp message handler +pub struct XcmMessageHandler(PhantomData<(T, H)>); + +/// XcmMessageHandler implements `DmpMessageHandler`. if xcm paused, the `max_weight` is set to `0`. +/// +/// Parameters type: +/// - `H`: `DmpMessageHandler` +impl DmpMessageHandler for XcmMessageHandler +where + H: DmpMessageHandler, +{ + fn handle_dmp_messages(iter: impl Iterator)>, max_weight: Weight) -> Weight { + let xcm_paused: bool = Pallet::::xcm_paused(); + if !xcm_paused { + H::handle_dmp_messages(iter, max_weight) + } else { + H::handle_dmp_messages(iter, 0) + } + } +} + +/// XcmMessageHandler implements `XcmpMessageHandler`. if xcm paused, the `max_weight` is set to +/// `0`. +/// +/// Parameters type: +/// - `H`: `XcmpMessageHandler` +impl XcmpMessageHandler for XcmMessageHandler +where + H: XcmpMessageHandler, +{ + fn handle_xcmp_messages<'a, I: Iterator>( + iter: I, + max_weight: Weight, + ) -> Weight { + let xcm_paused: bool = Pallet::::xcm_paused(); + if !xcm_paused { + H::handle_xcmp_messages(iter, max_weight) + } else { + H::handle_xcmp_messages(iter, 0) + } + } +} diff --git a/runtime/acala/src/lib.rs b/runtime/acala/src/lib.rs index 28525da277..79edeeb288 100644 --- a/runtime/acala/src/lib.rs +++ b/runtime/acala/src/lib.rs @@ -56,6 +56,7 @@ use module_evm::{CallInfo, CreateInfo, EvmTask, Runner}; use module_evm_accounts::EvmAddressMapping; use module_relaychain::RelayChainCallBuilder; use module_support::{AssetIdMapping, DispatchableTask}; +use module_transaction_pause::XcmMessageHandler; use module_transaction_payment::{Multiplier, TargetedFeeAdjustment, TransactionFeePoolTrader}; use orml_traits::{ create_median_value_data_provider, parameter_type_with_key, DataFeeder, DataProviderExtended, MultiCurrency, @@ -1366,10 +1367,10 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type Event = Event; type OnValidationData = (); type SelfParaId = ParachainInfo; - type DmpMessageHandler = runtime_common::XcmMessageHandler; + type DmpMessageHandler = XcmMessageHandler; type ReservedDmpWeight = ReservedDmpWeight; type OutboundXcmpMessageSource = XcmpQueue; - type XcmpMessageHandler = runtime_common::XcmMessageHandler; + type XcmpMessageHandler = XcmMessageHandler; type ReservedXcmpWeight = ReservedXcmpWeight; } diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 8ec2a0785d..d59b1941fd 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -21,8 +21,6 @@ sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot- sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } -polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.13", default-features = false } -cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.13", default-features = false } cumulus-pallet-parachain-system = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.13", default-features = false } orml-oracle = { path = "../../orml/oracle", default-features = false } @@ -36,7 +34,6 @@ primitives = { package = "acala-primitives", path = "../../primitives", default- module-prices = { path = "../../modules/prices", default-features = false } module-transaction-payment = { path = "../../modules/transaction-payment", default-features = false } -module-transaction-pause = { path = "../../modules/transaction-pause", default-features = false } module-nft = { path = "../../modules/nft", default-features = false } module-dex = { path = "../../modules/dex", default-features = false } @@ -79,8 +76,6 @@ std = [ "sp-runtime/std", "sp-std/std", - "polkadot-core-primitives/std", - "cumulus-primitives-core/std", "cumulus-pallet-parachain-system/std", "orml-oracle/std", @@ -92,7 +87,6 @@ std = [ "primitives/std", "module-prices/std", "module-transaction-payment/std", - "module-transaction-pause/std", "module-nft/std", "module-dex/std", diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index ab94beb5b3..d9f4753aa2 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -61,11 +61,6 @@ pub use xcm::latest::prelude::*; pub use xcm_builder::TakeRevenue; pub use xcm_executor::{traits::DropAssets, Assets}; -use cumulus_primitives_core::relay_chain::v1::Id; -use cumulus_primitives_core::{DmpMessageHandler, XcmpMessageHandler}; -/// Block number type used by the relay chain. -pub use polkadot_core_primitives::BlockNumber as RelayChainBlockNumber; - pub type TimeStampedPrice = orml_oracle::TimestampedValue; // Priority of unsigned transactions @@ -422,46 +417,6 @@ where } } -/// XcmMessageHandler of `DmpMessageHandler` and `XcmpMessageHandler` implementations. -/// if xcm is paused, the `max_weight` of each handle method is set to `0`. -/// -/// Parameters type: -/// - `A`: `DmpMessageHandler` or `XcmpMessageHandler` -pub struct XcmMessageHandler(PhantomData<(Runtime, A)>); - -impl DmpMessageHandler for XcmMessageHandler -where - Runtime: module_transaction_pause::Config, - A: DmpMessageHandler, -{ - fn handle_dmp_messages(iter: impl Iterator)>, max_weight: Weight) -> Weight { - let xcm_paused: bool = module_transaction_pause::Pallet::::xcm_paused(); - if !xcm_paused { - A::handle_dmp_messages(iter, max_weight) - } else { - A::handle_dmp_messages(iter, 0) - } - } -} - -impl XcmpMessageHandler for XcmMessageHandler -where - Runtime: module_transaction_pause::Config, - A: XcmpMessageHandler, -{ - fn handle_xcmp_messages<'a, I: Iterator>( - iter: I, - max_weight: Weight, - ) -> Weight { - let xcm_paused: bool = module_transaction_pause::Pallet::::xcm_paused(); - if !xcm_paused { - A::handle_xcmp_messages(iter, max_weight) - } else { - A::handle_xcmp_messages(iter, 0) - } - } -} - #[cfg(test)] mod tests { use super::*; diff --git a/runtime/integration-tests/Cargo.toml b/runtime/integration-tests/Cargo.toml index a5c0472561..2c8002ce72 100644 --- a/runtime/integration-tests/Cargo.toml +++ b/runtime/integration-tests/Cargo.toml @@ -134,12 +134,12 @@ polkadot-primitives = { git = "https://github.com/paritytech/polkadot", branch = polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.13" } kusama-runtime = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.13" } -xcm-emulator = { git = "https://github.com/zqhxuyuan/xcm-simulator", branch = "handler" } +xcm-emulator = { git = "https://github.com/shaunxw/xcm-simulator", rev = "87af52d07fc742cc9220bab6acb9afa061d09fd3" } acala-service = { path = "../../node/service", features = ["with-all-runtime"] } [features] -default = ["std", "with-karura-runtime"] +default = ["std"] no_std = [] with-mandala-runtime = [ "acala-service/with-mandala-runtime", diff --git a/runtime/integration-tests/src/relaychain/kusama_test_net.rs b/runtime/integration-tests/src/relaychain/kusama_test_net.rs index f31ecee7b9..7b68912a20 100644 --- a/runtime/integration-tests/src/relaychain/kusama_test_net.rs +++ b/runtime/integration-tests/src/relaychain/kusama_test_net.rs @@ -22,6 +22,7 @@ use crate::setup::*; use cumulus_primitives_core::ParaId; use frame_support::traits::GenesisBuild; +use module_transaction_pause::XcmMessageHandler; use polkadot_primitives::v1::{BlockNumber, MAX_CODE_SIZE, MAX_POV_SIZE}; use polkadot_runtime_parachains::configuration::HostConfiguration; use sp_runtime::traits::AccountIdConversion; @@ -40,8 +41,8 @@ decl_test_parachain! { pub struct Karura { Runtime = Runtime, Origin = Origin, - XcmpMessageHandler = runtime_common::XcmMessageHandler, - DmpMessageHandler = runtime_common::XcmMessageHandler, + XcmpMessageHandler = XcmMessageHandler, + DmpMessageHandler = XcmMessageHandler, new_ext = para_ext(2000), } } @@ -50,8 +51,8 @@ decl_test_parachain! { pub struct Sibling { Runtime = Runtime, Origin = Origin, - XcmpMessageHandler = runtime_common::XcmMessageHandler, - DmpMessageHandler = runtime_common::XcmMessageHandler, + XcmpMessageHandler = XcmMessageHandler, + DmpMessageHandler = XcmMessageHandler, new_ext = para_ext(2001), } } diff --git a/runtime/karura/src/lib.rs b/runtime/karura/src/lib.rs index d2d6213227..36c33ff139 100644 --- a/runtime/karura/src/lib.rs +++ b/runtime/karura/src/lib.rs @@ -56,6 +56,7 @@ use module_evm::{CallInfo, CreateInfo, EvmTask, Runner}; use module_evm_accounts::EvmAddressMapping; use module_relaychain::RelayChainCallBuilder; use module_support::{AssetIdMapping, DispatchableTask}; +use module_transaction_pause::XcmMessageHandler; use module_transaction_payment::{Multiplier, TargetedFeeAdjustment, TransactionFeePoolTrader}; use orml_traits::{ @@ -1386,10 +1387,10 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type Event = Event; type OnValidationData = (); type SelfParaId = ParachainInfo; - type DmpMessageHandler = runtime_common::XcmMessageHandler; + type DmpMessageHandler = XcmMessageHandler; type ReservedDmpWeight = ReservedDmpWeight; type OutboundXcmpMessageSource = XcmpQueue; - type XcmpMessageHandler = runtime_common::XcmMessageHandler; + type XcmpMessageHandler = XcmMessageHandler; type ReservedXcmpWeight = ReservedXcmpWeight; } diff --git a/runtime/mandala/src/lib.rs b/runtime/mandala/src/lib.rs index 88b4693215..6a4b4f5c04 100644 --- a/runtime/mandala/src/lib.rs +++ b/runtime/mandala/src/lib.rs @@ -53,6 +53,7 @@ use module_evm::{CallInfo, CreateInfo, EvmTask, Runner}; use module_evm_accounts::EvmAddressMapping; use module_relaychain::RelayChainCallBuilder; use module_support::{AssetIdMapping, DispatchableTask}; +use module_transaction_pause::XcmMessageHandler; use module_transaction_payment::{Multiplier, TargetedFeeAdjustment, TransactionFeePoolTrader}; use scale_info::TypeInfo; @@ -1535,10 +1536,10 @@ impl cumulus_pallet_parachain_system::Config for Runtime { type Event = Event; type OnValidationData = (); type SelfParaId = ParachainInfo; - type DmpMessageHandler = runtime_common::XcmMessageHandler; + type DmpMessageHandler = XcmMessageHandler; type ReservedDmpWeight = ReservedDmpWeight; type OutboundXcmpMessageSource = XcmpQueue; - type XcmpMessageHandler = runtime_common::XcmMessageHandler; + type XcmpMessageHandler = XcmMessageHandler; type ReservedXcmpWeight = ReservedXcmpWeight; } From 2680fb3ff27edf795c0c99bcc66c6eb06d51b599 Mon Sep 17 00:00:00 2001 From: zqh Date: Wed, 5 Jan 2022 11:15:37 +0800 Subject: [PATCH 08/12] fmt --- runtime/integration-tests/src/setup.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/runtime/integration-tests/src/setup.rs b/runtime/integration-tests/src/setup.rs index cfd0ab27fc..ec2926737c 100644 --- a/runtime/integration-tests/src/setup.rs +++ b/runtime/integration-tests/src/setup.rs @@ -78,14 +78,14 @@ mod karura_imports { constants::parachains, create_x2_parachain_multilocation, get_all_module_accounts, AcalaOracle, AccountId, AssetRegistry, AuctionManager, Authority, AuthoritysOriginId, Balance, Balances, BlockNumber, Call, CdpEngine, CdpTreasury, CreateClassDeposit, CreateTokenDeposit, Currencies, CurrencyId, CurrencyIdConvert, - DataDepositPerByte, DefaultExchangeRate, Dex, DmpQueue, EmergencyShutdown, Event, EvmAccounts, ExistentialDeposits, - FeePoolSize, FinancialCouncil, Get, GetNativeCurrencyId, Homa, HomaXcm, Honzon, IdleScheduler, KarPerSecond, - KaruraFoundationAccounts, KsmPerSecond, KusamaBondingDuration, KusdPerSecond, Loans, MaxTipsOfPriority, - MinimumDebitValue, MultiLocation, NativeTokenExistentialDeposit, NetworkId, NftPalletId, OneDay, Origin, - OriginCaller, ParachainAccount, ParachainInfo, ParachainSystem, PolkadotXcm, Proxy, ProxyType, Ratio, - RelayChainBlockNumberProvider, Runtime, Scheduler, Session, SessionManager, SevenDays, SwapBalanceThreshold, - System, Timestamp, TipPerWeightStep, TokenSymbol, Tokens, TreasuryPalletId, Utility, Vesting, XTokens, - XcmConfig, XcmExecutor, XcmpQueue, EVM, NFT, + DataDepositPerByte, DefaultExchangeRate, Dex, DmpQueue, EmergencyShutdown, Event, EvmAccounts, + ExistentialDeposits, FeePoolSize, FinancialCouncil, Get, GetNativeCurrencyId, Homa, HomaXcm, Honzon, + IdleScheduler, KarPerSecond, KaruraFoundationAccounts, KsmPerSecond, KusamaBondingDuration, KusdPerSecond, + Loans, MaxTipsOfPriority, MinimumDebitValue, MultiLocation, NativeTokenExistentialDeposit, NetworkId, + NftPalletId, OneDay, Origin, OriginCaller, ParachainAccount, ParachainInfo, ParachainSystem, PolkadotXcm, + Proxy, ProxyType, Ratio, RelayChainBlockNumberProvider, Runtime, Scheduler, Session, SessionManager, SevenDays, + SwapBalanceThreshold, System, Timestamp, TipPerWeightStep, TokenSymbol, Tokens, TreasuryPalletId, Utility, + Vesting, XTokens, XcmConfig, XcmExecutor, XcmpQueue, EVM, NFT, }; pub use primitives::TradingPair; pub use runtime_common::{calculate_asset_ratio, cent, dollar, millicent, KAR, KSM, KUSD, LKSM}; From a1965ebba163f0ee8ff24b0e9916e76d6cd93ecf Mon Sep 17 00:00:00 2001 From: zqh Date: Wed, 5 Jan 2022 13:08:30 +0800 Subject: [PATCH 09/12] add transaction pause bench method --- runtime/mandala/src/benchmarking/transaction_pause.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/runtime/mandala/src/benchmarking/transaction_pause.rs b/runtime/mandala/src/benchmarking/transaction_pause.rs index 54bdfd2ebe..9d19cac36d 100644 --- a/runtime/mandala/src/benchmarking/transaction_pause.rs +++ b/runtime/mandala/src/benchmarking/transaction_pause.rs @@ -30,6 +30,12 @@ runtime_benchmarks! { unpause_transaction { TransactionPause::pause_transaction(Origin::root(), b"Balances".to_vec(), b"transfer".to_vec())?; }: _(RawOrigin::Root, b"Balances".to_vec(), b"transfer".to_vec()) + + pause_xcm { + }: _(RawOrigin::Root) + + resume_xcm { + }: _(RawOrigin::Root) } #[cfg(test)] From f787793248ab55e42a18d2a4df9e4d65d851b7ec Mon Sep 17 00:00:00 2001 From: Acala Benchmarking Bot Date: Wed, 5 Jan 2022 07:06:50 +0000 Subject: [PATCH 10/12] cargo run --release --color=never --bin=acala --features=runtime-benchmarks --features=with-mandala-runtime -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=module_transaction_pause --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --template=./templates/runtime-weight-template.hbs --output=./runtime/mandala/src/weights/ --- .../src/weights/module_transaction_pause.rs | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/runtime/mandala/src/weights/module_transaction_pause.rs b/runtime/mandala/src/weights/module_transaction_pause.rs index 50a98d718a..e998f4b32a 100644 --- a/runtime/mandala/src/weights/module_transaction_pause.rs +++ b/runtime/mandala/src/weights/module_transaction_pause.rs @@ -18,17 +18,17 @@ //! Autogenerated weights for module_transaction_pause //! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 3.0.0 -//! DATE: 2021-08-15, STEPS: `[50, ]`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("mandala-latest"), DB CACHE: 128 +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2022-01-05, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 128 // Executed Command: // target/release/acala // benchmark -// --chain=mandala-latest +// --chain=dev // --steps=50 // --repeat=20 -// --pallet=* +// --pallet=module_transaction_pause // --extrinsic=* // --execution=wasm // --wasm-execution=compiled @@ -36,7 +36,6 @@ // --template=./templates/runtime-weight-template.hbs // --output=./runtime/mandala/src/weights/ - #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] @@ -48,23 +47,22 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl module_transaction_pause::WeightInfo for WeightInfo { fn pause_transaction() -> Weight { - (24_000_000 as Weight) + (22_402_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn unpause_transaction() -> Weight { - (25_000_000 as Weight) + (22_972_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn pause_xcm() -> Weight { - (22_667_000 as Weight) + (19_395_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn resume_xcm() -> Weight { - (22_608_000 as Weight) + (4_190_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) } } From 9caca6c92177f47913e0d201169ad8fce4ef61fc Mon Sep 17 00:00:00 2001 From: Acala Benchmarking Bot Date: Wed, 5 Jan 2022 07:21:39 +0000 Subject: [PATCH 11/12] cargo run --release --color=never --bin=acala --features=runtime-benchmarks --features=with-karura-runtime -- benchmark --chain=karura-dev --steps=50 --repeat=20 --pallet=module_transaction_pause --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --template=./templates/runtime-weight-template.hbs --output=./runtime/karura/src/weights/ --- .../karura/src/weights/module_transaction_pause.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/runtime/karura/src/weights/module_transaction_pause.rs b/runtime/karura/src/weights/module_transaction_pause.rs index a19b8a140a..4a674a4a3f 100644 --- a/runtime/karura/src/weights/module_transaction_pause.rs +++ b/runtime/karura/src/weights/module_transaction_pause.rs @@ -19,7 +19,7 @@ //! Autogenerated weights for module_transaction_pause //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2021-10-30, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-01-05, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("karura-dev"), DB CACHE: 128 // Executed Command: @@ -28,7 +28,7 @@ // --chain=karura-dev // --steps=50 // --repeat=20 -// --pallet=* +// --pallet=module_transaction_pause // --extrinsic=* // --execution=wasm // --wasm-execution=compiled @@ -36,7 +36,6 @@ // --template=./templates/runtime-weight-template.hbs // --output=./runtime/karura/src/weights/ - #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] @@ -48,23 +47,22 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl module_transaction_pause::WeightInfo for WeightInfo { fn pause_transaction() -> Weight { - (22_667_000 as Weight) + (22_432_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn unpause_transaction() -> Weight { - (22_608_000 as Weight) + (22_658_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn pause_xcm() -> Weight { - (22_667_000 as Weight) + (19_438_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn resume_xcm() -> Weight { - (22_608_000 as Weight) + (4_208_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) } } From 5e987f416c2c9c5977c695205e515f2e691774c0 Mon Sep 17 00:00:00 2001 From: Acala Benchmarking Bot Date: Wed, 5 Jan 2022 07:38:40 +0000 Subject: [PATCH 12/12] cargo run --release --color=never --bin=acala --features=runtime-benchmarks --features=with-acala-runtime -- benchmark --chain=acala-latest --steps=50 --repeat=20 --pallet=module_transaction_pause --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --template=./templates/runtime-weight-template.hbs --output=./runtime/acala/src/weights/ --- .../acala/src/weights/module_transaction_pause.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/runtime/acala/src/weights/module_transaction_pause.rs b/runtime/acala/src/weights/module_transaction_pause.rs index 4805a2845f..5d190f6ba2 100644 --- a/runtime/acala/src/weights/module_transaction_pause.rs +++ b/runtime/acala/src/weights/module_transaction_pause.rs @@ -19,7 +19,7 @@ //! Autogenerated weights for module_transaction_pause //! //! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2021-10-30, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! DATE: 2022-01-05, STEPS: `50`, REPEAT: 20, LOW RANGE: `[]`, HIGH RANGE: `[]` //! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("acala-latest"), DB CACHE: 128 // Executed Command: @@ -28,7 +28,7 @@ // --chain=acala-latest // --steps=50 // --repeat=20 -// --pallet=* +// --pallet=module_transaction_pause // --extrinsic=* // --execution=wasm // --wasm-execution=compiled @@ -36,7 +36,6 @@ // --template=./templates/runtime-weight-template.hbs // --output=./runtime/acala/src/weights/ - #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] #![allow(unused_imports)] @@ -48,23 +47,22 @@ use sp_std::marker::PhantomData; pub struct WeightInfo(PhantomData); impl module_transaction_pause::WeightInfo for WeightInfo { fn pause_transaction() -> Weight { - (23_319_000 as Weight) + (23_381_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn unpause_transaction() -> Weight { - (23_899_000 as Weight) + (23_853_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn pause_xcm() -> Weight { - (23_319_000 as Weight) + (20_265_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) .saturating_add(T::DbWeight::get().writes(1 as Weight)) } fn resume_xcm() -> Weight { - (23_899_000 as Weight) + (4_521_000 as Weight) .saturating_add(T::DbWeight::get().reads(1 as Weight)) - .saturating_add(T::DbWeight::get().writes(1 as Weight)) } }