Skip to content
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

Merged
merged 6 commits into from
Oct 27, 2023

Conversation

hansieodendaal
Copy link
Contributor

Description

  • Added a check to ban a misbehaving 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 not to try and supply blocks if it does not have both blocks corresponding to the start and end hash in its chain.
  • Moved all block sync RPC errors to the short ban category from the no=ban cetegrory.
  • Added happy path and ban integration-level unit tests for block sync.

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?

  • Code walk through.
  • Review and run unit tests .

Breaking Changes

  • None
  • Requires data directory on base node to be deleted
  • Requires hard fork
  • Other - Please specify

@github-actions
Copy link

github-actions bot commented Oct 25, 2023

Test Results (CI)

1 243 tests   1 243 ✔️  11m 3s ⏱️
     39 suites         0 💤
       1 files           0

Results for commit 7d8aebb.

♻️ This comment has been updated with latest results.

@ghpbot-tari-project ghpbot-tari-project added P-acks_required Process - Requires more ACKs or utACKs P-reviews_required Process - Requires a review from a lead maintainer to be merged labels Oct 25, 2023
@github-actions
Copy link

github-actions bot commented Oct 25, 2023

Test Results (Integration tests)

34 tests  +34   34 ✔️ +34   13m 15s ⏱️ + 13m 15s
11 suites +11     0 💤 ±  0 
  2 files   +  2     0 ±  0 

Results for commit 7d8aebb. ± Comparison against base commit 4947df5.

♻️ This comment has been updated with latest results.

base_layer/core/src/base_node/sync/rpc/service.rs Outdated Show resolved Hide resolved
base_layer/core/tests/helpers/sync.rs Outdated Show resolved Hide resolved
base_layer/core/tests/tests/header_sync.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@SWvheerden SWvheerden left a 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

base_layer/core/src/base_node/sync/rpc/tests.rs Outdated Show resolved Hide resolved
) {
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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for i in 0..blocks.len() - 1 {
for i in (0..blocks.len() - 1).rev() {

Copy link
Collaborator

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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
blocks.reverse();

hansieodendaal and others added 5 commits October 27, 2023 15:24
- 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.
@ghpbot-tari-project ghpbot-tari-project removed the P-reviews_required Process - Requires a review from a lead maintainer to be merged label Oct 27, 2023
@SWvheerden SWvheerden merged commit 5c2781e into tari-project:development Oct 27, 2023
8 of 9 checks passed
@hansieodendaal hansieodendaal deleted the ho_block_sync branch October 27, 2023 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P-acks_required Process - Requires more ACKs or utACKs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants