Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proxy pallet #5122

Merged
merged 8 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion chain-metadata.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion query-node/chain-metadata/2003.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ substrate-utility = { package = 'pallet-utility', default-features = false, git
pallet-vesting = { package = 'pallet-vesting', default-features = false, git = 'https://github.com/joystream/substrate', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9' }
pallet-multisig = { package = 'pallet-multisig', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'}
pallet-staking-runtime-api = { package = 'pallet-staking-runtime-api', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'}
pallet-proxy = { package = 'pallet-proxy', default-features = false, git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9'}

# Benchmarking
frame-benchmarking = { git = 'https://github.com/joystream/substrate.git', rev = '1d0eefca86ef31b9e7727df01a6ed23ad65491e9', default-features = false, optional = true }
Expand Down Expand Up @@ -163,6 +164,7 @@ std = [
'pallet-election-provider-multi-phase/std',
'pallet-election-provider-support-benchmarking?/std',
'pallet-staking-runtime-api/std',
'pallet-proxy/std',

# Joystream
'common/std',
Expand Down Expand Up @@ -207,6 +209,7 @@ runtime-benchmarks = [
"substrate-utility/runtime-benchmarks",
"pallet-election-provider-multi-phase/runtime-benchmarks",
"pallet-election-provider-support-benchmarking/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",

# Joystream
"common/runtime-benchmarks",
Expand Down Expand Up @@ -269,6 +272,7 @@ try-runtime = [
"pallet-transaction-payment/try-runtime",
"pallet-vesting/try-runtime",
"substrate-utility/try-runtime",
"pallet-proxy/try-runtime",
# joystream
'forum/try-runtime',
'membership/try-runtime',
Expand Down
95 changes: 91 additions & 4 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ mod weights;
#[macro_use]
extern crate lazy_static; // for proposals_configuration module

use codec::Decode;
use codec::{Decode, Encode, MaxEncodedLen};
use frame_election_provider_support::{
onchain, BalancingConfig, ElectionDataProvider, SequentialPhragmen, VoteWeight,
};
use frame_support::traits::{
ConstU16, ConstU32, Contains, Currency, EitherOfDiverse, Imbalance, KeyOwnerProofSystem,
LockIdentifier, OnUnbalanced, WithdrawReasons,
ConstU16, ConstU32, Contains, Currency, EitherOfDiverse, Imbalance, InstanceFilter,
KeyOwnerProofSystem, LockIdentifier, OnUnbalanced, WithdrawReasons,
};
use frame_support::weights::{constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight};
use frame_support::{dispatch::DispatchClass, pallet_prelude::Get};
use frame_support::{dispatch::DispatchClass, pallet_prelude::Get, RuntimeDebug};
pub use weights::{
block_weights::BlockExecutionWeight, extrinsic_weights::ExtrinsicBaseWeight,
rocksdb_weights::constants::RocksDbWeight,
Expand Down Expand Up @@ -1812,6 +1812,92 @@ impl pallet_multisig::Config for Runtime {
type WeightInfo = weights::pallet_multisig::SubstrateWeight<Runtime>;
}

parameter_types! {
pub const ProxyDepositBase: Balance = dollars!(1);
pub const ProxyDepositFactor: Balance = dollars!(1);
pub const AnnouncementDepositBase: Balance = dollars!(1);
pub const AnnouncementDepositFactor: Balance = dollars!(1);
}

/// The type used to represent the kinds of proxying allowed.
#[derive(
Copy,
Clone,
Eq,
PartialEq,
Ord,
PartialOrd,
Encode,
Decode,
RuntimeDebug,
MaxEncodedLen,
scale_info::TypeInfo,
)]
pub enum ProxyType {
Any,
NonTransfer,
Governance,
Staking,
WorkingGroups,
}
impl Default for ProxyType {
fn default() -> Self {
Self::Any
}
}
impl InstanceFilter<RuntimeCall> for ProxyType {
fn filter(&self, c: &RuntimeCall) -> bool {
match self {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a Referendum proxy type?
It would allow calling only:

  • referendum.vote
  • referendum.revealVote
  • referendum.releaseVoteStake
    The Governance type is a bit more extensive

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 2a2304b

ProxyType::Any => true,
ProxyType::NonTransfer => !matches!(
c,
RuntimeCall::Balances(..)
| RuntimeCall::Vesting(pallet_vesting::Call::vested_transfer { .. })
| RuntimeCall::Content(content::Call::initialize_channel_transfer { .. })
| RuntimeCall::Content(content::Call::buy_nft { .. })
| RuntimeCall::ProjectToken(project_token::Call::transfer { .. })
),
ProxyType::Governance => matches!(
c,
RuntimeCall::Council(..)
| RuntimeCall::Referendum(..)
| RuntimeCall::ProposalsEngine(..)
),
ProxyType::Staking => matches!(c, RuntimeCall::Staking(..)),
ProxyType::WorkingGroups => matches!(
c,
RuntimeCall::StorageWorkingGroup(..)
| RuntimeCall::DistributionWorkingGroup(..)
| RuntimeCall::ContentWorkingGroup(..)
),
}
}
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::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type Currency = Balances;
type ProxyType = ProxyType;
type ProxyDepositBase = ProxyDepositBase;
type ProxyDepositFactor = ProxyDepositFactor;
type MaxProxies = ConstU32<32>;
type WeightInfo = weights::pallet_proxy::SubstrateWeight<Runtime>;
type MaxPending = ConstU32<32>;
type CallHasher = BlakeTwo256;
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
}

/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
/// the specifics of the runtime. They can then be made to be agnostic over specific formats
/// of data like extrinsics, allowing for them to continue syncing the network through upgrades
Expand Down Expand Up @@ -1882,6 +1968,7 @@ construct_runtime!(
OperationsWorkingGroupBeta: working_group::<Instance7>::{Pallet, Call, Storage, Event<T>},
OperationsWorkingGroupGamma: working_group::<Instance8>::{Pallet, Call, Storage, Event<T>},
DistributionWorkingGroup: working_group::<Instance9>::{Pallet, Call, Storage, Event<T>},
Proxy: pallet_proxy,
}
);

Expand Down
1 change: 1 addition & 0 deletions runtime/src/runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ mod benches {
[storage, Storage]
[content, Content]
[project_token, ProjectToken]
[pallet_proxy, Proxy]
);
}

Expand Down
1 change: 1 addition & 0 deletions runtime/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub mod pallet_election_provider_multi_phase;
pub mod pallet_grandpa;
pub mod pallet_im_online;
pub mod pallet_multisig;
pub mod pallet_proxy;
pub mod pallet_session;
pub mod pallet_staking;
pub mod pallet_timestamp;
Expand Down
Loading
Loading