Skip to content

Commit 12e55d0

Browse files
authoredApr 17, 2025
test: setup once for benchmark_fetch_pending_hashes to avoid excessive losses (#15783)
1 parent 58a20dc commit 12e55d0

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed
 

‎crates/net/network/benches/tx_manager_hash_fetching.rs

+12-16
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,25 @@ criterion_group!(
2828
);
2929

3030
pub fn benchmark_fetch_pending_hashes(group: &mut BenchmarkGroup<'_, WallTime>, peers_num: usize) {
31-
let setup = || {
32-
let mut tx_fetcher = TransactionFetcher::<EthNetworkPrimitives>::default();
33-
let mut peers = HashMap::default();
31+
let mut tx_fetcher = TransactionFetcher::<EthNetworkPrimitives>::default();
32+
let mut peers = HashMap::default();
3433

35-
for _i in 0..peers_num {
36-
// NOTE: the worst case, each tx in the cache belongs to a differenct peer.
37-
let peer = PeerId::random();
38-
let hash = B256::random();
34+
for _i in 0..peers_num {
35+
// NOTE: the worst case, each tx in the cache belongs to a differenct peer.
36+
let peer = PeerId::random();
37+
let hash = B256::random();
3938

40-
let (mut peer_data, _) = new_mock_session(peer, EthVersion::Eth66);
41-
peer_data.seen_transactions_mut().insert(hash);
42-
peers.insert(peer, peer_data);
39+
let (mut peer_data, _) = new_mock_session(peer, EthVersion::Eth66);
40+
peer_data.seen_transactions_mut().insert(hash);
41+
peers.insert(peer, peer_data);
4342

44-
buffer_hash_to_tx_fetcher(&mut tx_fetcher, hash, peer, 0, None);
45-
}
46-
47-
(tx_fetcher, peers)
48-
};
43+
buffer_hash_to_tx_fetcher(&mut tx_fetcher, hash, peer, 0, None);
44+
}
4945

5046
let group_id = format!("fetch pending hashes, peers num: {}", peers_num);
5147

5248
group.bench_function(group_id, |b| {
53-
b.iter_with_setup(setup, |(mut tx_fetcher, peers)| {
49+
b.iter(|| {
5450
tx_fetcher.on_fetch_pending_hashes(&peers, |_| true);
5551
});
5652
});

0 commit comments

Comments
 (0)