Skip to content

Commit

Permalink
Benchmark combinatorial-tokens (#1387)
Browse files Browse the repository at this point in the history
* Expose benchmarking parameter

* Add security notes to code

* Update and test `TokenMerged` event

* Implement `TokenRedeemed` event

* Test `TokenRedeemed` event

* Add `CombinatorialTokensBenchmarkHelper`

* Implement `redeem_position` benchmark

* Implement first benchmarks, prediction markets benchmark helper

* Clear up errors

* Include benchmarks

* Extend tests

* Implement more benchmarks

* .

* .

* Use weight in `redeem_position`

* .

* .

* .

* First split bench

* Horizontal splits benchmarked

* .

* .

* .
  • Loading branch information
maltekliemann authored Oct 24, 2024
1 parent 3bda745 commit 2660096
Show file tree
Hide file tree
Showing 18 changed files with 1,271 additions and 80 deletions.
2 changes: 2 additions & 0 deletions primitives/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// You should have received a copy of the GNU General Public License
// along with Zeitgeist. If not, see <https://www.gnu.org/licenses/>.

mod combinatorial_tokens_benchmark_helper;
mod complete_set_operations_api;
mod deploy_pool_api;
mod dispute_api;
Expand All @@ -31,6 +32,7 @@ mod payout_api;
mod swaps;
mod zeitgeist_asset;

pub use combinatorial_tokens_benchmark_helper::*;
pub use complete_set_operations_api::*;
pub use deploy_pool_api::*;
pub use dispute_api::*;
Expand Down
13 changes: 13 additions & 0 deletions primitives/src/traits/combinatorial_tokens_benchmark_helper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use alloc::vec::Vec;
use sp_runtime::DispatchResult;

pub trait CombinatorialTokensBenchmarkHelper {
type Balance;
type MarketId;

/// Prepares the market with the specified `market_id` to have a particular `payout`.
fn setup_payout_vector(
market_id: Self::MarketId,
payout: Option<Vec<Self::Balance>>,
) -> DispatchResult;
}
8 changes: 8 additions & 0 deletions runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ macro_rules! decl_common_types {
#[cfg(feature = "runtime-benchmarks")]
use zrml_neo_swaps::types::DecisionMarketBenchmarkHelper;

#[cfg(feature = "runtime-benchmarks")]
use zrml_prediction_markets::types::PredictionMarketsCombinatorialTokensBenchmarkHelper;

pub type Block = generic::Block<Header, UncheckedExtrinsic>;

type Address = sp_runtime::MultiAddress<AccountId, ()>;
Expand Down Expand Up @@ -1154,12 +1157,15 @@ macro_rules! impl_config_traits {
}

impl zrml_combinatorial_tokens::Config for Runtime {
#[cfg(feature = "runtime-benchmarks")]
type BenchmarkHelper = PredictionMarketsCombinatorialTokensBenchmarkHelper<Runtime>;
type CombinatorialIdManager = CryptographicIdManager<MarketId, Blake2_256>;
type MarketCommons = MarketCommons;
type MultiCurrency = AssetManager;
type Payout = PredictionMarkets;
type RuntimeEvent = RuntimeEvent;
type PalletId = CombinatorialTokensPalletId;
type WeightInfo = zrml_combinatorial_tokens::weights::WeightInfo<Runtime>;
}

impl zrml_court::Config for Runtime {
Expand Down Expand Up @@ -1453,6 +1459,7 @@ macro_rules! create_runtime_api {
list_benchmark!(list, extra, pallet_vesting, Vesting);
list_benchmark!(list, extra, zrml_swaps, Swaps);
list_benchmark!(list, extra, zrml_authorized, Authorized);
list_benchmark!(list, extra, zrml_combinatorial_tokens, CombinatorialTokens);
list_benchmark!(list, extra, zrml_court, Court);
list_benchmark!(list, extra, zrml_futarchy, Futarchy);
list_benchmark!(list, extra, zrml_global_disputes, GlobalDisputes);
Expand Down Expand Up @@ -1543,6 +1550,7 @@ macro_rules! create_runtime_api {
add_benchmark!(params, batches, pallet_vesting, Vesting);
add_benchmark!(params, batches, zrml_swaps, Swaps);
add_benchmark!(params, batches, zrml_authorized, Authorized);
add_benchmark!(params, batches, zrml_combinatorial_tokens, CombinatorialTokens);
add_benchmark!(params, batches, zrml_court, Court);
add_benchmark!(params, batches, zrml_futarchy, Futarchy);
add_benchmark!(params, batches, zrml_global_disputes, GlobalDisputes);
Expand Down
5 changes: 3 additions & 2 deletions scripts/benchmarks/configuration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ export ORML_PALLETS_STEPS="${ORML_PALLETS_STEPS:-50}"
export ORML_WEIGHT_TEMPLATE="./misc/orml_weight_template.hbs"

export ZEITGEIST_PALLETS=(
zrml_authorized zrml_court zrml_futarchy zrml_global_disputes zrml_hybrid_router \
zrml_neo_swaps zrml_orderbook zrml_parimutuel zrml_prediction_markets zrml_swaps zrml_styx \
zrml_authorized zrml_combinatorial_tokens zrml_court zrml_futarchy zrml_global_disputes \
zrml_hybrid_router zrml_neo_swaps zrml_orderbook zrml_parimutuel zrml_prediction_markets \
zrml_swaps zrml_styx \
)
export ZEITGEIST_PALLETS_RUNS="${ZEITGEIST_PALLETS_RUNS:-20}"
export ZEITGEIST_PALLETS_STEPS="${ZEITGEIST_PALLETS_STEPS:-50}"
Expand Down
Loading

0 comments on commit 2660096

Please sign in to comment.