From 0613ac2c3a1bcc749cb4f1112e1b923220f76c5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 28 Sep 2023 11:41:55 +0100 Subject: [PATCH 1/4] benches: move bench lib code to apps crate and feature guard it --- apps/Cargo.toml | 3 +- benches/lib.rs => apps/src/lib/bench_utils.rs | 36 +++++++++---------- apps/src/lib/config/genesis.rs | 2 +- apps/src/lib/mod.rs | 2 ++ benches/Cargo.toml | 20 +++++------ benches/native_vps.rs | 4 +-- benches/process_wrapper.rs | 2 +- benches/txs.rs | 4 +-- benches/vps.rs | 4 +-- 9 files changed, 38 insertions(+), 39 deletions(-) rename benches/lib.rs => apps/src/lib/bench_utils.rs (96%) diff --git a/apps/Cargo.toml b/apps/Cargo.toml index 1d33f55df7..06a69e35ea 100644 --- a/apps/Cargo.toml +++ b/apps/Cargo.toml @@ -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", @@ -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"] } diff --git a/benches/lib.rs b/apps/src/lib/bench_utils.rs similarity index 96% rename from benches/lib.rs rename to apps/src/lib/bench_utils.rs index 47645abdf4..f88b92d3c0 100644 --- a/benches/lib.rs +++ b/apps/src/lib/bench_utils.rs @@ -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"; @@ -681,13 +682,12 @@ impl Default for BenchShieldedCtx { fn default() -> Self { let mut shell = BenchShell::default(); - let mut ctx = - Context::new::(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::(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( @@ -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 [ @@ -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, ) diff --git a/apps/src/lib/config/genesis.rs b/apps/src/lib/config/genesis.rs index b7281fd4ce..b70637e0bc 100644 --- a/apps/src/lib/config/genesis.rs +++ b/apps/src/lib/config/genesis.rs @@ -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 @@ -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; diff --git a/apps/src/lib/mod.rs b/apps/src/lib/mod.rs index 7df31ea2ea..b2991870ef 100644 --- a/apps/src/lib/mod.rs +++ b/apps/src/lib/mod.rs @@ -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; diff --git a/benches/Cargo.toml b/benches/Cargo.toml index 91a5d45333..d81dec84c2 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -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 @@ -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"] } diff --git a/benches/native_vps.rs b/benches/native_vps.rs index 77373080c4..2c317455dd 100644 --- a/benches/native_vps.rs +++ b/benches/native_vps.rs @@ -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 diff --git a/benches/process_wrapper.rs b/benches/process_wrapper.rs index ce466b1058..d6fbe9b483 100644 --- a/benches/process_wrapper.rs +++ b/benches/process_wrapper.rs @@ -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(); diff --git a/benches/txs.rs b/benches/txs.rs index a1373c7931..65f702bc43 100644 --- a/benches/txs.rs +++ b/benches/txs.rs @@ -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; diff --git a/benches/vps.rs b/benches/vps.rs index 6efaf78e4c..5e5d66d8dd 100644 --- a/benches/vps.rs +++ b/benches/vps.rs @@ -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"; From 4dc0304d2f38ac49c0779000f61b77baf6eecece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 28 Sep 2023 11:47:34 +0100 Subject: [PATCH 2/4] benches: update docs --- apps/src/lib/bench_utils.rs | 17 ++--------------- benches/README.md | 10 ++++++++++ 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/apps/src/lib/bench_utils.rs b/apps/src/lib/bench_utils.rs index f88b92d3c0..2bffe656ee 100644 --- a/apps/src/lib/bench_utils.rs +++ b/apps/src/lib/bench_utils.rs @@ -1,18 +1,5 @@ -//! Benchmarks module based on criterion. -//! -//! Measurements are taken on the elapsed wall-time. -//! -//! The benchmarks only focus on sucessfull transactions and vps: in case of -//! failure, the bench function shall panic to avoid timing incomplete execution -//! paths. -//! -//! In addition, this module also contains benchmarks for -//! [`WrapperTx`][`namada::core::types::transaction::wrapper::WrapperTx`] -//! validation and [`host_env`][`namada::vm::host_env`] exposed functions that -//! define the gas constants of [`gas`][`namada::core::ledger::gas`]. -//! -//! For more realistic results these benchmarks should be run on all the -//! combination of supported OS/architecture. +//! Library code for benchmarks provides a wrapper of the ledger's shell +//! `BenchShell` and helper functions to generate transactions. use std::fs::{File, OpenOptions}; use std::io::{Read, Write}; diff --git a/benches/README.md b/benches/README.md index 02b0d52a91..86978eb6f7 100644 --- a/benches/README.md +++ b/benches/README.md @@ -2,6 +2,16 @@ The benchmarks are built with [criterion.rs](https://bheisler.github.io/criterion.rs/book). +Measurements are taken on the elapsed wall-time. + +The benchmarks only focus on sucessfull transactions and vps: in case of failure, the bench function shall panic to avoid timing incomplete execution paths. + +In addition, this crate also contains benchmarks for `WrapperTx` (`namada::core::types::transaction::wrapper::WrapperTx`) validation and `host_env` (`namada::vm::host_env`) exposed functions that define the gas constants of `gas` (`namada::core::ledger::gas`). + +For more realistic results these benchmarks should be run on all the combination of supported OS/architecture. + +## Testing & running + To enable tracing logs, run with e.g. `RUST_LOG=debug`. To ensure that the benches can run successfully without performing measurement, you can run `make test-benches` from the workspace run. From 5aaa83e6a8d3d520df244c7947d6f188c6c485c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 28 Sep 2023 11:53:14 +0100 Subject: [PATCH 3/4] benches: rm unused deps --- Cargo.lock | 8 -------- benches/Cargo.toml | 8 -------- 2 files changed, 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 84cbd6f48e..92f191c816 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4167,22 +4167,14 @@ dependencies = [ name = "namada_benchmarks" version = "0.23.0" dependencies = [ - "async-trait", "borsh 0.9.4", "criterion", "ferveo-common", - "masp_primitives", - "masp_proofs", "namada", "namada_apps", - "namada_test_utils", - "prost", "rand 0.8.5", "rand_core 0.6.4", "sha2 0.9.9", - "tempfile", - "tokio", - "tracing-subscriber 0.3.17", ] [[package]] diff --git a/benches/Cargo.toml b/benches/Cargo.toml index d81dec84c2..fc4c3485a6 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -42,17 +42,9 @@ path = "host_env.rs" [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 -prost.workspace = true rand_core.workspace = true rand.workspace = true sha2.workspace = true -tempfile.workspace = true -tokio.workspace = true -tracing-subscriber = { workspace = true, features = ["std"]} From bc2e2859ed66796e664f6899d5bcc5608c741c37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 28 Sep 2023 12:16:33 +0100 Subject: [PATCH 4/4] changelog: add #1955 --- .../improvements/1955-avoid-testing-feature-in-workspace.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/unreleased/improvements/1955-avoid-testing-feature-in-workspace.md diff --git a/.changelog/unreleased/improvements/1955-avoid-testing-feature-in-workspace.md b/.changelog/unreleased/improvements/1955-avoid-testing-feature-in-workspace.md new file mode 100644 index 0000000000..7ce5c574b2 --- /dev/null +++ b/.changelog/unreleased/improvements/1955-avoid-testing-feature-in-workspace.md @@ -0,0 +1,3 @@ +- Refactor benchmarks to avoid enabling `"testing`" and `"dev"`` features by + default in the workspace. + ([\#1955](https://github.com/anoma/namada/pull/1955)) \ No newline at end of file