-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(code/consensus): Add support for full nodes (#750)
* feat(code/consensus): Add support for full nodes * fix lint * Update code/crates/core-consensus/src/state.rs Co-authored-by: Romain Ruetschi <[email protected]> Signed-off-by: DevOrbitlabs <[email protected]> * update * update --------- Signed-off-by: DevOrbitlabs <[email protected]> Co-authored-by: Romain Ruetschi <[email protected]>
- Loading branch information
Showing
6 changed files
with
247 additions
and
47 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
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod full_nodes; | ||
pub mod n3f0; | ||
pub mod n3f0_consensus_mode; | ||
pub mod n3f0_pubsub_protocol; | ||
|
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,165 @@ | ||
use std::time::Duration; | ||
|
||
use crate::{init_logging, TestBuilder}; | ||
|
||
#[tokio::test] | ||
pub async fn basic_full_node() { | ||
init_logging(module_path!()); | ||
|
||
const HEIGHT: u64 = 5; | ||
|
||
let mut test = TestBuilder::<()>::new(); | ||
|
||
// Add 3 validators with different voting powers | ||
test.add_node() | ||
.with_voting_power(10) | ||
.start() | ||
.wait_until(HEIGHT) | ||
.success(); | ||
test.add_node() | ||
.with_voting_power(20) | ||
.start() | ||
.wait_until(HEIGHT) | ||
.success(); | ||
test.add_node() | ||
.with_voting_power(30) | ||
.start() | ||
.wait_until(HEIGHT) | ||
.success(); | ||
|
||
// Add 2 full nodes that should follow consensus but not participate | ||
test.add_node() | ||
.full_node() | ||
.start() | ||
.wait_until(HEIGHT) | ||
.success(); | ||
test.add_node() | ||
.full_node() | ||
.start() | ||
.wait_until(HEIGHT) | ||
.success(); | ||
|
||
test.build().run(Duration::from_secs(30)).await | ||
} | ||
|
||
#[tokio::test] | ||
pub async fn full_node_crash_and_sync() { | ||
init_logging(module_path!()); | ||
|
||
const HEIGHT: u64 = 10; | ||
|
||
let mut test = TestBuilder::<()>::new(); | ||
|
||
// Add validators | ||
test.add_node() | ||
.with_voting_power(20) | ||
.start() | ||
.wait_until(HEIGHT) | ||
.success(); | ||
test.add_node() | ||
.with_voting_power(20) | ||
.start() | ||
.wait_until(HEIGHT) | ||
.success(); | ||
test.add_node() | ||
.with_voting_power(20) | ||
.start() | ||
.wait_until(HEIGHT) | ||
.success(); | ||
|
||
// Add a full node that crashes and needs to sync | ||
test.add_node() | ||
.full_node() | ||
.start() | ||
.wait_until(3) | ||
.crash() | ||
.reset_db() | ||
.restart_after(Duration::from_secs(5)) | ||
.wait_until(HEIGHT) | ||
.success(); | ||
|
||
test.build().run(Duration::from_secs(60)).await | ||
} | ||
|
||
#[tokio::test] | ||
pub async fn late_starting_full_node() { | ||
init_logging(module_path!()); | ||
|
||
const HEIGHT: u64 = 10; | ||
|
||
let mut test = TestBuilder::<()>::new(); | ||
|
||
// Add validators that start immediately | ||
test.add_node() | ||
.with_voting_power(20) | ||
.start() | ||
.wait_until(HEIGHT) | ||
.success(); | ||
test.add_node() | ||
.with_voting_power(20) | ||
.start() | ||
.wait_until(HEIGHT) | ||
.success(); | ||
test.add_node() | ||
.with_voting_power(20) | ||
.start() | ||
.wait_until(HEIGHT) | ||
.success(); | ||
|
||
// Add a full node that starts late | ||
test.add_node() | ||
.full_node() | ||
.start_after(1, Duration::from_secs(10)) | ||
.wait_until(HEIGHT) | ||
.success(); | ||
|
||
test.build().run(Duration::from_secs(60)).await | ||
} | ||
|
||
#[tokio::test] | ||
pub async fn mixed_validator_and_full_node_failures() { | ||
init_logging(module_path!()); | ||
|
||
const HEIGHT: u64 = 10; | ||
|
||
let mut test = TestBuilder::<()>::new(); | ||
|
||
// Add stable validators | ||
test.add_node() | ||
.with_voting_power(30) | ||
.start() | ||
.wait_until(HEIGHT) | ||
.success(); | ||
test.add_node() | ||
.with_voting_power(30) | ||
.start() | ||
.wait_until(HEIGHT) | ||
.success(); | ||
|
||
// Add a validator that crashes | ||
test.add_node() | ||
.with_voting_power(20) | ||
.start() | ||
.wait_until(5) | ||
.crash() | ||
.restart_after(Duration::from_secs(10)) | ||
.wait_until(HEIGHT) | ||
.success(); | ||
|
||
// Add full nodes - one stable, one that crashes | ||
test.add_node() | ||
.full_node() | ||
.start() | ||
.wait_until(HEIGHT) | ||
.success(); | ||
test.add_node() | ||
.full_node() | ||
.start() | ||
.wait_until(6) | ||
.crash() | ||
.restart_after(Duration::from_secs(15)) | ||
.wait_until(HEIGHT) | ||
.success(); | ||
|
||
test.build().run(Duration::from_secs(60)).await | ||
} |