Skip to content

Commit

Permalink
feat: remove default receipts for network components (#13371)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rjected authored Dec 12, 2024
1 parent 1289a76 commit 02f76b8
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 31 deletions.
6 changes: 5 additions & 1 deletion crates/net/eth-wire-types/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,11 @@ pub enum EthMessage<N: NetworkPrimitives = EthNetworkPrimitives> {
/// Represents a `GetReceipts` request-response pair.
GetReceipts(RequestPair<GetReceipts>),
/// Represents a Receipts request-response pair.
Receipts(RequestPair<Receipts>),
#[cfg_attr(
feature = "serde",
serde(bound = "N::Receipt: serde::Serialize + serde::de::DeserializeOwned")
)]
Receipts(RequestPair<Receipts<N::Receipt>>),
}

impl<N: NetworkPrimitives> EthMessage<N> {
Expand Down
12 changes: 5 additions & 7 deletions crates/net/eth-wire-types/src/primitives.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -30,15 +31,12 @@ pub trait NetworkPrimitives:
type PooledTransaction: SignedTransaction + TryFrom<Self::BroadcastedTransaction> + '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;
}

Expand Down
2 changes: 1 addition & 1 deletion crates/net/network-api/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ pub enum PeerRequest<N: NetworkPrimitives = EthNetworkPrimitives> {
/// The request for receipts.
request: GetReceipts,
/// The channel to send the response for receipts.
response: oneshot::Sender<RequestResult<Receipts>>,
response: oneshot::Sender<RequestResult<Receipts<N::Receipt>>>,
},
}

Expand Down
2 changes: 1 addition & 1 deletion crates/net/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ where
impl<C, N> NetworkConfig<C, N>
where
N: NetworkPrimitives,
C: BlockReader<Block = N::Block, Receipt = reth_primitives::Receipt, Header = N::BlockHeader>
C: BlockReader<Block = N::Block, Receipt = N::Receipt, Header = N::BlockHeader>
+ HeaderProvider
+ Clone
+ Unpin
Expand Down
16 changes: 7 additions & 9 deletions crates/net/network/src/eth_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,7 +81,7 @@ impl<C, N: NetworkPrimitives> EthRequestHandler<C, N> {
impl<C, N> EthRequestHandler<C, N>
where
N: NetworkPrimitives,
C: BlockReader + HeaderProvider + ReceiptProvider<Receipt = reth_primitives::Receipt>,
C: BlockReader + HeaderProvider + ReceiptProvider<Receipt: Encodable + TxReceipt>,
{
/// Returns the list of requested headers
fn get_headers_response(&self, request: GetBlockHeaders) -> Vec<C::Header> {
Expand Down Expand Up @@ -188,7 +188,7 @@ where
&self,
_peer_id: PeerId,
request: GetReceipts,
response: oneshot::Sender<RequestResult<Receipts>>,
response: oneshot::Sender<RequestResult<Receipts<C::Receipt>>>,
) {
self.metrics.eth_receipts_requests_received_total.increment(1);

Expand All @@ -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::<Vec<_>>();
let receipt =
receipts_by_block.into_iter().map(ReceiptWithBloom::from).collect::<Vec<_>>();

total_bytes += receipt.length();
receipts.push(receipt);
Expand All @@ -226,7 +224,7 @@ where
impl<C, N> Future for EthRequestHandler<C, N>
where
N: NetworkPrimitives,
C: BlockReader<Block = N::Block, Receipt = reth_primitives::Receipt>
C: BlockReader<Block = N::Block, Receipt = N::Receipt>
+ HeaderProvider<Header = N::BlockHeader>
+ Unpin,
{
Expand Down Expand Up @@ -317,6 +315,6 @@ pub enum IncomingEthRequest<N: NetworkPrimitives = EthNetworkPrimitives> {
/// The specific receipts requested.
request: GetReceipts,
/// The channel sender for the response containing receipts.
response: oneshot::Sender<RequestResult<Receipts>>,
response: oneshot::Sender<RequestResult<Receipts<N::Receipt>>>,
},
}
4 changes: 2 additions & 2 deletions crates/net/network/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub enum PeerResponse<N: NetworkPrimitives = EthNetworkPrimitives> {
/// Represents a response to a request for receipts.
Receipts {
/// The receiver channel for the response to a receipts request.
response: oneshot::Receiver<RequestResult<Receipts>>,
response: oneshot::Receiver<RequestResult<Receipts<N::Receipt>>>,
},
}

Expand Down Expand Up @@ -150,7 +150,7 @@ pub enum PeerResponseResult<N: NetworkPrimitives = EthNetworkPrimitives> {
/// Represents a result containing node data or an error.
NodeData(RequestResult<Vec<Bytes>>),
/// Represents a result containing receipts or an error.
Receipts(RequestResult<Vec<Vec<ReceiptWithBloom<reth_primitives::Receipt>>>>),
Receipts(RequestResult<Vec<Vec<ReceiptWithBloom<N::Receipt>>>>),
}

// === impl PeerResponseResult ===
Expand Down
14 changes: 4 additions & 10 deletions crates/node/builder/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -662,11 +662,8 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
>,
> + Unpin
+ 'static,
Node::Provider: BlockReader<
Receipt = reth_primitives::Receipt,
Block = N::Block,
Header = N::BlockHeader,
>,
Node::Provider:
BlockReader<Receipt = N::Receipt, Block = N::Block, Header = N::BlockHeader>,
{
self.start_network_with(builder, pool, Default::default())
}
Expand All @@ -692,11 +689,8 @@ impl<Node: FullNodeTypes> BuilderContext<Node> {
>,
> + Unpin
+ 'static,
Node::Provider: BlockReader<
Receipt = reth_primitives::Receipt,
Block = N::Block,
Header = N::BlockHeader,
>,
Node::Provider:
BlockReader<Receipt = N::Receipt, Block = N::Block, Header = N::BlockHeader>,
{
let (handle, network, txpool, eth) = builder
.transactions(pool, tx_config)
Expand Down

0 comments on commit 02f76b8

Please sign in to comment.