From d8dc25f7be39a3e8c9bf209d22253f6030756080 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Sun, 8 Oct 2023 19:01:27 +0800 Subject: [PATCH 1/7] OpenGov Signed-off-by: Xavier Lau --- Cargo.lock | 60 +++- Cargo.toml | 1 + node/Cargo.toml | 2 - node/src/chain_spec/crab.rs | 14 +- node/src/chain_spec/darwinia.rs | 14 +- node/src/chain_spec/pangolin.rs | 37 +- node/src/chain_spec/pangoro.rs | 14 +- node/src/service/mod.rs | 3 +- runtime/common/src/gov_origin.rs | 25 +- runtime/pangolin/Cargo.toml | 30 +- runtime/pangolin/src/lib.rs | 8 +- runtime/pangolin/src/pallets.rs | 10 +- runtime/pangolin/src/pallets/asset_manager.rs | 46 +-- runtime/pangolin/src/pallets/assets.rs | 2 +- runtime/pangolin/src/pallets/dmp_queue.rs | 2 +- .../src/pallets/elections_phragmen.rs | 49 --- runtime/pangolin/src/pallets/ethereum_xcm.rs | 2 +- .../pallets/{collective.rs => governance.rs} | 68 +++- .../pangolin/src/pallets/governance/origin.rs | 80 +++++ .../pangolin/src/pallets/governance/track.rs | 236 +++++++++++++ .../{democracy.rs => governance/v1.rs} | 23 +- runtime/pangolin/src/pallets/membership.rs | 33 -- runtime/pangolin/src/pallets/polkadot_xcm.rs | 2 +- runtime/pangolin/src/pallets/preimage.rs | 2 +- runtime/pangolin/src/pallets/proxy.rs | 4 +- runtime/pangolin/src/pallets/scheduler.rs | 2 +- runtime/pangolin/src/pallets/treasury.rs | 2 +- runtime/pangolin/src/pallets/xcmp_queue.rs | 4 +- runtime/pangolin/src/weights.rs | 2 - .../src/weights/pallet_elections_phragmen.rs | 328 ------------------ .../pangolin/src/weights/pallet_membership.rs | 215 ------------ runtime/pangoro/Cargo.toml | 2 - 32 files changed, 552 insertions(+), 770 deletions(-) delete mode 100644 runtime/pangolin/src/pallets/elections_phragmen.rs rename runtime/pangolin/src/pallets/{collective.rs => governance.rs} (50%) create mode 100644 runtime/pangolin/src/pallets/governance/origin.rs create mode 100644 runtime/pangolin/src/pallets/governance/track.rs rename runtime/pangolin/src/pallets/{democracy.rs => governance/v1.rs} (65%) delete mode 100644 runtime/pangolin/src/pallets/membership.rs delete mode 100644 runtime/pangolin/src/weights/pallet_elections_phragmen.rs delete mode 100644 runtime/pangolin/src/weights/pallet_membership.rs diff --git a/Cargo.lock b/Cargo.lock index 2c838d40f..921b1fed8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1136,9 +1136,9 @@ dependencies = [ [[package]] name = "cargo-platform" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cfa25e60aea747ec7e1124f238816749faa93759c6ff5b31f1ccdda137f4479" +checksum = "12024c4645c97566567129c204f65d5815a8c9aecf30fcbe682b2fe034996d36" dependencies = [ "serde", ] @@ -1388,8 +1388,8 @@ version = "6.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e959d788268e3bf9d35ace83e81b124190378e4c91c9067524675e33394b8ba" dependencies = [ - "strum", - "strum_macros", + "strum 0.24.1", + "strum_macros 0.24.3", "unicode-width", ] @@ -7175,9 +7175,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.16" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f30b0abd723be7e2ffca1272140fac1a2f084c77ec3e123c192b66af1ee9e6c2" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] @@ -7922,7 +7922,7 @@ dependencies = [ "sp-npos-elections", "sp-runtime", "sp-std", - "strum", + "strum 0.24.1", ] [[package]] @@ -8842,6 +8842,7 @@ dependencies = [ "pallet-bridge-messages", "pallet-bridge-parachains", "pallet-collective", + "pallet-conviction-voting", "pallet-democracy", "pallet-elections-phragmen", "pallet-ethereum", @@ -8857,6 +8858,7 @@ dependencies = [ "pallet-membership", "pallet-preimage", "pallet-proxy", + "pallet-referenda", "pallet-scheduler", "pallet-session", "pallet-sudo", @@ -8865,6 +8867,7 @@ dependencies = [ "pallet-transaction-payment-rpc-runtime-api", "pallet-treasury", "pallet-utility", + "pallet-whitelist", "pallet-xcm", "parachain-info", "parity-scale-codec", @@ -8887,6 +8890,7 @@ dependencies = [ "sp-transaction-pool", "sp-version", "static_assertions", + "strum 0.25.0", "substrate-wasm-builder", "xcm", "xcm-builder", @@ -9930,7 +9934,7 @@ dependencies = [ "rand 0.8.5", "sc-authority-discovery", "sc-network", - "strum", + "strum 0.24.1", "thiserror", "tracing-gum", ] @@ -13244,9 +13248,9 @@ dependencies = [ [[package]] name = "similar" -version = "2.2.1" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "420acb44afdae038210c99e69aae24109f32f15500aa708e81d46c9f29d55fcf" +checksum = "2aeaf503862c419d66959f5d7ca015337d864e9c49485d771b732e2a20453597" dependencies = [ "bstr 0.2.17", "unicode-segmentation", @@ -13544,7 +13548,7 @@ dependencies = [ "sp-mmr-primitives", "sp-runtime", "sp-std", - "strum", + "strum 0.24.1", ] [[package]] @@ -13725,7 +13729,7 @@ dependencies = [ "lazy_static", "sp-core", "sp-runtime", - "strum", + "strum 0.24.1", ] [[package]] @@ -14114,7 +14118,7 @@ checksum = "08615eea740067d9899969bc2891c68a19c315cb1f66640af9a9ecb91b13bcab" dependencies = [ "lazy_static", "maplit", - "strum", + "strum 0.24.1", ] [[package]] @@ -14325,7 +14329,16 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" dependencies = [ - "strum_macros", + "strum_macros 0.24.3", +] + +[[package]] +name = "strum" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" +dependencies = [ + "strum_macros 0.25.2", ] [[package]] @@ -14341,6 +14354,19 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "strum_macros" +version = "0.25.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad8d03b598d3d0fff69bf533ee3ef19b8eeb342729596df84bcc7e1f96ec4059" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 2.0.38", +] + [[package]] name = "stun" version = "0.4.4" @@ -14499,7 +14525,7 @@ dependencies = [ "cargo_metadata", "filetime", "sp-maybe-compressed-blob", - "strum", + "strum 0.24.1", "tempfile", "toml 0.7.8", "walkdir", @@ -15624,8 +15650,8 @@ checksum = "87fef6d0d508f08334e0ab0e6877feb4c0ecb3956bcf2cb950699b22fedf3e9c" dependencies = [ "anyhow", "libc", - "strum", - "strum_macros", + "strum 0.24.1", + "strum_macros 0.24.3", "tempfile", "thiserror", "wasm-opt-cxx-sys", diff --git a/Cargo.toml b/Cargo.toml index c6290598d..362950d47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,7 @@ libsecp256k1 = { version = "0.7", default-features = false } scale-info = { version = "2.9", default-features = false } sha3 = { version = "0.10" } static_assertions = { version = "1.1" } +strum = { version = "0.25", default-features = false } # cumulus cumulus-client-cli = { git = "https://github.com/paritytech/cumulus", branch = "polkadot-v0.9.43" } diff --git a/node/Cargo.toml b/node/Cargo.toml index b9cad84da..8893f9d6f 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -105,8 +105,6 @@ fast-runtime = [ # darwinia "crab-runtime?/fast-runtime", "darwinia-runtime?/fast-runtime", - "pangolin-runtime?/fast-runtime", - "pangoro-runtime?/fast-runtime", ] evm-tracing = [ diff --git a/node/src/chain_spec/crab.rs b/node/src/chain_spec/crab.rs index c5a07a1b0..c75affc7f 100644 --- a/node/src/chain_spec/crab.rs +++ b/node/src/chain_spec/crab.rs @@ -53,9 +53,10 @@ fn session_keys(keys: AuraId) -> SessionKeys { pub fn development_config() -> ChainSpec { ChainSpec::from_genesis( - "Crab2 Development", - "crab2-development", - ChainType::Development, + // Fulfill Polkadot.JS metadata upgrade requirements. + "Crab2 D", + "crab2-d", + ChainType::Live, move || { testnet_genesis( vec![ @@ -90,9 +91,10 @@ pub fn development_config() -> ChainSpec { pub fn local_config() -> ChainSpec { ChainSpec::from_genesis( - "Crab2 Local", - "crab2-local", - ChainType::Local, + // Fulfill Polkadot.JS metadata upgrade requirements. + "Crab2 L", + "crab2-l", + ChainType::Live, move || { testnet_genesis( vec![ diff --git a/node/src/chain_spec/darwinia.rs b/node/src/chain_spec/darwinia.rs index b42dd5fb6..f87b55935 100644 --- a/node/src/chain_spec/darwinia.rs +++ b/node/src/chain_spec/darwinia.rs @@ -53,9 +53,10 @@ fn session_keys(keys: AuraId) -> SessionKeys { pub fn development_config() -> ChainSpec { ChainSpec::from_genesis( - "Darwinia2 Development", - "darwinia2-development", - ChainType::Development, + // Fulfill Polkadot.JS metadata upgrade requirements. + "Darwinia2 D", + "darwinia2-d", + ChainType::Live, move || { testnet_genesis( vec![ @@ -90,9 +91,10 @@ pub fn development_config() -> ChainSpec { pub fn local_config() -> ChainSpec { ChainSpec::from_genesis( - "Darwinia2 Local", - "darwinia2-local", - ChainType::Local, + // Fulfill Polkadot.JS metadata upgrade requirements. + "Darwinia2 L", + "darwinia2-l", + ChainType::Live, move || { testnet_genesis( vec![ diff --git a/node/src/chain_spec/pangolin.rs b/node/src/chain_spec/pangolin.rs index f0bcd0017..a6c0621ed 100644 --- a/node/src/chain_spec/pangolin.rs +++ b/node/src/chain_spec/pangolin.rs @@ -53,9 +53,10 @@ fn session_keys(keys: AuraId) -> SessionKeys { pub fn development_config() -> ChainSpec { ChainSpec::from_genesis( - "Pangolin2 Development", - "pangolin2-development", - ChainType::Development, + // Fulfill Polkadot.JS metadata upgrade requirements. + "Pangolin2 D", + "pangolin2-d", + ChainType::Live, move || { testnet_genesis( vec![ @@ -90,9 +91,11 @@ pub fn development_config() -> ChainSpec { pub fn local_config() -> ChainSpec { ChainSpec::from_genesis( - "Pangolin2 Local", - "pangolin2-local", - ChainType::Local, + // Fulfill Polkadot.JS metadata upgrade requirements. + "Pangolin2 L", + "pangolin2-l", + // Fulfill Polkadot.JS metadata upgrade requirements. + ChainType::Live, move || { testnet_genesis( vec![ @@ -209,11 +212,8 @@ pub fn genesis_config() -> ChainSpec { ecdsa_authority: Default::default(), // Governance stuff. - democracy: Default::default(), council: Default::default(), technical_committee: Default::default(), - phragmen_election: Default::default(), - technical_membership: Default::default(), treasury: Default::default(), // Utility stuff. @@ -319,11 +319,20 @@ fn testnet_genesis( ecdsa_authority: Default::default(), // Governance stuff. - democracy: Default::default(), - council: Default::default(), - technical_committee: Default::default(), - phragmen_election: Default::default(), - technical_membership: Default::default(), + council: CouncilConfig { + members: vec![ + array_bytes::hex_n_into_unchecked(ALITH), + array_bytes::hex_n_into_unchecked(BALTATHAR), + ], + ..Default::default() + }, + technical_committee: TechnicalCommitteeConfig { + members: vec![ + array_bytes::hex_n_into_unchecked(ALITH), + array_bytes::hex_n_into_unchecked(BALTATHAR), + ], + ..Default::default() + }, treasury: Default::default(), // Utility stuff. diff --git a/node/src/chain_spec/pangoro.rs b/node/src/chain_spec/pangoro.rs index 82f88035a..5a0aead2e 100644 --- a/node/src/chain_spec/pangoro.rs +++ b/node/src/chain_spec/pangoro.rs @@ -53,9 +53,10 @@ fn session_keys(keys: AuraId) -> SessionKeys { pub fn development_config() -> ChainSpec { ChainSpec::from_genesis( - "Pangoro2 Development", - "pangoro2-development", - ChainType::Development, + // Fulfill Polkadot.JS metadata upgrade requirements. + "Pangoro2 D", + "pangoro2-d", + ChainType::Live, move || { testnet_genesis( vec![ @@ -90,9 +91,10 @@ pub fn development_config() -> ChainSpec { pub fn local_config() -> ChainSpec { ChainSpec::from_genesis( - "Pangoro2 Local", - "pangoro2-local", - ChainType::Local, + // Fulfill Polkadot.JS metadata upgrade requirements. + "Pangoro2 L", + "pangoro2-l", + ChainType::Live, move || { testnet_genesis( vec![ diff --git a/node/src/service/mod.rs b/node/src/service/mod.rs index bc779f10f..34b24af4b 100644 --- a/node/src/service/mod.rs +++ b/node/src/service/mod.rs @@ -86,7 +86,8 @@ pub trait IdentifyVariant { /// Returns true if this configuration is for a development network. fn is_dev(&self) -> bool { - self.id().ends_with("development") + // Fulfill Polkadot.JS metadata upgrade requirements. + self.id().ends_with("-d") } } impl IdentifyVariant for Box { diff --git a/runtime/common/src/gov_origin.rs b/runtime/common/src/gov_origin.rs index 5ff9d28d1..811105997 100644 --- a/runtime/common/src/gov_origin.rs +++ b/runtime/common/src/gov_origin.rs @@ -16,31 +16,34 @@ // You should have received a copy of the GNU General Public License // along with Darwinia. If not, see . +pub use frame_support::traits::{EitherOf, EitherOfDiverse}; + // darwinia use dc_primitives::AccountId; // frontier use fp_account::AccountId20; // substrate -use frame_support::traits::EitherOfDiverse; use frame_system::EnsureRoot; use pallet_collective::{EnsureProportionAtLeast, EnsureProportionMoreThan}; pub type Root = EnsureRoot; +pub type RootOr = EitherOf; +pub type RootOrDiverse = EitherOfDiverse; -pub type RootOrAtLeastHalf = - EitherOfDiverse>; +pub type RootOrAtLeastHalf = EitherOfDiverse>; +pub type AtLeastHalf = EnsureProportionAtLeast; -pub type RootOrMoreThanHalf = - EitherOfDiverse>; +pub type RootOrMoreThanHalf = EitherOfDiverse>; +pub type MoreThanHalf = EnsureProportionMoreThan; -pub type RootOrAtLeastTwoThird = - EitherOfDiverse>; +pub type RootOrAtLeastTwoThird = EitherOfDiverse>; +pub type AtLeastTwoThird = EnsureProportionAtLeast; -pub type RootOrAtLeastThreeFifth = - EitherOfDiverse>; +pub type RootOrAtLeastThreeFifth = EitherOfDiverse>; +pub type AtLeastThreeFifth = EnsureProportionAtLeast; -pub type RootOrAll = - EitherOfDiverse>; +pub type RootOrAll = EitherOfDiverse>; +pub type All = EnsureProportionAtLeast; /// An [`AccountId20`] generated from b"root". pub const ROOT: AccountId20 = diff --git a/runtime/pangolin/Cargo.toml b/runtime/pangolin/Cargo.toml index 30896317e..6d2244c4a 100644 --- a/runtime/pangolin/Cargo.toml +++ b/runtime/pangolin/Cargo.toml @@ -15,9 +15,9 @@ substrate-wasm-builder = { workspace = true, optional = true } codec = { workspace = true, package = "parity-scale-codec" } scale-info = { workspace = true } static_assertions = { workspace = true } +strum = { workspace = true, features = ["derive"] } # crates.io optional -array-bytes = { workspace = true } -# array-bytes = { workspace = true, optional = true } +array-bytes = { workspace = true, optional = true } # cumulus cumulus-pallet-aura-ext = { workspace = true } @@ -102,12 +102,14 @@ pallet-aura = { workspace = true } pallet-authorship = { workspace = true } pallet-balances = { workspace = true } pallet-collective = { workspace = true } +pallet-conviction-voting = { workspace = true } pallet-democracy = { workspace = true } pallet-elections-phragmen = { workspace = true } pallet-identity = { workspace = true } pallet-membership = { workspace = true } pallet-preimage = { workspace = true } pallet-proxy = { workspace = true } +pallet-referenda = { workspace = true } pallet-scheduler = { workspace = true } pallet-session = { workspace = true } pallet-sudo = { workspace = true } @@ -116,6 +118,7 @@ pallet-transaction-payment = { workspace = true } pallet-transaction-payment-rpc-runtime-api = { workspace = true } pallet-treasury = { workspace = true } pallet-utility = { workspace = true } +pallet-whitelist = { workspace = true } sp-api = { workspace = true } sp-block-builder = { workspace = true } sp-consensus-aura = { workspace = true } @@ -149,6 +152,7 @@ std = [ # crates.io "codec/std", "scale-info/std", + "strum/std", # cumulus "cumulus-pallet-aura-ext/std", @@ -233,12 +237,11 @@ std = [ "pallet-authorship/std", "pallet-balances/std", "pallet-collective/std", - "pallet-democracy/std", - "pallet-elections-phragmen/std", + "pallet-conviction-voting/std", "pallet-identity/std", - "pallet-membership/std", "pallet-preimage/std", "pallet-proxy/std", + "pallet-referenda/std", "pallet-scheduler/std", "pallet-session/std", "pallet-sudo/std", @@ -247,6 +250,7 @@ std = [ "pallet-transaction-payment/std", "pallet-treasury/std", "pallet-utility/std", + "pallet-whitelist/std", "sp-api/std", "sp-block-builder/std", "sp-consensus-aura/std", @@ -265,8 +269,6 @@ std = [ "substrate-wasm-builder", ] -fast-runtime = [] - evm-tracing = [ # moonbeam "moonbeam-evm-tracer", @@ -282,7 +284,7 @@ on-chain-release-build = [ runtime-benchmarks = [ # crates.io - # "array-bytes", + "array-bytes", # cumulus "cumulus-pallet-parachain-system/runtime-benchmarks", @@ -332,17 +334,17 @@ runtime-benchmarks = [ "pallet-assets/runtime-benchmarks", "pallet-balances/runtime-benchmarks", "pallet-collective/runtime-benchmarks", - "pallet-democracy/runtime-benchmarks", - "pallet-elections-phragmen/runtime-benchmarks", + "pallet-conviction-voting/runtime-benchmarks", "pallet-identity/runtime-benchmarks", - "pallet-membership/runtime-benchmarks", "pallet-preimage/runtime-benchmarks", "pallet-proxy/runtime-benchmarks", + "pallet-referenda/runtime-benchmarks", "pallet-scheduler/runtime-benchmarks", "pallet-sudo/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-treasury/runtime-benchmarks", "pallet-utility/runtime-benchmarks", + "pallet-whitelist/runtime-benchmarks", "sp-runtime/runtime-benchmarks", # substrate optional "frame-benchmarking/runtime-benchmarks", @@ -399,12 +401,11 @@ try-runtime = [ "pallet-authorship/try-runtime", "pallet-balances/try-runtime", "pallet-collective/try-runtime", - "pallet-democracy/try-runtime", - "pallet-elections-phragmen/try-runtime", + "pallet-conviction-voting/try-runtime", "pallet-identity/try-runtime", - "pallet-membership/try-runtime", "pallet-preimage/try-runtime", "pallet-proxy/try-runtime", + "pallet-referenda/try-runtime", "pallet-scheduler/try-runtime", "pallet-session/try-runtime", "pallet-sudo/try-runtime", @@ -412,6 +413,7 @@ try-runtime = [ "pallet-transaction-payment/try-runtime", "pallet-treasury/try-runtime", "pallet-utility/try-runtime", + "pallet-whitelist/try-runtime", "sp-runtime/try-runtime", # substrate optional "frame-try-runtime/try-runtime", diff --git a/runtime/pangolin/src/lib.rs b/runtime/pangolin/src/lib.rs index 6d5389855..93b7bea39 100644 --- a/runtime/pangolin/src/lib.rs +++ b/runtime/pangolin/src/lib.rs @@ -145,11 +145,15 @@ frame_support::construct_runtime! { EcdsaAuthority: darwinia_ecdsa_authority = 17, // Governance stuff. + ConvictionVoting: pallet_conviction_voting = 48, + Referenda: pallet_referenda = 49, + Origins: custom_origins = 50, + Whitelist: pallet_whitelist = 51, Democracy: pallet_democracy = 18, Council: pallet_collective:: = 19, TechnicalCommittee: pallet_collective:: = 20, - PhragmenElection: pallet_elections_phragmen = 21, - TechnicalMembership: pallet_membership:: = 22, + // PhragmenElection: pallet_elections_phragmen = 21, + // TechnicalMembership: pallet_membership:: = 22, Treasury: pallet_treasury = 23, // Tips: pallet_tips = 24, diff --git a/runtime/pangolin/src/pallets.rs b/runtime/pangolin/src/pallets.rs index 54fa3a5c1..a9ee8186a 100644 --- a/runtime/pangolin/src/pallets.rs +++ b/runtime/pangolin/src/pallets.rs @@ -65,14 +65,8 @@ mod message_gadget; mod ecdsa_authority; // Governance stuff. -mod democracy; - -mod collective; -pub use collective::*; - -mod elections_phragmen; - -mod membership; +mod governance; +pub use governance::*; mod treasury; pub use treasury::*; diff --git a/runtime/pangolin/src/pallets/asset_manager.rs b/runtime/pangolin/src/pallets/asset_manager.rs index 049391287..e1456f546 100644 --- a/runtime/pangolin/src/pallets/asset_manager.rs +++ b/runtime/pangolin/src/pallets/asset_manager.rs @@ -16,26 +16,26 @@ // You should have received a copy of the GNU General Public License // along with Darwinia. If not, see . +// crates.io +use codec::{Decode, Encode}; // darwinia use crate::*; +// polkadot +use xcm::prelude::*; // substrate -use frame_support::{dispatch::GetDispatchInfo, pallet_prelude::*, transactional}; -use frame_system::EnsureNever; use sp_runtime::traits::Hash; -// polkadot -use xcm::latest::prelude::*; // We instruct how to register the Assets // In this case, we tell it to create an Asset in pallet-assets pub struct AssetRegistrar; impl pallet_asset_manager::AssetRegistrar for AssetRegistrar { - #[transactional] + #[frame_support::transactional] fn create_foreign_asset( asset: crate::AssetId, min_balance: Balance, metadata: xcm_configs::AssetRegistrarMetadata, is_sufficient: bool, - ) -> DispatchResult { + ) -> sp_runtime::DispatchResult { Assets::force_create( RuntimeOrigin::root(), asset.into(), @@ -55,14 +55,17 @@ impl pallet_asset_manager::AssetRegistrar for AssetRegistrar { ) } - #[transactional] - fn destroy_foreign_asset(asset: crate::AssetId) -> DispatchResult { + #[frame_support::transactional] + fn destroy_foreign_asset(asset: crate::AssetId) -> sp_runtime::DispatchResult { // Mark the asset as destroying Assets::start_destroy(RuntimeOrigin::root(), asset.into())?; Ok(()) } - fn destroy_asset_dispatch_info_weight(asset: crate::AssetId) -> Weight { + fn destroy_asset_dispatch_info_weight(asset: crate::AssetId) -> frame_support::weights::Weight { + // substrate + use frame_support::dispatch::GetDispatchInfo; + // The dispatch info of destroy let call_weight = RuntimeCall::Assets(pallet_assets::Call::::start_destroy { id: asset.into() }) @@ -83,7 +86,7 @@ impl pallet_asset_manager::LocalAssetIdCreator for LocalAssetIdCreator } // Our AssetType. For now we only handle Xcm Assets -#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, scale_info::TypeInfo)] pub enum AssetType { Xcm(MultiLocation), } @@ -97,13 +100,6 @@ impl From for AssetType { Self::Xcm(location) } } -impl Into> for AssetType { - fn into(self) -> Option { - match self { - Self::Xcm(location) => Some(location), - } - } -} // Implementation on how to retrieve the AssetId from an `AssetType`. // We simply hash the `AssetType` and take the lowest 128 bits. impl From for crate::AssetId { @@ -113,14 +109,24 @@ impl From for crate::AssetId { if id == UsdtLocation::get() { 1027 } else { - let mut result: [u8; 8] = [0u8; 8]; + let mut result: [u8; 8] = [0_u8; 8]; let hash: sp_core::H256 = id.using_encoded(dc_primitives::Hashing::hash); + result.copy_from_slice(&hash.as_fixed_bytes()[0..8]); + u64::from_le_bytes(result) }, } } } +#[allow(clippy::from_over_into)] +impl Into> for AssetType { + fn into(self) -> Option { + match self { + Self::Xcm(location) => Some(location), + } + } +} frame_support::parameter_types! { /// 1000 is AssetHub paraId. @@ -138,11 +144,11 @@ impl pallet_asset_manager::Config for Runtime { type AssetRegistrarMetadata = xcm_configs::AssetRegistrarMetadata; type Balance = Balance; type Currency = Balances; - type ForeignAssetModifierOrigin = Root; + type ForeignAssetModifierOrigin = RootOr; type ForeignAssetType = AssetType; type LocalAssetDeposit = ConstU128<0>; type LocalAssetIdCreator = LocalAssetIdCreator; - type LocalAssetModifierOrigin = EnsureNever; + type LocalAssetModifierOrigin = RootOr; type RuntimeEvent = RuntimeEvent; type WeightInfo = pallet_asset_manager::weights::SubstrateWeight; } diff --git a/runtime/pangolin/src/pallets/assets.rs b/runtime/pangolin/src/pallets/assets.rs index d078cd27f..9c5de9a9e 100644 --- a/runtime/pangolin/src/pallets/assets.rs +++ b/runtime/pangolin/src/pallets/assets.rs @@ -46,7 +46,7 @@ impl pallet_assets::Config for Runtime { >; type Currency = Balances; type Extra = (); - type ForceOrigin = Root; + type ForceOrigin = RootOr; type Freezer = (); type MetadataDepositBase = ConstU128<0>; type MetadataDepositPerByte = ConstU128<0>; diff --git a/runtime/pangolin/src/pallets/dmp_queue.rs b/runtime/pangolin/src/pallets/dmp_queue.rs index 15bea9ad2..0170db7d5 100644 --- a/runtime/pangolin/src/pallets/dmp_queue.rs +++ b/runtime/pangolin/src/pallets/dmp_queue.rs @@ -20,7 +20,7 @@ use crate::*; impl cumulus_pallet_dmp_queue::Config for Runtime { - type ExecuteOverweightOrigin = Root; + type ExecuteOverweightOrigin = RootOr; type RuntimeEvent = RuntimeEvent; type XcmExecutor = xcm_executor::XcmExecutor; } diff --git a/runtime/pangolin/src/pallets/elections_phragmen.rs b/runtime/pangolin/src/pallets/elections_phragmen.rs deleted file mode 100644 index b51c53ae8..000000000 --- a/runtime/pangolin/src/pallets/elections_phragmen.rs +++ /dev/null @@ -1,49 +0,0 @@ -// This file is part of Darwinia. -// -// Copyright (C) 2018-2023 Darwinia Network -// SPDX-License-Identifier: GPL-3.0 -// -// Darwinia is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Darwinia is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Darwinia. If not, see . - -// darwinia -use crate::*; - -const MAX_CANDIDATES: u32 = 30; - -frame_support::parameter_types! { - pub const PhragmenElectionPalletId: frame_support::traits::LockIdentifier = *b"phrelect"; -} - -impl pallet_elections_phragmen::Config for Runtime { - type CandidacyBond = ConstU128<{ 100 * MILLIUNIT }>; - type ChangeMembers = Council; - type Currency = Balances; - type CurrencyToVote = frame_support::traits::U128CurrencyToVote; - type DesiredMembers = ConstU32; - type DesiredRunnersUp = ConstU32<7>; - type InitializeMembers = Council; - type KickedMember = Treasury; - type LoserCandidate = Treasury; - type MaxCandidates = ConstU32; - type MaxVoters = ConstU32<{ 10 * MAX_CANDIDATES }>; - type MaxVotesPerVoter = ConstU32<16>; - type PalletId = PhragmenElectionPalletId; - type RuntimeEvent = RuntimeEvent; - type TermDuration = ConstU32<{ 10 * MINUTES }>; - // 1 storage item created, key size is 32 bytes, value size is 16+16. - type VotingBondBase = ConstU128<{ darwinia_deposit(1, 64) }>; - // Additional data per vote is 32 bytes (account id). - type VotingBondFactor = ConstU128<{ darwinia_deposit(0, 32) }>; - type WeightInfo = weights::pallet_elections_phragmen::WeightInfo; -} diff --git a/runtime/pangolin/src/pallets/ethereum_xcm.rs b/runtime/pangolin/src/pallets/ethereum_xcm.rs index 02ba0a4d5..799b47c47 100644 --- a/runtime/pangolin/src/pallets/ethereum_xcm.rs +++ b/runtime/pangolin/src/pallets/ethereum_xcm.rs @@ -27,7 +27,7 @@ impl xcm_primitives::EnsureProxy for EthereumXcmEnsureProxy { } impl pallet_ethereum_xcm::Config for Runtime { - type ControllerOrigin = Root; + type ControllerOrigin = RootOr; type EnsureProxy = EthereumXcmEnsureProxy; type InvalidEvmTransactionError = pallet_ethereum::InvalidTransactionWrapper; type ReservedXcmpWeight = diff --git a/runtime/pangolin/src/pallets/collective.rs b/runtime/pangolin/src/pallets/governance.rs similarity index 50% rename from runtime/pangolin/src/pallets/collective.rs rename to runtime/pangolin/src/pallets/governance.rs index f097b6498..6fb862542 100644 --- a/runtime/pangolin/src/pallets/collective.rs +++ b/runtime/pangolin/src/pallets/governance.rs @@ -16,10 +16,18 @@ // You should have received a copy of the GNU General Public License // along with Darwinia. If not, see . +mod origin; +use origin::*; +pub use origin::{custom_origins, GeneralAdmin}; + +mod track; +use track::*; + +mod v1; + pub use pallet_collective::{Instance1 as CouncilCollective, Instance2 as TechnicalCollective}; -// darwinia -use crate::*; +pub(super) use crate::*; pub const COLLECTIVE_DESIRED_MEMBERS: u32 = 7; pub const COLLECTIVE_MAX_MEMBERS: u32 = 100; @@ -37,11 +45,11 @@ impl pallet_collective::Config for Runtime { type MaxMembers = ConstU32; type MaxProposalWeight = MaxProposalWeight; type MaxProposals = ConstU32<100>; - type MotionDuration = ConstU32<{ 10 * MINUTES }>; + type MotionDuration = ConstU32<{ 2 * MINUTES }>; type Proposal = RuntimeCall; type RuntimeEvent = RuntimeEvent; type RuntimeOrigin = RuntimeOrigin; - type SetMembersOrigin = Root; + type SetMembersOrigin = RootOr; type WeightInfo = weights::pallet_collective_council::WeightInfo; } impl pallet_collective::Config for Runtime { @@ -49,10 +57,58 @@ impl pallet_collective::Config for Runtime { type MaxMembers = ConstU32; type MaxProposalWeight = MaxProposalWeight; type MaxProposals = ConstU32<100>; - type MotionDuration = ConstU32<{ 10 * MINUTES }>; + type MotionDuration = ConstU32<{ 2 * MINUTES }>; type Proposal = RuntimeCall; type RuntimeEvent = RuntimeEvent; type RuntimeOrigin = RuntimeOrigin; - type SetMembersOrigin = Root; + type SetMembersOrigin = RootOr; type WeightInfo = weights::pallet_collective_technical_committee::WeightInfo; } + +impl pallet_conviction_voting::Config for Runtime { + type Currency = Balances; + type MaxTurnout = frame_support::traits::TotalIssuanceOf; + type MaxVotes = ConstU32<512>; + type Polls = Referenda; + type RuntimeEvent = RuntimeEvent; + type VoteLockingPeriod = ConstU32<{ 5 * MINUTES }>; + // TODO: weight + type WeightInfo = pallet_conviction_voting::weights::SubstrateWeight; +} + +pallet_referenda::impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber); + +impl pallet_referenda::Config for Runtime { + type AlarmInterval = ConstU32<1>; + type CancelOrigin = RootOr; + type Currency = Balances; + type KillOrigin = RootOr; + type MaxQueued = ConstU32<100>; + type Preimages = Preimage; + type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type Scheduler = Scheduler; + type Slash = Treasury; + type SubmissionDeposit = ConstU128<{ DARWINIA_PROPOSAL_REQUIREMENT }>; + type SubmitOrigin = frame_system::EnsureSigned; + type Tally = pallet_conviction_voting::TallyOf; + type Tracks = TracksInfo; + type UndecidingTimeout = ConstU32<{ 5 * MINUTES }>; + type Votes = pallet_conviction_voting::VotesOf; + // TODO: weight + type WeightInfo = pallet_referenda::weights::SubstrateWeight; +} + +impl custom_origins::Config for Runtime {} + +// The purpose of this pallet is to queue calls to be dispatched as by root later => the Dispatch +// origin corresponds to the Gov2 Whitelist track. +impl pallet_whitelist::Config for Runtime { + type DispatchWhitelistedOrigin = RootOr; + type Preimages = Preimage; + type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + // TODO: weight + type WeightInfo = pallet_whitelist::weights::SubstrateWeight; + type WhitelistOrigin = RootOrDiverse>; +} diff --git a/runtime/pangolin/src/pallets/governance/origin.rs b/runtime/pangolin/src/pallets/governance/origin.rs new file mode 100644 index 000000000..a3f54c4ab --- /dev/null +++ b/runtime/pangolin/src/pallets/governance/origin.rs @@ -0,0 +1,80 @@ +// This file is part of Darwinia. +// +// Copyright (C) 2018-2023 Darwinia Network +// SPDX-License-Identifier: GPL-3.0 +// +// Darwinia is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Darwinia is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Darwinia. If not, see . + +#[frame_support::pallet] +pub mod custom_origins { + // crates.io + use strum::EnumString; + // substrate + use frame_support::pallet_prelude::*; + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(_); + + #[derive( + Clone, PartialEq, Eq, Encode, Decode, TypeInfo, RuntimeDebug, MaxEncodedLen, EnumString, + )] + #[strum(serialize_all = "snake_case")] + #[pallet::origin] + pub enum Origin { + /// Origin able to dispatch a whitelisted call. + WhitelistedCaller, + /// General admin + GeneralAdmin, + /// Origin able to cancel referenda. + ReferendumCanceller, + /// Origin able to kill referenda. + ReferendumKiller, + } + + macro_rules! decl_unit_ensures { + ($name:ident: $success_type:ty = $success:expr) => { + pub struct $name; + impl> + From> EnsureOrigin for $name { + type Success = $success_type; + + fn try_origin(o: O) -> Result { + o.into().and_then(|o| match o { + Origin::$name => Ok($success), + r => Err(O::from(r)), + }) + } + + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin() -> Result { + Ok(O::from(Origin::$name)) + } + } + }; + ($name:ident) => { decl_unit_ensures! { $name : () = () } }; + ($name:ident: $success_type:ty = $success:expr, $($rest:tt)*) => { + decl_unit_ensures! { $name: $success_type = $success } + decl_unit_ensures! { $($rest)* } + }; + ($name:ident, $( $rest:tt )*) => { + decl_unit_ensures! { $name } + decl_unit_ensures! { $($rest)* } + }; + () => {} + } + decl_unit_ensures!(ReferendumCanceller, ReferendumKiller, WhitelistedCaller, GeneralAdmin); +} +pub use custom_origins::*; diff --git a/runtime/pangolin/src/pallets/governance/track.rs b/runtime/pangolin/src/pallets/governance/track.rs new file mode 100644 index 000000000..3c6b48103 --- /dev/null +++ b/runtime/pangolin/src/pallets/governance/track.rs @@ -0,0 +1,236 @@ +// This file is part of Darwinia. +// +// Copyright (C) 2018-2023 Darwinia Network +// SPDX-License-Identifier: GPL-3.0 +// +// Darwinia is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Darwinia is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Darwinia. If not, see . + +// core +use core::str::FromStr; +// darwinia +use super::*; + +// TODO: move to common-runtime +const fn percent(x: i32) -> sp_runtime::FixedI64 { + sp_runtime::FixedI64::from_rational(x as u128, 100) +} +const fn permill(x: i32) -> sp_runtime::FixedI64 { + sp_runtime::FixedI64::from_rational(x as u128, 1000) +} + +const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 5] = [ + ( + 0, + pallet_referenda::TrackInfo { + // Name of this track. + name: "root", + // A limit for the number of referenda on this track that can be being decided at once. + // For Root origin this should generally be just one. + max_deciding: 5, + // Amount that must be placed on deposit before a decision can be made. + decision_deposit: DARWINIA_PROPOSAL_REQUIREMENT, + // Amount of time this must be submitted for before a decision can be made. + prepare_period: 2 * MINUTES, + // Amount of time that a decision may take to be approved prior to cancellation. + decision_period: 2 * MINUTES, + // Amount of time that the approval criteria must hold before it can be approved. + confirm_period: 2 * MINUTES, + // Minimum amount of time that an approved proposal must be in the dispatch queue. + min_enactment_period: 2 * MINUTES, + // Minimum aye votes as percentage of overall conviction-weighted votes needed for + // approval as a function of time into decision period. + min_approval: pallet_referenda::Curve::make_reciprocal( + 1, + 2, + percent(80), + percent(50), + percent(100), + ), + // Minimum pre-conviction aye-votes ("support") as percentage of overall population that + // is needed for approval as a function of time into decision period. + min_support: pallet_referenda::Curve::make_linear(2, 2, permill(5), percent(25)), + }, + ), + ( + 1, + pallet_referenda::TrackInfo { + name: "whitelisted_caller", + max_deciding: 100, + decision_deposit: DARWINIA_PROPOSAL_REQUIREMENT, + prepare_period: 2 * MINUTES, + decision_period: 2 * MINUTES, + confirm_period: 2 * MINUTES, + min_enactment_period: 2 * MINUTES, + min_approval: pallet_referenda::Curve::make_reciprocal( + 1, + 2, + percent(96), + percent(50), + percent(100), + ), + min_support: pallet_referenda::Curve::make_reciprocal( + 1, + 2, + percent(1), + percent(0), + percent(2), + ), + }, + ), + ( + 2, + pallet_referenda::TrackInfo { + name: "general_admin", + max_deciding: 10, + decision_deposit: DARWINIA_PROPOSAL_REQUIREMENT, + prepare_period: 2 * MINUTES, + decision_period: 2 * MINUTES, + confirm_period: 2 * MINUTES, + min_enactment_period: 2 * MINUTES, + min_approval: pallet_referenda::Curve::make_reciprocal( + 1, + 2, + percent(80), + percent(50), + percent(100), + ), + min_support: pallet_referenda::Curve::make_reciprocal( + 1, + 2, + percent(10), + percent(0), + percent(50), + ), + }, + ), + ( + 3, + pallet_referenda::TrackInfo { + name: "referendum_canceller", + max_deciding: 20, + decision_deposit: DARWINIA_PROPOSAL_REQUIREMENT, + prepare_period: 2 * MINUTES, + decision_period: 2 * MINUTES, + confirm_period: 2 * MINUTES, + min_enactment_period: 2 * MINUTES, + min_approval: pallet_referenda::Curve::make_reciprocal( + 1, + 2, + percent(96), + percent(50), + percent(100), + ), + min_support: pallet_referenda::Curve::make_reciprocal( + 1, + 2, + percent(1), + percent(0), + percent(10), + ), + }, + ), + ( + 4, + pallet_referenda::TrackInfo { + name: "referendum_killer", + max_deciding: 100, + decision_deposit: DARWINIA_PROPOSAL_REQUIREMENT, + prepare_period: 2 * MINUTES, + decision_period: 2 * MINUTES, + confirm_period: 2 * MINUTES, + min_enactment_period: 2 * MINUTES, + min_approval: pallet_referenda::Curve::make_reciprocal( + 1, + 2, + percent(96), + percent(50), + percent(100), + ), + min_support: pallet_referenda::Curve::make_reciprocal( + 1, + 2, + percent(1), + percent(0), + percent(10), + ), + }, + ), +]; + +pub struct TracksInfo; +impl pallet_referenda::TracksInfo for TracksInfo { + type Id = u16; + type RuntimeOrigin = ::PalletsOrigin; + + fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo)] { + &TRACKS_DATA[..] + } + + fn track_for(id: &Self::RuntimeOrigin) -> Result { + if let Ok(system_origin) = frame_system::RawOrigin::try_from(id.clone()) { + match system_origin { + frame_system::RawOrigin::Root => { + if let Some((track_id, _)) = + Self::tracks().iter().find(|(_, track)| track.name == "root") + { + Ok(*track_id) + } else { + Err(()) + } + }, + _ => Err(()), + } + } else if let Ok(custom_origin) = custom_origins::Origin::try_from(id.clone()) { + if let Some((track_id, _)) = Self::tracks().iter().find(|(_, track)| { + if let Ok(track_custom_origin) = custom_origins::Origin::from_str(track.name) { + track_custom_origin == custom_origin + } else { + false + } + }) { + Ok(*track_id) + } else { + Err(()) + } + } else { + Err(()) + } + } +} + +// To ensure voters are always locked into their vote +#[test] +fn vote_locking_always_longer_than_enactment_period() { + for (_, track) in TRACKS_DATA { + assert!( + ::VoteLockingPeriod::get() + >= track.min_enactment_period, + "Track {} has enactment period {} < vote locking period {}", + track.name, + track.min_enactment_period, + ::VoteLockingPeriod::get(), + ); + } +} + +#[test] +fn all_tracks_have_origins() { + for (_, track) in TRACKS_DATA { + // check name.into() is successful either converts into "root" or custom origin + let track_is_root = track.name == "root"; + let track_has_custom_origin = custom_origins::Origin::from_str(track.name).is_ok(); + + assert!(track_is_root || track_has_custom_origin); + } +} diff --git a/runtime/pangolin/src/pallets/democracy.rs b/runtime/pangolin/src/pallets/governance/v1.rs similarity index 65% rename from runtime/pangolin/src/pallets/democracy.rs rename to runtime/pangolin/src/pallets/governance/v1.rs index 46faffbe3..c7474493e 100644 --- a/runtime/pangolin/src/pallets/democracy.rs +++ b/runtime/pangolin/src/pallets/governance/v1.rs @@ -17,34 +17,25 @@ // along with Darwinia. If not, see . // darwinia -use crate::*; +use super::*; -const ENACTMENT_PERIOD: u32 = 10 * MINUTES; +const ENACTMENT_PERIOD: u32 = 2 * MINUTES; impl pallet_democracy::Config for Runtime { type BlacklistOrigin = Root; - // To cancel a proposal before it has been passed, the technical committee must be unanimous or - // Root must agree. type CancelProposalOrigin = RootOrAll; - // To cancel a proposal which has been passed, 2/3 of the council must agree to it. type CancellationOrigin = RootOrAtLeastTwoThird; - type CooloffPeriod = ConstU32<{ 5 * MINUTES }>; + type CooloffPeriod = ConstU32<{ 2 * MINUTES }>; type Currency = Balances; type EnactmentPeriod = ConstU32; - /// A unanimous council can have the next scheduled referendum be a straight default-carries - /// (NTB) vote. type ExternalDefaultOrigin = RootOrAll; - /// A majority can have the next scheduled referendum be a straight majority-carries vote. type ExternalMajorityOrigin = RootOrAtLeastHalf; - /// A straight majority of the council can decide what their next motion is. type ExternalOrigin = RootOrAtLeastHalf; - /// Two thirds of the technical committee can have an ExternalMajority/ExternalDefault vote - /// be tabled immediately and with a shorter voting/enactment period. type FastTrackOrigin = RootOrAtLeastTwoThird; - type FastTrackVotingPeriod = ConstU32<{ MINUTES }>; + type FastTrackVotingPeriod = ConstU32<{ 2 * MINUTES }>; type InstantAllowed = ConstBool; type InstantOrigin = RootOrAll; - type LaunchPeriod = ConstU32<{ 10 * MINUTES }>; + type LaunchPeriod = ConstU32<{ 2 * MINUTES }>; type MaxBlacklisted = ConstU32<100>; type MaxDeposits = ConstU32<100>; type MaxProposals = ConstU32<100>; @@ -56,10 +47,8 @@ impl pallet_democracy::Config for Runtime { type Scheduler = Scheduler; type Slash = Treasury; type SubmitOrigin = frame_system::EnsureSigned; - // Any single technical committee member may veto a coming council proposal, however they can - // only do it once and it lasts only for the cool-off period. type VetoOrigin = pallet_collective::EnsureMember; type VoteLockingPeriod = ConstU32; - type VotingPeriod = ConstU32<{ 10 * MINUTES }>; + type VotingPeriod = ConstU32<{ 2 * MINUTES }>; type WeightInfo = weights::pallet_democracy::WeightInfo; } diff --git a/runtime/pangolin/src/pallets/membership.rs b/runtime/pangolin/src/pallets/membership.rs deleted file mode 100644 index cd408cc37..000000000 --- a/runtime/pangolin/src/pallets/membership.rs +++ /dev/null @@ -1,33 +0,0 @@ -// This file is part of Darwinia. -// -// Copyright (C) 2018-2023 Darwinia Network -// SPDX-License-Identifier: GPL-3.0 -// -// Darwinia is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Darwinia is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Darwinia. If not, see . - -// darwinia -use crate::*; - -impl pallet_membership::Config for Runtime { - type AddOrigin = Root; - type MaxMembers = ConstU32; - type MembershipChanged = TechnicalCommittee; - type MembershipInitialized = TechnicalCommittee; - type PrimeOrigin = Root; - type RemoveOrigin = Root; - type ResetOrigin = Root; - type RuntimeEvent = RuntimeEvent; - type SwapOrigin = Root; - type WeightInfo = weights::pallet_membership::WeightInfo; -} diff --git a/runtime/pangolin/src/pallets/polkadot_xcm.rs b/runtime/pangolin/src/pallets/polkadot_xcm.rs index 9a11409ed..6c64ab43a 100644 --- a/runtime/pangolin/src/pallets/polkadot_xcm.rs +++ b/runtime/pangolin/src/pallets/polkadot_xcm.rs @@ -285,7 +285,7 @@ frame_support::parameter_types! { } impl pallet_xcm::Config for Runtime { - type AdminOrigin = Root; + type AdminOrigin = RootOr; // ^ Override for AdvertisedXcmVersion default type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; type Currency = Balances; diff --git a/runtime/pangolin/src/pallets/preimage.rs b/runtime/pangolin/src/pallets/preimage.rs index d6bef7f7c..600d6d0f0 100644 --- a/runtime/pangolin/src/pallets/preimage.rs +++ b/runtime/pangolin/src/pallets/preimage.rs @@ -23,7 +23,7 @@ impl pallet_preimage::Config for Runtime { type BaseDeposit = ConstU128<{ 500 * UNIT }>; type ByteDeposit = ConstU128<{ darwinia_deposit(0, 1) }>; type Currency = Balances; - type ManagerOrigin = Root; + type ManagerOrigin = RootOr; type RuntimeEvent = RuntimeEvent; type WeightInfo = weights::pallet_preimage::WeightInfo; } diff --git a/runtime/pangolin/src/pallets/proxy.rs b/runtime/pangolin/src/pallets/proxy.rs index 0ea3fdb56..de0b625b0 100644 --- a/runtime/pangolin/src/pallets/proxy.rs +++ b/runtime/pangolin/src/pallets/proxy.rs @@ -65,10 +65,10 @@ impl frame_support::traits::InstanceFilter for ProxyType { ), ProxyType::Governance => matches!( c, - RuntimeCall::Democracy(..) + RuntimeCall::Referenda(..) + | RuntimeCall::ConvictionVoting(..) | RuntimeCall::Council(..) | RuntimeCall::TechnicalCommittee(..) - | RuntimeCall::PhragmenElection(..) | RuntimeCall::Treasury(..) ), ProxyType::Staking => { diff --git a/runtime/pangolin/src/pallets/scheduler.rs b/runtime/pangolin/src/pallets/scheduler.rs index 868dfd6d6..551ec257b 100644 --- a/runtime/pangolin/src/pallets/scheduler.rs +++ b/runtime/pangolin/src/pallets/scheduler.rs @@ -58,6 +58,6 @@ impl pallet_scheduler::Config for Runtime { type RuntimeCall = RuntimeCall; type RuntimeEvent = RuntimeEvent; type RuntimeOrigin = RuntimeOrigin; - type ScheduleOrigin = Root; + type ScheduleOrigin = RootOr; type WeightInfo = weights::pallet_scheduler::WeightInfo; } diff --git a/runtime/pangolin/src/pallets/treasury.rs b/runtime/pangolin/src/pallets/treasury.rs index 1e769c6c5..7cc968834 100644 --- a/runtime/pangolin/src/pallets/treasury.rs +++ b/runtime/pangolin/src/pallets/treasury.rs @@ -27,7 +27,7 @@ frame_support::parameter_types! { // In order to use `Tips`, which bounded by `pallet_treasury::Config` rather // `pallet_treasury::Config` Still use `DefaultInstance` here instead `Instance1` impl pallet_treasury::Config for Runtime { - type ApproveOrigin = Root; + type ApproveOrigin = RootOr; type Burn = (); type BurnDestination = (); type Currency = Balances; diff --git a/runtime/pangolin/src/pallets/xcmp_queue.rs b/runtime/pangolin/src/pallets/xcmp_queue.rs index daa2bd1f8..9096525e0 100644 --- a/runtime/pangolin/src/pallets/xcmp_queue.rs +++ b/runtime/pangolin/src/pallets/xcmp_queue.rs @@ -21,9 +21,9 @@ use crate::*; impl cumulus_pallet_xcmp_queue::Config for Runtime { type ChannelInfo = ParachainSystem; - type ControllerOrigin = Root; + type ControllerOrigin = RootOr; type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; - type ExecuteOverweightOrigin = Root; + type ExecuteOverweightOrigin = RootOr; type PriceForSiblingDelivery = (); type RuntimeEvent = RuntimeEvent; type VersionWrapper = (); diff --git a/runtime/pangolin/src/weights.rs b/runtime/pangolin/src/weights.rs index 2b0cc3ec5..11f84e93a 100644 --- a/runtime/pangolin/src/weights.rs +++ b/runtime/pangolin/src/weights.rs @@ -38,10 +38,8 @@ pub mod pallet_bridge_grandpa; pub mod pallet_collective_council; pub mod pallet_collective_technical_committee; pub mod pallet_democracy; -pub mod pallet_elections_phragmen; pub mod pallet_fee_market; pub mod pallet_identity; -pub mod pallet_membership; pub mod pallet_preimage; pub mod pallet_proxy; pub mod pallet_scheduler; diff --git a/runtime/pangolin/src/weights/pallet_elections_phragmen.rs b/runtime/pangolin/src/weights/pallet_elections_phragmen.rs deleted file mode 100644 index f1325f962..000000000 --- a/runtime/pangolin/src/weights/pallet_elections_phragmen.rs +++ /dev/null @@ -1,328 +0,0 @@ -// This file is part of Darwinia. -// -// Copyright (C) 2018-2023 Darwinia Network -// SPDX-License-Identifier: GPL-3.0 -// -// Darwinia is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Darwinia is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Darwinia. If not, see . - -//! Autogenerated weights for `pallet_elections_phragmen` -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-07-28, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `inv.cafe`, CPU: `13th Gen Intel(R) Core(TM) i9-13900K` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("pangolin-dev"), DB CACHE: 1024 - -// Executed Command: -// target/release/darwinia -// benchmark -// pallet -// --header -// .maintain/license-header -// --execution -// wasm -// --heap-pages -// 4096 -// --chain -// pangolin-dev -// --output -// runtime/pangolin/src/weights -// --extrinsic -// * -// --pallet -// * -// --steps -// 50 -// --repeat -// 20 - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(missing_docs)] - -use frame_support::{traits::Get, weights::Weight}; -use core::marker::PhantomData; - -/// Weight functions for `pallet_elections_phragmen`. -pub struct WeightInfo(PhantomData); -impl pallet_elections_phragmen::WeightInfo for WeightInfo { - /// Storage: PhragmenElection Candidates (r:1 w:0) - /// Proof Skipped: PhragmenElection Candidates (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: PhragmenElection Members (r:1 w:0) - /// Proof Skipped: PhragmenElection Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: PhragmenElection RunnersUp (r:1 w:0) - /// Proof Skipped: PhragmenElection RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: PhragmenElection Voting (r:1 w:1) - /// Proof Skipped: PhragmenElection Voting (max_values: None, max_size: None, mode: Measured) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1287), added: 3762, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(37), added: 2512, mode: MaxEncodedLen) - /// The range of component `v` is `[1, 16]`. - fn vote_equal(v: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `405 + v * (56 ±0)` - // Estimated: `4752 + v * (56 ±0)` - // Minimum execution time: 22_836_000 picoseconds. - Weight::from_parts(23_866_625, 0) - .saturating_add(Weight::from_parts(0, 4752)) - // Standard Error: 4_802 - .saturating_add(Weight::from_parts(140_515, 0).saturating_mul(v.into())) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(2)) - .saturating_add(Weight::from_parts(0, 56).saturating_mul(v.into())) - } - /// Storage: PhragmenElection Candidates (r:1 w:0) - /// Proof Skipped: PhragmenElection Candidates (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: PhragmenElection Members (r:1 w:0) - /// Proof Skipped: PhragmenElection Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: PhragmenElection RunnersUp (r:1 w:0) - /// Proof Skipped: PhragmenElection RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: PhragmenElection Voting (r:1 w:1) - /// Proof Skipped: PhragmenElection Voting (max_values: None, max_size: None, mode: Measured) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1287), added: 3762, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(37), added: 2512, mode: MaxEncodedLen) - /// The range of component `v` is `[2, 16]`. - fn vote_more(v: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `385 + v * (56 ±0)` - // Estimated: `4752 + v * (56 ±0)` - // Minimum execution time: 32_174_000 picoseconds. - Weight::from_parts(33_261_992, 0) - .saturating_add(Weight::from_parts(0, 4752)) - // Standard Error: 8_201 - .saturating_add(Weight::from_parts(200_408, 0).saturating_mul(v.into())) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(2)) - .saturating_add(Weight::from_parts(0, 56).saturating_mul(v.into())) - } - /// Storage: PhragmenElection Candidates (r:1 w:0) - /// Proof Skipped: PhragmenElection Candidates (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: PhragmenElection Members (r:1 w:0) - /// Proof Skipped: PhragmenElection Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: PhragmenElection RunnersUp (r:1 w:0) - /// Proof Skipped: PhragmenElection RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: PhragmenElection Voting (r:1 w:1) - /// Proof Skipped: PhragmenElection Voting (max_values: None, max_size: None, mode: Measured) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1287), added: 3762, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(37), added: 2512, mode: MaxEncodedLen) - /// The range of component `v` is `[2, 16]`. - fn vote_less(v: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `405 + v * (56 ±0)` - // Estimated: `4752 + v * (56 ±0)` - // Minimum execution time: 32_546_000 picoseconds. - Weight::from_parts(33_600_425, 0) - .saturating_add(Weight::from_parts(0, 4752)) - // Standard Error: 6_320 - .saturating_add(Weight::from_parts(157_859, 0).saturating_mul(v.into())) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(2)) - .saturating_add(Weight::from_parts(0, 56).saturating_mul(v.into())) - } - /// Storage: PhragmenElection Voting (r:1 w:1) - /// Proof Skipped: PhragmenElection Voting (max_values: None, max_size: None, mode: Measured) - /// Storage: Balances Locks (r:1 w:1) - /// Proof: Balances Locks (max_values: None, max_size: Some(1287), added: 3762, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:1 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(37), added: 2512, mode: MaxEncodedLen) - fn remove_voter() -> Weight { - // Proof Size summary in bytes: - // Measured: `735` - // Estimated: `4752` - // Minimum execution time: 35_033_000 picoseconds. - Weight::from_parts(36_254_000, 0) - .saturating_add(Weight::from_parts(0, 4752)) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(2)) - } - /// Storage: PhragmenElection Candidates (r:1 w:1) - /// Proof Skipped: PhragmenElection Candidates (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: PhragmenElection Members (r:1 w:0) - /// Proof Skipped: PhragmenElection Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: PhragmenElection RunnersUp (r:1 w:0) - /// Proof Skipped: PhragmenElection RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - /// The range of component `c` is `[1, 30]`. - fn submit_candidacy(c: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `1116 + c * (36 ±0)` - // Estimated: `2592 + c * (37 ±0)` - // Minimum execution time: 25_676_000 picoseconds. - Weight::from_parts(27_444_740, 0) - .saturating_add(Weight::from_parts(0, 2592)) - // Standard Error: 4_103 - .saturating_add(Weight::from_parts(83_653, 0).saturating_mul(c.into())) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(1)) - .saturating_add(Weight::from_parts(0, 37).saturating_mul(c.into())) - } - /// Storage: PhragmenElection Candidates (r:1 w:1) - /// Proof Skipped: PhragmenElection Candidates (max_values: Some(1), max_size: None, mode: Measured) - /// The range of component `c` is `[1, 30]`. - fn renounce_candidacy_candidate(c: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `375 + c * (38 ±0)` - // Estimated: `1857 + c * (39 ±0)` - // Minimum execution time: 23_286_000 picoseconds. - Weight::from_parts(24_864_459, 0) - .saturating_add(Weight::from_parts(0, 1857)) - // Standard Error: 3_765 - .saturating_add(Weight::from_parts(84_536, 0).saturating_mul(c.into())) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - .saturating_add(Weight::from_parts(0, 39).saturating_mul(c.into())) - } - /// Storage: PhragmenElection Members (r:1 w:1) - /// Proof Skipped: PhragmenElection Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: PhragmenElection RunnersUp (r:1 w:1) - /// Proof Skipped: PhragmenElection RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Council Prime (r:1 w:1) - /// Proof Skipped: Council Prime (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Council Proposals (r:1 w:0) - /// Proof Skipped: Council Proposals (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Council Members (r:0 w:1) - /// Proof Skipped: Council Members (max_values: Some(1), max_size: None, mode: Measured) - fn renounce_candidacy_members() -> Weight { - // Proof Size summary in bytes: - // Measured: `1137` - // Estimated: `2622` - // Minimum execution time: 31_432_000 picoseconds. - Weight::from_parts(33_343_000, 0) - .saturating_add(Weight::from_parts(0, 2622)) - .saturating_add(T::DbWeight::get().reads(4)) - .saturating_add(T::DbWeight::get().writes(4)) - } - /// Storage: PhragmenElection RunnersUp (r:1 w:1) - /// Proof Skipped: PhragmenElection RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - fn renounce_candidacy_runners_up() -> Weight { - // Proof Size summary in bytes: - // Measured: `700` - // Estimated: `2185` - // Minimum execution time: 22_474_000 picoseconds. - Weight::from_parts(24_282_000, 0) - .saturating_add(Weight::from_parts(0, 2185)) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(1)) - } - /// Storage: Benchmark Override (r:0 w:0) - /// Proof Skipped: Benchmark Override (max_values: None, max_size: None, mode: Measured) - fn remove_member_without_replacement() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 500_000_000_000 picoseconds. - Weight::from_parts(500_000_000_000, 0) - .saturating_add(Weight::from_parts(0, 0)) - } - /// Storage: PhragmenElection Members (r:1 w:1) - /// Proof Skipped: PhragmenElection Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: System Account (r:2 w:2) - /// Proof: System Account (max_values: None, max_size: Some(116), added: 2591, mode: MaxEncodedLen) - /// Storage: PhragmenElection RunnersUp (r:1 w:1) - /// Proof Skipped: PhragmenElection RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Council Prime (r:1 w:1) - /// Proof Skipped: Council Prime (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Council Proposals (r:1 w:0) - /// Proof Skipped: Council Proposals (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Council Members (r:0 w:1) - /// Proof Skipped: Council Members (max_values: Some(1), max_size: None, mode: Measured) - fn remove_member_with_replacement() -> Weight { - // Proof Size summary in bytes: - // Measured: `1332` - // Estimated: `6172` - // Minimum execution time: 47_679_000 picoseconds. - Weight::from_parts(49_928_000, 0) - .saturating_add(Weight::from_parts(0, 6172)) - .saturating_add(T::DbWeight::get().reads(6)) - .saturating_add(T::DbWeight::get().writes(6)) - } - /// Storage: PhragmenElection Voting (r:301 w:300) - /// Proof Skipped: PhragmenElection Voting (max_values: None, max_size: None, mode: Measured) - /// Storage: PhragmenElection Members (r:1 w:0) - /// Proof Skipped: PhragmenElection Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: PhragmenElection RunnersUp (r:1 w:0) - /// Proof Skipped: PhragmenElection RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: PhragmenElection Candidates (r:1 w:0) - /// Proof Skipped: PhragmenElection Candidates (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Balances Locks (r:300 w:300) - /// Proof: Balances Locks (max_values: None, max_size: Some(1287), added: 3762, mode: MaxEncodedLen) - /// Storage: Balances Freezes (r:300 w:0) - /// Proof: Balances Freezes (max_values: None, max_size: Some(37), added: 2512, mode: MaxEncodedLen) - /// Storage: System Account (r:300 w:300) - /// Proof: System Account (max_values: None, max_size: Some(116), added: 2591, mode: MaxEncodedLen) - /// The range of component `v` is `[150, 300]`. - /// The range of component `d` is `[0, 150]`. - fn clean_defunct_voters(v: u32, _d: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `939 + v * (582 ±0)` - // Estimated: `4424 + v * (3762 ±0)` - // Minimum execution time: 7_771_828_000 picoseconds. - Weight::from_parts(7_804_607_000, 0) - .saturating_add(Weight::from_parts(0, 4424)) - // Standard Error: 220_919 - .saturating_add(Weight::from_parts(32_217_369, 0).saturating_mul(v.into())) - .saturating_add(T::DbWeight::get().reads(4)) - .saturating_add(T::DbWeight::get().reads((4_u64).saturating_mul(v.into()))) - .saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(v.into()))) - .saturating_add(Weight::from_parts(0, 3762).saturating_mul(v.into())) - } - /// Storage: PhragmenElection Candidates (r:1 w:1) - /// Proof Skipped: PhragmenElection Candidates (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: PhragmenElection Members (r:1 w:1) - /// Proof Skipped: PhragmenElection Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: PhragmenElection RunnersUp (r:1 w:1) - /// Proof Skipped: PhragmenElection RunnersUp (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: PhragmenElection Voting (r:301 w:0) - /// Proof Skipped: PhragmenElection Voting (max_values: None, max_size: None, mode: Measured) - /// Storage: Council Proposals (r:1 w:0) - /// Proof Skipped: Council Proposals (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: System Account (r:17 w:17) - /// Proof: System Account (max_values: None, max_size: Some(116), added: 2591, mode: MaxEncodedLen) - /// Storage: PhragmenElection ElectionRounds (r:1 w:1) - /// Proof Skipped: PhragmenElection ElectionRounds (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Council Members (r:0 w:1) - /// Proof Skipped: Council Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: Council Prime (r:0 w:1) - /// Proof Skipped: Council Prime (max_values: Some(1), max_size: None, mode: Measured) - /// The range of component `c` is `[1, 30]`. - /// The range of component `v` is `[1, 300]`. - /// The range of component `e` is `[300, 4800]`. - fn election_phragmen(c: u32, v: u32, e: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `0 + c * (3085 ±0) + e * (18 ±0) + v * (400 ±0)` - // Estimated: `83983 + c * (1738 ±10) + e * (5 ±0) + v * (2547 ±4)` - // Minimum execution time: 502_249_000 picoseconds. - Weight::from_parts(511_465_000, 0) - .saturating_add(Weight::from_parts(0, 83983)) - // Standard Error: 2_190_223 - .saturating_add(Weight::from_parts(14_891_996, 0).saturating_mul(c.into())) - // Standard Error: 218_061 - .saturating_add(Weight::from_parts(6_458_226, 0).saturating_mul(v.into())) - // Standard Error: 13_989 - .saturating_add(Weight::from_parts(161_829, 0).saturating_mul(e.into())) - .saturating_add(T::DbWeight::get().reads(12)) - .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(c.into()))) - .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(v.into()))) - .saturating_add(T::DbWeight::get().writes(4)) - .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(c.into()))) - .saturating_add(Weight::from_parts(0, 1738).saturating_mul(c.into())) - .saturating_add(Weight::from_parts(0, 5).saturating_mul(e.into())) - .saturating_add(Weight::from_parts(0, 2547).saturating_mul(v.into())) - } -} diff --git a/runtime/pangolin/src/weights/pallet_membership.rs b/runtime/pangolin/src/weights/pallet_membership.rs deleted file mode 100644 index a825d4cce..000000000 --- a/runtime/pangolin/src/weights/pallet_membership.rs +++ /dev/null @@ -1,215 +0,0 @@ -// This file is part of Darwinia. -// -// Copyright (C) 2018-2023 Darwinia Network -// SPDX-License-Identifier: GPL-3.0 -// -// Darwinia is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Darwinia is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Darwinia. If not, see . - -//! Autogenerated weights for `pallet_membership` -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev -//! DATE: 2023-07-28, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `inv.cafe`, CPU: `13th Gen Intel(R) Core(TM) i9-13900K` -//! EXECUTION: Some(Wasm), WASM-EXECUTION: Compiled, CHAIN: Some("pangolin-dev"), DB CACHE: 1024 - -// Executed Command: -// target/release/darwinia -// benchmark -// pallet -// --header -// .maintain/license-header -// --execution -// wasm -// --heap-pages -// 4096 -// --chain -// pangolin-dev -// --output -// runtime/pangolin/src/weights -// --extrinsic -// * -// --pallet -// * -// --steps -// 50 -// --repeat -// 20 - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(missing_docs)] - -use frame_support::{traits::Get, weights::Weight}; -use core::marker::PhantomData; - -/// Weight functions for `pallet_membership`. -pub struct WeightInfo(PhantomData); -impl pallet_membership::WeightInfo for WeightInfo { - /// Storage: TechnicalMembership Members (r:1 w:1) - /// Proof: TechnicalMembership Members (max_values: Some(1), max_size: Some(2002), added: 2497, mode: MaxEncodedLen) - /// Storage: TechnicalCommittee Proposals (r:1 w:0) - /// Proof Skipped: TechnicalCommittee Proposals (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: TechnicalCommittee Members (r:0 w:1) - /// Proof Skipped: TechnicalCommittee Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: TechnicalCommittee Prime (r:0 w:1) - /// Proof Skipped: TechnicalCommittee Prime (max_values: Some(1), max_size: None, mode: Measured) - /// The range of component `m` is `[1, 99]`. - fn add_member(m: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `135 + m * (40 ±0)` - // Estimated: `3487 + m * (40 ±0)` - // Minimum execution time: 10_369_000 picoseconds. - Weight::from_parts(12_094_269, 0) - .saturating_add(Weight::from_parts(0, 3487)) - // Standard Error: 3_523 - .saturating_add(Weight::from_parts(1_325, 0).saturating_mul(m.into())) - .saturating_add(T::DbWeight::get().reads(2)) - .saturating_add(T::DbWeight::get().writes(3)) - .saturating_add(Weight::from_parts(0, 40).saturating_mul(m.into())) - } - /// Storage: TechnicalMembership Members (r:1 w:1) - /// Proof: TechnicalMembership Members (max_values: Some(1), max_size: Some(2002), added: 2497, mode: MaxEncodedLen) - /// Storage: TechnicalCommittee Proposals (r:1 w:0) - /// Proof Skipped: TechnicalCommittee Proposals (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: TechnicalMembership Prime (r:1 w:0) - /// Proof: TechnicalMembership Prime (max_values: Some(1), max_size: Some(20), added: 515, mode: MaxEncodedLen) - /// Storage: TechnicalCommittee Members (r:0 w:1) - /// Proof Skipped: TechnicalCommittee Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: TechnicalCommittee Prime (r:0 w:1) - /// Proof Skipped: TechnicalCommittee Prime (max_values: Some(1), max_size: None, mode: Measured) - /// The range of component `m` is `[2, 100]`. - fn remove_member(m: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `215 + m * (40 ±0)` - // Estimated: `3487 + m * (40 ±0)` - // Minimum execution time: 12_404_000 picoseconds. - Weight::from_parts(13_339_434, 0) - .saturating_add(Weight::from_parts(0, 3487)) - // Standard Error: 502 - .saturating_add(Weight::from_parts(9_013, 0).saturating_mul(m.into())) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(3)) - .saturating_add(Weight::from_parts(0, 40).saturating_mul(m.into())) - } - /// Storage: TechnicalMembership Members (r:1 w:1) - /// Proof: TechnicalMembership Members (max_values: Some(1), max_size: Some(2002), added: 2497, mode: MaxEncodedLen) - /// Storage: TechnicalCommittee Proposals (r:1 w:0) - /// Proof Skipped: TechnicalCommittee Proposals (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: TechnicalMembership Prime (r:1 w:0) - /// Proof: TechnicalMembership Prime (max_values: Some(1), max_size: Some(20), added: 515, mode: MaxEncodedLen) - /// Storage: TechnicalCommittee Members (r:0 w:1) - /// Proof Skipped: TechnicalCommittee Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: TechnicalCommittee Prime (r:0 w:1) - /// Proof Skipped: TechnicalCommittee Prime (max_values: Some(1), max_size: None, mode: Measured) - /// The range of component `m` is `[2, 100]`. - fn swap_member(m: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `215 + m * (40 ±0)` - // Estimated: `3487 + m * (40 ±0)` - // Minimum execution time: 12_556_000 picoseconds. - Weight::from_parts(14_644_636, 0) - .saturating_add(Weight::from_parts(0, 3487)) - // Standard Error: 3_928 - .saturating_add(Weight::from_parts(208, 0).saturating_mul(m.into())) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(3)) - .saturating_add(Weight::from_parts(0, 40).saturating_mul(m.into())) - } - /// Storage: TechnicalMembership Members (r:1 w:1) - /// Proof: TechnicalMembership Members (max_values: Some(1), max_size: Some(2002), added: 2497, mode: MaxEncodedLen) - /// Storage: TechnicalCommittee Proposals (r:1 w:0) - /// Proof Skipped: TechnicalCommittee Proposals (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: TechnicalMembership Prime (r:1 w:0) - /// Proof: TechnicalMembership Prime (max_values: Some(1), max_size: Some(20), added: 515, mode: MaxEncodedLen) - /// Storage: TechnicalCommittee Members (r:0 w:1) - /// Proof Skipped: TechnicalCommittee Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: TechnicalCommittee Prime (r:0 w:1) - /// Proof Skipped: TechnicalCommittee Prime (max_values: Some(1), max_size: None, mode: Measured) - /// The range of component `m` is `[1, 100]`. - fn reset_member(m: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `215 + m * (40 ±0)` - // Estimated: `3487 + m * (40 ±0)` - // Minimum execution time: 12_070_000 picoseconds. - Weight::from_parts(13_532_144, 0) - .saturating_add(Weight::from_parts(0, 3487)) - // Standard Error: 799 - .saturating_add(Weight::from_parts(74_316, 0).saturating_mul(m.into())) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(3)) - .saturating_add(Weight::from_parts(0, 40).saturating_mul(m.into())) - } - /// Storage: TechnicalMembership Members (r:1 w:1) - /// Proof: TechnicalMembership Members (max_values: Some(1), max_size: Some(2002), added: 2497, mode: MaxEncodedLen) - /// Storage: TechnicalCommittee Proposals (r:1 w:0) - /// Proof Skipped: TechnicalCommittee Proposals (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: TechnicalMembership Prime (r:1 w:1) - /// Proof: TechnicalMembership Prime (max_values: Some(1), max_size: Some(20), added: 515, mode: MaxEncodedLen) - /// Storage: TechnicalCommittee Members (r:0 w:1) - /// Proof Skipped: TechnicalCommittee Members (max_values: Some(1), max_size: None, mode: Measured) - /// Storage: TechnicalCommittee Prime (r:0 w:1) - /// Proof Skipped: TechnicalCommittee Prime (max_values: Some(1), max_size: None, mode: Measured) - /// The range of component `m` is `[1, 100]`. - fn change_key(m: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `215 + m * (40 ±0)` - // Estimated: `3487 + m * (40 ±0)` - // Minimum execution time: 12_884_000 picoseconds. - Weight::from_parts(14_121_225, 0) - .saturating_add(Weight::from_parts(0, 3487)) - // Standard Error: 804 - .saturating_add(Weight::from_parts(13_145, 0).saturating_mul(m.into())) - .saturating_add(T::DbWeight::get().reads(3)) - .saturating_add(T::DbWeight::get().writes(4)) - .saturating_add(Weight::from_parts(0, 40).saturating_mul(m.into())) - } - /// Storage: TechnicalMembership Members (r:1 w:0) - /// Proof: TechnicalMembership Members (max_values: Some(1), max_size: Some(2002), added: 2497, mode: MaxEncodedLen) - /// Storage: TechnicalMembership Prime (r:0 w:1) - /// Proof: TechnicalMembership Prime (max_values: Some(1), max_size: Some(20), added: 515, mode: MaxEncodedLen) - /// Storage: TechnicalCommittee Prime (r:0 w:1) - /// Proof Skipped: TechnicalCommittee Prime (max_values: Some(1), max_size: None, mode: Measured) - /// The range of component `m` is `[1, 100]`. - fn set_prime(m: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `31 + m * (20 ±0)` - // Estimated: `3487 + m * (20 ±0)` - // Minimum execution time: 5_086_000 picoseconds. - Weight::from_parts(5_621_470, 0) - .saturating_add(Weight::from_parts(0, 3487)) - // Standard Error: 2_352 - .saturating_add(Weight::from_parts(11_067, 0).saturating_mul(m.into())) - .saturating_add(T::DbWeight::get().reads(1)) - .saturating_add(T::DbWeight::get().writes(2)) - .saturating_add(Weight::from_parts(0, 20).saturating_mul(m.into())) - } - /// Storage: TechnicalMembership Prime (r:0 w:1) - /// Proof: TechnicalMembership Prime (max_values: Some(1), max_size: Some(20), added: 515, mode: MaxEncodedLen) - /// Storage: TechnicalCommittee Prime (r:0 w:1) - /// Proof Skipped: TechnicalCommittee Prime (max_values: Some(1), max_size: None, mode: Measured) - /// The range of component `m` is `[1, 100]`. - fn clear_prime(m: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 2_022_000 picoseconds. - Weight::from_parts(2_279_793, 0) - .saturating_add(Weight::from_parts(0, 0)) - // Standard Error: 122 - .saturating_add(Weight::from_parts(127, 0).saturating_mul(m.into())) - .saturating_add(T::DbWeight::get().writes(2)) - } -} diff --git a/runtime/pangoro/Cargo.toml b/runtime/pangoro/Cargo.toml index 7a1722c06..30707d4d8 100644 --- a/runtime/pangoro/Cargo.toml +++ b/runtime/pangoro/Cargo.toml @@ -257,8 +257,6 @@ evm-tracing = [ "moonbeam-evm-tracer", ] -fast-runtime = [] - # A feature that should be enabled when the runtime should be build for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller like logging for example. From 2e061c0c05fa923aad906a5a08b94ba7388fcf2c Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Wed, 11 Oct 2023 12:09:29 +0800 Subject: [PATCH 2/7] Restructure --- node/src/chain_spec/pangolin.rs | 2 ++ runtime/pangolin/src/lib.rs | 14 +++++++------- runtime/pangolin/src/pallets.rs | 3 --- runtime/pangolin/src/pallets/governance.rs | 2 ++ .../src/pallets/{ => governance}/treasury.rs | 4 ++-- runtime/pangolin/src/pallets/governance/v1.rs | 2 +- runtime/pangolin/src/pallets/staking.rs | 2 +- 7 files changed, 15 insertions(+), 14 deletions(-) rename runtime/pangolin/src/pallets/{ => governance}/treasury.rs (96%) diff --git a/node/src/chain_spec/pangolin.rs b/node/src/chain_spec/pangolin.rs index a6c0621ed..9fae26fbf 100644 --- a/node/src/chain_spec/pangolin.rs +++ b/node/src/chain_spec/pangolin.rs @@ -215,6 +215,7 @@ pub fn genesis_config() -> ChainSpec { council: Default::default(), technical_committee: Default::default(), treasury: Default::default(), + democracy: Default::default(), // Utility stuff. sudo: SudoConfig { key: Some(array_bytes::hex_n_into_unchecked(SUDO)) }, @@ -334,6 +335,7 @@ fn testnet_genesis( ..Default::default() }, treasury: Default::default(), + democracy: Default::default(), // Utility stuff. sudo: SudoConfig { key: Some(array_bytes::hex_n_into_unchecked(ALITH)) }, diff --git a/runtime/pangolin/src/lib.rs b/runtime/pangolin/src/lib.rs index 9a8527eb7..e98d6d105 100644 --- a/runtime/pangolin/src/lib.rs +++ b/runtime/pangolin/src/lib.rs @@ -145,17 +145,17 @@ frame_support::construct_runtime! { EcdsaAuthority: darwinia_ecdsa_authority = 17, // Governance stuff. - ConvictionVoting: pallet_conviction_voting = 48, - Referenda: pallet_referenda = 49, - Origins: custom_origins = 50, - Whitelist: pallet_whitelist = 51, - Democracy: pallet_democracy = 18, - Council: pallet_collective:: = 19, - TechnicalCommittee: pallet_collective:: = 20, // PhragmenElection: pallet_elections_phragmen = 21, // TechnicalMembership: pallet_membership:: = 22, + Council: pallet_collective:: = 19, + TechnicalCommittee: pallet_collective:: = 20, Treasury: pallet_treasury = 23, // Tips: pallet_tips = 24, + Democracy: pallet_democracy = 18, + ConvictionVoting: pallet_conviction_voting = 48, + Referenda: pallet_referenda = 49, + Origins: custom_origins = 50, + Whitelist: pallet_whitelist = 51, // Utility stuff. Sudo: pallet_sudo = 25, diff --git a/runtime/pangolin/src/pallets.rs b/runtime/pangolin/src/pallets.rs index a9ee8186a..ec709be80 100644 --- a/runtime/pangolin/src/pallets.rs +++ b/runtime/pangolin/src/pallets.rs @@ -68,9 +68,6 @@ mod ecdsa_authority; mod governance; pub use governance::*; -mod treasury; -pub use treasury::*; - // Utility stuff. mod sudo; diff --git a/runtime/pangolin/src/pallets/governance.rs b/runtime/pangolin/src/pallets/governance.rs index 6fb862542..21fa9c200 100644 --- a/runtime/pangolin/src/pallets/governance.rs +++ b/runtime/pangolin/src/pallets/governance.rs @@ -20,6 +20,8 @@ mod origin; use origin::*; pub use origin::{custom_origins, GeneralAdmin}; +mod treasury; + mod track; use track::*; diff --git a/runtime/pangolin/src/pallets/treasury.rs b/runtime/pangolin/src/pallets/governance/treasury.rs similarity index 96% rename from runtime/pangolin/src/pallets/treasury.rs rename to runtime/pangolin/src/pallets/governance/treasury.rs index 7cc968834..6e9ff1080 100644 --- a/runtime/pangolin/src/pallets/treasury.rs +++ b/runtime/pangolin/src/pallets/governance/treasury.rs @@ -17,7 +17,7 @@ // along with Darwinia. If not, see . // darwinia -use crate::*; +use super::*; frame_support::parameter_types! { pub const TreasuryPalletId: frame_support::PalletId = frame_support::PalletId(*b"da/trsry"); @@ -41,6 +41,6 @@ impl pallet_treasury::Config for Runtime { type RuntimeEvent = RuntimeEvent; type SpendFunds = (); type SpendOrigin = frame_support::traits::NeverEnsureOrigin; - type SpendPeriod = ConstU32<{ 10 * MINUTES }>; + type SpendPeriod = ConstU32<{ 2 * MINUTES }>; type WeightInfo = weights::pallet_treasury::WeightInfo; } diff --git a/runtime/pangolin/src/pallets/governance/v1.rs b/runtime/pangolin/src/pallets/governance/v1.rs index c7474493e..e937cfebb 100644 --- a/runtime/pangolin/src/pallets/governance/v1.rs +++ b/runtime/pangolin/src/pallets/governance/v1.rs @@ -23,7 +23,7 @@ const ENACTMENT_PERIOD: u32 = 2 * MINUTES; impl pallet_democracy::Config for Runtime { type BlacklistOrigin = Root; - type CancelProposalOrigin = RootOrAll; + type CancelProposalOrigin = RootOrAtLeastTwoThird; type CancellationOrigin = RootOrAtLeastTwoThird; type CooloffPeriod = ConstU32<{ 2 * MINUTES }>; type Currency = Balances; diff --git a/runtime/pangolin/src/pallets/staking.rs b/runtime/pangolin/src/pallets/staking.rs index 805beca6c..1b69102c2 100644 --- a/runtime/pangolin/src/pallets/staking.rs +++ b/runtime/pangolin/src/pallets/staking.rs @@ -77,7 +77,7 @@ impl darwinia_staking::Config for Runtime { type MaxCommission = MaxCommission; type MaxDeposits = ::MaxDeposits; type MaxUnstakings = ConstU32<16>; - type MinStakingDuration = ConstU32<{ 10 * MINUTES }>; + type MinStakingDuration = ConstU32<{ 2 * MINUTES }>; type PayoutFraction = PayoutFraction; type RewardRemainder = Treasury; type Ring = RingStaking; From 0925892deead449fc7c39201635bebf03ae5269c Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Wed, 11 Oct 2023 12:15:01 +0800 Subject: [PATCH 3/7] Add migration --- runtime/pangolin/src/migration.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/runtime/pangolin/src/migration.rs b/runtime/pangolin/src/migration.rs index 675d47fca..245778f55 100644 --- a/runtime/pangolin/src/migration.rs +++ b/runtime/pangolin/src/migration.rs @@ -41,7 +41,15 @@ impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade { } fn migrate() -> frame_support::weights::Weight { - frame_support::weights::Weight::zero() - // RuntimeBlockWeights::get().max_block + migration::clear_storage_prefix(b"PhragmenElection", b"Members", &[], None, None); + migration::clear_storage_prefix(b"PhragmenElection", b"RunnersUp", &[], None, None); + migration::clear_storage_prefix(b"PhragmenElection", b"Candidates", &[], None, None); + migration::clear_storage_prefix(b"PhragmenElection", b"ElectionRounds", &[], None, None); + migration::clear_storage_prefix(b"PhragmenElection", b"Voting", &[], None, None); + migration::clear_storage_prefix(b"TechnicalMembership", b"Members", &[], None, None); + migration::clear_storage_prefix(b"TechnicalMembership", b"Prime", &[], None, None); + + // frame_support::weights::Weight::zero() + RuntimeBlockWeights::get().max_block // ::DbWeight::get().reads_writes(5, 5) } From d9d7635d973b8f2f92de207cb8e0fea0700bef81 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Wed, 11 Oct 2023 12:17:32 +0800 Subject: [PATCH 4/7] Correct dependencies --- Cargo.lock | 2 -- runtime/pangolin/Cargo.toml | 5 +++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 921b1fed8..b13b978cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8844,7 +8844,6 @@ dependencies = [ "pallet-collective", "pallet-conviction-voting", "pallet-democracy", - "pallet-elections-phragmen", "pallet-ethereum", "pallet-ethereum-xcm", "pallet-evm", @@ -8855,7 +8854,6 @@ dependencies = [ "pallet-evm-precompile-simple", "pallet-fee-market", "pallet-identity", - "pallet-membership", "pallet-preimage", "pallet-proxy", "pallet-referenda", diff --git a/runtime/pangolin/Cargo.toml b/runtime/pangolin/Cargo.toml index 6d2244c4a..49a585a48 100644 --- a/runtime/pangolin/Cargo.toml +++ b/runtime/pangolin/Cargo.toml @@ -104,9 +104,7 @@ pallet-balances = { workspace = true } pallet-collective = { workspace = true } pallet-conviction-voting = { workspace = true } pallet-democracy = { workspace = true } -pallet-elections-phragmen = { workspace = true } pallet-identity = { workspace = true } -pallet-membership = { workspace = true } pallet-preimage = { workspace = true } pallet-proxy = { workspace = true } pallet-referenda = { workspace = true } @@ -238,6 +236,7 @@ std = [ "pallet-balances/std", "pallet-collective/std", "pallet-conviction-voting/std", + "pallet-democracy/std", "pallet-identity/std", "pallet-preimage/std", "pallet-proxy/std", @@ -335,6 +334,7 @@ runtime-benchmarks = [ "pallet-balances/runtime-benchmarks", "pallet-collective/runtime-benchmarks", "pallet-conviction-voting/runtime-benchmarks", + "pallet-democracy/runtime-benchmarks", "pallet-identity/runtime-benchmarks", "pallet-preimage/runtime-benchmarks", "pallet-proxy/runtime-benchmarks", @@ -402,6 +402,7 @@ try-runtime = [ "pallet-balances/try-runtime", "pallet-collective/try-runtime", "pallet-conviction-voting/try-runtime", + "pallet-democracy/try-runtime", "pallet-identity/try-runtime", "pallet-preimage/try-runtime", "pallet-proxy/try-runtime", From 276d68f5ae7fdcd163eed0a14cd408faebc206da Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Wed, 11 Oct 2023 14:22:15 +0800 Subject: [PATCH 5/7] Fix compile --- runtime/pangolin/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/runtime/pangolin/src/lib.rs b/runtime/pangolin/src/lib.rs index e98d6d105..4eb7d0e3e 100644 --- a/runtime/pangolin/src/lib.rs +++ b/runtime/pangolin/src/lib.rs @@ -211,9 +211,7 @@ frame_benchmarking::define_benchmarks! { [pallet_collective, Council] [pallet_collective, TechnicalCommittee] [pallet_democracy, Democracy] - [pallet_elections_phragmen, PhragmenElection] [pallet_identity, Identity] - [pallet_membership, TechnicalMembership] [pallet_preimage, Preimage] [pallet_proxy, Proxy] [pallet_scheduler, Scheduler] From 96451086c21dbe1b62340fdb4b481766be33b3d5 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Wed, 11 Oct 2023 15:57:31 +0800 Subject: [PATCH 6/7] Fix test --- runtime/pangolin/src/pallets/governance/track.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runtime/pangolin/src/pallets/governance/track.rs b/runtime/pangolin/src/pallets/governance/track.rs index 3c6b48103..781a4a95c 100644 --- a/runtime/pangolin/src/pallets/governance/track.rs +++ b/runtime/pangolin/src/pallets/governance/track.rs @@ -213,13 +213,13 @@ impl pallet_referenda::TracksInfo for TracksInfo { #[test] fn vote_locking_always_longer_than_enactment_period() { for (_, track) in TRACKS_DATA { + let vote_locking_period = <::VoteLockingPeriod as frame_support::traits::Get>::get(); + assert!( - ::VoteLockingPeriod::get() - >= track.min_enactment_period, - "Track {} has enactment period {} < vote locking period {}", + vote_locking_period >= track.min_enactment_period, + "Track {} has enactment period {} < vote locking period {vote_locking_period}", track.name, track.min_enactment_period, - ::VoteLockingPeriod::get(), ); } } From 60a359f4f04af41307ae13a57e2b11328973ef38 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Fri, 13 Oct 2023 10:29:44 +0800 Subject: [PATCH 7/7] Adjust time --- node/Cargo.toml | 9 +++-- runtime/common/src/lib.rs | 6 +-- runtime/crab/src/pallets/session.rs | 3 +- runtime/crab/src/pallets/staking.rs | 4 +- runtime/darwinia/src/pallets/session.rs | 3 +- runtime/darwinia/src/pallets/staking.rs | 4 +- runtime/pangolin/Cargo.toml | 2 + runtime/pangolin/src/pallets/governance.rs | 14 +++++-- .../pangolin/src/pallets/governance/track.rs | 40 +++++++++---------- .../src/pallets/governance/treasury.rs | 2 +- runtime/pangolin/src/pallets/governance/v1.rs | 14 +++---- runtime/pangolin/src/pallets/session.rs | 3 +- runtime/pangoro/src/pallets/session.rs | 3 +- 13 files changed, 61 insertions(+), 46 deletions(-) diff --git a/node/Cargo.toml b/node/Cargo.toml index 8893f9d6f..3b694b662 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -48,10 +48,10 @@ fp-evm = { workspace = true, features = ["std"] } fp-rpc = { workspace = true, features = ["std"] } # moonbeam -moonbeam-primitives-ext = { workspace = true, optional = true, features = ["std"] } -moonbeam-rpc-debug = { workspace = true } -moonbeam-rpc-primitives-debug = { workspace = true, features = ["std"] } -moonbeam-rpc-trace = { workspace = true } +moonbeam-primitives-ext = { workspace = true, optional = true, features = ["std"] } +moonbeam-rpc-debug = { workspace = true } +moonbeam-rpc-primitives-debug = { workspace = true, features = ["std"] } +moonbeam-rpc-trace = { workspace = true } # polkadot polkadot-cli = { workspace = true } @@ -105,6 +105,7 @@ fast-runtime = [ # darwinia "crab-runtime?/fast-runtime", "darwinia-runtime?/fast-runtime", + "pangolin-runtime?/fast-runtime", ] evm-tracing = [ diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 186aca415..759789ae0 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -45,11 +45,11 @@ use frame_support::{ #[macro_export] macro_rules! fast_runtime_or_not { - ($name:ident, $development_type:ty, $production_type:ty) => { + ($name:ident, $type:ty, $fast:expr, $regular:expr) => { #[cfg(feature = "fast-runtime")] - type $name = $development_type; + const $name: $type = $fast; #[cfg(not(feature = "fast-runtime"))] - type $name = $production_type; + const $name: $type = $regular; }; } diff --git a/runtime/crab/src/pallets/session.rs b/runtime/crab/src/pallets/session.rs index 383efa998..303b40d03 100644 --- a/runtime/crab/src/pallets/session.rs +++ b/runtime/crab/src/pallets/session.rs @@ -25,9 +25,10 @@ sp_runtime::impl_opaque_keys! { } } -fast_runtime_or_not!(Period, ConstU32<{ 5 * MINUTES }>, ConstU32<{ 6 * HOURS }>); +fast_runtime_or_not!(PERIOD, BlockNumber, 5 * MINUTES, 6 * HOURS); type Offset = ConstU32<0>; +type Period = ConstU32<{ PERIOD }>; impl pallet_session::Config for Runtime { type Keys = SessionKeys; diff --git a/runtime/crab/src/pallets/staking.rs b/runtime/crab/src/pallets/staking.rs index 953f9d4ca..73b78050c 100644 --- a/runtime/crab/src/pallets/staking.rs +++ b/runtime/crab/src/pallets/staking.rs @@ -19,7 +19,9 @@ // darwinia use crate::*; -fast_runtime_or_not!(MinStakingDuration, ConstU32<{ 5 * MINUTES }>, ConstU32<{ 14 * DAYS }>); +fast_runtime_or_not!(DURATION, BlockNumber, 5 * MINUTES, 14 * DAYS); + +type MinStakingDuration = ConstU32<{ DURATION }>; pub enum RingStaking {} impl darwinia_staking::Stake for RingStaking { diff --git a/runtime/darwinia/src/pallets/session.rs b/runtime/darwinia/src/pallets/session.rs index 383efa998..303b40d03 100644 --- a/runtime/darwinia/src/pallets/session.rs +++ b/runtime/darwinia/src/pallets/session.rs @@ -25,9 +25,10 @@ sp_runtime::impl_opaque_keys! { } } -fast_runtime_or_not!(Period, ConstU32<{ 5 * MINUTES }>, ConstU32<{ 6 * HOURS }>); +fast_runtime_or_not!(PERIOD, BlockNumber, 5 * MINUTES, 6 * HOURS); type Offset = ConstU32<0>; +type Period = ConstU32<{ PERIOD }>; impl pallet_session::Config for Runtime { type Keys = SessionKeys; diff --git a/runtime/darwinia/src/pallets/staking.rs b/runtime/darwinia/src/pallets/staking.rs index dd0ea72eb..055228344 100644 --- a/runtime/darwinia/src/pallets/staking.rs +++ b/runtime/darwinia/src/pallets/staking.rs @@ -19,7 +19,9 @@ // darwinia use crate::*; -fast_runtime_or_not!(MinStakingDuration, ConstU32<{ 5 * MINUTES }>, ConstU32<{ 14 * DAYS }>); +fast_runtime_or_not!(DURATION, BlockNumber, 5 * MINUTES, 14 * DAYS); + +type MinStakingDuration = ConstU32<{ DURATION }>; pub enum RingStaking {} impl darwinia_staking::Stake for RingStaking { diff --git a/runtime/pangolin/Cargo.toml b/runtime/pangolin/Cargo.toml index 49a585a48..8367c0815 100644 --- a/runtime/pangolin/Cargo.toml +++ b/runtime/pangolin/Cargo.toml @@ -273,6 +273,8 @@ evm-tracing = [ "moonbeam-evm-tracer", ] +fast-runtime = [] + # A feature that should be enabled when the runtime should be build for on-chain # deployment. This will disable stuff that shouldn't be part of the on-chain wasm # to make it smaller like logging for example. diff --git a/runtime/pangolin/src/pallets/governance.rs b/runtime/pangolin/src/pallets/governance.rs index 21fa9c200..27563ff25 100644 --- a/runtime/pangolin/src/pallets/governance.rs +++ b/runtime/pangolin/src/pallets/governance.rs @@ -31,6 +31,12 @@ pub use pallet_collective::{Instance1 as CouncilCollective, Instance2 as Technic pub(super) use crate::*; +fast_runtime_or_not!(TIME_1, BlockNumber, 2 * MINUTES, 10 * MINUTES); +fast_runtime_or_not!(TIME_2, BlockNumber, 5 * MINUTES, 20 * MINUTES); + +type Time1 = ConstU32; +type Time2 = ConstU32; + pub const COLLECTIVE_DESIRED_MEMBERS: u32 = 7; pub const COLLECTIVE_MAX_MEMBERS: u32 = 100; pub const COLLECTIVE_MAX_PROPOSALS: u32 = 100; @@ -47,7 +53,7 @@ impl pallet_collective::Config for Runtime { type MaxMembers = ConstU32; type MaxProposalWeight = MaxProposalWeight; type MaxProposals = ConstU32<100>; - type MotionDuration = ConstU32<{ 2 * MINUTES }>; + type MotionDuration = Time1; type Proposal = RuntimeCall; type RuntimeEvent = RuntimeEvent; type RuntimeOrigin = RuntimeOrigin; @@ -59,7 +65,7 @@ impl pallet_collective::Config for Runtime { type MaxMembers = ConstU32; type MaxProposalWeight = MaxProposalWeight; type MaxProposals = ConstU32<100>; - type MotionDuration = ConstU32<{ 2 * MINUTES }>; + type MotionDuration = Time1; type Proposal = RuntimeCall; type RuntimeEvent = RuntimeEvent; type RuntimeOrigin = RuntimeOrigin; @@ -73,7 +79,7 @@ impl pallet_conviction_voting::Config for Runtime { type MaxVotes = ConstU32<512>; type Polls = Referenda; type RuntimeEvent = RuntimeEvent; - type VoteLockingPeriod = ConstU32<{ 5 * MINUTES }>; + type VoteLockingPeriod = Time2; // TODO: weight type WeightInfo = pallet_conviction_voting::weights::SubstrateWeight; } @@ -95,7 +101,7 @@ impl pallet_referenda::Config for Runtime { type SubmitOrigin = frame_system::EnsureSigned; type Tally = pallet_conviction_voting::TallyOf; type Tracks = TracksInfo; - type UndecidingTimeout = ConstU32<{ 5 * MINUTES }>; + type UndecidingTimeout = Time2; type Votes = pallet_conviction_voting::VotesOf; // TODO: weight type WeightInfo = pallet_referenda::weights::SubstrateWeight; diff --git a/runtime/pangolin/src/pallets/governance/track.rs b/runtime/pangolin/src/pallets/governance/track.rs index 781a4a95c..e474c180d 100644 --- a/runtime/pangolin/src/pallets/governance/track.rs +++ b/runtime/pangolin/src/pallets/governance/track.rs @@ -41,13 +41,13 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 5] // Amount that must be placed on deposit before a decision can be made. decision_deposit: DARWINIA_PROPOSAL_REQUIREMENT, // Amount of time this must be submitted for before a decision can be made. - prepare_period: 2 * MINUTES, + prepare_period: TIME_1, // Amount of time that a decision may take to be approved prior to cancellation. - decision_period: 2 * MINUTES, + decision_period: TIME_1, // Amount of time that the approval criteria must hold before it can be approved. - confirm_period: 2 * MINUTES, + confirm_period: TIME_1, // Minimum amount of time that an approved proposal must be in the dispatch queue. - min_enactment_period: 2 * MINUTES, + min_enactment_period: TIME_1, // Minimum aye votes as percentage of overall conviction-weighted votes needed for // approval as a function of time into decision period. min_approval: pallet_referenda::Curve::make_reciprocal( @@ -68,10 +68,10 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 5] name: "whitelisted_caller", max_deciding: 100, decision_deposit: DARWINIA_PROPOSAL_REQUIREMENT, - prepare_period: 2 * MINUTES, - decision_period: 2 * MINUTES, - confirm_period: 2 * MINUTES, - min_enactment_period: 2 * MINUTES, + prepare_period: TIME_1, + decision_period: TIME_1, + confirm_period: TIME_1, + min_enactment_period: TIME_1, min_approval: pallet_referenda::Curve::make_reciprocal( 1, 2, @@ -94,10 +94,10 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 5] name: "general_admin", max_deciding: 10, decision_deposit: DARWINIA_PROPOSAL_REQUIREMENT, - prepare_period: 2 * MINUTES, - decision_period: 2 * MINUTES, - confirm_period: 2 * MINUTES, - min_enactment_period: 2 * MINUTES, + prepare_period: TIME_1, + decision_period: TIME_1, + confirm_period: TIME_1, + min_enactment_period: TIME_1, min_approval: pallet_referenda::Curve::make_reciprocal( 1, 2, @@ -120,10 +120,10 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 5] name: "referendum_canceller", max_deciding: 20, decision_deposit: DARWINIA_PROPOSAL_REQUIREMENT, - prepare_period: 2 * MINUTES, - decision_period: 2 * MINUTES, - confirm_period: 2 * MINUTES, - min_enactment_period: 2 * MINUTES, + prepare_period: TIME_1, + decision_period: TIME_1, + confirm_period: TIME_1, + min_enactment_period: TIME_1, min_approval: pallet_referenda::Curve::make_reciprocal( 1, 2, @@ -146,10 +146,10 @@ const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 5] name: "referendum_killer", max_deciding: 100, decision_deposit: DARWINIA_PROPOSAL_REQUIREMENT, - prepare_period: 2 * MINUTES, - decision_period: 2 * MINUTES, - confirm_period: 2 * MINUTES, - min_enactment_period: 2 * MINUTES, + prepare_period: TIME_1, + decision_period: TIME_1, + confirm_period: TIME_1, + min_enactment_period: TIME_1, min_approval: pallet_referenda::Curve::make_reciprocal( 1, 2, diff --git a/runtime/pangolin/src/pallets/governance/treasury.rs b/runtime/pangolin/src/pallets/governance/treasury.rs index 6e9ff1080..167a9cbc9 100644 --- a/runtime/pangolin/src/pallets/governance/treasury.rs +++ b/runtime/pangolin/src/pallets/governance/treasury.rs @@ -41,6 +41,6 @@ impl pallet_treasury::Config for Runtime { type RuntimeEvent = RuntimeEvent; type SpendFunds = (); type SpendOrigin = frame_support::traits::NeverEnsureOrigin; - type SpendPeriod = ConstU32<{ 2 * MINUTES }>; + type SpendPeriod = Time1; type WeightInfo = weights::pallet_treasury::WeightInfo; } diff --git a/runtime/pangolin/src/pallets/governance/v1.rs b/runtime/pangolin/src/pallets/governance/v1.rs index e937cfebb..478e5b4ed 100644 --- a/runtime/pangolin/src/pallets/governance/v1.rs +++ b/runtime/pangolin/src/pallets/governance/v1.rs @@ -19,23 +19,21 @@ // darwinia use super::*; -const ENACTMENT_PERIOD: u32 = 2 * MINUTES; - impl pallet_democracy::Config for Runtime { type BlacklistOrigin = Root; type CancelProposalOrigin = RootOrAtLeastTwoThird; type CancellationOrigin = RootOrAtLeastTwoThird; - type CooloffPeriod = ConstU32<{ 2 * MINUTES }>; + type CooloffPeriod = Time1; type Currency = Balances; - type EnactmentPeriod = ConstU32; + type EnactmentPeriod = Time1; type ExternalDefaultOrigin = RootOrAll; type ExternalMajorityOrigin = RootOrAtLeastHalf; type ExternalOrigin = RootOrAtLeastHalf; type FastTrackOrigin = RootOrAtLeastTwoThird; - type FastTrackVotingPeriod = ConstU32<{ 2 * MINUTES }>; + type FastTrackVotingPeriod = Time1; type InstantAllowed = ConstBool; type InstantOrigin = RootOrAll; - type LaunchPeriod = ConstU32<{ 2 * MINUTES }>; + type LaunchPeriod = Time1; type MaxBlacklisted = ConstU32<100>; type MaxDeposits = ConstU32<100>; type MaxProposals = ConstU32<100>; @@ -48,7 +46,7 @@ impl pallet_democracy::Config for Runtime { type Slash = Treasury; type SubmitOrigin = frame_system::EnsureSigned; type VetoOrigin = pallet_collective::EnsureMember; - type VoteLockingPeriod = ConstU32; - type VotingPeriod = ConstU32<{ 2 * MINUTES }>; + type VoteLockingPeriod = Time1; + type VotingPeriod = Time1; type WeightInfo = weights::pallet_democracy::WeightInfo; } diff --git a/runtime/pangolin/src/pallets/session.rs b/runtime/pangolin/src/pallets/session.rs index 383efa998..303b40d03 100644 --- a/runtime/pangolin/src/pallets/session.rs +++ b/runtime/pangolin/src/pallets/session.rs @@ -25,9 +25,10 @@ sp_runtime::impl_opaque_keys! { } } -fast_runtime_or_not!(Period, ConstU32<{ 5 * MINUTES }>, ConstU32<{ 6 * HOURS }>); +fast_runtime_or_not!(PERIOD, BlockNumber, 5 * MINUTES, 6 * HOURS); type Offset = ConstU32<0>; +type Period = ConstU32<{ PERIOD }>; impl pallet_session::Config for Runtime { type Keys = SessionKeys; diff --git a/runtime/pangoro/src/pallets/session.rs b/runtime/pangoro/src/pallets/session.rs index 383efa998..303b40d03 100644 --- a/runtime/pangoro/src/pallets/session.rs +++ b/runtime/pangoro/src/pallets/session.rs @@ -25,9 +25,10 @@ sp_runtime::impl_opaque_keys! { } } -fast_runtime_or_not!(Period, ConstU32<{ 5 * MINUTES }>, ConstU32<{ 6 * HOURS }>); +fast_runtime_or_not!(PERIOD, BlockNumber, 5 * MINUTES, 6 * HOURS); type Offset = ConstU32<0>; +type Period = ConstU32<{ PERIOD }>; impl pallet_session::Config for Runtime { type Keys = SessionKeys;