Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
fix benchmark and added weights
  • Loading branch information
b-yap committed Jul 6, 2023
commit 229825d7d58fe3a47e22ac1b484c69a659197706
58 changes: 36 additions & 22 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,10 @@ pub fn run() -> Result<()> {
Some(Subcommand::Benchmark(cmd)) => {
let runner = cli.create_runner(cmd)?;
// Switch on the concrete benchmark sub-command-
match cmd {
BenchmarkCmd::Pallet(cmd) =>
match (cmd, runner.config().chain_spec.identify()) {
(BenchmarkCmd::Pallet(cmd), runtime) =>
if cfg!(feature = "runtime-benchmarks") {
match runner.config().chain_spec.identify() {
match runtime {
ChainIdentity::Amplitude => runner.sync_run(|config| {
cmd.run::<Block, AmplitudeRuntimeExecutor>(config)
}),
Expand All @@ -291,7 +291,7 @@ pub fn run() -> Result<()> {
You can enable it with `--features runtime-benchmarks`."
.into())
},
BenchmarkCmd::Block(cmd) => match runner.config().chain_spec.identify() {
(BenchmarkCmd::Block(cmd), runtime) => match runtime {
ChainIdentity::Amplitude => runner.sync_run(|config| {
let partials = new_partial::<
amplitude_runtime::RuntimeApi,
Expand Down Expand Up @@ -322,43 +322,57 @@ pub fn run() -> Result<()> {
}),
},
#[cfg(not(feature = "runtime-benchmarks"))]
BenchmarkCmd::Storage(_) =>
(BenchmarkCmd::Storage(_), _) =>
return Err(sc_cli::Error::Input(
"Compile with --features=runtime-benchmarks \
to enable storage benchmarks."
.into(),
)
.into()),
#[cfg(feature = "runtime-benchmarks")]
BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| {
let partials = match runner.config().chain_spec.identify() {
ChainIdentity::Amplitude => new_partial::<
(BenchmarkCmd::Storage(cmd), runtime) => match runtime {
ChainIdentity::Amplitude => runner.sync_run(|config| {
let partials = new_partial::<
amplitude_runtime::RuntimeApi,
AmplitudeRuntimeExecutor,
>(&config)?,
>(&config)?;
let db = partials.backend.expose_db();
let storage = partials.backend.expose_storage();

ChainIdentity::Foucoco => new_partial::<
cmd.run(config, partials.client.clone(), db, storage)
}),
ChainIdentity::Foucoco => runner.sync_run(|config| {
let partials = new_partial::<
foucoco_runtime::RuntimeApi,
FoucocoRuntimeExecutor,
>(&config)?,
>(&config)?;
let db = partials.backend.expose_db();
let storage = partials.backend.expose_storage();

ChainIdentity::Pendulum => new_partial::<
cmd.run(config, partials.client.clone(), db, storage)
}),
ChainIdentity::Pendulum => runner.sync_run(|config| {
let partials = new_partial::<
pendulum_runtime::RuntimeApi,
PendulumRuntimeExecutor,
>(&config)?,
>(&config)?;
let db = partials.backend.expose_db();
let storage = partials.backend.expose_storage();

ChainIdentity::Development => new_partial::<
cmd.run(config, partials.client.clone(), db, storage)
}),
ChainIdentity::Development => runner.sync_run(|config| {
let partials = new_partial::<
development_runtime::RuntimeApi,
DevelopmentRuntimeExecutor,
>(&config)?,
};

let db = partials.backend.expose_db();
let storage = partials.backend.expose_storage();
>(&config)?;
let db = partials.backend.expose_db();
let storage = partials.backend.expose_storage();

cmd.run(config, partials.client.clone(), db, storage)
}),
BenchmarkCmd::Machine(cmd) =>
cmd.run(config, partials.client.clone(), db, storage)
}),
},
(BenchmarkCmd::Machine(cmd), _) =>
runner.sync_run(|config| cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone())),
// NOTE: this allows the Client to leniently implement
// new benchmark commands without requiring a companion MR.
Expand Down
10 changes: 10 additions & 0 deletions runtime/amplitude/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@ runtime-benchmarks = [
"frame-system/runtime-benchmarks",
"pallet-balances/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",

"fee/runtime-benchmarks",
"issue/runtime-benchmarks",
"nomination/runtime-benchmarks",
"oracle/runtime-benchmarks",
"redeem/runtime-benchmarks",
"replace/runtime-benchmarks",
"stellar-relay/runtime-benchmarks",
"vault-registry/runtime-benchmarks",

"pallet-xcm/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"xcm-builder/runtime-benchmarks",
Expand Down
24 changes: 24 additions & 0 deletions runtime/amplitude/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1072,11 +1072,35 @@ impl staking::Config for Runtime {
type CurrencyId = CurrencyId;
}

#[cfg(feature = "runtime-benchmarks")]
pub struct DataFeederBenchmark<K, V, A>(PhantomData<(K, V, A)>);

#[cfg(feature = "runtime-benchmarks")]
impl<K, V, A> orml_traits::DataFeeder<K, V, A> for DataFeederBenchmark<K, V, A> {
fn feed_value(_who: A, _key: K, _value: V) -> sp_runtime::DispatchResult {
Ok(())
}
}

#[cfg(feature = "runtime-benchmarks")]
impl<K, V, A> orml_traits::DataProvider<K, V> for DataFeederBenchmark<K, V, A> {
fn get(_key: &K) -> Option<V> {
None
}
}

impl oracle::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type WeightInfo = oracle::SubstrateWeight<Runtime>;
type DataProvider = DataProviderImpl;
#[cfg(feature = "runtime-benchmarks")]
type DataFeedProvider = DataFeederBenchmark<
oracle::OracleKey,
oracle::TimestampedValue<UnsignedFixedPoint, Moment>,
Self::AccountId,
>;
}

parameter_types! {
pub const OrganizationLimit: u32 = 255;
pub const ValidatorLimit: u32 = 255;
Expand Down
1 change: 1 addition & 0 deletions runtime/amplitude/src/weights/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

pub mod block_weights;
pub mod extrinsic_weights;
pub mod pallet_xcm;
pub mod paritydb_weights;
pub mod rocksdb_weights;

Expand Down
Loading