diff --git a/blockchain/chain_sync/src/tipset_syncer.rs b/blockchain/chain_sync/src/tipset_syncer.rs index c77313838ab..92cef2dbc7a 100644 --- a/blockchain/chain_sync/src/tipset_syncer.rs +++ b/blockchain/chain_sync/src/tipset_syncer.rs @@ -913,15 +913,16 @@ async fn sync_headers_in_reverse FORK_LENGTH_THRESHOLD { - return Err(TipsetRangeSyncerError::ChainForkLengthExceedsMaximum); - } - // If we have not found a common ancestor by the last iteration, then return an error - if i == (fork_tipsets.len() - 1) { - return Err(TipsetRangeSyncerError::ChainForkLengthExceedsFinalityThreshold); + if potential_common_ancestor.epoch() < fork_tipsets[i].epoch() { + i += 1; + } else { + fork_length += 1; + // Increment the fork length and enfore the fork length check + if fork_length > FORK_LENGTH_THRESHOLD { + return Err(TipsetRangeSyncerError::ChainForkLengthExceedsMaximum); + } + // If we have not found a common ancestor by the last iteration, then return an error + if i == (fork_tipsets.len() - 1) { + return Err(TipsetRangeSyncerError::ChainForkLengthExceedsFinalityThreshold); + } + potential_common_ancestor = chain_store + .tipset_from_keys(potential_common_ancestor.parents()) + .await?; } - potential_common_ancestor = chain_store - .tipset_from_keys(potential_common_ancestor.parents()) - .await?; } } Ok(parent_tipsets)