Skip to content

Commit

Permalink
feat: cancel in progress full blocks (paradigmxyz#2813)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored May 24, 2023
1 parent 2ec97f3 commit df82387
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
10 changes: 9 additions & 1 deletion crates/consensus/beacon/src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions crates/consensus/beacon/src/engine/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit df82387

Please sign in to comment.