-
Notifications
You must be signed in to change notification settings - Fork 131
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 #286
Add proxy pallet #286
Changes from 14 commits
563908a
71dae03
bbbede6
43bff65
3c00ccc
305f31a
2370729
377da13
6037740
ddae821
53cd822
55f5a02
ad43983
622b5b3
efc4cb1
c9249b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
#[cfg(feature = "std")] | ||
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); | ||
|
||
use codec::Encode; | ||
use codec::{Decode, Encode, MaxEncodedLen}; | ||
|
||
use pallet_commitments::CanCommit; | ||
use pallet_grandpa::{ | ||
|
@@ -17,6 +17,7 @@ use frame_support::pallet_prelude::{DispatchError, DispatchResult, Get}; | |
use frame_system::{EnsureNever, EnsureRoot, RawOrigin}; | ||
|
||
use pallet_registry::CanRegisterIdentity; | ||
use scale_info::TypeInfo; | ||
use smallvec::smallvec; | ||
use sp_api::impl_runtime_apis; | ||
use sp_consensus_aura::sr25519::AuthorityId as AuraId; | ||
|
@@ -40,8 +41,8 @@ use sp_version::RuntimeVersion; | |
pub use frame_support::{ | ||
construct_runtime, parameter_types, | ||
traits::{ | ||
ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, KeyOwnerProofSystem, PrivilegeCmp, | ||
Randomness, StorageInfo, | ||
ConstBool, ConstU128, ConstU32, ConstU64, ConstU8, InstanceFilter, KeyOwnerProofSystem, | ||
PrivilegeCmp, Randomness, StorageInfo, | ||
}, | ||
weights::{ | ||
constants::{ | ||
|
@@ -50,7 +51,7 @@ pub use frame_support::{ | |
IdentityFee, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, | ||
WeightToFeePolynomial, | ||
}, | ||
StorageValue, | ||
RuntimeDebug, StorageValue, | ||
}; | ||
pub use frame_system::Call as SystemCall; | ||
pub use pallet_balances::Call as BalancesCall; | ||
|
@@ -87,6 +88,13 @@ type MemberCount = u32; | |
|
||
pub type Nonce = u32; | ||
|
||
// Method used to calculate the fee of an extrinsic | ||
pub const fn deposit(items: u32, bytes: u32) -> Balance { | ||
pub const ITEMS_FEE: Balance = 2_000 * 10_000; | ||
pub const BYTES_FEE: Balance = 100 * 10_000; | ||
items as Balance * ITEMS_FEE + bytes as Balance * BYTES_FEE | ||
} | ||
|
||
// 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 | ||
|
@@ -473,9 +481,9 @@ impl pallet_sudo::Config for Runtime { | |
|
||
parameter_types! { | ||
// One storage item; key size is 32; value is size 4+4+16+32 bytes = 56 bytes. | ||
pub const DepositBase: Balance = (1) as Balance * 2_000 * 10_000 + (88 as Balance) * 100 * 10_000; | ||
pub const DepositBase: Balance = deposit(1, 88); | ||
// Additional storage item size of 32 bytes. | ||
pub const DepositFactor: Balance = (0) as Balance * 2_000 * 10_000 + (32 as Balance) * 100 * 10_000; | ||
pub const DepositFactor: Balance = deposit(0, 32); | ||
pub const MaxSignatories: u32 = 100; | ||
} | ||
|
||
|
@@ -489,6 +497,121 @@ impl pallet_multisig::Config for Runtime { | |
type WeightInfo = pallet_multisig::weights::SubstrateWeight<Runtime>; | ||
} | ||
|
||
// Proxy Pallet config | ||
parameter_types! { | ||
// One storage item; key size sizeof(AccountId) = 32, value sizeof(Balance) = 8; 40 total | ||
pub const ProxyDepositBase: Balance = deposit(1, 40); | ||
// Adding 32 bytes + sizeof(ProxyType) = 32 + 1 | ||
pub const ProxyDepositFactor: Balance = deposit(0, 33); | ||
pub const MaxProxies: u32 = 20; // max num proxies per acct | ||
pub const MaxPending: u32 = 15 * 5; // max blocks pending ~15min | ||
// 16 bytes | ||
pub const AnnouncementDepositBase: Balance = deposit(1, 16); | ||
// 68 bytes per announcement | ||
pub const AnnouncementDepositFactor: Balance = deposit(0, 68); | ||
} | ||
|
||
#[derive( | ||
Copy, | ||
Clone, | ||
Eq, | ||
PartialEq, | ||
Ord, | ||
PartialOrd, | ||
Encode, | ||
Decode, | ||
RuntimeDebug, | ||
MaxEncodedLen, | ||
TypeInfo, | ||
)] | ||
pub enum ProxyType { | ||
Any, | ||
Owner, // Subnet owner Calls | ||
NonCritical, | ||
NonTransfer, | ||
Senate, | ||
NonFungibile, // Nothing involving moving TAO | ||
Triumvirate, | ||
Governance, // Both above governance | ||
Staking, | ||
Registration, | ||
} | ||
impl Default for ProxyType { | ||
fn default() -> Self { | ||
Self::Any | ||
} | ||
} // allow all Calls; required to be most permissive | ||
impl InstanceFilter<RuntimeCall> for ProxyType { | ||
fn filter(&self, c: &RuntimeCall) -> bool { | ||
match self { | ||
ProxyType::Any => true, | ||
ProxyType::NonTransfer => !matches!(c, RuntimeCall::Balances(..)), | ||
ProxyType::NonFungibile => !matches!( | ||
c, | ||
RuntimeCall::Balances(..) | ||
| RuntimeCall::SubtensorModule(pallet_subtensor::Call::add_stake { .. }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note to self: Rebase stao off development so we can capture this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After rebase, the NonFungibile excludes all extrinsic related to balance in Subtensor pallet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ha.. this was a note for me ! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pls add stao extrinsic in filter |
||
| RuntimeCall::SubtensorModule(pallet_subtensor::Call::remove_stake { .. }) | ||
| RuntimeCall::SubtensorModule(pallet_subtensor::Call::burned_register { .. }) | ||
| RuntimeCall::SubtensorModule(pallet_subtensor::Call::root_register { .. }) | ||
), | ||
ProxyType::Owner => matches!(c, RuntimeCall::AdminUtils(..)), | ||
ProxyType::NonCritical => !matches!( | ||
c, | ||
RuntimeCall::SubtensorModule(pallet_subtensor::Call::dissolve_network { .. }) | ||
| RuntimeCall::SubtensorModule(pallet_subtensor::Call::root_register { .. }) | ||
| RuntimeCall::SubtensorModule(pallet_subtensor::Call::burned_register { .. }) | ||
| RuntimeCall::Triumvirate(..) | ||
), | ||
ProxyType::Triumvirate => matches!( | ||
c, | ||
RuntimeCall::Triumvirate(..) | RuntimeCall::TriumvirateMembers(..) | ||
), | ||
ProxyType::Senate => matches!(c, RuntimeCall::SenateMembers(..)), | ||
ProxyType::Governance => matches!( | ||
c, | ||
RuntimeCall::SenateMembers(..) | ||
| RuntimeCall::Triumvirate(..) | ||
| RuntimeCall::TriumvirateMembers(..) | ||
), | ||
ProxyType::Staking => matches!( | ||
c, | ||
RuntimeCall::SubtensorModule(pallet_subtensor::Call::add_stake { .. }) | ||
| RuntimeCall::SubtensorModule(pallet_subtensor::Call::remove_stake { .. }) | ||
), | ||
ProxyType::Registration => matches!( | ||
c, | ||
RuntimeCall::SubtensorModule(pallet_subtensor::Call::burned_register { .. }) | ||
| RuntimeCall::SubtensorModule(pallet_subtensor::Call::register { .. }) | ||
), | ||
} | ||
} | ||
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, | ||
(ProxyType::Governance, ProxyType::Triumvirate | ProxyType::Senate) => 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 = MaxProxies; | ||
type WeightInfo = pallet_proxy::weights::SubstrateWeight<Runtime>; | ||
type MaxPending = MaxPending; | ||
type CallHasher = BlakeTwo256; | ||
type AnnouncementDepositBase = AnnouncementDepositBase; | ||
type AnnouncementDepositFactor = AnnouncementDepositFactor; | ||
} | ||
|
||
parameter_types! { | ||
pub MaximumSchedulerWeight: Weight = Perbill::from_percent(80) * | ||
BlockWeights::get().max_block; | ||
|
@@ -540,8 +663,8 @@ impl pallet_scheduler::Config for Runtime { | |
|
||
parameter_types! { | ||
pub const PreimageMaxSize: u32 = 4096 * 1024; | ||
pub const PreimageBaseDeposit: Balance = (2) as Balance * 2_000 * 10_000_000 + (64 as Balance) * 100 * 1_000_000; | ||
pub const PreimageByteDeposit: Balance = (0) as Balance * 2_000 * 10_000_000 + (1 as Balance) * 100 * 1_000_000; | ||
pub const PreimageBaseDeposit: Balance = deposit(2, 64); | ||
pub const PreimageByteDeposit: Balance = deposit(0, 1); | ||
} | ||
|
||
impl pallet_preimage::Config for Runtime { | ||
|
@@ -991,6 +1114,7 @@ construct_runtime!( | |
Multisig: pallet_multisig, | ||
Preimage: pallet_preimage, | ||
Scheduler: pallet_scheduler, | ||
Proxy: pallet_proxy, | ||
Registry: pallet_registry, | ||
Commitments: pallet_commitments, | ||
AdminUtils: pallet_admin_utils | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does this figure come from ? The calculation doesnt seem to match the comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From multisig pallet, I get the code as follows. the comments from substrate upstream. I will check if we should change it.
/// This is held for an additional storage item whose value size is
///
4 + sizeof((BlockNumber, Balance, AccountId))
bytes and whose key size is///
32 + sizeof(AccountId)
bytes.#[pallet::constant]
type DepositBase: Get<BalanceOf>;