From 5c7d5a3b3e81431a75eb5b910ea93a70904ab7bb Mon Sep 17 00:00:00 2001 From: int88 <106391185+int88@users.noreply.github.com> Date: Fri, 30 Jun 2023 20:01:30 +0800 Subject: [PATCH] feat: make chain canonical if new payload is the missing block for current sync target (#3459) Co-authored-by: Matthias Seitz --- crates/consensus/beacon/src/engine/forkchoice.rs | 3 ++- crates/consensus/beacon/src/engine/mod.rs | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/consensus/beacon/src/engine/forkchoice.rs b/crates/consensus/beacon/src/engine/forkchoice.rs index 8332ea0308..f41200e396 100644 --- a/crates/consensus/beacon/src/engine/forkchoice.rs +++ b/crates/consensus/beacon/src/engine/forkchoice.rs @@ -18,7 +18,8 @@ pub(crate) struct ForkchoiceStateTracker { impl ForkchoiceStateTracker { /// Sets the latest forkchoice state that we received. /// - /// If the status is valid, we also update the last valid forkchoice state. + /// If the status is `VALID`, we also update the last valid forkchoice state and set the + /// `sync_target` to `None`, since we're now fully synced. pub(crate) fn set_latest(&mut self, state: ForkchoiceState, status: ForkchoiceStatus) { if status.is_valid() { self.set_valid(state); diff --git a/crates/consensus/beacon/src/engine/mod.rs b/crates/consensus/beacon/src/engine/mod.rs index 7f6c23bcf9..d815d91b31 100644 --- a/crates/consensus/beacon/src/engine/mod.rs +++ b/crates/consensus/beacon/src/engine/mod.rs @@ -830,6 +830,7 @@ where Err(status) => return Ok(status), }; let block_hash = block.hash(); + let block_num_hash = block.num_hash(); // now check the block itself if let Some(status) = self.check_invalid_ancestor_with_head(block.parent_hash, block.hash) { @@ -847,6 +848,13 @@ where let status = match res { Ok(status) => { if status.is_valid() { + if let Some(target) = self.forkchoice_state_tracker.sync_target_state() { + // if we're currently syncing and the inserted block is the targeted FCU + // head block, we can try to make it canonical. + if block_hash == target.head_block_hash { + self.try_make_sync_target_canonical(block_num_hash); + } + } // block was successfully inserted, so we can cancel the full block request, if // any exists self.sync.cancel_full_block_request(block_hash);