feat: make chain canonical if new payload is the missing block for current sync target (#3459)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
int88
2023-06-30 20:01:30 +08:00
committed by GitHub
parent 07e81c0e7e
commit 5c7d5a3b3e
2 changed files with 10 additions and 1 deletions

View File

@ -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);

View File

@ -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);