Skip to content

Commit

Permalink
Update proxy filter (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
AurevoirXavier authored Jan 11, 2023
1 parent db36081 commit 7982fa7
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 36 deletions.
4 changes: 2 additions & 2 deletions node/src/chain_spec/crab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ pub fn genesis_config() -> ChainSpec {
)],
..Default::default()
},
vesting: Default::default(),

// Consensus stuff.
staking: StakingConfig {
Expand Down Expand Up @@ -193,7 +194,6 @@ pub fn genesis_config() -> ChainSpec {

// Utility stuff.
sudo: SudoConfig { key: Some(array_bytes::hex_n_into_unchecked(ALITH)) },
vesting: Default::default(),

// XCM stuff.
polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },
Expand Down Expand Up @@ -252,6 +252,7 @@ fn testnet_genesis(
)],
..Default::default()
},
vesting: Default::default(),

// Consensus stuff.
staking: StakingConfig {
Expand Down Expand Up @@ -287,7 +288,6 @@ fn testnet_genesis(

// Utility stuff.
sudo: SudoConfig { key: Some(array_bytes::hex_n_into_unchecked(ALITH)) },
vesting: Default::default(),

// XCM stuff.
polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },
Expand Down
4 changes: 2 additions & 2 deletions node/src/chain_spec/darwinia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ pub fn genesis_config() -> ChainSpec {
)],
..Default::default()
},
vesting: Default::default(),

// Consensus stuff.
staking: StakingConfig {
Expand Down Expand Up @@ -193,7 +194,6 @@ pub fn genesis_config() -> ChainSpec {

// Utility stuff.
sudo: SudoConfig { key: Some(array_bytes::hex_n_into_unchecked(ALITH)) },
vesting: Default::default(),

// XCM stuff.
polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },
Expand Down Expand Up @@ -252,6 +252,7 @@ fn testnet_genesis(
)],
..Default::default()
},
vesting: Default::default(),

// Consensus stuff.
staking: StakingConfig {
Expand Down Expand Up @@ -287,7 +288,6 @@ fn testnet_genesis(

// Utility stuff.
sudo: SudoConfig { key: Some(array_bytes::hex_n_into_unchecked(ALITH)) },
vesting: Default::default(),

// XCM stuff.
polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },
Expand Down
4 changes: 2 additions & 2 deletions node/src/chain_spec/pangolin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ pub fn genesis_config() -> ChainSpec {
)],
..Default::default()
},
vesting: Default::default(),

// Consensus stuff.
staking: StakingConfig {
Expand Down Expand Up @@ -193,7 +194,6 @@ pub fn genesis_config() -> ChainSpec {

// Utility stuff.
sudo: SudoConfig { key: Some(array_bytes::hex_n_into_unchecked(ALITH)) },
vesting: Default::default(),

// XCM stuff.
polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },
Expand Down Expand Up @@ -246,6 +246,7 @@ fn testnet_genesis(
)],
..Default::default()
},
vesting: Default::default(),

// Consensus stuff.
staking: StakingConfig {
Expand Down Expand Up @@ -281,7 +282,6 @@ fn testnet_genesis(

// Utility stuff.
sudo: SudoConfig { key: Some(array_bytes::hex_n_into_unchecked(ALITH)) },
vesting: Default::default(),

// XCM stuff.
polkadot_xcm: PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },
Expand Down
2 changes: 1 addition & 1 deletion runtime/crab/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ frame_support::construct_runtime! {
Balances: pallet_balances = 5,
TransactionPayment: pallet_transaction_payment = 6,
Assets: pallet_assets = 34,
Vesting: pallet_vesting = 20,
Deposit: darwinia_deposit = 40,
AccountMigration: darwinia_account_migration = 41,

Expand All @@ -255,7 +256,6 @@ frame_support::construct_runtime! {

// Utility stuff.
Sudo: pallet_sudo = 19,
Vesting: pallet_vesting = 20,
Utility: pallet_utility = 21,
Identity: pallet_identity = 22,
Scheduler: pallet_scheduler = 23,
Expand Down
4 changes: 2 additions & 2 deletions runtime/crab/src/pallets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ mod transaction_payment;
mod assets;
pub use assets::*;

mod vesting;

mod deposit;

mod account_migration;
Expand Down Expand Up @@ -79,8 +81,6 @@ mod tips;
// Utility stuff.
mod sudo;

mod vesting;

mod utility;

mod identity;
Expand Down
59 changes: 52 additions & 7 deletions runtime/crab/src/pallets/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,68 @@ pub enum ProxyType {
Any,
NonTransfer,
Governance,
Staking,
IdentityJudgement,
EthereumBridge,
CancelProxy,
EcdsaBridge,
SubstrateBridge,
}
impl Default for ProxyType {
fn default() -> Self {
Self::Any
}
}
impl frame_support::traits::InstanceFilter<RuntimeCall> for ProxyType {
// TODO: configure filter
fn filter(&self, _c: &RuntimeCall) -> bool {
fn filter(&self, c: &RuntimeCall) -> bool {
match self {
ProxyType::Any => true,
ProxyType::NonTransfer => true,
ProxyType::Governance => true,
ProxyType::IdentityJudgement => true,
ProxyType::EthereumBridge => true,
ProxyType::NonTransfer => !matches!(
c,
RuntimeCall::Balances(..)
| RuntimeCall::Assets(..)
| RuntimeCall::Vesting(pallet_vesting::Call::vested_transfer { .. })
| RuntimeCall::Deposit(..)
| RuntimeCall::Staking(..)
// Might contains transfer {
| RuntimeCall::Utility(..)
| RuntimeCall::Proxy(..)
| RuntimeCall::Multisig(..)
| RuntimeCall::PolkadotXcm(..)
| RuntimeCall::Ethereum(..) // }
),
ProxyType::Governance => matches!(
c,
RuntimeCall::Democracy(..)
| RuntimeCall::Council(..)
| RuntimeCall::TechnicalCommittee(..)
| RuntimeCall::PhragmenElection(..)
| RuntimeCall::Treasury(..)
| RuntimeCall::Tips(..)
),
ProxyType::Staking => {
matches!(
c,
RuntimeCall::Session(..) | RuntimeCall::Deposit(..) | RuntimeCall::Staking(..)
)
},
ProxyType::IdentityJudgement =>
matches!(c, RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. })),
ProxyType::CancelProxy => {
matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }))
},
ProxyType::EcdsaBridge => {
matches!(c, RuntimeCall::EcdsaAuthority(..))
},
ProxyType::SubstrateBridge => {
matches!(
c,
RuntimeCall::BridgePolkadotGrandpa(..)
| RuntimeCall::BridgePolkadotParachain(..)
| RuntimeCall::BridgeDarwiniaMessages(..)
| RuntimeCall::BridgeDarwiniaDispatch(..)
| RuntimeCall::DarwiniaFeeMarket(..)
)
},
}
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/darwinia/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ frame_support::construct_runtime! {
Balances: pallet_balances = 5,
TransactionPayment: pallet_transaction_payment = 6,
Assets: pallet_assets = 34,
Vesting: pallet_vesting = 20,
Deposit: darwinia_deposit = 40,
AccountMigration: darwinia_account_migration = 41,

Expand All @@ -255,7 +256,6 @@ frame_support::construct_runtime! {

// Utility stuff.
Sudo: pallet_sudo = 19,
Vesting: pallet_vesting = 20,
Utility: pallet_utility = 21,
Identity: pallet_identity = 22,
Scheduler: pallet_scheduler = 23,
Expand Down
4 changes: 2 additions & 2 deletions runtime/darwinia/src/pallets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ mod transaction_payment;
mod assets;
pub use assets::*;

mod vesting;

mod deposit;

mod account_migration;
Expand Down Expand Up @@ -79,8 +81,6 @@ mod tips;
// Utility stuff.
mod sudo;

mod vesting;

mod utility;

mod identity;
Expand Down
59 changes: 52 additions & 7 deletions runtime/darwinia/src/pallets/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,68 @@ pub enum ProxyType {
Any,
NonTransfer,
Governance,
Staking,
IdentityJudgement,
EthereumBridge,
CancelProxy,
EcdsaBridge,
SubstrateBridge,
}
impl Default for ProxyType {
fn default() -> Self {
Self::Any
}
}
impl frame_support::traits::InstanceFilter<RuntimeCall> for ProxyType {
// TODO: configure filter
fn filter(&self, _c: &RuntimeCall) -> bool {
fn filter(&self, c: &RuntimeCall) -> bool {
match self {
ProxyType::Any => true,
ProxyType::NonTransfer => true,
ProxyType::Governance => true,
ProxyType::IdentityJudgement => true,
ProxyType::EthereumBridge => true,
ProxyType::NonTransfer => !matches!(
c,
RuntimeCall::Balances(..)
| RuntimeCall::Assets(..)
| RuntimeCall::Vesting(pallet_vesting::Call::vested_transfer { .. })
| RuntimeCall::Deposit(..)
| RuntimeCall::Staking(..)
// Might contains transfer {
| RuntimeCall::Utility(..)
| RuntimeCall::Proxy(..)
| RuntimeCall::Multisig(..)
| RuntimeCall::PolkadotXcm(..)
| RuntimeCall::Ethereum(..) // }
),
ProxyType::Governance => matches!(
c,
RuntimeCall::Democracy(..)
| RuntimeCall::Council(..)
| RuntimeCall::TechnicalCommittee(..)
| RuntimeCall::PhragmenElection(..)
| RuntimeCall::Treasury(..)
| RuntimeCall::Tips(..)
),
ProxyType::Staking => {
matches!(
c,
RuntimeCall::Session(..) | RuntimeCall::Deposit(..) | RuntimeCall::Staking(..)
)
},
ProxyType::IdentityJudgement =>
matches!(c, RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. })),
ProxyType::CancelProxy => {
matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }))
},
ProxyType::EcdsaBridge => {
matches!(c, RuntimeCall::EcdsaAuthority(..))
},
ProxyType::SubstrateBridge => {
matches!(
c,
RuntimeCall::BridgeKusamaGrandpa(..)
| RuntimeCall::BridgeKusamaParachain(..)
| RuntimeCall::BridgeCrabMessages(..)
| RuntimeCall::BridgeCrabDispatch(..)
| RuntimeCall::CrabFeeMarket(..)
)
},
}
}

Expand Down
2 changes: 1 addition & 1 deletion runtime/pangolin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ frame_support::construct_runtime! {
Balances: pallet_balances = 5,
TransactionPayment: pallet_transaction_payment = 6,
Assets: pallet_assets = 34,
Vesting: pallet_vesting = 20,
Deposit: darwinia_deposit = 40,
AccountMigration: darwinia_account_migration = 41,

Expand All @@ -252,7 +253,6 @@ frame_support::construct_runtime! {

// Utility stuff.
Sudo: pallet_sudo = 19,
Vesting: pallet_vesting = 20,
Utility: pallet_utility = 21,
Identity: pallet_identity = 22,
Scheduler: pallet_scheduler = 23,
Expand Down
4 changes: 2 additions & 2 deletions runtime/pangolin/src/pallets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ mod transaction_payment;
mod assets;
pub use assets::*;

mod vesting;

mod deposit;

mod account_migration;
Expand Down Expand Up @@ -80,8 +82,6 @@ mod tips;
// Utility stuff.
mod sudo;

mod vesting;

mod utility;

mod identity;
Expand Down
Loading

0 comments on commit 7982fa7

Please sign in to comment.