From c7245b55491a818c8ca974bc15d348c9e53658fd Mon Sep 17 00:00:00 2001 From: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com> Date: Mon, 5 Feb 2024 14:38:05 +0100 Subject: [PATCH 01/10] feat: add ElectionsConfig in Genesis --- nodes/parachain/src/chain_spec/base.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/nodes/parachain/src/chain_spec/base.rs b/nodes/parachain/src/chain_spec/base.rs index c3f5344e4..e97d645a6 100644 --- a/nodes/parachain/src/chain_spec/base.rs +++ b/nodes/parachain/src/chain_spec/base.rs @@ -31,7 +31,7 @@ use base_runtime::{ inflation::{perbill_annual_to_perbill_round, BLOCKS_PER_YEAR}, InflationInfo, Range, }, - AccountId, AuraId as AuthorityId, Balance, BalancesConfig, MinCandidateStk, ParachainInfoConfig, + AccountId, AuraId as AuthorityId, Balance, BalancesConfig, ElectionsConfig, MinCandidateStk, ParachainInfoConfig, ParachainStakingConfig, PolkadotXcmConfig, RuntimeGenesisConfig, SessionConfig, SudoConfig, SystemConfig, PLMC, }; @@ -216,9 +216,12 @@ fn base_testnet_genesis( sudo_account: AccountId, id: ParaId, ) -> RuntimeGenesisConfig { + const ENDOWMENT: Balance = 10_000_000 * PLMC; + const STASH: Balance = ENDOWMENT / 1000; + RuntimeGenesisConfig { system: SystemConfig { code: wasm_binary.to_vec(), ..Default::default() }, - balances: BalancesConfig { balances: endowed_accounts }, + balances: BalancesConfig { balances: endowed_accounts.clone() }, parachain_info: ParachainInfoConfig { parachain_id: id, ..Default::default() }, parachain_staking: ParachainStakingConfig { candidates: stakers.iter().map(|(accunt, _, balance)| (accunt.clone(), *balance)).collect::>(), @@ -254,7 +257,15 @@ fn base_testnet_genesis( council: Default::default(), technical_committee: Default::default(), democracy: Default::default(), - elections: Default::default(), + elections: ElectionsConfig { + members: endowed_accounts + .iter() + .map(|(member, _)| member) + .take((endowed_accounts.len() + 1) / 2) + .cloned() + .map(|member| (member, STASH)) + .collect(), + }, treasury: Default::default(), vesting: Default::default(), } From a29356dfc2253ff543849dcaac98f5ba90514fb7 Mon Sep 17 00:00:00 2001 From: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com> Date: Mon, 5 Feb 2024 14:38:32 +0100 Subject: [PATCH 02/10] feat: add pallet_elections_phragmen to the bechmark CLI --- runtimes/base/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/runtimes/base/src/lib.rs b/runtimes/base/src/lib.rs index 9f30492fb..f49b64049 100644 --- a/runtimes/base/src/lib.rs +++ b/runtimes/base/src/lib.rs @@ -814,6 +814,7 @@ mod benches { [pallet_session, SessionBench::] [pallet_timestamp, Timestamp] [cumulus_pallet_xcmp_queue, XcmpQueue] + [pallet_elections_phragmen, Elections] ); } From a351da4446c082b68469e2f1aef87d7185ee2a24 Mon Sep 17 00:00:00 2001 From: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com> Date: Tue, 6 Feb 2024 14:20:52 +0100 Subject: [PATCH 03/10] fmt --- runtimes/shared-configuration/src/governance.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/runtimes/shared-configuration/src/governance.rs b/runtimes/shared-configuration/src/governance.rs index 70ca8c924..39b19e33e 100644 --- a/runtimes/shared-configuration/src/governance.rs +++ b/runtimes/shared-configuration/src/governance.rs @@ -104,20 +104,24 @@ parameter_types! { pub const MinimumDeposit: Balance = 100 * PLMC; pub const EnactmentPeriod: BlockNumber = ENACTMENT_PERIOD; pub const CooloffPeriod: BlockNumber = COOLOFF_PERIOD; + // Council Pallet pub const CouncilMotionDuration: BlockNumber = COUNCIL_MOTION_DURATION; pub const CouncilMaxProposals: u32 = 7; pub const CouncilMaxMembers: u32 = 20; + // Technical Committee pub const TechnicalMotionDuration: BlockNumber = TECHNICAL_MOTION_DURATION; pub const TechnicalMaxProposals: u32 = 7; pub const TechnicalMaxMembers: u32 = 5; + // Extras pub const PreimageBaseDeposit: Balance = deposit(2, 64); pub const MaxProposals: u32 = 10; pub const MaxVotes: u32 = 100; pub const MaxBlacklisted: u32 = 100; pub const MaxDeposits: u32 = 100; + //Treasury pub const ProposalBond: Permill = Permill::from_percent(5); pub const ProposalBondMinimum: Balance = 50 * PLMC; From db71cfeb45a7805e7fd6f087506bd7da821fddfd Mon Sep 17 00:00:00 2001 From: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com> Date: Tue, 6 Feb 2024 14:24:47 +0100 Subject: [PATCH 04/10] feat: refactor the justfile --- justfile | 110 ++++++++++++++++--------------------------------------- 1 file changed, 32 insertions(+), 78 deletions(-) diff --git a/justfile b/justfile index af2e2c708..700993d04 100644 --- a/justfile +++ b/justfile @@ -1,100 +1,54 @@ # Help information default: - @just --list - -# Build everything -build-all: - cargo build --release - -# Build the "Base" Runtime -build-base-runtime: - cargo build --release -p polimec-base-runtime - -# Build the "Testnet" Runtime -build-parachain-runtime: - cargo build --release -p polimec-parachain-runtime - -# Build the "Parachain" Node -build-parachain-node: - cargo build --release -p polimec-parachain-node + @just --list # Build the "Base" Runtime using srtool build-base-srtool: - srtool build --root -p polimec-base-runtime --runtime-dir runtimes/base --build-opts="--features=on-chain-release-build" + srtool build --root -p polimec-base-runtime --runtime-dir runtimes/base --build-opts="--features=on-chain-release-build" # Build the "Testnet" Runtime using srtool -build-parachain-srtool: - srtool build --root -p polimec-parachain-runtime --runtime-dir runtimes/testnet # Test the runtimes features test-runtime-features: - cargo test --features runtime-benchmarks -p polimec-parachain-runtime + cargo test --features runtime-benchmarks -p polimec-parachain-runtime # Run the integration tests test-integration: - cargo test -p integration-tests - + cargo test -p integration-tests + +# Run the runtime benchmarks +# src: https://github.com/polkadot-fellows/runtimes/blob/main/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/cumulus_pallet_xcmp_queue.rs +benchmark-runtime pallet="pallet-linear-release" features="runtime-benchmarks": + cargo run --features {{ features }} --release -p polimec-parachain-node benchmark pallet \ + --chain=polimec-rococo-local \ + --steps=50 \ + --repeat=20 \ + --pallet={{ pallet }} \ + --extrinsic=* \ + --wasm-execution=compiled \ + --heap-pages=4096 \ + --output=runtimes/base/src/weights/{{ replace(pallet, "-", "_") }}.rs # Benchmark the "Testnet" Runtime -benchmark-runtime-funding: - cargo run --features runtime-benchmarks --release -p polimec-parachain-node benchmark pallet \ - --chain=polimec-rococo-local \ - --steps=50 \ - --repeat=20 \ - --pallet=pallet_funding \ - --extrinsic '*' \ - --wasm-execution=compiled \ - --heap-pages=4096 \ - --output=runtimes/testnet/src/weights/pallet_funding.rs - - -# Benchmark the "Testnet" Runtime -benchmark-runtime-linear-release: - cargo run --features runtime-benchmarks --release -p polimec-parachain-node benchmark pallet \ - --chain=polimec-rococo-local \ - --steps=50 \ - --repeat=20 \ - --pallet=pallet_linear_release \ - --extrinsic '*' \ - --wasm-execution=compiled \ - --heap-pages=4096 \ - --output=runtimes/testnet/src/weights/pallet_linear_release.rs - -# Benchmark the "Testnet" Runtime -benchmark-pallet-funding: - cargo run --features runtime-benchmarks,fast-mode --release -p polimec-parachain-node benchmark pallet \ - --chain=polimec-rococo-local \ - --steps=50 \ - --repeat=20 \ - --pallet=pallet_funding \ - --extrinsic '*' \ - --heap-pages=4096 \ - --output=pallets/funding/src/weights-test.rs \ - --template=./.maintain/frame-weight-template.hbs - -benchmark-pallet-linear-release: - cargo run --features runtime-benchmarks,fast-mode --release -p polimec-parachain-node benchmark pallet \ - --chain=polimec-rococo-local \ - --steps=50 \ - --repeat=20 \ - --pallet=pallet_linear_release \ - --extrinsic '*' \ - --heap-pages=4096 \ - --output=pallets/linear-release/src/weights.rs \ - --template=./.maintain/frame-weight-template.hbs - -benchmarks-test: - cargo test --features runtime-benchmarks -p pallet-funding benchmarks - +benchmark-pallet pallet="pallet-linear-release" features="runtime-benchmarks": + cargo run --features {{ features }} --release -p polimec-parachain-node benchmark pallet \ + --chain=polimec-rococo-local \ + --steps=50 \ + --repeat=20 \ + --pallet={{ pallet }} \ + --extrinsic '*' \ + --heap-pages=4096 \ + --output=pallets/{{ replace(pallet, "pallet-", "") }}/src/weights.rs \ + --template=./.maintain/frame-weight-template.hbs # Build the Node Docker Image -docker-build tag = "latest" package= "polimec-parachain-node": - ./scripts/build_image.sh {{tag}} ./Dockerfile {{package}} +docker-build tag="latest" package="polimec-parachain-node": + ./scripts/build_image.sh {{ tag }} ./Dockerfile {{ package }} # Create the "Base" Runtime Chainspec create-chainspec-base: - ./scripts/create_base_chain_spec.sh ./runtimes/base/target/srtool/release/wbuild/polimec-base-runtime/polimec_base_runtime.compact.compressed.wasm 2105 + ./scripts/create_base_chain_spec.sh ./runtimes/base/target/srtool/release/wbuild/polimec-base-runtime/polimec_base_runtime.compact.compressed.wasm 2105 # Use zombienet to spawn rococo + polimec testnet -zombienet path_to_file = "scripts/zombienet/native/base-rococo-local.toml": - zombienet spawn {{path_to_file}} \ No newline at end of file +zombienet path_to_file="scripts/zombienet/native/base-rococo-local.toml": + zombienet spawn {{ path_to_file }} From a4df7f0ba94c6f5b5bf3e8107cd7361706329ff8 Mon Sep 17 00:00:00 2001 From: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com> Date: Tue, 6 Feb 2024 14:50:00 +0100 Subject: [PATCH 05/10] feat: align the flags with the sdk --- justfile | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/justfile b/justfile index 700993d04..986750f0c 100644 --- a/justfile +++ b/justfile @@ -16,30 +16,35 @@ test-runtime-features: test-integration: cargo test -p integration-tests -# Run the runtime benchmarks -# src: https://github.com/polkadot-fellows/runtimes/blob/main/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/cumulus_pallet_xcmp_queue.rs +# Run the Runtime benchmarks +# src: https://github.com/polkadot-fellows/runtimes/blob/48ccfae6141d2924f579d81e8b1877efd208693f/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/cumulus_pallet_xcmp_queue.rs benchmark-runtime pallet="pallet-linear-release" features="runtime-benchmarks": cargo run --features {{ features }} --release -p polimec-parachain-node benchmark pallet \ - --chain=polimec-rococo-local \ - --steps=50 \ - --repeat=20 \ - --pallet={{ pallet }} \ - --extrinsic=* \ - --wasm-execution=compiled \ - --heap-pages=4096 \ - --output=runtimes/base/src/weights/{{ replace(pallet, "-", "_") }}.rs + --chain=polimec-rococo-local \ + --steps=50 \ + --repeat=20 \ + --pallet={{ pallet }} \ + --extrinsic=* \ + --wasm-execution=compiled \ + --heap-pages=4096 \ + --output=runtimes/base/src/weights/{{ replace(pallet, "-", "_") }}.rs # Benchmark the "Testnet" Runtime +# src: https://github.com/paritytech/polkadot-sdk/blob/bc2e5e1fe26e2c2c8ee766ff9fe7be7e212a0c62/substrate/frame/nfts/src/weights.rs benchmark-pallet pallet="pallet-linear-release" features="runtime-benchmarks": cargo run --features {{ features }} --release -p polimec-parachain-node benchmark pallet \ - --chain=polimec-rococo-local \ - --steps=50 \ - --repeat=20 \ - --pallet={{ pallet }} \ - --extrinsic '*' \ - --heap-pages=4096 \ - --output=pallets/{{ replace(pallet, "pallet-", "") }}/src/weights.rs \ - --template=./.maintain/frame-weight-template.hbs + --chain=polimec-rococo-local \ + --steps=50 \ + --repeat=20 \ + --pallet={{ pallet }} \ + --no-storage-info \ + --no-median-slopes \ + --no-min-squares \ + --extrinsic '*' \ + --wasm-execution=compiled \ + --heap-pages=4096 \ + --output=pallets/{{ replace(pallet, "pallet-", "") }}/src/weights.rs \ + --template=./.maintain/frame-weight-template.hbs # Build the Node Docker Image docker-build tag="latest" package="polimec-parachain-node": From 0e8fef7de495cecaadfe2b58642ad342f46d3f02 Mon Sep 17 00:00:00 2001 From: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com> Date: Tue, 6 Feb 2024 15:32:28 +0100 Subject: [PATCH 06/10] feat: use the production chain --- justfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/justfile b/justfile index 986750f0c..4114ee4a5 100644 --- a/justfile +++ b/justfile @@ -18,9 +18,9 @@ test-integration: # Run the Runtime benchmarks # src: https://github.com/polkadot-fellows/runtimes/blob/48ccfae6141d2924f579d81e8b1877efd208693f/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/cumulus_pallet_xcmp_queue.rs -benchmark-runtime pallet="pallet-linear-release" features="runtime-benchmarks": +benchmark-runtime pallet="pallet-elections-phragmen" features="runtime-benchmarks": cargo run --features {{ features }} --release -p polimec-parachain-node benchmark pallet \ - --chain=polimec-rococo-local \ + --chain=base-polkadot \ --steps=50 \ --repeat=20 \ --pallet={{ pallet }} \ @@ -31,9 +31,9 @@ benchmark-runtime pallet="pallet-linear-release" features="runtime-benchmarks": # Benchmark the "Testnet" Runtime # src: https://github.com/paritytech/polkadot-sdk/blob/bc2e5e1fe26e2c2c8ee766ff9fe7be7e212a0c62/substrate/frame/nfts/src/weights.rs -benchmark-pallet pallet="pallet-linear-release" features="runtime-benchmarks": +benchmark-pallet pallet="pallet-elections-phragmen" features="runtime-benchmarks": cargo run --features {{ features }} --release -p polimec-parachain-node benchmark pallet \ - --chain=polimec-rococo-local \ + --chain=base-polkadot \ --steps=50 \ --repeat=20 \ --pallet={{ pallet }} \ From 644dc016e5329f9fb1631ab9eb5e3de6026847f3 Mon Sep 17 00:00:00 2001 From: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com> Date: Tue, 6 Feb 2024 15:41:21 +0100 Subject: [PATCH 07/10] chore: fix toml metadata --- pallets/democracy/Cargo.toml | 6 +++--- pallets/elections-phragmen/Cargo.toml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pallets/democracy/Cargo.toml b/pallets/democracy/Cargo.toml index 02be6e932..79f6a1459 100644 --- a/pallets/democracy/Cargo.toml +++ b/pallets/democracy/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "pallet-democracy" -version = "4.0.0-dev" +version.workspace = true authors.workspace = true edition.workspace = true -license = "Apache-2.0" -homepage = "https://substrate.io" +license-file.workspace = true +homepage.workspace = true repository.workspace = true description = "FRAME pallet for democracy" readme = "README.md" diff --git a/pallets/elections-phragmen/Cargo.toml b/pallets/elections-phragmen/Cargo.toml index 05a690229..a25219461 100644 --- a/pallets/elections-phragmen/Cargo.toml +++ b/pallets/elections-phragmen/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "pallet-elections-phragmen" -version = "5.0.0-dev" +version.workspace = true authors.workspace = true edition.workspace = true -license = "Apache-2.0" -homepage = "https://substrate.io" +license-file.workspace = true +homepage.workspace = true repository.workspace = true description = "FRAME pallet based on seq-Phragmén election method." readme = "README.md" From 24ea013c26f795c88c0dc2ed02da24d4ed6ca63e Mon Sep 17 00:00:00 2001 From: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com> Date: Tue, 6 Feb 2024 15:44:50 +0100 Subject: [PATCH 08/10] feat: give to the endowed accounts enough balance --- pallets/elections-phragmen/src/benchmarking.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pallets/elections-phragmen/src/benchmarking.rs b/pallets/elections-phragmen/src/benchmarking.rs index 517bff81f..d6e71de65 100644 --- a/pallets/elections-phragmen/src/benchmarking.rs +++ b/pallets/elections-phragmen/src/benchmarking.rs @@ -24,14 +24,12 @@ use frame_system::RawOrigin; use crate::Pallet as Elections; -const BALANCE_FACTOR: u32 = 250; - /// grab new account with infinite balance. fn endowed_account(name: &'static str, index: u32) -> T::AccountId { let account: T::AccountId = account(name, index, 0); // Fund each account with at-least their stake but still a sane amount as to not mess up // the vote calculation. - let amount = default_stake::(T::MaxVoters::get()) * BalanceOf::::from(BALANCE_FACTOR); + let amount = default_stake::(T::MaxVoters::get()) * T::CandidacyBond::get(); let _ = T::Currency::set_balance(&account, amount); // important to increase the total issuance since T::CurrencyToVote will need it to be sane for // phragmen to work. From 34c95a51c6632951180636e48f5ddd5ea063fae9 Mon Sep 17 00:00:00 2001 From: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com> Date: Tue, 6 Feb 2024 17:42:09 +0100 Subject: [PATCH 09/10] feat: add all the pallets in the define_benchmarks! macro --- runtimes/base/src/lib.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/runtimes/base/src/lib.rs b/runtimes/base/src/lib.rs index f49b64049..da42cbed3 100644 --- a/runtimes/base/src/lib.rs +++ b/runtimes/base/src/lib.rs @@ -809,12 +809,38 @@ construct_runtime!( #[cfg(feature = "runtime-benchmarks")] mod benches { frame_benchmarking::define_benchmarks!( + // System support stuff. [frame_system, SystemBench::] + [pallet_timestamp, Timestamp] + [pallet_sudo, Sudo] + [pallet_utility, Utility] + [pallet_multisig, Multisig] + [pallet_proxy, Proxy] + + // Monetary stuff. [pallet_balances, Balances] + [pallet_vesting, Vesting] + + // Collator support. [pallet_session, SessionBench::] - [pallet_timestamp, Timestamp] + [pallet_parachain_staking, ParachainStaking] + + // XCM helpers. [cumulus_pallet_xcmp_queue, XcmpQueue] + [pallet_xcm, PolkadotXcm] + + // Governance + [pallet_treasury, Treasury] + [pallet_democracy, Democracy] + [pallet_collective, Council] + [pallet_collective, TechnicalCommittee] [pallet_elections_phragmen, Elections] + [pallet_preimage, Preimage] + [pallet_scheduler, Scheduler] + + // Oracle + [pallet_membership, OracleProvidersMembership] + //[orml_oracle, Oracle] ); } From a7928b74d2123d8e56f8dd3559813a80fff22b62 Mon Sep 17 00:00:00 2001 From: Leonardo Razovic <4128940+lrazovic@users.noreply.github.com> Date: Tue, 6 Feb 2024 18:03:19 +0100 Subject: [PATCH 10/10] chore: update doc --- justfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/justfile b/justfile index 4114ee4a5..ef5799fe7 100644 --- a/justfile +++ b/justfile @@ -16,8 +16,8 @@ test-runtime-features: test-integration: cargo test -p integration-tests -# Run the Runtime benchmarks # src: https://github.com/polkadot-fellows/runtimes/blob/48ccfae6141d2924f579d81e8b1877efd208693f/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/cumulus_pallet_xcmp_queue.rs +# Benchmark a specific pallet on the "Base" Runtime benchmark-runtime pallet="pallet-elections-phragmen" features="runtime-benchmarks": cargo run --features {{ features }} --release -p polimec-parachain-node benchmark pallet \ --chain=base-polkadot \ @@ -29,8 +29,8 @@ benchmark-runtime pallet="pallet-elections-phragmen" features="runtime-benchmark --heap-pages=4096 \ --output=runtimes/base/src/weights/{{ replace(pallet, "-", "_") }}.rs -# Benchmark the "Testnet" Runtime # src: https://github.com/paritytech/polkadot-sdk/blob/bc2e5e1fe26e2c2c8ee766ff9fe7be7e212a0c62/substrate/frame/nfts/src/weights.rs +# Run the Runtime benchmarks for a specific pallet benchmark-pallet pallet="pallet-elections-phragmen" features="runtime-benchmarks": cargo run --features {{ features }} --release -p polimec-parachain-node benchmark pallet \ --chain=base-polkadot \