Skip to content

Commit fd2065a

Browse files
committed
feat(sync): implement state-based bootstrap detection to resolve genesis deadlock
Resolves critical issue preventing network initialization from genesis state. Problem: - Nodes at height 0 with no peers remained in DiscoveringPeers state indefinitely - Block production rejected with NotSynced error during peer discovery - Two-node regtest networks could never bootstrap from genesis - Created permanent deadlock preventing any block production Solution: - Implement multi-factor bootstrap detection with 30-second timeout - Allow block production when: height==0 AND no_peers AND timeout_reached - Add state transition tracking to accumulate discovery time - Reset bootstrap timer when first peers are discovered - Prevent fork creation by restricting bootstrap to genesis (height==0) only Key Changes: - Add bootstrap timing fields to SyncActor (state_entered_at, discovery_time_accumulated) - Implement transition_to_state() helper with automatic time tracking - Implement determine_sync_state() with bootstrap detection logic - Implement check_bootstrap_mode() with multi-factor safety checks - Update get_sync_status() to use new bootstrap-aware logic - Update UpdatePeers handler to reset timer on peer discovery - Refactor all state transitions to use timing-aware helper method Safety Features: - Genesis-only restriction prevents forks during network partitions - Multi-factor detection prevents false positives - Self-correcting: automatically exits bootstrap when peers appear - Progressive logging (trace -> info -> warn) for operational visibility Testing: - 8 comprehensive unit tests covering all bootstrap scenarios - Tests validate fork prevention (height > 0 blocked) - Tests verify timer accumulation and reset logic - All tests passing with 100% success rate Documentation: - SYNC_BOOTSTRAP_IMPLEMENTATION_PLAN.md provides complete technical analysis - Inline documentation explains bootstrap detection logic - Implementation plan includes regtest testing procedures
1 parent 73fdc71 commit fd2065a

File tree

2 files changed

+2044
-35
lines changed

2 files changed

+2044
-35
lines changed

0 commit comments

Comments
 (0)