diff --git a/Cargo.lock b/Cargo.lock index 7f4b8d4ee..eaf400bab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7155,6 +7155,7 @@ dependencies = [ "proptest-derive 0.5.0", "rand 0.8.5", "reth-chainspec", + "reth-codecs", "reth-codecs-derive", "reth-primitives", "serde", diff --git a/crates/consensus/auto-seal/src/client.rs b/crates/consensus/auto-seal/src/client.rs index b9befa738..d55cf6443 100644 --- a/crates/consensus/auto-seal/src/client.rs +++ b/crates/consensus/auto-seal/src/client.rs @@ -4,11 +4,11 @@ use crate::Storage; use reth_network_p2p::{ bodies::client::{BodiesClient, BodiesFut}, download::DownloadClient, - headers::client::{HeadersClient, HeadersFut, HeadersRequest}, + headers::client::{HeadersClient, HeadersDirection, HeadersFut, HeadersRequest}, priority::Priority, }; use reth_network_peers::{PeerId, WithPeerId}; -use reth_primitives::{BlockBody, BlockHashOrNumber, Header, HeadersDirection, B256}; +use reth_primitives::{BlockBody, BlockHashOrNumber, Header, B256}; use std::fmt::Debug; use tracing::{trace, warn}; diff --git a/crates/net/downloaders/src/file_client.rs b/crates/net/downloaders/src/file_client.rs index 3d00c3892..eaf392677 100644 --- a/crates/net/downloaders/src/file_client.rs +++ b/crates/net/downloaders/src/file_client.rs @@ -5,13 +5,12 @@ use reth_network_p2p::{ bodies::client::{BodiesClient, BodiesFut}, download::DownloadClient, error::RequestError, - headers::client::{HeadersClient, HeadersFut, HeadersRequest}, + headers::client::{HeadersClient, HeadersDirection, HeadersFut, HeadersRequest}, priority::Priority, }; use reth_network_peers::PeerId; use reth_primitives::{ - BlockBody, BlockHash, BlockHashOrNumber, BlockNumber, Header, HeadersDirection, SealedHeader, - B256, + BlockBody, BlockHash, BlockHashOrNumber, BlockNumber, Header, SealedHeader, B256, }; use std::{collections::HashMap, io, path::Path}; use thiserror::Error; diff --git a/crates/net/downloaders/src/headers/reverse_headers.rs b/crates/net/downloaders/src/headers/reverse_headers.rs index e123ce712..c9e4a51c2 100644 --- a/crates/net/downloaders/src/headers/reverse_headers.rs +++ b/crates/net/downloaders/src/headers/reverse_headers.rs @@ -10,16 +10,14 @@ use reth_consensus::Consensus; use reth_network_p2p::{ error::{DownloadError, DownloadResult, PeerRequestResult}, headers::{ - client::{HeadersClient, HeadersRequest}, + client::{HeadersClient, HeadersDirection, HeadersRequest}, downloader::{validate_header_download, HeaderDownloader, SyncTarget}, error::{HeadersDownloaderError, HeadersDownloaderResult}, }, priority::Priority, }; use reth_network_peers::PeerId; -use reth_primitives::{ - BlockHashOrNumber, BlockNumber, GotExpected, Header, HeadersDirection, SealedHeader, B256, -}; +use reth_primitives::{BlockHashOrNumber, BlockNumber, GotExpected, Header, SealedHeader, B256}; 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 242a73243..245643569 100644 --- a/crates/net/eth-wire-types/Cargo.toml +++ b/crates/net/eth-wire-types/Cargo.toml @@ -14,6 +14,7 @@ workspace = true [dependencies] # reth reth-chainspec.workspace = true +reth-codecs.workspace = true reth-codecs-derive.workspace = true reth-primitives.workspace = true alloy-rlp = { workspace = true, features = ["derive"] } @@ -47,4 +48,3 @@ arbitrary = [ "dep:proptest-arbitrary-interop", ] serde = ["dep:serde"] - diff --git a/crates/net/eth-wire-types/src/blocks.rs b/crates/net/eth-wire-types/src/blocks.rs index c8668c251..536ef7a75 100644 --- a/crates/net/eth-wire-types/src/blocks.rs +++ b/crates/net/eth-wire-types/src/blocks.rs @@ -5,11 +5,13 @@ use alloy_rlp::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWra use reth_codecs_derive::{add_arbitrary_tests, derive_arbitrary}; #[cfg(any(test, feature = "arbitrary"))] use reth_primitives::generate_valid_header; -use reth_primitives::{BlockBody, BlockHashOrNumber, Header, HeadersDirection, B256}; +use reth_primitives::{BlockBody, BlockHashOrNumber, Header, B256}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; +use crate::HeadersDirection; + /// A request for a peer to return block headers starting at the requested block. /// The peer must return at most [`limit`](#structfield.limit) headers. /// If the [`reverse`](#structfield.reverse) field is `true`, the headers will be returned starting @@ -107,11 +109,14 @@ impl From> for BlockBodies { #[cfg(test)] mod tests { - use crate::{message::RequestPair, BlockBodies, BlockHeaders, GetBlockBodies, GetBlockHeaders}; + use crate::{ + message::RequestPair, BlockBodies, BlockHeaders, GetBlockBodies, GetBlockHeaders, + HeadersDirection, + }; use alloy_rlp::{Decodable, Encodable}; use reth_primitives::{ - hex, BlockHashOrNumber, Header, HeadersDirection, Signature, Transaction, - TransactionSigned, TxKind, TxLegacy, U256, + hex, BlockHashOrNumber, Header, Signature, Transaction, TransactionSigned, TxKind, + TxLegacy, U256, }; use std::str::FromStr; diff --git a/crates/primitives/src/header.rs b/crates/net/eth-wire-types/src/header.rs similarity index 99% rename from crates/primitives/src/header.rs rename to crates/net/eth-wire-types/src/header.rs index 5642bac7c..c9589527b 100644 --- a/crates/primitives/src/header.rs +++ b/crates/net/eth-wire-types/src/header.rs @@ -5,8 +5,6 @@ use bytes::BufMut; use reth_codecs::derive_arbitrary; use serde::{Deserialize, Serialize}; -pub use reth_primitives_traits::{Header, HeaderError, SealedHeader}; - /// Represents the direction for a headers request depending on the `reverse` field of the request. /// > The response must contain a number of block headers, of rising number when reverse is 0, /// > falling when 1 @@ -88,8 +86,8 @@ impl From for bool { #[cfg(test)] mod tests { use super::*; - use crate::{address, b256, bloom, bytes, hex, Address, Bytes, B256, U256}; use alloy_rlp::{Decodable, Encodable}; + use reth_primitives::{address, b256, bloom, bytes, hex, Address, Bytes, Header, B256, U256}; use std::str::FromStr; // Test vector from: https://eips.ethereum.org/EIPS/eip-2481 diff --git a/crates/net/eth-wire-types/src/lib.rs b/crates/net/eth-wire-types/src/lib.rs index e75898a1f..f14bc4739 100644 --- a/crates/net/eth-wire-types/src/lib.rs +++ b/crates/net/eth-wire-types/src/lib.rs @@ -18,6 +18,9 @@ pub use version::EthVersion; pub mod message; pub use message::{EthMessage, EthMessageID, ProtocolMessage}; +pub mod header; +pub use header::*; + pub mod blocks; pub use blocks::*; diff --git a/crates/net/network/src/eth_requests.rs b/crates/net/network/src/eth_requests.rs index 7df124375..8ee317554 100644 --- a/crates/net/network/src/eth_requests.rs +++ b/crates/net/network/src/eth_requests.rs @@ -7,12 +7,12 @@ use crate::{ use alloy_rlp::Encodable; use futures::StreamExt; use reth_eth_wire::{ - BlockBodies, BlockHeaders, GetBlockBodies, GetBlockHeaders, GetNodeData, GetReceipts, NodeData, - Receipts, + BlockBodies, BlockHeaders, GetBlockBodies, GetBlockHeaders, GetNodeData, GetReceipts, + HeadersDirection, NodeData, Receipts, }; use reth_network_p2p::error::RequestResult; use reth_network_peers::PeerId; -use reth_primitives::{BlockBody, BlockHashOrNumber, Header, HeadersDirection}; +use reth_primitives::{BlockBody, BlockHashOrNumber, Header}; use reth_storage_api::{BlockReader, HeaderProvider, ReceiptProvider}; use std::{ future::Future, diff --git a/crates/net/network/tests/it/connect.rs b/crates/net/network/tests/it/connect.rs index 2dbd311cb..b379a6704 100644 --- a/crates/net/network/tests/it/connect.rs +++ b/crates/net/network/tests/it/connect.rs @@ -4,7 +4,7 @@ use alloy_node_bindings::Geth; use alloy_provider::{ext::AdminApi, ProviderBuilder}; use futures::StreamExt; use reth_discv4::Discv4Config; -use reth_eth_wire::DisconnectReason; +use reth_eth_wire::{DisconnectReason, HeadersDirection}; use reth_net_banlist::BanList; use reth_network::{ test_utils::{enr_to_peer_id, NetworkEventStream, PeerConfig, Testnet, GETH_TIMEOUT}, @@ -16,7 +16,6 @@ use reth_network_p2p::{ sync::{NetworkSyncUpdater, SyncState}, }; use reth_network_peers::{mainnet_nodes, NodeRecord}; -use reth_primitives::HeadersDirection; use reth_provider::test_utils::NoopProvider; use reth_transaction_pool::test_utils::testing_pool; use secp256k1::SecretKey; diff --git a/crates/net/network/tests/it/requests.rs b/crates/net/network/tests/it/requests.rs index 555acd08b..85669dc9f 100644 --- a/crates/net/network/tests/it/requests.rs +++ b/crates/net/network/tests/it/requests.rs @@ -2,6 +2,7 @@ //! Tests for eth related requests use rand::Rng; +use reth_eth_wire::HeadersDirection; use reth_network::{ test_utils::{NetworkEventStream, Testnet}, NetworkEvents, @@ -12,8 +13,8 @@ use reth_network_p2p::{ headers::client::{HeadersClient, HeadersRequest}, }; use reth_primitives::{ - Block, BlockBody, Bytes, Header, HeadersDirection, Signature, Transaction, TransactionSigned, - TxEip2930, TxKind, U256, + Block, BlockBody, Bytes, Header, Signature, Transaction, TransactionSigned, TxEip2930, TxKind, + U256, }; use reth_provider::test_utils::MockEthProvider; use std::sync::Arc; diff --git a/crates/net/p2p/src/full_block.rs b/crates/net/p2p/src/full_block.rs index 93af03d5b..fcee4c52b 100644 --- a/crates/net/p2p/src/full_block.rs +++ b/crates/net/p2p/src/full_block.rs @@ -6,10 +6,9 @@ use crate::{ }; use futures::Stream; use reth_consensus::{Consensus, ConsensusError}; +use reth_eth_wire_types::HeadersDirection; use reth_network_peers::WithPeerId; -use reth_primitives::{ - BlockBody, GotExpected, Header, HeadersDirection, SealedBlock, SealedHeader, B256, -}; +use reth_primitives::{BlockBody, GotExpected, Header, SealedBlock, SealedHeader, B256}; use std::{ cmp::Reverse, collections::{HashMap, VecDeque}, diff --git a/crates/net/p2p/src/headers/client.rs b/crates/net/p2p/src/headers/client.rs index 5b70aa1e5..4a4b903a8 100644 --- a/crates/net/p2p/src/headers/client.rs +++ b/crates/net/p2p/src/headers/client.rs @@ -1,7 +1,7 @@ use crate::{download::DownloadClient, error::PeerRequestResult, priority::Priority}; use futures::{Future, FutureExt}; -pub use reth_eth_wire_types::BlockHeaders; -use reth_primitives::{BlockHashOrNumber, Header, HeadersDirection}; +pub use reth_eth_wire_types::{BlockHeaders, HeadersDirection}; +use reth_primitives::{BlockHashOrNumber, Header}; use std::{ fmt::Debug, pin::Pin, diff --git a/crates/net/p2p/src/test_utils/full_block.rs b/crates/net/p2p/src/test_utils/full_block.rs index cfba59dbf..731aa39e7 100644 --- a/crates/net/p2p/src/test_utils/full_block.rs +++ b/crates/net/p2p/src/test_utils/full_block.rs @@ -6,10 +6,10 @@ use crate::{ priority::Priority, }; use parking_lot::Mutex; +use reth_eth_wire_types::HeadersDirection; use reth_network_peers::{PeerId, WithPeerId}; use reth_primitives::{ - BlockBody, BlockHashOrNumber, BlockNumHash, Header, HeadersDirection, SealedBlock, - SealedHeader, B256, + BlockBody, BlockHashOrNumber, BlockNumHash, Header, SealedBlock, SealedHeader, B256, }; use std::{collections::HashMap, sync::Arc}; diff --git a/crates/net/p2p/src/test_utils/headers.rs b/crates/net/p2p/src/test_utils/headers.rs index 73dd04849..a47753539 100644 --- a/crates/net/p2p/src/test_utils/headers.rs +++ b/crates/net/p2p/src/test_utils/headers.rs @@ -12,8 +12,9 @@ use crate::{ }; use futures::{Future, FutureExt, Stream, StreamExt}; use reth_consensus::{test_utils::TestConsensus, Consensus}; +use reth_eth_wire_types::HeadersDirection; use reth_network_peers::{PeerId, WithPeerId}; -use reth_primitives::{Header, HeadersDirection, SealedHeader}; +use reth_primitives::{Header, SealedHeader}; use std::{ fmt, pin::Pin, diff --git a/crates/node/core/Cargo.toml b/crates/node/core/Cargo.toml index 5dc0ed8f5..997aacc63 100644 --- a/crates/node/core/Cargo.toml +++ b/crates/node/core/Cargo.toml @@ -102,7 +102,7 @@ optimism = [ "reth-provider/optimism", "reth-rpc-types-compat/optimism", "reth-rpc-eth-api/optimism", - "reth-rpc-eth-types/optimism" + "reth-rpc-eth-types/optimism", ] jemalloc = ["dep:tikv-jemalloc-ctl"] diff --git a/crates/node/core/src/utils.rs b/crates/node/core/src/utils.rs index 7bf3314f5..75672cd34 100644 --- a/crates/node/core/src/utils.rs +++ b/crates/node/core/src/utils.rs @@ -6,10 +6,10 @@ use reth_chainspec::ChainSpec; use reth_consensus_common::validation::validate_block_pre_execution; use reth_network_p2p::{ bodies::client::BodiesClient, - headers::client::{HeadersClient, HeadersRequest}, + headers::client::{HeadersClient, HeadersDirection, HeadersRequest}, priority::Priority, }; -use reth_primitives::{BlockHashOrNumber, HeadersDirection, SealedBlock, SealedHeader}; +use reth_primitives::{BlockHashOrNumber, SealedBlock, SealedHeader}; use reth_rpc_types::engine::{JwtError, JwtSecret}; use std::{ env::VarError, diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 666a84361..29154d591 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -29,7 +29,6 @@ mod compression; pub mod constants; pub mod eip4844; pub mod genesis; -pub mod header; pub mod proofs; mod receipt; pub use reth_static_file_types as static_file; @@ -47,13 +46,12 @@ pub use constants::{ MAINNET_GENESIS_HASH, SEPOLIA_GENESIS_HASH, }; pub use genesis::{ChainConfig, Genesis, GenesisAccount}; -pub use header::{Header, HeadersDirection, SealedHeader}; pub use receipt::{ gas_spent_by_transactions, Receipt, ReceiptWithBloom, ReceiptWithBloomRef, Receipts, }; pub use reth_primitives_traits::{ - logs_bloom, Account, Bytecode, GotExpected, GotExpectedBoxed, Log, LogData, Request, Requests, - StorageEntry, Withdrawal, Withdrawals, + logs_bloom, Account, Bytecode, GotExpected, GotExpectedBoxed, Header, HeaderError, Log, + LogData, Request, Requests, SealedHeader, StorageEntry, Withdrawal, Withdrawals, }; pub use static_file::StaticFileSegment;