Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Cargo.lock

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

28 changes: 28 additions & 0 deletions modules/transaction-pause/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ pub mod module {
pallet_name_bytes: Vec<u8>,
function_name_bytes: Vec<u8>,
},
/// Paused Xcm message
XcmPaused,
/// Unpaused Xcm message
XcmUnPaused,
}

/// The paused transaction map
Expand All @@ -81,6 +85,10 @@ pub mod module {
#[pallet::getter(fn paused_transactions)]
pub type PausedTransactions<T: Config> = StorageMap<_, Twox64Concat, (Vec<u8>, Vec<u8>), (), OptionQuery>;

#[pallet::storage]
#[pallet::getter(fn xcm_paused)]
pub type XcmPaused<T: Config> = StorageValue<_, bool, ValueQuery>;

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

Expand Down Expand Up @@ -129,6 +137,26 @@ pub mod module {
};
Ok(())
}

#[pallet::weight(T::WeightInfo::pause_xcm())]
pub fn pause_xcm(origin: OriginFor<T>) -> DispatchResult {
T::UpdateOrigin::ensure_origin(origin)?;
if !XcmPaused::<T>::get() {
XcmPaused::<T>::set(true);
Self::deposit_event(Event::XcmPaused);
}
Ok(())
}

#[pallet::weight(T::WeightInfo::unpause_xcm())]
pub fn unpause_xcm(origin: OriginFor<T>) -> DispatchResult {
T::UpdateOrigin::ensure_origin(origin)?;
if XcmPaused::<T>::get() {
XcmPaused::<T>::set(false);
Self::deposit_event(Event::XcmUnPaused);
}
Ok(())
}
}
}

Expand Down
22 changes: 22 additions & 0 deletions modules/transaction-pause/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -64,6 +66,16 @@ impl<T: frame_system::Config> WeightInfo for AcalaWeight<T> {
.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
Expand All @@ -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))
}
}
4 changes: 2 additions & 2 deletions runtime/acala/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Runtime, DmpQueue>;
type ReservedDmpWeight = ReservedDmpWeight;
type OutboundXcmpMessageSource = XcmpQueue;
type XcmpMessageHandler = XcmpQueue;
type XcmpMessageHandler = runtime_common::XcmMessageHandlerOrPaused<Runtime, XcmpQueue>;
type ReservedXcmpWeight = ReservedXcmpWeight;
}

Expand Down
10 changes: 10 additions & 0 deletions runtime/acala/src/weights/module_transaction_pause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,14 @@ impl<T: frame_system::Config> 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))
}
}
6 changes: 6 additions & 0 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 }

Expand Down Expand Up @@ -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",
Expand All @@ -89,6 +94,7 @@ std = [
"primitives/std",
"module-prices/std",
"module-transaction-payment/std",
"module-transaction-pause/std",
"module-nft/std",
"module-dex/std",

Expand Down
45 changes: 45 additions & 0 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Price, primitives::Moment>;

// Priority of unsigned transactions
Expand Down Expand Up @@ -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<Runtime, A>(PhantomData<(Runtime, A)>);

impl<Runtime, A> DmpMessageHandler for XcmMessageHandlerOrPaused<Runtime, A>
where
Runtime: module_transaction_pause::Config,
A: DmpMessageHandler,
{
fn handle_dmp_messages(iter: impl Iterator<Item = (RelayChainBlockNumber, Vec<u8>)>, max_weight: Weight) -> Weight {
let xcm_paused: bool = module_transaction_pause::Pallet::<Runtime>::xcm_paused();
if xcm_paused {
A::handle_dmp_messages(iter, 0)
} else {
A::handle_dmp_messages(iter, max_weight)
}
}
}

impl<Runtime, A> XcmpMessageHandler for XcmMessageHandlerOrPaused<Runtime, A>
where
Runtime: module_transaction_pause::Config,
A: XcmpMessageHandler,
{
fn handle_xcmp_messages<'a, I: Iterator<Item = (Id, BlockNumber, &'a [u8])>>(
iter: I,
max_weight: Weight,
) -> Weight {
let xcm_paused: bool = module_transaction_pause::Pallet::<Runtime>::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::*;
Expand Down
3 changes: 2 additions & 1 deletion runtime/integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down Expand Up @@ -131,7 +132,7 @@ 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"] }

Expand Down
Loading