perf: ignore download request if already inflight (#2856)

This commit is contained in:
Matthias Seitz
2023-05-26 14:23:45 +02:00
committed by GitHub
parent 01d264c9ae
commit dd0a0f2951
2 changed files with 14 additions and 2 deletions

View File

@@ -558,7 +558,7 @@ where
self.sync.set_pipeline_sync_target(target);
} else {
// trigger a full block download for the _missing_ new head
self.sync.download_full_block(state.head_block_hash)
self.sync.download_full_block(state.head_block_hash);
}
PayloadStatus::from_status(PayloadStatusEnum::Syncing)

View File

@@ -100,8 +100,19 @@ where
self.pipeline_state.is_idle()
}
/// Returns true if there's already a request for the given hash.
pub(crate) fn is_inflight_request(&self, hash: H256) -> bool {
self.inflight_full_block_requests.iter().any(|req| *req.hash() == hash)
}
/// Starts requesting a full block from the network.
pub(crate) fn download_full_block(&mut self, hash: H256) {
///
/// Returns `true` if the request was started, `false` if there's already a request for the
/// given hash.
pub(crate) fn download_full_block(&mut self, hash: H256) -> bool {
if self.is_inflight_request(hash) {
return false
}
trace!(
target: "consensus::engine",
?hash,
@@ -109,6 +120,7 @@ where
);
let request = self.full_block_client.get_full_block(hash);
self.inflight_full_block_requests.push(request);
true
}
/// Sets a new target to sync the pipeline to.