Skip to content

Commit

Permalink
Impl Block, and implicitly Header and Body, for SealedBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
emhane committed Nov 14, 2024
1 parent ab284eb commit ca03eff
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
18 changes: 14 additions & 4 deletions crates/primitives-traits/src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Header: FullBlockHeader, Body: FullBlockBody> + Compact {}
pub trait FullBlock:
Block<Header: FullBlockHeader, Body: FullBlockBody>
+ Compact
+ alloy_rlp::Encodable
+ alloy_rlp::Decodable
{
}

impl<T> FullBlock for T where T: Block<Header: FullBlockHeader, Body: FullBlockBody> + Compact {}
impl<T> FullBlock for T where
T: Block<Header: FullBlockHeader, Body: FullBlockBody>
+ Compact
+ alloy_rlp::Encodable
+ alloy_rlp::Decodable
{
}

/// Abstraction of block data type.
// todo: make sealable super-trait, depends on <https://github.com/paradigmxyz/reth/issues/11449>
Expand All @@ -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,
Expand Down
17 changes: 17 additions & 0 deletions crates/primitives/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,23 @@ impl<H, B> SealedBlock<H, B> {
}
}

impl<H, B> reth_primitives_traits::Block for SealedBlock<H, B>
where
H: reth_primitives_traits::BlockHeader,
B: reth_primitives_traits::BlockBody<Header = H>,
{
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]
Expand Down
5 changes: 3 additions & 2 deletions crates/stages/stages/src/stages/bodies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -78,7 +79,7 @@ where
+ StatsReader
+ BlockReader
+ BlockWriter<Body = D::Body>,
D: BodyDownloader<Body: BlockBody<Transaction: Compact>>,
D: BodyDownloader<Body: BlockBody<Header = alloy_consensus::Header, Transaction: Compact>>,
{
/// Return the id of the stage
fn id(&self) -> StageId {
Expand Down Expand Up @@ -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)?;

Expand Down

0 comments on commit ca03eff

Please sign in to comment.