This document describes the test application built on top of the Malachite BFT consensus engine.
| Test App | |
|---|---|
| Location | code/crates/test/app/ |
| Purpose | Integration testing, fault injection, and runnable example |
| Integration level | Channel-based (app-channel) |
| Context | TestContext (from malachitebft-test) |
| Value type | u64 (factored into primes) |
| Value payload mode | ProposalAndParts (configurable) |
| Network codec | Protobuf |
| Signing | Ed25519 |
The test app uses the channel-based integration level (malachitebft-app-channel). The engine is started with EngineBuilder, which returns a set of channels. The application runs a tokio::spawned loop over channels.consensus.recv(), handling AppMsg variants (GetValue, ReceivedProposalPart, Decided, Finalized, etc.). All actor wiring is handled internally.
Serves as both the integration test harness (used by code/crates/test/tests/) and a standalone runnable application with CLI support. Provides a middleware system for fault injection and configurable consensus behavior.
| Module | File | Purpose |
|---|---|---|
main |
src/main.rs |
CLI entry point (start, init, testnet, dump-wal) |
node |
src/node.rs |
App (in-memory) and CliApp (file-based) Node impls |
app |
src/app.rs |
Main AppMsg event loop, monitor_state, log level reloading |
state |
src/state.rs |
Proposal creation, validation, value assembly, validator rotation |
config |
src/config.rs |
Configuration loading with env var overlay, validator rotation config |
metrics |
src/metrics.rs |
DbMetrics implementing StoreMetrics for Prometheus |
store |
src/store.rs |
Re-export from malachitebft-test-store |
streaming |
src/streaming.rs |
Re-export from malachitebft-test-streaming |
App— Used by the integration test framework. Configuration and keys are provided in-memory. UsesNoMetricsfor the store.CliApp— Used by the CLI binary. Configuration and keys are loaded from files on disk. Registers PrometheusDbMetricsand serves a metrics endpoint.
Reuses TestContext from malachitebft-test (crates/test/src/context.rs). This context routes all operations through a Middleware trait, enabling per-node behavior customization in tests.
- Values are random
u64integers - Streamed as prime factors:
Init(metadata) →Data(one per factor) →Fin(Keccak256 signature) - 500ms artificial delay simulates execution
The Middleware trait (crates/test/src/middleware.rs) provides hooks at key consensus points:
get_validator_set()— override validator sets per heightget_timeouts()— override timeoutson_propose_value()— intercept/modify proposalsget_validity()— control validity decisionson_commit()— hook into commits
Built-in variants: DefaultMiddleware, RotateValidators, EpochValidators, RotateEpochValidators.
The validator set for a given height is resolved with the following priority:
- Middleware — if the middleware returns a validator set, it takes priority
- Validator rotation — if
validator_rotation.enabledis true in config, rotates the genesis validator set based on height and configured period/selection size - Genesis — falls back to the genesis validator set
The Config struct includes:
- Standard consensus, logging, metrics, runtime, and value sync configuration
test— test-specific config (target time, etc.)validator_rotation— configurable validator set rotation (enabled,rotation_period,selection_size)
Configuration is loaded from TOML files with environment variable overlay (prefix MALACHITE__).
# Generate testnet configs
cargo run -p arc-malachitebft-test-app -- testnet --nodes 3 --home nodes
# Start a node
cargo run -p arc-malachitebft-test-app -- start --home nodes/node-0Integration tests cover: equivocation, finalization, full nodes, liveness, WAL recovery, value sync, Byzantine tolerance (n=3f+0, n=3f+1), pubsub protocols, and consensus modes.
Extracted streaming module for proposal part stream reassembly:
MinSeq<T>,MinHeap<T>— MinHeap-based stream reassembly ensuring ordered deliveryStreamState— per-stream buffer stateProposalParts— assembled proposal parts (height, round, proposer, parts vector)PartStreamsMap— multi-stream state machine managing concurrent proposal streams
Extracted redb-based persistent storage with pluggable metrics:
Store<M: StoreMetrics>— async store backed by redb, generic over metrics implementationDb<M>— synchronous database layer with metrics instrumentationDecidedValue— committed value with its commit certificateStoreMetricstrait — pluggable metrics interface with default no-op implementationsNoMetrics— zero-cost no-op metrics implementation- Table management for decided values, certificates, undecided proposals, and pending proposal parts
code/crates/test/ # malachitebft-test (TestContext, Middleware, Node traits)
code/crates/test/streaming/ # malachitebft-test-streaming (stream reassembly)
code/crates/test/store/ # malachitebft-test-store (redb storage + metrics trait)
code/crates/test/app/ # malachitebft-test-app (lib + bin: test app with CLI)
code/crates/test/cli/ # malachitebft-test-cli (CLI arg parsing, logging, runtime)
code/crates/test/framework/ # malachitebft-test-framework (TestRunner, NodeInfo)
code/crates/test/tests/ # Integration tests
code/crates/test/mbt/ # Model-based tests
code/crates/test/mempool/ # Mempool utilities
malachitebft-test-streaming
└── malachitebft-app-channel, malachitebft-test
malachitebft-test-store
└── malachitebft-test-streaming, malachitebft-app-channel, malachitebft-test
malachitebft-test-app (lib + bin)
└── malachitebft-test-store, malachitebft-test-streaming
└── malachitebft-test, malachitebft-test-cli
└── malachitebft-app-channel