From ca03eff2c4b3f307e0d5dc52ebbe0afe48ce0e64 Mon Sep 17 00:00:00 2001 From: Emilia Hane Date: Thu, 14 Nov 2024 18:39:53 +0100 Subject: [PATCH] Impl Block, and implicitly Header and Body, for SealedBlock --- crates/primitives-traits/src/block/mod.rs | 18 ++++++++++++++---- crates/primitives/src/block.rs | 17 +++++++++++++++++ crates/stages/stages/src/stages/bodies.rs | 5 +++-- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/crates/primitives-traits/src/block/mod.rs b/crates/primitives-traits/src/block/mod.rs index a6867e204c6d..46a99089c27e 100644 --- a/crates/primitives-traits/src/block/mod.rs +++ b/crates/primitives-traits/src/block/mod.rs @@ -13,9 +13,21 @@ use reth_codecs::Compact; use crate::{BlockBody, BlockHeader, Body, FullBlockBody, FullBlockHeader, Header, InMemorySize}; /// Helper trait that unifies all behaviour required by block to support full node operations. -pub trait FullBlock: Block + Compact {} +pub trait FullBlock: + Block + + Compact + + alloy_rlp::Encodable + + alloy_rlp::Decodable +{ +} -impl FullBlock for T where T: Block + Compact {} +impl FullBlock for T where + T: Block + + Compact + + alloy_rlp::Encodable + + alloy_rlp::Decodable +{ +} /// Abstraction of block data type. // todo: make sealable super-trait, depends on @@ -32,8 +44,6 @@ pub trait Block: + Eq + serde::Serialize + for<'a> serde::Deserialize<'a> - + alloy_rlp::Encodable - + alloy_rlp::Decodable + Header + Body< Self::Header, diff --git a/crates/primitives/src/block.rs b/crates/primitives/src/block.rs index 0789e20d40ab..6c1330a239a9 100644 --- a/crates/primitives/src/block.rs +++ b/crates/primitives/src/block.rs @@ -302,6 +302,23 @@ impl SealedBlock { } } +impl reth_primitives_traits::Block for SealedBlock +where + H: reth_primitives_traits::BlockHeader, + B: reth_primitives_traits::BlockBody
, +{ + type Header = H; + type Body = B; + + fn header(&self) -> &Self::Header { + self.header.header() + } + + fn body(&self) -> &Self::Body { + &self.body + } +} + impl SealedBlock { /// Splits the sealed block into underlying components #[inline] diff --git a/crates/stages/stages/src/stages/bodies.rs b/crates/stages/stages/src/stages/bodies.rs index 640bae866594..37e6960f04a8 100644 --- a/crates/stages/stages/src/stages/bodies.rs +++ b/crates/stages/stages/src/stages/bodies.rs @@ -16,6 +16,7 @@ use reth_db_api::{ }; use reth_network_p2p::bodies::{downloader::BodyDownloader, response::BlockResponse}; use reth_primitives::StaticFileSegment; +use reth_primitives_traits::Body as _; use reth_provider::{ providers::{StaticFileProvider, StaticFileWriter}, BlockReader, BlockWriter, DBProvider, ProviderError, StaticFileProviderFactory, StatsReader, @@ -78,7 +79,7 @@ where + StatsReader + BlockReader + BlockWriter, - D: BodyDownloader>, + D: BodyDownloader>, { /// Return the id of the stage fn id(&self) -> StageId { @@ -192,7 +193,7 @@ where match response { BlockResponse::Full(block) => { // Write transactions - for transaction in block.body.transactions() { + for transaction in block.transactions() { let appended_tx_number = static_file_producer.append_transaction(next_tx_num, transaction)?;