feat: add metrics for already seen txs and hashes (#2467)

This commit is contained in:
Matthias Seitz
2023-05-01 10:25:54 +02:00
committed by GitHub
parent 005ebd8511
commit 0702a5e6fb
2 changed files with 16 additions and 1 deletions

View File

@ -45,6 +45,10 @@ pub struct TransactionsManagerMetrics {
pub(crate) propagated_transactions: Counter,
/// Total number of reported bad transactions
pub(crate) reported_bad_transactions: Counter,
/// Total number of messages with already seen hashes
pub(crate) messages_with_already_seen_hashes: Counter,
/// Total number of messages with already seen full transactions
pub(crate) messages_with_already_seen_transactions: Counter,
}
/// Metrics for Disconnection types

View File

@ -32,7 +32,7 @@ use std::{
};
use tokio::sync::{mpsc, oneshot};
use tokio_stream::wrappers::{ReceiverStream, UnboundedReceiverStream};
use tracing::trace;
use tracing::{debug, trace};
/// Cache limit of transactions to keep track of for a single peer.
const PEER_TRANSACTION_CACHE_LIMIT: usize = 1024 * 10;
@ -311,9 +311,15 @@ where
if peer.request_tx.try_send(req).is_ok() {
self.inflight_requests.push(GetPooledTxRequest { peer_id, response: rx })
}
if num_already_seen > 0 {
self.metrics.messages_with_already_seen_hashes.increment(1);
debug!(target: "net::tx", num_hashes=%num_already_seen, ?peer_id, client=?peer.client_version, "Peer sent already seen hashes");
}
}
if num_already_seen > 0 {
self.metrics.messages_with_already_seen_hashes.increment(1);
self.report_bad_message(peer_id);
}
}
@ -447,6 +453,11 @@ where
}
}
}
if num_already_seen > 0 {
self.metrics.messages_with_already_seen_transactions.increment(1);
debug!(target: "net::tx", num_txs=%num_already_seen, ?peer_id, client=?peer.client_version, "Peer sent already seen transactions");
}
}
if has_bad_transactions || num_already_seen > 0 {