reth_network_p2p/snap/
client.rs

1use crate::{download::DownloadClient, error::PeerRequestResult, priority::Priority};
2use futures::Future;
3use reth_eth_wire_types::snap::{
4    AccountRangeMessage, ByteCodesMessage, GetAccountRangeMessage, GetByteCodesMessage,
5    GetStorageRangesMessage, GetTrieNodesMessage, StorageRangesMessage, TrieNodesMessage,
6};
7
8/// Response types for snap sync requests
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub enum SnapResponse {
11    /// Response containing account range data
12    AccountRange(AccountRangeMessage),
13    /// Response containing storage ranges data
14    StorageRanges(StorageRangesMessage),
15    /// Response containing bytecode data
16    ByteCodes(ByteCodesMessage),
17    /// Response containing trie node data
18    TrieNodes(TrieNodesMessage),
19}
20
21/// The snap sync downloader client
22#[auto_impl::auto_impl(&, Arc, Box)]
23pub trait SnapClient: DownloadClient {
24    /// The output future type for snap requests
25    type Output: Future<Output = PeerRequestResult<SnapResponse>> + Send + Sync + Unpin;
26
27    /// Sends the account range request to the p2p network and returns the account range
28    /// response received from a peer.
29    fn get_account_range(&self, request: GetAccountRangeMessage) -> Self::Output {
30        self.get_account_range_with_priority(request, Priority::Normal)
31    }
32
33    /// Sends the account range request to the p2p network with priority set and returns
34    /// the account range response received from a peer.
35    fn get_account_range_with_priority(
36        &self,
37        request: GetAccountRangeMessage,
38        priority: Priority,
39    ) -> Self::Output;
40
41    /// Sends the storage ranges request to the p2p network and returns the storage ranges
42    /// response received from a peer.
43    fn get_storage_ranges(&self, request: GetStorageRangesMessage) -> Self::Output;
44
45    /// Sends the storage ranges request to the p2p network with priority set and returns
46    /// the storage ranges response received from a peer.
47    fn get_storage_ranges_with_priority(
48        &self,
49        request: GetStorageRangesMessage,
50        priority: Priority,
51    ) -> Self::Output;
52
53    /// Sends the byte codes request to the p2p network and returns the byte codes
54    /// response received from a peer.
55    fn get_byte_codes(&self, request: GetByteCodesMessage) -> Self::Output;
56
57    /// Sends the byte codes request to the p2p network with priority set and returns
58    /// the byte codes response received from a peer.
59    fn get_byte_codes_with_priority(
60        &self,
61        request: GetByteCodesMessage,
62        priority: Priority,
63    ) -> Self::Output;
64
65    /// Sends the trie nodes request to the p2p network and returns the trie nodes
66    /// response received from a peer.
67    fn get_trie_nodes(&self, request: GetTrieNodesMessage) -> Self::Output;
68
69    /// Sends the trie nodes request to the p2p network with priority set and returns
70    /// the trie nodes response received from a peer.
71    fn get_trie_nodes_with_priority(
72        &self,
73        request: GetTrieNodesMessage,
74        priority: Priority,
75    ) -> Self::Output;
76}