Skip to content

Commit

Permalink
benches: move bench lib code to apps crate and feature guard it
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Sep 28, 2023
1 parent 8635da4 commit 0613ac2
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 39 deletions.
3 changes: 2 additions & 1 deletion apps/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ mainnet = [
dev = ["namada/dev"]
std = ["ed25519-consensus/std", "rand/std", "rand_core/std", "namada/std"]
# for integration tests and test utilies
testing = ["dev"]
testing = ["dev", "namada_test_utils"]

abciplus = [
"namada/abciplus",
Expand All @@ -67,6 +67,7 @@ abciplus = [

[dependencies]
namada = {path = "../shared", features = ["ferveo-tpke", "masp-tx-gen", "multicore", "http-client"]}
namada_test_utils = {path = "../test_utils", optional = true}
ark-serialize.workspace = true
ark-std.workspace = true
arse-merkle-tree = { workspace = true, features = ["blake2b"] }
Expand Down
36 changes: 18 additions & 18 deletions benches/lib.rs → apps/src/lib/bench_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,21 @@ use namada::types::transaction::governance::InitProposalData;
use namada::types::transaction::pos::Bond;
use namada::types::transaction::GasLimit;
use namada::vm::wasm::run;
use namada_apps::cli::args::{Tx as TxArgs, TxTransfer};
use namada_apps::cli::context::FromContext;
use namada_apps::cli::Context;
use namada_apps::config::TendermintMode;
use namada_apps::facade::tendermint_proto::abci::RequestInitChain;
use namada_apps::facade::tendermint_proto::google::protobuf::Timestamp;
use namada_apps::node::ledger::shell::Shell;
use namada_apps::wallet::{defaults, CliWalletUtils};
use namada_apps::{config, wasm_loader};
use namada_test_utils::tx_data::TxWriteData;
use rand_core::OsRng;
use sha2::{Digest, Sha256};
use tempfile::TempDir;

use crate::cli::args::{Tx as TxArgs, TxTransfer};
use crate::cli::context::FromContext;
use crate::cli::Context;
use crate::config::TendermintMode;
use crate::facade::tendermint_proto::abci::RequestInitChain;
use crate::facade::tendermint_proto::google::protobuf::Timestamp;
use crate::node::ledger::shell::Shell;
use crate::wallet::{defaults, CliWalletUtils};
use crate::{config, wasm_loader};

pub const WASM_DIR: &str = "../wasm";
pub const TX_BOND_WASM: &str = "tx_bond.wasm";
pub const TX_TRANSFER_WASM: &str = "tx_transfer.wasm";
Expand Down Expand Up @@ -681,13 +682,12 @@ impl Default for BenchShieldedCtx {
fn default() -> Self {
let mut shell = BenchShell::default();

let mut ctx =
Context::new::<DefaultIo>(namada_apps::cli::args::Global {
chain_id: None,
base_dir: shell.tempdir.as_ref().canonicalize().unwrap(),
wasm_dir: Some(WASM_DIR.into()),
})
.unwrap();
let mut ctx = Context::new::<DefaultIo>(crate::cli::args::Global {
chain_id: None,
base_dir: shell.tempdir.as_ref().canonicalize().unwrap(),
wasm_dir: Some(WASM_DIR.into()),
})
.unwrap();

// Generate spending key for Albert and Bertha
ctx.wallet.gen_spending_key(
Expand All @@ -700,7 +700,7 @@ impl Default for BenchShieldedCtx {
None,
true,
);
namada_apps::wallet::save(&ctx.wallet).unwrap();
crate::wallet::save(&ctx.wallet).unwrap();

// Generate payment addresses for both Albert and Bertha
for (alias, viewing_alias) in [
Expand Down Expand Up @@ -732,7 +732,7 @@ impl Default for BenchShieldedCtx {
.unwrap();
}

namada_apps::wallet::save(&ctx.wallet).unwrap();
crate::wallet::save(&ctx.wallet).unwrap();
namada::ledger::storage::update_allowed_conversions(
&mut shell.wl_storage,
)
Expand Down
2 changes: 1 addition & 1 deletion apps/src/lib/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use namada::types::key::dkg_session_keys::DkgPublicKey;
use namada::types::key::*;
use namada::types::time::{DateTimeUtc, DurationSecs};
use namada::types::token::Denomination;
use namada::types::uint::Uint;
use namada::types::{storage, token};

/// Genesis configuration file format
Expand Down Expand Up @@ -908,6 +907,7 @@ pub fn genesis(num_validators: u64) -> Genesis {
};
use namada::types::ethereum_events::testing::DAI_ERC20_ETH_ADDRESS;
use namada::types::ethereum_events::EthAddress;
use namada::types::uint::Uint;

use crate::wallet;

Expand Down
2 changes: 2 additions & 0 deletions apps/src/lib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#![deny(rustdoc::broken_intra_doc_links)]
#![deny(rustdoc::private_intra_doc_links)]

#[cfg(feature = "testing")]
pub mod bench_utils;
pub mod cli;
pub mod client;
pub mod config;
Expand Down
20 changes: 8 additions & 12 deletions benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ readme.workspace = true
repository.workspace = true
version.workspace = true

[lib]
name = "namada_benches"
path = "lib.rs"

[[bench]]
name = "whitelisted_txs"
harness = false
Expand All @@ -42,21 +38,21 @@ harness = false
path = "host_env.rs"

[dependencies]

[dev-dependencies]
namada = { path = "../shared", features = ["testing"] }
namada_apps = { path = "../apps", features = ["testing"] }
namada_test_utils = { path = "../test_utils" }
async-trait.workspace = true
borsh.workspace = true
criterion = { version = "0.5", features = ["html_reports"] }
ferveo-common.workspace = true
masp_primitives.workspace = true
masp_proofs.workspace = true
namada = { path = "../shared", features = ["testing"] }
namada_apps = { path = "../apps", features = ["testing"] }
namada_test_utils = { path = "../test_utils" }
prost.workspace = true
rand.workspace = true
rand_core.workspace = true
rand.workspace = true
sha2.workspace = true
tokio.workspace = true
tempfile.workspace = true
tokio.workspace = true
tracing-subscriber = { workspace = true, features = ["std"]}

[dev-dependencies]
criterion = { version = "0.5", features = ["html_reports"] }
4 changes: 2 additions & 2 deletions benches/native_vps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ use namada::types::storage::{Epoch, TxIndex};
use namada::types::transaction::governance::{
InitProposalData, VoteProposalData,
};
use namada_apps::wallet::defaults;
use namada_benches::{
use namada_apps::bench_utils::{
generate_foreign_key_tx, generate_ibc_transfer_tx, generate_ibc_tx,
generate_tx, BenchShell, TX_IBC_WASM, TX_INIT_PROPOSAL_WASM,
TX_TRANSFER_WASM, TX_VOTE_PROPOSAL_WASM,
};
use namada_apps::wallet::defaults;

fn replay_protection(c: &mut Criterion) {
// Write a random key under the replay protection subspace
Expand Down
2 changes: 1 addition & 1 deletion benches/process_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use namada::types::key::RefTo;
use namada::types::storage::BlockHeight;
use namada::types::time::DateTimeUtc;
use namada::types::transaction::{Fee, WrapperTx};
use namada_apps::bench_utils::{generate_tx, BenchShell, TX_TRANSFER_WASM};
use namada_apps::node::ledger::shell::process_proposal::ValidationMeta;
use namada_apps::wallet::defaults;
use namada_benches::{generate_tx, BenchShell, TX_TRANSFER_WASM};

fn process_tx(c: &mut Criterion) {
let mut shell = BenchShell::default();
Expand Down
4 changes: 2 additions & 2 deletions benches/txs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ use namada::types::transaction::governance::{
};
use namada::types::transaction::pos::{Bond, CommissionChange, Withdraw};
use namada::types::transaction::EllipticCurve;
use namada_apps::wallet::defaults;
use namada_benches::{
use namada_apps::bench_utils::{
generate_ibc_transfer_tx, generate_tx, BenchShell, BenchShieldedCtx,
ALBERT_PAYMENT_ADDRESS, ALBERT_SPENDING_KEY, BERTHA_PAYMENT_ADDRESS,
TX_BOND_WASM, TX_CHANGE_VALIDATOR_COMMISSION_WASM, TX_INIT_PROPOSAL_WASM,
TX_REVEAL_PK_WASM, TX_UNBOND_WASM, TX_UNJAIL_VALIDATOR_WASM,
TX_UPDATE_ACCOUNT_WASM, TX_VOTE_PROPOSAL_WASM, VP_VALIDATOR_WASM,
};
use namada_apps::wallet::defaults;
use rand::rngs::StdRng;
use rand::SeedableRng;
use sha2::Digest;
Expand Down
4 changes: 2 additions & 2 deletions benches/vps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ use namada::types::storage::{Key, TxIndex};
use namada::types::transaction::governance::VoteProposalData;
use namada::types::transaction::pos::{Bond, CommissionChange};
use namada::vm::wasm::run;
use namada_apps::wallet::defaults;
use namada_benches::{
use namada_apps::bench_utils::{
generate_foreign_key_tx, generate_tx, BenchShell, BenchShieldedCtx,
ALBERT_PAYMENT_ADDRESS, ALBERT_SPENDING_KEY, BERTHA_PAYMENT_ADDRESS,
TX_BOND_WASM, TX_CHANGE_VALIDATOR_COMMISSION_WASM, TX_REVEAL_PK_WASM,
TX_TRANSFER_WASM, TX_UNBOND_WASM, TX_UPDATE_ACCOUNT_WASM,
TX_VOTE_PROPOSAL_WASM, VP_VALIDATOR_WASM,
};
use namada_apps::wallet::defaults;
use sha2::Digest;

const VP_USER_WASM: &str = "vp_user.wasm";
Expand Down

0 comments on commit 0613ac2

Please sign in to comment.