reth_eth_wire_types/
primitives.rs

1//! Abstraction over primitive types in network messages.
2
3use alloy_rlp::{Decodable, Encodable};
4use reth_primitives_traits::{Block, BlockBody, BlockHeader, SignedTransaction};
5use std::fmt::Debug;
6
7/// Abstraction over primitive types which might appear in network messages. See
8/// [`crate::EthMessage`] for more context.
9pub trait NetworkPrimitives:
10    Send + Sync + Unpin + Clone + Debug + PartialEq + Eq + 'static
11{
12    /// The block header type.
13    type BlockHeader: BlockHeader + 'static;
14
15    /// The block body type.
16    type BlockBody: BlockBody + 'static;
17
18    /// Full block type.
19    type Block: Block<Header = Self::BlockHeader, Body = Self::BlockBody>
20        + Encodable
21        + Decodable
22        + 'static;
23
24    /// The transaction type which peers announce in `Transactions` messages. It is different from
25    /// `PooledTransactions` to account for Ethereum case where EIP-4844 transactions are not being
26    /// announced and can only be explicitly requested from peers.
27    type BroadcastedTransaction: SignedTransaction + 'static;
28
29    /// The transaction type which peers return in `PooledTransactions` messages.
30    type PooledTransaction: SignedTransaction + TryFrom<Self::BroadcastedTransaction> + 'static;
31
32    /// The transaction type which peers return in `GetReceipts` messages.
33    type Receipt: Encodable
34        + Decodable
35        + Send
36        + Sync
37        + Unpin
38        + Clone
39        + Debug
40        + PartialEq
41        + Eq
42        + 'static;
43}
44
45/// Primitive types used by Ethereum network.
46#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
47#[non_exhaustive]
48pub struct EthNetworkPrimitives;
49
50impl NetworkPrimitives for EthNetworkPrimitives {
51    type BlockHeader = alloy_consensus::Header;
52    type BlockBody = reth_primitives::BlockBody;
53    type Block = reth_primitives::Block;
54    type BroadcastedTransaction = reth_primitives::TransactionSigned;
55    type PooledTransaction = reth_primitives::PooledTransactionsElement;
56    type Receipt = reth_primitives::Receipt;
57}