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

The ban peer log will now supply n reason why the peer was banned #1638

Merged
merged 1 commit into from
Mar 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion base_layer/core/src/base_node/states/block_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,20 @@ async fn find_chain_split_height<B: BlockchainBackend + 'static>(
if prev_header.height + 1 == header.height {
return Ok(header.height);
} else {
warn!(
target: LOG_TARGET,
"Banning peer {} from local node, because they supplied invalid chain link", sync_peer
);
ban_sync_peer(shared, sync_peers, sync_peer.clone()).await?;
return Err(BlockSyncError::InvalidChainLink);
}
}
}
}
warn!(
target: LOG_TARGET,
"Banning all peers from local node, because they could not provide a valid chain link",
);
ban_all_sync_peers(shared, sync_peers).await?;
Err(BlockSyncError::ForkChainNotLinked)
}
Expand Down Expand Up @@ -364,6 +372,10 @@ async fn request_and_add_blocks<B: BlockchainBackend + 'static>(
"Invalid block {} received from peer. Retrying",
block_hash.to_hex(),
);
warn!(
target: LOG_TARGET,
"Banning peer {} from local node, because they supplied invalid block", sync_peer
);
ban_sync_peer(shared, sync_peers, sync_peer.clone()).await?;
break;
},
Expand All @@ -373,6 +385,10 @@ async fn request_and_add_blocks<B: BlockchainBackend + 'static>(
"Validation on block {} from peer failed. Retrying",
block_hash.to_hex(),
);
warn!(
target: LOG_TARGET,
"Banning peer {} from local node, because they supplied invalid block", sync_peer
);
ban_sync_peer(shared, sync_peers, sync_peer.clone()).await?;
break;
},
Expand Down Expand Up @@ -419,6 +435,10 @@ async fn request_blocks<B: BlockchainBackend + 'static>(
return Ok((blocks, sync_peer));
} else {
debug!(target: LOG_TARGET, "This was NOT the blocks we were expecting.");
warn!(
target: LOG_TARGET,
"Banning peer {} from local node, because they supplied the incorrect blocks", sync_peer
);
ban_sync_peer(shared, sync_peers, sync_peer.clone()).await?;
}
} else {
Expand All @@ -428,6 +448,11 @@ async fn request_blocks<B: BlockchainBackend + 'static>(
block_nums.len(),
hist_blocks.len()
);
warn!(
target: LOG_TARGET,
"Banning peer {} from local node, because they supplied the incorrect number of blocks",
sync_peer
);
ban_sync_peer(shared, sync_peers, sync_peer.clone()).await?;
}
},
Expand Down Expand Up @@ -486,6 +511,10 @@ async fn request_headers<B: BlockchainBackend + 'static>(
return Ok((headers, sync_peer));
} else {
debug!(target: LOG_TARGET, "This was NOT the headers we were expecting.");
warn!(
target: LOG_TARGET,
"Banning peer {} from local node, because they supplied the incorrect headers", sync_peer
);
ban_sync_peer(shared, sync_peers, sync_peer.clone()).await?;
}
} else {
Expand All @@ -495,11 +524,20 @@ async fn request_headers<B: BlockchainBackend + 'static>(
block_nums.len(),
headers.len()
);
warn!(
target: LOG_TARGET,
"Banning peer {} from local node, because they supplied the incorrect number of headers",
sync_peer
);
ban_sync_peer(shared, sync_peers, sync_peer.clone()).await?;
}
},
Err(CommsInterfaceError::UnexpectedApiResponse) => {
debug!(target: LOG_TARGET, "Remote node provided an unexpected api response.",);
warn!(
target: LOG_TARGET,
"Banning peer {} from local node, because they provided an unexpected api response", sync_peer
);
ban_sync_peer(shared, sync_peers, sync_peer.clone()).await?;
},
Err(CommsInterfaceError::RequestTimedOut) => {
Expand Down Expand Up @@ -567,7 +605,6 @@ async fn ban_sync_peer<B: BlockchainBackend + 'static>(
sync_peer: NodeId,
) -> Result<(), BlockSyncError>
{
warn!(target: LOG_TARGET, "Banning peer {} from local node.", sync_peer);
sync_peers.retain(|p| *p != sync_peer);
let peer = shared.peer_manager.find_by_node_id(&sync_peer).await?;
shared.peer_manager.set_banned(&peer.public_key, true).await?;
Expand All @@ -585,6 +622,7 @@ async fn ban_all_sync_peers<B: BlockchainBackend + 'static>(
) -> Result<(), BlockSyncError>
{
while !sync_peers.is_empty() {
warn!(target: LOG_TARGET, "Banning peer {} from local node.", sync_peers[0]);
ban_sync_peer(shared, sync_peers, sync_peers[0].clone()).await?;
}
Ok(())
Expand Down