Skip to content

Commit

Permalink
Verify tx response data against request
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane committed Feb 6, 2024
1 parent 020ba53 commit 482c157
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion crates/net/network/src/transactions/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use reth_interfaces::p2p::error::{RequestError, RequestResult};
use reth_primitives::{PeerId, PooledTransactionsElement, TxHash};
use schnellru::{ByLength, Unlimited};
use std::{
collections::HashMap,
collections::{HashMap, HashSet},
num::NonZeroUsize,
pin::Pin,
task::{Context, Poll},
Expand Down Expand Up @@ -816,6 +816,22 @@ impl Stream for TransactionFetcher {
true
});

if transactions.0.is_empty() {
// todo: report peer for sending empty response
}

let transactions_len = transactions.0.len();
let unique_fetched = transactions.0.into_iter().collect::<HashSet<_>>();
if unique_fetched.len() != transactions_len {
// todo: report peer for sending duplicates
}

for tx in unique_fetched {
if !requested_hashes.remove(&tx.hash()) {
// todo: report peer for sending hash that weren't requested
}
}

self.remove_from_unknown_hashes(fetched);
// buffer left over hashes
self.buffer_hashes_for_retry(requested_hashes, &peer_id);
Expand Down

0 comments on commit 482c157

Please sign in to comment.