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

fix: ban header sync peer if no headers provided #3297

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions base_layer/core/src/base_node/sync/header_sync/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,6 @@ pub enum BlockHeaderSyncError {
InvalidProtocolResponse(String),
#[error("Headers did not form a chain. Expected {actual} to equal the previous hash {expected}")]
ChainLinkBroken { actual: String, expected: String },
#[error("Invalid remote peer behaviour: {0}")]
InvalidRemotePeerBehaviour(String),
}
14 changes: 14 additions & 0 deletions base_layer/core/src/base_node/sync/header_sync/synchronizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ impl<'a, B: BlockchainBackend + 'static> HeaderSynchronizer<'a, B> {
warn!(target: LOG_TARGET, "Chain split not found for peer {}.", peer);
self.ban_peer_long(peer, BanReason::ChainSplitNotFound).await?;
},
Err(err @ BlockHeaderSyncError::InvalidRemotePeerBehaviour(_)) => {
warn!(target: LOG_TARGET, "{}", err);
self.ban_peer_long(node_id, BanReason::PeerMisbehaviour(err.to_string()))
.await?;
},
Err(err @ BlockHeaderSyncError::InvalidBlockHeight { .. }) => {
warn!(target: LOG_TARGET, "{}", err);
self.ban_peer_long(node_id, BanReason::GeneralHeaderSyncFailure(err))
Expand Down Expand Up @@ -382,6 +387,13 @@ impl<'a, B: BlockchainBackend + 'static> HeaderSynchronizer<'a, B> {
peer
);

if headers.is_empty() {
return Err(BlockHeaderSyncError::InvalidRemotePeerBehaviour(format!(
"Remote peer {} advertised a better chain but did not return headers",
peer
)));
}

if fork_hash_index >= block_hashes.len() as u32 {
let _ = self
.ban_peer_long(peer.clone(), BanReason::SplitHashGreaterThanHashes {
Expand Down Expand Up @@ -677,6 +689,8 @@ enum BanReason {
GeneralHeaderSyncFailure(BlockHeaderSyncError),
#[error("Peer did not respond timeously during RPC negotiation")]
RpcNegotiationTimedOut,
#[error("Peer misbehaviour: {0}")]
PeerMisbehaviour(String),
}

struct ChainSplitInfo {
Expand Down