From b0c55cc3cef060583968986ec5d55ea75bc39b32 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Rios Date: Mon, 1 Jul 2024 15:13:54 +0200 Subject: [PATCH] new benchmarks --- .../funding/src/functions/7_ct_migration.rs | 8 +- pallets/funding/src/lib.rs | 302 ++++++++++-------- pallets/funding/src/tests/8_ct_migration.rs | 6 +- 3 files changed, 171 insertions(+), 145 deletions(-) diff --git a/pallets/funding/src/functions/7_ct_migration.rs b/pallets/funding/src/functions/7_ct_migration.rs index 001ee6217..5a2f81e7f 100644 --- a/pallets/funding/src/functions/7_ct_migration.rs +++ b/pallets/funding/src/functions/7_ct_migration.rs @@ -216,7 +216,7 @@ impl Pallet { para_id: ParaId::from(recipient), }); - Pallet::::do_start_migration_readiness_check( + Pallet::::do_start_pallet_migration_readiness_check( &(T::PalletId::get().into_account_truncating()), project_id, ) @@ -233,7 +233,7 @@ impl Pallet { /// After the bidirectional HRMP channels are established, check that the project chain has the Polimec receiver pallet, /// and has minted the amount of CTs sold to the Polimec sovereign account. #[transactional] - pub fn do_start_migration_readiness_check(caller: &AccountIdOf, project_id: ProjectId) -> DispatchResult { + pub fn do_start_pallet_migration_readiness_check(caller: &AccountIdOf, project_id: ProjectId) -> DispatchResult { // * Get variables * let mut project_details = ProjectsDetails::::get(project_id).ok_or(Error::::ProjectDetailsNotFound)?; let Some(MigrationType::Pallet(ref mut migration_info)) = project_details.migration_type else { @@ -270,7 +270,7 @@ impl Pallet { } // * Update storage * - let call = Call::::migration_check_response { query_id: Default::default(), response: Default::default() }; + let call = Call::::pallet_migration_readiness_response { query_id: Default::default(), response: Default::default() }; let query_id_holdings = pallet_xcm::Pallet::::new_notify_query( project_multilocation.clone(), @@ -328,7 +328,7 @@ impl Pallet { /// Handle the migration readiness check response from the project chain. #[transactional] - pub fn do_migration_check_response( + pub fn do_pallet_migration_readiness_response( location: MultiLocation, query_id: xcm::v3::QueryId, response: xcm::v3::Response, diff --git a/pallets/funding/src/lib.rs b/pallets/funding/src/lib.rs index da3c4ff39..1956e8e7e 100644 --- a/pallets/funding/src/lib.rs +++ b/pallets/funding/src/lib.rs @@ -839,7 +839,7 @@ pub mod pallet { Self::do_create_project(&account, project, did) } - #[pallet::call_index(35)] + #[pallet::call_index(1)] #[pallet::weight(WeightInfoOf::::remove_project())] pub fn remove_project(origin: OriginFor, jwt: UntrustedToken, project_id: ProjectId) -> DispatchResult { let (account, did, investor_type, _cid) = @@ -849,7 +849,7 @@ pub mod pallet { } /// Change the metadata hash of a project - #[pallet::call_index(1)] + #[pallet::call_index(2)] #[pallet::weight(WeightInfoOf::::edit_project())] pub fn edit_project( origin: OriginFor, @@ -864,7 +864,7 @@ pub mod pallet { } /// Starts the evaluation round of a project. It needs to be called by the project issuer. - #[pallet::call_index(2)] + #[pallet::call_index(3)] #[pallet::weight(WeightInfoOf::::start_evaluation(::MaxProjectsToUpdateInsertionAttempts::get() - 1))] pub fn start_evaluation( origin: OriginFor, @@ -880,7 +880,7 @@ pub mod pallet { /// Starts the auction round for a project. From the next block forward, any professional or /// institutional user can set bids for a token_amount/token_price pair. /// Any bids from this point until the auction_closing starts, will be considered as valid. - #[pallet::call_index(3)] + #[pallet::call_index(4)] #[pallet::weight(WeightInfoOf::::start_auction_manually(::MaxProjectsToUpdateInsertionAttempts::get() - 1))] pub fn start_auction( origin: OriginFor, @@ -894,7 +894,7 @@ pub mod pallet { } /// Bond PLMC for a project in the evaluation stage - #[pallet::call_index(4)] + #[pallet::call_index(5)] #[pallet::weight( WeightInfoOf::::evaluation(T::MaxEvaluationsPerUser::get() - 1) )] @@ -910,8 +910,24 @@ pub mod pallet { Self::do_evaluate(&account, project_id, usd_amount, did, investor_type, whitelisted_policy) } + #[pallet::call_index(6)] + #[pallet::weight(WeightInfoOf::::end_evaluation_success( + ::MaxProjectsToUpdateInsertionAttempts::get() - 1, + ))] + pub fn root_do_evaluation_end(origin: OriginFor, project_id: ProjectId) -> DispatchResultWithPostInfo { + ensure_root(origin)?; + Self::do_evaluation_end(project_id) + } + + #[pallet::call_index(7)] + #[pallet::weight(WeightInfoOf::::start_auction_manually(::MaxProjectsToUpdateInsertionAttempts::get() - 1))] + pub fn root_do_auction_opening(origin: OriginFor, project_id: ProjectId) -> DispatchResultWithPostInfo { + ensure_root(origin)?; + Self::do_start_auction_opening(T::PalletId::get().into_account_truncating(), project_id) + } + /// Bid for a project in the Auction round - #[pallet::call_index(5)] + #[pallet::call_index(8)] #[pallet::weight( WeightInfoOf::::bid( ::MaxBidsPerUser::get() - 1, @@ -934,8 +950,63 @@ pub mod pallet { Self::do_bid(&account, project_id, ct_amount, multiplier, asset, did, investor_type, whitelisted_policy) } + #[pallet::call_index(9)] + #[pallet::weight(WeightInfoOf::::start_auction_closing_phase( + ::MaxProjectsToUpdateInsertionAttempts::get() - 1, + ))] + pub fn root_do_start_auction_closing( + origin: OriginFor, + project_id: ProjectId, + ) -> DispatchResultWithPostInfo { + ensure_root(origin)?; + Self::do_start_auction_closing(project_id) + } + + #[pallet::call_index(10)] + #[pallet::weight(WeightInfoOf::::end_auction_closing( + ::MaxProjectsToUpdateInsertionAttempts::get() - 1, + ::MaxBidsPerProject::get() / 2, + ::MaxBidsPerProject::get() / 2, + ) + .max(WeightInfoOf::::end_auction_closing( + ::MaxProjectsToUpdateInsertionAttempts::get() - 1, + ::MaxBidsPerProject::get(), + 0u32, + )) + .max(WeightInfoOf::::end_auction_closing( + ::MaxProjectsToUpdateInsertionAttempts::get() - 1, + 0u32, + ::MaxBidsPerProject::get(), + )))] + pub fn root_do_end_auction_closing(origin: OriginFor, project_id: ProjectId) -> DispatchResultWithPostInfo { + ensure_root(origin)?; + Self::do_end_auction_closing(project_id) + } + + #[pallet::call_index(11)] + #[pallet::weight(WeightInfoOf::::start_community_funding( + ::MaxProjectsToUpdateInsertionAttempts::get() - 1, + ::MaxBidsPerProject::get() / 2, + ::MaxBidsPerProject::get() / 2, + ) + .max(WeightInfoOf::::start_community_funding( + ::MaxProjectsToUpdateInsertionAttempts::get() - 1, + ::MaxBidsPerProject::get(), + 0u32, + )) + .max(WeightInfoOf::::start_community_funding( + ::MaxProjectsToUpdateInsertionAttempts::get() - 1, + 0u32, + ::MaxBidsPerProject::get(), + )))] + pub fn root_do_community_funding(origin: OriginFor, project_id: ProjectId) -> DispatchResultWithPostInfo { + ensure_root(origin)?; + Self::do_start_community_funding(project_id) + } + + /// Buy tokens in the Community or Remainder round at the price set in the Auction Round - #[pallet::call_index(6)] + #[pallet::call_index(12)] #[pallet::weight( WeightInfoOf::::contribution(T::MaxContributionsPerUser::get() - 1) .max(WeightInfoOf::::contribution_ends_round( @@ -968,8 +1039,17 @@ pub mod pallet { ) } + #[pallet::call_index(13)] + #[pallet::weight(WeightInfoOf::::start_remainder_funding( + ::MaxProjectsToUpdateInsertionAttempts::get() - 1, + ))] + pub fn root_do_remainder_funding(origin: OriginFor, project_id: ProjectId) -> DispatchResultWithPostInfo { + ensure_root(origin)?; + Self::do_start_remainder_funding(project_id) + } + /// Buy tokens in the Community or Remainder round at the price set in the Auction Round - #[pallet::call_index(7)] + #[pallet::call_index(14)] #[pallet::weight( WeightInfoOf::::contribution(T::MaxContributionsPerUser::get() - 1) .max(WeightInfoOf::::contribution_ends_round( @@ -1002,9 +1082,28 @@ pub mod pallet { ) } - #[pallet::call_index(8)] + #[pallet::call_index(15)] + #[pallet::weight(WeightInfoOf::::end_funding_automatically_rejected_evaluators_slashed( + ::MaxProjectsToUpdateInsertionAttempts::get() - 1, + ) + .max(WeightInfoOf::::end_funding_awaiting_decision_evaluators_slashed( + ::MaxProjectsToUpdateInsertionAttempts::get() - 1, + )) + .max(WeightInfoOf::::end_funding_awaiting_decision_evaluators_unchanged( + ::MaxProjectsToUpdateInsertionAttempts::get() - 1, + )) + .max(WeightInfoOf::::end_funding_automatically_accepted_evaluators_rewarded( + ::MaxProjectsToUpdateInsertionAttempts::get() - 1, + ::MaxEvaluationsPerProject::get(), + )))] + pub fn root_do_end_funding(origin: OriginFor, project_id: ProjectId) -> DispatchResultWithPostInfo { + ensure_root(origin)?; + Self::do_end_funding(project_id) + } + + #[pallet::call_index(16)] #[pallet::weight(WeightInfoOf::::decide_project_outcome( - ::MaxProjectsToUpdateInsertionAttempts::get() - 1 + ::MaxProjectsToUpdateInsertionAttempts::get() - 1 ))] pub fn decide_project_outcome( origin: OriginFor, @@ -1019,7 +1118,26 @@ pub mod pallet { Self::do_decide_project_outcome(account, project_id, outcome) } - #[pallet::call_index(9)] + #[pallet::call_index(17)] + #[pallet::weight(WeightInfoOf::::project_decision())] + pub fn root_do_project_decision( + origin: OriginFor, + project_id: ProjectId, + decision: FundingOutcomeDecision, + ) -> DispatchResultWithPostInfo { + ensure_root(origin)?; + Self::do_project_decision(project_id, decision) + } + + #[pallet::call_index(18)] + #[pallet::weight(WeightInfoOf::::start_settlement_funding_success() + .max(WeightInfoOf::::start_settlement_funding_failure()))] + pub fn root_do_start_settlement(origin: OriginFor, project_id: ProjectId) -> DispatchResultWithPostInfo { + ensure_root(origin)?; + Self::do_start_settlement(project_id) + } + + #[pallet::call_index(19)] #[pallet::weight(WeightInfoOf::::settle_successful_evaluation())] pub fn settle_successful_evaluation( origin: OriginFor, @@ -1033,7 +1151,7 @@ pub mod pallet { Self::do_settle_successful_evaluation(bid, project_id) } - #[pallet::call_index(10)] + #[pallet::call_index(20)] #[pallet::weight(WeightInfoOf::::settle_successful_bid())] pub fn settle_successful_bid( origin: OriginFor, @@ -1046,7 +1164,7 @@ pub mod pallet { Self::do_settle_successful_bid(bid, project_id) } - #[pallet::call_index(11)] + #[pallet::call_index(21)] #[pallet::weight(WeightInfoOf::::settle_successful_contribution())] pub fn settle_successful_contribution( origin: OriginFor, @@ -1060,7 +1178,7 @@ pub mod pallet { Self::do_settle_successful_contribution(bid, project_id) } - #[pallet::call_index(12)] + #[pallet::call_index(22)] #[pallet::weight(WeightInfoOf::::settle_failed_evaluation())] pub fn settle_failed_evaluation( origin: OriginFor, @@ -1074,7 +1192,7 @@ pub mod pallet { Self::do_settle_failed_evaluation(bid, project_id) } - #[pallet::call_index(13)] + #[pallet::call_index(23)] #[pallet::weight(WeightInfoOf::::settle_failed_bid())] pub fn settle_failed_bid( origin: OriginFor, @@ -1087,7 +1205,7 @@ pub mod pallet { Self::do_settle_failed_bid(bid, project_id) } - #[pallet::call_index(14)] + #[pallet::call_index(24)] #[pallet::weight(WeightInfoOf::::settle_failed_contribution())] pub fn settle_failed_contribution( origin: OriginFor, @@ -1101,9 +1219,9 @@ pub mod pallet { Self::do_settle_failed_contribution(bid, project_id) } - #[pallet::call_index(22)] + #[pallet::call_index(25)] #[pallet::weight(Weight::from_parts(1000, 0))] - pub fn configure_receiver_pallet_migration( + pub fn start_pallet_migration( origin: OriginFor, jwt: UntrustedToken, project_id: ProjectId, @@ -1116,9 +1234,9 @@ pub mod pallet { Self::do_start_pallet_migration(&account, project_id, para_id) } - #[pallet::call_index(23)] + #[pallet::call_index(26)] #[pallet::weight(Weight::from_parts(1000, 0))] - pub fn start_migration_readiness_check( + pub fn start_offchain_migration( origin: OriginFor, jwt: UntrustedToken, project_id: ProjectId, @@ -1126,23 +1244,37 @@ pub mod pallet { let (account, _did, investor_type, _cid) = T::InvestorOrigin::ensure_origin(origin, &jwt, T::VerifierPublicKey::get())?; ensure!(investor_type == InvestorType::Institutional, Error::::WrongInvestorType); - Self::do_start_migration_readiness_check(&account, project_id) + + Self::do_start_offchain_migration(project_id, account) + } + + #[pallet::call_index(27)] + #[pallet::weight(Weight::from_parts(1000, 0))] + pub fn start_pallet_migration_readiness_check( + origin: OriginFor, + jwt: UntrustedToken, + project_id: ProjectId, + ) -> DispatchResult { + let (account, _did, investor_type, _cid) = + T::InvestorOrigin::ensure_origin(origin, &jwt, T::VerifierPublicKey::get())?; + ensure!(investor_type == InvestorType::Institutional, Error::::WrongInvestorType); + Self::do_start_pallet_migration_readiness_check(&account, project_id) } /// Called only by other chains through a query response xcm message - #[pallet::call_index(24)] + #[pallet::call_index(28)] #[pallet::weight(Weight::from_parts(1000, 0))] - pub fn migration_check_response( + pub fn pallet_migration_readiness_response( origin: OriginFor, query_id: xcm::v3::QueryId, response: xcm::v3::Response, ) -> DispatchResult { let location = ensure_response(::RuntimeOrigin::from(origin))?; - Self::do_migration_check_response(location, query_id, response) + Self::do_pallet_migration_readiness_response(location, query_id, response) } - #[pallet::call_index(26)] + #[pallet::call_index(29)] #[pallet::weight(Weight::from_parts(1000, 0))] pub fn send_pallet_migration_for( origin: OriginFor, @@ -1153,7 +1285,7 @@ pub mod pallet { Self::do_send_pallet_migration_for(project_id, participant) } - #[pallet::call_index(27)] + #[pallet::call_index(30)] #[pallet::weight(Weight::from_parts(1000, 0))] pub fn confirm_pallet_migrations( origin: OriginFor, @@ -1165,7 +1297,7 @@ pub mod pallet { Self::do_confirm_pallet_migrations(location, query_id, response) } - #[pallet::call_index(38)] + #[pallet::call_index(31)] #[pallet::weight(Weight::from_parts(1000, 0))] pub fn confirm_offchain_migration( origin: OriginFor, @@ -1177,121 +1309,15 @@ pub mod pallet { Self::do_confirm_offchain_migration(project_id, caller, participant) } - #[pallet::call_index(28)] - #[pallet::weight(WeightInfoOf::::end_evaluation_success( - ::MaxProjectsToUpdateInsertionAttempts::get() - 1, - ))] - pub fn root_do_evaluation_end(origin: OriginFor, project_id: ProjectId) -> DispatchResultWithPostInfo { - ensure_root(origin)?; - Self::do_evaluation_end(project_id) - } - - #[pallet::call_index(29)] - #[pallet::weight(WeightInfoOf::::start_auction_manually(::MaxProjectsToUpdateInsertionAttempts::get() - 1))] - pub fn root_do_auction_opening(origin: OriginFor, project_id: ProjectId) -> DispatchResultWithPostInfo { - ensure_root(origin)?; - Self::do_start_auction_opening(T::PalletId::get().into_account_truncating(), project_id) - } - - #[pallet::call_index(30)] - #[pallet::weight(WeightInfoOf::::start_auction_closing_phase( - ::MaxProjectsToUpdateInsertionAttempts::get() - 1, - ))] - pub fn root_do_start_auction_closing( - origin: OriginFor, - project_id: ProjectId, - ) -> DispatchResultWithPostInfo { - ensure_root(origin)?; - Self::do_start_auction_closing(project_id) - } - - #[pallet::call_index(31)] - #[pallet::weight(WeightInfoOf::::end_auction_closing( - ::MaxProjectsToUpdateInsertionAttempts::get() - 1, - ::MaxBidsPerProject::get() / 2, - ::MaxBidsPerProject::get() / 2, - ) - .max(WeightInfoOf::::end_auction_closing( - ::MaxProjectsToUpdateInsertionAttempts::get() - 1, - ::MaxBidsPerProject::get(), - 0u32, - )) - .max(WeightInfoOf::::end_auction_closing( - ::MaxProjectsToUpdateInsertionAttempts::get() - 1, - 0u32, - ::MaxBidsPerProject::get(), - )))] - pub fn root_do_end_auction_closing(origin: OriginFor, project_id: ProjectId) -> DispatchResultWithPostInfo { - ensure_root(origin)?; - Self::do_end_auction_closing(project_id) - } - #[pallet::call_index(32)] - #[pallet::weight(WeightInfoOf::::start_community_funding( - ::MaxProjectsToUpdateInsertionAttempts::get() - 1, - ::MaxBidsPerProject::get() / 2, - ::MaxBidsPerProject::get() / 2, - ) - .max(WeightInfoOf::::start_community_funding( - ::MaxProjectsToUpdateInsertionAttempts::get() - 1, - ::MaxBidsPerProject::get(), - 0u32, - )) - .max(WeightInfoOf::::start_community_funding( - ::MaxProjectsToUpdateInsertionAttempts::get() - 1, - 0u32, - ::MaxBidsPerProject::get(), - )))] - pub fn root_do_community_funding(origin: OriginFor, project_id: ProjectId) -> DispatchResultWithPostInfo { - ensure_root(origin)?; - Self::do_start_community_funding(project_id) - } - - #[pallet::call_index(33)] - #[pallet::weight(WeightInfoOf::::start_remainder_funding( - ::MaxProjectsToUpdateInsertionAttempts::get() - 1, - ))] - pub fn root_do_remainder_funding(origin: OriginFor, project_id: ProjectId) -> DispatchResultWithPostInfo { - ensure_root(origin)?; - Self::do_start_remainder_funding(project_id) - } - - #[pallet::call_index(34)] - #[pallet::weight(WeightInfoOf::::end_funding_automatically_rejected_evaluators_slashed( - ::MaxProjectsToUpdateInsertionAttempts::get() - 1, - ) - .max(WeightInfoOf::::end_funding_awaiting_decision_evaluators_slashed( - ::MaxProjectsToUpdateInsertionAttempts::get() - 1, - )) - .max(WeightInfoOf::::end_funding_awaiting_decision_evaluators_unchanged( - ::MaxProjectsToUpdateInsertionAttempts::get() - 1, - )) - .max(WeightInfoOf::::end_funding_automatically_accepted_evaluators_rewarded( - ::MaxProjectsToUpdateInsertionAttempts::get() - 1, - ::MaxEvaluationsPerProject::get(), - )))] - pub fn root_do_end_funding(origin: OriginFor, project_id: ProjectId) -> DispatchResultWithPostInfo { - ensure_root(origin)?; - Self::do_end_funding(project_id) - } - - #[pallet::call_index(36)] - #[pallet::weight(WeightInfoOf::::project_decision())] - pub fn root_do_project_decision( + #[pallet::weight(Weight::from_parts(1000, 0))] + pub fn mark_project_migration_as_finished( origin: OriginFor, project_id: ProjectId, - decision: FundingOutcomeDecision, - ) -> DispatchResultWithPostInfo { - ensure_root(origin)?; - Self::do_project_decision(project_id, decision) - } + ) -> DispatchResult { + let _caller = ensure_signed(origin)?; - #[pallet::call_index(37)] - #[pallet::weight(WeightInfoOf::::start_settlement_funding_success() - .max(WeightInfoOf::::start_settlement_funding_failure()))] - pub fn root_do_start_settlement(origin: OriginFor, project_id: ProjectId) -> DispatchResultWithPostInfo { - ensure_root(origin)?; - Self::do_start_settlement(project_id) + Self::do_mark_project_ct_migration_as_finished(project_id) } } diff --git a/pallets/funding/src/tests/8_ct_migration.rs b/pallets/funding/src/tests/8_ct_migration.rs index 676d7ac8f..2ea95dc62 100644 --- a/pallets/funding/src/tests/8_ct_migration.rs +++ b/pallets/funding/src/tests/8_ct_migration.rs @@ -145,7 +145,7 @@ mod pallet_migration { .into(); inst.execute(|| { - assert_ok!(PolimecFunding::do_migration_check_response( + assert_ok!(PolimecFunding::do_pallet_migration_readiness_response( MultiLocation::new(1u8, X1(Parachain(6969u32))), 0u64, Response::Assets(ct_multiassets), @@ -167,7 +167,7 @@ mod pallet_migration { patch: 0, }; inst.execute(|| { - assert_ok!(PolimecFunding::do_migration_check_response( + assert_ok!(PolimecFunding::do_pallet_migration_readiness_response( MultiLocation::new(1u8, X1(Parachain(6969u32))), 1u64, Response::PalletsInfo(bounded_vec![pallet_info]), @@ -252,7 +252,7 @@ mod offchain_migration { } #[test] - fn mark_project_as_migration_finished() { + fn mark_project_migration_as_finished() { let inst = MockInstantiator::new(Some(RefCell::new(new_test_ext()))); let (project_id, mut inst) = create_offchain_migration_project(inst);