-
Notifications
You must be signed in to change notification settings - Fork 220
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: ban bad block-sync peers #5871
feat: ban bad block-sync peers #5871
Conversation
2dee0e3
to
7121b61
Compare
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.
Looking good, I want us to add a comment and rename a test, the other one is a nit
) { | ||
if blocks_with_anchor.is_empty() || blocks_with_anchor.len() < 2 { | ||
panic!("blocks must have at least 2 elements"); | ||
} | ||
let set_best_block = set_best_block.unwrap_or(false); | ||
let mut blocks: Vec<_> = blocks_with_anchor.to_vec(); | ||
blocks.reverse(); | ||
for i in 0..blocks.len() - 1 { |
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.
for i in 0..blocks.len() - 1 { | |
for i in (0..blocks.len() - 1).rev() { |
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.
nit: if just do this, you don't have to swap around the entire array, and the code above is more direct what's going on. Because it seems strange that you delete a block, and then you set the next block as the best block
) { | ||
if blocks_with_anchor.is_empty() || blocks_with_anchor.len() < 2 { | ||
panic!("blocks must have at least 2 elements"); | ||
} | ||
let set_best_block = set_best_block.unwrap_or(false); | ||
let mut blocks: Vec<_> = blocks_with_anchor.to_vec(); | ||
blocks.reverse(); |
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.
blocks.reverse(); |
- Added a check to ban a misbahaving peer after block sync when not supplying any or all of the blocks corresponding to the accumulated difficulty they claimed they had. - Added a check in the RPC block-sync server method to not try and supply blocks past its own end of chain best block. - Added integration level unit tests for block sync.
adb942e
to
40838b6
Compare
40838b6
to
1218d43
Compare
Description
Motivation and Context
The new unit tests that were added highlighted some issues where sync peers are not banned for their bad behaviour.
How Has This Been Tested?
Added new integration-level unit tests.
What process can a PR reviewer use to test or verify this change?
Breaking Changes