From f07413b209bc95cc1393e38d4e6fce6bd6f25d3a Mon Sep 17 00:00:00 2001 From: SW van Heerden Date: Tue, 31 Mar 2020 14:31:22 +0200 Subject: [PATCH] The ban peer log will now supply n reason why the peer was banned --- .../core/src/base_node/states/block_sync.rs | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/base_layer/core/src/base_node/states/block_sync.rs b/base_layer/core/src/base_node/states/block_sync.rs index 457abf926e..39a09671d2 100644 --- a/base_layer/core/src/base_node/states/block_sync.rs +++ b/base_layer/core/src/base_node/states/block_sync.rs @@ -325,12 +325,20 @@ async fn find_chain_split_height( 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) } @@ -364,6 +372,10 @@ async fn request_and_add_blocks( "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; }, @@ -373,6 +385,10 @@ async fn request_and_add_blocks( "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; }, @@ -419,6 +435,10 @@ async fn request_blocks( 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 { @@ -428,6 +448,11 @@ async fn request_blocks( 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?; } }, @@ -486,6 +511,10 @@ async fn request_headers( 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 { @@ -495,11 +524,20 @@ async fn request_headers( 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) => { @@ -567,7 +605,6 @@ async fn ban_sync_peer( 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?; @@ -585,6 +622,7 @@ async fn ban_all_sync_peers( ) -> 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(())