Skip to content

Commit

Permalink
Merge pull request #5122 from mnaamani/luxor-add-proxy-pallet
Browse files Browse the repository at this point in the history
Add proxy pallet
  • Loading branch information
mnaamani committed Apr 5, 2024
2 parents 3580787 + fd313dd commit dc6d1a7
Show file tree
Hide file tree
Showing 18 changed files with 1,251 additions and 411 deletions.
18 changes: 17 additions & 1 deletion 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 bin/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ authors = ['Joystream contributors']
build = 'build.rs'
edition = '2018'
name = 'joystream-node'
version = '8.5.0'
version = '8.6.0'
default-run = "joystream-node"

[[bin]]
Expand Down
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 @@ -72,6 +72,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 @@ -169,6 +170,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 @@ -213,6 +215,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 @@ -271,6 +274,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
100 changes: 96 additions & 4 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ mod weights;
#[macro_use]
extern crate lazy_static; // for proposals_configuration module

use codec::Decode;
use codec::{Decode, Encode, MaxEncodedLen};
use core::ops::Div;
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 @@ -1834,6 +1834,97 @@ 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,
Referendum,
Staking,
StorageTransactor,
}
impl Default for ProxyType {
fn default() -> Self {
Self::Any
}
}
impl InstanceFilter<RuntimeCall> for ProxyType {
fn filter(&self, c: &RuntimeCall) -> bool {
match self {
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::Referendum => matches!(
c,
RuntimeCall::Referendum(referendum::Call::vote { .. })
| RuntimeCall::Referendum(referendum::Call::reveal_vote { .. })
| RuntimeCall::Referendum(referendum::Call::release_vote_stake { .. })
),
ProxyType::Staking => matches!(c, RuntimeCall::Staking(..)),
ProxyType::StorageTransactor => matches!(
c,
RuntimeCall::Storage(storage::Call::accept_pending_data_objects { .. })
),
}
}
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 @@ -1904,6 +1995,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 @@ -126,6 +126,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

0 comments on commit dc6d1a7

Please sign in to comment.