Skip to content

Commit

Permalink
Double-check evaluation reward benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRios committed May 24, 2024
1 parent 38ea2c1 commit 89d340a
Show file tree
Hide file tree
Showing 5 changed files with 535 additions and 286 deletions.
11 changes: 2 additions & 9 deletions pallets/funding/src/tests/3_auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,12 +676,11 @@ mod round_flow {
fn all_bids_but_one_have_price_higher_than_wap() {
let mut inst = MockInstantiator::new(Some(RefCell::new(new_test_ext())));
let total_allocation = 10_000_000 * CT_UNIT;
let initial_price = PriceOf::<TestRuntime>::from_float(10.0f64);
let min_bid_ct = 500 * CT_UNIT; // 5k USD at 10USD/CT
let max_bids_per_project: u32 = <TestRuntime as Config>::MaxBidsPerProject::get();
let big_bid: BidParams<TestRuntime> = (BIDDER_1, total_allocation).into();
let small_bids: Vec<BidParams<TestRuntime>> =
(0..max_bids_per_project-1).map(|i| (i + BIDDER_1, min_bid_ct).into()).collect();
(0..max_bids_per_project - 1).map(|i| (i + BIDDER_1, min_bid_ct).into()).collect();
let all_bids = vec![vec![big_bid.clone()], small_bids.clone()].into_iter().flatten().collect_vec();

let mut project_metadata = default_project_metadata(ISSUER_1);
Expand All @@ -697,17 +696,11 @@ mod round_flow {
);

let wap = inst.get_project_details(project_id).weighted_average_price.unwrap();
let absolute_price = <TestRuntime as Config>::PriceProvider::convert_back_to_normal_price(
wap,
USD_DECIMALS,
project_metadata.token_information.decimals,
);
let big_bid = inst.execute(|| Bids::<TestRuntime>::get((project_id, BIDDER_1, 0))).unwrap();

let all_bids = inst.execute(|| Bids::<TestRuntime>::iter_prefix_values((project_id,)).collect_vec());

let higher_than_wap_bids = all_bids.iter().filter(|bid| bid.original_ct_usd_price > wap).collect_vec();
assert_eq!(higher_than_wap_bids.len(), (max_bids_per_project-1u32) as usize);
assert_eq!(higher_than_wap_bids.len(), (max_bids_per_project - 1u32) as usize);
}
}

Expand Down
97 changes: 97 additions & 0 deletions pallets/funding/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub trait WeightInfo {
fn end_evaluation_success(x: u32, ) -> Weight;
fn end_evaluation_failure() -> Weight;
fn start_auction_closing_phase(x: u32, ) -> Weight;
fn end_auction_closing(x: u32, y: u32, z: u32, ) -> Weight;
fn start_community_funding(x: u32, y: u32, z: u32, ) -> Weight;
fn start_remainder_funding(x: u32, ) -> Weight;
fn end_funding_automatically_rejected_evaluators_slashed(x: u32, ) -> Weight;
Expand Down Expand Up @@ -558,6 +559,54 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add(Weight::from_parts(0, 2501).saturating_mul(x.into()))
}
/// Storage: `Funding::ProjectsDetails` (r:1 w:1)
/// Proof: `Funding::ProjectsDetails` (`max_values`: None, `max_size`: Some(397), added: 2872, mode: `MaxEncodedLen`)
/// Storage: `Funding::ProjectsMetadata` (r:1 w:0)
/// Proof: `Funding::ProjectsMetadata` (`max_values`: None, `max_size`: Some(502), added: 2977, mode: `MaxEncodedLen`)
/// Storage: `Funding::Nonce` (r:1 w:1)
/// Proof: `Funding::Nonce` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
/// Storage: `Random::RandomMaterial` (r:1 w:0)
/// Proof: `Random::RandomMaterial` (`max_values`: Some(1), `max_size`: Some(2594), added: 3089, mode: `MaxEncodedLen`)
/// Storage: `Funding::Bids` (r:513 w:512)
/// Proof: `Funding::Bids` (`max_values`: None, `max_size`: Some(306), added: 2781, mode: `MaxEncodedLen`)
/// Storage: `Funding::DidWithWinningBids` (r:256 w:256)
/// Proof: `Funding::DidWithWinningBids` (`max_values`: None, `max_size`: Some(95), added: 2570, mode: `MaxEncodedLen`)
/// Storage: `ForeignAssets::Asset` (r:1 w:1)
/// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`)
/// Storage: `ForeignAssets::Account` (r:257 w:257)
/// Proof: `ForeignAssets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:256 w:256)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `Balances::Holds` (r:256 w:256)
/// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(1149), added: 3624, mode: `MaxEncodedLen`)
/// Storage: `Funding::ProjectsToUpdate` (r:99 w:1)
/// Proof: `Funding::ProjectsToUpdate` (`max_values`: None, `max_size`: Some(26), added: 2501, mode: `MaxEncodedLen`)
/// The range of component `x` is `[1, 99]`.
/// The range of component `y` is `[1, 256]`.
/// The range of component `z` is `[1, 256]`.
fn end_auction_closing(x: u32, y: u32, z: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `28251 + x * (28 ±0) + y * (225 ±0) + z * (392 ±0)`
// Estimated: `4079 + x * (2501 ±0) + y * (2781 ±0) + z * (3624 ±0)`
// Minimum execution time: 3_181_609_000 picoseconds.
Weight::from_parts(208_634_454, 4079)
// Standard Error: 64_217
.saturating_add(Weight::from_parts(2_432_568, 0).saturating_mul(x.into()))
// Standard Error: 24_628
.saturating_add(Weight::from_parts(10_591_792, 0).saturating_mul(y.into()))
// Standard Error: 24_628
.saturating_add(Weight::from_parts(62_828_707, 0).saturating_mul(z.into()))
.saturating_add(T::DbWeight::get().reads(7_u64))
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into())))
.saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(y.into())))
.saturating_add(T::DbWeight::get().reads((4_u64).saturating_mul(z.into())))
.saturating_add(T::DbWeight::get().writes(5_u64))
.saturating_add(T::DbWeight::get().writes((2_u64).saturating_mul(y.into())))
.saturating_add(T::DbWeight::get().writes((4_u64).saturating_mul(z.into())))
.saturating_add(Weight::from_parts(0, 2501).saturating_mul(x.into()))
.saturating_add(Weight::from_parts(0, 2781).saturating_mul(y.into()))
.saturating_add(Weight::from_parts(0, 3624).saturating_mul(z.into()))
}
/// Storage: `Funding::ProjectsDetails` (r:1 w:1)
/// Proof: `Funding::ProjectsDetails` (`max_values`: None, `max_size`: Some(380), added: 2855, mode: `MaxEncodedLen`)
/// Storage: `Funding::ProjectsMetadata` (r:1 w:0)
/// Proof: `Funding::ProjectsMetadata` (`max_values`: None, `max_size`: Some(502), added: 2977, mode: `MaxEncodedLen`)
Expand Down Expand Up @@ -1239,6 +1288,54 @@ impl WeightInfo for () {
.saturating_add(Weight::from_parts(0, 2501).saturating_mul(x.into()))
}
/// Storage: `Funding::ProjectsDetails` (r:1 w:1)
/// Proof: `Funding::ProjectsDetails` (`max_values`: None, `max_size`: Some(397), added: 2872, mode: `MaxEncodedLen`)
/// Storage: `Funding::ProjectsMetadata` (r:1 w:0)
/// Proof: `Funding::ProjectsMetadata` (`max_values`: None, `max_size`: Some(502), added: 2977, mode: `MaxEncodedLen`)
/// Storage: `Funding::Nonce` (r:1 w:1)
/// Proof: `Funding::Nonce` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`)
/// Storage: `Random::RandomMaterial` (r:1 w:0)
/// Proof: `Random::RandomMaterial` (`max_values`: Some(1), `max_size`: Some(2594), added: 3089, mode: `MaxEncodedLen`)
/// Storage: `Funding::Bids` (r:513 w:512)
/// Proof: `Funding::Bids` (`max_values`: None, `max_size`: Some(306), added: 2781, mode: `MaxEncodedLen`)
/// Storage: `Funding::DidWithWinningBids` (r:256 w:256)
/// Proof: `Funding::DidWithWinningBids` (`max_values`: None, `max_size`: Some(95), added: 2570, mode: `MaxEncodedLen`)
/// Storage: `ForeignAssets::Asset` (r:1 w:1)
/// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(210), added: 2685, mode: `MaxEncodedLen`)
/// Storage: `ForeignAssets::Account` (r:257 w:257)
/// Proof: `ForeignAssets::Account` (`max_values`: None, `max_size`: Some(134), added: 2609, mode: `MaxEncodedLen`)
/// Storage: `System::Account` (r:256 w:256)
/// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`)
/// Storage: `Balances::Holds` (r:256 w:256)
/// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(1149), added: 3624, mode: `MaxEncodedLen`)
/// Storage: `Funding::ProjectsToUpdate` (r:99 w:1)
/// Proof: `Funding::ProjectsToUpdate` (`max_values`: None, `max_size`: Some(26), added: 2501, mode: `MaxEncodedLen`)
/// The range of component `x` is `[1, 99]`.
/// The range of component `y` is `[1, 256]`.
/// The range of component `z` is `[1, 256]`.
fn end_auction_closing(x: u32, y: u32, z: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `28251 + x * (28 ±0) + y * (225 ±0) + z * (392 ±0)`
// Estimated: `4079 + x * (2501 ±0) + y * (2781 ±0) + z * (3624 ±0)`
// Minimum execution time: 3_181_609_000 picoseconds.
Weight::from_parts(208_634_454, 4079)
// Standard Error: 64_217
.saturating_add(Weight::from_parts(2_432_568, 0).saturating_mul(x.into()))
// Standard Error: 24_628
.saturating_add(Weight::from_parts(10_591_792, 0).saturating_mul(y.into()))
// Standard Error: 24_628
.saturating_add(Weight::from_parts(62_828_707, 0).saturating_mul(z.into()))
.saturating_add(RocksDbWeight::get().reads(7_u64))
.saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(x.into())))
.saturating_add(RocksDbWeight::get().reads((2_u64).saturating_mul(y.into())))
.saturating_add(RocksDbWeight::get().reads((4_u64).saturating_mul(z.into())))
.saturating_add(RocksDbWeight::get().writes(5_u64))
.saturating_add(RocksDbWeight::get().writes((2_u64).saturating_mul(y.into())))
.saturating_add(RocksDbWeight::get().writes((4_u64).saturating_mul(z.into())))
.saturating_add(Weight::from_parts(0, 2501).saturating_mul(x.into()))
.saturating_add(Weight::from_parts(0, 2781).saturating_mul(y.into()))
.saturating_add(Weight::from_parts(0, 3624).saturating_mul(z.into()))
}
/// Storage: `Funding::ProjectsDetails` (r:1 w:1)
/// Proof: `Funding::ProjectsDetails` (`max_values`: None, `max_size`: Some(380), added: 2855, mode: `MaxEncodedLen`)
/// Storage: `Funding::ProjectsMetadata` (r:1 w:0)
/// Proof: `Funding::ProjectsMetadata` (`max_values`: None, `max_size`: Some(502), added: 2977, mode: `MaxEncodedLen`)
Expand Down
136 changes: 136 additions & 0 deletions runtimes/polimec/src/benchmarks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,138 @@
#[cfg(any(feature = "runtime-benchmarks", feature = "std"))]
pub mod helpers;

#[test]
fn output_max_pallet_funding_values() {
use crate::weights::pallet_funding::SubstrateWeight;
use frame_support::pallet_prelude::Get;
use pallet_funding::weights::WeightInfo;

use crate::Runtime;

let max_projects_to_update_insertion_attempts: u32 =
<Runtime as pallet_funding::Config>::MaxProjectsToUpdateInsertionAttempts::get();
let max_evaluations_per_user: u32 = <Runtime as pallet_funding::Config>::MaxEvaluationsPerUser::get();
let max_bids_per_user: u32 = <Runtime as pallet_funding::Config>::MaxBidsPerUser::get();
let max_contributions_per_user: u32 = <Runtime as pallet_funding::Config>::MaxContributionsPerUser::get();
let max_bids_per_project: u32 = <Runtime as pallet_funding::Config>::MaxBidsPerProject::get();
let max_evaluations_per_project: u32 = <Runtime as pallet_funding::Config>::MaxEvaluationsPerProject::get();

let create_project = SubstrateWeight::<Runtime>::create_project();
dbg!(create_project);

let remove_project = SubstrateWeight::<Runtime>::remove_project();
dbg!(remove_project);

let edit_project = SubstrateWeight::<Runtime>::edit_project();
dbg!(edit_project);

let start_evaluation = SubstrateWeight::<Runtime>::start_evaluation(max_projects_to_update_insertion_attempts - 1);
dbg!(start_evaluation);

let start_auction_manually =
SubstrateWeight::<Runtime>::start_auction_manually(max_projects_to_update_insertion_attempts - 1);
dbg!(start_auction_manually);

let evaluation = SubstrateWeight::<Runtime>::evaluation(max_evaluations_per_user - 1);
dbg!(evaluation);

let bid = SubstrateWeight::<Runtime>::bid(max_bids_per_user, 10);
dbg!(bid);

let contribution = SubstrateWeight::<Runtime>::contribution(max_contributions_per_user);
dbg!(contribution);

let contribution_ends_round = SubstrateWeight::<Runtime>::contribution_ends_round(
max_contributions_per_user - 1,
max_projects_to_update_insertion_attempts - 1,
);
dbg!(contribution_ends_round);

let decide_project_outcome =
SubstrateWeight::<Runtime>::decide_project_outcome(max_projects_to_update_insertion_attempts - 1);
dbg!(decide_project_outcome);

let settle_successful_evaluation = SubstrateWeight::<Runtime>::settle_successful_evaluation();
dbg!(settle_successful_evaluation);

let settle_failed_evaluation = SubstrateWeight::<Runtime>::settle_failed_evaluation();
dbg!(settle_failed_evaluation);

let settle_successful_bid = SubstrateWeight::<Runtime>::settle_successful_bid();
dbg!(settle_successful_bid);

let settle_failed_bid = SubstrateWeight::<Runtime>::settle_failed_bid();
dbg!(settle_failed_bid);

let settle_successful_contribution = SubstrateWeight::<Runtime>::settle_successful_contribution();
dbg!(settle_successful_contribution);

let settle_failed_contribution = SubstrateWeight::<Runtime>::settle_failed_contribution();
dbg!(settle_failed_contribution);

let end_evaluation_success =
SubstrateWeight::<Runtime>::end_evaluation_success(max_projects_to_update_insertion_attempts - 1);
dbg!(end_evaluation_success);

let end_evaluation_failure = SubstrateWeight::<Runtime>::end_evaluation_failure();
dbg!(end_evaluation_failure);

let start_auction_closing_phase =
SubstrateWeight::<Runtime>::start_auction_closing_phase(max_projects_to_update_insertion_attempts - 1);
dbg!(start_auction_closing_phase);

let end_auction_closing = SubstrateWeight::<Runtime>::end_auction_closing(
max_projects_to_update_insertion_attempts - 1,
max_bids_per_project,
0,
);
dbg!(end_auction_closing);

let start_community_funding = SubstrateWeight::<Runtime>::start_community_funding(
max_projects_to_update_insertion_attempts - 1,
max_bids_per_project,
0,
);
dbg!(start_community_funding);

let start_remainder_funding =
SubstrateWeight::<Runtime>::start_remainder_funding(max_projects_to_update_insertion_attempts - 1);
dbg!(start_remainder_funding);

let end_funding_automatically_rejected_evaluators_slashed =
SubstrateWeight::<Runtime>::end_funding_automatically_rejected_evaluators_slashed(
max_projects_to_update_insertion_attempts - 1,
);
dbg!(end_funding_automatically_rejected_evaluators_slashed);

let end_funding_awaiting_decision_evaluators_slashed =
SubstrateWeight::<Runtime>::end_funding_awaiting_decision_evaluators_slashed(
max_projects_to_update_insertion_attempts - 1,
);
dbg!(end_funding_awaiting_decision_evaluators_slashed);

let end_funding_awaiting_decision_evaluators_unchanged =
SubstrateWeight::<Runtime>::end_funding_awaiting_decision_evaluators_unchanged(
max_projects_to_update_insertion_attempts - 1,
);
dbg!(end_funding_awaiting_decision_evaluators_unchanged);

let end_funding_automatically_accepted_evaluators_rewarded =
SubstrateWeight::<Runtime>::end_funding_automatically_accepted_evaluators_rewarded(
max_projects_to_update_insertion_attempts - 1,
max_evaluations_per_project,
);
dbg!(end_funding_automatically_accepted_evaluators_rewarded);

let project_decision = SubstrateWeight::<Runtime>::project_decision();
dbg!(project_decision);

let start_settlement_funding_success = SubstrateWeight::<Runtime>::start_settlement_funding_success();
dbg!(start_settlement_funding_success);

let start_settlement_funding_failure = SubstrateWeight::<Runtime>::start_settlement_funding_failure();
dbg!(start_settlement_funding_failure);

let total_blockspace = <Runtime as frame_system::Config>::BlockWeights::get().max_block;
dbg!(total_blockspace);
}
2 changes: 1 addition & 1 deletion runtimes/polimec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ impl pallet_funding::Config for Runtime {
type SuccessToSettlementTime = SuccessToSettlementTime;
type VerifierPublicKey = VerifierPublicKey;
type Vesting = LinearRelease;
type WeightInfo = weights::pallet_funding::WeightInfo<Runtime>;
type WeightInfo = weights::pallet_funding::SubstrateWeight<Runtime>;
}

#[cfg(feature = "runtime-benchmarks")]
Expand Down
Loading

0 comments on commit 89d340a

Please sign in to comment.