Skip to content

Commit

Permalink
chore: move serde bincode compat bound to NodePrimitives
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Dec 13, 2024
1 parent fb962fc commit b466a96
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
5 changes: 3 additions & 2 deletions crates/evm/execution-types/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ pub(super) mod serde_bincode_compat {
use reth_primitives::{
serde_bincode_compat::SealedBlockWithSenders, EthPrimitives, NodePrimitives,
};
use reth_primitives_traits::{serde_bincode_compat::SerdeBincodeCompat, Block};
use reth_trie_common::serde_bincode_compat::updates::TrieUpdates;
use serde::{ser::SerializeMap, Deserialize, Deserializer, Serialize, Serializer};
use serde_with::{DeserializeAs, SerializeAs};
Expand Down Expand Up @@ -576,7 +577,7 @@ pub(super) mod serde_bincode_compat {

impl<B> Serialize for SealedBlocksWithSenders<'_, B>
where
B: reth_primitives_traits::Block,
B: Block<Header: SerdeBincodeCompat, Body: SerdeBincodeCompat>,
{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand All @@ -594,7 +595,7 @@ pub(super) mod serde_bincode_compat {

impl<'de, B> Deserialize<'de> for SealedBlocksWithSenders<'_, B>
where
B: reth_primitives_traits::Block,
B: Block<Header: SerdeBincodeCompat, Body: SerdeBincodeCompat>,
{
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
Expand Down
5 changes: 2 additions & 3 deletions crates/primitives-traits/src/block/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use alloy_eips::{eip2718::Encodable2718, eip4895::Withdrawals};
use alloy_primitives::{Bytes, B256};

/// Helper trait that unifies all behaviour required by transaction to support full node operations.
pub trait FullBlockBody: BlockBody<Transaction: FullSignedTx> {}
pub trait FullBlockBody: BlockBody<Transaction: FullSignedTx> + MaybeSerdeBincodeCompat {}

impl<T> FullBlockBody for T where T: BlockBody<Transaction: FullSignedTx> {}
impl<T> FullBlockBody for T where T: BlockBody<Transaction: FullSignedTx> + MaybeSerdeBincodeCompat {}

/// Abstraction for block's body.
pub trait BlockBody:
Expand All @@ -27,7 +27,6 @@ pub trait BlockBody:
+ alloy_rlp::Decodable
+ InMemorySize
+ MaybeSerde
+ MaybeSerdeBincodeCompat
+ 'static
{
/// Ordered list of signed transactions as committed in block.
Expand Down
11 changes: 4 additions & 7 deletions crates/primitives-traits/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
Block, BlockBody, BlockHeader, FullBlock, FullBlockBody, FullBlockHeader, FullReceipt,
FullSignedTx, Receipt, SignedTransaction,
};
use crate::{Block, FullBlock, FullBlockBody, FullBlockHeader, FullReceipt, FullSignedTx, Receipt};
use core::fmt;

/// Configures all the primitive types of the node.
Expand All @@ -11,11 +8,11 @@ pub trait NodePrimitives:
/// Block primitive.
type Block: Block<Header = Self::BlockHeader, Body = Self::BlockBody>;
/// Block header primitive.
type BlockHeader: BlockHeader;
type BlockHeader: FullBlockHeader;
/// Block body primitive.
type BlockBody: BlockBody<Transaction = Self::SignedTx, OmmerHeader = Self::BlockHeader>;
type BlockBody: FullBlockBody<Transaction = Self::SignedTx, OmmerHeader = Self::BlockHeader>;
/// Signed version of the transaction type.
type SignedTx: SignedTransaction + 'static;
type SignedTx: FullSignedTx;
/// A receipt.
type Receipt: Receipt;
}
Expand Down
13 changes: 8 additions & 5 deletions crates/primitives/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ impl<T: InMemorySize> InMemorySize for BlockBody<T> {

impl<T> reth_primitives_traits::BlockBody for BlockBody<T>
where
T: SignedTransaction + MaybeSerdeBincodeCompat,
T: SignedTransaction,
{
type Transaction = T;
type OmmerHeader = Header;
Expand Down Expand Up @@ -715,7 +715,10 @@ pub(super) mod serde_bincode_compat {
use alloy_consensus::serde_bincode_compat::Header;
use alloy_eips::eip4895::Withdrawals;
use alloy_primitives::Address;
use reth_primitives_traits::serde_bincode_compat::{SealedHeader, SerdeBincodeCompat};
use reth_primitives_traits::{
serde_bincode_compat::{SealedHeader, SerdeBincodeCompat},
Block,
};
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use serde_with::{DeserializeAs, SerializeAs};

Expand Down Expand Up @@ -868,15 +871,15 @@ pub(super) mod serde_bincode_compat {
#[derive(Debug, Serialize, Deserialize)]
pub struct SealedBlockWithSenders<'a, B = super::Block>
where
B: reth_primitives_traits::Block,
B: Block<Header: SerdeBincodeCompat, Body: SerdeBincodeCompat>,
{
block: SealedBlock<'a, B::Header, B::Body>,
senders: Cow<'a, Vec<Address>>,
}

impl<'a, B> From<&'a super::SealedBlockWithSenders<B>> for SealedBlockWithSenders<'a, B>
where
B: reth_primitives_traits::Block,
B: Block<Header: SerdeBincodeCompat, Body: SerdeBincodeCompat>,
{
fn from(value: &'a super::SealedBlockWithSenders<B>) -> Self {
Self { block: SealedBlock::from(&value.block), senders: Cow::Borrowed(&value.senders) }
Expand All @@ -885,7 +888,7 @@ pub(super) mod serde_bincode_compat {

impl<'a, B> From<SealedBlockWithSenders<'a, B>> for super::SealedBlockWithSenders<B>
where
B: reth_primitives_traits::Block,
B: Block<Header: SerdeBincodeCompat, Body: SerdeBincodeCompat>,
{
fn from(value: SealedBlockWithSenders<'a, B>) -> Self {
Self { block: value.block.into(), senders: value.senders.into_owned() }
Expand Down

0 comments on commit b466a96

Please sign in to comment.