From b1729d22e40fa43382bc3dcc843674d3a319c71c Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 14 Nov 2024 23:03:09 +0100 Subject: [PATCH] feat: impl block for sealedblock (#12555) --- crates/primitives-traits/src/block/body.rs | 7 ++--- crates/primitives-traits/src/block/header.rs | 10 +++--- crates/primitives/src/block.rs | 32 +++++++++++++++++--- 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/crates/primitives-traits/src/block/body.rs b/crates/primitives-traits/src/block/body.rs index c5f15aefea..bb52b89724 100644 --- a/crates/primitives-traits/src/block/body.rs +++ b/crates/primitives-traits/src/block/body.rs @@ -1,10 +1,8 @@ //! Block body abstraction. -use alloc::fmt; - -use alloy_consensus::Transaction; - use crate::InMemorySize; +use alloc::fmt; +use alloy_consensus::Transaction; /// Abstraction for block's body. pub trait BlockBody: @@ -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 diff --git a/crates/primitives-traits/src/block/header.rs b/crates/primitives-traits/src/block/header.rs index 7ab76f2498..0c1fc3e57f 100644 --- a/crates/primitives-traits/src/block/header.rs +++ b/crates/primitives-traits/src/block/header.rs @@ -1,11 +1,9 @@ //! Block header data primitive. -use core::fmt; - -use alloy_primitives::Sealable; -use reth_codecs::Compact; - use crate::InMemorySize; +use alloy_primitives::Sealable; +use core::fmt; +use reth_codecs::Compact; /// Helper trait that unifies all behaviour required by block header to support full node /// operations. @@ -28,6 +26,7 @@ pub trait BlockHeader: + alloy_consensus::BlockHeader + Sealable + InMemorySize + + 'static { } @@ -47,5 +46,6 @@ impl BlockHeader for T where + alloy_consensus::BlockHeader + Sealable + InMemorySize + + 'static { } diff --git a/crates/primitives/src/block.rs b/crates/primitives/src/block.rs index 0f96a9d584..d6476c29b4 100644 --- a/crates/primitives/src/block.rs +++ b/crates/primitives/src/block.rs @@ -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 { @@ -463,6 +463,24 @@ where } } +impl reth_primitives_traits::Block for SealedBlock +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 where @@ -959,6 +977,12 @@ mod tests { use alloy_rlp::{Decodable, Encodable}; use std::str::FromStr; + const fn _traits() { + const fn assert_block() {} + assert_block::(); + assert_block::(); + } + /// Check parsing according to EIP-1898. #[test] fn can_parse_blockid_u64() {