Skip to main content

reth_network_p2p/receipts/
client.rs

1use std::pin::Pin;
2
3use crate::{download::DownloadClient, error::PeerRequestResult, priority::Priority};
4use alloy_consensus::TxReceipt;
5use alloy_primitives::B256;
6use futures::Future;
7use reth_eth_wire_types::Receipts70;
8
9/// The receipts future type
10pub type ReceiptsFut<R = reth_ethereum_primitives::Receipt> =
11    Pin<Box<dyn Future<Output = PeerRequestResult<ReceiptsResponse<R>>> + Send + Sync>>;
12
13/// Response from a receipts request.
14///
15/// **Note for [`ReceiptsClient`] callers:** the network layer handles eth/70
16/// continuation rounds internally, so `last_block_incomplete` is always `false`
17/// by the time this response reaches a [`ReceiptsClient`] consumer. The field
18/// exists for internal use by the fetcher during multi-round assembly.
19#[derive(Debug, Clone, PartialEq, Eq)]
20pub struct ReceiptsResponse<R> {
21    /// Receipts grouped by block, in the same order as the requested hashes.
22    pub receipts: Vec<Vec<R>>,
23    /// When `true`, the **last** block in [`receipts`](Self::receipts) was
24    /// truncated by the remote peer (eth/70 `Receipts70.last_block_incomplete`).
25    ///
26    /// This is used internally by the fetcher to drive continuation rounds.
27    /// Responses surfaced through [`ReceiptsClient`] always have this set to
28    /// `false`.
29    pub last_block_incomplete: bool,
30}
31
32impl<R> ReceiptsResponse<R> {
33    /// Creates a complete (non-truncated) response.
34    #[inline]
35    pub const fn new(receipts: Vec<Vec<R>>) -> Self {
36        Self { receipts, last_block_incomplete: false }
37    }
38}
39
40impl<R> From<Receipts70<R>> for ReceiptsResponse<R> {
41    fn from(r70: Receipts70<R>) -> Self {
42        Self { receipts: r70.receipts, last_block_incomplete: r70.last_block_incomplete }
43    }
44}
45
46/// A client capable of downloading block receipts from peers.
47#[auto_impl::auto_impl(&, Arc, Box)]
48pub trait ReceiptsClient: DownloadClient {
49    /// The receipt type this client fetches.
50    type Receipt: TxReceipt;
51
52    /// The output of the request future for querying block receipts.
53    type Output: Future<Output = PeerRequestResult<ReceiptsResponse<Self::Receipt>>>
54        + Sync
55        + Send
56        + Unpin;
57
58    /// Fetches the receipts for the requested block hashes.
59    fn get_receipts(&self, hashes: Vec<B256>) -> Self::Output {
60        self.get_receipts_with_priority(hashes, Priority::Normal)
61    }
62
63    /// Fetches the receipts for the requested block hashes with priority.
64    fn get_receipts_with_priority(&self, hashes: Vec<B256>, priority: Priority) -> Self::Output;
65}