Skip to content

Comments

feat: add cycle to SyncEvent::SyncComplete#459

Open
xdustinface wants to merge 1 commit intov0.42-devfrom
feat/sync-cycle
Open

feat: add cycle to SyncEvent::SyncComplete#459
xdustinface wants to merge 1 commit intov0.42-devfrom
feat/sync-cycle

Conversation

@xdustinface
Copy link
Collaborator

@xdustinface xdustinface commented Feb 20, 2026

Emit SyncComplete on every not-synced to synced transition instead of only once, with a cycle field (0 = initial, 1+ = incremental) so consumers can distinguish sync phases. Duration logging measures per-cycle time instead of time since client start.

Summary by CodeRabbit

Release Notes

  • New Features
    • Enhanced sync completion tracking with cycle information now included in sync events for better progress monitoring and cycle management.

Emit `SyncComplete` on every not-synced to synced transition instead of only once, with a cycle field (0 = initial, 1+ = incremental) so consumers can distinguish sync phases.
Duration logging measures per-cycle time instead of time since client start.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 20, 2026

📝 Walkthrough

Walkthrough

A cycle parameter is added to the OnSyncCompleteCallback function signature and SyncComplete event variant across FFI interfaces, callbacks, and synchronization logic to track synchronization cycles. The cycle value propagates from the sync coordinator through the event and callback systems, with cycle counting and timing logic implemented in the progress aggregation task.

Changes

Cohort / File(s) Summary
FFI Header & Type Definitions
dash-spv-ffi/include/dash_spv_ffi.h, dash-spv-ffi/src/callbacks.rs
OnSyncCompleteCallback function pointer type updated to include uint32_t cycle parameter between header_tip and user_data.
Callback Implementations
dash-spv-ffi/src/bin/ffi_cli.rs, dash-spv-ffi/tests/unit/test_async_operations.rs
Callback function signatures updated to accept the new cycle parameter; ffi_cli now logs cycle value alongside header tip.
Sync Event & Coordination Logic
dash-spv/src/sync/events.rs, dash-spv/src/sync/sync_coordinator.rs
SyncComplete event variant expanded with cycle: u32 field; sync coordinator updated with cycle tracking, timing per cycle, and cycle counter incrementation on transition to synced state.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 A cycle spins, a new dawn breaks,
Each sync complete, the counter wakes,
From tip to cycle, data flows,
Through callbacks dancing, onward goes! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: adding a cycle field to SyncEvent::SyncComplete, which is the primary alteration across all modified files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/sync-cycle

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@xdustinface xdustinface marked this pull request as ready for review February 20, 2026 21:00
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@dash-spv-ffi/tests/unit/test_async_operations.rs`:
- Around line 272-275: The integration test defines unused callbacks
on_sync_progress and on_sync_complete whose signatures don't match the official
OnSyncProgressCallback/OnSyncCompleteCallback (see callbacks.rs) and are never
registered via dash_spv_ffi_client_set_sync_event_callbacks; either remove these
unused functions from dash-spv-ffi/tests/integration/test_full_workflow.rs or
update their signatures to match the official callback types (and then pass them
into dash_spv_ffi_client_set_sync_event_callbacks so they are actually
registered), ensuring the function names (on_sync_progress, on_sync_complete)
and registration call match the FFI types used in callbacks.rs.

Comment on lines +272 to 275
extern "C" fn on_sync_complete(_header_tip: u32, _cycle: u32, user_data: *mut c_void) {
let data = unsafe { &*(user_data as *const EventData) };
data.sync_complete.store(true, Ordering::SeqCst);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

rg -n 'on_sync_complete' --type=rs -C 8 dash-spv-ffi/tests/

Repository: dashpay/rust-dashcore

Length of output: 91


🏁 Script executed:

rg -n 'on_sync_complete' --type rust -C 8 dash-spv-ffi/tests/

Repository: dashpay/rust-dashcore

Length of output: 5172


🏁 Script executed:

rg -n 'OnSyncCompleteCallback|on_sync_complete.*=' --type rust -C 3 dash-spv-ffi/

Repository: dashpay/rust-dashcore

Length of output: 1121


🏁 Script executed:

rg -n 'FFISyncEventCallbacks' --type rust -C 5 dash-spv-ffi/tests/integration/test_full_workflow.rs

Repository: dashpay/rust-dashcore

Length of output: 47


🏁 Script executed:

rg -n 'extern "C" fn' --type rust -C 2 dash-spv-ffi/tests/integration/test_full_workflow.rs | head -60

Repository: dashpay/rust-dashcore

Length of output: 643


🏁 Script executed:

rg -n 'on_sync_progress\|on_sync_complete' --type rust -B 30 dash-spv-ffi/tests/integration/test_full_workflow.rs | grep -A 30 "struct\|FFI" | head -80

Repository: dashpay/rust-dashcore

Length of output: 47


🏁 Script executed:

sed -n '60,150p' dash-spv-ffi/tests/integration/test_full_workflow.rs

Repository: dashpay/rust-dashcore

Length of output: 3536


🏁 Script executed:

rg -n 'dash_spv_ffi_client_set_sync_event_callbacks\|on_sync' --type rust dash-spv-ffi/tests/integration/test_full_workflow.rs

Repository: dashpay/rust-dashcore

Length of output: 47


🏁 Script executed:

sed -n '1,200p' dash-spv-ffi/tests/integration/test_full_workflow.rs | grep -n 'on_sync_progress\|on_sync_complete\|set_sync_event'

Repository: dashpay/rust-dashcore

Length of output: 280


🏁 Script executed:

rg -n 'dash_spv_ffi' --type rust dash-spv-ffi/tests/integration/test_full_workflow.rs | grep -i 'callback\|event'

Repository: dashpay/rust-dashcore

Length of output: 47


🏁 Script executed:

wc -l dash-spv-ffi/tests/integration/test_full_workflow.rs && sed -n '90,200p' dash-spv-ffi/tests/integration/test_full_workflow.rs

Repository: dashpay/rust-dashcore

Length of output: 4179


Unit test callback signature is correct; integration test has unused callbacks with incompatible signature.

The unit test correctly implements on_sync_complete(_header_tip: u32, _cycle: u32, user_data: *mut c_void) matching the official OnSyncCompleteCallback type defined in callbacks.rs:212.

However, the integration test in dash-spv-ffi/tests/integration/test_full_workflow.rs (lines 71, 83) defines callbacks with an incompatible signature:

  • on_sync_progress(progress: f64, msg: *const c_char, user_data: *mut c_void)
  • on_sync_complete(success: bool, error: *const c_char, user_data: *mut c_void)

These callbacks are never used—they're defined but never passed to dash_spv_ffi_client_set_sync_event_callbacks or any other FFI function. Remove these unused callbacks or update them to match the official callback types and properly register them.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@dash-spv-ffi/tests/unit/test_async_operations.rs` around lines 272 - 275, The
integration test defines unused callbacks on_sync_progress and on_sync_complete
whose signatures don't match the official
OnSyncProgressCallback/OnSyncCompleteCallback (see callbacks.rs) and are never
registered via dash_spv_ffi_client_set_sync_event_callbacks; either remove these
unused functions from dash-spv-ffi/tests/integration/test_full_workflow.rs or
update their signatures to match the official callback types (and then pass them
into dash_spv_ffi_client_set_sync_event_callbacks so they are actually
registered), ensuring the function names (on_sync_progress, on_sync_complete)
and registration call match the FFI types used in callbacks.rs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant