Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/plmc 442 delete remove from update store #180

Merged
merged 9 commits into from
Mar 11, 2024
Merged
Changes from 1 commit
Commits
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
remove do_english_auction automatic benchmark as its the same now as …
…manual benchmark
  • Loading branch information
vstam1 committed Mar 6, 2024
commit b06bc0eba0df8a30832235e6f37c06eff5216967
69 changes: 0 additions & 69 deletions pallets/funding/src/benchmarking.rs
Original file line number Diff line number Diff line change
@@ -2700,68 +2700,6 @@ mod benchmarks {
assert_eq!(project_details.status, ProjectStatus::EvaluationFailed);
}

//do_english_auction
#[benchmark]
fn start_auction_automatically(
// Insertion attempts in add_to_update_store. Total amount of storage items iterated through in `ProjectsToUpdate`. Leave one free to make the extrinsic pass
x: Linear<1, { <T as Config>::MaxProjectsToUpdateInsertionAttempts::get() - 1 }>,
// No `y` param because we don't need to remove the automatic transition from storage
) {
// * setup *
let mut inst = BenchInstantiator::<T>::new(None);

// real benchmark starts at block 0, and we can't call `events()` at block 0
inst.advance_time(1u32.into()).unwrap();

let issuer = account::<AccountIdOf<T>>("issuer", 0, 0);
whitelist_account!(issuer);

let project_metadata = default_project::<T>(inst.get_new_nonce(), issuer.clone());
let project_id = inst.create_evaluating_project(project_metadata, issuer.clone());

let evaluations = default_evaluations();
let plmc_for_evaluating = BenchInstantiator::<T>::calculate_evaluation_plmc_spent(evaluations.clone());
let existential_plmc: Vec<UserToPLMCBalance<T>> = plmc_for_evaluating.accounts().existential_deposits();
let ct_account_deposits: Vec<UserToPLMCBalance<T>> = plmc_for_evaluating.accounts().ct_account_deposits();

inst.mint_plmc_to(existential_plmc);
inst.mint_plmc_to(ct_account_deposits);
inst.mint_plmc_to(plmc_for_evaluating);

inst.advance_time(One::one()).unwrap();
inst.bond_for_users(project_id, evaluations).expect("All evaluations are accepted");

run_blocks_to_execute_next_transition(project_id, UpdateType::EvaluationEnd, &mut inst);

let current_block = inst.current_block();
let automatic_transition_block =
current_block + <T as Config>::AuctionInitializePeriodDuration::get() + One::one();
let insertion_block_number: BlockNumberFor<T> =
automatic_transition_block + T::EnglishAuctionDuration::get() + One::one();
let block_number = insertion_block_number;

fill_projects_to_update::<T>(x, block_number);

// we don't use advance time to avoid triggering on_initialize. This benchmark should only measure the extrinsic
// weight and not the whole on_initialize call weight
frame_system::Pallet::<T>::set_block_number(automatic_transition_block);

let jwt = get_mock_jwt(issuer.clone(), InvestorType::Institutional);
#[extrinsic_call]
start_auction(RawOrigin::Signed(issuer), jwt, project_id);

// * validity checks *
// Storage
let stored_details = ProjectsDetails::<T>::get(project_id).unwrap();
assert_eq!(stored_details.status, ProjectStatus::AuctionRound(AuctionPhase::English));

// Events
let current_block = inst.current_block();
frame_system::Pallet::<T>::assert_last_event(
Event::<T>::EnglishAuctionStarted { project_id, when: current_block.into() }.into(),
);
}

// do_candle_auction
#[benchmark]
fn start_candle_phase(
@@ -3532,13 +3470,6 @@ mod benchmarks {
});
}

#[test]
fn bench_start_auction_automatically() {
new_test_ext().execute_with(|| {
assert_ok!(PalletFunding::<TestRuntime>::test_start_auction_automatically());
});
}

#[test]
fn bench_bid_with_ct_deposit() {
new_test_ext().execute_with(|| {
4 changes: 2 additions & 2 deletions pallets/funding/src/functions.rs
Original file line number Diff line number Diff line change
@@ -394,7 +394,7 @@ impl<T: Config> Pallet<T> {
Err(insertion_attempts) =>
return Err(DispatchErrorWithPostInfo {
post_info: PostDispatchInfo {
actual_weight: Some(WeightInfoOf::<T>::start_auction_automatically(insertion_attempts)),
actual_weight: Some(WeightInfoOf::<T>::start_auction_manually(insertion_attempts)),
pays_fee: Pays::Yes,
},
error: Error::<T>::TooManyInsertionAttempts.into(),
@@ -405,7 +405,7 @@ impl<T: Config> Pallet<T> {
Self::deposit_event(Event::EnglishAuctionStarted { project_id, when: now });

Ok(PostDispatchInfo {
actual_weight: Some(WeightInfoOf::<T>::start_auction_automatically(insertion_attempts)),
actual_weight: Some(WeightInfoOf::<T>::start_auction_manually(insertion_attempts)),
pays_fee: Pays::Yes,
})
}
3 changes: 1 addition & 2 deletions pallets/funding/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1048,7 +1048,7 @@ pub mod pallet {
/// institutional user can set bids for a token_amount/token_price pair.
/// Any bids from this point until the candle_auction starts, will be considered as valid.
#[pallet::call_index(3)]
#[pallet::weight(WeightInfoOf::<T>::start_auction_manually(<T as Config>::MaxProjectsToUpdateInsertionAttempts::get() - 1, 10_000u32))]
#[pallet::weight(WeightInfoOf::<T>::start_auction_manually(<T as Config>::MaxProjectsToUpdateInsertionAttempts::get() - 1))]
pub fn start_auction(
origin: OriginFor<T>,
jwt: UntrustedToken,
@@ -1423,7 +1423,6 @@ pub mod pallet {
.actual_weight
.unwrap_or(WeightInfoOf::<T>::start_auction_manually(
<T as Config>::MaxProjectsToUpdateInsertionAttempts::get() - 1,
10_000,
)),
);
},
43 changes: 3 additions & 40 deletions pallets/funding/src/weights.rs
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ pub trait WeightInfo {
fn create() -> Weight;
fn edit_metadata() -> Weight;
fn start_evaluation(x: u32, ) -> Weight;
fn start_auction_manually(x: u32, y: u32, ) -> Weight;
fn start_auction_manually(x: u32 ) -> Weight;
fn first_evaluation() -> Weight;
fn second_to_limit_evaluation(x: u32, ) -> Weight;
fn evaluation_over_limit() -> Weight;
@@ -79,7 +79,6 @@ pub trait WeightInfo {
fn contribution_unbond_for() -> Weight;
fn end_evaluation_success(x: u32, ) -> Weight;
fn end_evaluation_failure() -> Weight;
fn start_auction_automatically(x: u32, ) -> Weight;
fn start_candle_phase(x: u32, ) -> Weight;
fn start_community_funding_success(x: u32, y: u32, z: u32, ) -> Weight;
fn start_community_funding_failure(x: u32, ) -> Weight;
@@ -159,7 +158,7 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
/// Proof: `PolimecFunding::ProjectsToUpdate` (`max_values`: None, `max_size`: Some(27), added: 2502, mode: `MaxEncodedLen`)
/// The range of component `x` is `[1, 99]`.
/// The range of component `y` is `[1, 10000]`.
fn start_auction_manually(x: u32, y: u32, ) -> Weight {
fn start_auction_manually(x: u32 ) -> Weight {
// Proof Size summary in bytes:
// Measured: `0 + x * (539 ±0) + y * (13 ±0)`
// Estimated: `217021 + x * (8051 ±6_772) + y * (979 ±66)`
@@ -721,24 +720,6 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
}
/// Storage: `PolimecFunding::ProjectsDetails` (r:1 w:1)
/// Proof: `PolimecFunding::ProjectsDetails` (`max_values`: None, `max_size`: Some(349), added: 2824, mode: `MaxEncodedLen`)
/// Storage: `PolimecFunding::ProjectsToUpdate` (r:102 w:2)
/// Proof: `PolimecFunding::ProjectsToUpdate` (`max_values`: None, `max_size`: Some(27), added: 2502, mode: `MaxEncodedLen`)
/// The range of component `x` is `[1, 99]`.
fn start_auction_automatically(x: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `413 + x * (29 ±0)`
// Estimated: `8496 + x * (2502 ±0)`
// Minimum execution time: 26_000_000 picoseconds.
Weight::from_parts(28_124_881, 8496)
// Standard Error: 5_442
.saturating_add(Weight::from_parts(2_521_942, 0).saturating_mul(x.into()))
.saturating_add(T::DbWeight::get().reads(4_u64))
.saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into())))
.saturating_add(T::DbWeight::get().writes(3_u64))
.saturating_add(Weight::from_parts(0, 2502).saturating_mul(x.into()))
}
/// Storage: `PolimecFunding::ProjectsDetails` (r:1 w:1)
/// Proof: `PolimecFunding::ProjectsDetails` (`max_values`: None, `max_size`: Some(349), added: 2824, mode: `MaxEncodedLen`)
/// Storage: `PolimecFunding::ProjectsToUpdate` (r:100 w:1)
/// Proof: `PolimecFunding::ProjectsToUpdate` (`max_values`: None, `max_size`: Some(27), added: 2502, mode: `MaxEncodedLen`)
/// The range of component `x` is `[1, 99]`.
@@ -1060,7 +1041,7 @@ impl WeightInfo for () {
/// Proof: `PolimecFunding::ProjectsToUpdate` (`max_values`: None, `max_size`: Some(27), added: 2502, mode: `MaxEncodedLen`)
/// The range of component `x` is `[1, 99]`.
/// The range of component `y` is `[1, 10000]`.
fn start_auction_manually(x: u32, y: u32, ) -> Weight {
fn start_auction_manually(x: u32 ) -> Weight {
// Proof Size summary in bytes:
// Measured: `0 + x * (539 ±0) + y * (13 ±0)`
// Estimated: `217021 + x * (8051 ±6_772) + y * (979 ±66)`
@@ -1622,24 +1603,6 @@ impl WeightInfo for () {
}
/// Storage: `PolimecFunding::ProjectsDetails` (r:1 w:1)
/// Proof: `PolimecFunding::ProjectsDetails` (`max_values`: None, `max_size`: Some(349), added: 2824, mode: `MaxEncodedLen`)
/// Storage: `PolimecFunding::ProjectsToUpdate` (r:102 w:2)
/// Proof: `PolimecFunding::ProjectsToUpdate` (`max_values`: None, `max_size`: Some(27), added: 2502, mode: `MaxEncodedLen`)
/// The range of component `x` is `[1, 99]`.
fn start_auction_automatically(x: u32, ) -> Weight {
// Proof Size summary in bytes:
// Measured: `413 + x * (29 ±0)`
// Estimated: `8496 + x * (2502 ±0)`
// Minimum execution time: 26_000_000 picoseconds.
Weight::from_parts(28_124_881, 8496)
// Standard Error: 5_442
.saturating_add(Weight::from_parts(2_521_942, 0).saturating_mul(x.into()))
.saturating_add(RocksDbWeight::get().reads(4_u64))
.saturating_add(RocksDbWeight::get().reads((1_u64).saturating_mul(x.into())))
.saturating_add(RocksDbWeight::get().writes(3_u64))
.saturating_add(Weight::from_parts(0, 2502).saturating_mul(x.into()))
}
/// Storage: `PolimecFunding::ProjectsDetails` (r:1 w:1)
/// Proof: `PolimecFunding::ProjectsDetails` (`max_values`: None, `max_size`: Some(349), added: 2824, mode: `MaxEncodedLen`)
/// Storage: `PolimecFunding::ProjectsToUpdate` (r:100 w:1)
/// Proof: `PolimecFunding::ProjectsToUpdate` (`max_values`: None, `max_size`: Some(27), added: 2502, mode: `MaxEncodedLen`)
/// The range of component `x` is `[1, 99]`.