Trait NetworkPrimitives

pub trait NetworkPrimitives:
    Send
    + Sync
    + Unpin
    + Clone
    + Debug
    + 'static {
    type BlockHeader: BlockHeader + 'static;
    type BlockBody: BlockBody + 'static;
    type Block: Block<Header = Self::BlockHeader, Body = Self::BlockBody> + Encodable + Decodable + 'static;
    type BroadcastedTransaction: SignedTransaction + 'static;
    type PooledTransaction: SignedTransaction + TryFrom<Self::BroadcastedTransaction> + 'static;
    type Receipt: TxReceipt + RlpEncodableReceipt + RlpDecodableReceipt + Encodable + Decodable + Unpin + 'static;
    type NewBlockPayload: NewBlockPayload<Block = Self::Block>;
}
Expand description

Abstraction over primitive types which might appear in network messages.

This trait defines the types used in the Ethereum Wire Protocol (devp2p) for peer-to-peer communication. While NodePrimitives defines the core types used throughout the node (consensus format), NetworkPrimitives defines how these types are represented when transmitted over the network.

The key distinction is in transaction handling:

  • NodePrimitives defines SignedTx - the consensus format stored in blocks
  • NetworkPrimitives defines BroadcastedTransaction and PooledTransaction - the formats used for network propagation with additional data like blob sidecars

These traits work together through implementations like NetPrimitivesFor, which ensures type compatibility between a node’s internal representation and its network representation.

See crate::EthMessage for more context.

Required Associated Types§

type BlockHeader: BlockHeader + 'static

The block header type.

type BlockBody: BlockBody + 'static

The block body type.

type Block: Block<Header = Self::BlockHeader, Body = Self::BlockBody> + Encodable + Decodable + 'static

Full block type.

type BroadcastedTransaction: SignedTransaction + 'static

The transaction type which peers announce in Transactions messages.

This is different from PooledTransactions to account for the Ethereum case where EIP-4844 blob transactions are not announced over the network and can only be explicitly requested from peers. This is because blob transactions can be quite large and broadcasting them to all peers would cause significant bandwidth usage.

type PooledTransaction: SignedTransaction + TryFrom<Self::BroadcastedTransaction> + 'static

The transaction type which peers return in PooledTransactions messages.

For EIP-4844 blob transactions, this includes the full blob sidecar with KZG commitments and proofs that are needed for validation but are not included in the consensus block format.

type Receipt: TxReceipt + RlpEncodableReceipt + RlpDecodableReceipt + Encodable + Decodable + Unpin + 'static

The transaction type which peers return in GetReceipts messages.

type NewBlockPayload: NewBlockPayload<Block = Self::Block>

The payload type for the NewBlock message.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

§

impl<N, Pooled, NewBlock> NetworkPrimitives for BasicNetworkPrimitives<N, Pooled, NewBlock>
where N: NodePrimitives, Pooled: SignedTransaction + TryFrom<<N as NodePrimitives>::SignedTx> + 'static, NewBlock: NewBlockPayload<Block = <N as NodePrimitives>::Block>,