Add peer score adjustment msgs (#2901)

## Issue Addressed

N/A

## Proposed Changes

This PR adds the `msg` field to `Peer score adjusted` log messages. These `msg` fields help identify *why* a peer was banned.

Example:

```
Jan 11 04:18:48.096 DEBG Peer score adjusted                     score: -100.00, peer_id: 16Uiu2HAmQskxKWWGYfginwZ51n5uDbhvjHYnvASK7PZ5gBdLmzWj, msg: attn_unknown_head, service: libp2p
Jan 11 04:18:48.096 DEBG Peer score adjusted                     score: -27.86, peer_id: 16Uiu2HAmA7cCb3MemVDbK3MHZoSb7VN3cFUG3vuSZgnGesuVhPDE, msg: sync_past_slot, service: libp2p
Jan 11 04:18:48.096 DEBG Peer score adjusted                     score: -100.00, peer_id: 16Uiu2HAmQskxKWWGYfginwZ51n5uDbhvjHYnvASK7PZ5gBdLmzWj, msg: attn_unknown_head, service: libp2p
Jan 11 04:18:48.096 DEBG Peer score adjusted                     score: -28.86, peer_id: 16Uiu2HAmA7cCb3MemVDbK3MHZoSb7VN3cFUG3vuSZgnGesuVhPDE, msg: sync_past_slot, service: libp2p
Jan 11 04:18:48.096 DEBG Peer score adjusted                     score: -29.86, peer_id: 16Uiu2HAmA7cCb3MemVDbK3MHZoSb7VN3cFUG3vuSZgnGesuVhPDE, msg: sync_past_slot, service: libp2p
```

There is also a `libp2p_report_peer_msgs_total` metrics which allows us to see count of reports per `msg` tag. 

## Additional Info

NA
This commit is contained in:
Paul Hauner
2022-01-12 05:32:14 +00:00
parent 61f60bdf03
commit aaa5344eab
13 changed files with 378 additions and 110 deletions

View File

@@ -682,7 +682,7 @@ impl<T: BeaconChainTypes> BackFillSync<T> {
if let Some(peer_action) = peer_action {
for peer in self.participating_peers.drain() {
network.report_peer(peer, *peer_action);
network.report_peer(peer, *peer_action, "backfill_batch_failed");
}
}
self.fail_sync(BackFillError::BatchProcessingFailed(batch_id))
@@ -804,7 +804,11 @@ impl<T: BeaconChainTypes> BackFillSync<T> {
"batch_epoch" => id, "score_adjustment" => %action,
"original_peer" => %attempt.peer_id, "new_peer" => %processed_attempt.peer_id
);
network.report_peer(attempt.peer_id, action);
network.report_peer(
attempt.peer_id,
action,
"backfill_reprocessed_original_peer",
);
} else {
// The same peer corrected it's previous mistake. There was an error, so we
// negative score the original peer.
@@ -813,7 +817,11 @@ impl<T: BeaconChainTypes> BackFillSync<T> {
"batch_epoch" => id, "score_adjustment" => %action,
"original_peer" => %attempt.peer_id, "new_peer" => %processed_attempt.peer_id
);
network.report_peer(attempt.peer_id, action);
network.report_peer(
attempt.peer_id,
action,
"backfill_reprocessed_same_peer",
);
}
}
}

View File

@@ -369,8 +369,11 @@ impl<T: BeaconChainTypes> SyncManager<T> {
} else {
crit!(self.log, "Parent chain has no blocks");
}
self.network
.report_peer(peer_id, PeerAction::MidToleranceError);
self.network.report_peer(
peer_id,
PeerAction::MidToleranceError,
"bbroot_failed_chains",
);
return;
}
// add the block to response
@@ -388,8 +391,11 @@ impl<T: BeaconChainTypes> SyncManager<T> {
// tolerate this behaviour.
if !single_block_request.block_returned {
warn!(self.log, "Peer didn't respond with a block it referenced"; "referenced_block_hash" => %single_block_request.hash, "peer_id" => %peer_id);
self.network
.report_peer(peer_id, PeerAction::MidToleranceError);
self.network.report_peer(
peer_id,
PeerAction::MidToleranceError,
"bbroot_no_block",
);
}
return;
}
@@ -512,8 +518,11 @@ impl<T: BeaconChainTypes> SyncManager<T> {
warn!(self.log, "Single block lookup failed"; "outcome" => ?outcome);
// This could be a range of errors. But we couldn't process the block.
// For now we consider this a mid tolerance error.
self.network
.report_peer(peer_id, PeerAction::MidToleranceError);
self.network.report_peer(
peer_id,
PeerAction::MidToleranceError,
"single_block_lookup_failed",
);
}
}
}
@@ -836,8 +845,11 @@ impl<T: BeaconChainTypes> SyncManager<T> {
self.request_parent(parent_request);
// We do not tolerate these kinds of errors. We will accept a few but these are signs
// of a faulty peer.
self.network
.report_peer(peer, PeerAction::LowToleranceError);
self.network.report_peer(
peer,
PeerAction::LowToleranceError,
"parent_request_bad_hash",
);
} else {
// The last block in the queue is the only one that has not attempted to be processed yet.
//
@@ -907,6 +919,7 @@ impl<T: BeaconChainTypes> SyncManager<T> {
self.network.report_peer(
parent_request.last_submitted_peer,
PeerAction::MidToleranceError,
"parent_request_err",
);
}
}
@@ -945,6 +958,7 @@ impl<T: BeaconChainTypes> SyncManager<T> {
self.network.report_peer(
parent_request.last_submitted_peer,
PeerAction::LowToleranceError,
"request_parent_import_failed",
);
return; // drop the request
}
@@ -1112,8 +1126,11 @@ impl<T: BeaconChainTypes> SyncManager<T> {
// A peer sent an object (block or attestation) that referenced a parent.
// The processing of this chain failed.
self.failed_chains.insert(chain_head);
self.network
.report_peer(peer_id, PeerAction::MidToleranceError);
self.network.report_peer(
peer_id,
PeerAction::MidToleranceError,
"parent_lookup_failed",
);
}
}
}

View File

@@ -170,13 +170,14 @@ impl<T: EthSpec> SyncNetworkContext<T> {
}
/// Reports to the scoring algorithm the behaviour of a peer.
pub fn report_peer(&mut self, peer_id: PeerId, action: PeerAction) {
pub fn report_peer(&mut self, peer_id: PeerId, action: PeerAction, msg: &'static str) {
debug!(self.log, "Sync reporting peer"; "peer_id" => %peer_id, "action" => %action);
self.network_send
.send(NetworkMessage::ReportPeer {
peer_id,
action,
source: ReportSource::SyncService,
msg,
})
.unwrap_or_else(|e| {
warn!(self.log, "Could not report peer, channel failed"; "error"=> %e);

View File

@@ -533,7 +533,7 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
if let Some(peer_action) = peer_action {
for (peer, _) in self.peers.drain() {
network.report_peer(peer, *peer_action);
network.report_peer(peer, *peer_action, "batch_failed");
}
}
Err(RemoveChain::ChainFailed(batch_id))
@@ -624,7 +624,11 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
"batch_epoch" => id, "score_adjustment" => %action,
"original_peer" => %attempt.peer_id, "new_peer" => %processed_attempt.peer_id
);
network.report_peer(attempt.peer_id, action);
network.report_peer(
attempt.peer_id,
action,
"batch_reprocessed_original_peer",
);
} else {
// The same peer corrected it's previous mistake. There was an error, so we
// negative score the original peer.
@@ -633,7 +637,11 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
"batch_epoch" => id, "score_adjustment" => %action,
"original_peer" => %attempt.peer_id, "new_peer" => %processed_attempt.peer_id
);
network.report_peer(attempt.peer_id, action);
network.report_peer(
attempt.peer_id,
action,
"batch_reprocessed_same_peer",
);
}
}
}