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

feat: impl block for sealedblock #12555

Merged
merged 2 commits into from
Nov 14, 2024
Merged
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
5 changes: 2 additions & 3 deletions crates/primitives-traits/src/block/body.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
//! Block body abstraction.
use crate::InMemorySize;
use alloc::fmt;

use alloy_consensus::Transaction;

use crate::InMemorySize;

/// Abstraction for block's body.
pub trait BlockBody:
Send
Expand All @@ -21,6 +19,7 @@ pub trait BlockBody:
+ alloy_rlp::Encodable
+ alloy_rlp::Decodable
+ InMemorySize
+ 'static
{
/// Ordered list of signed transactions as committed in block.
// todo: requires trait for signed transaction
Expand Down
8 changes: 4 additions & 4 deletions crates/primitives-traits/src/block/header.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
//! Block header data primitive.
use core::fmt;

use crate::InMemorySize;
use alloy_primitives::Sealable;
use core::fmt;
use reth_codecs::Compact;

use crate::InMemorySize;

/// Helper trait that unifies all behaviour required by block header to support full node
/// operations.
pub trait FullBlockHeader: BlockHeader + Compact {}
Expand All @@ -28,6 +26,7 @@ pub trait BlockHeader:
+ alloy_consensus::BlockHeader
+ Sealable
+ InMemorySize
+ 'static
{
}

Expand All @@ -47,5 +46,6 @@ impl<T> BlockHeader for T where
+ alloy_consensus::BlockHeader
+ Sealable
+ InMemorySize
+ 'static
{
}
32 changes: 28 additions & 4 deletions crates/primitives/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ impl reth_primitives_traits::Block for Block {
type Header = Header;
type Body = BlockBody;

fn body(&self) -> &Self::Body {
&self.body
}

fn header(&self) -> &Self::Header {
&self.header
}

fn body(&self) -> &Self::Body {
&self.body
}
}

impl InMemorySize for Block {
Expand Down Expand Up @@ -463,6 +463,24 @@ where
}
}

impl<H, B> reth_primitives_traits::Block for SealedBlock<H, B>
where
H: reth_primitives_traits::BlockHeader,
B: reth_primitives_traits::BlockBody,
Self: Serialize + for<'a> Deserialize<'a>,
{
type Header = H;
type Body = B;

fn header(&self) -> &Self::Header {
self.header.header()
}

fn body(&self) -> &Self::Body {
&self.body
}
}

#[cfg(any(test, feature = "arbitrary"))]
impl<'a, H, B> arbitrary::Arbitrary<'a> for SealedBlock<H, B>
where
Expand Down Expand Up @@ -959,6 +977,12 @@ mod tests {
use alloy_rlp::{Decodable, Encodable};
use std::str::FromStr;

const fn _traits() {
const fn assert_block<T: reth_primitives_traits::Block>() {}
assert_block::<Block>();
assert_block::<SealedBlock>();
}

/// Check parsing according to EIP-1898.
#[test]
fn can_parse_blockid_u64() {
Expand Down
Loading