Commit 1c8086b
feat(sync): implement production-ready sync features with NetworkActor integration
Implements three critical features for SyncActor functionality:
**Feature 1: LoadCheckpoint Handler**
- Full checkpoint loading with state restoration
- Automatic sync resumption based on SYNC_THRESHOLD (2 blocks)
- Error handling for missing/corrupted checkpoints
- Graceful fallback to fresh start on checkpoint errors
**Feature 2: Active Peer Discovery**
- StartSync handler queries NetworkActor.GetConnectedPeers directly
- UpdatePeers handler triggers state transitions on peer discovery/loss
- Automatic transition to RequestingBlocks when peers available
- Returns to DiscoveringPeers if all peers lost during sync
**Feature 3: Active Sync Loop**
- Periodic block requesting (2-second interval) during active sync
- Completion detection (5-second interval) with threshold checking
- RequestBlocks handler with CRITICAL correlation_id fix for request tracking
- Rate limiting via max_concurrent_requests configuration
**Metrics Enhancements**
- Added record_checkpoint_loaded() for checkpoint metrics
- Added record_sync_complete() for sync completion tracking
**Architecture**
Uses direct NetworkActor integration instead of External Coordinator pattern:
- NetworkMessage::GetConnectedPeers for peer discovery
- NetworkMessage::RequestBlocks with correlation_id for block fetching
- NetworkMessage::HandleBlockResponse for automatic forwarding
All 43 unit tests passing. Production-ready implementation.
Co-Authored-By: Claude <[email protected]>1 parent d214db2 commit 1c8086b
2 files changed
+332
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
609 | 609 | | |
610 | 610 | | |
611 | 611 | | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
612 | 632 | | |
613 | 633 | | |
614 | 634 | | |
| |||
0 commit comments