Skip to content

Commit

Permalink
Merge branch 'tomas/test-benchmarks' (#1907)
Browse files Browse the repository at this point in the history
* origin/tomas/test-benchmarks:
  changelog: add #1907
  benches: upgrade criterion.rs
  bench: fix ibc native_vp bench
  benches/process_wrapper: increase gas limit to make it pass
  benches: update tx signatures for multisig
  benches: fix gov to enter voting period before voting
  benches: fix epoch params in gov proposals
  shared/ledger/gov: add some logging to gov VP
  benches: add README.md
  benches: add tracing support
  CI/build-and-test: run `make test-benches`
  make: add `test-benches` recipe and add it to `test`
  • Loading branch information
Fraccaman committed Sep 25, 2023
2 parents 8c09f9b + ffb9278 commit 2ea12bb
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 110 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/testing/1907-test-benchmarks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Updated benchmarks and added tests to ensure they're working.
([\#1907](https://github.com/anoma/namada/pull/1907))
4 changes: 4 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ jobs:
name: coverage${{ matrix.make.suffix }}-${{ github.event.pull_request.head.sha || github.sha }}
path: target/html
retention-days: 3
- name: Run benchmarks tests
run: make test-benches${{ matrix.make.suffix }}
env:
RUSTFLAGS: "-C linker=clang -C link-arg=-fuse-ld=/usr/local/bin/mold"
- name: Print sccache stats
if: always()
run: sccache --show-stats
Expand Down
72 changes: 10 additions & 62 deletions Cargo.lock

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

6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ reset-ledger:
audit:
$(cargo) audit $(foreach ignore,$(audit-ignores), --ignore $(ignore))

test: test-unit test-e2e test-wasm
test: test-unit test-e2e test-wasm test-benches

test-coverage:
# Run integration tests with pre-built MASP proofs
Expand Down Expand Up @@ -206,6 +206,10 @@ test-debug:
--nocapture \
-Z unstable-options --report-time

# Test that the benchmarks run successfully without performing measurement
test-benches:
$(cargo) +$(nightly) test --package namada_benchmarks --benches

# Run PoS state machine tests
test-pos-sm:
cd proof_of_stake && \
Expand Down
3 changes: 2 additions & 1 deletion benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ rand_core.workspace = true
sha2.workspace = true
tokio.workspace = true
tempfile.workspace = true
tracing-subscriber = { workspace = true, features = ["std"]}

[dev-dependencies]
criterion = { version = "0.4", features = ["html_reports"] }
criterion = { version = "0.5", features = ["html_reports"] }
19 changes: 19 additions & 0 deletions benches/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Benchmarks

The benchmarks are built with [criterion.rs](https://bheisler.github.io/criterion.rs/book).

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.

To test a selected bench can run successfully on a single run, use can use e.g.:

```shell
cargo test --bench native_vps
```

To benchmark a selected bench with a minimum sample size use e.g.:

```shell
cargo bench --bench whitelisted_txs -- --sample-size 10
```
28 changes: 24 additions & 4 deletions benches/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::fs::{File, OpenOptions};
use std::io::{Read, Write};
use std::ops::{Deref, DerefMut};
use std::path::PathBuf;
use std::sync::Once;

use borsh::{BorshDeserialize, BorshSerialize};
use masp_primitives::transaction::Transaction;
Expand Down Expand Up @@ -67,6 +68,7 @@ use namada::ledger::ibc::storage::{channel_key, connection_key};
use namada::ledger::queries::{
Client, EncodedResponseQuery, RequestCtx, RequestQuery, Router, RPC,
};
use namada::ledger::storage_api::StorageRead;
use namada::proof_of_stake;
use namada::proto::{Code, Data, Section, Signature, Tx};
use namada::sdk::args::InputAmount;
Expand All @@ -82,7 +84,7 @@ use namada::types::io::DefaultIo;
use namada::types::masp::{
ExtendedViewingKey, PaymentAddress, TransferSource, TransferTarget,
};
use namada::types::storage::{BlockHeight, KeySeg, TxIndex};
use namada::types::storage::{BlockHeight, Epoch, KeySeg, TxIndex};
use namada::types::time::DateTimeUtc;
use namada::types::token::DenominatedAmount;
use namada::types::transaction::governance::InitProposalData;
Expand Down Expand Up @@ -125,6 +127,10 @@ const BERTHA_SPENDING_KEY: &str = "bertha_spending";
const FILE_NAME: &str = "shielded.dat";
const TMP_FILE_NAME: &str = "shielded.tmp";

/// For `tracing_subscriber`, which fails if called more than once in the same
/// process
static SHELL_INIT: Once = Once::new();

pub struct BenchShell {
pub inner: Shell,
/// NOTE: Temporary directory should be dropped last since Shell need to
Expand All @@ -148,6 +154,14 @@ impl DerefMut for BenchShell {

impl Default for BenchShell {
fn default() -> Self {
SHELL_INIT.call_once(|| {
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::from_default_env(),
)
.init();
});

let (sender, _) = tokio::sync::mpsc::unbounded_channel();
let tempdir = tempfile::tempdir().unwrap();
let path = tempdir.path().canonicalize().unwrap();
Expand Down Expand Up @@ -203,16 +217,17 @@ impl Default for BenchShell {

// Initialize governance proposal
let content_section = Section::ExtraData(Code::new(vec![]));
let voting_start_epoch = Epoch(25);
let signed_tx = generate_tx(
TX_INIT_PROPOSAL_WASM,
InitProposalData {
id: None,
content: content_section.get_hash(),
author: defaults::albert_address(),
r#type: ProposalType::Default(None),
voting_start_epoch: 12.into(),
voting_end_epoch: 15.into(),
grace_epoch: 18.into(),
voting_start_epoch,
voting_end_epoch: 28.into(),
grace_epoch: 34.into(),
},
None,
Some(vec![content_section]),
Expand All @@ -227,6 +242,11 @@ impl Default for BenchShell {
for _ in 0..=(params.pipeline_len + params.unbonding_len) {
bench_shell.advance_epoch();
}
// Must start after current epoch
debug_assert_eq!(
bench_shell.wl_storage.get_block_epoch().unwrap().next(),
voting_start_epoch
);

bench_shell
}
Expand Down
Loading

0 comments on commit 2ea12bb

Please sign in to comment.