Skip to content

Commit 69df27e

Browse files
feat: add Client trait for snap sync downloader client (paradigmxyz#15449)
1 parent 40015a8 commit 69df27e

4 files changed

Lines changed: 30 additions & 1 deletion

File tree

crates/net/eth-wire-types/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub use capability::*;
4747
pub mod primitives;
4848
pub use primitives::*;
4949

50-
mod snap;
50+
pub mod snap;
5151
pub use snap::*;
5252

5353
/// re-export for convenience

crates/net/p2p/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ pub mod priority;
4141
/// Syncing related traits.
4242
pub mod sync;
4343

44+
/// Snap related traits.
45+
pub mod snap;
46+
4447
/// Common test helpers for mocking out Consensus, Downloaders and Header Clients.
4548
#[cfg(any(test, feature = "test-utils"))]
4649
pub mod test_utils;

crates/net/p2p/src/snap/client.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use crate::{download::DownloadClient, error::PeerRequestResult, priority::Priority};
2+
use futures::Future;
3+
use reth_eth_wire_types::snap::{AccountRangeMessage, GetAccountRangeMessage};
4+
5+
/// The snap sync downloader client
6+
#[auto_impl::auto_impl(&, Arc, Box)]
7+
pub trait SnapClient: DownloadClient {
8+
/// The output future type for account range requests
9+
type Output: Future<Output = PeerRequestResult<AccountRangeMessage>> + Send + Sync + Unpin;
10+
11+
/// Sends the account range request to the p2p network and returns the account range
12+
/// response received from a peer.
13+
fn get_account_range(&self, request: GetAccountRangeMessage) -> Self::Output {
14+
self.get_account_range_with_priority(request, Priority::Normal)
15+
}
16+
17+
/// Sends the account range request to the p2p network with priority set and returns
18+
/// the account range response received from a peer.
19+
fn get_account_range_with_priority(
20+
&self,
21+
request: GetAccountRangeMessage,
22+
priority: Priority,
23+
) -> Self::Output;
24+
}

crates/net/p2p/src/snap/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/// SNAP related traits.
2+
pub mod client;

0 commit comments

Comments
 (0)