Skip to content

Commit

Permalink
fix: lagging code (#6441)
Browse files Browse the repository at this point in the history
Fixes a bug where the node would not reorg to a chain with a lower
height, even if it had a higher difficulty
  • Loading branch information
stringhandler committed Aug 2, 2024
1 parent ad14053 commit af1f451
Showing 1 changed file with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -380,19 +380,26 @@ fn determine_sync_mode(
}

// This is to test the block propagation by delaying lagging.
if local_tip_height.saturating_add(blocks_behind_before_considered_lagging) > network_tip_height {
info!(
target: LOG_TARGET,
"While we are behind, we are still within {} blocks of them, so we are staying as listening and \
waiting for the propagated blocks",
blocks_behind_before_considered_lagging
);
return SyncStatus::BehindButNotYetLagging {
local: local.clone(),
network: network.claimed_chain_metadata().clone(),
sync_peers: vec![network.clone().into()],
// If the config is 0, ignore this set.
if blocks_behind_before_considered_lagging > 0 {
// Otherwise, only wait when the tip is above us, otherwise
// chains with a lower height will never be reorged to.
if network_tip_height > local_tip_height &&
local_tip_height.saturating_add(blocks_behind_before_considered_lagging) > network_tip_height
{
info!(
target: LOG_TARGET,
"While we are behind, we are still within {} blocks of them, so we are staying as listening and \
waiting for the propagated blocks",
blocks_behind_before_considered_lagging
);
return SyncStatus::BehindButNotYetLagging {
local: local.clone(),
network: network.claimed_chain_metadata().clone(),
sync_peers: vec![network.clone().into()],
};
};
};
}

debug!(
target: LOG_TARGET,
Expand Down

0 comments on commit af1f451

Please sign in to comment.