forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[testing] introduce the Cluster struct & integration test for causal …
…completion (MystenLabs#487)
- Loading branch information
Showing
13 changed files
with
204 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
use async_trait::async_trait; | ||
use executor::{ExecutionIndices, ExecutionState, ExecutionStateError}; | ||
use thiserror::Error; | ||
|
||
/// A simple/dumb execution engine. | ||
pub struct SimpleExecutionState; | ||
|
||
#[async_trait] | ||
impl ExecutionState for SimpleExecutionState { | ||
type Transaction = String; | ||
type Error = SimpleExecutionError; | ||
|
||
async fn handle_consensus_transaction( | ||
&self, | ||
_execution_indices: ExecutionIndices, | ||
_transaction: Self::Transaction, | ||
) -> Result<Vec<u8>, Self::Error> { | ||
Ok(Vec::default()) | ||
} | ||
|
||
fn ask_consensus_write_lock(&self) -> bool { | ||
true | ||
} | ||
|
||
fn release_consensus_write_lock(&self) {} | ||
|
||
async fn load_execution_indices(&self) -> Result<ExecutionIndices, Self::Error> { | ||
Ok(ExecutionIndices::default()) | ||
} | ||
} | ||
|
||
/// A simple/dumb execution error. | ||
#[derive(Debug, Error)] | ||
pub enum SimpleExecutionError { | ||
#[error("Something went wrong in the authority")] | ||
ServerError, | ||
|
||
#[error("The client made something bad")] | ||
ClientError, | ||
} | ||
|
||
#[async_trait] | ||
impl ExecutionStateError for SimpleExecutionError { | ||
fn node_error(&self) -> bool { | ||
match self { | ||
Self::ServerError => true, | ||
Self::ClientError => false, | ||
} | ||
} | ||
|
||
fn to_string(&self) -> String { | ||
ToString::to_string(&self) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// Copyright (c) 2022, Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
use std::time::Duration; | ||
use test_utils::cluster::Cluster; | ||
use tracing::{info, subscriber::set_global_default}; | ||
use tracing_subscriber::filter::{EnvFilter, LevelFilter}; | ||
|
||
#[ignore] | ||
#[tokio::test] | ||
async fn test_read_causal_signed_certificates() { | ||
const CURRENT_ROUND_METRIC: &str = "narwhal_primary_current_round"; | ||
|
||
// Enabled debug tracing so we can easily observe the | ||
// nodes logs. | ||
setup_tracing(); | ||
|
||
let mut cluster = Cluster::new(None); | ||
|
||
// start the cluster | ||
let nodes = cluster.start(4).await; | ||
|
||
// Let primaries advance little bit | ||
tokio::time::sleep(Duration::from_secs(10)).await; | ||
|
||
// Ensure all nodes advanced | ||
for node in nodes { | ||
let metric_family = node.registry.gather(); | ||
|
||
for metric in metric_family { | ||
if metric.get_name() == CURRENT_ROUND_METRIC { | ||
let value = metric.get_metric().first().unwrap().get_gauge().get_value(); | ||
|
||
info!("Metrics name {} -> {:?}", metric.get_name(), value); | ||
|
||
// If the current round is increasing then it means that the | ||
// node starts catching up and is proposing. | ||
assert!(value > 1.0, "Node didn't progress further than the round 1"); | ||
} | ||
} | ||
} | ||
|
||
// Now stop node 0 | ||
cluster.stop_node(0); | ||
|
||
// Let other primaries advance | ||
tokio::time::sleep(Duration::from_secs(10)).await; | ||
|
||
// Now start the validator 0 again | ||
let node = cluster.start_node(0).await.unwrap(); | ||
|
||
// Now check that the current round advances. Give the opportunity with a few | ||
// iterations. If metric hasn't picked up then we know that node can't make | ||
// progress. | ||
let mut node_made_progress = false; | ||
for _ in 0..10 { | ||
tokio::time::sleep(Duration::from_secs(1)).await; | ||
|
||
let metric_family = node.registry.gather(); | ||
|
||
for metric in metric_family { | ||
if metric.get_name() == CURRENT_ROUND_METRIC { | ||
let value = metric.get_metric().first().unwrap().get_gauge().get_value(); | ||
|
||
info!("Metrics name {} -> {:?}", metric.get_name(), value); | ||
|
||
// If the current round is increasing then it means that the | ||
// node starts catching up and is proposing. | ||
if value > 1.0 { | ||
node_made_progress = true; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
assert!( | ||
node_made_progress, | ||
"Node 0 didn't make progress - causal completion didn't succeed" | ||
); | ||
} | ||
|
||
fn setup_tracing() { | ||
// Setup tracing | ||
let tracing_level = "debug"; | ||
let network_tracing_level = "info"; | ||
|
||
let filter = EnvFilter::builder() | ||
.with_default_directive(LevelFilter::INFO.into()) | ||
.parse(format!( | ||
"{tracing_level},h2={network_tracing_level},tower={network_tracing_level},hyper={network_tracing_level},tonic::transport={network_tracing_level}" | ||
)).unwrap(); | ||
let env_filter = EnvFilter::try_from_default_env().unwrap_or(filter); | ||
let subscriber_builder = | ||
tracing_subscriber::fmt::Subscriber::builder().with_env_filter(env_filter); | ||
|
||
let subscriber = subscriber_builder.with_writer(std::io::stderr).finish(); | ||
set_global_default(subscriber).expect("Failed to set subscriber"); | ||
} |
Oops, something went wrong.