sui_single_node_benchmark/
workload.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use crate::benchmark_context::BenchmarkContext;
5use crate::command::WorkloadKind;
6use crate::tx_generator::{MoveTxGenerator, PackagePublishTxGenerator, TxGenerator};
7use std::path::PathBuf;
8use std::sync::Arc;
9use sui_test_transaction_builder::PublishData;
10
11#[derive(Clone)]
12pub struct Workload {
13    pub tx_count: u64,
14    pub workload_kind: WorkloadKind,
15}
16
17impl Workload {
18    pub fn new(tx_count: u64, workload_kind: WorkloadKind) -> Self {
19        Self {
20            tx_count,
21            workload_kind,
22        }
23    }
24
25    pub(crate) fn num_accounts(&self) -> u64 {
26        self.tx_count
27    }
28
29    pub(crate) fn gas_object_num_per_account(&self) -> u64 {
30        self.workload_kind.gas_object_num_per_account()
31    }
32
33    pub(crate) async fn create_tx_generator(
34        &self,
35        ctx: &mut BenchmarkContext,
36    ) -> Arc<dyn TxGenerator> {
37        match &self.workload_kind {
38            WorkloadKind::PTB {
39                num_transfers,
40                use_native_transfer,
41                num_dynamic_fields,
42                computation,
43                num_shared_objects,
44                num_mints,
45                nft_size,
46                use_batch_mint,
47            } => {
48                let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
49                path.extend(["move_package"]);
50                let move_package = ctx.publish_package(PublishData::Source(path, false)).await;
51                let root_objects = ctx
52                    .preparing_dynamic_fields(move_package.0, *num_dynamic_fields)
53                    .await;
54                let shared_objects = ctx
55                    .prepare_shared_objects(move_package.0, *num_shared_objects)
56                    .await;
57                Arc::new(MoveTxGenerator::new(
58                    move_package.0,
59                    *num_transfers,
60                    *use_native_transfer,
61                    *computation,
62                    root_objects,
63                    shared_objects,
64                    *num_mints,
65                    *nft_size,
66                    *use_batch_mint,
67                ))
68            }
69            WorkloadKind::Publish {
70                manifest_file: manifest_path,
71            } => Arc::new(PackagePublishTxGenerator::new(ctx, manifest_path.clone()).await),
72        }
73    }
74}