Skip to content

Commit 73b4073

Browse files
authored
refactor(txns): inline validation logic and remove validation.rs (#16668)
Signed-off-by: 7suyash7 <[email protected]>
1 parent 1efc666 commit 73b4073

File tree

4 files changed

+15
-184
lines changed

4 files changed

+15
-184
lines changed

crates/net/network/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ pub use manager::NetworkManager;
168168
pub use metrics::TxTypesCounter;
169169
pub use network::{NetworkHandle, NetworkProtocols};
170170
pub use swarm::NetworkConnectionState;
171-
pub use transactions::MessageFilter;
172171

173172
/// re-export p2p interfaces
174173
pub use reth_network_p2p as p2p;

crates/net/network/src/transactions/fetcher.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,12 @@
2828
use super::{
2929
config::TransactionFetcherConfig,
3030
constants::{tx_fetcher::*, SOFT_LIMIT_COUNT_HASHES_IN_GET_POOLED_TRANSACTIONS_REQUEST},
31-
MessageFilter, PeerMetadata, PooledTransactions,
32-
SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESPONSE,
31+
PeerMetadata, PooledTransactions, SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESPONSE,
3332
};
3433
use crate::{
3534
cache::{LruCache, LruMap},
3635
duration_metered_exec,
3736
metrics::TransactionFetcherMetrics,
38-
transactions::{validation, PartiallyFilterMessage},
3937
};
4038
use alloy_consensus::transaction::PooledTransaction;
4139
use alloy_primitives::TxHash;
@@ -60,7 +58,6 @@ use std::{
6058
};
6159
use tokio::sync::{mpsc::error::TrySendError, oneshot, oneshot::error::RecvError};
6260
use tracing::trace;
63-
use validation::FilterOutcome;
6461

6562
/// The type responsible for fetching missing transactions from peers.
6663
///
@@ -85,8 +82,6 @@ pub struct TransactionFetcher<N: NetworkPrimitives = EthNetworkPrimitives> {
8582
pub hashes_pending_fetch: LruCache<TxHash>,
8683
/// Tracks all hashes in the transaction fetcher.
8784
pub hashes_fetch_inflight_and_pending_fetch: LruMap<TxHash, TxFetchMetadata, ByLength>,
88-
/// Filter for valid announcement and response data.
89-
pub(super) filter_valid_message: MessageFilter,
9085
/// Info on capacity of the transaction fetcher.
9186
pub info: TransactionFetcherInfo,
9287
#[doc(hidden)]
@@ -919,20 +914,19 @@ impl<N: NetworkPrimitives> TransactionFetcher<N> {
919914
//
920915
let unvalidated_payload_len = verified_payload.len();
921916

922-
let (validation_outcome, valid_payload) =
923-
self.filter_valid_message.partially_filter_valid_entries(verified_payload);
917+
let valid_payload = verified_payload.dedup();
924918

925919
// todo: validate based on announced tx size/type and report peer for sending
926920
// invalid response <https://github.com/paradigmxyz/reth/issues/6529>. requires
927921
// passing the rlp encoded length down from active session along with the decoded
928922
// tx.
929923

930-
if validation_outcome == FilterOutcome::ReportPeer {
924+
if valid_payload.len() != unvalidated_payload_len {
931925
trace!(target: "net::tx",
932-
peer_id=format!("{peer_id:#}"),
933-
unvalidated_payload_len,
934-
valid_payload_len=valid_payload.len(),
935-
"received invalid `PooledTransactions` response from peer, filtered out duplicate entries"
926+
peer_id=format!("{peer_id:#}"),
927+
unvalidated_payload_len,
928+
valid_payload_len=valid_payload.len(),
929+
"received `PooledTransactions` response from peer with duplicate entries, filtered them out"
936930
);
937931
}
938932
// valid payload will have at least one transaction at this point. even if the tx
@@ -1014,7 +1008,6 @@ impl<T: NetworkPrimitives> Default for TransactionFetcher<T> {
10141008
hashes_fetch_inflight_and_pending_fetch: LruMap::new(
10151009
DEFAULT_MAX_CAPACITY_CACHE_INFLIGHT_AND_PENDING_FETCH,
10161010
),
1017-
filter_valid_message: Default::default(),
10181011
info: TransactionFetcherInfo::default(),
10191012
metrics: Default::default(),
10201013
}

crates/net/network/src/transactions/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ pub mod constants;
88
pub mod fetcher;
99
/// Defines the [`TransactionPolicies`] trait for aggregating transaction-related policies.
1010
pub mod policy;
11-
pub mod validation;
1211

1312
pub use self::constants::{
1413
tx_fetcher::DEFAULT_SOFT_LIMIT_BYTE_SIZE_POOLED_TRANSACTIONS_RESP_ON_PACK_GET_POOLED_TRANSACTIONS_REQ,
@@ -20,7 +19,6 @@ pub use config::{
2019
TransactionPropagationPolicy, TransactionsManagerConfig,
2120
};
2221
use policy::{NetworkPolicies, TransactionPolicies};
23-
pub use validation::*;
2422

2523
pub(crate) use fetcher::{FetchEvent, TransactionFetcher};
2624

@@ -596,10 +594,15 @@ impl<Pool: TransactionPool, N: NetworkPrimitives, PBundle: TransactionPolicies>
596594
}
597595

598596
// 1. filter out spam
599-
let (validation_outcome, mut partially_valid_msg) =
600-
self.transaction_fetcher.filter_valid_message.partially_filter_valid_entries(msg);
597+
if msg.is_empty() {
598+
self.report_peer(peer_id, ReputationChangeKind::BadAnnouncement);
599+
return;
600+
}
601+
602+
let original_len = msg.len();
603+
let mut partially_valid_msg = msg.dedup();
601604

602-
if validation_outcome == FilterOutcome::ReportPeer {
605+
if partially_valid_msg.len() != original_len {
603606
self.report_peer(peer_id, ReputationChangeKind::BadAnnouncement);
604607
}
605608

crates/net/network/src/transactions/validation.rs

Lines changed: 0 additions & 164 deletions
This file was deleted.

0 commit comments

Comments
 (0)