From 458832676e01eff5cd17f50bf4738f4137e0ac2e Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Fri, 10 Jan 2025 19:13:42 +0100 Subject: [PATCH] migrate builder --- crates/node/builder/src/components/builder.rs | 9 +- crates/node/builder/src/components/mod.rs | 14 +- crates/node/builder/src/setup.rs | 11 +- crates/primitives/src/block.rs | 818 ------------------ 4 files changed, 22 insertions(+), 830 deletions(-) diff --git a/crates/node/builder/src/components/builder.rs b/crates/node/builder/src/components/builder.rs index 977381b6582b..4e67616cd433 100644 --- a/crates/node/builder/src/components/builder.rs +++ b/crates/node/builder/src/components/builder.rs @@ -10,7 +10,7 @@ use crate::{ use reth_consensus::{ConsensusError, FullConsensus}; use reth_evm::execute::BlockExecutorProvider; use reth_network::NetworkPrimitives; -use reth_node_api::{BodyTy, HeaderTy, NodeTypes, NodeTypesWithEngine, TxTy}; +use reth_node_api::{BlockTy, BodyTy, HeaderTy, NodeTypes, NodeTypesWithEngine, TxTy}; use reth_payload_builder::PayloadBuilderHandle; use reth_transaction_pool::{PoolTransaction, TransactionPool}; use std::{future::Future, marker::PhantomData}; @@ -310,6 +310,7 @@ where Primitives: NetworkPrimitives< BlockHeader = HeaderTy, BlockBody = BodyTy, + Block = BlockTy, >, >, PayloadB: PayloadServiceBuilder, @@ -393,7 +394,11 @@ pub trait NodeComponentsBuilder: Send { impl NodeComponentsBuilder for F where - N: NetworkPrimitives, BlockBody = BodyTy>, + N: NetworkPrimitives< + BlockHeader = HeaderTy, + BlockBody = BodyTy, + Block = BlockTy, + >, Node: FullNodeTypes, F: FnOnce(&BuilderContext) -> Fut + Send, Fut: Future>> + Send, diff --git a/crates/node/builder/src/components/mod.rs b/crates/node/builder/src/components/mod.rs index c5ac67e5cbc7..93fe031bf577 100644 --- a/crates/node/builder/src/components/mod.rs +++ b/crates/node/builder/src/components/mod.rs @@ -27,7 +27,9 @@ use reth_consensus::{ConsensusError, FullConsensus}; use reth_evm::execute::BlockExecutorProvider; use reth_network::{NetworkHandle, NetworkPrimitives}; use reth_network_api::FullNetwork; -use reth_node_api::{BodyTy, HeaderTy, NodeTypes, NodeTypesWithEngine, PayloadBuilder, TxTy}; +use reth_node_api::{ + BlockTy, BodyTy, HeaderTy, NodeTypes, NodeTypesWithEngine, PayloadBuilder, TxTy, +}; use reth_payload_builder::PayloadBuilderHandle; use reth_transaction_pool::{PoolTransaction, TransactionPool}; @@ -53,9 +55,7 @@ pub trait NodeComponents: Clone + Unpin + Send + Sync + 'stati + 'static; /// Network API. - type Network: FullNetwork< - Client: BlockClient
, Body = BodyTy>, - >; + type Network: FullNetwork>>; /// Builds new blocks. type PayloadBuilder: PayloadBuilder::Engine> @@ -102,7 +102,11 @@ pub struct Components NodeComponents for Components where - N: NetworkPrimitives, BlockBody = BodyTy>, + N: NetworkPrimitives< + BlockHeader = HeaderTy, + BlockBody = BodyTy, + Block = BlockTy, + >, Node: FullNodeTypes, Pool: TransactionPool>> + Unpin diff --git a/crates/node/builder/src/setup.rs b/crates/node/builder/src/setup.rs index 610ca7bbc799..00cc9d58f96a 100644 --- a/crates/node/builder/src/setup.rs +++ b/crates/node/builder/src/setup.rs @@ -2,6 +2,7 @@ use std::sync::Arc; +use crate::BlockTy; use alloy_primitives::{BlockNumber, B256}; use reth_config::{config::StageConfig, PruneConfig}; use reth_consensus::{Consensus, ConsensusError}; @@ -14,7 +15,7 @@ use reth_exex::ExExManagerHandle; use reth_network_p2p::{ bodies::downloader::BodyDownloader, headers::downloader::HeaderDownloader, BlockClient, }; -use reth_node_api::{BodyTy, HeaderTy}; +use reth_node_api::HeaderTy; use reth_provider::{providers::ProviderNodeTypes, ProviderFactory}; use reth_stages::{prelude::DefaultStages, stages::ExecutionStage, Pipeline, StageSet}; use reth_static_file::StaticFileProducer; @@ -27,7 +28,7 @@ use tokio::sync::watch; pub fn build_networked_pipeline( config: &StageConfig, client: Client, - consensus: Arc>, + consensus: Arc, Error = ConsensusError>>, provider_factory: ProviderFactory, task_executor: &TaskExecutor, metrics_tx: reth_stages::MetricEventsSender, @@ -39,7 +40,7 @@ pub fn build_networked_pipeline( ) -> eyre::Result> where N: ProviderNodeTypes, - Client: BlockClient
, Body = BodyTy> + 'static, + Client: BlockClient> + 'static, Executor: BlockExecutorProvider, { // building network downloaders using the fetch client @@ -75,7 +76,7 @@ pub fn build_pipeline( stage_config: &StageConfig, header_downloader: H, body_downloader: B, - consensus: Arc>, + consensus: Arc, Error = ConsensusError>>, max_block: Option, metrics_tx: reth_stages::MetricEventsSender, prune_config: Option, @@ -86,7 +87,7 @@ pub fn build_pipeline( where N: ProviderNodeTypes, H: HeaderDownloader
> + 'static, - B: BodyDownloader
, Body = BodyTy> + 'static, + B: BodyDownloader> + 'static, Executor: BlockExecutorProvider, { let mut builder = Pipeline::::builder(); diff --git a/crates/primitives/src/block.rs b/crates/primitives/src/block.rs index f7e918466f3e..2d5d84f196d1 100644 --- a/crates/primitives/src/block.rs +++ b/crates/primitives/src/block.rs @@ -27,824 +27,6 @@ pub type BlockWithSenders = reth_primitives_traits::block::RecoveredB // TODO(mattsse): deprecate alias pub type SealedBlockWithSenders = reth_primitives_traits::block::RecoveredBlock; -// /// We need to implement RLP traits manually because we currently don't have a way to flatten -// /// [`BlockBody`] into [`Block`]. -// mod block_rlp { -// use super::*; -// -// #[derive(RlpDecodable)] -// #[rlp(trailing)] -// struct Helper { -// header: H, -// transactions: Vec, -// ommers: Vec
, -// withdrawals: Option, -// } -// -// #[derive(RlpEncodable)] -// #[rlp(trailing)] -// struct HelperRef<'a, H, T = TransactionSigned> { -// header: &'a H, -// transactions: &'a Vec, -// ommers: &'a Vec
, -// withdrawals: Option<&'a Withdrawals>, -// } -// -// impl<'a, T> From<&'a Block> for HelperRef<'a, Header, T> { -// fn from(block: &'a Block) -> Self { -// let Block { header, body: BlockBody { transactions, ommers, withdrawals } } = block; -// Self { header, transactions, ommers, withdrawals: withdrawals.as_ref() } -// } -// } -// -// impl<'a> From<&'a SealedBlock> for HelperRef<'a, SealedHeader> { -// fn from(block: &'a SealedBlock) -> Self { -// let SealedBlock { header, body: BlockBody { transactions, ommers, withdrawals } } = -// block; -// Self { header, transactions, ommers, withdrawals: withdrawals.as_ref() } -// } -// } -// -// impl Decodable for SealedBlock { -// fn decode(b: &mut &[u8]) -> alloy_rlp::Result { -// let Helper { header, transactions, ommers, withdrawals } = Helper::decode(b)?; -// Ok(Self { header, body: BlockBody { transactions, ommers, withdrawals } }) -// } -// } -// -// impl Encodable for SealedBlock { -// fn encode(&self, out: &mut dyn bytes::BufMut) { -// let helper: HelperRef<'_, _, _> = self.into(); -// helper.encode(out) -// } -// -// fn length(&self) -> usize { -// let helper: HelperRef<'_, _, _> = self.into(); -// helper.length() -// } -// } -// } -// -// /// Sealed block with senders recovered from transactions. -// #[derive(Debug, Clone, PartialEq, Eq, Default, Deref, DerefMut)] -// pub struct BlockWithSenders { -// /// Block -// #[deref] -// #[deref_mut] -// pub block: B, -// /// List of senders that match the transactions in the block -// senders: Vec
, -// } -// -// impl BlockWithSenders { -// /// New block with senders -// pub const fn new_unchecked(block: B, senders: Vec
) -> Self { -// Self { block, senders } -// } -// -// /// New block with senders. Return none if len of tx and senders does not match -// pub fn new(block: B, senders: Vec
) -> Option { -// (block.body().transactions().len() == senders.len()).then_some(Self { block, senders }) -// } -// -// /// Returns all senders of the transactions in the block. -// pub fn senders(&self) -> &[Address] { -// &self.senders -// } -// -// /// Returns an iterator over all senders in the block. -// pub fn senders_iter(&self) -> impl Iterator { -// self.senders.iter() -// } -// -// /// Seal the block with a known hash. -// /// -// /// WARNING: This method does not perform validation whether the hash is correct. -// #[inline] -// pub fn seal_unchecked(self, hash: B256) -> SealedBlockWithSenders { -// let Self { block, senders } = self; -// SealedBlockWithSenders:: { block: block.seal(hash), senders } -// } -// -// /// Calculate the header hash and seal the block with senders so that it can't be changed. -// #[inline] -// pub fn seal_slow(self) -> SealedBlockWithSenders { -// SealedBlockWithSenders { block: self.block.seal_slow(), senders: self.senders } -// } -// -// /// Split Structure to its components -// #[inline] -// pub fn split(self) -> (B, Vec
) { -// (self.block, self.senders) -// } -// -// /// Returns an iterator over all transactions and their sender. -// #[inline] -// pub fn transactions_with_sender( -// &self, -// ) -> impl Iterator::Transaction)> -// + '_ { -// self.senders.iter().zip(self.block.body().transactions()) -// } -// -// /// Returns an iterator over all transactions in the chain. -// #[inline] -// pub fn into_transactions_ecrecovered( -// self, -// ) -> impl Iterator::Transaction>> where -// ::Transaction: SignedTransaction, -// { -// self.block -// .split() -// .1 -// .into_transactions() -// .into_iter() -// .zip(self.senders) -// .map(|(tx, sender)| tx.with_signer(sender)) -// } -// -// /// Consumes the block and returns the transactions of the block. -// #[inline] -// pub fn into_transactions( -// self, -// ) -> Vec<::Transaction> { -// self.block.split().1.into_transactions() -// } -// } -// -// /// Sealed Ethereum full block. -// /// -// /// Withdrawals can be optionally included at the end of the RLP encoded message. -// #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -// pub struct SealedBlock { -// /// Locked block header. -// header: SealedHeader, -// /// Block body. -// body: B, -// } -// -// impl SealedBlock { -// /// Create a new sealed block instance using the sealed header and block body. -// #[inline] -// pub const fn new(header: SealedHeader, body: B) -> Self { -// Self { header, body } -// } -// -// /// Header hash. -// #[inline] -// pub const fn hash(&self) -> B256 { -// self.header.hash() -// } -// -// /// Returns reference to block header. -// pub const fn header(&self) -> &H { -// self.header.header() -// } -// -// /// Returns reference to block body. -// pub const fn body(&self) -> &B { -// &self.body -// } -// -// /// Returns the Sealed header. -// pub const fn sealed_header(&self) -> &SealedHeader { -// &self.header -// } -// -// /// Clones the wrapped header and returns a [`SealedHeader`] sealed with the hash. -// pub fn clone_sealed_header(&self) -> SealedHeader -// where -// H: Clone, -// { -// self.header.clone() -// } -// -// /// Consumes the block and returns the sealed header. -// pub fn into_sealed_header(self) -> SealedHeader { -// self.header -// } -// -// /// Consumes the block and returns the header. -// pub fn into_header(self) -> H { -// self.header.unseal() -// } -// -// /// Consumes the block and returns the body. -// pub fn into_body(self) -> B { -// self.body -// } -// -// /// Splits the [`BlockBody`] and [`SealedHeader`] into separate components -// #[inline] -// pub fn split(self) -> (SealedHeader, B) { -// (self.header, self.body) -// } -// } -// -// impl SealedBlock -// where -// B: reth_primitives_traits::BlockBody, -// { -// /// Returns an iterator over all blob versioned hashes from the block body. -// #[inline] -// pub fn blob_versioned_hashes_iter(&self) -> impl Iterator + '_ { -// self.body.blob_versioned_hashes_iter() -// } -// } -// -// impl SealedBlock -// where -// B: reth_primitives_traits::BlockBody, -// { -// /// Returns the number of transactions in the block. -// #[inline] -// pub fn transaction_count(&self) -> usize { -// self.body.transaction_count() -// } -// } -// -// impl SealedBlock -// where -// H: alloy_consensus::BlockHeader, -// B: reth_primitives_traits::BlockBody, -// { -// /// Return the number hash tuple. -// pub fn num_hash(&self) -> BlockNumHash { -// BlockNumHash::new(self.number(), self.hash()) -// } -// -// /// Return a [`BlockWithParent`] for this header. -// pub fn block_with_parent(&self) -> BlockWithParent { -// BlockWithParent { parent: self.parent_hash(), block: self.num_hash() } -// } -// -// /// Ensures that the transaction root in the block header is valid. -// /// -// /// The transaction root is the Keccak 256-bit hash of the root node of the trie structure -// /// populated with each transaction in the transactions list portion of the block. -// /// -// /// # Returns -// /// -// /// Returns `Ok(())` if the calculated transaction root matches the one stored in the header, -// /// indicating that the transactions in the block are correctly represented in the trie. -// /// -// /// Returns `Err(error)` if the transaction root validation fails, providing a `GotExpected` -// /// error containing the calculated and expected roots. -// pub fn ensure_transaction_root_valid(&self) -> Result<(), GotExpected> -// where -// B::Transaction: Encodable2718, -// { -// let calculated_root = self.body.calculate_tx_root(); -// -// if self.header.transactions_root() != calculated_root { -// return Err(GotExpected { -// got: calculated_root, -// expected: self.header.transactions_root(), -// }) -// } -// -// Ok(()) -// } -// } -// -// impl SealedBlock -// where -// H: reth_primitives_traits::BlockHeader, -// B: reth_primitives_traits::BlockBody, -// { -// /// Expensive operation that recovers transaction signer. See [`SealedBlockWithSenders`]. -// pub fn senders(&self) -> Option> -// where -// B::Transaction: SignedTransaction, -// { -// self.body.recover_signers() -// } -// -// /// Seal sealed block with recovered transaction senders. -// pub fn seal_with_senders(self) -> Option> -// where -// B::Transaction: SignedTransaction, -// T: reth_primitives_traits::Block
, -// { -// self.try_seal_with_senders().ok() -// } -// -// /// Seal sealed block with recovered transaction senders. -// pub fn try_seal_with_senders(self) -> Result, Self> -// where -// B::Transaction: SignedTransaction, -// T: reth_primitives_traits::Block
, -// { -// match self.senders() { -// Some(senders) => Ok(SealedBlockWithSenders { block: self, senders }), -// None => Err(self), -// } -// } -// -// /// Transform into a [`SealedBlockWithSenders`]. -// /// -// /// # Panics -// /// -// /// If the number of senders does not match the number of transactions in the block -// /// and the signer recovery for one of the transactions fails. -// #[track_caller] -// pub fn with_senders_unchecked(self, senders: Vec
) -> SealedBlockWithSenders -// where -// B::Transaction: SignedTransaction, -// T: reth_primitives_traits::Block
, -// { -// self.try_with_senders_unchecked(senders).expect("stored block is valid") -// } -// -// /// Transform into a [`SealedBlockWithSenders`] using the given senders. -// /// -// /// If the number of senders does not match the number of transactions in the block, this -// falls /// back to manually recovery, but _without ensuring that the signature has a low `s` -// value_. /// See also [`TransactionSigned::recover_signer_unchecked`] -// /// -// /// Returns an error if a signature is invalid. -// #[track_caller] -// pub fn try_with_senders_unchecked( -// self, -// senders: Vec
, -// ) -> Result, Self> -// where -// B::Transaction: SignedTransaction, -// T: reth_primitives_traits::Block
, -// { -// let senders = if self.body.transactions().len() == senders.len() { -// senders -// } else { -// let Some(senders) = self.body.recover_signers_unchecked() else { return Err(self) }; -// senders -// }; -// -// Ok(SealedBlockWithSenders { block: self, senders }) -// } -// -// /// Unseal the block -// pub fn unseal(self) -> Block -// where -// Block: reth_primitives_traits::Block
, -// { -// Block::new(self.header.unseal(), self.body) -// } -// } -// -// impl InMemorySize for SealedBlock { -// #[inline] -// fn size(&self) -> usize { -// self.header.size() + self.body.size() -// } -// } -// -// impl From for Block { -// fn from(block: SealedBlock) -> Self { -// block.unseal() -// } -// } -// -// impl Default for SealedBlock -// where -// SealedHeader: Default, -// B: Default, -// { -// fn default() -> Self { -// Self { header: Default::default(), body: Default::default() } -// } -// } -// -// impl Deref for SealedBlock { -// type Target = H; -// -// fn deref(&self) -> &Self::Target { -// self.header.header() -// } -// } -// -// #[cfg(any(test, feature = "arbitrary"))] -// impl<'a, H, B> arbitrary::Arbitrary<'a> for SealedBlock -// where -// SealedHeader: arbitrary::Arbitrary<'a>, -// B: arbitrary::Arbitrary<'a>, -// { -// fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { -// Ok(Self { header: u.arbitrary()?, body: u.arbitrary()? }) -// } -// } -// -// #[cfg(any(test, feature = "test-utils"))] -// impl SealedBlock -// where -// H: reth_primitives_traits::test_utils::TestHeader, -// { -// /// Returns a mutable reference to the header. -// pub fn header_mut(&mut self) -> &mut H { -// self.header.header_mut() -// } -// -// /// Returns a mutable reference to the header. -// pub fn body_mut(&mut self) -> &mut B { -// &mut self.body -// } -// -// /// Updates the block header. -// pub fn set_header(&mut self, header: H) { -// self.header.set_header(header) -// } -// -// /// Updates the block hash. -// pub fn set_hash(&mut self, hash: alloy_primitives::BlockHash) { -// self.header.set_hash(hash); -// } -// -// /// Updates the parent block hash. -// pub fn set_parent_hash(&mut self, hash: alloy_primitives::BlockHash) { -// self.header.set_parent_hash(hash); -// } -// -// /// Updates the block number. -// pub fn set_block_number(&mut self, number: alloy_primitives::BlockNumber) { -// self.header.set_block_number(number); -// } -// -// /// Updates the block state root. -// pub fn set_state_root(&mut self, state_root: B256) { -// self.header.set_state_root(state_root); -// } -// -// /// Updates the block difficulty. -// pub fn set_difficulty(&mut self, difficulty: alloy_primitives::U256) { -// self.header.set_difficulty(difficulty); -// } -// } -// -// /// A helepr trait to construct [`SealedBlock`] from a [`reth_primitives_traits::Block`]. -// pub type SealedBlockFor = SealedBlock< -// ::Header, -// ::Body, -// >; -// -// /// Sealed block with senders recovered from transactions. -// #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Deref, DerefMut)] -// pub struct SealedBlockWithSenders { -// /// Sealed block -// #[deref] -// #[deref_mut] -// #[serde(bound = "SealedBlock: Serialize + serde::de::DeserializeOwned")] -// pub block: SealedBlock, -// /// List of senders that match transactions from block. -// senders: Vec
, -// } -// -// impl Default for SealedBlockWithSenders { -// fn default() -> Self { -// Self { block: SealedBlock::default(), senders: Default::default() } -// } -// } -// -// impl SealedBlockWithSenders { -// /// New sealed block with sender -// pub const fn new_unhashed( -// block: SealedBlock, -// senders: Vec
, -// ) -> Self { -// Self { block, senders } -// } -// -// /// New sealed block with sender. Return none if len of tx and senders does not match -// pub fn try_new_unhashed( -// block: SealedBlock, -// senders: Vec
, -// ) -> Option { -// (block.body.transactions().len() == senders.len()).then_some(Self { block, senders }) -// } -// } -// -// impl SealedBlockWithSenders { -// /// Returns all senders of the transactions in the block. -// pub fn senders(&self) -> &[Address] { -// &self.senders -// } -// -// /// Returns an iterator over all senders in the block. -// pub fn senders_iter(&self) -> impl Iterator { -// self.senders.iter() -// } -// -// /// Split Structure to its components -// #[inline] -// pub fn split(self) -> (SealedBlock, Vec
) { -// (self.block, self.senders) -// } -// -// /// Returns the unsealed [`BlockWithSenders`] -// #[inline] -// pub fn unseal(self) -> BlockWithSenders { -// let (block, senders) = self.split(); -// let (header, body) = block.split(); -// let header = header.unseal(); -// BlockWithSenders::new_unchecked(B::new(header, body), senders) -// } -// -// /// Returns an iterator over all transactions in the block. -// #[inline] -// pub fn transactions(&self) -> &[::Transaction] -// { self.block.body.transactions() -// } -// -// /// Returns an iterator over all transactions and their sender. -// #[inline] -// pub fn transactions_with_sender( -// &self, -// ) -> impl Iterator::Transaction)> -// + '_ { -// self.senders.iter().zip(self.block.body.transactions()) -// } -// -// /// Consumes the block and returns the transactions of the block. -// #[inline] -// pub fn into_transactions( -// self, -// ) -> Vec<::Transaction> { -// self.block.body.into_transactions() -// } -// -// /// Returns an iterator over all transactions in the chain. -// #[inline] -// pub fn into_transactions_ecrecovered( -// self, -// ) -> impl Iterator::Transaction>> where -// ::Transaction: SignedTransaction, -// { -// self.block -// .body -// .into_transactions() -// .into_iter() -// .zip(self.senders) -// .map(|(tx, sender)| tx.with_signer(sender)) -// } -// } -// -// #[cfg(any(test, feature = "test-utils"))] -// impl SealedBlockWithSenders -// where -// B: reth_primitives_traits::Block, -// { -// /// Returns a mutable reference to the recovered senders. -// pub fn senders_mut(&mut self) -> &mut Vec
{ -// &mut self.senders -// } -// -// /// Appends the sender to the list of senders. -// pub fn push_sender(&mut self, sender: Address) { -// self.senders.push(sender); -// } -// } -// -// #[cfg(any(test, feature = "arbitrary"))] -// impl<'a, B> arbitrary::Arbitrary<'a> for SealedBlockWithSenders -// where -// B: reth_primitives_traits::Block + arbitrary::Arbitrary<'a>, -// { -// fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { -// let block = B::arbitrary(u)?; -// -// let senders = block -// .body() -// .transactions() -// .iter() -// .map(|tx| tx.recover_signer().unwrap()) -// .collect::>(); -// -// let (header, body) = block.split(); -// let block = SealedBlock::new(SealedHeader::seal(header), body); -// Ok(Self { block, senders }) -// } -// } -// -// /// Bincode-compatible block type serde implementations. -// #[cfg(feature = "serde-bincode-compat")] -// pub(super) mod serde_bincode_compat { -// use alloc::{borrow::Cow, vec::Vec}; -// use alloy_primitives::Address; -// use reth_primitives_traits::{ -// serde_bincode_compat::{SealedHeader, SerdeBincodeCompat}, -// Block, -// }; -// use serde::{Deserialize, Deserializer, Serialize, Serializer}; -// use serde_with::{DeserializeAs, SerializeAs}; -// -// /// Bincode-compatible [`super::BlockBody`] serde implementation. -// pub type BlockBody<'a, T = super::TransactionSigned> = -// reth_primitives_traits::serde_bincode_compat::BlockBody<'a, T>; -// -// /// Bincode-compatible [`super::SealedBlock`] serde implementation. -// /// -// /// Intended to use with the [`serde_with::serde_as`] macro in the following way: -// /// ```rust -// /// use reth_primitives::{serde_bincode_compat, SealedBlock}; -// /// use serde::{Deserialize, Serialize}; -// /// use serde_with::serde_as; -// /// -// /// #[serde_as] -// /// #[derive(Serialize, Deserialize)] -// /// struct Data { -// /// #[serde_as(as = "serde_bincode_compat::SealedBlock")] -// /// block: SealedBlock, -// /// } -// /// ``` -// #[derive(Debug, Serialize, Deserialize)] -// pub struct SealedBlock<'a, H = super::Header, B = super::BlockBody> -// where -// H: SerdeBincodeCompat, -// B: SerdeBincodeCompat, -// { -// header: SealedHeader<'a, H>, -// body: B::BincodeRepr<'a>, -// } -// -// impl<'a, H, B> From<&'a super::SealedBlock> for SealedBlock<'a, H, B> -// where -// H: SerdeBincodeCompat, -// B: SerdeBincodeCompat, -// { -// fn from(value: &'a super::SealedBlock) -> Self { -// Self { -// header: SealedHeader::from(&value.header), -// body: B::BincodeRepr::from(&value.body), -// } -// } -// } -// -// impl<'a, H, B> From> for super::SealedBlock -// where -// H: SerdeBincodeCompat, -// B: SerdeBincodeCompat, -// { -// fn from(value: SealedBlock<'a, H, B>) -> Self { -// Self { header: value.header.into(), body: value.body.into() } -// } -// } -// -// impl SerializeAs for SealedBlock<'_> { -// fn serialize_as(source: &super::SealedBlock, serializer: S) -> Result -// where -// S: Serializer, -// { -// SealedBlock::from(source).serialize(serializer) -// } -// } -// -// impl<'de> DeserializeAs<'de, super::SealedBlock> for SealedBlock<'de> { -// fn deserialize_as(deserializer: D) -> Result -// where -// D: Deserializer<'de>, -// { -// SealedBlock::deserialize(deserializer).map(Into::into) -// } -// } -// -// /// Bincode-compatible [`super::SealedBlockWithSenders`] serde implementation. -// /// -// /// Intended to use with the [`serde_with::serde_as`] macro in the following way: -// /// ```rust -// /// use reth_primitives::{serde_bincode_compat, SealedBlockWithSenders}; -// /// use serde::{Deserialize, Serialize}; -// /// use serde_with::serde_as; -// /// -// /// #[serde_as] -// /// #[derive(Serialize, Deserialize)] -// /// struct Data { -// /// #[serde_as(as = "serde_bincode_compat::SealedBlockWithSenders")] -// /// block: SealedBlockWithSenders, -// /// } -// /// ``` -// #[derive(Debug, Serialize, Deserialize)] -// pub struct SealedBlockWithSenders<'a, B = super::Block> -// where -// B: Block, -// { -// block: SealedBlock<'a, B::Header, B::Body>, -// senders: Cow<'a, Vec
>, -// } -// -// impl<'a, B> From<&'a super::SealedBlockWithSenders> for SealedBlockWithSenders<'a, B> -// where -// B: Block, -// { -// fn from(value: &'a super::SealedBlockWithSenders) -> Self { -// Self { block: SealedBlock::from(&value.block), senders: Cow::Borrowed(&value.senders) -// } } -// } -// -// impl<'a, B> From> for super::SealedBlockWithSenders -// where -// B: Block, -// { -// fn from(value: SealedBlockWithSenders<'a, B>) -> Self { -// Self { block: value.block.into(), senders: value.senders.into_owned() } -// } -// } -// -// impl SerializeAs for SealedBlockWithSenders<'_> { -// fn serialize_as( -// source: &super::SealedBlockWithSenders, -// serializer: S, -// ) -> Result -// where -// S: Serializer, -// { -// SealedBlockWithSenders::from(source).serialize(serializer) -// } -// } -// -// impl<'de> DeserializeAs<'de, super::SealedBlockWithSenders> for SealedBlockWithSenders<'de> { -// fn deserialize_as(deserializer: D) -> Result -// where -// D: Deserializer<'de>, -// { -// SealedBlockWithSenders::deserialize(deserializer).map(Into::into) -// } -// } -// -// #[cfg(test)] -// mod tests { -// use super::super::{serde_bincode_compat, BlockBody, SealedBlock, SealedBlockWithSenders}; -// use arbitrary::Arbitrary; -// use rand::Rng; -// use reth_testing_utils::generators; -// use serde::{Deserialize, Serialize}; -// use serde_with::serde_as; -// -// #[test] -// fn test_block_body_bincode_roundtrip() { -// #[serde_as] -// #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] -// struct Data { -// #[serde_as(as = "serde_bincode_compat::BlockBody")] -// block_body: BlockBody, -// } -// -// let mut bytes = [0u8; 1024]; -// generators::rng().fill(bytes.as_mut_slice()); -// let data = Data { -// block_body: BlockBody::arbitrary(&mut arbitrary::Unstructured::new(&bytes)) -// .unwrap(), -// }; -// -// let encoded = bincode::serialize(&data).unwrap(); -// let decoded: Data = bincode::deserialize(&encoded).unwrap(); -// assert_eq!(decoded, data); -// } -// -// #[test] -// fn test_sealed_block_bincode_roundtrip() { -// #[serde_as] -// #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] -// struct Data { -// #[serde_as(as = "serde_bincode_compat::SealedBlock")] -// block: SealedBlock, -// } -// -// let mut bytes = [0u8; 1024]; -// generators::rng().fill(bytes.as_mut_slice()); -// let data = Data { -// block: SealedBlock::arbitrary(&mut -// arbitrary::Unstructured::new(&bytes)).unwrap(), }; -// -// let encoded = bincode::serialize(&data).unwrap(); -// let decoded: Data = bincode::deserialize(&encoded).unwrap(); -// assert_eq!(decoded, data); -// } -// -// #[test] -// fn test_sealed_block_with_senders_bincode_roundtrip() { -// #[serde_as] -// #[derive(Debug, PartialEq, Eq, Serialize, Deserialize)] -// struct Data { -// #[serde_as(as = "serde_bincode_compat::SealedBlockWithSenders")] -// block: SealedBlockWithSenders, -// } -// -// let mut bytes = [0u8; 1024]; -// generators::rng().fill(bytes.as_mut_slice()); -// let data = Data { -// block: SealedBlockWithSenders::arbitrary(&mut -// arbitrary::Unstructured::new(&bytes)) .unwrap(), -// }; -// -// let encoded = bincode::serialize(&data).unwrap(); -// let decoded: Data = bincode::deserialize(&encoded).unwrap(); -// assert_eq!(decoded, data); -// } -// } -// } - #[cfg(test)] mod tests { use super::*;