Skip to content

Commit

Permalink
Get reference gas price (MystenLabs#10373)
Browse files Browse the repository at this point in the history
## Description 

Use `num_chunks_per_thread` to control how many calls we make per client
per thread

## Test Plan 

How did you test the new or updated feature?

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
wlmyng authored Apr 4, 2023
1 parent 6cac032 commit 77ceb5e
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crates/sui-rpc-loadgen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ cargo run --bin sui-rpc-loadgen -- --urls "http://127.0.0.1:9000" "http://127.0.
cargo run --bin sui-rpc-loadgen -- --urls "http://127.0.0.1:9000" "http://127.0.0.1:9000" --num-threads 4 get-all-balances
```

### Get Reference Gas Price
```bash
cargo run --bin sui-rpc-loadgen -- --urls "http://127.0.0.1:9000" "http://127.0.0.1:9000" --num-threads 4 get-reference-gas-price --num-chunks-per-thread 10
```

# Useful commands

```bash
Expand Down
13 changes: 13 additions & 0 deletions crates/sui-rpc-loadgen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ pub enum ClapCommand {
#[clap(flatten)]
common: CommonOptions,
},
#[clap(name = "get-reference-gas-price")]
GetReferenceGasPrice {
#[clap(flatten)]
common: CommonOptions,
},
}

fn get_keypair() -> Result<SignerInfo> {
Expand Down Expand Up @@ -206,6 +211,14 @@ async fn main() -> Result<(), Box<dyn Error>> {
let objects = load_objects_from_file(expand_path(&opts.data_directory));
(Command::new_multi_get_objects(objects), common, false)
}
ClapCommand::GetReferenceGasPrice { common } => {
let num_repeats = common.num_chunks_per_thread;
(
Command::new_get_reference_gas_price(num_repeats),
common,
false,
)
}
};

let signer_info = need_keystore.then_some(get_keypair()?);
Expand Down
40 changes: 40 additions & 0 deletions crates/sui-rpc-loadgen/src/payload/get_reference_gas_price.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use anyhow::Result;
use futures::future::try_join_all;
use sui_sdk::SuiClient;

use crate::payload::{GetReferenceGasPrice, ProcessPayload, RpcCommandProcessor, SignerInfo};
use async_trait::async_trait;

#[async_trait]
impl<'a> ProcessPayload<'a, &'a GetReferenceGasPrice> for RpcCommandProcessor {
async fn process(
&'a self,
op: &'a GetReferenceGasPrice,
_signer_info: &Option<SignerInfo>,
) -> Result<()> {
let clients = self.get_clients().await?;

let futures = (0..op.num_repeats).map(|_| {
let clients = clients.clone();
async move {
let futures = clients.iter().map(get_reference_gas_price);
try_join_all(futures).await
}
});

try_join_all(futures).await.unwrap();
Ok(())
}
}

async fn get_reference_gas_price(client: &SuiClient) -> Result<u64> {
let results = client
.governance_api()
.get_reference_gas_price()
.await
.unwrap();
Ok(results)
}
15 changes: 15 additions & 0 deletions crates/sui-rpc-loadgen/src/payload/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
mod checkpoint_utils;
mod get_all_balances;
mod get_checkpoints;
mod get_reference_gas_price;
mod multi_get_objects;
mod pay_sui;
mod query_transactions;
Expand Down Expand Up @@ -123,6 +124,14 @@ impl Command {
}
}

pub fn new_get_reference_gas_price(num_repeats: usize) -> Self {
let get_reference_gas_price = GetReferenceGasPrice { num_repeats };
Self {
data: CommandData::GetReferenceGasPrice(get_reference_gas_price),
..Default::default()
}
}

pub fn with_repeat_n_times(mut self, num: usize) -> Self {
self.repeat_n_times = num;
self
Expand All @@ -143,6 +152,7 @@ pub enum CommandData {
QueryTransactionBlocks(QueryTransactionBlocks),
MultiGetObjects(MultiGetObjects),
GetAllBalances(GetAllBalances),
GetReferenceGasPrice(GetReferenceGasPrice),
}

impl Default for CommandData {
Expand Down Expand Up @@ -198,6 +208,11 @@ pub struct GetAllBalances {
pub addresses: Vec<SuiAddress>,
}

#[derive(Clone)]
pub struct GetReferenceGasPrice {
num_repeats: usize,
}

#[async_trait]
pub trait Processor {
/// process commands in order
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ impl RpcCommandProcessor {
CommandData::QueryTransactionBlocks(ref v) => self.process(v, signer_info).await,
CommandData::MultiGetObjects(ref v) => self.process(v, signer_info).await,
CommandData::GetAllBalances(ref v) => self.process(v, signer_info).await,
CommandData::GetReferenceGasPrice(ref v) => self.process(v, signer_info).await,
}
}

Expand Down

0 comments on commit 77ceb5e

Please sign in to comment.