Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/benchmarks refactor #160

Merged
merged 10 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
115 changes: 37 additions & 78 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,100 +1,59 @@
# 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/48ccfae6141d2924f579d81e8b1877efd208693f/system-parachains/asset-hubs/asset-hub-polkadot/src/weights/cumulus_pallet_xcmp_queue.rs
benchmark-runtime pallet="pallet-elections-phragmen" features="runtime-benchmarks":
cargo run --features {{ features }} --release -p polimec-parachain-node benchmark pallet \
--chain=base-polkadot \
--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

# src: https://github.com/paritytech/polkadot-sdk/blob/bc2e5e1fe26e2c2c8ee766ff9fe7be7e212a0c62/substrate/frame/nfts/src/weights.rs
benchmark-pallet pallet="pallet-elections-phragmen" features="runtime-benchmarks":
cargo run --features {{ features }} --release -p polimec-parachain-node benchmark pallet \
--chain=base-polkadot \
--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":
./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}}
zombienet path_to_file="scripts/zombienet/native/base-rococo-local.toml":
zombienet spawn {{ path_to_file }}
17 changes: 14 additions & 3 deletions nodes/parachain/src/chain_spec/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down Expand Up @@ -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::<Vec<_>>(),
Expand Down Expand Up @@ -254,7 +257,15 @@ fn base_testnet_genesis(
council: Default::default(),
technical_committee: Default::default(),
democracy: Default::default(),
elections: Default::default(),
elections: ElectionsConfig {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A genesis config is required to start the benchmarks.

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(),
}
Expand Down
6 changes: 3 additions & 3 deletions pallets/democracy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 3 additions & 3 deletions pallets/elections-phragmen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 1 addition & 3 deletions pallets/elections-phragmen/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config>(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>(T::MaxVoters::get()) * BalanceOf::<T>::from(BALANCE_FACTOR);
let amount = default_stake::<T>(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.
Expand Down
1 change: 1 addition & 0 deletions runtimes/base/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,7 @@ mod benches {
[pallet_session, SessionBench::<Runtime>]
[pallet_timestamp, Timestamp]
[cumulus_pallet_xcmp_queue, XcmpQueue]
[pallet_elections_phragmen, Elections]
);
}

Expand Down
4 changes: 4 additions & 0 deletions runtimes/shared-configuration/src/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down