Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Introduce stacked filtering (#6273)
Browse files Browse the repository at this point in the history
* Introduce stacked filtering.

* Benchmarks

* Remove unneeded crates

* Fix proxy type's permissiveness checks.

* Repot multisig to make utility stateless.

* Repot filter stack impl into macro

* Fix wasm build

* Tests

* Final test.

* Tests for the macro

* Fix test

* Line width

* Fix

* Update frame/multisig/src/benchmarking.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Update primitives/std/with_std.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Grumble

* Update frame/support/src/traits.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update frame/support/src/traits.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update frame/support/src/traits.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update frame/support/src/traits.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update frame/support/src/traits.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Update frame/multisig/src/tests.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Update frame/multisig/src/tests.rs

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>

* Grumble

* Migration

* Grumble

* Comments

* Migration

* Fix

* Fix

* Line width

* Allow unused

* Update frame/multisig/src/lib.rs

Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>

* Fix up grumble.

* Remove Utility constraint in NonTransfer

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Alexander Popiak <alexander.popiak@parity.io>
  • Loading branch information
4 people authored Jun 8, 2020
1 parent 9fe0da5 commit 39a3372
Show file tree
Hide file tree
Showing 19 changed files with 1,623 additions and 883 deletions.
18 changes: 18 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ members = [
"frame/indices",
"frame/membership",
"frame/metadata",
"frame/multisig",
"frame/nicks",
"frame/offences",
"frame/proxy",
Expand Down
3 changes: 3 additions & 0 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pallet-im-online = { version = "2.0.0-rc2", default-features = false, path = "..
pallet-indices = { version = "2.0.0-rc2", default-features = false, path = "../../../frame/indices" }
pallet-identity = { version = "2.0.0-rc2", default-features = false, path = "../../../frame/identity" }
pallet-membership = { version = "2.0.0-rc2", default-features = false, path = "../../../frame/membership" }
pallet-multisig = { version = "2.0.0-rc2", default-features = false, path = "../../../frame/multisig" }
pallet-offences = { version = "2.0.0-rc2", default-features = false, path = "../../../frame/offences" }
pallet-offences-benchmarking = { version = "2.0.0-rc2", path = "../../../frame/offences/benchmarking", default-features = false, optional = true }
pallet-proxy = { version = "2.0.0-rc2", default-features = false, path = "../../../frame/proxy" }
Expand Down Expand Up @@ -108,6 +109,7 @@ std = [
"pallet-indices/std",
"sp-inherents/std",
"pallet-membership/std",
"pallet-multisig/std",
"pallet-identity/std",
"node-primitives/std",
"sp-offchain/std",
Expand Down Expand Up @@ -151,6 +153,7 @@ runtime-benchmarks = [
"pallet-elections-phragmen/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
"pallet-im-online/runtime-benchmarks",
"pallet-multisig/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-society/runtime-benchmarks",
Expand Down
4 changes: 4 additions & 0 deletions bin/node/runtime/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ pub mod currency {
pub const MILLICENTS: Balance = 1_000_000_000;
pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent.
pub const DOLLARS: Balance = 100 * CENTS;

pub const fn deposit(items: u32, bytes: u32) -> Balance {
items as Balance * 15 * CENTS + (bytes as Balance) * 6 * CENTS
}
}

/// Time.
Expand Down
60 changes: 42 additions & 18 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#![recursion_limit="256"]

use sp_std::prelude::*;

use frame_support::{
construct_runtime, parameter_types, debug, RuntimeDebug,
weights::{
Expand All @@ -31,6 +32,7 @@ use frame_support::{
},
traits::{Currency, Imbalance, KeyOwnerProofSystem, OnUnbalanced, Randomness, LockIdentifier},
};
use frame_support::traits::{Filter, InstanceFilter};
use codec::{Encode, Decode};
use sp_core::{
crypto::KeyTypeId,
Expand Down Expand Up @@ -79,7 +81,6 @@ use impls::{CurrencyToVoteHandler, Author, TargetedFeeAdjustment};
/// Constant values used within the runtime.
pub mod constants;
use constants::{time::*, currency::*};
use frame_support::traits::InstanceFilter;

// Make the WASM binary available.
#[cfg(feature = "std")]
Expand Down Expand Up @@ -111,6 +112,15 @@ pub fn native_version() -> NativeVersion {

type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;

pub struct BaseFilter;
impl Filter<Call> for BaseFilter {
fn filter(_call: &Call) -> bool {
true
}
}
pub struct IsCallable;
frame_support::impl_filter_stack!(IsCallable, BaseFilter, Call, is_callable);

pub struct DealWithFees;
impl OnUnbalanced<NegativeImbalance> for DealWithFees {
fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item=NegativeImbalance>) {
Expand Down Expand Up @@ -169,24 +179,28 @@ impl frame_system::Trait for Runtime {
type OnKilledAccount = ();
}

const fn deposit(items: u32, bytes: u32) -> Balance { items as Balance * 15 * CENTS + (bytes as Balance) * 6 * CENTS }
impl pallet_utility::Trait for Runtime {
type Event = Event;
type Call = Call;
type IsCallable = IsCallable;
}

parameter_types! {
// One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes.
pub const MultisigDepositBase: Balance = deposit(1, 88);
pub const DepositBase: Balance = deposit(1, 88);
// Additional storage item size of 32 bytes.
pub const MultisigDepositFactor: Balance = deposit(0, 32);
pub const DepositFactor: Balance = deposit(0, 32);
pub const MaxSignatories: u16 = 100;
}

impl pallet_utility::Trait for Runtime {
impl pallet_multisig::Trait for Runtime {
type Event = Event;
type Call = Call;
type Currency = Balances;
type MultisigDepositBase = MultisigDepositBase;
type MultisigDepositFactor = MultisigDepositFactor;
type DepositBase = DepositBase;
type DepositFactor = DepositFactor;
type MaxSignatories = MaxSignatories;
type IsCallable = ();
type IsCallable = IsCallable;
}

parameter_types! {
Expand All @@ -211,8 +225,7 @@ impl InstanceFilter<Call> for ProxyType {
match self {
ProxyType::Any => true,
ProxyType::NonTransfer => !matches!(c,
Call::Balances(..) | Call::Utility(..)
| Call::Vesting(pallet_vesting::Call::vested_transfer(..))
Call::Balances(..) | Call::Vesting(pallet_vesting::Call::vested_transfer(..))
| Call::Indices(pallet_indices::Call::transfer(..))
),
ProxyType::Governance => matches!(c,
Expand All @@ -222,13 +235,22 @@ impl InstanceFilter<Call> for ProxyType {
ProxyType::Staking => matches!(c, Call::Staking(..)),
}
}
fn is_superset(&self, o: &Self) -> bool {
match (self, o) {
(x, y) if x == y => true,
(ProxyType::Any, _) => true,
(_, ProxyType::Any) => false,
(ProxyType::NonTransfer, _) => true,
_ => false,
}
}
}

impl pallet_proxy::Trait for Runtime {
type Event = Event;
type Call = Call;
type Currency = Balances;
type IsCallable = ();
type IsCallable = IsCallable;
type ProxyType = ProxyType;
type ProxyDepositBase = ProxyDepositBase;
type ProxyDepositFactor = ProxyDepositFactor;
Expand Down Expand Up @@ -263,9 +285,9 @@ parameter_types! {

impl pallet_indices::Trait for Runtime {
type AccountIndex = AccountIndex;
type Event = Event;
type Currency = Balances;
type Deposit = IndexDeposit;
type Event = Event;
}

parameter_types! {
Expand Down Expand Up @@ -341,11 +363,11 @@ impl pallet_session::Trait for Runtime {
type ValidatorId = <Self as frame_system::Trait>::AccountId;
type ValidatorIdOf = pallet_staking::StashOf<Self>;
type ShouldEndSession = Babe;
type NextSessionRotation = Babe;
type SessionManager = pallet_session::historical::NoteHistoricalRoot<Self, Staking>;
type SessionHandler = <SessionKeys as OpaqueKeys>::KeyTypeIdProviders;
type Keys = SessionKeys;
type DisabledValidatorsThreshold = DisabledValidatorsThreshold;
type NextSessionRotation = Babe;
}

impl pallet_session::historical::Trait for Runtime {
Expand Down Expand Up @@ -474,8 +496,8 @@ parameter_types! {
const_assert!(DesiredMembers::get() <= pallet_collective::MAX_MEMBERS);

impl pallet_elections_phragmen::Trait for Runtime {
type ModuleId = ElectionsPhragmenModuleId;
type Event = Event;
type ModuleId = ElectionsPhragmenModuleId;
type Currency = Balances;
type ChangeMembers = Council;
// NOTE: this implies that council's genesis members cannot be set directly and must come from
Expand Down Expand Up @@ -530,6 +552,7 @@ parameter_types! {
}

impl pallet_treasury::Trait for Runtime {
type ModuleId = TreasuryModuleId;
type Currency = Balances;
type ApproveOrigin = pallet_collective::EnsureMembers<_4, AccountId, CouncilCollective>;
type RejectOrigin = pallet_collective::EnsureMembers<_2, AccountId, CouncilCollective>;
Expand All @@ -544,7 +567,6 @@ impl pallet_treasury::Trait for Runtime {
type ProposalBondMinimum = ProposalBondMinimum;
type SpendPeriod = SpendPeriod;
type Burn = Burn;
type ModuleId = TreasuryModuleId;
}

parameter_types! {
Expand Down Expand Up @@ -635,8 +657,8 @@ impl frame_system::offchain::SigningTypes for Runtime {
impl<C> frame_system::offchain::SendTransactionTypes<C> for Runtime where
Call: From<C>,
{
type OverarchingCall = Call;
type Extrinsic = UncheckedExtrinsic;
type OverarchingCall = Call;
}

impl pallet_im_online::Trait for Runtime {
Expand Down Expand Up @@ -746,6 +768,7 @@ parameter_types! {

impl pallet_society::Trait for Runtime {
type Event = Event;
type ModuleId = SocietyModuleId;
type Currency = Balances;
type Randomness = RandomnessCollectiveFlip;
type CandidateDeposit = CandidateDeposit;
Expand All @@ -758,7 +781,6 @@ impl pallet_society::Trait for Runtime {
type FounderSetOrigin = pallet_collective::EnsureProportionMoreThan<_1, _2, AccountId, CouncilCollective>;
type SuspensionJudgementOrigin = pallet_society::EnsureFounder<Runtime>;
type ChallengePeriod = ChallengePeriod;
type ModuleId = SocietyModuleId;
}

parameter_types! {
Expand All @@ -779,7 +801,7 @@ construct_runtime!(
UncheckedExtrinsic = UncheckedExtrinsic
{
System: frame_system::{Module, Call, Config, Storage, Event<T>},
Utility: pallet_utility::{Module, Call, Storage, Event<T>},
Utility: pallet_utility::{Module, Call, Event},
Babe: pallet_babe::{Module, Call, Storage, Config, Inherent(Timestamp)},
Timestamp: pallet_timestamp::{Module, Call, Storage, Inherent},
Authorship: pallet_authorship::{Module, Call, Storage, Inherent},
Expand Down Expand Up @@ -809,6 +831,7 @@ construct_runtime!(
Vesting: pallet_vesting::{Module, Call, Storage, Event<T>, Config<T>},
Scheduler: pallet_scheduler::{Module, Call, Storage, Event<T>},
Proxy: pallet_proxy::{Module, Call, Storage, Event<T>},
Multisig: pallet_multisig::{Module, Call, Storage, Event<T>},
}
);

Expand Down Expand Up @@ -1058,6 +1081,7 @@ impl_runtime_apis! {
add_benchmark!(params, batches, b"elections", Elections);
add_benchmark!(params, batches, b"identity", Identity);
add_benchmark!(params, batches, b"im-online", ImOnline);
add_benchmark!(params, batches, b"multisig", Multisig);
add_benchmark!(params, batches, b"offences", OffencesBench::<Runtime>);
add_benchmark!(params, batches, b"proxy", Proxy);
add_benchmark!(params, batches, b"scheduler", Scheduler);
Expand Down
2 changes: 1 addition & 1 deletion frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ impl<T: Trait<I>, I: Instance> Module<T, I> {
///
/// NOTE: LOW-LEVEL: This will not attempt to maintain total issuance. It is expected that
/// the caller will do this.
fn mutate_account<R>(
pub fn mutate_account<R>(
who: &T::AccountId,
f: impl FnOnce(&mut AccountData<T::Balance>) -> R
) -> R {
Expand Down
44 changes: 44 additions & 0 deletions frame/multisig/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
[package]
name = "pallet-multisig"
version = "2.0.0-rc2"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
license = "Apache-2.0"
homepage = "https://substrate.dev"
repository = "https://github.com/paritytech/substrate/"
description = "FRAME multi-signature dispatch pallet"

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

[dependencies]
serde = { version = "1.0.101", optional = true }
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false }
frame-support = { version = "2.0.0-rc2", default-features = false, path = "../support" }
frame-system = { version = "2.0.0-rc2", default-features = false, path = "../system" }
sp-core = { version = "2.0.0-rc2", default-features = false, path = "../../primitives/core" }
sp-runtime = { version = "2.0.0-rc2", default-features = false, path = "../../primitives/runtime" }
sp-std = { version = "2.0.0-rc2", default-features = false, path = "../../primitives/std" }
sp-io = { version = "2.0.0-rc2", default-features = false, path = "../../primitives/io" }

frame-benchmarking = { version = "2.0.0-rc2", default-features = false, path = "../benchmarking", optional = true }

[dev-dependencies]
sp-core = { version = "2.0.0-rc2", path = "../../primitives/core" }
pallet-balances = { version = "2.0.0-rc2", path = "../balances" }

[features]
default = ["std"]
std = [
"serde",
"codec/std",
"sp-runtime/std",
"frame-support/std",
"frame-system/std",
"sp-io/std",
"sp-std/std"
]
runtime-benchmarks = [
"frame-benchmarking",
"frame-support/runtime-benchmarks",
]
Loading

0 comments on commit 39a3372

Please sign in to comment.