mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
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:
@ -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);
|
||||
|
||||
@ -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);
|
||||
|
||||
Reference in New Issue
Block a user