From 02f76b813ed27a97fd4b90c1a46e1c1cf0cbb134 Mon Sep 17 00:00:00 2001 From: Dan Cline <6798349+Rjected@users.noreply.github.com> Date: Thu, 12 Dec 2024 18:44:55 -0500 Subject: [PATCH] feat: remove default receipts for network components (#13371) --- crates/net/eth-wire-types/src/message.rs | 6 +++++- crates/net/eth-wire-types/src/primitives.rs | 12 +++++------- crates/net/network-api/src/events.rs | 2 +- crates/net/network/src/config.rs | 2 +- crates/net/network/src/eth_requests.rs | 16 +++++++--------- crates/net/network/src/message.rs | 4 ++-- crates/node/builder/src/builder/mod.rs | 14 ++++---------- 7 files changed, 25 insertions(+), 31 deletions(-) diff --git a/crates/net/eth-wire-types/src/message.rs b/crates/net/eth-wire-types/src/message.rs index 9a8667203108..308baf48f6c9 100644 --- a/crates/net/eth-wire-types/src/message.rs +++ b/crates/net/eth-wire-types/src/message.rs @@ -223,7 +223,11 @@ pub enum EthMessage { /// Represents a `GetReceipts` request-response pair. GetReceipts(RequestPair), /// Represents a Receipts request-response pair. - Receipts(RequestPair), + #[cfg_attr( + feature = "serde", + serde(bound = "N::Receipt: serde::Serialize + serde::de::DeserializeOwned") + )] + Receipts(RequestPair>), } impl EthMessage { diff --git a/crates/net/eth-wire-types/src/primitives.rs b/crates/net/eth-wire-types/src/primitives.rs index 17f1943186a8..3d14bf154c0c 100644 --- a/crates/net/eth-wire-types/src/primitives.rs +++ b/crates/net/eth-wire-types/src/primitives.rs @@ -1,5 +1,6 @@ //! Abstraction over primitive types in network messages. +use alloy_consensus::{RlpDecodableReceipt, RlpEncodableReceipt, TxReceipt}; use alloy_rlp::{Decodable, Encodable}; use reth_primitives_traits::{Block, BlockBody, BlockHeader, SignedTransaction}; use std::fmt::Debug; @@ -30,15 +31,12 @@ pub trait NetworkPrimitives: type PooledTransaction: SignedTransaction + TryFrom + 'static; /// The transaction type which peers return in `GetReceipts` messages. - type Receipt: Encodable + type Receipt: TxReceipt + + RlpEncodableReceipt + + RlpDecodableReceipt + + Encodable + Decodable - + Send - + Sync + Unpin - + Clone - + Debug - + PartialEq - + Eq + 'static; } diff --git a/crates/net/network-api/src/events.rs b/crates/net/network-api/src/events.rs index 39c89f4c4e21..b8335da9b977 100644 --- a/crates/net/network-api/src/events.rs +++ b/crates/net/network-api/src/events.rs @@ -225,7 +225,7 @@ pub enum PeerRequest { /// The request for receipts. request: GetReceipts, /// The channel to send the response for receipts. - response: oneshot::Sender>, + response: oneshot::Sender>>, }, } diff --git a/crates/net/network/src/config.rs b/crates/net/network/src/config.rs index fb383b104a51..324cd518916d 100644 --- a/crates/net/network/src/config.rs +++ b/crates/net/network/src/config.rs @@ -148,7 +148,7 @@ where impl NetworkConfig where N: NetworkPrimitives, - C: BlockReader + C: BlockReader + HeaderProvider + Clone + Unpin diff --git a/crates/net/network/src/eth_requests.rs b/crates/net/network/src/eth_requests.rs index d5a8caf220e8..47dc8a89e992 100644 --- a/crates/net/network/src/eth_requests.rs +++ b/crates/net/network/src/eth_requests.rs @@ -4,7 +4,7 @@ use crate::{ budget::DEFAULT_BUDGET_TRY_DRAIN_DOWNLOADERS, metered_poll_nested_stream_with_budget, metrics::EthRequestHandlerMetrics, }; -use alloy_consensus::BlockHeader; +use alloy_consensus::{BlockHeader, ReceiptWithBloom, TxReceipt}; use alloy_eips::BlockHashOrNumber; use alloy_rlp::Encodable; use futures::StreamExt; @@ -81,7 +81,7 @@ impl EthRequestHandler { impl EthRequestHandler where N: NetworkPrimitives, - C: BlockReader + HeaderProvider + ReceiptProvider, + C: BlockReader + HeaderProvider + ReceiptProvider, { /// Returns the list of requested headers fn get_headers_response(&self, request: GetBlockHeaders) -> Vec { @@ -188,7 +188,7 @@ where &self, _peer_id: PeerId, request: GetReceipts, - response: oneshot::Sender>, + response: oneshot::Sender>>, ) { self.metrics.eth_receipts_requests_received_total.increment(1); @@ -200,10 +200,8 @@ where if let Some(receipts_by_block) = self.client.receipts_by_block(BlockHashOrNumber::Hash(hash)).unwrap_or_default() { - let receipt = receipts_by_block - .into_iter() - .map(|receipt| receipt.with_bloom()) - .collect::>(); + let receipt = + receipts_by_block.into_iter().map(ReceiptWithBloom::from).collect::>(); total_bytes += receipt.length(); receipts.push(receipt); @@ -226,7 +224,7 @@ where impl Future for EthRequestHandler where N: NetworkPrimitives, - C: BlockReader + C: BlockReader + HeaderProvider
+ Unpin, { @@ -317,6 +315,6 @@ pub enum IncomingEthRequest { /// The specific receipts requested. request: GetReceipts, /// The channel sender for the response containing receipts. - response: oneshot::Sender>, + response: oneshot::Sender>>, }, } diff --git a/crates/net/network/src/message.rs b/crates/net/network/src/message.rs index ff5093b67328..8b738adeef73 100644 --- a/crates/net/network/src/message.rs +++ b/crates/net/network/src/message.rs @@ -99,7 +99,7 @@ pub enum PeerResponse { /// Represents a response to a request for receipts. Receipts { /// The receiver channel for the response to a receipts request. - response: oneshot::Receiver>, + response: oneshot::Receiver>>, }, } @@ -150,7 +150,7 @@ pub enum PeerResponseResult { /// Represents a result containing node data or an error. NodeData(RequestResult>), /// Represents a result containing receipts or an error. - Receipts(RequestResult>>>), + Receipts(RequestResult>>>), } // === impl PeerResponseResult === diff --git a/crates/node/builder/src/builder/mod.rs b/crates/node/builder/src/builder/mod.rs index 98c831f2f5a2..2413609d032c 100644 --- a/crates/node/builder/src/builder/mod.rs +++ b/crates/node/builder/src/builder/mod.rs @@ -662,11 +662,8 @@ impl BuilderContext { >, > + Unpin + 'static, - Node::Provider: BlockReader< - Receipt = reth_primitives::Receipt, - Block = N::Block, - Header = N::BlockHeader, - >, + Node::Provider: + BlockReader, { self.start_network_with(builder, pool, Default::default()) } @@ -692,11 +689,8 @@ impl BuilderContext { >, > + Unpin + 'static, - Node::Provider: BlockReader< - Receipt = reth_primitives::Receipt, - Block = N::Block, - Header = N::BlockHeader, - >, + Node::Provider: + BlockReader, { let (handle, network, txpool, eth) = builder .transactions(pool, tx_config)