Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid enabling "testing" feature in workspace from benches #1955

Merged
merged 4 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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))
8 changes: 0 additions & 8 deletions Cargo.lock

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

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
53 changes: 20 additions & 33 deletions benches/lib.rs → apps/src/lib/bench_utils.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -91,20 +78,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 +669,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 +687,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 +719,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
24 changes: 6 additions & 18 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,13 @@ harness = false
path = "host_env.rs"

[dependencies]
async-trait.workspace = true
borsh.workspace = true
ferveo-common.workspace = true
masp_primitives.workspace = true
masp_proofs.workspace = true

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

[dev-dependencies]
criterion = { version = "0.5", features = ["html_reports"] }
10 changes: 10 additions & 0 deletions benches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
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