Skip to content

Commit

Permalink
[narwhal] enable randomized tests for new consensus schedule algorithm (
Browse files Browse the repository at this point in the history
MystenLabs#12876)

## Description 

Making the consensus randomized tests run for both the new and current
schedule algorithm to ensure that until we enable it on production
things work as expected.

## Test Plan 

How did you test the new or updated feature?

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
akichidis authored Aug 4, 2023
1 parent 52a1867 commit a2a6d6e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .config/nextest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ status-level = "skip"
fail-fast = false
# Do not retry failing tests
retries = 0
# Mark tests as slow after 4 hours, kill them right after
slow-timeout = { period = "4h", terminate-after = 1 }
# Mark tests as slow after 7 hours, kill them right after
slow-timeout = { period = "7h", terminate-after = 1 }

[profile.simtestnightly]
# Print out output for failing tests as soon as they fail, and also at the end
Expand Down
62 changes: 49 additions & 13 deletions narwhal/consensus/src/tests/randomized_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use crate::bullshark::Bullshark;
use crate::consensus::{ConsensusState, LeaderSchedule, LeaderSwapTable};
use crate::consensus_utils::make_consensus_store;
use crate::consensus_utils::NUM_SUB_DAGS_PER_SCHEDULE;
use crate::metrics::ConsensusMetrics;
use config::{Authority, AuthorityIdentifier, Committee, Stake};
use fastcrypto::hash::Hash;
Expand All @@ -22,6 +21,7 @@ use std::num::NonZeroUsize;
use std::ops::RangeInclusive;
use std::sync::Arc;
use storage::ConsensusStore;
use sui_protocol_config::ProtocolConfig;
use test_utils::latest_protocol_version;
use test_utils::mock_certificate_with_rand;
use test_utils::CommitteeFixture;
Expand Down Expand Up @@ -75,6 +75,18 @@ impl ExecutionPlan {
#[ignore]
#[tokio::test(flavor = "multi_thread", worker_threads = 8)]
async fn bullshark_randomised_tests() {
// Run the consensus tests without the new consensus schedule changes
let protocol_config = latest_protocol_version();
bullshark_randomised_tests_with_config(protocol_config).await;

// TODO: remove once the new leader election schedule feature is enabled on a protocol version
// Run the consensus tests with the new consensus schedule changes enabled
let mut config: ProtocolConfig = latest_protocol_version();
config.set_narwhal_new_leader_election_schedule(true);
bullshark_randomised_tests_with_config(config).await;
}

async fn bullshark_randomised_tests_with_config(protocol_config: ProtocolConfig) {
// Configuration regarding the randomized tests. The tests will run for different values
// on the below parameters to increase the different cases we can generate.

Expand All @@ -83,7 +95,7 @@ async fn bullshark_randomised_tests() {
// A the committee size values to be used
const COMMITTEE_SIZE: [usize; 3] = [4, 7, 10];
// Rounds for which we will create DAGs
const DAG_ROUNDS: [Round; 6] = [6, 7, 8, 10, 12, 15];
const DAG_ROUNDS: [Round; 4] = [8, 10, 12, 15];
// The number of different execution plans to be created and tested against for every generated DAG
const EXECUTION_PLANS: u64 = 500;
// The number of DAGs that should be generated and tested against for every set of properties.
Expand Down Expand Up @@ -173,10 +185,12 @@ async fn bullshark_randomised_tests() {

let consensus_store = store.clone();

let config = protocol_config.clone();

let handle = tokio::spawn(async move {
// Create a randomized DAG
let (certificates, committee) =
generate_randomised_dag(committee_size, dag_rounds, run_id, mode);
generate_randomised_dag(committee_size, dag_rounds, run_id, mode, &config);

// Now provide the DAG to create execution plans, run them via consensus
// and compare output against each other to ensure they are the same.
Expand All @@ -188,7 +202,8 @@ async fn bullshark_randomised_tests() {
dag_rounds,
run_id,
mode,
consensus_store
consensus_store,
&config
);
});

Expand Down Expand Up @@ -219,13 +234,24 @@ fn test_determinism() {
slow_nodes_failure_probability: 0.5,
minimum_committee_size: None,
};
let protocol_config = latest_protocol_version();

for seed in 0..=10 {
// Compare the creation of DAG & committee
let (dag_1, committee_1) =
generate_randomised_dag(committee_size, number_of_rounds, seed, failure_modes);
let (dag_2, committee_2) =
generate_randomised_dag(committee_size, number_of_rounds, seed, failure_modes);
let (dag_1, committee_1) = generate_randomised_dag(
committee_size,
number_of_rounds,
seed,
failure_modes,
&protocol_config,
);
let (dag_2, committee_2) = generate_randomised_dag(
committee_size,
number_of_rounds,
seed,
failure_modes,
&protocol_config,
);

assert_eq!(committee_1, committee_2);
assert_eq!(dag_1, dag_2);
Expand All @@ -252,6 +278,7 @@ fn generate_randomised_dag(
number_of_rounds: Round,
seed: u64,
modes: FailureModes,
protocol_config: &ProtocolConfig,
) -> (VecDeque<Certificate>, Committee) {
// Create an RNG to share for the committee creation
let rand = StdRng::seed_from_u64(seed);
Expand All @@ -264,8 +291,14 @@ fn generate_randomised_dag(
let genesis = Certificate::genesis(&committee);

// Create a known DAG
let (original_certificates, _last_round) =
make_certificates_with_parameters(seed, &committee, 1..=number_of_rounds, genesis, modes);
let (original_certificates, _last_round) = make_certificates_with_parameters(
seed,
&committee,
1..=number_of_rounds,
genesis,
modes,
protocol_config,
);

(original_certificates, committee)
}
Expand All @@ -281,6 +314,7 @@ pub fn make_certificates_with_parameters(
range: RangeInclusive<Round>,
initial_parents: Vec<Certificate>,
modes: FailureModes,
protocol_config: &ProtocolConfig,
) -> (VecDeque<Certificate>, Vec<Certificate>) {
let mut rand = StdRng::seed_from_u64(seed);

Expand Down Expand Up @@ -416,7 +450,7 @@ pub fn make_certificates_with_parameters(
// Now create the certificate with the provided parents
let (_, certificate) = mock_certificate_with_rand(
committee,
&latest_protocol_version(),
protocol_config,
authority.id(),
round,
parents_digests.clone(),
Expand Down Expand Up @@ -470,6 +504,7 @@ fn generate_and_run_execution_plans(
run_id: u64,
modes: FailureModes,
store: Arc<ConsensusStore>,
protocol_config: &ProtocolConfig,
) {
println!(
"Running execution plans for run_id {} for rounds={}, committee={}, gc_depth={}, modes={:?}",
Expand Down Expand Up @@ -497,12 +532,13 @@ fn generate_and_run_execution_plans(
// Now create a new Bullshark engine
let metrics = Arc::new(ConsensusMetrics::new(&Registry::new()));
let mut state = ConsensusState::new(metrics.clone(), gc_depth);
const SUB_DAGS_PER_SCHEDULE: u64 = 5;
let mut bullshark = Bullshark::new(
committee.clone(),
store.clone(),
latest_protocol_version(),
protocol_config.clone(),
metrics.clone(),
NUM_SUB_DAGS_PER_SCHEDULE,
SUB_DAGS_PER_SCHEDULE,
LeaderSchedule::new(committee.clone(), LeaderSwapTable::default()),
);

Expand Down

0 comments on commit a2a6d6e

Please sign in to comment.