Skip to content

Commit 9bbcbf5

Browse files
committed
fix(sync): set SYNC_THRESHOLD to 0 to prevent premature sync completion (TM-A1)
Nodes were incorrectly marked as "synced" when 1-2 blocks behind due to SYNC_THRESHOLD=2. This caused consensus stalls after partition recovery because nodes never requested missing blocks (e.g., node at height 615 with target 617 passed the check: 615 + 2 >= 617). Changed SYNC_THRESHOLD from 2 to 0 at all 5 locations in sync_actor.rs so nodes are only considered synced when current_height >= target_height.
1 parent 7485468 commit 9bbcbf5

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

app/src/actors_v2/network/sync_actor.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl SyncActorState {
146146

147147
/// Determine if we're in active sync or bootstrap mode
148148
fn determine_sync_state(&self) -> bool {
149-
const SYNC_THRESHOLD: u64 = 2;
149+
const SYNC_THRESHOLD: u64 = 0;
150150

151151
// Case 1: Target height known → Simple comparison
152152
if self.target_height > 0 {
@@ -704,7 +704,7 @@ impl Actor for SyncActor {
704704
let mut s = state.write().unwrap();
705705

706706
// Check if sync is complete
707-
const SYNC_THRESHOLD: u64 = 2;
707+
const SYNC_THRESHOLD: u64 = 0;
708708

709709
// Sync is complete when:
710710
// 1. Sync is running and in active sync state (RequestingBlocks or ProcessingBlocks)
@@ -894,7 +894,7 @@ impl Handler<SyncMessage> for SyncActor {
894894
);
895895

896896
// Check if already synced
897-
const SYNC_THRESHOLD: u64 = 2;
897+
const SYNC_THRESHOLD: u64 = 0;
898898
if s.target_height > 0
899899
&& s.current_height + SYNC_THRESHOLD >= s.target_height
900900
{
@@ -949,7 +949,7 @@ impl Handler<SyncMessage> for SyncActor {
949949

950950
// Transition based on peer availability and sync status
951951
if !s.sync_peers.is_empty() {
952-
const SYNC_THRESHOLD: u64 = 2;
952+
const SYNC_THRESHOLD: u64 = 0;
953953

954954
if s.target_height == 0 {
955955
// target_height=0 means we haven't queried the network yet
@@ -1484,7 +1484,7 @@ impl Handler<SyncMessage> for SyncActor {
14841484

14851485
// Transition based on sync status
14861486
if s.is_running && s.sync_state == SyncState::DiscoveringPeers {
1487-
const SYNC_THRESHOLD: u64 = 2;
1487+
const SYNC_THRESHOLD: u64 = 0;
14881488

14891489
if s.target_height == 0 {
14901490
// target_height=0 means we haven't queried the network yet

0 commit comments

Comments
 (0)