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

Update benchmarks to v2 #1008

Merged
merged 7 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ sp-session = { default-features = false, git = "https://github.com/paritytech/po
sp-staking = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sp-state-machine = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sp-std = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sp-storage = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sp-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sp-tracing = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sp-transaction-pool = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
Expand Down
91 changes: 29 additions & 62 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -88,69 +88,36 @@ CollectionHelpers: CollectionHelpers.sol

evm_stubs: UniqueFungible UniqueNFT UniqueRefungible UniqueRefungibleToken ContractHelpers CollectionHelpers

.PHONY: _bench
_bench:
cargo run --profile production --features runtime-benchmarks,$(RUNTIME) -- \
benchmark pallet --pallet pallet-$(if $(PALLET),$(PALLET),$(error Must set PALLET)) \
# TODO: Create benchmarking profile, make it a proper dependency
.PHONY: benchmarking-node
benchmarking-node:
cargo build --profile production --features runtime-benchmarks

define _bench =
.PHONY: bench-$(1)
bench-$(1): benchmarking-node
./target/production/unique-collator \
benchmark pallet --pallet pallet-$(1) \
--wasm-execution compiled --extrinsic '*' \
$(if $(TEMPLATE),$(TEMPLATE),--template=.maintain/frame-weight-template.hbs) --steps=50 --repeat=80 --heap-pages=4096 \
--output=$(if $(OUTPUT),$(OUTPUT),./pallets/$(if $(PALLET_DIR),$(PALLET_DIR),$(PALLET))/src/weights.rs)

.PHONY: bench-evm-migration
bench-evm-migration:
make _bench PALLET=evm-migration

.PHONY: bench-configuration
bench-configuration:
make _bench PALLET=configuration

.PHONY: bench-common
bench-common:
make _bench PALLET=common

.PHONY: bench-unique
bench-unique:
make _bench PALLET=unique

.PHONY: bench-fungible
bench-fungible:
make _bench PALLET=fungible

.PHONY: bench-refungible
bench-refungible:
make _bench PALLET=refungible

.PHONY: bench-nonfungible
bench-nonfungible:
make _bench PALLET=nonfungible

.PHONY: bench-structure
bench-structure:
make _bench PALLET=structure

.PHONY: bench-foreign-assets
bench-foreign-assets:
make _bench PALLET=foreign-assets

.PHONY: bench-collator-selection
bench-collator-selection:
make _bench PALLET=collator-selection

.PHONY: bench-identity
bench-identity:
make _bench PALLET=identity

.PHONY: bench-app-promotion
bench-app-promotion:
make _bench PALLET=app-promotion

.PHONY: bench-maintenance
bench-maintenance:
make _bench PALLET=maintenance

.PHONY: bench-xcm
bench-xcm:
make _bench PALLET=xcm OUTPUT=./runtime/common/weights/xcm.rs TEMPLATE="--template=.maintain/external-weight-template.hbs"
$(if $(4),$(4),--template=.maintain/frame-weight-template.hbs) --steps=50 --repeat=80 --heap-pages=4096 \
--output=$$(if $(3),$(3),./pallets/$(if $(2),$(2),$(1))/src/weights.rs)
endef

# _bench,pallet,(pallet_dir|),(output|),(extra|)
$(eval $(call _bench,evm-migration))
$(eval $(call _bench,configuration))
$(eval $(call _bench,common))
$(eval $(call _bench,unique))
$(eval $(call _bench,fungible))
$(eval $(call _bench,refungible))
$(eval $(call _bench,nonfungible))
$(eval $(call _bench,structure))
$(eval $(call _bench,foreign-assets))
$(eval $(call _bench,collator-selection))
$(eval $(call _bench,identity))
$(eval $(call _bench,app-promotion))
$(eval $(call _bench,maintenance))
$(eval $(call _bench,xcm,,./runtime/common/weights/xcm.rs,"--template=.maintain/external-weights/template.hbs"))

.PHONY: bench
bench: bench-app-promotion bench-common bench-evm-migration bench-unique bench-structure bench-fungible bench-refungible bench-nonfungible bench-configuration bench-foreign-assets bench-maintenance bench-xcm bench-collator-selection bench-identity
Expand Down
2 changes: 1 addition & 1 deletion node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ macro_rules! testnet_genesis {
vesting: VestingConfig { vesting: vec![] },
parachain_info: ParachainInfoConfig {
parachain_id: $id.into(),
Default::default()
..Default::default()
},
aura: AuraConfig {
authorities: $initial_invulnerables
Expand Down
30 changes: 19 additions & 11 deletions node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ use sc_service::config::{BasePath, PrometheusConfig};
use sp_runtime::traits::AccountIdConversion;
use up_common::types::opaque::RuntimeId;

#[cfg(feature = "runtime-benchmarks")]
use crate::chain_spec::default_runtime;
#[cfg(feature = "runtime-benchmarks")]
use crate::service::DefaultRuntimeExecutor;
#[cfg(feature = "quartz-runtime")]
use crate::service::QuartzRuntimeExecutor;
#[cfg(feature = "unique-runtime")]
Expand Down Expand Up @@ -355,26 +351,37 @@ pub fn run() -> Result<()> {
#[cfg(feature = "runtime-benchmarks")]
Some(Subcommand::Benchmark(cmd)) => {
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
use polkadot_cli::Block;
use sp_io::SubstrateHostFunctions;

let runner = cli.create_runner(cmd)?;
// Switch on the concrete benchmark sub-command-
match cmd {
BenchmarkCmd::Pallet(cmd) => {
runner.sync_run(|config| cmd.run::<Block, DefaultRuntimeExecutor>(config))
runner.sync_run(|config| cmd.run::<Block, SubstrateHostFunctions>(config))
}
BenchmarkCmd::Block(cmd) => runner.sync_run(|config| {
let partials = new_partial::<
default_runtime::RuntimeApi,
DefaultRuntimeExecutor,
opal_runtime::Runtime,
opal_runtime::RuntimeApi,
OpalRuntimeExecutor,
_,
>(&config, crate::service::parachain_build_import_queue)?;
>(
&config,
crate::service::parachain_build_import_queue::<opal_runtime::Runtime, _, _>,
)?;
cmd.run(partials.client)
}),
BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| {
let partials = new_partial::<
default_runtime::RuntimeApi,
DefaultRuntimeExecutor,
opal_runtime::Runtime,
opal_runtime::RuntimeApi,
OpalRuntimeExecutor,
_,
>(&config, crate::service::parachain_build_import_queue)?;
>(
&config,
crate::service::parachain_build_import_queue::<opal_runtime::Runtime, _, _>,
)?;
let db = partials.backend.expose_db();
let storage = partials.backend.expose_storage();

Expand All @@ -392,6 +399,7 @@ pub fn run() -> Result<()> {
Some(Subcommand::TryRuntime(cmd)) => {
use std::{future::Future, pin::Pin};

use polkadot_cli::Block;
use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, NativeExecutionDispatch};
use try_runtime_cli::block_building_info::timestamp_with_aura_info;

Expand Down
4 changes: 2 additions & 2 deletions node/cli/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub struct FullDeps<C, P, SC> {
}

/// Instantiate all Full RPC extensions.
pub fn create_full<C, P, SC, R, A, B>(
pub fn create_full<C, P, SC, R, B>(
io: &mut RpcModule<()>,
deps: FullDeps<C, P, SC>,
) -> Result<(), Box<dyn std::error::Error + Send + Sync>>
Expand Down Expand Up @@ -244,7 +244,7 @@ where
EthFilter::new(
client.clone(),
eth_backend,
graph.clone(),
graph,
filter_pool,
500_usize, // max stored filters
max_past_logs,
Expand Down
83 changes: 43 additions & 40 deletions node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,23 +93,6 @@ pub struct QuartzRuntimeExecutor;
/// Opal native executor instance.
pub struct OpalRuntimeExecutor;

#[cfg(all(feature = "unique-runtime", feature = "runtime-benchmarks"))]
pub type DefaultRuntimeExecutor = UniqueRuntimeExecutor;

#[cfg(all(
not(feature = "unique-runtime"),
feature = "quartz-runtime",
feature = "runtime-benchmarks"
))]
pub type DefaultRuntimeExecutor = QuartzRuntimeExecutor;

#[cfg(all(
not(feature = "unique-runtime"),
not(feature = "quartz-runtime"),
feature = "runtime-benchmarks"
))]
pub type DefaultRuntimeExecutor = OpalRuntimeExecutor;

#[cfg(feature = "unique-runtime")]
impl NativeExecutionDispatch for UniqueRuntimeExecutor {
/// Only enable the benchmarking host functions when we actually want to benchmark.
Expand Down Expand Up @@ -515,7 +498,7 @@ where
select_chain,
};

create_full::<_, _, _, Runtime, RuntimeApi, _>(&mut rpc_handle, full_deps)?;
create_full::<_, _, _, Runtime, _>(&mut rpc_handle, full_deps)?;

let eth_deps = EthDeps {
client,
Expand Down Expand Up @@ -564,7 +547,7 @@ where
config: parachain_config,
keystore: params.keystore_container.keystore(),
backend: backend.clone(),
network: network.clone(),
network,
sync_service: sync_service.clone(),
system_rpc_tx,
telemetry: telemetry.as_mut(),
Expand Down Expand Up @@ -617,19 +600,21 @@ where
if validator {
start_consensus(
client.clone(),
backend.clone(),
prometheus_registry.as_ref(),
telemetry.as_ref().map(|t| t.handle()),
&task_manager,
relay_chain_interface.clone(),
transaction_pool,
sync_service.clone(),
params.keystore_container.keystore(),
overseer_handle,
relay_chain_slot_duration,
para_id,
collator_key.expect("cli args do not allow this"),
announce_block,
StartConsensusParameters {
backend: backend.clone(),
prometheus_registry: prometheus_registry.as_ref(),
telemetry: telemetry.as_ref().map(|t| t.handle()),
task_manager: &task_manager,
relay_chain_interface: relay_chain_interface.clone(),
sync_oracle: sync_service,
keystore: params.keystore_container.keystore(),
overseer_handle,
relay_chain_slot_duration,
para_id,
collator_key: collator_key.expect("cli args do not allow this"),
announce_block,
},
)?;
}

Expand Down Expand Up @@ -687,23 +672,27 @@ where
.map_err(Into::into)
}

pub fn start_consensus<ExecutorDispatch, RuntimeApi, Runtime>(
client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,
pub struct StartConsensusParameters<'a> {
backend: Arc<FullBackend>,
prometheus_registry: Option<&Registry>,
prometheus_registry: Option<&'a Registry>,
telemetry: Option<TelemetryHandle>,
task_manager: &TaskManager,
task_manager: &'a TaskManager,
relay_chain_interface: Arc<dyn RelayChainInterface>,
transaction_pool: Arc<
sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,
>,
sync_oracle: Arc<SyncingService<Block>>,
keystore: KeystorePtr,
overseer_handle: OverseerHandle,
relay_chain_slot_duration: Duration,
para_id: ParaId,
collator_key: CollatorPair,
announce_block: Arc<dyn Fn(Hash, Option<Vec<u8>>) + Send + Sync>,
}

pub fn start_consensus<ExecutorDispatch, RuntimeApi, Runtime>(
client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,
transaction_pool: Arc<
sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,
>,
parameters: StartConsensusParameters<'_>,
) -> Result<(), sc_service::Error>
where
ExecutorDispatch: NativeExecutionDispatch + 'static,
Expand All @@ -714,14 +703,28 @@ where
RuntimeApi::RuntimeApi: RuntimeApiDep<Runtime> + 'static,
Runtime: RuntimeInstance,
{
let StartConsensusParameters {
backend,
prometheus_registry,
telemetry,
task_manager,
relay_chain_interface,
sync_oracle,
keystore,
overseer_handle,
relay_chain_slot_duration,
para_id,
collator_key,
announce_block,
} = parameters;
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;

let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
task_manager.spawn_handle(),
client.clone(),
transaction_pool,
prometheus_registry,
telemetry.clone(),
telemetry,
);
let proposer = Proposer::new(proposer_factory);

Expand Down Expand Up @@ -1060,7 +1063,7 @@ where
select_chain,
};

create_full::<_, _, _, Runtime, RuntimeApi, _>(&mut rpc_module, full_deps)?;
create_full::<_, _, _, Runtime, _>(&mut rpc_module, full_deps)?;

let eth_deps = EthDeps {
client,
Expand Down
Loading