Skip to content

Commit

Permalink
Add statelessnet support, beautify list output
Browse files Browse the repository at this point in the history
  • Loading branch information
telezhnaya committed May 29, 2024
1 parent 9c04438 commit b5b506f
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 20 deletions.
46 changes: 35 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ humantime = "2.1.0"
prometheus-client = "0.22.2"
regex = "1.10.4"
serde_json = "1.0.115"
strum = { version = "0.26.2", features = ["derive"] }
thiserror = "1.0.58"
tokio = { version = "1.37.0", features = ["rt-multi-thread", "tokio-macros", "parking_lot", "signal", "process"] }
tower-http = { version = "0.5.2", features = ["timeout"] }
Expand All @@ -26,6 +27,7 @@ near-crypto = "0.21.2"
near-jsonrpc-client = "0.9.0"
near-jsonrpc-primitives = "0.21.2"
near-primitives = "0.21.2"
strum_macros = "0.26.2"

[dev-dependencies]
more-asserts = "0.3.1"
3 changes: 2 additions & 1 deletion src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ async fn list(engine: Engine) -> anyhow::Result<()> {
}

async fn test(opts: Opts, engine: Engine) -> anyhow::Result<()> {
info!("running selected transactions: {:?}", opts.transaction_kind);
let rpc_client = JsonRpcClient::connect(&opts.rpc_url);
for (kind, tx) in engine.transactions() {
if *kind == opts.transaction_kind {
if opts.transaction_kind.contains(kind) {
info!("executing transaction {} for {}", tx.kind(), opts.signer_id);
let outcome = tx.execute(&rpc_client, opts.clone()).await?;
info!(
Expand Down
8 changes: 4 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use std::net::SocketAddr;

#[derive(clap::ValueEnum, Debug, Clone, Subcommand)]
pub enum Mode {
/// Run all transactions continuously.
/// Run selected transactions continuously.
Run,
/// Display the available transaction types.
List,
/// Run a single transaction once.
/// Run selected transactions once.
Test,
}

Expand Down Expand Up @@ -53,8 +53,8 @@ pub struct Opts {
#[clap(long, env)]
pub pool_id: u32,
/// Transaction kind
#[clap(long, env, value_enum, default_value = "token-transfer-default")]
pub transaction_kind: TransactionKind,
#[clap(long, env, value_delimiter = ',')]
pub transaction_kind: Vec<TransactionKind>,
/// Number of times each transaction is performed at every benchmarking run
#[clap(long, env, default_value_t = 1)]
pub repeats_number: u32,
Expand Down
9 changes: 7 additions & 2 deletions src/transaction/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Engine {
}

async fn run_all_once(&self, opts: Opts, metrics: &Arc<Metrics>) {
info!("running all transactions");
info!("running selected transactions: {:?}", opts.transaction_kind);
let mut tasks = JoinSet::new();
let metrics = metrics.clone();
let transactions = self.transactions.clone();
Expand All @@ -108,13 +108,18 @@ async fn run_account_transactions_once(
"mainnet"
} else if opts.rpc_url.contains("testnet") {
"testnet"
} else if opts.rpc_url.contains("statelessnet") {
"statelessnet"
} else {
"localnet"
};

let rpc_client = JsonRpcClient::connect(&opts.rpc_url);

for (kind, tx_sample) in transactions {
if !opts.transaction_kind.is_empty() && !opts.transaction_kind.contains(&kind) {
continue;
}
let labels = Labels::new(kind.to_string(), network.to_string(), opts.location.clone());
metrics.attempted_transactions.get_or_create(&labels).inc();
for i in 0..opts.repeats_number {
Expand Down Expand Up @@ -264,7 +269,7 @@ mod tests {
ft_account_id: "bear.near".parse().unwrap(),
exchange_id: "flamingo.near".parse().unwrap(),
pool_id: 0,
transaction_kind: TransactionKind::TokenTransferDefault,
transaction_kind: vec![],
period: Duration::from_millis(1),
metric_server_address: SocketAddr::from_str("0.0.0.0:9000").unwrap(),
location: LOCATION.to_string(),
Expand Down
5 changes: 3 additions & 2 deletions src/transaction/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use async_trait::async_trait;
use derive_more::{Display, From};
use near_crypto::InMemorySigner;
use near_jsonrpc_client::{methods, JsonRpcClient};
use near_jsonrpc_primitives::types::query::QueryResponseKind;
use near_jsonrpc_primitives::types::transactions::RpcSendTransactionRequest;
use near_primitives::hash::CryptoHash;
use near_primitives::types::{BlockReference, Nonce};
use std::time::Duration;
use strum_macros::Display;
use tokio::time::Instant;
use tracing::{debug, warn};

Expand All @@ -20,7 +20,8 @@ mod token_transfer_default;
mod token_transfer_final;
mod token_transfer_included_final;

#[derive(clap::ValueEnum, Debug, PartialEq, Eq, Hash, Display, From, Clone)]
#[derive(clap::ValueEnum, Debug, PartialEq, Eq, Hash, Display, Clone)]
#[strum(serialize_all = "kebab-case")]
pub enum TransactionKind {
TokenTransferDefault,
TokenTransferIncludedFinal,
Expand Down

0 comments on commit b5b506f

Please sign in to comment.