Skip to content

Commit 1c8086b

Browse files
michaelgptclaude
andcommitted
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

File tree

2 files changed

+332
-17
lines changed

2 files changed

+332
-17
lines changed

app/src/actors_v2/network/metrics.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,26 @@ impl SyncMetrics {
609609
std::time::Duration::from_secs(0)
610610
}
611611
}
612+
613+
pub fn record_checkpoint_loaded(&mut self, blocks_synced: u64) {
614+
self.blocks_synced = blocks_synced;
615+
self.last_updated = SystemTime::now();
616+
tracing::debug!(
617+
blocks_synced = blocks_synced,
618+
"Checkpoint loaded metrics recorded"
619+
);
620+
}
621+
622+
pub fn record_sync_complete(&mut self, final_height: u64) {
623+
self.current_height = final_height;
624+
self.is_syncing = false;
625+
self.last_updated = SystemTime::now();
626+
tracing::info!(
627+
final_height = final_height,
628+
blocks_synced = self.blocks_synced,
629+
"Sync completed successfully - metrics recorded"
630+
);
631+
}
612632
}
613633

614634
impl Default for SyncMetrics {

0 commit comments

Comments
 (0)