[10] add proxy pallet

This commit is contained in:
Nikita Khateev
2023-11-20 17:39:12 +04:00
parent 999808e9d6
commit 5e4cef4117
8 changed files with 115 additions and 13 deletions
Generated
+11 -1
View File
@@ -1519,6 +1519,13 @@ dependencies = [
"unicode-width",
]
[[package]]
name = "common"
version = "0.1.0"
dependencies = [
"polkadot-core-primitives",
]
[[package]]
name = "common"
version = "0.1.0"
@@ -7304,6 +7311,7 @@ version = "0.1.0"
dependencies = [
"clap",
"color-print",
"common 0.1.0",
"cumulus-client-cli",
"cumulus-client-collator",
"cumulus-client-consensus-aura",
@@ -7359,6 +7367,7 @@ dependencies = [
name = "parachain-template-runtime"
version = "0.1.0"
dependencies = [
"common 0.1.0",
"cumulus-pallet-aura-ext",
"cumulus-pallet-dmp-queue",
"cumulus-pallet-parachain-system",
@@ -7382,6 +7391,7 @@ dependencies = [
"pallet-collator-selection",
"pallet-multisig",
"pallet-parachain-template",
"pallet-proxy",
"pallet-session",
"pallet-sudo",
"pallet-timestamp",
@@ -9483,7 +9493,7 @@ dependencies = [
"ark-serialize",
"ark-std",
"blake2 0.10.6",
"common",
"common 0.1.0 (git+https://github.com/w3f/ring-proof)",
"fflonk",
"merlin 3.0.0",
]
+1 -1
View File
@@ -1,5 +1,5 @@
[workspace]
members = ["node", "pallets/template", "runtime"]
members = [ "common", "node", "pallets/template", "runtime"]
package.edition = "2021"
package.repository = "https://github.com/paritytech/polkadot-sdk"
resolver = "2"
+12
View File
@@ -0,0 +1,12 @@
[package]
name = "common"
version = "0.1.0"
authors = ["Anonymous"]
edition.workspace = true
description = "Logic which is common to all runtimes"
license = "Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
polkadot-core-primitives = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0", default-features = false }
+16
View File
@@ -0,0 +1,16 @@
pub use currency::*;
mod currency {
use polkadot_core_primitives::Balance;
// Unit = the base number of indivisible units for balances
pub const UNIT: Balance = 1_000_000_000_000;
pub const MILLIUNIT: Balance = 1_000_000_000;
pub const MICROUNIT: Balance = 1_000_000;
/// The existential deposit. Set to 1/10 of the Connected Relay Chain.
pub const EXISTENTIAL_DEPOSIT: Balance = MILLIUNIT;
pub const fn deposit(items: u32, bytes: u32) -> Balance {
(items as Balance * 20 * UNIT + bytes as Balance * 100 * MILLIUNIT) / 100
}
}
+1
View File
@@ -20,6 +20,7 @@ futures = "0.3.28"
# Local
parachain-template-runtime = { path = "../runtime" }
common = { path = "../common" }
# Substrate
frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0", default-features = false }
+2 -1
View File
@@ -1,5 +1,6 @@
use common::EXISTENTIAL_DEPOSIT;
use cumulus_primitives_core::ParaId;
use parachain_template_runtime::{AccountId, AuraId, Signature, EXISTENTIAL_DEPOSIT};
use parachain_template_runtime::{AccountId, AuraId, Signature};
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::ChainType;
use serde::{Deserialize, Serialize};
+2
View File
@@ -27,6 +27,7 @@ smallvec = "1.11.0"
# Local
pallet-parachain-template = { path = "../pallets/template", default-features = false }
common = { path = "../common", default-features = false }
# Substrate
frame-benchmarking = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0", default-features = false, optional = true }
@@ -41,6 +42,7 @@ pallet-authorship = { git = "https://github.com/paritytech/polkadot-sdk", branch
pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0", default-features = false }
pallet-multisig = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0", default-features = false }
pallet-session = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0", default-features = false }
pallet-proxy = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0", default-features = false }
pallet-sudo = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0", default-features = false }
pallet-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0", default-features = false }
pallet-transaction-payment = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.3.0", default-features = false }
+70 -10
View File
@@ -11,6 +11,8 @@ use constants::currency::*;
mod weights;
pub mod xcm_config;
use codec::{Decode, Encode, MaxEncodedLen};
use common::{deposit, EXISTENTIAL_DEPOSIT, MICROUNIT, MILLIUNIT};
use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
use cumulus_primitives_core::ParaId;
use frame_support::{
@@ -18,7 +20,7 @@ use frame_support::{
dispatch::DispatchClass,
genesis_builder_helper::{build_config, create_default_config},
parameter_types,
traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything},
traits::{ConstBool, ConstU32, ConstU64, ConstU8, EitherOfDiverse, Everything, InstanceFilter},
weights::{
constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight, WeightToFeeCoefficient,
WeightToFeeCoefficients, WeightToFeePolynomial,
@@ -36,6 +38,7 @@ use pallet_xcm::{EnsureXcm, IsVoiceOfBody};
use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery;
// Polkadot imports
use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};
use scale_info::TypeInfo;
use smallvec::smallvec;
use sp_api::impl_runtime_apis;
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
@@ -46,7 +49,7 @@ use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, IdentifyAccount, Verify},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, MultiSignature,
ApplyExtrinsicResult, MultiSignature, RuntimeDebug,
};
pub use sp_runtime::{MultiAddress, Perbill, Permill};
use sp_std::prelude::*;
@@ -207,14 +210,6 @@ pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
pub const HOURS: BlockNumber = MINUTES * 60;
pub const DAYS: BlockNumber = HOURS * 24;
// Unit = the base number of indivisible units for balances
pub const UNIT: Balance = 1_000_000_000_000;
pub const MILLIUNIT: Balance = 1_000_000_000;
pub const MICROUNIT: Balance = 1_000_000;
/// The existential deposit. Set to 1/10 of the Connected Relay Chain.
pub const EXISTENTIAL_DEPOSIT: Balance = MILLIUNIT;
/// We assume that ~5% of the block weight is consumed by `on_initialize`
/// handlers. This is used to limit the maximal weight of a single extrinsic.
const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(5);
@@ -341,6 +336,70 @@ impl pallet_authorship::Config for Runtime {
type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Aura>;
}
parameter_types! {
pub const MaxProxies: u32 = 32;
pub const MaxPending: u32 = 32;
pub const ProxyDepositBase: Balance = deposit(1, 40);
pub const AnnouncementDepositBase: Balance = deposit(1, 48);
pub const ProxyDepositFactor: Balance = deposit(0, 33);
pub const AnnouncementDepositFactor: Balance = deposit(0, 66);
}
/// The type used to represent the kinds of proxying allowed.
/// If you are adding new pallets, consider adding new proxy type
#[derive(
Copy,
Clone,
Decode,
Default,
Encode,
Eq,
MaxEncodedLen,
Ord,
PartialEq,
PartialOrd,
RuntimeDebug,
TypeInfo,
)]
pub enum ProxyType {
/// Allows to proxy all calls
#[default]
Any,
/// Allows all non-transfer calls
NonTransfer,
/// Allows to finish the proxy
CancelProxy,
/// Allows to operate with collators list (invulnerables, candidates, etc.)
Collator,
}
impl InstanceFilter<RuntimeCall> for ProxyType {
fn filter(&self, c: &RuntimeCall) -> bool {
match self {
ProxyType::Any => true,
ProxyType::NonTransfer => !matches!(c, RuntimeCall::Balances { .. }),
ProxyType::CancelProxy =>
matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })),
ProxyType::Collator => matches!(c, RuntimeCall::CollatorSelection { .. }),
}
}
}
impl pallet_proxy::Config for Runtime {
type AnnouncementDepositBase = AnnouncementDepositBase;
type AnnouncementDepositFactor = AnnouncementDepositFactor;
type CallHasher = BlakeTwo256;
type Currency = Balances;
type MaxPending = MaxPending;
type MaxProxies = MaxProxies;
type ProxyDepositBase = ProxyDepositBase;
type ProxyDepositFactor = ProxyDepositFactor;
type ProxyType = ProxyType;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type WeightInfo = pallet_proxy::weights::SubstrateWeight<Runtime>;
}
parameter_types! {
pub const ExistentialDeposit: Balance = EXISTENTIAL_DEPOSIT;
}
@@ -520,6 +579,7 @@ construct_runtime!(
ParachainSystem: cumulus_pallet_parachain_system = 1,
Timestamp: pallet_timestamp = 2,
ParachainInfo: parachain_info = 3,
Proxy: pallet_proxy = 4,
// Monetary stuff.
Balances: pallet_balances = 10,