From 81aed4cd740a5f44bc0de1d4ddb7c7d4ca4cfe43 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 2 Dec 2024 10:52:02 +0100 Subject: [PATCH 1/2] chore: use alloy's blockwithparent --- .../downloaders/src/headers/reverse_headers.rs | 3 +-- crates/net/p2p/src/headers/downloader.rs | 3 +-- crates/primitives-traits/src/header/mod.rs | 2 +- crates/primitives-traits/src/header/sealed.rs | 17 ++--------------- crates/primitives-traits/src/lib.rs | 2 +- 5 files changed, 6 insertions(+), 21 deletions(-) diff --git a/crates/net/downloaders/src/headers/reverse_headers.rs b/crates/net/downloaders/src/headers/reverse_headers.rs index 63a20ff27f5b..be359134e79d 100644 --- a/crates/net/downloaders/src/headers/reverse_headers.rs +++ b/crates/net/downloaders/src/headers/reverse_headers.rs @@ -1225,11 +1225,10 @@ mod tests { use super::*; use crate::headers::test_utils::child_header; use alloy_consensus::Header; - use alloy_eips::BlockNumHash; + use alloy_eips::{eip1898::BlockWithParent, BlockNumHash}; use assert_matches::assert_matches; use reth_consensus::test_utils::TestConsensus; use reth_network_p2p::test_utils::TestHeadersClient; - use reth_primitives_traits::BlockWithParent; /// Tests that `replace_number` works the same way as `Option::replace` #[test] diff --git a/crates/net/p2p/src/headers/downloader.rs b/crates/net/p2p/src/headers/downloader.rs index eca03bdb4e79..1bc76924a6c8 100644 --- a/crates/net/p2p/src/headers/downloader.rs +++ b/crates/net/p2p/src/headers/downloader.rs @@ -1,12 +1,11 @@ use super::error::HeadersDownloaderResult; use crate::error::{DownloadError, DownloadResult}; use alloy_consensus::BlockHeader; -use alloy_eips::BlockHashOrNumber; +use alloy_eips::{eip1898::BlockWithParent, BlockHashOrNumber}; use alloy_primitives::B256; use futures::Stream; use reth_consensus::HeaderValidator; use reth_primitives::SealedHeader; -use reth_primitives_traits::BlockWithParent; use std::fmt::Debug; /// A downloader capable of fetching and yielding block headers. diff --git a/crates/primitives-traits/src/header/mod.rs b/crates/primitives-traits/src/header/mod.rs index ea5f7eafb518..abcdf4ee0cca 100644 --- a/crates/primitives-traits/src/header/mod.rs +++ b/crates/primitives-traits/src/header/mod.rs @@ -1,5 +1,5 @@ mod sealed; -pub use sealed::{BlockWithParent, Header, SealedHeader}; +pub use sealed::{Header, SealedHeader}; mod error; pub use error::HeaderError; diff --git a/crates/primitives-traits/src/header/sealed.rs b/crates/primitives-traits/src/header/sealed.rs index f167ffbf2847..3b3fe1b2e4bd 100644 --- a/crates/primitives-traits/src/header/sealed.rs +++ b/crates/primitives-traits/src/header/sealed.rs @@ -1,26 +1,13 @@ +use crate::InMemorySize; pub use alloy_consensus::Header; - -use core::mem; - use alloy_consensus::Sealed; use alloy_eips::BlockNumHash; use alloy_primitives::{keccak256, BlockHash, Sealable, B256}; use alloy_rlp::{Decodable, Encodable}; use bytes::BufMut; +use core::mem; use derive_more::{AsRef, Deref}; -use crate::InMemorySize; - -/// A helper struct to store the block number/hash and its parent hash. -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct BlockWithParent { - /// Parent hash. - pub parent: B256, - /// Block number/hash. - pub block: BlockNumHash, -} - /// A [`Header`] that is sealed at a precalculated hash, use [`SealedHeader::unseal()`] if you want /// to modify header. #[derive(Debug, Clone, PartialEq, Eq, Hash, AsRef, Deref)] diff --git a/crates/primitives-traits/src/lib.rs b/crates/primitives-traits/src/lib.rs index 5bdfd01eb9ce..c88da5ad7a7b 100644 --- a/crates/primitives-traits/src/lib.rs +++ b/crates/primitives-traits/src/lib.rs @@ -58,7 +58,7 @@ pub use storage::StorageEntry; pub mod header; #[cfg(any(test, feature = "arbitrary", feature = "test-utils"))] pub use header::test_utils; -pub use header::{BlockWithParent, Header, HeaderError, SealedHeader}; +pub use header::{Header, HeaderError, SealedHeader}; /// Bincode-compatible serde implementations for common abstracted types in Reth. /// From 02da6875ba73f90034531442abfcc904fff35842 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 2 Dec 2024 10:54:46 +0100 Subject: [PATCH 2/2] chore: use alloy's blockwithparent --- crates/primitives-traits/src/header/sealed.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/primitives-traits/src/header/sealed.rs b/crates/primitives-traits/src/header/sealed.rs index 3b3fe1b2e4bd..1a5163e6ba3f 100644 --- a/crates/primitives-traits/src/header/sealed.rs +++ b/crates/primitives-traits/src/header/sealed.rs @@ -2,7 +2,7 @@ use crate::InMemorySize; pub use alloy_consensus::Header; use alloy_consensus::Sealed; use alloy_eips::BlockNumHash; -use alloy_primitives::{keccak256, BlockHash, Sealable, B256}; +use alloy_primitives::{keccak256, BlockHash, Sealable}; use alloy_rlp::{Decodable, Encodable}; use bytes::BufMut; use core::mem;