Skip to content

Commit

Permalink
Merge branch 'tomas/avoid-testing-feature-in-workspace' (#1955)
Browse files Browse the repository at this point in the history
* origin/tomas/avoid-testing-feature-in-workspace:
  changelog: add #1955
  benches: rm unused deps
  benches: update docs
  benches: move bench lib code to apps crate and feature guard it
  • Loading branch information
tzemanovic committed Oct 24, 2023
2 parents 1fd4d7c + bc2e285 commit 000c731
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 63 deletions.
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))
9 changes: 0 additions & 9 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", "namada_sdk/std"]
# for integration tests and test utilies
testing = ["dev"]
testing = ["dev", "namada_test_utils"]

abciplus = [
"namada/abciplus",
Expand All @@ -68,6 +68,7 @@ abciplus = [
[dependencies]
namada = {path = "../shared", features = ["ferveo-tpke", "masp-tx-gen", "multicore", "http-client"]}
namada_sdk = {path = "../sdk", default-features = false, features = ["wasm-runtime", "masp-tx-gen"]}
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
40 changes: 14 additions & 26 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 @@ -87,14 +74,6 @@ use namada::types::token::DenominatedAmount;
use namada::types::transaction::governance::InitProposalData;
use namada::types::transaction::pos::Bond;
use namada::vm::wasm::run;
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_sdk::masp::{
self, ShieldedContext, ShieldedTransfer, ShieldedUtils,
};
Expand All @@ -105,6 +84,15 @@ use rand_core::OsRng;
use sha2::{Digest, Sha256};
use tempfile::TempDir;

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 @@ -695,7 +683,7 @@ impl Default for BenchShieldedCtx {
fn default() -> Self {
let mut shell = BenchShell::default();

let mut ctx = Context::new::<StdIo>(namada_apps::cli::args::Global {
let mut ctx = Context::new::<StdIo>(crate::cli::args::Global {
chain_id: None,
base_dir: shell.tempdir.as_ref().canonicalize().unwrap(),
wasm_dir: Some(WASM_DIR.into()),
Expand All @@ -713,7 +701,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 @@ -745,7 +733,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 @@ -14,7 +14,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};
use namada_sdk::eth_bridge::EthereumBridgeConfig;

Expand Down Expand Up @@ -902,6 +901,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 namada_sdk::eth_bridge::{
Contracts, Erc20WhitelistEntry, UpgradeableContract,
};
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
25 changes: 6 additions & 19 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,23 +38,14 @@ harness = false
path = "host_env.rs"

[dependencies]
async-trait.workspace = true

[dev-dependencies]
namada = { path = "../shared", features = ["testing"] }
namada_apps = { path = "../apps", features = ["testing"] }
borsh.workspace = true
borsh-ext.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_sdk = {path = "../sdk", 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
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 @@ -24,8 +24,7 @@ use namada::types::transaction::pos::{
Bond, CommissionChange, Redelegation, 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_ACCOUNT_WASM,
Expand All @@ -34,6 +33,7 @@ use namada_benches::{
TX_UPDATE_ACCOUNT_WASM, TX_VOTE_PROPOSAL_WASM, TX_WITHDRAW_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 000c731

Please sign in to comment.