chore: alloy 0.14 (#15635)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Yash Atreya
2025-04-11 11:58:57 +05:30
committed by GitHub
parent 2563e93d95
commit 58fe204ff2
126 changed files with 968 additions and 868 deletions

View File

@@ -34,7 +34,7 @@ schnellru.workspace = true
tracing.workspace = true
thiserror.workspace = true
parking_lot.workspace = true
rand = { workspace = true, optional = true }
rand_08 = { workspace = true, optional = true }
generic-array.workspace = true
serde = { workspace = true, optional = true }
itertools.workspace = true
@@ -42,7 +42,7 @@ itertools.workspace = true
[dev-dependencies]
secp256k1 = { workspace = true, features = ["rand"] }
assert_matches.workspace = true
rand.workspace = true
rand_08.workspace = true
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
reth-tracing.workspace = true
@@ -55,8 +55,8 @@ serde = [
"enr/serde",
"generic-array/serde",
"parking_lot/serde",
"rand?/serde",
"rand_08?/serde",
"secp256k1/serde",
"reth-ethereum-forks/serde",
]
test-utils = ["dep:rand"]
test-utils = ["dep:rand_08"]

View File

@@ -214,15 +214,13 @@ impl Discv4 {
///
/// ```
/// # use std::io;
/// use rand::thread_rng;
/// use reth_discv4::{Discv4, Discv4Config};
/// use reth_network_peers::{pk2id, NodeRecord, PeerId};
/// use secp256k1::SECP256K1;
/// use std::{net::SocketAddr, str::FromStr};
/// # async fn t() -> io::Result<()> {
/// // generate a (random) keypair
/// let mut rng = thread_rng();
/// let (secret_key, pk) = SECP256K1.generate_keypair(&mut rng);
/// let (secret_key, pk) = SECP256K1.generate_keypair(&mut rand_08::thread_rng());
/// let id = pk2id(&pk);
///
/// let socket = SocketAddr::from_str("0.0.0.0:0").unwrap();
@@ -2399,7 +2397,7 @@ mod tests {
use crate::test_utils::{create_discv4, create_discv4_with_config, rng_endpoint, rng_record};
use alloy_primitives::hex;
use alloy_rlp::{Decodable, Encodable};
use rand::{thread_rng, Rng};
use rand_08::Rng;
use reth_ethereum_forks::{EnrForkIdEntry, ForkHash};
use reth_network_peers::mainnet_nodes;
use std::future::poll_fn;
@@ -2534,7 +2532,7 @@ mod tests {
#[tokio::test]
async fn test_mapped_ipv4() {
reth_tracing::init_test_tracing();
let mut rng = thread_rng();
let mut rng = rand_08::thread_rng();
let config = Discv4Config::builder().build();
let (_discv4, mut service) = create_discv4_with_config(config).await;
@@ -2549,8 +2547,8 @@ mod tests {
enr_sq: Some(rng.gen()),
};
let id = PeerId::random_with(&mut rng);
service.on_ping(ping, addr, id, rng.gen());
let id = PeerId::random();
service.on_ping(ping, addr, id, B256::random());
let key = kad_key(id);
match service.kbuckets.entry(&key) {
@@ -2566,7 +2564,7 @@ mod tests {
#[tokio::test]
async fn test_respect_ping_expiration() {
reth_tracing::init_test_tracing();
let mut rng = thread_rng();
let mut rng = rand_08::thread_rng();
let config = Discv4Config::builder().build();
let (_discv4, mut service) = create_discv4_with_config(config).await;
@@ -2581,8 +2579,8 @@ mod tests {
enr_sq: Some(rng.gen()),
};
let id = PeerId::random_with(&mut rng);
service.on_ping(ping, addr, id, rng.gen());
let id = PeerId::random();
service.on_ping(ping, addr, id, B256::random());
let key = kad_key(id);
match service.kbuckets.entry(&key) {
@@ -2979,7 +2977,7 @@ mod tests {
#[test]
fn test_insert() {
let local_node_record = rng_record(&mut rand::thread_rng());
let local_node_record = rng_record(&mut rand_08::thread_rng());
let mut kbuckets: KBucketsTable<NodeKey, NodeEntry> = KBucketsTable::new(
NodeKey::from(&local_node_record).into(),
Duration::from_secs(60),
@@ -2988,7 +2986,7 @@ mod tests {
None,
);
let new_record = rng_record(&mut rand::thread_rng());
let new_record = rng_record(&mut rand_08::thread_rng());
let key = kad_key(new_record.id);
match kbuckets.entry(&key) {
kbucket::Entry::Absent(entry) => {

View File

@@ -594,12 +594,12 @@ mod tests {
use alloy_primitives::hex;
use assert_matches::assert_matches;
use enr::EnrPublicKey;
use rand::{thread_rng, Rng, RngCore};
use rand_08::{thread_rng as rng, Rng, RngCore};
use reth_ethereum_forks::ForkHash;
#[test]
fn test_endpoint_ipv_v4() {
let mut rng = thread_rng();
let mut rng = rng();
for _ in 0..100 {
let mut ip = [0u8; 4];
rng.fill_bytes(&mut ip);
@@ -616,7 +616,7 @@ mod tests {
#[test]
fn test_endpoint_ipv_64() {
let mut rng = thread_rng();
let mut rng = rng();
for _ in 0..100 {
let mut ip = [0u8; 16];
rng.fill_bytes(&mut ip);
@@ -633,7 +633,7 @@ mod tests {
#[test]
fn test_ping_message() {
let mut rng = thread_rng();
let mut rng = rng();
for _ in 0..100 {
let mut ip = [0u8; 16];
rng.fill_bytes(&mut ip);
@@ -651,7 +651,7 @@ mod tests {
#[test]
fn test_ping_message_with_enr() {
let mut rng = thread_rng();
let mut rng = rng();
for _ in 0..100 {
let mut ip = [0u8; 16];
rng.fill_bytes(&mut ip);
@@ -669,13 +669,13 @@ mod tests {
#[test]
fn test_pong_message() {
let mut rng = thread_rng();
let mut rng = rng();
for _ in 0..100 {
let mut ip = [0u8; 16];
rng.fill_bytes(&mut ip);
let msg = Pong {
to: rng_endpoint(&mut rng),
echo: rng.gen(),
echo: B256::random(),
expire: rng.gen(),
enr_sq: None,
};
@@ -687,13 +687,13 @@ mod tests {
#[test]
fn test_pong_message_with_enr() {
let mut rng = thread_rng();
let mut rng = rng();
for _ in 0..100 {
let mut ip = [0u8; 16];
rng.fill_bytes(&mut ip);
let msg = Pong {
to: rng_endpoint(&mut rng),
echo: rng.gen(),
echo: B256::random(),
expire: rng.gen(),
enr_sq: Some(rng.gen()),
};
@@ -705,7 +705,7 @@ mod tests {
#[test]
fn test_hash_mismatch() {
let mut rng = thread_rng();
let mut rng = rng();
let msg = rng_message(&mut rng);
let (secret_key, _) = SECP256K1.generate_keypair(&mut rng);
let (buf, _) = msg.encode(&secret_key);
@@ -722,7 +722,7 @@ mod tests {
#[test]
fn neighbours_max_ipv4() {
let mut rng = thread_rng();
let mut rng = rng();
let msg = Message::Neighbours(Neighbours {
nodes: std::iter::repeat_with(|| rng_ipv4_record(&mut rng)).take(16).collect(),
expire: rng.gen(),
@@ -736,7 +736,7 @@ mod tests {
#[test]
fn neighbours_max_nodes() {
let mut rng = thread_rng();
let mut rng = rng();
for _ in 0..1000 {
let msg = Message::Neighbours(Neighbours {
nodes: std::iter::repeat_with(|| rng_ipv6_record(&mut rng))
@@ -764,7 +764,7 @@ mod tests {
#[test]
fn test_encode_decode_message() {
let mut rng = thread_rng();
let mut rng = rng();
for _ in 0..100 {
let msg = rng_message(&mut rng);
let (secret_key, pk) = SECP256K1.generate_keypair(&mut rng);
@@ -798,7 +798,7 @@ mod tests {
use enr::secp256k1::SecretKey;
use std::net::Ipv4Addr;
let mut rng = rand::rngs::OsRng;
let mut rng = rand_08::rngs::OsRng;
let key = SecretKey::new(&mut rng);
let ip = Ipv4Addr::new(127, 0, 0, 1);
let tcp = 3000;
@@ -816,7 +816,7 @@ mod tests {
builder.build(&key).unwrap()
};
let enr_response = EnrResponse { request_hash: rng.gen(), enr };
let enr_response = EnrResponse { request_hash: B256::random(), enr };
let mut buf = Vec::new();
enr_response.encode(&mut buf);
@@ -908,7 +908,7 @@ mod tests {
use enr::{secp256k1::SecretKey, EnrPublicKey};
use std::net::Ipv4Addr;
let key = SecretKey::new(&mut rand::rngs::OsRng);
let key = SecretKey::new(&mut rand_08::rngs::OsRng);
let ip = Ipv4Addr::new(127, 0, 0, 1);
let tcp = 3000;

View File

@@ -1,12 +1,14 @@
//! Mock discovery support
// TODO(rand): update ::random calls after rand_09 migration
use crate::{
proto::{FindNode, Message, Neighbours, NodeEndpoint, Packet, Ping, Pong},
receive_loop, send_loop, Discv4, Discv4Config, Discv4Service, EgressSender, IngressEvent,
IngressReceiver, PeerId, SAFE_MAX_DATAGRAM_NEIGHBOUR_RECORDS,
};
use alloy_primitives::{hex, B256};
use rand::{thread_rng, Rng, RngCore};
use alloy_primitives::{hex, B256, B512};
use rand_08::{thread_rng, Rng, RngCore};
use reth_ethereum_forks::{ForkHash, ForkId};
use reth_network_peers::{pk2id, NodeRecord};
use secp256k1::{SecretKey, SECP256K1};
@@ -265,7 +267,8 @@ pub fn rng_endpoint(rng: &mut impl Rng) -> NodeEndpoint {
/// Generates a random [`NodeRecord`] using the provided random number generator.
pub fn rng_record(rng: &mut impl RngCore) -> NodeRecord {
let NodeEndpoint { address, udp_port, tcp_port } = rng_endpoint(rng);
NodeRecord { address, tcp_port, udp_port, id: rng.gen() }
// TODO(rand)
NodeRecord { address, tcp_port, udp_port, id: B512::random() }
}
/// Generates a random IPv6 [`NodeRecord`] using the provided random number generator.
@@ -273,7 +276,8 @@ pub fn rng_ipv6_record(rng: &mut impl RngCore) -> NodeRecord {
let mut ip = [0u8; 16];
rng.fill_bytes(&mut ip);
let address = IpAddr::V6(ip.into());
NodeRecord { address, tcp_port: rng.gen(), udp_port: rng.gen(), id: rng.gen() }
// TODO(rand)
NodeRecord { address, tcp_port: rng.gen(), udp_port: rng.gen(), id: B512::random() }
}
/// Generates a random IPv4 [`NodeRecord`] using the provided random number generator.
@@ -281,7 +285,8 @@ pub fn rng_ipv4_record(rng: &mut impl RngCore) -> NodeRecord {
let mut ip = [0u8; 4];
rng.fill_bytes(&mut ip);
let address = IpAddr::V4(ip.into());
NodeRecord { address, tcp_port: rng.gen(), udp_port: rng.gen(), id: rng.gen() }
// TODO(rand)
NodeRecord { address, tcp_port: rng.gen(), udp_port: rng.gen(), id: B512::random() }
}
/// Generates a random [`Message`] using the provided random number generator.
@@ -295,11 +300,11 @@ pub fn rng_message(rng: &mut impl RngCore) -> Message {
}),
2 => Message::Pong(Pong {
to: rng_endpoint(rng),
echo: rng.gen(),
echo: B256::random(),
expire: rng.gen(),
enr_sq: None,
}),
3 => Message::FindNode(FindNode { id: rng.gen(), expire: rng.gen() }),
3 => Message::FindNode(FindNode { id: B512::random(), expire: rng.gen() }),
4 => {
let num: usize = rng.gen_range(1..=SAFE_MAX_DATAGRAM_NEIGHBOUR_RECORDS);
Message::Neighbours(Neighbours {

View File

@@ -43,3 +43,4 @@ metrics.workspace = true
reth-tracing.workspace = true
tokio = { workspace = true, features = ["rt-multi-thread"] }
secp256k1 = { workspace = true, features = ["std", "rand"] }
rand_08.workspace = true

View File

@@ -600,7 +600,7 @@ pub fn get_lookup_target(
target[byte] ^= 1 << (7 - bit);
// Randomize the bits after the target.
let mut rng = rand::thread_rng();
let mut rng = rand::rng();
// Randomize remaining bits in the byte we modified.
if bit < 7 {
// Compute the mask of the bits that need to be randomized.
@@ -608,7 +608,7 @@ pub fn get_lookup_target(
// Clear.
target[byte] &= !bits_to_randomize;
// Randomize.
target[byte] |= rng.gen::<u8>() & bits_to_randomize;
target[byte] |= rng.random::<u8>() & bits_to_randomize;
}
// Randomize remaining bytes.
rng.fill_bytes(&mut target[byte + 1..]);
@@ -655,7 +655,7 @@ pub async fn lookup(
mod test {
use super::*;
use ::enr::{CombinedKey, EnrKey};
use rand::thread_rng;
use rand_08::thread_rng;
use reth_chainspec::MAINNET;
use tracing::trace;

View File

@@ -707,7 +707,7 @@ mod tests {
// calculate min for chunk byte length range, pick a lower bound that guarantees at least
// one block will be read
let chunk_byte_len = rand::thread_rng().gen_range(2000..=10_000);
let chunk_byte_len = rand::rng().random_range(2000..=10_000);
trace!(target: "downloaders::file::test", chunk_byte_len);
// init reader

View File

@@ -31,10 +31,10 @@ typenum.workspace = true
byteorder.workspace = true
# crypto
rand.workspace = true
ctr.workspace = true
digest.workspace = true
secp256k1 = { workspace = true, features = ["global-context", "std", "recovery", "rand"] }
rand_08.workspace = true
concat-kdf.workspace = true
sha2.workspace = true
sha3.workspace = true

View File

@@ -15,7 +15,7 @@ use alloy_rlp::{Encodable, Rlp, RlpEncodable, RlpMaxEncodedLen};
use byteorder::{BigEndian, ByteOrder, ReadBytesExt};
use ctr::Ctr64BE;
use digest::{crypto_common::KeyIvInit, Digest};
use rand::{thread_rng, Rng};
use rand_08::{thread_rng as rng, Rng};
use reth_network_peers::{id2pk, pk2id};
use secp256k1::{
ecdsa::{RecoverableSignature, RecoveryId},
@@ -312,8 +312,9 @@ impl ECIES {
/// Create a new ECIES client with the given static secret key and remote peer ID.
pub fn new_client(secret_key: SecretKey, remote_id: PeerId) -> Result<Self, ECIESError> {
let mut rng = thread_rng();
let nonce = rng.gen();
// TODO(rand): use rng for nonce
let mut rng = rng();
let nonce = B256::random();
let ephemeral_secret_key = SecretKey::new(&mut rng);
Self::new_static_client(secret_key, remote_id, nonce, ephemeral_secret_key)
}
@@ -354,8 +355,8 @@ impl ECIES {
/// Create a new ECIES server with the given static secret key.
pub fn new_server(secret_key: SecretKey) -> Result<Self, ECIESError> {
let mut rng = thread_rng();
let nonce = rng.gen();
let mut rng = rng();
let nonce = B256::random();
let ephemeral_secret_key = SecretKey::new(&mut rng);
Self::new_static_server(secret_key, nonce, ephemeral_secret_key)
}
@@ -366,7 +367,7 @@ impl ECIES {
}
fn encrypt_message(&self, data: &[u8], out: &mut BytesMut) {
let mut rng = thread_rng();
let mut rng = rng();
out.reserve(secp256k1::constants::UNCOMPRESSED_PUBLIC_KEY_SIZE + 16 + data.len() + 32);
@@ -382,7 +383,7 @@ impl ECIES {
let enc_key = B128::from_slice(&key[..16]);
let mac_key = sha256(&key[16..32]);
let iv: B128 = rng.gen();
let iv = B128::random();
let mut encryptor = Ctr64BE::<Aes128>::new((&enc_key.0).into(), (&iv.0).into());
let mut encrypted = data.to_vec();
@@ -442,7 +443,7 @@ impl ECIES {
}
.encode(&mut out);
out.resize(out.len() + thread_rng().gen_range(100..=300), 0);
out.resize(out.len() + rng().gen_range(100..=300), 0);
out
}
@@ -763,7 +764,7 @@ mod tests {
#[test]
fn communicate() {
let mut rng = thread_rng();
let mut rng = rng();
let server_secret_key = SecretKey::new(&mut rng);
let server_public_key = PublicKey::from_secret_key(SECP256K1, &server_secret_key);
let client_secret_key = SecretKey::new(&mut rng);

View File

@@ -180,7 +180,7 @@ mod tests {
async fn can_write_and_read() {
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let addr = listener.local_addr().unwrap();
let server_key = SecretKey::new(&mut rand::thread_rng());
let server_key = SecretKey::new(&mut rand_08::thread_rng());
let handle = tokio::spawn(async move {
// roughly based off of the design of tokio::net::TcpListener
@@ -195,7 +195,7 @@ mod tests {
// create the server pubkey
let server_id = pk2id(&server_key.public_key(SECP256K1));
let client_key = SecretKey::new(&mut rand::thread_rng());
let client_key = SecretKey::new(&mut rand_08::thread_rng());
let outgoing = TcpStream::connect(addr).await.unwrap();
let mut client_stream =
ECIESStream::connect(outgoing, client_key, server_id).await.unwrap();
@@ -209,7 +209,7 @@ mod tests {
async fn connection_should_timeout() {
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let addr = listener.local_addr().unwrap();
let server_key = SecretKey::new(&mut rand::thread_rng());
let server_key = SecretKey::new(&mut rand_08::thread_rng());
let _handle = tokio::spawn(async move {
// Delay accepting the connection for longer than the client's timeout period
@@ -225,7 +225,7 @@ mod tests {
// create the server pubkey
let server_id = pk2id(&server_key.public_key(SECP256K1));
let client_key = SecretKey::new(&mut rand::thread_rng());
let client_key = SecretKey::new(&mut rand_08::thread_rng());
let outgoing = TcpStream::connect(addr).await.unwrap();
// Attempt to connect, expecting a timeout due to the server's delayed response

View File

@@ -97,7 +97,7 @@ mod tests {
};
use alloy_consensus::{Header, TxLegacy};
use alloy_eips::BlockHashOrNumber;
use alloy_primitives::{hex, PrimitiveSignature as Signature, TxKind, U256};
use alloy_primitives::{hex, Signature, TxKind, U256};
use alloy_rlp::{Decodable, Encodable};
use reth_ethereum_primitives::{BlockBody, Transaction, TransactionSigned};
use std::str::FromStr;

View File

@@ -770,7 +770,7 @@ mod tests {
use super::*;
use alloy_consensus::Typed2718;
use alloy_eips::eip2718::Encodable2718;
use alloy_primitives::{b256, hex, PrimitiveSignature as Signature, U256};
use alloy_primitives::{b256, hex, Signature, U256};
use reth_ethereum_primitives::{Transaction, TransactionSigned};
use std::str::FromStr;

View File

@@ -582,12 +582,12 @@ mod tests {
#[test]
fn init_custom_status_fields() {
let mut rng = rand::thread_rng();
let head_hash = rng.gen();
let total_difficulty = U256::from(rng.gen::<u64>());
let mut rng = rand::rng();
let head_hash = rng.random();
let total_difficulty = U256::from(rng.random::<u64>());
// create a genesis that has a random part, so we can check that the hash is preserved
let genesis = Genesis { nonce: rng.gen(), ..Default::default() };
let genesis = Genesis { nonce: rng.random(), ..Default::default() };
// build head
let head = Head {

View File

@@ -86,7 +86,7 @@ impl<T> Default for PooledTransactions<T> {
mod tests {
use crate::{message::RequestPair, GetPooledTransactions, PooledTransactions};
use alloy_consensus::{transaction::PooledTransaction, TxEip1559, TxLegacy};
use alloy_primitives::{hex, PrimitiveSignature as Signature, TxKind, U256};
use alloy_primitives::{hex, Signature, TxKind, U256};
use alloy_rlp::{Decodable, Encodable};
use reth_chainspec::MIN_TRANSACTION_GAS;
use reth_ethereum_primitives::{Transaction, TransactionSigned};

View File

@@ -54,6 +54,7 @@ tokio = { workspace = true, features = ["rt", "rt-multi-thread"] }
tokio-util = { workspace = true, features = ["io", "codec"] }
rand.workspace = true
secp256k1 = { workspace = true, features = ["global-context", "std", "recovery"] }
rand_08.workspace = true
arbitrary = { workspace = true, features = ["derive"] }
proptest.workspace = true
@@ -87,6 +88,7 @@ serde = [
"reth-primitives-traits/serde",
"reth-ethereum-forks/serde",
"alloy-consensus/serde",
"rand_08/serde",
]
[[test]]

View File

@@ -536,7 +536,7 @@ mod tests {
async fn can_write_and_read_ecies() {
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let local_addr = listener.local_addr().unwrap();
let server_key = SecretKey::new(&mut rand::thread_rng());
let server_key = SecretKey::new(&mut rand_08::thread_rng());
let test_msg = EthMessage::<EthNetworkPrimitives>::NewBlockHashes(
vec![
BlockHashNumber { hash: B256::random(), number: 5 },
@@ -560,7 +560,7 @@ mod tests {
// create the server pubkey
let server_id = pk2id(&server_key.public_key(SECP256K1));
let client_key = SecretKey::new(&mut rand::thread_rng());
let client_key = SecretKey::new(&mut rand_08::thread_rng());
let outgoing = TcpStream::connect(local_addr).await.unwrap();
let outgoing = ECIESStream::connect(outgoing, client_key, server_id).await.unwrap();
@@ -578,7 +578,7 @@ mod tests {
// create tcpstream
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let local_addr = listener.local_addr().unwrap();
let server_key = SecretKey::new(&mut rand::thread_rng());
let server_key = SecretKey::new(&mut rand_08::thread_rng());
let test_msg = EthMessage::<EthNetworkPrimitives>::NewBlockHashes(
vec![
BlockHashNumber { hash: B256::random(), number: 5 },
@@ -631,7 +631,7 @@ mod tests {
// create the server pubkey
let server_id = pk2id(&server_key.public_key(SECP256K1));
let client_key = SecretKey::new(&mut rand::thread_rng());
let client_key = SecretKey::new(&mut rand_08::thread_rng());
let outgoing = TcpStream::connect(local_addr).await.unwrap();
let sink = ECIESStream::connect(outgoing, client_key, server_id).await.unwrap();

View File

@@ -47,7 +47,7 @@ impl HelloMessageWithProtocols {
/// use reth_eth_wire::HelloMessageWithProtocols;
/// use reth_network_peers::pk2id;
/// use secp256k1::{SecretKey, SECP256K1};
/// let secret_key = SecretKey::new(&mut rand::thread_rng());
/// let secret_key = SecretKey::new(&mut rand_08::thread_rng());
/// let id = pk2id(&secret_key.public_key(SECP256K1));
/// let status = HelloMessageWithProtocols::builder(id).build();
/// ```
@@ -130,7 +130,7 @@ impl HelloMessage {
/// use reth_eth_wire::HelloMessage;
/// use reth_network_peers::pk2id;
/// use secp256k1::{SecretKey, SECP256K1};
/// let secret_key = SecretKey::new(&mut rand::thread_rng());
/// let secret_key = SecretKey::new(&mut rand_08::thread_rng());
/// let id = pk2id(&secret_key.public_key(SECP256K1));
/// let status = HelloMessage::builder(id).build();
/// ```
@@ -222,7 +222,7 @@ mod tests {
#[test]
fn test_hello_encoding_round_trip() {
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let id = pk2id(&secret_key.public_key(SECP256K1));
let hello = P2PMessage::Hello(HelloMessage {
protocol_version: ProtocolVersion::V5,
@@ -242,7 +242,7 @@ mod tests {
#[test]
fn hello_encoding_length() {
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let id = pk2id(&secret_key.public_key(SECP256K1));
let hello = P2PMessage::Hello(HelloMessage {
protocol_version: ProtocolVersion::V5,
@@ -261,7 +261,7 @@ mod tests {
#[test]
fn hello_message_id_prefix() {
// ensure that the hello message id is prefixed
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let id = pk2id(&secret_key.public_key(SECP256K1));
let hello = P2PMessage::Hello(HelloMessage {
protocol_version: ProtocolVersion::V5,

View File

@@ -19,7 +19,7 @@ pub type P2pPassthroughTcpStream = P2PStream<Framed<TcpStream, LengthDelimitedCo
/// Returns a new testing `HelloMessage` and new secretkey
pub fn eth_hello() -> (HelloMessageWithProtocols, SecretKey) {
let server_key = SecretKey::new(&mut rand::thread_rng());
let server_key = SecretKey::new(&mut rand_08::thread_rng());
let protocols = vec![EthVersion::Eth67.into()];
let hello = HelloMessageWithProtocols {
protocol_version: ProtocolVersion::V5,

View File

@@ -67,6 +67,7 @@ rustc-hash.workspace = true
thiserror.workspace = true
parking_lot.workspace = true
rand.workspace = true
rand_08.workspace = true
secp256k1 = { workspace = true, features = ["global-context", "std", "recovery"] }
derive_more.workspace = true
schnellru.workspace = true
@@ -125,6 +126,7 @@ serde = [
"reth-transaction-pool/serde",
"reth-ethereum-primitives/serde",
"reth-network-api/serde",
"rand_08/serde",
]
test-utils = [
"reth-transaction-pool/test-utils",

View File

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

View File

@@ -1,10 +1,8 @@
#![allow(missing_docs)]
use alloy_primitives::{
private::proptest::test_runner::{RngAlgorithm, TestRng},
U256,
};
use alloy_primitives::U256;
use criterion::*;
use rand::SeedableRng;
use reth_network::{
test_utils::Testnet,
transactions::{
@@ -63,9 +61,8 @@ 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(
TestRng::deterministic_rng(RngAlgorithm::ChaCha),
);
let mut gen =
TransactionGenerator::new(rand::rngs::StdRng::seed_from_u64(0));
let tx = gen.gen_eip1559_pooled();
let sender = tx.sender();

View File

@@ -28,7 +28,7 @@ pub use secp256k1::SecretKey;
/// Convenience function to create a new random [`SecretKey`]
pub fn rng_secret_key() -> SecretKey {
SecretKey::new(&mut rand::thread_rng())
SecretKey::new(&mut rand_08::thread_rng())
}
/// All network related initialization settings.
@@ -696,14 +696,13 @@ impl NetworkMode {
mod tests {
use super::*;
use alloy_eips::eip2124::ForkHash;
use rand::thread_rng;
use reth_chainspec::{Chain, MAINNET};
use reth_dns_discovery::tree::LinkEntry;
use reth_storage_api::noop::NoopProvider;
use std::sync::Arc;
fn builder() -> NetworkConfigBuilder {
let secret_key = SecretKey::new(&mut thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
NetworkConfigBuilder::new(secret_key)
}

View File

@@ -338,14 +338,12 @@ impl Discovery {
#[cfg(test)]
mod tests {
use super::*;
use rand::thread_rng;
use secp256k1::SECP256K1;
use std::net::{Ipv4Addr, SocketAddrV4};
#[tokio::test(flavor = "multi_thread")]
async fn test_discovery_setup() {
let mut rng = thread_rng();
let (secret_key, _) = SECP256K1.generate_keypair(&mut rng);
let (secret_key, _) = SECP256K1.generate_keypair(&mut rand_08::thread_rng());
let discovery_addr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, 0));
let _discovery = Discovery::new(
discovery_addr,
@@ -364,7 +362,7 @@ mod tests {
use tracing::trace;
async fn start_discovery_node(udp_port_discv4: u16, udp_port_discv5: u16) -> Discovery {
let secret_key = SecretKey::new(&mut thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let discv4_addr = format!("127.0.0.1:{udp_port_discv4}").parse().unwrap();
let discv5_addr: SocketAddr = format!("127.0.0.1:{udp_port_discv5}").parse().unwrap();

View File

@@ -898,7 +898,7 @@ mod tests {
let fork_filter = self.fork_filter.clone();
let local_peer_id = self.local_peer_id;
let mut hello = self.hello.clone();
let key = SecretKey::new(&mut rand::thread_rng());
let key = SecretKey::new(&mut rand_08::thread_rng());
hello.id = pk2id(&key.public_key(SECP256K1));
Box::pin(async move {
let outgoing = TcpStream::connect(local_addr).await.unwrap();
@@ -989,7 +989,7 @@ mod tests {
fn default() -> Self {
let (active_session_tx, active_session_rx) = mpsc::channel(100);
let (secret_key, pk) = SECP256K1.generate_keypair(&mut rand::thread_rng());
let (secret_key, pk) = SECP256K1.generate_keypair(&mut rand_08::thread_rng());
let local_peer_id = pk2id(&pk);
Self {

View File

@@ -195,7 +195,7 @@ impl<N: NetworkPrimitives> NetworkState<N> {
// Shuffle to propagate to a random sample of peers on every block announcement
let mut peers: Vec<_> = self.active_peers.iter_mut().collect();
peers.shuffle(&mut rand::thread_rng());
peers.shuffle(&mut rand::rng());
for (peer_id, peer) in peers {
if peer.blocks.contains(&msg.hash) {

View File

@@ -638,7 +638,7 @@ where
where
C: ChainSpecProvider<ChainSpec: Hardforks>,
{
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let config = Self::network_config_builder(secret_key).build(client.clone());
Self { config, client, secret_key }
}
@@ -658,7 +658,7 @@ where
where
C: ChainSpecProvider<ChainSpec: Hardforks>,
{
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let builder = Self::network_config_builder(secret_key);
let hello_message =

View File

@@ -1911,7 +1911,7 @@ mod tests {
use super::*;
use crate::{test_utils::Testnet, NetworkConfigBuilder, NetworkManager};
use alloy_consensus::{transaction::PooledTransaction, TxEip1559, TxLegacy};
use alloy_primitives::{hex, PrimitiveSignature as Signature, TxKind, U256};
use alloy_primitives::{hex, Signature, TxKind, U256};
use alloy_rlp::Decodable;
use constants::tx_fetcher::DEFAULT_MAX_COUNT_FALLBACK_PEERS;
use futures::FutureExt;
@@ -1940,7 +1940,7 @@ mod tests {
async fn new_tx_manager(
) -> (TransactionsManager<TestPool, EthNetworkPrimitives>, NetworkManager<EthNetworkPrimitives>)
{
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let client = NoopProvider::default();
let config = NetworkConfigBuilder::new(secret_key)
@@ -1998,7 +1998,7 @@ mod tests {
let listener0 = handle0.event_listener();
handle0.add_peer(*handle1.peer_id(), handle1.local_addr());
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let client = NoopProvider::default();
let pool = testing_pool();
@@ -2066,7 +2066,7 @@ mod tests {
let listener0 = handle0.event_listener();
handle0.add_peer(*handle1.peer_id(), handle1.local_addr());
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let client = NoopProvider::default();
let pool = testing_pool();
@@ -2131,7 +2131,7 @@ mod tests {
async fn test_handle_incoming_transactions_hashes() {
reth_tracing::init_test_tracing();
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let client = NoopProvider::default();
let config = NetworkConfigBuilder::new(secret_key)
@@ -2238,7 +2238,7 @@ mod tests {
let listener0 = handle0.event_listener();
handle0.add_peer(*handle1.peer_id(), handle1.local_addr());
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let client = NoopProvider::default();
let pool = testing_pool();
@@ -2314,7 +2314,7 @@ mod tests {
let listener0 = handle0.event_listener();
handle0.add_peer(*handle1.peer_id(), handle1.local_addr());
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let client = NoopProvider::default();
let pool = testing_pool();

View File

@@ -3,7 +3,7 @@
//! announcements. Validation and filtering of announcements is network dependent.
use crate::metrics::{AnnouncedTxTypesMetrics, TxTypesCounter};
use alloy_primitives::{PrimitiveSignature as Signature, TxHash};
use alloy_primitives::{Signature, TxHash};
use derive_more::{Deref, DerefMut};
use reth_eth_wire::{
DedupPayload, Eth68TxMetadata, HandleMempoolData, PartiallyValidData, ValidAnnouncementData,

View File

@@ -1,4 +1,4 @@
use alloy_primitives::{PrimitiveSignature as Signature, B256};
use alloy_primitives::{Signature, B256};
use reth_eth_wire::{GetPooledTransactions, PooledTransactions};
use reth_ethereum_primitives::TransactionSigned;
use reth_network::{

View File

@@ -93,7 +93,7 @@ async fn test_already_connected() {
reth_tracing::init_test_tracing();
let mut net = Testnet::default();
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let client = NoopProvider::default();
let p1 = PeerConfig::default();
@@ -137,8 +137,8 @@ async fn test_get_peer() {
reth_tracing::init_test_tracing();
let mut net = Testnet::default();
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key_1 = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let secret_key_1 = SecretKey::new(&mut rand_08::thread_rng());
let client = NoopProvider::default();
let p1 = PeerConfig::default();
@@ -171,8 +171,8 @@ async fn test_get_peer_by_id() {
reth_tracing::init_test_tracing();
let mut net = Testnet::default();
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key_1 = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let secret_key_1 = SecretKey::new(&mut rand_08::thread_rng());
let client = NoopProvider::default();
let p1 = PeerConfig::default();
let p2 = PeerConfig::with_secret_key(client.clone(), secret_key);
@@ -204,7 +204,7 @@ async fn test_get_peer_by_id() {
#[ignore]
async fn test_connect_with_boot_nodes() {
reth_tracing::init_test_tracing();
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let mut discv4 = Discv4Config::builder();
discv4.add_boot_nodes(mainnet_nodes());
@@ -225,7 +225,7 @@ async fn test_connect_with_boot_nodes() {
#[ignore]
async fn test_connect_with_builder() {
reth_tracing::init_test_tracing();
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let mut discv4 = Discv4Config::builder();
discv4.add_boot_nodes(mainnet_nodes());
@@ -262,7 +262,7 @@ async fn test_connect_with_builder() {
#[ignore]
async fn test_connect_to_trusted_peer() {
reth_tracing::init_test_tracing();
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let discv4 = Discv4Config::builder();
let client = NoopProvider::default();
@@ -319,7 +319,7 @@ async fn test_connect_to_trusted_peer() {
async fn test_incoming_node_id_blacklist() {
reth_tracing::init_test_tracing();
tokio::time::timeout(GETH_TIMEOUT, async move {
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
// instantiate geth and add ourselves as a peer
let temp_dir = tempfile::tempdir().unwrap().into_path();
@@ -374,7 +374,7 @@ async fn test_incoming_node_id_blacklist() {
async fn test_incoming_connect_with_single_geth() {
reth_tracing::init_test_tracing();
tokio::time::timeout(GETH_TIMEOUT, async move {
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
// instantiate geth and add ourselves as a peer
let temp_dir = tempfile::tempdir().unwrap().into_path();
@@ -419,7 +419,7 @@ async fn test_incoming_connect_with_single_geth() {
async fn test_outgoing_connect_with_single_geth() {
reth_tracing::init_test_tracing();
tokio::time::timeout(GETH_TIMEOUT, async move {
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let config = NetworkConfigBuilder::new(secret_key)
.listener_port(0)
@@ -466,7 +466,7 @@ async fn test_outgoing_connect_with_single_geth() {
async fn test_geth_disconnect() {
reth_tracing::init_test_tracing();
tokio::time::timeout(GETH_TIMEOUT, async move {
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let config = NetworkConfigBuilder::eth(secret_key)
.listener_port(0)
@@ -587,7 +587,7 @@ async fn test_trusted_peer_only() {
drop(handles);
let _handle = net.spawn();
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let peers_config = PeersConfig::default().with_trusted_nodes_only(true);
let config = NetworkConfigBuilder::eth(secret_key)
@@ -639,7 +639,7 @@ async fn test_trusted_peer_only() {
#[tokio::test(flavor = "multi_thread")]
async fn test_network_state_change() {
let net = Testnet::create(1).await;
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let peers_config =
PeersConfig::default().with_refill_slots_interval(Duration::from_millis(500));
@@ -681,7 +681,7 @@ async fn test_network_state_change() {
#[tokio::test(flavor = "multi_thread")]
async fn test_exceed_outgoing_connections() {
let net = Testnet::create(2).await;
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let peers_config = PeersConfig::default().with_max_outbound(1);
let config = NetworkConfigBuilder::eth(secret_key)
@@ -722,7 +722,7 @@ async fn test_exceed_outgoing_connections() {
#[tokio::test(flavor = "multi_thread")]
async fn test_disconnect_incoming_when_exceeded_incoming_connections() {
let net = Testnet::create(1).await;
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let peers_config = PeersConfig::default().with_max_inbound(0);
let config = NetworkConfigBuilder::eth(secret_key)
@@ -838,7 +838,7 @@ async fn new_random_peer(
max_in_bound: usize,
trusted_nodes: Vec<TrustedPeer>,
) -> NetworkManager<EthNetworkPrimitives> {
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let peers_config =
PeersConfig::default().with_max_inbound(max_in_bound).with_trusted_nodes(trusted_nodes);
@@ -909,7 +909,7 @@ async fn test_connect_peer_in_different_network_should_fail() {
tokio::task::spawn(peer);
// peer in sepolia.
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
// If the remote disconnect first, then we would not get a fatal protocol error. So set
// max_backoff_count to 0 to speed up the removal of the peer.
let peers_config = PeersConfig::default().with_max_backoff_count(0);

View File

@@ -283,7 +283,7 @@ async fn test_connect_to_non_multiplex_peer() {
let net = Testnet::create(1).await;
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let config = NetworkConfigBuilder::eth(secret_key)
.listener_port(0)

View File

@@ -4,7 +4,7 @@
use std::sync::Arc;
use alloy_consensus::{Header, TxEip2930};
use alloy_primitives::{Bytes, PrimitiveSignature as Signature, TxKind, U256};
use alloy_primitives::{Bytes, Signature, TxKind, U256};
use rand::Rng;
use reth_eth_wire::HeadersDirection;
use reth_ethereum_primitives::{Block, Transaction, TransactionSigned};
@@ -22,12 +22,12 @@ use reth_provider::test_utils::MockEthProvider;
/// Returns a new [`TransactionSigned`] with some random parameters
pub fn rng_transaction(rng: &mut impl rand::RngCore) -> TransactionSigned {
let request = Transaction::Eip2930(TxEip2930 {
chain_id: rng.gen(),
nonce: rng.gen(),
gas_price: rng.gen(),
gas_limit: rng.gen(),
chain_id: rng.random(),
nonce: rng.random(),
gas_price: rng.random(),
gas_limit: rng.random(),
to: TxKind::Create,
value: U256::from(rng.gen::<u128>()),
value: U256::from(rng.random::<u128>()),
input: Bytes::from(vec![1, 2]),
access_list: Default::default(),
});
@@ -39,7 +39,7 @@ pub fn rng_transaction(rng: &mut impl rand::RngCore) -> TransactionSigned {
#[tokio::test(flavor = "multi_thread")]
async fn test_get_body() {
reth_tracing::init_test_tracing();
let mut rng = rand::thread_rng();
let mut rng = rand::rng();
let mock_provider = Arc::new(MockEthProvider::default());
let mut net = Testnet::create_with(2, mock_provider.clone()).await;
@@ -63,7 +63,7 @@ async fn test_get_body() {
// request some blocks
for _ in 0..100 {
// Set a new random block to the mock storage and request it via the network
let block_hash = rng.gen();
let block_hash = rng.random();
let mut block: Block = Block::default();
block.body.transactions.push(rng_transaction(&mut rng));
@@ -81,7 +81,7 @@ async fn test_get_body() {
#[tokio::test(flavor = "multi_thread")]
async fn test_get_header() {
reth_tracing::init_test_tracing();
let mut rng = rand::thread_rng();
let mut rng = rand::rng();
let mock_provider = Arc::new(MockEthProvider::default());
let mut net = Testnet::create_with(2, mock_provider.clone()).await;
@@ -102,13 +102,13 @@ async fn test_get_header() {
let connected = events0.next_session_established().await.unwrap();
assert_eq!(connected, *handle1.peer_id());
let start: u64 = rng.gen();
let mut hash = rng.gen();
let start: u64 = rng.random();
let mut hash = rng.random();
// request some headers
for idx in 0..100 {
// Set a new random header to the mock storage and request it via the network
let header = Header { number: start + idx, parent_hash: hash, ..Default::default() };
hash = rng.gen();
hash = rng.random();
mock_provider.add_header(hash, header.clone());

View File

@@ -25,7 +25,7 @@ fn is_addr_in_use_kind(err: &NetworkError, kind: ServiceKind) -> bool {
#[tokio::test(flavor = "multi_thread")]
async fn test_is_default_syncing() {
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let config = NetworkConfigBuilder::eth(secret_key)
.disable_discovery()
.listener_port(0)
@@ -36,7 +36,7 @@ async fn test_is_default_syncing() {
#[tokio::test(flavor = "multi_thread")]
async fn test_listener_addr_in_use() {
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let config = NetworkConfigBuilder::eth(secret_key)
.disable_discovery()
.listener_port(0)
@@ -55,7 +55,7 @@ async fn test_listener_addr_in_use() {
#[tokio::test(flavor = "multi_thread")]
async fn test_discovery_addr_in_use() {
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let disc_config = Discv4Config::default();
let addr = SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, 0));
let any_port_listener = TcpListener::bind(addr).await.unwrap();
@@ -71,7 +71,7 @@ async fn test_discovery_addr_in_use() {
// <https://github.com/paradigmxyz/reth/issues/8851>
#[tokio::test(flavor = "multi_thread")]
async fn test_tcp_port_node_record_no_discovery() {
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let config = NetworkConfigBuilder::eth(secret_key)
.listener_port(0)
.disable_discovery()
@@ -89,7 +89,7 @@ async fn test_tcp_port_node_record_no_discovery() {
// <https://github.com/paradigmxyz/reth/issues/8851>
#[tokio::test(flavor = "multi_thread")]
async fn test_tcp_port_node_record_discovery() {
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let config = NetworkConfigBuilder::eth(secret_key)
.listener_port(0)
.discovery_port(0)
@@ -108,7 +108,7 @@ async fn test_tcp_port_node_record_discovery() {
#[tokio::test(flavor = "multi_thread")]
async fn test_node_record_address_with_nat() {
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let config = NetworkConfigBuilder::eth(secret_key)
.add_nat(Some(NatResolver::ExternalIp("10.1.1.1".parse().unwrap())))
.disable_discv4_discovery()
@@ -124,7 +124,7 @@ async fn test_node_record_address_with_nat() {
#[tokio::test(flavor = "multi_thread")]
async fn test_node_record_address_with_nat_disable_discovery() {
let secret_key = SecretKey::new(&mut rand::thread_rng());
let secret_key = SecretKey::new(&mut rand_08::thread_rng());
let config = NetworkConfigBuilder::eth(secret_key)
.add_nat(Some(NatResolver::ExternalIp("10.1.1.1".parse().unwrap())))
.disable_discovery()

View File

@@ -1,5 +1,4 @@
use alloy_primitives::U256;
use rand::thread_rng;
use reth_network::{
test_utils::Testnet,
transactions::{TransactionPropagationMode::Max, TransactionsManagerConfig},
@@ -40,7 +39,7 @@ async fn transaction_hash_fetching() {
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(rand::rng());
let tx = gen.gen_eip1559_pooled();
let sender = tx.sender();
provider.add_account(sender, ExtendedAccount::new(0, U256::from(100_000_000)));

View File

@@ -3,9 +3,8 @@
use std::sync::Arc;
use alloy_consensus::TxLegacy;
use alloy_primitives::{PrimitiveSignature as Signature, U256};
use alloy_primitives::{Signature, U256};
use futures::StreamExt;
use rand::thread_rng;
use reth_ethereum_primitives::TransactionSigned;
use reth_network::{test_utils::Testnet, NetworkEvent, NetworkEventListenerProvider};
use reth_network_api::{events::PeerEvent, PeersInfo};
@@ -33,7 +32,7 @@ async fn test_tx_gossip() {
let mut peer0_tx_listener = peer0.pool().unwrap().pending_transactions_listener();
let mut peer1_tx_listener = peer1.pool().unwrap().pending_transactions_listener();
let mut gen = TransactionGenerator::new(thread_rng());
let mut gen = TransactionGenerator::new(rand::rng());
let tx = gen.gen_eip1559_pooled();
// ensure the sender has balance
@@ -70,7 +69,7 @@ async fn test_4844_tx_gossip_penalization() {
let mut peer1_tx_listener = peer1.pool().unwrap().pending_transactions_listener();
let mut gen = TransactionGenerator::new(thread_rng());
let mut gen = TransactionGenerator::new(rand::rng());
// peer 0 will be penalized for sending txs[0] over gossip
let txs = vec![gen.gen_eip4844_pooled(), gen.gen_eip1559_pooled()];

View File

@@ -33,6 +33,7 @@ secp256k1 = { workspace = true, features = ["rand"] }
serde_json.workspace = true
enr.workspace = true
tokio = { workspace = true, features = ["net", "macros", "rt"] }
rand_08.workspace = true
[features]
default = ["std"]

View File

@@ -327,7 +327,7 @@ mod tests {
#[test]
#[cfg(feature = "secp256k1")]
fn pk2id2pk() {
let prikey = secp256k1::SecretKey::new(&mut rand::thread_rng());
let prikey = secp256k1::SecretKey::new(&mut rand_08::thread_rng());
let pubkey = secp256k1::PublicKey::from_secret_key(secp256k1::SECP256K1, &prikey);
assert_eq!(pubkey, id2pk(pk2id(&pubkey)).unwrap());
}

View File

@@ -236,21 +236,21 @@ impl TryFrom<&Enr<secp256k1::SecretKey>> for NodeRecord {
mod tests {
use super::*;
use alloy_rlp::Decodable;
use rand::{thread_rng, Rng, RngCore};
use rand::{rng, Rng, RngCore};
use std::net::Ipv6Addr;
#[test]
fn test_mapped_ipv6() {
let mut rng = thread_rng();
let mut rng = rng();
let v4: Ipv4Addr = "0.0.0.0".parse().unwrap();
let v6 = v4.to_ipv6_mapped();
let record = NodeRecord {
address: v6.into(),
tcp_port: rng.gen(),
udp_port: rng.gen(),
id: rng.gen(),
tcp_port: rng.random(),
udp_port: rng.random(),
id: rng.random(),
};
assert!(record.clone().convert_ipv4_mapped());
@@ -259,14 +259,14 @@ mod tests {
#[test]
fn test_mapped_ipv4() {
let mut rng = thread_rng();
let mut rng = rng();
let v4: Ipv4Addr = "0.0.0.0".parse().unwrap();
let record = NodeRecord {
address: v4.into(),
tcp_port: rng.gen(),
udp_port: rng.gen(),
id: rng.gen(),
tcp_port: rng.random(),
udp_port: rng.random(),
id: rng.random(),
};
assert!(!record.clone().convert_ipv4_mapped());
@@ -275,15 +275,15 @@ mod tests {
#[test]
fn test_noderecord_codec_ipv4() {
let mut rng = thread_rng();
let mut rng = rng();
for _ in 0..100 {
let mut ip = [0u8; 4];
rng.fill_bytes(&mut ip);
let record = NodeRecord {
address: IpAddr::V4(ip.into()),
tcp_port: rng.gen(),
udp_port: rng.gen(),
id: rng.gen(),
tcp_port: rng.random(),
udp_port: rng.random(),
id: rng.random(),
};
let decoded = NodeRecord::decode(&mut alloy_rlp::encode(record).as_slice()).unwrap();
@@ -293,15 +293,15 @@ mod tests {
#[test]
fn test_noderecord_codec_ipv6() {
let mut rng = thread_rng();
let mut rng = rng();
for _ in 0..100 {
let mut ip = [0u8; 16];
rng.fill_bytes(&mut ip);
let record = NodeRecord {
address: IpAddr::V6(ip.into()),
tcp_port: rng.gen(),
udp_port: rng.gen(),
id: rng.gen(),
tcp_port: rng.random(),
udp_port: rng.random(),
id: rng.random(),
};
let decoded = NodeRecord::decode(&mut alloy_rlp::encode(record).as_slice()).unwrap();