feat: cancel in progress full blocks (#2813)

This commit is contained in:
Matthias Seitz
2023-05-24 14:22:30 +02:00
committed by GitHub
parent 2ec97f34fe
commit df8238718c
2 changed files with 14 additions and 1 deletions

View File

@ -624,6 +624,7 @@ where
Ok(block) => block,
Err(status) => return Ok(status),
};
let block_hash = block.hash();
let res = if self.sync.is_pipeline_idle() {
// we can only insert new payloads if the pipeline is _not_ running, because it holds
@ -634,7 +635,14 @@ where
};
let status = match res {
Ok(status) => Ok(status),
Ok(status) => {
if status.is_valid() {
// block was successfully inserted, so we can cancel the full block request, if
// any exists
self.sync.cancel_full_block_request(block_hash);
}
Ok(status)
}
Err(error) => {
debug!(target: "consensus::engine", ?error, "Error while processing payload");
self.map_insert_error(error)

View File

@ -85,6 +85,11 @@ where
self.inflight_full_block_requests.clear();
}
/// Cancels the full block request with the given hash.
pub(crate) fn cancel_full_block_request(&mut self, hash: H256) {
self.inflight_full_block_requests.retain(|req| *req.hash() != hash);
}
/// Returns `true` if the pipeline is idle.
pub(crate) fn is_pipeline_idle(&self) -> bool {
self.pipeline_state.is_idle()