Skip to content

Commit

Permalink
wip fix bench
Browse files Browse the repository at this point in the history
  • Loading branch information
nanocryk committed Dec 4, 2024
1 parent deed96d commit d17efb5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
13 changes: 10 additions & 3 deletions pallets/author-noting/src/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ benchmarks! {
let mut container_chains = vec![];

let data = if TypeId::of::<<<T as Config>::RelayOrPara as RelayOrPara>::InherentArg>() == TypeId::of::<tp_author_noting_inherent::OwnParachainInherentData>() {


let mut sproof_builder = test_sproof::ParaHeaderSproofBuilder::default();

for para_id in 1..x {
Expand All @@ -73,8 +71,8 @@ benchmarks! {
let num_each_container_chain = 2;
T::ContainerChainAuthor::set_authors_for_para_id(para_id, vec![author; num_each_container_chain]);
sproof_builder.num_items += 1;
}

}
let (root, proof) = sproof_builder.into_state_root_and_proof();
T::RelayOrPara::set_current_relay_chain_state(cumulus_pallet_parachain_system::RelayChainState {
state_root: root,
Expand All @@ -85,6 +83,13 @@ benchmarks! {
relay_storage_proof: proof,
};

for para_id in 1..x {
let para_id = para_id.into();
let author: T::AccountId = account("account id", 0u32, 0u32);

T::AuthorNotingHook::prepare_worst_case_for_bench(&author, 1, para_id);
}

*(Box::new(arg) as Box<dyn Any>).downcast().unwrap()
} else if TypeId::of::<<<T as Config>::RelayOrPara as RelayOrPara>::InherentArg>() == TypeId::of::<()>() {

Expand Down Expand Up @@ -113,6 +118,8 @@ benchmarks! {

let head_data = HeadData(header.encode());
frame_support::storage::unhashed::put(&key, &head_data);

T::AuthorNotingHook::prepare_worst_case_for_bench(&author, 1, para_id);
}
let arg = ();
*(Box::new(arg) as Box<dyn Any>).downcast().unwrap()
Expand Down
4 changes: 2 additions & 2 deletions pallets/inflation-rewards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ impl<T: Config> AuthorNotingHook<T::AccountId> for Pallet<T> {
}

#[cfg(feature = "runtime-benchmarks")]
fn prepare_worst_case_for_bench(a: &T::AccountId, b: BlockNumber, p: ParaId) {
fn prepare_worst_case_for_bench(_a: &T::AccountId, _b: BlockNumber, para_id: ParaId) {
// arbitrary amount to perform rewarding
// we mint twice as much to the rewards account to make it possible
let reward_amount = 1_000_000_000u32;
Expand All @@ -313,7 +313,7 @@ impl<T: Config> AuthorNotingHook<T::AccountId> for Pallet<T> {
.expect("to mint tokens");

ChainsToReward::<T>::put(ChainsToRewardValue {
para_ids: sp_std::vec![p].try_into().expect("to be in bound"),
para_ids: sp_std::vec![para_id].try_into().expect("to be in bound"),
rewards_per_chain: BalanceOf::<T>::from(reward_amount),
});
}
Expand Down
18 changes: 15 additions & 3 deletions pallets/services-payment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ impl<T: Config> AuthorNotingHook<T::AccountId> for Pallet<T> {
) -> Weight {
if Pallet::<T>::burn_block_production_free_credit_for_para(&para_id).is_err() {
let (amount_to_charge, _weight) = T::ProvideBlockProductionCost::block_cost(&para_id);

match T::Currency::withdraw(
&Self::parachain_tank(para_id),
amount_to_charge,
Expand All @@ -547,9 +548,20 @@ impl<T: Config> AuthorNotingHook<T::AccountId> for Pallet<T> {
}

#[cfg(feature = "runtime-benchmarks")]
fn prepare_worst_case_for_bench(a: &T::AccountId, b: BlockNumber, p: ParaId) {
// nothing to prepare, `burn_block_production_free_credit_for_para` will return Err and make
// the branch above execute
fn prepare_worst_case_for_bench(
_author: &T::AccountId,
_block_number: BlockNumber,
para_id: ParaId,
) {
let (amount_to_charge, _weight) = T::ProvideBlockProductionCost::block_cost(&para_id);
// mint large amount (bigger than ED) to ensure withdraw will not fail.
let mint = BalanceOf::<T>::from(2_000_000_000u32) + amount_to_charge;

// mint twice more to not have ED issues
T::Currency::resolve_creating(
&Self::parachain_tank(para_id),
T::Currency::issue(mint),
);
}
}

Expand Down

0 comments on commit d17efb5

Please sign in to comment.