From dcc8c370abc2d920be920432e0a737b5b02804fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Anda=20Estensen?= Date: Thu, 19 Sep 2024 11:17:25 +0200 Subject: [PATCH 1/2] net: replace reth-primitive imports with alloy-eips --- Cargo.lock | 5 +++++ crates/net/downloaders/Cargo.toml | 1 + crates/net/downloaders/src/file_client.rs | 3 ++- crates/net/downloaders/src/headers/reverse_headers.rs | 3 ++- crates/net/eth-wire-types/Cargo.toml | 1 + crates/net/eth-wire-types/src/blocks.rs | 3 ++- crates/net/eth-wire/Cargo.toml | 1 + crates/net/eth-wire/tests/fuzz_roundtrip.rs | 3 ++- crates/net/network/Cargo.toml | 1 + crates/net/network/src/eth_requests.rs | 3 ++- crates/net/p2p/Cargo.toml | 1 + crates/net/p2p/src/error.rs | 3 ++- crates/net/p2p/src/headers/client.rs | 3 ++- crates/net/p2p/src/headers/downloader.rs | 3 ++- crates/net/p2p/src/test_utils/full_block.rs | 5 ++--- crates/net/p2p/src/test_utils/headers.rs | 2 +- 16 files changed, 29 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bb12cde94f3c..e3496d38ddfc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6847,6 +6847,7 @@ dependencies = [ name = "reth-downloaders" version = "1.0.7" dependencies = [ + "alloy-eips", "alloy-primitives", "alloy-rlp", "assert_matches", @@ -7076,6 +7077,7 @@ dependencies = [ name = "reth-eth-wire" version = "1.0.7" dependencies = [ + "alloy-eips", "alloy-primitives", "alloy-rlp", "arbitrary", @@ -7111,6 +7113,7 @@ name = "reth-eth-wire-types" version = "1.0.7" dependencies = [ "alloy-chains", + "alloy-eips", "alloy-genesis", "alloy-primitives", "alloy-rlp", @@ -7510,6 +7513,7 @@ dependencies = [ name = "reth-network" version = "1.0.7" dependencies = [ + "alloy-eips", "alloy-node-bindings", "alloy-primitives", "alloy-provider", @@ -7590,6 +7594,7 @@ dependencies = [ name = "reth-network-p2p" version = "1.0.7" dependencies = [ + "alloy-eips", "alloy-primitives", "auto_impl", "derive_more", diff --git a/crates/net/downloaders/Cargo.toml b/crates/net/downloaders/Cargo.toml index 35883de00e4a..5e7f4dd47a27 100644 --- a/crates/net/downloaders/Cargo.toml +++ b/crates/net/downloaders/Cargo.toml @@ -27,6 +27,7 @@ reth-db-api = { workspace = true, optional = true } reth-testing-utils = { workspace = true, optional = true } # ethereum +alloy-eips.workspace = true alloy-primitives.workspace = true alloy-rlp.workspace = true diff --git a/crates/net/downloaders/src/file_client.rs b/crates/net/downloaders/src/file_client.rs index 8487d2b37980..10e96aee3a7f 100644 --- a/crates/net/downloaders/src/file_client.rs +++ b/crates/net/downloaders/src/file_client.rs @@ -1,5 +1,6 @@ use std::{collections::HashMap, io, path::Path}; +use alloy_eips::BlockHashOrNumber; use alloy_primitives::{BlockHash, BlockNumber, B256}; use futures::Future; use itertools::Either; @@ -11,7 +12,7 @@ use reth_network_p2p::{ priority::Priority, }; use reth_network_peers::PeerId; -use reth_primitives::{BlockBody, BlockHashOrNumber, Header, SealedHeader}; +use reth_primitives::{BlockBody, Header, SealedHeader}; use thiserror::Error; use tokio::{fs::File, io::AsyncReadExt}; use tokio_stream::StreamExt; diff --git a/crates/net/downloaders/src/headers/reverse_headers.rs b/crates/net/downloaders/src/headers/reverse_headers.rs index c43d3dbd934c..0a05021e847b 100644 --- a/crates/net/downloaders/src/headers/reverse_headers.rs +++ b/crates/net/downloaders/src/headers/reverse_headers.rs @@ -2,6 +2,7 @@ use super::task::TaskDownloader; use crate::metrics::HeaderDownloaderMetrics; +use alloy_eips::BlockHashOrNumber; use alloy_primitives::{BlockNumber, B256}; use futures::{stream::Stream, FutureExt}; use futures_util::{stream::FuturesUnordered, StreamExt}; @@ -18,7 +19,7 @@ use reth_network_p2p::{ priority::Priority, }; use reth_network_peers::PeerId; -use reth_primitives::{BlockHashOrNumber, GotExpected, Header, SealedHeader}; +use reth_primitives::{GotExpected, Header, SealedHeader}; use reth_tasks::{TaskSpawner, TokioTaskExecutor}; use std::{ cmp::{Ordering, Reverse}, diff --git a/crates/net/eth-wire-types/Cargo.toml b/crates/net/eth-wire-types/Cargo.toml index 4ec0bf8e4914..1452a683b478 100644 --- a/crates/net/eth-wire-types/Cargo.toml +++ b/crates/net/eth-wire-types/Cargo.toml @@ -19,6 +19,7 @@ reth-primitives.workspace = true # ethereum alloy-chains = { workspace = true, features = ["rlp"] } +alloy-eips.workspace = true alloy-genesis.workspace = true alloy-primitives.workspace = true alloy-rlp = { workspace = true, features = ["derive"] } diff --git a/crates/net/eth-wire-types/src/blocks.rs b/crates/net/eth-wire-types/src/blocks.rs index 87344d72d3f2..c2ee8ef59e7f 100644 --- a/crates/net/eth-wire-types/src/blocks.rs +++ b/crates/net/eth-wire-types/src/blocks.rs @@ -2,10 +2,11 @@ //! types. use crate::HeadersDirection; +use alloy_eips::BlockHashOrNumber; use alloy_primitives::B256; use alloy_rlp::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper}; use reth_codecs_derive::add_arbitrary_tests; -use reth_primitives::{BlockBody, BlockHashOrNumber, Header}; +use reth_primitives::{BlockBody, Header}; /// A request for a peer to return block headers starting at the requested block. /// The peer must return at most [`limit`](#structfield.limit) headers. diff --git a/crates/net/eth-wire/Cargo.toml b/crates/net/eth-wire/Cargo.toml index 13224a37ada1..9df7088be8ed 100644 --- a/crates/net/eth-wire/Cargo.toml +++ b/crates/net/eth-wire/Cargo.toml @@ -22,6 +22,7 @@ reth-eth-wire-types.workspace = true reth-network-peers.workspace = true # ethereum +alloy-eips.workspace = true alloy-primitives.workspace = true # metrics diff --git a/crates/net/eth-wire/tests/fuzz_roundtrip.rs b/crates/net/eth-wire/tests/fuzz_roundtrip.rs index 7c01e1e1eb20..818a9beae605 100644 --- a/crates/net/eth-wire/tests/fuzz_roundtrip.rs +++ b/crates/net/eth-wire/tests/fuzz_roundtrip.rs @@ -48,6 +48,7 @@ macro_rules! fuzz_type_and_name { #[cfg(test)] pub mod fuzz_rlp { use crate::roundtrip_encoding; + use alloy_eips::BlockHashOrNumber; use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper}; use reth_codecs::add_arbitrary_tests; use reth_eth_wire::{ @@ -56,7 +57,7 @@ pub mod fuzz_rlp { NewPooledTransactionHashes66, NewPooledTransactionHashes68, NodeData, P2PMessage, PooledTransactions, Receipts, Status, Transactions, }; - use reth_primitives::{BlockHashOrNumber, TransactionSigned}; + use reth_primitives::TransactionSigned; use serde::{Deserialize, Serialize}; use test_fuzz::test_fuzz; diff --git a/crates/net/network/Cargo.toml b/crates/net/network/Cargo.toml index 5bb5254a9dee..23407678dc9e 100644 --- a/crates/net/network/Cargo.toml +++ b/crates/net/network/Cargo.toml @@ -34,6 +34,7 @@ reth-network-peers = { workspace = true, features = ["net"] } reth-network-types.workspace = true # ethereum +alloy-eips.workspace = true alloy-primitives.workspace = true alloy-rlp.workspace = true enr = { workspace = true, features = ["serde", "rust-secp256k1"] } diff --git a/crates/net/network/src/eth_requests.rs b/crates/net/network/src/eth_requests.rs index 9eebbe086861..f0c355b174a4 100644 --- a/crates/net/network/src/eth_requests.rs +++ b/crates/net/network/src/eth_requests.rs @@ -7,6 +7,7 @@ use std::{ time::Duration, }; +use alloy_eips::BlockHashOrNumber; use alloy_rlp::Encodable; use futures::StreamExt; use reth_eth_wire::{ @@ -16,7 +17,7 @@ use reth_eth_wire::{ use reth_network_api::test_utils::PeersHandle; use reth_network_p2p::error::RequestResult; use reth_network_peers::PeerId; -use reth_primitives::{BlockBody, BlockHashOrNumber, Header}; +use reth_primitives::{BlockBody, Header}; use reth_storage_api::{BlockReader, HeaderProvider, ReceiptProvider}; use tokio::sync::{mpsc::Receiver, oneshot}; use tokio_stream::wrappers::ReceiverStream; diff --git a/crates/net/p2p/Cargo.toml b/crates/net/p2p/Cargo.toml index e7b268c4bfdf..c43f7f5b347c 100644 --- a/crates/net/p2p/Cargo.toml +++ b/crates/net/p2p/Cargo.toml @@ -21,6 +21,7 @@ reth-network-types.workspace = true reth-storage-errors.workspace = true # ethereum +alloy-eips.workspace = true alloy-primitives.workspace = true # async diff --git a/crates/net/p2p/src/error.rs b/crates/net/p2p/src/error.rs index 96fc04420973..9394a9fdf6c5 100644 --- a/crates/net/p2p/src/error.rs +++ b/crates/net/p2p/src/error.rs @@ -1,12 +1,13 @@ use std::ops::RangeInclusive; use super::headers::client::HeadersRequest; +use alloy_eips::BlockHashOrNumber; use alloy_primitives::{BlockNumber, B256}; use derive_more::{Display, Error}; use reth_consensus::ConsensusError; use reth_network_peers::WithPeerId; use reth_network_types::ReputationChangeKind; -use reth_primitives::{BlockHashOrNumber, GotExpected, GotExpectedBoxed, Header}; +use reth_primitives::{GotExpected, GotExpectedBoxed, Header}; use reth_storage_errors::{db::DatabaseError, provider::ProviderError}; use tokio::sync::{mpsc, oneshot}; diff --git a/crates/net/p2p/src/headers/client.rs b/crates/net/p2p/src/headers/client.rs index 4a4b903a8261..b73ea4e925f9 100644 --- a/crates/net/p2p/src/headers/client.rs +++ b/crates/net/p2p/src/headers/client.rs @@ -1,7 +1,8 @@ use crate::{download::DownloadClient, error::PeerRequestResult, priority::Priority}; +use alloy_eips::BlockHashOrNumber; use futures::{Future, FutureExt}; pub use reth_eth_wire_types::{BlockHeaders, HeadersDirection}; -use reth_primitives::{BlockHashOrNumber, Header}; +use reth_primitives::Header; use std::{ fmt::Debug, pin::Pin, diff --git a/crates/net/p2p/src/headers/downloader.rs b/crates/net/p2p/src/headers/downloader.rs index f3222d4bd5d2..5565880ed399 100644 --- a/crates/net/p2p/src/headers/downloader.rs +++ b/crates/net/p2p/src/headers/downloader.rs @@ -1,9 +1,10 @@ use super::error::HeadersDownloaderResult; use crate::error::{DownloadError, DownloadResult}; +use alloy_eips::BlockHashOrNumber; use alloy_primitives::B256; use futures::Stream; use reth_consensus::Consensus; -use reth_primitives::{BlockHashOrNumber, SealedHeader}; +use reth_primitives::SealedHeader; /// A downloader capable of fetching and yielding block headers. /// /// A downloader represents a distinct strategy for submitting requests to download block headers, diff --git a/crates/net/p2p/src/test_utils/full_block.rs b/crates/net/p2p/src/test_utils/full_block.rs index 2749915c7875..3a12d4424274 100644 --- a/crates/net/p2p/src/test_utils/full_block.rs +++ b/crates/net/p2p/src/test_utils/full_block.rs @@ -5,13 +5,12 @@ use crate::{ headers::client::{HeadersClient, HeadersRequest}, priority::Priority, }; +use alloy_eips::{BlockHashOrNumber, BlockNumHash}; use alloy_primitives::B256; use parking_lot::Mutex; use reth_eth_wire_types::HeadersDirection; use reth_network_peers::{PeerId, WithPeerId}; -use reth_primitives::{ - BlockBody, BlockHashOrNumber, BlockNumHash, Header, SealedBlock, SealedHeader, -}; +use reth_primitives::{BlockBody, Header, SealedBlock, SealedHeader}; use std::{collections::HashMap, sync::Arc}; /// A headers+bodies client implementation that does nothing. diff --git a/crates/net/p2p/src/test_utils/headers.rs b/crates/net/p2p/src/test_utils/headers.rs index a47753539ddc..18bb31804419 100644 --- a/crates/net/p2p/src/test_utils/headers.rs +++ b/crates/net/p2p/src/test_utils/headers.rs @@ -108,7 +108,7 @@ impl TestDownload { let request = HeadersRequest { limit: self.limit, direction: HeadersDirection::Rising, - start: reth_primitives::BlockHashOrNumber::Number(0), // ignored + start: alloy_eips::BlockHashOrNumber::Number(0), // ignored }; let client = self.client.clone(); self.fut = Some(Box::pin(client.get_headers(request))); From ad77b6ba78ee19064d9c366ab029826d496d2221 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 20 Sep 2024 08:10:13 +0200 Subject: [PATCH 2/2] rm alloy-eips --- Cargo.lock | 1 - crates/net/eth-wire/Cargo.toml | 1 - crates/net/eth-wire/tests/fuzz_roundtrip.rs | 3 +-- crates/net/p2p/src/test_utils/headers.rs | 2 +- 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e3496d38ddfc..9129844933aa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7077,7 +7077,6 @@ dependencies = [ name = "reth-eth-wire" version = "1.0.7" dependencies = [ - "alloy-eips", "alloy-primitives", "alloy-rlp", "arbitrary", diff --git a/crates/net/eth-wire/Cargo.toml b/crates/net/eth-wire/Cargo.toml index 9df7088be8ed..13224a37ada1 100644 --- a/crates/net/eth-wire/Cargo.toml +++ b/crates/net/eth-wire/Cargo.toml @@ -22,7 +22,6 @@ reth-eth-wire-types.workspace = true reth-network-peers.workspace = true # ethereum -alloy-eips.workspace = true alloy-primitives.workspace = true # metrics diff --git a/crates/net/eth-wire/tests/fuzz_roundtrip.rs b/crates/net/eth-wire/tests/fuzz_roundtrip.rs index 818a9beae605..db9dd5c0abec 100644 --- a/crates/net/eth-wire/tests/fuzz_roundtrip.rs +++ b/crates/net/eth-wire/tests/fuzz_roundtrip.rs @@ -48,7 +48,6 @@ macro_rules! fuzz_type_and_name { #[cfg(test)] pub mod fuzz_rlp { use crate::roundtrip_encoding; - use alloy_eips::BlockHashOrNumber; use alloy_rlp::{RlpDecodableWrapper, RlpEncodableWrapper}; use reth_codecs::add_arbitrary_tests; use reth_eth_wire::{ @@ -139,7 +138,7 @@ pub mod fuzz_rlp { impl Default for GetBlockHeadersWrapper { fn default() -> Self { Self(GetBlockHeaders { - start_block: BlockHashOrNumber::Number(0), + start_block: 0u64.into(), limit: Default::default(), skip: Default::default(), direction: Default::default(), diff --git a/crates/net/p2p/src/test_utils/headers.rs b/crates/net/p2p/src/test_utils/headers.rs index 18bb31804419..e61ec2213a8b 100644 --- a/crates/net/p2p/src/test_utils/headers.rs +++ b/crates/net/p2p/src/test_utils/headers.rs @@ -108,7 +108,7 @@ impl TestDownload { let request = HeadersRequest { limit: self.limit, direction: HeadersDirection::Rising, - start: alloy_eips::BlockHashOrNumber::Number(0), // ignored + start: 0u64.into(), // ignored }; let client = self.client.clone(); self.fut = Some(Box::pin(client.get_headers(request)));