Skip to content

Commit ffcce85

Browse files
gavofyorkseerscodeNikVolf
authored
Filter calls in utility (paritytech#6131)
* Filter calls. * Remove old proxy code * Docs and repot * Update frame/utility/src/tests.rs Co-authored-by: Marcio Diaz <marcio.diaz@gmail.com> * fix test * Grumble * Bump runtime version * fix * Attempt general fix Co-authored-by: Marcio Diaz <marcio.diaz@gmail.com> Co-authored-by: NikVolf <nikvolf@gmail.com>
1 parent 3dedc03 commit ffcce85

File tree

11 files changed

+92
-17
lines changed

11 files changed

+92
-17
lines changed

bin/node/cli/tests/build_spec_works.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn build_spec_works() {
2525
let base_path = tempdir().expect("could not create a temp dir");
2626

2727
let output = Command::new(cargo_bin("substrate"))
28-
.args(&["build-spec", "--rc1", "-d"])
28+
.args(&["build-spec", "--dev", "-d"])
2929
.arg(base_path.path())
3030
.output()
3131
.unwrap();

bin/node/cli/tests/check_block_works.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn check_block_works() {
3131
common::run_dev_node_for_a_while(base_path.path());
3232

3333
let status = Command::new(cargo_bin("substrate"))
34-
.args(&["check-block", "--rc1", "--pruning", "archive", "-d"])
34+
.args(&["check-block", "--dev", "--pruning", "archive", "-d"])
3535
.arg(base_path.path())
3636
.arg("1")
3737
.status()

bin/node/cli/tests/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub fn run_dev_node_for_a_while(base_path: &Path) {
5151
let mut cmd = Command::new(cargo_bin("substrate"));
5252

5353
let mut cmd = cmd
54-
.args(&["--rc1"])
54+
.args(&["--dev"])
5555
.arg("-d")
5656
.arg(base_path)
5757
.spawn()

bin/node/cli/tests/export_import_flow.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ impl<'a> ExportImportRevertExecutor<'a> {
8282
let sub_command_str = sub_command.to_string();
8383
// Adding "--binary" if need be.
8484
let arguments: Vec<&str> = match format_opt {
85-
FormatOpt::Binary => vec![&sub_command_str, "--rc1", "--pruning", "archive", "--binary", "-d"],
86-
FormatOpt::Json => vec![&sub_command_str, "--rc1", "--pruning", "archive", "-d"],
85+
FormatOpt::Binary => vec![&sub_command_str, "--dev", "--pruning", "archive", "--binary", "-d"],
86+
FormatOpt::Json => vec![&sub_command_str, "--dev", "--pruning", "archive", "-d"],
8787
};
8888

8989
let tmp: TempDir;
@@ -136,7 +136,7 @@ impl<'a> ExportImportRevertExecutor<'a> {
136136
let _ = fs::remove_dir_all(&self.db_path);
137137
}
138138

139-
/// Runs the `import-blocks` command, asserting that an error was found or
139+
/// Runs the `import-blocks` command, asserting that an error was found or
140140
/// not depending on `expected_to_fail`.
141141
fn run_import(&mut self, fmt_opt: FormatOpt, expected_to_fail: bool) {
142142
let log = self.run_block_command(SubCommand::ImportBlocks, fmt_opt, expected_to_fail);
@@ -166,7 +166,7 @@ impl<'a> ExportImportRevertExecutor<'a> {
166166
/// Runs the `revert` command.
167167
fn run_revert(&self) {
168168
let output = Command::new(cargo_bin("substrate"))
169-
.args(&["revert", "--rc1", "--pruning", "archive", "-d"])
169+
.args(&["revert", "--dev", "--pruning", "archive", "-d"])
170170
.arg(&self.base_path.path())
171171
.output()
172172
.unwrap();

bin/node/cli/tests/inspect_works.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn inspect_works() {
3131
common::run_dev_node_for_a_while(base_path.path());
3232

3333
let status = Command::new(cargo_bin("substrate"))
34-
.args(&["inspect", "--rc1", "--pruning", "archive", "-d"])
34+
.args(&["inspect", "--dev", "--pruning", "archive", "-d"])
3535
.arg(base_path.path())
3636
.args(&["block", "1"])
3737
.status()

bin/node/cli/tests/purge_chain_works.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn purge_chain_works() {
3030
common::run_dev_node_for_a_while(base_path.path());
3131

3232
let status = Command::new(cargo_bin("substrate"))
33-
.args(&["purge-chain", "--rc1", "-d"])
33+
.args(&["purge-chain", "--dev", "-d"])
3434
.arg(base_path.path())
3535
.arg("-y")
3636
.status()

bin/node/cli/tests/running_the_node_and_interrupt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn running_the_node_works_and_can_be_interrupted() {
3131
fn run_command_and_kill(signal: Signal) {
3232
let base_path = tempdir().expect("could not create a temp dir");
3333
let mut cmd = Command::new(cargo_bin("substrate"))
34-
.args(&["--rc1", "-d"])
34+
.args(&["--dev", "-d"])
3535
.arg(base_path.path())
3636
.spawn()
3737
.unwrap();

bin/node/runtime/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
9393
// and set impl_version to 0. If only runtime
9494
// implementation changes and behavior does not, then leave spec_version as
9595
// is and increment impl_version.
96-
spec_version: 250,
97-
impl_version: 2,
96+
spec_version: 251,
97+
impl_version: 0,
9898
apis: RUNTIME_API_VERSIONS,
9999
transaction_version: 1,
100100
};
@@ -179,6 +179,7 @@ impl pallet_utility::Trait for Runtime {
179179
type MultisigDepositBase = MultisigDepositBase;
180180
type MultisigDepositFactor = MultisigDepositFactor;
181181
type MaxSignatories = MaxSignatories;
182+
type IsCallable = ();
182183
}
183184

184185
parameter_types! {

frame/support/src/traits.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ use crate::storage::StorageMap;
3333
use crate::weights::Weight;
3434
use impl_trait_for_tuples::impl_for_tuples;
3535

36+
/// Simple trait for providing a filter over a reference to some type.
37+
pub trait Filter<T> {
38+
/// Determine if a given value should be allowed through the filter (returns `true`) or not.
39+
fn filter(_: &T) -> bool;
40+
}
41+
42+
impl<T> Filter<T> for () {
43+
fn filter(_: &T) -> bool { true }
44+
}
45+
3646
/// An abstraction of a value stored within storage, but possibly as part of a larger composite
3747
/// item.
3848
pub trait StoredMap<K, T> {

frame/utility/src/lib.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ use codec::{Encode, Decode};
6767
use sp_core::TypeId;
6868
use sp_io::hashing::blake2_256;
6969
use frame_support::{decl_module, decl_event, decl_error, decl_storage, Parameter, ensure, RuntimeDebug};
70-
use frame_support::{traits::{Get, ReservableCurrency, Currency},
70+
use frame_support::{traits::{Get, ReservableCurrency, Currency, Filter},
7171
weights::{Weight, GetDispatchInfo, DispatchClass, FunctionOf, Pays},
7272
dispatch::{DispatchResultWithPostInfo, DispatchErrorWithPostInfo, PostDispatchInfo},
7373
};
74-
use frame_system::{self as system, ensure_signed};
74+
use frame_system::{self as system, ensure_signed, ensure_root};
7575
use sp_runtime::{DispatchError, DispatchResult, traits::Dispatchable};
7676

7777
mod tests;
@@ -85,7 +85,8 @@ pub trait Trait: frame_system::Trait {
8585
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
8686

8787
/// The overarching call type.
88-
type Call: Parameter + Dispatchable<Origin=Self::Origin, PostInfo=PostDispatchInfo> + GetDispatchInfo + From<frame_system::Call<Self>>;
88+
type Call: Parameter + Dispatchable<Origin=Self::Origin, PostInfo=PostDispatchInfo>
89+
+ GetDispatchInfo + From<frame_system::Call<Self>>;
8990

9091
/// The currency mechanism.
9192
type Currency: ReservableCurrency<Self::AccountId>;
@@ -103,6 +104,9 @@ pub trait Trait: frame_system::Trait {
103104

104105
/// The maximum amount of signatories allowed in the multisig.
105106
type MaxSignatories: Get<u16>;
107+
108+
/// Is a given call compatible with the proxying subsystem?
109+
type IsCallable: Filter<<Self as Trait>::Call>;
106110
}
107111

108112
/// A global extrinsic index, formed as the extrinsic index within a block, together with that
@@ -164,6 +168,8 @@ decl_error! {
164168
WrongTimepoint,
165169
/// A timepoint was given, yet no multisig operation is underway.
166170
UnexpectedTimepoint,
171+
/// A call with a `false` IsCallable filter was attempted.
172+
Uncallable,
167173
}
168174
}
169175

@@ -191,6 +197,8 @@ decl_event! {
191197
/// A multisig operation has been cancelled. First param is the account that is
192198
/// cancelling, third is the multisig account, fourth is hash of the call.
193199
MultisigCancelled(AccountId, Timepoint<BlockNumber>, AccountId, CallHash),
200+
/// A call with a `false` IsCallable filter was attempted.
201+
Uncallable(u32),
194202
}
195203
}
196204

@@ -230,7 +238,8 @@ decl_module! {
230238

231239
/// Send a batch of dispatch calls.
232240
///
233-
/// This will execute until the first one fails and then stop.
241+
/// This will execute until the first one fails and then stop. Calls must fulfil the
242+
/// `IsCallable` filter unless the origin is `Root`.
234243
///
235244
/// May be called from any origin.
236245
///
@@ -266,7 +275,12 @@ decl_module! {
266275
Pays::Yes,
267276
)]
268277
fn batch(origin, calls: Vec<<T as Trait>::Call>) {
278+
let is_root = ensure_root(origin.clone()).is_ok();
269279
for (index, call) in calls.into_iter().enumerate() {
280+
if !is_root && !T::IsCallable::filter(&call) {
281+
Self::deposit_event(Event::<T>::Uncallable(index as u32));
282+
return Ok(())
283+
}
270284
let result = call.dispatch(origin.clone());
271285
if let Err(e) = result {
272286
Self::deposit_event(Event::<T>::BatchInterrupted(index as u32, e.error));
@@ -278,6 +292,8 @@ decl_module! {
278292

279293
/// Send a call through an indexed pseudonym of the sender.
280294
///
295+
/// Calls must each fulfil the `IsCallable` filter.
296+
///
281297
/// The dispatch origin for this call must be _Signed_.
282298
///
283299
/// # <weight>
@@ -293,6 +309,7 @@ decl_module! {
293309
)]
294310
fn as_sub(origin, index: u16, call: Box<<T as Trait>::Call>) -> DispatchResult {
295311
let who = ensure_signed(origin)?;
312+
ensure!(T::IsCallable::filter(&call), Error::<T>::Uncallable);
296313
let pseudonym = Self::sub_account_id(who, index);
297314
call.dispatch(frame_system::RawOrigin::Signed(pseudonym).into())
298315
.map(|_| ()).map_err(|e| e.error)
@@ -301,7 +318,8 @@ decl_module! {
301318
/// Register approval for a dispatch to be made from a deterministic composite account if
302319
/// approved by a total of `threshold - 1` of `other_signatories`.
303320
///
304-
/// If there are enough, then dispatch the call.
321+
/// If there are enough, then dispatch the call. Calls must each fulfil the `IsCallable`
322+
/// filter.
305323
///
306324
/// Payment: `MultisigDepositBase` will be reserved if this is the first approval, plus
307325
/// `threshold` times `MultisigDepositFactor`. It is returned once this dispatch happens or
@@ -364,6 +382,7 @@ decl_module! {
364382
call: Box<<T as Trait>::Call>,
365383
) -> DispatchResultWithPostInfo {
366384
let who = ensure_signed(origin)?;
385+
ensure!(T::IsCallable::filter(call.as_ref()), Error::<T>::Uncallable);
367386
ensure!(threshold >= 1, Error::<T>::ZeroThreshold);
368387
let max_sigs = T::MaxSignatories::get() as usize;
369388
ensure!(!other_signatories.is_empty(), Error::<T>::TooFewSignatories);

0 commit comments

Comments
 (0)