Skip to main content

reth_network_p2p/block_access_lists/
client.rs

1use crate::{download::DownloadClient, error::PeerRequestResult, priority::Priority};
2use alloy_primitives::B256;
3use auto_impl::auto_impl;
4use futures::Future;
5use reth_eth_wire_types::BlockAccessLists;
6
7/// Controls whether a BAL request must wait for a capable peer or may complete early when none are
8/// available.
9#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
10pub enum BalRequirement {
11    /// Keep waiting until an eth/71-capable peer is available.
12    Mandatory,
13    /// Return early if no connected peer can serve BALs.
14    #[default]
15    Optional,
16}
17
18/// A client capable of downloading block access lists.
19#[auto_impl(&, Arc, Box)]
20pub trait BlockAccessListsClient: DownloadClient {
21    /// The bal type this client fetches.
22    type Output: Future<Output = PeerRequestResult<BlockAccessLists>> + Send + Sync + Unpin;
23
24    ///  Fetches the block access lists for given hashes.
25    fn get_block_access_lists(&self, hashes: Vec<B256>) -> Self::Output {
26        self.get_block_access_lists_with_priority_and_requirement(
27            hashes,
28            Priority::Normal,
29            BalRequirement::default(),
30        )
31    }
32
33    /// Fetches the block access lists for given hashes with the requested BAL availability policy.
34    fn get_block_access_lists_with_requirement(
35        &self,
36        hashes: Vec<B256>,
37        requirement: BalRequirement,
38    ) -> Self::Output {
39        self.get_block_access_lists_with_priority_and_requirement(
40            hashes,
41            Priority::Normal,
42            requirement,
43        )
44    }
45
46    ///  Fetches the block access lists for given hashes with priority
47    fn get_block_access_lists_with_priority(
48        &self,
49        hashes: Vec<B256>,
50        priority: Priority,
51    ) -> Self::Output {
52        self.get_block_access_lists_with_priority_and_requirement(
53            hashes,
54            priority,
55            BalRequirement::default(),
56        )
57    }
58
59    /// Fetches the block access lists for given hashes with priority and BAL availability policy.
60    fn get_block_access_lists_with_priority_and_requirement(
61        &self,
62        hashes: Vec<B256>,
63        priority: Priority,
64        requirement: BalRequirement,
65    ) -> Self::Output;
66}