Skip to content

Commit

Permalink
transaction-emitter: move TxnEmitter into its own crate for easier reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill authored and bors-libra committed Nov 5, 2021
1 parent 3848eef commit ab4d9c1
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 28 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ members = [
"consensus",
"consensus/consensus-types",
"consensus/safety-rules",
"crates/transaction-emitter",
"crypto/crypto",
"crypto/crypto-derive",
"devtools/x",
Expand Down
21 changes: 21 additions & 0 deletions crates/transaction-emitter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "transaction-emitter"
version = "0.0.0"
authors = ["Diem Association <[email protected]>"]
repository = "https://github.com/diem/diem"
homepage = "https://diem.com"
license = "Apache-2.0"
publish = false
edition = "2021"

[dependencies]
anyhow = { version = "1.0", features = ["backtrace"] }
futures = "0.3.12"
itertools = "0.10.0"
rand = "0.8.3"
rand_core = "0.6.2"
tokio = { version = "1.8.1", features = ["full"] }

diem-logger = { path = "../../common/logger" }
diem-sdk = { path = "../../sdk" }
diem-workspace-hack = { path = "../../common/workspace-hack" }
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0

use crate::ChainInfo;
use anyhow::{anyhow, format_err, Context, Result};
use diem_logger::*;
use diem_sdk::{
Expand Down Expand Up @@ -245,22 +244,28 @@ impl SubmissionWorker {
}

#[derive(Debug)]
pub struct TxnEmitter<'t> {
pub struct TxnEmitter<'t, 'd> {
accounts: Vec<LocalAccount>,
txn_factory: TransactionFactory,
chain_info: ChainInfo<'t>,
treasury_compliance_account: &'t mut LocalAccount,
designated_dealer_account: &'d mut LocalAccount,
client: JsonRpcClient,
rng: ::rand::rngs::StdRng,
}

impl<'t> TxnEmitter<'t> {
pub fn new(chain_info: ChainInfo<'t>, rng: ::rand::rngs::StdRng) -> Self {
let txn_factory = TransactionFactory::new(chain_info.chain_id());
let client = JsonRpcClient::new(chain_info.json_rpc());
impl<'t, 'd> TxnEmitter<'t, 'd> {
pub fn new(
treasury_compliance_account: &'t mut LocalAccount,
designated_dealer_account: &'d mut LocalAccount,
client: JsonRpcClient,
transaction_factory: TransactionFactory,
rng: ::rand::rngs::StdRng,
) -> Self {
Self {
accounts: vec![],
txn_factory,
chain_info,
txn_factory: transaction_factory,
treasury_compliance_account,
designated_dealer_account,
client,
rng,
}
Expand All @@ -277,7 +282,7 @@ impl<'t> TxnEmitter<'t> {
pub async fn get_money_source(&mut self, coins_total: u64) -> Result<&mut LocalAccount> {
let client = self.client.clone();
println!("Creating and minting faucet account");
let mut faucet_account = &mut self.chain_info.designated_dealer_account;
let mut faucet_account = &mut self.designated_dealer_account;
let mint_txn = gen_transfer_txn_request(
faucet_account,
&faucet_account.address(),
Expand Down Expand Up @@ -313,7 +318,7 @@ impl<'t> TxnEmitter<'t> {
let client = self.pick_mint_client(json_rpc_clients).clone();
let batch_size = min(MAX_TXN_BATCH_SIZE, seed_account_num - i);
let mut batch = gen_random_accounts(batch_size, self.rng());
let creation_account = &mut self.chain_info.treasury_compliance_account;
let creation_account = &mut self.treasury_compliance_account;
let txn_factory = &self.txn_factory;
let create_requests = batch
.iter()
Expand Down
27 changes: 14 additions & 13 deletions testsuite/forge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,38 @@ edition = "2018"

[dependencies]
anyhow = { version = "1.0", features = ["backtrace"] }
base64 = "0.13.0"
futures = "0.3.12"
hyper-proxy = "0.9.1"
hyper = { version = "0.14.4", features = ["full"] }
hyper-proxy = "0.9.1"
hyper-tls = "0.5.0"
itertools = "0.10.0"
k8s-openapi = { version = "0.11.0", default-features = false, features = ["v1_15"] }
kube = "0.51.0"
rand = "0.8.3"
rand_core = "0.6.2"
rayon = "1.5.0"
regex = "1.4.3"
reqwest = { version = "0.11.2", features = ["blocking", "json"] }
rusoto_core = "0.46.0"
rusoto_credential = "0.46.0"
rusoto_eks = "0.46.0"
rusoto_sts = "0.46.0"
rusoto_credential = "0.46.0"
serde = { version = "1.0.124", features = ["derive"] }
serde_json = "1.0.64"
structopt = "0.3.21"
tempfile = "3.2.0"
termcolor = "1.1.2"
tokio = { version = "1.8.1", features = ["full"] }
reqwest = { version = "0.11.2", features = ["blocking", "json"] }
rand_core = "0.6.2"
serde = { version = "1.0.124", features = ["derive"] }
serde_json = "1.0.64"
url = "2.2.2"
tempfile = "3.2.0"

diem-sdk = { path = "../../sdk" }
debug-interface = { path = "../../common/debug-interface" }
diem-logger = { path = "../../common/logger" }
diem-config = { path = "../../config" }
diem-workspace-hack = { path = "../../common/workspace-hack" }
diem-framework-releases = { path = "../../diem-move/diem-framework/DPN/releases" }
diem-genesis-tool = { path = "../../config/management/genesis" }
diem-logger = { path = "../../common/logger" }
diem-retrier = { path = "../../common/retrier" }
diem-sdk = { path = "../../sdk" }
diem-secure-storage = { path = "../../secure/storage" }
base64 = "0.13.0"
kube = "0.51.0"
k8s-openapi = { version = "0.11.0", default-features = false, features = ["v1_15"] }
diem-workspace-hack = { path = "../../common/workspace-hack" }
transaction-emitter = { path = "../../crates/transaction-emitter" }
3 changes: 1 addition & 2 deletions testsuite/forge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ pub use runner::*;
mod backend;
pub use backend::*;

mod txn_emitter;
pub use txn_emitter::*;
pub use transaction_emitter::*;

mod report;
pub use report::*;
Expand Down
14 changes: 12 additions & 2 deletions testsuite/testcases/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ pub mod gas_price_test;
pub mod partial_nodes_down_test;
pub mod performance_test;

use diem_sdk::types::PeerId;
use diem_sdk::{
client::Client as JsonRpcClient, transaction_builder::TransactionFactory, types::PeerId,
};
use forge::{EmitJobRequest, NetworkContext, NodeExt, Result, TxnEmitter, TxnStats, Version};
use rand::SeedableRng;
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -49,7 +51,15 @@ pub fn generate_traffic<'t>(
.filter(|v| validators.contains(&v.peer_id()))
.map(|n| n.async_json_rpc_client())
.collect::<Vec<_>>();
let mut emitter = TxnEmitter::new(ctx.swarm().chain_info(), rng);
let chain_info = ctx.swarm().chain_info();
let transaction_factory = TransactionFactory::new(chain_info.chain_id);
let mut emitter = TxnEmitter::new(
chain_info.treasury_compliance_account,
chain_info.designated_dealer_account,
JsonRpcClient::new(&chain_info.json_rpc_url),
transaction_factory,
rng,
);
let emit_job_request = match fixed_tps {
Some(tps) => EmitJobRequest::fixed_tps(validator_clients, tps, gas_price),
None => EmitJobRequest::default(validator_clients, gas_price),
Expand Down
1 change: 1 addition & 0 deletions x.toml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ members = [
"socket-bench-server",
"state-sync-v2", # Will be removed once state sync v2 is plugged into diem-node.
"test-generation",
"transaction-emitter",
"x",
"x-core",
"x-lint",
Expand Down

0 comments on commit ab4d9c1

Please sign in to comment.