From 5e4cef411790b50ea13a6c2d89cba87b07ee31a8 Mon Sep 17 00:00:00 2001 From: Nikita Khateev Date: Mon, 20 Nov 2023 17:39:12 +0400 Subject: [PATCH 1/4] [10] add proxy pallet --- Cargo.lock | 12 ++++++- Cargo.toml | 2 +- common/Cargo.toml | 12 +++++++ common/src/lib.rs | 16 +++++++++ node/Cargo.toml | 1 + node/src/chain_spec.rs | 3 +- runtime/Cargo.toml | 2 ++ runtime/src/lib.rs | 80 ++++++++++++++++++++++++++++++++++++------ 8 files changed, 115 insertions(+), 13 deletions(-) create mode 100644 common/Cargo.toml create mode 100644 common/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index ce4babd..a95169d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", ] diff --git a/Cargo.toml b/Cargo.toml index e7c44ec..83c060f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/common/Cargo.toml b/common/Cargo.toml new file mode 100644 index 0000000..c760999 --- /dev/null +++ b/common/Cargo.toml @@ -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 } \ No newline at end of file diff --git a/common/src/lib.rs b/common/src/lib.rs new file mode 100644 index 0000000..fe6aaa9 --- /dev/null +++ b/common/src/lib.rs @@ -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 + } +} diff --git a/node/Cargo.toml b/node/Cargo.toml index 24d5ff8..c9e5d2c 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -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 } diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index 73a05da..f39e0ff 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -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}; diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 30436bd..edaa510 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -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 } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index b5a98d8..9e2bd8a 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -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; } +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 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; +} + 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, From a2ef39fb78899599787e859bee4f03f3805aa275 Mon Sep 17 00:00:00 2001 From: Nikita Khateev Date: Mon, 20 Nov 2023 18:18:59 +0400 Subject: [PATCH 2/4] [10] updates with multisig introduction --- common/Cargo.toml | 12 ------------ common/src/lib.rs | 16 ---------------- runtime/src/lib.rs | 11 +++++++---- 3 files changed, 7 insertions(+), 32 deletions(-) delete mode 100644 common/Cargo.toml delete mode 100644 common/src/lib.rs diff --git a/common/Cargo.toml b/common/Cargo.toml deleted file mode 100644 index c760999..0000000 --- a/common/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[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 } \ No newline at end of file diff --git a/common/src/lib.rs b/common/src/lib.rs deleted file mode 100644 index fe6aaa9..0000000 --- a/common/src/lib.rs +++ /dev/null @@ -1,16 +0,0 @@ -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 - } -} diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 9e2bd8a..2ecf304 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -7,7 +7,6 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); pub mod constants; -use constants::currency::*; mod weights; pub mod xcm_config; @@ -378,9 +377,13 @@ impl InstanceFilter for ProxyType { 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 { .. }), + ProxyType::CancelProxy => matches!( + c, + RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) + | RuntimeCall::Multisig { .. } + ), + ProxyType::Collator => + matches!(c, RuntimeCall::CollatorSelection { .. } | RuntimeCall::Multisig { .. }), } } } From a3917e55cc6dd1e2afa139bfba498a8690c6c747 Mon Sep 17 00:00:00 2001 From: Nikita Khateev Date: Tue, 21 Nov 2023 12:31:47 +0400 Subject: [PATCH 3/4] [10] fix build --- Cargo.lock | 11 +---------- Cargo.toml | 2 +- node/Cargo.toml | 1 - node/src/chain_spec.rs | 5 +++-- runtime/Cargo.toml | 1 - runtime/src/constants.rs | 3 +++ runtime/src/lib.rs | 6 +++--- 7 files changed, 11 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a95169d..1b34d10 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1519,13 +1519,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "common" -version = "0.1.0" -dependencies = [ - "polkadot-core-primitives", -] - [[package]] name = "common" version = "0.1.0" @@ -7311,7 +7304,6 @@ version = "0.1.0" dependencies = [ "clap", "color-print", - "common 0.1.0", "cumulus-client-cli", "cumulus-client-collator", "cumulus-client-consensus-aura", @@ -7367,7 +7359,6 @@ 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", @@ -9493,7 +9484,7 @@ dependencies = [ "ark-serialize", "ark-std", "blake2 0.10.6", - "common 0.1.0 (git+https://github.com/w3f/ring-proof)", + "common", "fflonk", "merlin 3.0.0", ] diff --git a/Cargo.toml b/Cargo.toml index 83c060f..138eaa2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = [ "common", "node", "pallets/template", "runtime"] +members = [ "node", "pallets/template", "runtime"] package.edition = "2021" package.repository = "https://github.com/paritytech/polkadot-sdk" resolver = "2" diff --git a/node/Cargo.toml b/node/Cargo.toml index c9e5d2c..24d5ff8 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -20,7 +20,6 @@ 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 } diff --git a/node/src/chain_spec.rs b/node/src/chain_spec.rs index f39e0ff..e352738 100644 --- a/node/src/chain_spec.rs +++ b/node/src/chain_spec.rs @@ -1,6 +1,7 @@ -use common::EXISTENTIAL_DEPOSIT; use cumulus_primitives_core::ParaId; -use parachain_template_runtime::{AccountId, AuraId, Signature}; +use parachain_template_runtime::{ + constants::currency::EXISTENTIAL_DEPOSIT, AccountId, AuraId, Signature, +}; use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup}; use sc_service::ChainType; use serde::{Deserialize, Serialize}; diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index edaa510..e165a39 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -27,7 +27,6 @@ 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 } diff --git a/runtime/src/constants.rs b/runtime/src/constants.rs index f1833cf..b3a1690 100644 --- a/runtime/src/constants.rs +++ b/runtime/src/constants.rs @@ -1,10 +1,13 @@ pub mod currency { use crate::Balance; + pub const MICROCENTS: Balance = 1_000_000; pub const MILLICENTS: Balance = 1_000_000_000; pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent. pub const DOLLARS: Balance = 100 * CENTS; + pub const EXISTENTIAL_DEPOSIT: Balance = MILLICENTS; + pub const fn deposit(items: u32, bytes: u32) -> Balance { items as Balance * 15 * CENTS + (bytes as Balance) * 6 * CENTS } diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 2ecf304..9d95b86 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -11,7 +11,7 @@ mod weights; pub mod xcm_config; use codec::{Decode, Encode, MaxEncodedLen}; -use common::{deposit, EXISTENTIAL_DEPOSIT, MICROUNIT, MILLIUNIT}; +use constants::currency::{deposit, EXISTENTIAL_DEPOSIT, MICROCENTS, MILLICENTS}; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use cumulus_primitives_core::ParaId; use frame_support::{ @@ -140,7 +140,7 @@ impl WeightToFeePolynomial for WeightToFee { fn polynomial() -> WeightToFeeCoefficients { // in Rococo, extrinsic base weight (smallest non-zero weight) is mapped to 1 // MILLIUNIT: in our template, we map to 1/10 of that, or 1/10 MILLIUNIT - let p = MILLIUNIT / 10; + let p = MILLICENTS / 10; let q = 100 * Balance::from(ExtrinsicBaseWeight::get().ref_time()); smallvec![WeightToFeeCoefficient { degree: 1, @@ -428,7 +428,7 @@ impl pallet_balances::Config for Runtime { parameter_types! { /// Relay Chain `TransactionByteFee` / 10 - pub const TransactionByteFee: Balance = 10 * MICROUNIT; + pub const TransactionByteFee: Balance = 10 * MICROCENTS; } impl pallet_transaction_payment::Config for Runtime { From 78343cc652076c11dc86d6e94005710d9662555a Mon Sep 17 00:00:00 2001 From: Nikita Khateev Date: Tue, 21 Nov 2023 13:22:06 +0400 Subject: [PATCH 4/4] [10] fix comments --- runtime/src/lib.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 9d95b86..37611d9 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -11,7 +11,6 @@ mod weights; pub mod xcm_config; use codec::{Decode, Encode, MaxEncodedLen}; -use constants::currency::{deposit, EXISTENTIAL_DEPOSIT, MICROCENTS, MILLICENTS}; use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; use cumulus_primitives_core::ParaId; use frame_support::{ @@ -55,12 +54,16 @@ use sp_std::prelude::*; #[cfg(feature = "std")] use sp_version::NativeVersion; use sp_version::RuntimeVersion; -use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}; // XCM Imports use xcm::latest::prelude::BodyId; -use xcm_config::{RelayLocation, XcmConfig, XcmOriginToTransactDispatchOrigin}; use xcm_executor::XcmExecutor; +use crate::{ + constants::currency::{deposit, EXISTENTIAL_DEPOSIT, MICROCENTS, MILLICENTS}, + weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight}, + xcm_config::{RelayLocation, XcmConfig, XcmOriginToTransactDispatchOrigin}, +}; + /// Alias to 512-bit hash when used in the context of a transaction signature on /// the chain. pub type Signature = MultiSignature; @@ -345,7 +348,7 @@ parameter_types! { } /// The type used to represent the kinds of proxying allowed. -/// If you are adding new pallets, consider adding new proxy type +/// If you are adding new pallets, consider adding new ProxyType variant #[derive( Copy, Clone,