Skip to content
This repository was archived by the owner on May 21, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
lockdown_pallet
  • Loading branch information
Valentin Fernandez committed May 18, 2023
commit 170c76b5d8810badcae76959b27f0f52814c77a7
50 changes: 50 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions node/service/src/chain_spec/trappist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ fn testnet_genesis(
phantom: Default::default(),
},
treasury: Default::default(),
lockdown_mode: Default::default(),
}
}

Expand Down Expand Up @@ -349,5 +350,6 @@ fn trappist_live_genesis(
phantom: Default::default(),
},
treasury: Default::default(),
lockdown_mode: Default::default(),
}
}
44 changes: 41 additions & 3 deletions pallets/asset-registry/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@
#![allow(unused_parens)]
#![allow(unused_imports)]

use frame_support::{traits::Get, weights::Weight};
use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};
use sp_std::marker::PhantomData;

pub trait WeightInfo {
fn register_reserve_asset() -> Weight;
fn unregister_reserve_asset() -> Weight;
}

/// Weight functions for `pallet_asset_registry`.
pub struct WeightInfo<T>(PhantomData<T>);
impl<T: frame_system::Config> pallet_asset_registry::WeightInfo for WeightInfo<T> {
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Storage: Assets Asset (r:1 w:0)
/// Proof: Assets Asset (max_values: None, max_size: Some(210), added: 2685, mode: MaxEncodedLen)
/// Storage: AssetRegistry AssetIdMultiLocation (r:1 w:1)
Expand Down Expand Up @@ -67,3 +72,36 @@ impl<T: frame_system::Config> pallet_asset_registry::WeightInfo for WeightInfo<T
.saturating_add(T::DbWeight::get().writes(2))
}
}

impl WeightInfo for () {
/// Storage: Assets Asset (r:1 w:0)
/// Proof: Assets Asset (max_values: None, max_size: Some(210), added: 2685, mode: MaxEncodedLen)
/// Storage: AssetRegistry AssetIdMultiLocation (r:1 w:1)
/// Proof: AssetRegistry AssetIdMultiLocation (max_values: None, max_size: Some(622), added: 3097, mode: MaxEncodedLen)
/// Storage: AssetRegistry AssetMultiLocationId (r:0 w:1)
/// Proof: AssetRegistry AssetMultiLocationId (max_values: None, max_size: Some(622), added: 3097, mode: MaxEncodedLen)
fn register_reserve_asset() -> Weight {
// Proof Size summary in bytes:
// Measured: `123`
// Estimated: `7762`
// Minimum execution time: 21_998_000 picoseconds.
Weight::from_parts(22_970_000, 0)
.saturating_add(Weight::from_parts(0, 7762))
.saturating_add(RocksDbWeight::get().reads(2))
.saturating_add(RocksDbWeight::get().writes(2))
}
/// Storage: AssetRegistry AssetIdMultiLocation (r:1 w:1)
/// Proof: AssetRegistry AssetIdMultiLocation (max_values: None, max_size: Some(622), added: 3097, mode: MaxEncodedLen)
/// Storage: AssetRegistry AssetMultiLocationId (r:0 w:1)
/// Proof: AssetRegistry AssetMultiLocationId (max_values: None, max_size: Some(622), added: 3097, mode: MaxEncodedLen)
fn unregister_reserve_asset() -> Weight {
// Proof Size summary in bytes:
// Measured: `107`
// Estimated: `4087`
// Minimum execution time: 17_862_000 picoseconds.
Weight::from_parts(18_454_000, 0)
.saturating_add(Weight::from_parts(0, 4087))
.saturating_add(RocksDbWeight::get().reads(1))
.saturating_add(RocksDbWeight::get().writes(2))
}
}
77 changes: 77 additions & 0 deletions pallets/lockdown-mode/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
[package]
name = "pallet-lockdown-mode"
version = "0.1.0"
description = "Trappist pallet for setting lockdown mode."
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/paritytech/trappist"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive",] }
scale-info = { version = "2.3.1", default-features = false, features = ["derive"] }
sp-runtime = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
sp-std = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.40" }
frame-benchmarking = { version = "4.0.0-dev", default-features = false, optional = true, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
frame-support = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
frame-system = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40", default-features = false }
pallet-assets = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
pallet-balances = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
log = "0.4.17"
xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.40" }

xcm-primitives = { path = "../../primitives/xcm", default-features = false }

[dev-dependencies]
sp-core = { version = "7.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
sp-io = { version = "7.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
sp-runtime = { version = "7.0.0", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }
pallet-remark = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.40" }


xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.40" }
xcm-simulator = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.40" }
xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.40" }
xcm-builder = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.40" }
pallet-xcm = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.40" }
polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.40" }
polkadot-runtime-parachains = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.40" }
polkadot-parachain = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.40" }

parachain-info = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40", default-features = false }
parachains-common = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40", default-features = false }
cumulus-pallet-dmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40", default-features = false }
cumulus-pallet-xcmp-queue = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40", default-features = false }
cumulus-primitives-core = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.40", default-features = false }

[features]
default = ["std"]
std = [
"codec/std",
"sp-runtime/std",
"sp-std/std",
"pallet-assets/std",
"pallet-balances/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
"xcm-primitives/std",
"xcm/std",
"xcm-executor/std",
"xcm-builder/std",
"pallet-xcm/std",
"polkadot-core-primitives/std",
"polkadot-runtime-parachains/std",
"polkadot-parachain/std",
"parachain-info/std",
"parachains-common/std",
"cumulus-pallet-dmp-queue/std",
"cumulus-pallet-xcmp-queue/std",
"cumulus-primitives-core/std",
]
runtime-benchmarks = ["frame-benchmarking/runtime-benchmarks"]
try-runtime = ["frame-support/try-runtime"]
41 changes: 41 additions & 0 deletions pallets/lockdown-mode/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Lockdown Mode Pallet

The Lockdown Mode Pallet is a Substrate module that provides functionality to lock down the runtime execution in a Substrate-based blockchain system. When the lockdown mode is activated, it filters out incoming calls and messages to ensure that only authorized actions are allowed.

## Overview

This pallet the governance of the chain to activate or deactivate a lockdown mode. When the lockdown mode is activated, incoming runtime calls and downward messages are filtered based on a preconfigured filter. Additionally, it suspends the execution of XCM (Cross-Consensus Message) messages in the `on_idle` hook.

The lockdown mode status is stored in the `LockdownModeStatus` storage item. When the lockdown mode is deactivated, the system resumes normal operations, including the execution of XCM messages in the `on_idle` hook.

## Configuration

This pallet supports configurable traits that allow customization according to specific needs.

### Types

- `RuntimeEvent`: Specifies the runtime event type.
- `LockdownModeOrigin`: Specifies the origin that is allowed to activate and deactivate the lockdown mode.
- `BlackListedCalls`: Specifies the filter used to filter incoming runtime calls in lockdown mode.
- `LockdownDmpHandler`: Specifies the handler for downward messages in lockdown mode.
- `XcmExecutorManager`: Interface to control the execution of XCMP Queue messages.


## Extrinsics

The pallet provides the following extrinsics:

- `activate_lockdown_mode`: Activates the lockdown mode. Only the specified `LockdownModeOrigin` can call this extrinsic. It updates the `LockdownModeStatus` storage item to `ACTIVATED` (true) and attempts to suspend the execution of XCM messages in the `on_idle` hook.
- `deactivate_lockdown_mode`: Deactivates the lockdown mode. Only the specified `LockdownModeOrigin` can call this extrinsic. It updates the `LockdownModeStatus` storage item to `DEACTIVATED` (false) and attempts to resume the execution of XCM messages in the `on_idle` hook.


#### Errors

Possible errors returned by the dispatchable calls are:

- `LockdownModeAlreadyActivated`: The lockdown mode is already activated.
- `LockdownModeAlreadyDeactivated`: The lockdown mode is already deactivated.

Please note that any failure to suspend or resume XCM execution in the `on_idle` hook is not treated as a fatal error that stops the function execution. Instead, it is recorded as an event `FailedToSuspendIdleXcmExecution` or `FailedToResumeIdleXcmExecution`, respectively, and the function continues its execution.

The lockdown mode can serve as a crucial tool in system maintenance or in case of emergency, when it's necessary to restrict system operation and ensure the system's security and stability.
26 changes: 26 additions & 0 deletions pallets/lockdown-mode/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

use super::*;

#[allow(unused)]
use crate::Pallet as LockdownMode;
use crate::{ACTIVATED, DEACTIVATED};
use frame_benchmarking::benchmarks;
use frame_system::RawOrigin;

benchmarks! {
activate_lockdown_mode {
LockdownModeStatus::<T>::put(DEACTIVATED);
}: activate_lockdown_mode(RawOrigin::Root)
verify {
assert_eq!(LockdownModeStatus::<T>::get(), ACTIVATED);
}

deactivate_lockdown_mode {
LockdownModeStatus::<T>::put(ACTIVATED);
}: deactivate_lockdown_mode(RawOrigin::Root)
verify {
assert_eq!(LockdownModeStatus::<T>::get(), DEACTIVATED);
}

impl_benchmark_test_suite!(LockdownMode, crate::mock::new_test_ext(), crate::mock::Test);
}
Loading