Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(sdk): make BlockBody and BlockHeader methods callable on SealedBlock #12552

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading