Skip to content

Commit

Permalink
Make the sequencer more solid (MystenLabs#1049)
Browse files Browse the repository at this point in the history
Make the sequencer robust
  • Loading branch information
asonnino authored Mar 24, 2022
1 parent 5ceb05b commit 88c88d8
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 60 deletions.
1 change: 1 addition & 0 deletions sui_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ similar-asserts = "1.2.0"
serde-reflection = "0.3.5"
serde_yaml = "0.8.23"
pretty_assertions = "1.2.0"
temp_testdir = "0.2"

test_utils = { path = "../test_utils" }

Expand Down
6 changes: 3 additions & 3 deletions sui_core/src/consensus_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl ConsensusClient {
/// and right order.
async fn synchronize(&mut self, connection: &mut TcpDataStream) -> SuiResult<()> {
let request = ConsensusSync {
sequencer_number: self.last_consensus_index,
sequence_number: self.last_consensus_index,
};
let bytes = Bytes::from(serialize_consensus_sync(&request));
connection
Expand All @@ -106,9 +106,9 @@ impl ConsensusClient {
Ok(SerializedMessage::ConsensusOutput(value)) => {
let ConsensusOutput {
message,
sequencer_number,
sequence_number,
} = *value;
(message, sequencer_number)
(message, sequence_number)
}
Ok(_) => {
log::error!("{}", SuiError::UnexpectedMessage);
Expand Down
18 changes: 15 additions & 3 deletions sui_core/src/unit_tests/consensus_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ async fn handle_consensus_output() {
buffer_size: NETWORK_BUFFER_SIZE,
consensus_delay: Duration::from_millis(0),
};
Sequencer::spawn(sequencer).await;
let store_path = temp_testdir::TempDir::default();
Sequencer::spawn(sequencer, store_path.as_ref())
.await
.unwrap();

// Spawn a consensus client.
let state = Arc::new(authority);
Expand All @@ -154,6 +157,9 @@ async fn handle_consensus_output() {
state.db().last_consensus_index().unwrap(),
SequenceNumber::from(1)
);

// Cleanup the storage.
let _ = std::fs::remove_dir_all(store_path);
}

#[tokio::test]
Expand All @@ -170,7 +176,7 @@ async fn test_guardrail() {
}

#[tokio::test]
async fn test_sync() {
async fn sync_with_consensus() {
// Initialize an authority with a (owned) gas object and a shared object.
let mut objects = test_gas_objects();
objects.push(test_shared_object());
Expand All @@ -192,7 +198,10 @@ async fn test_sync() {
buffer_size: NETWORK_BUFFER_SIZE,
consensus_delay: Duration::from_millis(0),
};
Sequencer::spawn(sequencer).await;
let store_path = temp_testdir::TempDir::default();
Sequencer::spawn(sequencer, store_path.as_ref())
.await
.unwrap();

// Submit a certificate to the sequencer.
tokio::task::yield_now().await;
Expand Down Expand Up @@ -252,4 +261,7 @@ async fn test_sync() {
.unwrap()
.unwrap();
assert_eq!(certificate_1_sequence, SequenceNumber::from(1));

// Cleanup the storage.
let _ = std::fs::remove_dir_all(store_path);
}
4 changes: 2 additions & 2 deletions sui_core/tests/staged/sui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ CertifiedTransaction:
ConsensusOutput:
STRUCT:
- message: BYTES
- sequencer_number:
- sequence_number:
TYPENAME: SequenceNumber
ConsensusSync:
STRUCT:
- sequencer_number:
- sequence_number:
TYPENAME: SequenceNumber
Data:
ENUM:
Expand Down
4 changes: 2 additions & 2 deletions sui_types/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1102,10 +1102,10 @@ impl BcsSignable for TransactionData {}
pub struct ConsensusOutput {
#[serde(with = "serde_bytes")]
pub message: Vec<u8>,
pub sequencer_number: SequenceNumber,
pub sequence_number: SequenceNumber,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ConsensusSync {
pub sequencer_number: SequenceNumber,
pub sequence_number: SequenceNumber,
}
2 changes: 2 additions & 0 deletions test_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ log = "0.4.14"
rand = "0.7.3"
rocksdb = "0.18.0"

typed-store = { git = "https://github.com/MystenLabs/mysten-infra", rev ="e44bca4513a6ff6c97399cd79e82e4bc00571ac3"}

sui-types = { path = "../sui_types" }
sui-network = { path = "../network_utils" }
Loading

0 comments on commit 88c88d8

Please sign in to comment.