From bac24e6f2f3bafd0f2b6baca0f57bb38b6999f2f Mon Sep 17 00:00:00 2001 From: Chralt Date: Mon, 17 Jul 2023 16:39:21 +0200 Subject: [PATCH] Add dispatch call indices (#1036) * add call indices * update copyrights * fix copyrights * Update zrml/rikiddo/src/lib.rs Co-authored-by: Harald Heckmann --------- Co-authored-by: Harald Heckmann --- zrml/authorized/src/lib.rs | 3 ++- zrml/court/src/lib.rs | 3 +++ zrml/global-disputes/src/lib.rs | 17 +++++++++++------ zrml/liquidity-mining/src/lib.rs | 3 ++- zrml/orderbook-v1/src/lib.rs | 4 ++++ zrml/prediction-markets/src/lib.rs | 17 +++++++++++++++++ zrml/styx/src/lib.rs | 3 +++ zrml/swaps/src/lib.rs | 11 +++++++++++ 8 files changed, 53 insertions(+), 8 deletions(-) diff --git a/zrml/authorized/src/lib.rs b/zrml/authorized/src/lib.rs index 95a82638a..10bb0f8fe 100644 --- a/zrml/authorized/src/lib.rs +++ b/zrml/authorized/src/lib.rs @@ -76,12 +76,13 @@ mod pallet { #[pallet::call] impl Pallet { /// Overwrites already provided outcomes for the same market and account. - #[frame_support::transactional] + #[pallet::call_index(0)] #[pallet::weight( T::WeightInfo::authorize_market_outcome_first_report(CacheSize::get()).max( T::WeightInfo::authorize_market_outcome_existing_report(), ) )] + #[frame_support::transactional] pub fn authorize_market_outcome( origin: OriginFor, market_id: MarketIdOf, diff --git a/zrml/court/src/lib.rs b/zrml/court/src/lib.rs index 7c5b091c4..6ff3e42b5 100644 --- a/zrml/court/src/lib.rs +++ b/zrml/court/src/lib.rs @@ -101,6 +101,7 @@ mod pallet { #[pallet::call] impl Pallet { // MARK(non-transactional): `remove_juror_from_all_courts_of_all_markets` is infallible. + #[pallet::call_index(0)] #[pallet::weight(T::WeightInfo::exit_court())] pub fn exit_court(origin: OriginFor) -> DispatchResult { let who = ensure_signed(origin)?; @@ -111,6 +112,7 @@ mod pallet { } // MARK(non-transactional): Once `reserve_named` is successful, `insert` won't fail. + #[pallet::call_index(1)] #[pallet::weight(T::WeightInfo::join_court())] pub fn join_court(origin: OriginFor) -> DispatchResult { let who = ensure_signed(origin)?; @@ -128,6 +130,7 @@ mod pallet { } // MARK(non-transactional): No fallible storage operation is performed. + #[pallet::call_index(2)] #[pallet::weight(T::WeightInfo::vote())] pub fn vote( origin: OriginFor, diff --git a/zrml/global-disputes/src/lib.rs b/zrml/global-disputes/src/lib.rs index 14b594ea8..e5968f693 100644 --- a/zrml/global-disputes/src/lib.rs +++ b/zrml/global-disputes/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2022 Forecasting Technologies LTD. +// Copyright 2022-2023 Forecasting Technologies LTD. // // This file is part of Zeitgeist. // @@ -209,8 +209,9 @@ mod pallet { /// /// Complexity: `O(n)`, where `n` is the number of owner(s) of the winner outcome /// in the case that this gets called for an already finished global dispute. - #[frame_support::transactional] + #[pallet::call_index(0)] #[pallet::weight(T::WeightInfo::add_vote_outcome(T::MaxOwners::get()))] + #[frame_support::transactional] pub fn add_vote_outcome( origin: OriginFor, #[pallet::compact] market_id: MarketIdOf, @@ -258,11 +259,12 @@ mod pallet { /// /// Complexity: `O(n)`, /// where `n` is the number of all existing outcomes for a global dispute. - #[frame_support::transactional] + #[pallet::call_index(1)] #[pallet::weight(T::WeightInfo::purge_outcomes( T::RemoveKeysLimit::get(), T::MaxOwners::get(), ))] + #[frame_support::transactional] pub fn purge_outcomes( origin: OriginFor, #[pallet::compact] market_id: MarketIdOf, @@ -314,12 +316,13 @@ mod pallet { /// # Weight /// /// Complexity: `O(n)`, where `n` is the number of owners for the winning outcome. - #[frame_support::transactional] + #[pallet::call_index(2)] #[pallet::weight( T::WeightInfo::reward_outcome_owner_no_funds(T::MaxOwners::get()).max( T::WeightInfo::reward_outcome_owner_with_funds(T::MaxOwners::get()), ) )] + #[frame_support::transactional] pub fn reward_outcome_owner( origin: OriginFor, #[pallet::compact] market_id: MarketIdOf, @@ -396,11 +399,12 @@ mod pallet { /// /// Complexity: `O(n + m)`, where `n` is the number of all current votes on global disputes, /// and `m` is the number of owners for the specified outcome. - #[frame_support::transactional] + #[pallet::call_index(3)] #[pallet::weight(T::WeightInfo::vote_on_outcome( T::MaxOwners::get(), T::MaxGlobalDisputeVotes::get(), ))] + #[frame_support::transactional] pub fn vote_on_outcome( origin: OriginFor, #[pallet::compact] market_id: MarketIdOf, @@ -482,7 +486,7 @@ mod pallet { /// /// Complexity: `O(n + m)`, where `n` is the number of all current votes on global disputes, /// and `m` is the number of owners for the winning outcome. - #[frame_support::transactional] + #[pallet::call_index(4)] #[pallet::weight( T::WeightInfo::unlock_vote_balance_set( T::MaxGlobalDisputeVotes::get(), @@ -493,6 +497,7 @@ mod pallet { T::MaxOwners::get(), )) )] + #[frame_support::transactional] pub fn unlock_vote_balance( origin: OriginFor, voter: AccountIdLookupOf, diff --git a/zrml/liquidity-mining/src/lib.rs b/zrml/liquidity-mining/src/lib.rs index 57d4220a7..b0da46b9b 100644 --- a/zrml/liquidity-mining/src/lib.rs +++ b/zrml/liquidity-mining/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2022 Forecasting Technologies LTD. +// Copyright 2022-2023 Forecasting Technologies LTD. // Copyright 2021-2022 Zeitgeist PM LLC. // // This file is part of Zeitgeist. @@ -87,6 +87,7 @@ mod pallet { #[pallet::call] impl Pallet { + #[pallet::call_index(0)] #[pallet::weight(T::WeightInfo::set_per_block_distribution())] // MARK(non-transactional): `set_per_block_distribution` is infallible. pub fn set_per_block_distribution( diff --git a/zrml/orderbook-v1/src/lib.rs b/zrml/orderbook-v1/src/lib.rs index 3934d1318..ba80157c7 100644 --- a/zrml/orderbook-v1/src/lib.rs +++ b/zrml/orderbook-v1/src/lib.rs @@ -1,3 +1,4 @@ +// Copyright 2022-2023 Forecasting Technologies LTD. // Copyright 2021-2022 Zeitgeist PM LLC. // // This file is part of Zeitgeist. @@ -67,6 +68,7 @@ mod pallet { #[pallet::call] impl Pallet { + #[pallet::call_index(0)] #[pallet::weight( T::WeightInfo::cancel_order_ask().max(T::WeightInfo::cancel_order_bid()) )] @@ -112,6 +114,7 @@ mod pallet { } } + #[pallet::call_index(1)] #[pallet::weight( T::WeightInfo::fill_order_ask().max(T::WeightInfo::fill_order_bid()) )] @@ -178,6 +181,7 @@ mod pallet { } } + #[pallet::call_index(2)] #[pallet::weight( T::WeightInfo::make_order_ask().max(T::WeightInfo::make_order_bid()) )] diff --git a/zrml/prediction-markets/src/lib.rs b/zrml/prediction-markets/src/lib.rs index e4390ed3e..665cb4a78 100644 --- a/zrml/prediction-markets/src/lib.rs +++ b/zrml/prediction-markets/src/lib.rs @@ -303,6 +303,7 @@ mod pallet { /// /// Must be called by `DestroyOrigin`. Bonds (unless already returned) are slashed without /// exception. Can currently only be used for destroying CPMM markets. + #[pallet::call_index(0)] #[pallet::weight(( T::WeightInfo::admin_destroy_reported_market( T::MaxCategories::get().into(), @@ -419,6 +420,7 @@ mod pallet { // // Within the same block, operations that interact with the activeness of the same // market will behave differently before and after this call. + #[pallet::call_index(1)] #[pallet::weight(( T::WeightInfo::admin_move_market_to_closed( CacheSize::get(), CacheSize::get()), Pays::No @@ -452,6 +454,7 @@ mod pallet { /// /// Complexity: `O(n + m)`, where `n` is the number of market ids /// per dispute / report block, m is the number of disputes. + #[pallet::call_index(2)] #[pallet::weight(( T::WeightInfo::admin_move_market_to_resolved_scalar_reported(CacheSize::get()) .max( @@ -512,6 +515,7 @@ mod pallet { /// # Weight /// /// Complexity: `O(1)` + #[pallet::call_index(3)] #[pallet::weight((T::WeightInfo::approve_market(), Pays::No))] #[transactional] pub fn approve_market( @@ -564,6 +568,7 @@ mod pallet { /// # Weight /// /// Complexity: `O(edit_reason.len())` + #[pallet::call_index(4)] #[pallet::weight(( T::WeightInfo::request_edit(edit_reason.len() as u32), Pays::No, @@ -609,6 +614,7 @@ mod pallet { // The worst-case scenario is assumed // and the correct weight is calculated at the end of this function. // This also occurs in numerous other functions. + #[pallet::call_index(5)] #[pallet::weight(T::WeightInfo::buy_complete_set(T::MaxCategories::get().into()))] #[transactional] pub fn buy_complete_set( @@ -625,6 +631,7 @@ mod pallet { /// # Weight /// /// Complexity: `O(n)`, where `n` is the number of outstanding disputes. + #[pallet::call_index(6)] #[pallet::weight(T::WeightInfo::dispute_authorized())] #[transactional] pub fn dispute( @@ -701,6 +708,7 @@ mod pallet { /// where `n` is the number of outcome assets for the categorical market /// and `m` is the number of market ids, /// which open at the same time as the specified market. + #[pallet::call_index(7)] #[pallet::weight( T::WeightInfo::create_market(CacheSize::get()) .saturating_add(T::WeightInfo::buy_complete_set(T::MaxCategories::get().into())) @@ -763,6 +771,7 @@ mod pallet { /// /// Complexity: `O(n)`, where `n` is the number of market ids, /// which close at the same time as the specified market. + #[pallet::call_index(8)] #[pallet::weight(T::WeightInfo::create_market(CacheSize::get()))] #[transactional] pub fn create_market( @@ -851,6 +860,7 @@ mod pallet { /// /// Complexity: `O(n)`, where `n` is the number of markets /// which end at the same time as the market before the edit. + #[pallet::call_index(9)] #[pallet::weight(T::WeightInfo::edit_market(CacheSize::get()))] #[transactional] pub fn edit_market( @@ -927,6 +937,7 @@ mod pallet { /// where `n` is the number of outcome assets for the categorical market, /// and `m` is the number of market ids, /// which open at the same time as the specified market. + #[pallet::call_index(10)] #[pallet::weight( T::WeightInfo::buy_complete_set(T::MaxCategories::get().into()) .saturating_add( @@ -978,6 +989,7 @@ mod pallet { /// where `n` is the number of outcome assets for the categorical market, /// and `m` is the number of market ids, /// which open at the same time as the specified market. + #[pallet::call_index(11)] #[pallet::weight( T::WeightInfo::deploy_swap_pool_for_market_open_pool(weights.len() as u32) .max( @@ -1085,6 +1097,7 @@ mod pallet { /// # Weight /// /// Complexity: `O(1)` + #[pallet::call_index(12)] #[pallet::weight(T::WeightInfo::redeem_shares_categorical() .max(T::WeightInfo::redeem_shares_scalar()) )] @@ -1229,6 +1242,7 @@ mod pallet { /// which open at the same time as the specified market, /// and `m` is the number of market ids, /// which close at the same time as the specified market. + #[pallet::call_index(13)] #[pallet::weight(( T::WeightInfo::reject_market( CacheSize::get(), @@ -1266,6 +1280,7 @@ mod pallet { /// /// Complexity: `O(n)`, where `n` is the number of market ids, /// which reported at the same time as the specified market. + #[pallet::call_index(14)] #[pallet::weight(T::WeightInfo::report(CacheSize::get()))] #[transactional] pub fn report( @@ -1377,6 +1392,7 @@ mod pallet { /// # Weight /// /// Complexity: `O(n)`, where `n` is the number of assets for a categorical market. + #[pallet::call_index(15)] #[pallet::weight( T::WeightInfo::sell_complete_set(T::MaxCategories::get().into()) )] @@ -1434,6 +1450,7 @@ mod pallet { /// The outcomes of the disputes and the report outcome /// are added to the global dispute voting outcomes. /// The bond of each dispute is the initial vote amount. + #[pallet::call_index(16)] #[pallet::weight(T::WeightInfo::start_global_dispute(CacheSize::get(), CacheSize::get()))] #[transactional] pub fn start_global_dispute( diff --git a/zrml/styx/src/lib.rs b/zrml/styx/src/lib.rs index e00713303..ed96c5dca 100644 --- a/zrml/styx/src/lib.rs +++ b/zrml/styx/src/lib.rs @@ -1,3 +1,4 @@ +// Copyright 2022-2023 Forecasting Technologies LTD. // Copyright 2021-2022 Zeitgeist PM LLC. // // This file is part of Zeitgeist. @@ -85,6 +86,7 @@ pub mod pallet { impl Pallet { /// Burns ZTG(styx.burnAmount()) to cross, granting the ability to claim your zeitgeist avatar. /// The signer can only cross once. + #[pallet::call_index(0)] #[pallet::weight(T::WeightInfo::cross())] pub fn cross(origin: OriginFor) -> DispatchResult { let who = ensure_signed(origin)?; @@ -113,6 +115,7 @@ pub mod pallet { /// # Arguments /// /// * `amount`: The amount of the new burn price + #[pallet::call_index(1)] #[pallet::weight(T::WeightInfo::set_burn_amount())] pub fn set_burn_amount( origin: OriginFor, diff --git a/zrml/swaps/src/lib.rs b/zrml/swaps/src/lib.rs index 995c049c7..f9824bc7b 100644 --- a/zrml/swaps/src/lib.rs +++ b/zrml/swaps/src/lib.rs @@ -129,6 +129,7 @@ mod pallet { /// /// Complexity: `O(1)` if the market is scalar, `O(n)` where `n` is the number of /// assets in the pool if the market is categorical. + #[pallet::call_index(0)] #[pallet::weight( T::WeightInfo::admin_clean_up_pool_cpmm_categorical(T::MaxAssets::get() as u32) .max(T::WeightInfo::admin_clean_up_pool_cpmm_scalar()) @@ -184,6 +185,7 @@ mod pallet { // verifying that `min_assets_out` has the correct length. We do limit the linear factor to // the maximum number of assets to prevent unnecessary spending in case of erroneous input, // though. + #[pallet::call_index(1)] #[pallet::weight(T::WeightInfo::pool_exit( min_assets_out.len().min(T::MaxAssets::get().into()) as u32 ))] @@ -245,6 +247,7 @@ mod pallet { /// # Weight /// /// Complexity: O(1) + #[pallet::call_index(2)] #[pallet::weight(T::WeightInfo::pool_exit_subsidy())] #[transactional] pub fn pool_exit_subsidy( @@ -340,6 +343,7 @@ mod pallet { /// # Weight /// /// Complexity: `O(1)` + #[pallet::call_index(3)] #[pallet::weight(T::WeightInfo::pool_exit_with_exact_asset_amount())] // MARK(non-transactional): Immediately calls and returns a transactional. pub fn pool_exit_with_exact_asset_amount( @@ -377,6 +381,7 @@ mod pallet { /// # Weight /// /// Complexity: `O(1)` + #[pallet::call_index(4)] #[pallet::weight(T::WeightInfo::pool_exit_with_exact_pool_amount())] #[transactional] pub fn pool_exit_with_exact_pool_amount( @@ -456,6 +461,7 @@ mod pallet { // verifying that `min_assets_out` has the correct length. We do limit the linear factor to // the maximum number of assets to prevent unnecessary spending in case of erroneous input, // though. + #[pallet::call_index(5)] #[pallet::weight(T::WeightInfo::pool_join( max_assets_in.len().min(T::MaxAssets::get().into()) as u32 ))] @@ -510,6 +516,7 @@ mod pallet { /// # Weight /// /// Complexity: O(1) + #[pallet::call_index(6)] #[pallet::weight(T::WeightInfo::pool_join_subsidy())] #[transactional] pub fn pool_join_subsidy( @@ -580,6 +587,7 @@ mod pallet { /// /// Complexity: O(1) // MARK(non-transactional): Immediately calls and returns a transactional. + #[pallet::call_index(7)] #[pallet::weight(T::WeightInfo::pool_join_with_exact_asset_amount())] pub fn pool_join_with_exact_asset_amount( origin: OriginFor, @@ -616,6 +624,7 @@ mod pallet { /// # Weight /// /// Complexity: `O(1)` + #[pallet::call_index(8)] #[pallet::weight(T::WeightInfo::pool_join_with_exact_pool_amount())] #[transactional] pub fn pool_join_with_exact_pool_amount( @@ -687,6 +696,7 @@ mod pallet { /// Complexity: `O(1)` if the scoring rule is CPMM, `O(n)` where `n` is the amount of /// assets if the scoring rule is Rikiddo. // TODO(#790): Replace with maximum of CPMM and Rikiddo benchmark! + #[pallet::call_index(9)] #[pallet::weight(T::WeightInfo::swap_exact_amount_in_cpmm())] #[transactional] pub fn swap_exact_amount_in( @@ -730,6 +740,7 @@ mod pallet { /// Complexity: `O(1)` if the scoring rule is CPMM, `O(n)` where `n` is the amount of /// assets if the scoring rule is Rikiddo. // TODO(#790): Replace with maximum of CPMM and Rikiddo benchmark! + #[pallet::call_index(10)] #[pallet::weight(T::WeightInfo::swap_exact_amount_out_cpmm())] #[transactional] pub fn swap_exact_amount_out(