spawn task whe getting blocks

This commit is contained in:
Boog900 2024-05-27 01:31:07 +01:00
parent 851a898b03
commit eb69895278
No known key found for this signature in database
GPG key ID: 42AB1287CB0041C2
2 changed files with 23 additions and 1 deletions

View file

@ -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,

View file

@ -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>,