Skip to content

Commit

Permalink
fix: benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Grigoriy Simonov committed Oct 12, 2023
1 parent af2b5f4 commit 01ad947
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 95 deletions.
4 changes: 0 additions & 4 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
17 changes: 0 additions & 17 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
2 changes: 1 addition & 1 deletion pallets/app-promotion/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ mod benchmarks {
}

#[benchmark]
fn payout_stakers(b: Linear<0, 100>) -> Result<(), BenchmarkError> {
fn payout_stakers(b: Linear<1, 100>) -> Result<(), BenchmarkError> {
let pallet_admin = account::<T::AccountId>("admin", 1, SEED);
PromototionPallet::<T>::set_admin_address(
RawOrigin::Root.into(),
Expand Down
23 changes: 9 additions & 14 deletions pallets/collator-selection/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ mod benchmarks {
// Both invulnerables and candidates count together against MaxCollators.
// Maybe try putting it in braces? 1 .. (T::MaxCollators::get() - 2)
#[benchmark]
fn add_invulnerable<T>(b: Linear<1, MAX_COLLATORS>) -> Result<(), BenchmarkError> {
fn add_invulnerable<T>(b: Linear<2, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
let b = b - 1;
register_validators::<T>(b);
register_invulnerables::<T>(b);

Expand Down Expand Up @@ -268,7 +269,8 @@ mod benchmarks {
// worst case is when we have all the max-candidate slots filled except one, and we fill that
// one.
#[benchmark]
fn onboard(c: Linear<1, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
fn onboard(c: Linear<2, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
let c = c - 1;
register_validators::<T>(c);
register_candidates::<T>(c);

Expand All @@ -293,9 +295,7 @@ mod benchmarks {

// worst case is the last candidate leaving.
#[benchmark]
fn offboard(c: Linear<0, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
let c = c + 1;

fn offboard(c: Linear<1, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
register_validators::<T>(c);
register_candidates::<T>(c);

Expand All @@ -317,8 +317,7 @@ mod benchmarks {

// worst case is the last candidate leaving.
#[benchmark]
fn release_license(c: Linear<0, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
let c = c + 1;
fn release_license(c: Linear<1, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
let bond = balance_unit::<T>();

register_validators::<T>(c);
Expand All @@ -343,8 +342,7 @@ mod benchmarks {

// worst case is the last candidate leaving.
#[benchmark]
fn force_release_license(c: Linear<0, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
let c = c + 1;
fn force_release_license(c: Linear<1, MAX_INVULNERABLES>) -> Result<(), BenchmarkError> {
let bond = balance_unit::<T>();

register_validators::<T>(c);
Expand Down Expand Up @@ -400,12 +398,9 @@ mod benchmarks {
// worst case for new session.
#[benchmark]
fn new_session(
r: Linear<0, MAX_INVULNERABLES>,
c: Linear<0, MAX_INVULNERABLES>,
r: Linear<1, MAX_INVULNERABLES>,
c: Linear<1, MAX_INVULNERABLES>,
) -> Result<(), BenchmarkError> {
let r = r + 1;
let c = c + 1;

frame_system::Pallet::<T>::set_block_number(0u32.into());

register_validators::<T>(c);
Expand Down
81 changes: 42 additions & 39 deletions pallets/nonfungible/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use frame_benchmarking::v2::{account, benchmarks, BenchmarkError};
use pallet_common::{
bench_init,
benchmarking::{
create_collection_raw, load_is_admin_and_property_permissions, property_key, property_value,
create_collection_raw, property_key, property_value,
},
CommonCollectionOperations,
};
Expand Down Expand Up @@ -334,49 +334,52 @@ mod benchmarks {
Ok(())
}

// TODO:
#[benchmark]
fn init_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> {
bench_init! {
owner: sub; collection: collection(owner);
owner: cross_from_sub;
};

let perms = (0..b)
.map(|k| PropertyKeyPermission {
key: property_key(k as usize),
permission: PropertyPermission {
mutable: false,
collection_admin: true,
token_owner: true,
},
})
.collect::<Vec<_>>();
<Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
let props = (0..b)
.map(|k| Property {
key: property_key(k as usize),
value: property_value(),
})
.collect::<Vec<_>>();
let item = create_max_item(&collection, &owner, owner.clone())?;

// let (is_collection_admin, property_permissions) =
// load_is_admin_and_property_permissions(&collection, &owner);
todo!();
// bench_init! {
// owner: sub; collection: collection(owner);
// owner: cross_from_sub;
// };

// let perms = (0..b)
// .map(|k| PropertyKeyPermission {
// key: property_key(k as usize),
// permission: PropertyPermission {
// mutable: false,
// collection_admin: true,
// token_owner: true,
// },
// })
// .collect::<Vec<_>>();
// <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
#[block]
{
// let mut property_writer =
// pallet_common::BenchmarkPropertyWriter::new(&collection, lazy_collection_info);

// property_writer.write_token_properties(
// item,
// props.into_iter(),
// crate::erc::ERC721TokenEvent::TokenChanged {
// token_id: item.into(),
// }
// .to_log(T::ContractAddress::get()),
// )?;
}
// let props = (0..b)
// .map(|k| Property {
// key: property_key(k as usize),
// value: property_value(),
// })
// .collect::<Vec<_>>();
// let item = create_max_item(&collection, &owner, owner.clone())?;

// let (is_collection_admin, property_permissions) =
// load_is_admin_and_property_permissions(&collection, &owner);
// #[block]
// {
// let mut property_writer =
// pallet_common::BenchmarkPropertyWriter::new(&collection, lazy_collection_info);

// property_writer.write_token_properties(
// item,
// props.into_iter(),
// crate::erc::ERC721TokenEvent::TokenChanged {
// token_id: item.into(),
// }
// .to_log(T::ContractAddress::get()),
// )?;
// }

Ok(())
}
Expand Down
40 changes: 20 additions & 20 deletions pallets/refungible/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,35 +490,35 @@ mod benchmarks {
Ok(())
}

// TODO:
#[benchmark]
fn init_token_properties(b: Linear<0, MAX_PROPERTIES_PER_ITEM>) -> Result<(), BenchmarkError> {
bench_init! {
owner: sub; collection: collection(owner);
owner: cross_from_sub;
};
// bench_init! {
// owner: sub; collection: collection(owner);
// owner: cross_from_sub;
// };

// let perms = (0..b)
// .map(|k| PropertyKeyPermission {
// key: property_key(k as usize),
// permission: PropertyPermission {
// mutable: false,
// collection_admin: true,
// token_owner: true,
// },
// })
// .collect::<Vec<_>>();
// <Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;

let perms = (0..b)
.map(|k| PropertyKeyPermission {
key: property_key(k as usize),
permission: PropertyPermission {
mutable: false,
collection_admin: true,
token_owner: true,
},
})
.collect::<Vec<_>>();
<Pallet<T>>::set_token_property_permissions(&collection, &owner, perms)?;
#[block]
{}
// let props = (0..b).map(|k| Property {
// key: property_key(k as usize),
// value: property_value(),
// }).collect::<Vec<_>>();
// let item = create_max_item(&collection, &owner, [(owner.clone(), 200)])?;

// let (is_collection_admin, property_permissions) = load_is_admin_and_property_permissions(&collection, &owner);

#[block]
{}
todo!();
// let (is_collection_admin, property_permissions) = load_is_admin_and_property_permissions(&collection, &owner)
// let mut property_writer = pallet_common::collection_info_loaded_property_writer(
// &collection,
// is_collection_admin,
Expand Down

0 comments on commit 01ad947

Please sign in to comment.