diff --git a/p2p/cuprate-p2p/src/block_downloader.rs b/p2p/cuprate-p2p/src/block_downloader.rs index 58424c5d..2ce59d9b 100644 --- a/p2p/cuprate-p2p/src/block_downloader.rs +++ b/p2p/cuprate-p2p/src/block_downloader.rs @@ -190,6 +190,27 @@ where else { return; }; + + let next_request_id = self + .inflight_requests + .last_key_value() + .map(|(id, _)| *id + 1) + .unwrap_or(0); + + self.inflight_requests + .insert(next_request_id, block_entry_to_get.clone()); + + self.block_download_tasks.spawn(async move { + ( + next_request_id, + request_batch_from_peer( + client, + block_entry_to_get.ids, + block_entry_to_get.start_height, + ) + .await, + ) + }); } async fn run(mut self) -> Result<(), BlockDownloadError> { @@ -219,7 +240,7 @@ where } } -async fn request_batch<N: NetworkZone>( +async fn request_batch_from_peer<N: NetworkZone>( mut client: ClientPoolDropGuard<N>, ids: ByteArrayVec<32>, expected_start_height: u64, diff --git a/p2p/cuprate-p2p/src/block_downloader/chain_tracker.rs b/p2p/cuprate-p2p/src/block_downloader/chain_tracker.rs index a325905e..a23ba3ad 100644 --- a/p2p/cuprate-p2p/src/block_downloader/chain_tracker.rs +++ b/p2p/cuprate-p2p/src/block_downloader/chain_tracker.rs @@ -19,6 +19,7 @@ pub(crate) struct ChainEntry<N: NetworkZone> { } /// A batch of blocks to retrieve. +#[derive(Clone)] pub struct BlocksToRetrieve<N: NetworkZone> { /// The block IDs to get. pub ids: ByteArrayVec<32>,