mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 03:11:01 +00:00
Add Call Filter That Prevents Nested batch_all (#9009)
* add filter preventing nested `batch_all` * more tests * fix test * cargo run --release --features=runtime-benchmarks --manifest-path=bin/node/cli/Cargo.toml -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=pallet_utility --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./frame/utility/src/weights.rs --template=./.maintain/frame-weight-template.hbs Co-authored-by: Parity Bot <admin@parity.io>
This commit is contained in:
@@ -62,7 +62,7 @@ use sp_core::TypeId;
|
||||
use sp_io::hashing::blake2_256;
|
||||
use frame_support::{
|
||||
transactional,
|
||||
traits::{OriginTrait, UnfilteredDispatchable},
|
||||
traits::{OriginTrait, UnfilteredDispatchable, IsSubType},
|
||||
weights::{GetDispatchInfo, extract_actual_weight},
|
||||
dispatch::PostDispatchInfo,
|
||||
};
|
||||
@@ -91,7 +91,9 @@ pub mod pallet {
|
||||
/// The overarching call type.
|
||||
type Call: Parameter + Dispatchable<Origin=Self::Origin, PostInfo=PostDispatchInfo>
|
||||
+ GetDispatchInfo + From<frame_system::Call<Self>>
|
||||
+ UnfilteredDispatchable<Origin=Self::Origin>;
|
||||
+ UnfilteredDispatchable<Origin=Self::Origin>
|
||||
+ IsSubType<Call<Self>>
|
||||
+ IsType<<Self as frame_system::Config>::Call>;
|
||||
|
||||
/// Weight information for extrinsics in this pallet.
|
||||
type WeightInfo: WeightInfo;
|
||||
@@ -266,7 +268,13 @@ pub mod pallet {
|
||||
let result = if is_root {
|
||||
call.dispatch_bypass_filter(origin.clone())
|
||||
} else {
|
||||
call.dispatch(origin.clone())
|
||||
let mut filtered_origin = origin.clone();
|
||||
// Don't allow users to nest `batch_all` calls.
|
||||
filtered_origin.add_filter(move |c: &<T as frame_system::Config>::Call| {
|
||||
let c = <T as Config>::Call::from_ref(c);
|
||||
!matches!(c.is_sub_type(), Some(Call::batch_all(_)))
|
||||
});
|
||||
call.dispatch(filtered_origin)
|
||||
};
|
||||
// Add the weight of this call.
|
||||
weight = weight.saturating_add(extract_actual_weight(&result, &info));
|
||||
|
||||
Reference in New Issue
Block a user