Skip to content

Commit

Permalink
[Consensus] introduce consensus only simtests (MystenLabs#20683)
Browse files Browse the repository at this point in the history
## Description 

PR is introducing the framework to enable us run Consensus-only
simtests. Looking on the existing sui-swarm it would be a bit
challenging to reuse as APIs are different and especially when we need
to access consensus specific components.

The PR is using similar patterns that have been used in sui-swarm but I
am expecting to refine this as we go. This might be a good start for
now. A simple simtest method has been added for the time being
`test_committee_start_simple` . Eventually we want to replace the tests
on `authority_node` and add a few more cases. Motivation to do this has
been the Garbage Collection work when investigating some edge cases
where reproducibility was important to confirm the issues.

Example to run this simtest with additional logging, a high regional
variance in latency, and outputting the result in `output.txt`

```
SUI_SIM_CONFIG=regional_high_variance RUST_LOG=info,consensus_core=debug cargo simtest test_committee_start  --nocapture > output.txt 2>&1
```

## Test plan 

CI

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
  • Loading branch information
akichidis authored Feb 13, 2025
1 parent e491c96 commit b3f1ebd
Show file tree
Hide file tree
Showing 10 changed files with 522 additions and 4 deletions.
26 changes: 26 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ exclude = [
members = [
"consensus/config",
"consensus/core",
"consensus/simtests",
"crates/anemo-benchmark",
"crates/bin-version",
"crates/mysten-common",
Expand Down Expand Up @@ -716,6 +717,7 @@ x = { path = "crates/x" }

consensus-config = { path = "consensus/config" }
consensus-core = { path = "consensus/core" }
consensus-simtests = { path = "consensus/simtests" }

sui-execution = { path = "sui-execution" }
# sui-move-natives = { path = "sui-execution/latest/sui-move-natives", package = "sui-move-natives-latest" }
Expand Down
12 changes: 12 additions & 0 deletions consensus/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,27 @@ mod leader_scoring;
mod leader_timeout;
mod linearizer;
mod metrics;
#[cfg(not(msim))]
mod network;
#[cfg(msim)]
pub mod network;

mod stake_aggregator;
mod storage;
mod subscriber;
mod synchronizer;
mod threshold_clock;
#[cfg(not(msim))]
mod transaction;
#[cfg(msim)]
pub mod transaction;

mod universal_committer;

#[cfg(test)]
#[path = "tests/randomized_tests.rs"]
mod randomized_tests;

mod round_prober;
#[cfg(test)]
mod test_dag;
Expand All @@ -54,7 +63,10 @@ pub use commit_consumer::{CommitConsumer, CommitConsumerMonitor};
pub use network::{
connection_monitor::{AnemoConnectionMonitor, ConnectionMonitorHandle, ConnectionStatus},
metrics::{MetricsMakeCallbackHandler, NetworkRouteMetrics, QuinnConnectionMetrics},
tonic_network::to_socket_addr,
};
#[cfg(msim)]
pub use transaction::NoopTransactionVerifier;
pub use transaction::{
BlockStatus, ClientError, TransactionClient, TransactionVerifier, ValidationError,
};
3 changes: 3 additions & 0 deletions consensus/core/src/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ mod metrics_layer;
mod network_tests;
#[cfg(test)]
pub(crate) mod test_network;
#[cfg(not(msim))]
pub(crate) mod tonic_network;
#[cfg(msim)]
pub mod tonic_network;
mod tonic_tls;

/// A stream of serialized filtered blocks returned over the network.
Expand Down
2 changes: 1 addition & 1 deletion consensus/core/src/network/tonic_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ fn to_host_port_str(addr: &Multiaddr) -> Result<String, &'static str> {

/// Attempts to convert a multiaddr of the form `/[ip4,ip6]/{}/[udp,tcp]/{port}` into
/// a SocketAddr value.
fn to_socket_addr(addr: &Multiaddr) -> Result<SocketAddr, &'static str> {
pub fn to_socket_addr(addr: &Multiaddr) -> Result<SocketAddr, &'static str> {
let mut iter = addr.iter();

match (iter.next(), iter.next()) {
Expand Down
6 changes: 3 additions & 3 deletions consensus/core/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,10 @@ pub enum ValidationError {
}

/// `NoopTransactionVerifier` accepts all transactions.
#[cfg(test)]
pub(crate) struct NoopTransactionVerifier;
#[cfg(any(test, msim))]
pub struct NoopTransactionVerifier;

#[cfg(test)]
#[cfg(any(test, msim))]
#[async_trait::async_trait]
impl TransactionVerifier for NoopTransactionVerifier {
fn verify_batch(&self, _batch: &[&[u8]]) -> Result<(), ValidationError> {
Expand Down
32 changes: 32 additions & 0 deletions consensus/simtests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "consensus-simtests"
version = "0.1.0"
license = "Apache-2.0"
authors = ["Mysten Labs <[email protected]>"]
edition = "2021"
publish = false

[lints]
workspace = true

[target.'cfg(msim)'.dependencies]
sui-simulator.workspace = true
anyhow.workspace = true
arc-swap.workspace = true
consensus-config.workspace = true
consensus-core.workspace = true
mysten-metrics.workspace = true
mysten-network.workspace = true
parking_lot.workspace = true
prometheus.workspace = true
rand.workspace = true
sui-config.workspace = true
sui-macros.workspace = true
sui-protocol-config.workspace = true
tokio.workspace = true
tokio-stream.workspace = true
tokio-util.workspace = true
tracing.workspace = true
typed-store.workspace = true
tempfile.workspace = true
telemetry-subscribers.workspace = true
9 changes: 9 additions & 0 deletions consensus/simtests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

#[cfg(msim)]
mod node;

#[cfg(msim)]
#[path = "tests/simtests.rs"]
mod simtests;
Loading

0 comments on commit b3f1ebd

Please sign in to comment.