move header.rs to eth-wire-types (#9345)

This commit is contained in:
Qiwei Yang
2024-07-06 18:29:02 +08:00
committed by GitHub
parent ebe3ef5e79
commit 0ce192921f
18 changed files with 41 additions and 39 deletions

1
Cargo.lock generated
View File

@ -7155,6 +7155,7 @@ dependencies = [
"proptest-derive 0.5.0", "proptest-derive 0.5.0",
"rand 0.8.5", "rand 0.8.5",
"reth-chainspec", "reth-chainspec",
"reth-codecs",
"reth-codecs-derive", "reth-codecs-derive",
"reth-primitives", "reth-primitives",
"serde", "serde",

View File

@ -4,11 +4,11 @@ use crate::Storage;
use reth_network_p2p::{ use reth_network_p2p::{
bodies::client::{BodiesClient, BodiesFut}, bodies::client::{BodiesClient, BodiesFut},
download::DownloadClient, download::DownloadClient,
headers::client::{HeadersClient, HeadersFut, HeadersRequest}, headers::client::{HeadersClient, HeadersDirection, HeadersFut, HeadersRequest},
priority::Priority, priority::Priority,
}; };
use reth_network_peers::{PeerId, WithPeerId}; 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 std::fmt::Debug;
use tracing::{trace, warn}; use tracing::{trace, warn};

View File

@ -5,13 +5,12 @@ use reth_network_p2p::{
bodies::client::{BodiesClient, BodiesFut}, bodies::client::{BodiesClient, BodiesFut},
download::DownloadClient, download::DownloadClient,
error::RequestError, error::RequestError,
headers::client::{HeadersClient, HeadersFut, HeadersRequest}, headers::client::{HeadersClient, HeadersDirection, HeadersFut, HeadersRequest},
priority::Priority, priority::Priority,
}; };
use reth_network_peers::PeerId; use reth_network_peers::PeerId;
use reth_primitives::{ use reth_primitives::{
BlockBody, BlockHash, BlockHashOrNumber, BlockNumber, Header, HeadersDirection, SealedHeader, BlockBody, BlockHash, BlockHashOrNumber, BlockNumber, Header, SealedHeader, B256,
B256,
}; };
use std::{collections::HashMap, io, path::Path}; use std::{collections::HashMap, io, path::Path};
use thiserror::Error; use thiserror::Error;

View File

@ -10,16 +10,14 @@ use reth_consensus::Consensus;
use reth_network_p2p::{ use reth_network_p2p::{
error::{DownloadError, DownloadResult, PeerRequestResult}, error::{DownloadError, DownloadResult, PeerRequestResult},
headers::{ headers::{
client::{HeadersClient, HeadersRequest}, client::{HeadersClient, HeadersDirection, HeadersRequest},
downloader::{validate_header_download, HeaderDownloader, SyncTarget}, downloader::{validate_header_download, HeaderDownloader, SyncTarget},
error::{HeadersDownloaderError, HeadersDownloaderResult}, error::{HeadersDownloaderError, HeadersDownloaderResult},
}, },
priority::Priority, priority::Priority,
}; };
use reth_network_peers::PeerId; use reth_network_peers::PeerId;
use reth_primitives::{ use reth_primitives::{BlockHashOrNumber, BlockNumber, GotExpected, Header, SealedHeader, B256};
BlockHashOrNumber, BlockNumber, GotExpected, Header, HeadersDirection, SealedHeader, B256,
};
use reth_tasks::{TaskSpawner, TokioTaskExecutor}; use reth_tasks::{TaskSpawner, TokioTaskExecutor};
use std::{ use std::{
cmp::{Ordering, Reverse}, cmp::{Ordering, Reverse},

View File

@ -14,6 +14,7 @@ workspace = true
[dependencies] [dependencies]
# reth # reth
reth-chainspec.workspace = true reth-chainspec.workspace = true
reth-codecs.workspace = true
reth-codecs-derive.workspace = true reth-codecs-derive.workspace = true
reth-primitives.workspace = true reth-primitives.workspace = true
alloy-rlp = { workspace = true, features = ["derive"] } alloy-rlp = { workspace = true, features = ["derive"] }
@ -47,4 +48,3 @@ arbitrary = [
"dep:proptest-arbitrary-interop", "dep:proptest-arbitrary-interop",
] ]
serde = ["dep:serde"] serde = ["dep:serde"]

View File

@ -5,11 +5,13 @@ use alloy_rlp::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWra
use reth_codecs_derive::{add_arbitrary_tests, derive_arbitrary}; use reth_codecs_derive::{add_arbitrary_tests, derive_arbitrary};
#[cfg(any(test, feature = "arbitrary"))] #[cfg(any(test, feature = "arbitrary"))]
use reth_primitives::generate_valid_header; use reth_primitives::generate_valid_header;
use reth_primitives::{BlockBody, BlockHashOrNumber, Header, HeadersDirection, B256}; use reth_primitives::{BlockBody, BlockHashOrNumber, Header, B256};
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::HeadersDirection;
/// A request for a peer to return block headers starting at the requested block. /// A request for a peer to return block headers starting at the requested block.
/// The peer must return at most [`limit`](#structfield.limit) headers. /// The peer must return at most [`limit`](#structfield.limit) headers.
/// If the [`reverse`](#structfield.reverse) field is `true`, the headers will be returned starting /// If the [`reverse`](#structfield.reverse) field is `true`, the headers will be returned starting
@ -107,11 +109,14 @@ impl From<Vec<BlockBody>> for BlockBodies {
#[cfg(test)] #[cfg(test)]
mod tests { 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 alloy_rlp::{Decodable, Encodable};
use reth_primitives::{ use reth_primitives::{
hex, BlockHashOrNumber, Header, HeadersDirection, Signature, Transaction, hex, BlockHashOrNumber, Header, Signature, Transaction, TransactionSigned, TxKind,
TransactionSigned, TxKind, TxLegacy, U256, TxLegacy, U256,
}; };
use std::str::FromStr; use std::str::FromStr;

View File

@ -5,8 +5,6 @@ use bytes::BufMut;
use reth_codecs::derive_arbitrary; use reth_codecs::derive_arbitrary;
use serde::{Deserialize, Serialize}; 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. /// 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, /// > The response must contain a number of block headers, of rising number when reverse is 0,
/// > falling when 1 /// > falling when 1
@ -88,8 +86,8 @@ impl From<HeadersDirection> for bool {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::{address, b256, bloom, bytes, hex, Address, Bytes, B256, U256};
use alloy_rlp::{Decodable, Encodable}; use alloy_rlp::{Decodable, Encodable};
use reth_primitives::{address, b256, bloom, bytes, hex, Address, Bytes, Header, B256, U256};
use std::str::FromStr; use std::str::FromStr;
// Test vector from: https://eips.ethereum.org/EIPS/eip-2481 // Test vector from: https://eips.ethereum.org/EIPS/eip-2481

View File

@ -18,6 +18,9 @@ pub use version::EthVersion;
pub mod message; pub mod message;
pub use message::{EthMessage, EthMessageID, ProtocolMessage}; pub use message::{EthMessage, EthMessageID, ProtocolMessage};
pub mod header;
pub use header::*;
pub mod blocks; pub mod blocks;
pub use blocks::*; pub use blocks::*;

View File

@ -7,12 +7,12 @@ use crate::{
use alloy_rlp::Encodable; use alloy_rlp::Encodable;
use futures::StreamExt; use futures::StreamExt;
use reth_eth_wire::{ use reth_eth_wire::{
BlockBodies, BlockHeaders, GetBlockBodies, GetBlockHeaders, GetNodeData, GetReceipts, NodeData, BlockBodies, BlockHeaders, GetBlockBodies, GetBlockHeaders, GetNodeData, GetReceipts,
Receipts, HeadersDirection, NodeData, Receipts,
}; };
use reth_network_p2p::error::RequestResult; use reth_network_p2p::error::RequestResult;
use reth_network_peers::PeerId; 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 reth_storage_api::{BlockReader, HeaderProvider, ReceiptProvider};
use std::{ use std::{
future::Future, future::Future,

View File

@ -4,7 +4,7 @@ use alloy_node_bindings::Geth;
use alloy_provider::{ext::AdminApi, ProviderBuilder}; use alloy_provider::{ext::AdminApi, ProviderBuilder};
use futures::StreamExt; use futures::StreamExt;
use reth_discv4::Discv4Config; use reth_discv4::Discv4Config;
use reth_eth_wire::DisconnectReason; use reth_eth_wire::{DisconnectReason, HeadersDirection};
use reth_net_banlist::BanList; use reth_net_banlist::BanList;
use reth_network::{ use reth_network::{
test_utils::{enr_to_peer_id, NetworkEventStream, PeerConfig, Testnet, GETH_TIMEOUT}, test_utils::{enr_to_peer_id, NetworkEventStream, PeerConfig, Testnet, GETH_TIMEOUT},
@ -16,7 +16,6 @@ use reth_network_p2p::{
sync::{NetworkSyncUpdater, SyncState}, sync::{NetworkSyncUpdater, SyncState},
}; };
use reth_network_peers::{mainnet_nodes, NodeRecord}; use reth_network_peers::{mainnet_nodes, NodeRecord};
use reth_primitives::HeadersDirection;
use reth_provider::test_utils::NoopProvider; use reth_provider::test_utils::NoopProvider;
use reth_transaction_pool::test_utils::testing_pool; use reth_transaction_pool::test_utils::testing_pool;
use secp256k1::SecretKey; use secp256k1::SecretKey;

View File

@ -2,6 +2,7 @@
//! Tests for eth related requests //! Tests for eth related requests
use rand::Rng; use rand::Rng;
use reth_eth_wire::HeadersDirection;
use reth_network::{ use reth_network::{
test_utils::{NetworkEventStream, Testnet}, test_utils::{NetworkEventStream, Testnet},
NetworkEvents, NetworkEvents,
@ -12,8 +13,8 @@ use reth_network_p2p::{
headers::client::{HeadersClient, HeadersRequest}, headers::client::{HeadersClient, HeadersRequest},
}; };
use reth_primitives::{ use reth_primitives::{
Block, BlockBody, Bytes, Header, HeadersDirection, Signature, Transaction, TransactionSigned, Block, BlockBody, Bytes, Header, Signature, Transaction, TransactionSigned, TxEip2930, TxKind,
TxEip2930, TxKind, U256, U256,
}; };
use reth_provider::test_utils::MockEthProvider; use reth_provider::test_utils::MockEthProvider;
use std::sync::Arc; use std::sync::Arc;

View File

@ -6,10 +6,9 @@ use crate::{
}; };
use futures::Stream; use futures::Stream;
use reth_consensus::{Consensus, ConsensusError}; use reth_consensus::{Consensus, ConsensusError};
use reth_eth_wire_types::HeadersDirection;
use reth_network_peers::WithPeerId; use reth_network_peers::WithPeerId;
use reth_primitives::{ use reth_primitives::{BlockBody, GotExpected, Header, SealedBlock, SealedHeader, B256};
BlockBody, GotExpected, Header, HeadersDirection, SealedBlock, SealedHeader, B256,
};
use std::{ use std::{
cmp::Reverse, cmp::Reverse,
collections::{HashMap, VecDeque}, collections::{HashMap, VecDeque},

View File

@ -1,7 +1,7 @@
use crate::{download::DownloadClient, error::PeerRequestResult, priority::Priority}; use crate::{download::DownloadClient, error::PeerRequestResult, priority::Priority};
use futures::{Future, FutureExt}; use futures::{Future, FutureExt};
pub use reth_eth_wire_types::BlockHeaders; pub use reth_eth_wire_types::{BlockHeaders, HeadersDirection};
use reth_primitives::{BlockHashOrNumber, Header, HeadersDirection}; use reth_primitives::{BlockHashOrNumber, Header};
use std::{ use std::{
fmt::Debug, fmt::Debug,
pin::Pin, pin::Pin,

View File

@ -6,10 +6,10 @@ use crate::{
priority::Priority, priority::Priority,
}; };
use parking_lot::Mutex; use parking_lot::Mutex;
use reth_eth_wire_types::HeadersDirection;
use reth_network_peers::{PeerId, WithPeerId}; use reth_network_peers::{PeerId, WithPeerId};
use reth_primitives::{ use reth_primitives::{
BlockBody, BlockHashOrNumber, BlockNumHash, Header, HeadersDirection, SealedBlock, BlockBody, BlockHashOrNumber, BlockNumHash, Header, SealedBlock, SealedHeader, B256,
SealedHeader, B256,
}; };
use std::{collections::HashMap, sync::Arc}; use std::{collections::HashMap, sync::Arc};

View File

@ -12,8 +12,9 @@ use crate::{
}; };
use futures::{Future, FutureExt, Stream, StreamExt}; use futures::{Future, FutureExt, Stream, StreamExt};
use reth_consensus::{test_utils::TestConsensus, Consensus}; use reth_consensus::{test_utils::TestConsensus, Consensus};
use reth_eth_wire_types::HeadersDirection;
use reth_network_peers::{PeerId, WithPeerId}; use reth_network_peers::{PeerId, WithPeerId};
use reth_primitives::{Header, HeadersDirection, SealedHeader}; use reth_primitives::{Header, SealedHeader};
use std::{ use std::{
fmt, fmt,
pin::Pin, pin::Pin,

View File

@ -102,7 +102,7 @@ optimism = [
"reth-provider/optimism", "reth-provider/optimism",
"reth-rpc-types-compat/optimism", "reth-rpc-types-compat/optimism",
"reth-rpc-eth-api/optimism", "reth-rpc-eth-api/optimism",
"reth-rpc-eth-types/optimism" "reth-rpc-eth-types/optimism",
] ]
jemalloc = ["dep:tikv-jemalloc-ctl"] jemalloc = ["dep:tikv-jemalloc-ctl"]

View File

@ -6,10 +6,10 @@ use reth_chainspec::ChainSpec;
use reth_consensus_common::validation::validate_block_pre_execution; use reth_consensus_common::validation::validate_block_pre_execution;
use reth_network_p2p::{ use reth_network_p2p::{
bodies::client::BodiesClient, bodies::client::BodiesClient,
headers::client::{HeadersClient, HeadersRequest}, headers::client::{HeadersClient, HeadersDirection, HeadersRequest},
priority::Priority, priority::Priority,
}; };
use reth_primitives::{BlockHashOrNumber, HeadersDirection, SealedBlock, SealedHeader}; use reth_primitives::{BlockHashOrNumber, SealedBlock, SealedHeader};
use reth_rpc_types::engine::{JwtError, JwtSecret}; use reth_rpc_types::engine::{JwtError, JwtSecret};
use std::{ use std::{
env::VarError, env::VarError,

View File

@ -29,7 +29,6 @@ mod compression;
pub mod constants; pub mod constants;
pub mod eip4844; pub mod eip4844;
pub mod genesis; pub mod genesis;
pub mod header;
pub mod proofs; pub mod proofs;
mod receipt; mod receipt;
pub use reth_static_file_types as static_file; pub use reth_static_file_types as static_file;
@ -47,13 +46,12 @@ pub use constants::{
MAINNET_GENESIS_HASH, SEPOLIA_GENESIS_HASH, MAINNET_GENESIS_HASH, SEPOLIA_GENESIS_HASH,
}; };
pub use genesis::{ChainConfig, Genesis, GenesisAccount}; pub use genesis::{ChainConfig, Genesis, GenesisAccount};
pub use header::{Header, HeadersDirection, SealedHeader};
pub use receipt::{ pub use receipt::{
gas_spent_by_transactions, Receipt, ReceiptWithBloom, ReceiptWithBloomRef, Receipts, gas_spent_by_transactions, Receipt, ReceiptWithBloom, ReceiptWithBloomRef, Receipts,
}; };
pub use reth_primitives_traits::{ pub use reth_primitives_traits::{
logs_bloom, Account, Bytecode, GotExpected, GotExpectedBoxed, Log, LogData, Request, Requests, logs_bloom, Account, Bytecode, GotExpected, GotExpectedBoxed, Header, HeaderError, Log,
StorageEntry, Withdrawal, Withdrawals, LogData, Request, Requests, SealedHeader, StorageEntry, Withdrawal, Withdrawals,
}; };
pub use static_file::StaticFileSegment; pub use static_file::StaticFileSegment;