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

Commit

Permalink
Generalised proxies (#6156)
Browse files Browse the repository at this point in the history
* Initial work

* It should work

* Fix node

* Fix tests

* Initial test

* Tests

* Expunge proxy functionality from democracy and elections

* Allow different proxy types

* Repotted

* Build

* Build

* Making a start on weights

* Undo breaking change

* Line widths.

* Fix

* fix tests

* finish benchmarks?

* Storage name!

* Utility -> Proxy

* proxy weight

* add proxy weight

* remove weights

* Update transfer constraint

* Again, fix constraints

* Fix negation

* Update frame/proxy/Cargo.toml

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* Remove unneeded event.

* Grumbles

* Apply suggestions from code review

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
  • Loading branch information
3 people committed Jun 2, 2020
1 parent 3833722 commit 342caad
Show file tree
Hide file tree
Showing 20 changed files with 724 additions and 738 deletions.
17 changes: 17 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 @@ -86,6 +86,7 @@ members = [
"frame/metadata",
"frame/nicks",
"frame/offences",
"frame/proxy",
"frame/randomness-collective-flip",
"frame/recovery",
"frame/scheduler",
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 @@ -61,6 +61,7 @@ pallet-identity = { version = "2.0.0-rc2", default-features = false, path = "../
pallet-membership = { version = "2.0.0-rc2", default-features = false, path = "../../../frame/membership" }
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" }
pallet-randomness-collective-flip = { version = "2.0.0-rc2", default-features = false, path = "../../../frame/randomness-collective-flip" }
pallet-recovery = { version = "2.0.0-rc2", default-features = false, path = "../../../frame/recovery" }
pallet-session = { version = "2.0.0-rc2", features = ["historical"], path = "../../../frame/session", default-features = false }
Expand Down Expand Up @@ -111,6 +112,7 @@ std = [
"node-primitives/std",
"sp-offchain/std",
"pallet-offences/std",
"pallet-proxy/std",
"sp-core/std",
"pallet-randomness-collective-flip/std",
"sp-std/std",
Expand Down Expand Up @@ -149,6 +151,7 @@ runtime-benchmarks = [
"pallet-elections-phragmen/runtime-benchmarks",
"pallet-identity/runtime-benchmarks",
"pallet-im-online/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-society/runtime-benchmarks",
"pallet-staking/runtime-benchmarks",
Expand Down
61 changes: 56 additions & 5 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@

use sp_std::prelude::*;
use frame_support::{
construct_runtime, parameter_types, debug,
construct_runtime, parameter_types, debug, RuntimeDebug,
weights::{
Weight, IdentityFee,
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
},
traits::{Currency, Imbalance, KeyOwnerProofSystem, OnUnbalanced, Randomness, LockIdentifier},
};
use codec::{Encode, Decode};
use sp_core::{
crypto::KeyTypeId,
u32_trait::{_1, _2, _3, _4},
Expand Down Expand Up @@ -60,7 +61,6 @@ use pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo;
use pallet_contracts_rpc_runtime_api::ContractExecResult;
use pallet_session::{historical as pallet_session_historical};
use sp_inherents::{InherentData, CheckInherentsResult};
use codec::Encode;
use static_assertions::const_assert;

#[cfg(any(feature = "std", test))]
Expand All @@ -79,6 +79,7 @@ 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 @@ -168,11 +169,13 @@ 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 }

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

Expand All @@ -186,6 +189,52 @@ impl pallet_utility::Trait for Runtime {
type IsCallable = ();
}

parameter_types! {
// One storage item; key size 32, value size 8; .
pub const ProxyDepositBase: Balance = deposit(1, 8);
// Additional storage item size of 33 bytes.
pub const ProxyDepositFactor: Balance = deposit(0, 33);
pub const MaxProxies: u16 = 32;
}

/// The type used to represent the kinds of proxying allowed.
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, RuntimeDebug)]
pub enum ProxyType {
Any,
NonTransfer,
Governance,
Staking,
}
impl Default for ProxyType { fn default() -> Self { Self::Any } }
impl InstanceFilter<Call> for ProxyType {
fn filter(&self, c: &Call) -> bool {
match self {
ProxyType::Any => true,
ProxyType::NonTransfer => !matches!(c,
Call::Balances(..) | Call::Utility(..)
| Call::Vesting(pallet_vesting::Call::vested_transfer(..))
| Call::Indices(pallet_indices::Call::transfer(..))
),
ProxyType::Governance => matches!(c,
Call::Democracy(..) | Call::Council(..) | Call::Society(..)
| Call::TechnicalCommittee(..) | Call::Elections(..) | Call::Treasury(..)
),
ProxyType::Staking => matches!(c, Call::Staking(..)),
}
}
}

impl pallet_proxy::Trait for Runtime {
type Event = Event;
type Call = Call;
type Currency = Balances;
type IsCallable = ();
type ProxyType = ProxyType;
type ProxyDepositBase = ProxyDepositBase;
type ProxyDepositFactor = ProxyDepositFactor;
type MaxProxies = MaxProxies;
}

parameter_types! {
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * MaximumBlockWeight::get();
}
Expand Down Expand Up @@ -759,6 +808,7 @@ construct_runtime!(
Recovery: pallet_recovery::{Module, Call, Storage, Event<T>},
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},
}
);

Expand Down Expand Up @@ -1009,6 +1059,7 @@ impl_runtime_apis! {
add_benchmark!(params, batches, b"identity", Identity);
add_benchmark!(params, batches, b"im-online", ImOnline);
add_benchmark!(params, batches, b"offences", OffencesBench::<Runtime>);
add_benchmark!(params, batches, b"proxy", Proxy);
add_benchmark!(params, batches, b"scheduler", Scheduler);
add_benchmark!(params, batches, b"session", SessionBench::<Runtime>);
add_benchmark!(params, batches, b"staking", Staking);
Expand Down
13 changes: 8 additions & 5 deletions client/network/test/src/block_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ fn import_single_good_block_works() {

match import_single_block(
&mut substrate_test_runtime_client::new(),
BlockOrigin::File, block,
&mut PassThroughVerifier(true),
BlockOrigin::File,
block,
&mut PassThroughVerifier(true)
) {
Ok(BlockImportResult::ImportedUnknown(ref num, ref aux, ref org))
if *num == number && *aux == expected_aux && *org == Some(peer_id) => {}
Expand All @@ -70,7 +71,8 @@ fn import_single_good_block_works() {
fn import_single_good_known_block_is_ignored() {
let (mut client, _hash, number, _, block) = prepare_good_block();
match import_single_block(
&mut client, BlockOrigin::File,
&mut client,
BlockOrigin::File,
block,
&mut PassThroughVerifier(true)
) {
Expand All @@ -85,8 +87,9 @@ fn import_single_good_block_without_header_fails() {
block.header = None;
match import_single_block(
&mut substrate_test_runtime_client::new(),
BlockOrigin::File, block,
&mut PassThroughVerifier(true),
BlockOrigin::File,
block,
&mut PassThroughVerifier(true)
) {
Err(BlockImportError::IncompleteHeader(ref org)) if *org == Some(peer_id) => {}
_ => panic!()
Expand Down
9 changes: 3 additions & 6 deletions frame/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1257,12 +1257,9 @@ where
) {
if amount.is_zero() || reasons.is_none() { return }
let mut new_lock = Some(BalanceLock { id, amount, reasons: reasons.into() });
let mut locks = Self::locks(who).into_iter().filter_map(|l|
if l.id == id {
new_lock.take()
} else {
Some(l)
}).collect::<Vec<_>>();
let mut locks = Self::locks(who).into_iter()
.filter_map(|l| if l.id == id { new_lock.take() } else { Some(l) })
.collect::<Vec<_>>();
if let Some(lock) = new_lock {
locks.push(lock)
}
Expand Down
Loading

0 comments on commit 342caad

Please sign in to comment.