-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of dynamic extrinsic filter (#288)
* initial commit of extrinsic-filter impl * adjustment to TOML and runtime * more comments and error types * add mock.rs * add tests * add benchmarking and weights * spaces -> tabs (why cargo fmt didn't work?) * update comment * add testcase set_mode_should_not_clear_blocked_extrinsics
- Loading branch information
1 parent
e38998a
commit 2fc9f42
Showing
10 changed files
with
1,174 additions
and
96 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
[package] | ||
name = 'pallet-extrinsic-filter' | ||
authors = ['Litentry Dev'] | ||
description = 'Pallet for dynamically filtering extrinsics' | ||
edition = '2021' | ||
homepage = 'https://litentry.com/' | ||
license = 'GPL-3.0' | ||
repository = 'https://github.com/litentry/litentry-parachain' | ||
version = '0.1.0' | ||
|
||
[dependencies] | ||
codec = { package = "parity-scale-codec", version = "2.2", default-features = false, features = ["derive", "max-encoded-len"] } | ||
scale-info = { version = "1.0", default-features = false, features = ["derive"] } | ||
|
||
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } | ||
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } | ||
|
||
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } | ||
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } | ||
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false, optional = true } | ||
|
||
[dev-dependencies] | ||
pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } | ||
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.13" } | ||
sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } | ||
sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.13", default-features = false } | ||
|
||
[features] | ||
default = ["std"] | ||
runtime-benchmarks = [ | ||
"frame-benchmarking/runtime-benchmarks", | ||
"frame-support/runtime-benchmarks", | ||
"frame-system/runtime-benchmarks", | ||
] | ||
std = [ | ||
"codec/std", | ||
"sp-std/std", | ||
"sp-runtime/std", | ||
"sp-io/std", | ||
"sp-core/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"frame-benchmarking/std", | ||
"pallet-balances/std", | ||
"pallet-timestamp/std", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2020-2022 Litentry Technologies GmbH. | ||
// This file is part of Litentry. | ||
// | ||
// Litentry is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Litentry is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Litentry. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
//! Benchmarking setup for pallet-extrinsic-filter | ||
|
||
use super::*; | ||
|
||
#[allow(unused)] | ||
use crate::Pallet as ExtrinsicFilter; | ||
use frame_benchmarking::{benchmarks, impl_benchmark_test_suite}; | ||
use frame_system::RawOrigin; | ||
use sp_std::vec; | ||
|
||
const MAX_BYTES: u32 = 1_024; | ||
|
||
fn assert_last_event<T: Config>(generic_event: <T as Config>::Event) { | ||
frame_system::Pallet::<T>::assert_last_event(generic_event.into()); | ||
} | ||
|
||
benchmarks! { | ||
block_extrinsics { | ||
let p in 1 .. MAX_BYTES; | ||
let f in 1 .. MAX_BYTES; | ||
|
||
let pallet_name_bytes = vec![0u8; p as usize]; | ||
let function_name_bytes = vec![0u8; f as usize]; | ||
}: _(RawOrigin::Root, pallet_name_bytes.clone(), Some(function_name_bytes.clone())) | ||
verify { | ||
assert_eq!( | ||
ExtrinsicFilter::<T>::blocked_extrinsics((pallet_name_bytes.clone(), function_name_bytes.clone())), | ||
Some(()) | ||
); | ||
assert_last_event::<T>(Event::ExtrinsicsBlocked { | ||
pallet_name_bytes, | ||
function_name_bytes: Some(function_name_bytes) | ||
}.into()); | ||
} | ||
|
||
unblock_extrinsics { | ||
let p in 1 .. MAX_BYTES; | ||
let f in 1 .. MAX_BYTES; | ||
|
||
let pallet_name_bytes = vec![0u8; p as usize]; | ||
let function_name_bytes = vec![0u8; f as usize]; | ||
// block them | ||
assert!(ExtrinsicFilter::<T>::block_extrinsics( | ||
RawOrigin::Root.into(), | ||
pallet_name_bytes.clone(), | ||
Some(function_name_bytes.clone()) | ||
).is_ok()); | ||
}: _(RawOrigin::Root, pallet_name_bytes.clone(), Some(function_name_bytes.clone())) | ||
verify { | ||
assert_eq!( | ||
ExtrinsicFilter::<T>::blocked_extrinsics((pallet_name_bytes.clone(), function_name_bytes.clone())), | ||
None | ||
); | ||
assert_last_event::<T>(Event::ExtrinsicsUnblocked { | ||
pallet_name_bytes, | ||
function_name_bytes: Some(function_name_bytes) | ||
}.into()); | ||
} | ||
} | ||
|
||
impl_benchmark_test_suite!(ExtrinsicFilter, crate::mock::new_test_ext(), crate::mock::Test,); |
Oops, something went wrong.