-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(code/consensus): Add support for full nodes #750
Merged
+247
−47
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ef01d8e
feat(code/consensus): Add support for full nodes
hoank101 818f09c
fix lint
hoank101 2044caa
Merge branch 'main' into feat/742
hoank101 888f1ab
Update code/crates/core-consensus/src/state.rs
hoank101 f5a4ea8
update
hoank101 e931020
Merge branch 'main' into feat/742
hoank101 a6c29b2
update
hoank101 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 | ||
hoank101 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the proposal filtering, seems we are trying to defend against a bug where
get_proposer()
returns a non-validator/ full node address...but in this case theis_validator()
should also fail.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it's just defensive coding. Maybe we can change the check to do a
debug_assert
or even anassert
in order to ensure this code path is never hit.