Skip to content

Commit 90ad566

Browse files
authored
Merge pull request #1008 from UniqueNetwork/fix/update-benchmarks-to-v2
Update benchmarks to v2
2 parents 900be63 + 4275a8f commit 90ad566

File tree

31 files changed

+2560
-1359
lines changed

31 files changed

+2560
-1359
lines changed

Cargo.lock

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ sp-session = { default-features = false, git = "https://github.com/paritytech/po
170170
sp-staking = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
171171
sp-state-machine = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
172172
sp-std = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
173+
sp-storage = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
173174
sp-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
174175
sp-tracing = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
175176
sp-transaction-pool = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }

Makefile

+29-62
Original file line numberDiff line numberDiff line change
@@ -88,69 +88,36 @@ CollectionHelpers: CollectionHelpers.sol
8888

8989
evm_stubs: UniqueFungible UniqueNFT UniqueRefungible UniqueRefungibleToken ContractHelpers CollectionHelpers
9090

91-
.PHONY: _bench
92-
_bench:
93-
cargo run --profile production --features runtime-benchmarks,$(RUNTIME) -- \
94-
benchmark pallet --pallet pallet-$(if $(PALLET),$(PALLET),$(error Must set PALLET)) \
91+
# TODO: Create benchmarking profile, make it a proper dependency
92+
.PHONY: benchmarking-node
93+
benchmarking-node:
94+
cargo build --profile production --features runtime-benchmarks
95+
96+
define _bench =
97+
.PHONY: bench-$(1)
98+
bench-$(1): benchmarking-node
99+
./target/production/unique-collator \
100+
benchmark pallet --pallet pallet-$(1) \
95101
--wasm-execution compiled --extrinsic '*' \
96-
$(if $(TEMPLATE),$(TEMPLATE),--template=.maintain/frame-weight-template.hbs) --steps=50 --repeat=80 --heap-pages=4096 \
97-
--output=$(if $(OUTPUT),$(OUTPUT),./pallets/$(if $(PALLET_DIR),$(PALLET_DIR),$(PALLET))/src/weights.rs)
98-
99-
.PHONY: bench-evm-migration
100-
bench-evm-migration:
101-
make _bench PALLET=evm-migration
102-
103-
.PHONY: bench-configuration
104-
bench-configuration:
105-
make _bench PALLET=configuration
106-
107-
.PHONY: bench-common
108-
bench-common:
109-
make _bench PALLET=common
110-
111-
.PHONY: bench-unique
112-
bench-unique:
113-
make _bench PALLET=unique
114-
115-
.PHONY: bench-fungible
116-
bench-fungible:
117-
make _bench PALLET=fungible
118-
119-
.PHONY: bench-refungible
120-
bench-refungible:
121-
make _bench PALLET=refungible
122-
123-
.PHONY: bench-nonfungible
124-
bench-nonfungible:
125-
make _bench PALLET=nonfungible
126-
127-
.PHONY: bench-structure
128-
bench-structure:
129-
make _bench PALLET=structure
130-
131-
.PHONY: bench-foreign-assets
132-
bench-foreign-assets:
133-
make _bench PALLET=foreign-assets
134-
135-
.PHONY: bench-collator-selection
136-
bench-collator-selection:
137-
make _bench PALLET=collator-selection
138-
139-
.PHONY: bench-identity
140-
bench-identity:
141-
make _bench PALLET=identity
142-
143-
.PHONY: bench-app-promotion
144-
bench-app-promotion:
145-
make _bench PALLET=app-promotion
146-
147-
.PHONY: bench-maintenance
148-
bench-maintenance:
149-
make _bench PALLET=maintenance
150-
151-
.PHONY: bench-xcm
152-
bench-xcm:
153-
make _bench PALLET=xcm OUTPUT=./runtime/common/weights/xcm.rs TEMPLATE="--template=.maintain/external-weight-template.hbs"
102+
$(if $(4),$(4),--template=.maintain/frame-weight-template.hbs) --steps=50 --repeat=80 --heap-pages=4096 \
103+
--output=$$(if $(3),$(3),./pallets/$(if $(2),$(2),$(1))/src/weights.rs)
104+
endef
105+
106+
# _bench,pallet,(pallet_dir|),(output|),(extra|)
107+
$(eval $(call _bench,evm-migration))
108+
$(eval $(call _bench,configuration))
109+
$(eval $(call _bench,common))
110+
$(eval $(call _bench,unique))
111+
$(eval $(call _bench,fungible))
112+
$(eval $(call _bench,refungible))
113+
$(eval $(call _bench,nonfungible))
114+
$(eval $(call _bench,structure))
115+
$(eval $(call _bench,foreign-assets))
116+
$(eval $(call _bench,collator-selection))
117+
$(eval $(call _bench,identity))
118+
$(eval $(call _bench,app-promotion))
119+
$(eval $(call _bench,maintenance))
120+
$(eval $(call _bench,xcm,,./runtime/common/weights/xcm.rs,"--template=.maintain/external-weights/template.hbs"))
154121

155122
.PHONY: bench
156123
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

node/cli/src/chain_spec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ macro_rules! testnet_genesis {
238238
vesting: VestingConfig { vesting: vec![] },
239239
parachain_info: ParachainInfoConfig {
240240
parachain_id: $id.into(),
241-
Default::default()
241+
..Default::default()
242242
},
243243
aura: AuraConfig {
244244
authorities: $initial_invulnerables

node/cli/src/command.rs

+19-11
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ use sc_service::config::{BasePath, PrometheusConfig};
4242
use sp_runtime::traits::AccountIdConversion;
4343
use up_common::types::opaque::RuntimeId;
4444

45-
#[cfg(feature = "runtime-benchmarks")]
46-
use crate::chain_spec::default_runtime;
47-
#[cfg(feature = "runtime-benchmarks")]
48-
use crate::service::DefaultRuntimeExecutor;
4945
#[cfg(feature = "quartz-runtime")]
5046
use crate::service::QuartzRuntimeExecutor;
5147
#[cfg(feature = "unique-runtime")]
@@ -355,26 +351,37 @@ pub fn run() -> Result<()> {
355351
#[cfg(feature = "runtime-benchmarks")]
356352
Some(Subcommand::Benchmark(cmd)) => {
357353
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
354+
use polkadot_cli::Block;
355+
use sp_io::SubstrateHostFunctions;
356+
358357
let runner = cli.create_runner(cmd)?;
359358
// Switch on the concrete benchmark sub-command-
360359
match cmd {
361360
BenchmarkCmd::Pallet(cmd) => {
362-
runner.sync_run(|config| cmd.run::<Block, DefaultRuntimeExecutor>(config))
361+
runner.sync_run(|config| cmd.run::<Block, SubstrateHostFunctions>(config))
363362
}
364363
BenchmarkCmd::Block(cmd) => runner.sync_run(|config| {
365364
let partials = new_partial::<
366-
default_runtime::RuntimeApi,
367-
DefaultRuntimeExecutor,
365+
opal_runtime::Runtime,
366+
opal_runtime::RuntimeApi,
367+
OpalRuntimeExecutor,
368368
_,
369-
>(&config, crate::service::parachain_build_import_queue)?;
369+
>(
370+
&config,
371+
crate::service::parachain_build_import_queue::<opal_runtime::Runtime, _, _>,
372+
)?;
370373
cmd.run(partials.client)
371374
}),
372375
BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| {
373376
let partials = new_partial::<
374-
default_runtime::RuntimeApi,
375-
DefaultRuntimeExecutor,
377+
opal_runtime::Runtime,
378+
opal_runtime::RuntimeApi,
379+
OpalRuntimeExecutor,
376380
_,
377-
>(&config, crate::service::parachain_build_import_queue)?;
381+
>(
382+
&config,
383+
crate::service::parachain_build_import_queue::<opal_runtime::Runtime, _, _>,
384+
)?;
378385
let db = partials.backend.expose_db();
379386
let storage = partials.backend.expose_storage();
380387

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

402+
use polkadot_cli::Block;
395403
use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, NativeExecutionDispatch};
396404
use try_runtime_cli::block_building_info::timestamp_with_aura_info;
397405

node/cli/src/rpc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub struct FullDeps<C, P, SC> {
6767
}
6868

6969
/// Instantiate all Full RPC extensions.
70-
pub fn create_full<C, P, SC, R, A, B>(
70+
pub fn create_full<C, P, SC, R, B>(
7171
io: &mut RpcModule<()>,
7272
deps: FullDeps<C, P, SC>,
7373
) -> Result<(), Box<dyn std::error::Error + Send + Sync>>
@@ -244,7 +244,7 @@ where
244244
EthFilter::new(
245245
client.clone(),
246246
eth_backend,
247-
graph.clone(),
247+
graph,
248248
filter_pool,
249249
500_usize, // max stored filters
250250
max_past_logs,

node/cli/src/service.rs

+43-40
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,6 @@ pub struct QuartzRuntimeExecutor;
9393
/// Opal native executor instance.
9494
pub struct OpalRuntimeExecutor;
9595

96-
#[cfg(all(feature = "unique-runtime", feature = "runtime-benchmarks"))]
97-
pub type DefaultRuntimeExecutor = UniqueRuntimeExecutor;
98-
99-
#[cfg(all(
100-
not(feature = "unique-runtime"),
101-
feature = "quartz-runtime",
102-
feature = "runtime-benchmarks"
103-
))]
104-
pub type DefaultRuntimeExecutor = QuartzRuntimeExecutor;
105-
106-
#[cfg(all(
107-
not(feature = "unique-runtime"),
108-
not(feature = "quartz-runtime"),
109-
feature = "runtime-benchmarks"
110-
))]
111-
pub type DefaultRuntimeExecutor = OpalRuntimeExecutor;
112-
11396
#[cfg(feature = "unique-runtime")]
11497
impl NativeExecutionDispatch for UniqueRuntimeExecutor {
11598
/// Only enable the benchmarking host functions when we actually want to benchmark.
@@ -515,7 +498,7 @@ where
515498
select_chain,
516499
};
517500

518-
create_full::<_, _, _, Runtime, RuntimeApi, _>(&mut rpc_handle, full_deps)?;
501+
create_full::<_, _, _, Runtime, _>(&mut rpc_handle, full_deps)?;
519502

520503
let eth_deps = EthDeps {
521504
client,
@@ -564,7 +547,7 @@ where
564547
config: parachain_config,
565548
keystore: params.keystore_container.keystore(),
566549
backend: backend.clone(),
567-
network: network.clone(),
550+
network,
568551
sync_service: sync_service.clone(),
569552
system_rpc_tx,
570553
telemetry: telemetry.as_mut(),
@@ -617,19 +600,21 @@ where
617600
if validator {
618601
start_consensus(
619602
client.clone(),
620-
backend.clone(),
621-
prometheus_registry.as_ref(),
622-
telemetry.as_ref().map(|t| t.handle()),
623-
&task_manager,
624-
relay_chain_interface.clone(),
625603
transaction_pool,
626-
sync_service.clone(),
627-
params.keystore_container.keystore(),
628-
overseer_handle,
629-
relay_chain_slot_duration,
630-
para_id,
631-
collator_key.expect("cli args do not allow this"),
632-
announce_block,
604+
StartConsensusParameters {
605+
backend: backend.clone(),
606+
prometheus_registry: prometheus_registry.as_ref(),
607+
telemetry: telemetry.as_ref().map(|t| t.handle()),
608+
task_manager: &task_manager,
609+
relay_chain_interface: relay_chain_interface.clone(),
610+
sync_oracle: sync_service,
611+
keystore: params.keystore_container.keystore(),
612+
overseer_handle,
613+
relay_chain_slot_duration,
614+
para_id,
615+
collator_key: collator_key.expect("cli args do not allow this"),
616+
announce_block,
617+
},
633618
)?;
634619
}
635620

@@ -687,23 +672,27 @@ where
687672
.map_err(Into::into)
688673
}
689674

690-
pub fn start_consensus<ExecutorDispatch, RuntimeApi, Runtime>(
691-
client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,
675+
pub struct StartConsensusParameters<'a> {
692676
backend: Arc<FullBackend>,
693-
prometheus_registry: Option<&Registry>,
677+
prometheus_registry: Option<&'a Registry>,
694678
telemetry: Option<TelemetryHandle>,
695-
task_manager: &TaskManager,
679+
task_manager: &'a TaskManager,
696680
relay_chain_interface: Arc<dyn RelayChainInterface>,
697-
transaction_pool: Arc<
698-
sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,
699-
>,
700681
sync_oracle: Arc<SyncingService<Block>>,
701682
keystore: KeystorePtr,
702683
overseer_handle: OverseerHandle,
703684
relay_chain_slot_duration: Duration,
704685
para_id: ParaId,
705686
collator_key: CollatorPair,
706687
announce_block: Arc<dyn Fn(Hash, Option<Vec<u8>>) + Send + Sync>,
688+
}
689+
690+
pub fn start_consensus<ExecutorDispatch, RuntimeApi, Runtime>(
691+
client: Arc<FullClient<RuntimeApi, ExecutorDispatch>>,
692+
transaction_pool: Arc<
693+
sc_transaction_pool::FullPool<Block, FullClient<RuntimeApi, ExecutorDispatch>>,
694+
>,
695+
parameters: StartConsensusParameters<'_>,
707696
) -> Result<(), sc_service::Error>
708697
where
709698
ExecutorDispatch: NativeExecutionDispatch + 'static,
@@ -714,14 +703,28 @@ where
714703
RuntimeApi::RuntimeApi: RuntimeApiDep<Runtime> + 'static,
715704
Runtime: RuntimeInstance,
716705
{
706+
let StartConsensusParameters {
707+
backend,
708+
prometheus_registry,
709+
telemetry,
710+
task_manager,
711+
relay_chain_interface,
712+
sync_oracle,
713+
keystore,
714+
overseer_handle,
715+
relay_chain_slot_duration,
716+
para_id,
717+
collator_key,
718+
announce_block,
719+
} = parameters;
717720
let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;
718721

719722
let proposer_factory = sc_basic_authorship::ProposerFactory::with_proof_recording(
720723
task_manager.spawn_handle(),
721724
client.clone(),
722725
transaction_pool,
723726
prometheus_registry,
724-
telemetry.clone(),
727+
telemetry,
725728
);
726729
let proposer = Proposer::new(proposer_factory);
727730

@@ -1060,7 +1063,7 @@ where
10601063
select_chain,
10611064
};
10621065

1063-
create_full::<_, _, _, Runtime, RuntimeApi, _>(&mut rpc_module, full_deps)?;
1066+
create_full::<_, _, _, Runtime, _>(&mut rpc_module, full_deps)?;
10641067

10651068
let eth_deps = EthDeps {
10661069
client,

0 commit comments

Comments
 (0)