feat(net): make benchmark inputs deterministic (#13563)

This commit is contained in:
Hoa Nguyen
2024-12-27 21:16:25 +07:00
committed by GitHub
parent d644900a80
commit 8f81f0ccf2
2 changed files with 16 additions and 6 deletions

View File

@ -1,9 +1,11 @@
#![allow(missing_docs)]
use alloy_primitives::U256;
use alloy_primitives::{
private::proptest::test_runner::{RngAlgorithm, TestRng},
U256,
};
use criterion::*;
use futures::StreamExt;
use pprof::criterion::{Output, PProfProfiler};
use rand::thread_rng;
use reth_network::{test_utils::Testnet, NetworkEventListenerProvider};
use reth_network_api::Peers;
use reth_provider::test_utils::{ExtendedAccount, MockEthProvider};
@ -49,7 +51,9 @@ pub fn broadcast_ingress_bench(c: &mut Criterion) {
}
// prepare some transactions
let mut gen = TransactionGenerator::new(thread_rng());
let mut gen = TransactionGenerator::new(TestRng::deterministic_rng(
RngAlgorithm::ChaCha,
));
let num_broadcasts = 10;
for _ in 0..num_broadcasts {
for _ in 0..2 {

View File

@ -1,8 +1,11 @@
#![allow(missing_docs)]
use alloy_primitives::U256;
use alloy_primitives::{
private::proptest::test_runner::{RngAlgorithm, TestRng},
U256,
};
use criterion::*;
use pprof::criterion::{Output, PProfProfiler};
use rand::thread_rng;
use reth_network::{
test_utils::Testnet,
transactions::{
@ -61,7 +64,10 @@ pub fn tx_fetch_bench(c: &mut Criterion) {
let peer_pool = peer.pool().unwrap();
for _ in 0..num_tx_per_peer {
let mut gen = TransactionGenerator::new(thread_rng());
let mut gen = TransactionGenerator::new(
TestRng::deterministic_rng(RngAlgorithm::ChaCha),
);
let tx = gen.gen_eip1559_pooled();
let sender = tx.sender();
provider.add_account(