You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This commit addresses three critical bugs (P0) and one enhancement (P1) in the V2 sync
detection system that prevented nodes from properly detecting when they are behind the
network and need to sync before producing blocks.
## Critical Bugs Fixed
### Bug #1: Placeholder Height Discovery
- **Problem**: SyncActor used `status.connected_peers` (peer count) instead of actual
chain height for sync target discovery
- **Fix**: Added `chain_height` field to NetworkStatus and updated SyncActor to use
actual blockchain height
- **Impact**: Sync target height now correctly reflects network state
### Bug #2: Incorrect Sync State Reporting
- **Problem**: `is_syncing` only returned true for 2 of 7 sync states, causing nodes
at height 0 to report "synced" when network was 13+ blocks ahead
- **Fix**: Replaced state-based logic with height comparison using 2-block tolerance
- **Impact**: Sync status now accurately reflects whether node is behind network
### Bug #3: No-Op InitializeSyncState Handler
- **Problem**: Handler logged message but took no action, leaving SyncActor in Stopped
state with no sync triggered on startup
- **Fix**: Implemented full initialization logic that queries storage height and
triggers sync discovery
- **Impact**: Sync now properly initializes on node startup
## Enhancement
### Faster Health Check on Startup
- Added initial health check at T+5s (previously T+60s)
- Enables faster detection of startup sync issues
- Continues with 60-second periodic checks after initial check
## Files Modified
- app/src/actors_v2/network/messages.rs: Added chain_height field, enhanced StartSync
- app/src/actors_v2/network/network_actor.rs: Added get_network_status_async()
- app/src/actors_v2/network/sync_actor.rs: Fixed height discovery, sync logic, handler
- app/src/actors_v2/chain/handlers.rs: Implemented InitializeSyncState handler
- app/src/actors_v2/chain/actor.rs: Added initial health check, updated trigger_sync
- app/src/actors_v2/network/rpc.rs: Added chain_height to RPC responses
- app/src/actors_v2/network/handlers/network_handlers.rs: Added chain_height field
- Test files: Updated StartSync message construction
## Testing
Before: Node-2 starting 30s after Node-1 incorrectly reported "Node is synced" at
height 0 and attempted block production while 13+ blocks behind.
Expected After: Node-2 detects it's behind, reports "Skipping block production - node
is syncing", syncs to current height, then resumes block production.
0 commit comments