Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
feat: report different request errors (paradigmxyz#3857)
Browse files Browse the repository at this point in the history
  • Loading branch information
altugbakan authored and merklefruit committed Jul 27, 2023
1 parent 5d953cc commit 7423282
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions crates/net/network/src/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use reth_eth_wire::{
EthVersion, GetPooledTransactions, NewPooledTransactionHashes, NewPooledTransactionHashes66,
NewPooledTransactionHashes68, PooledTransactions, Transactions,
};
use reth_interfaces::{p2p::error::RequestResult, sync::SyncStateProvider};
use reth_interfaces::{
p2p::error::{RequestError, RequestResult},
sync::SyncStateProvider,
};
use reth_metrics::common::mpsc::UnboundedMeteredReceiver;
use reth_network_api::{Peers, ReputationChangeKind};
use reth_primitives::{
Expand Down Expand Up @@ -472,10 +475,22 @@ where
}
}

fn report_bad_message(&self, peer_id: PeerId) {
trace!(target: "net::tx", ?peer_id, "Penalizing peer for bad transaction");
fn report_peer(&self, peer_id: PeerId, kind: ReputationChangeKind) {
trace!(target: "net::tx", ?peer_id, ?kind);
self.network.reputation_change(peer_id, kind);
self.metrics.reported_bad_transactions.increment(1);
self.network.reputation_change(peer_id, ReputationChangeKind::BadTransactions);
}

fn on_request_error(&self, peer_id: PeerId, req_err: RequestError) {
let kind = match req_err {
RequestError::UnsupportedCapability => ReputationChangeKind::BadProtocol,
RequestError::Timeout => ReputationChangeKind::Timeout,
RequestError::ChannelClosed | RequestError::ConnectionDropped => {
ReputationChangeKind::Dropped
}
RequestError::BadResponse => ReputationChangeKind::BadTransactions,
};
self.report_peer(peer_id, kind);
}

fn report_already_seen(&self, peer_id: PeerId) {
Expand All @@ -492,7 +507,7 @@ where
fn on_bad_import(&mut self, hash: TxHash) {
if let Some(peers) = self.transactions_by_peers.remove(&hash) {
for peer_id in peers {
self.report_bad_message(peer_id);
self.report_peer(peer_id, ReputationChangeKind::BadTransactions);
}
}
}
Expand Down Expand Up @@ -537,11 +552,11 @@ where
Poll::Ready(Ok(Ok(txs))) => {
this.import_transactions(req.peer_id, txs.0, TransactionSource::Response);
}
Poll::Ready(Ok(Err(_))) => {
this.report_bad_message(req.peer_id);
Poll::Ready(Ok(Err(req_err))) => {
this.on_request_error(req.peer_id, req_err);
}
Poll::Ready(Err(_)) => {
this.report_bad_message(req.peer_id);
this.on_request_error(req.peer_id, RequestError::ConnectionDropped)
}
}
}
Expand Down

0 comments on commit 7423282

Please sign in to comment.