Skip to content

refactor: remove SyncState::Initializing variant#465

Merged
xdustinface merged 1 commit into
v0.42-devfrom
refactor/drop-initializing-state
Feb 25, 2026
Merged

refactor: remove SyncState::Initializing variant#465
xdustinface merged 1 commit into
v0.42-devfrom
refactor/drop-initializing-state

Conversation

@xdustinface

@xdustinface xdustinface commented Feb 21, 2026

Copy link
Copy Markdown
Collaborator

The Initializing state was only used as a default before initialize() was called. Replace it with WaitForEvents as the default state to simplify the state machine.

Summary by CodeRabbit

  • Refactor

    • Reordered and simplified synchronization state ordering; replaced the previous initial state with a new "wait for events" state and updated status labels used in progress reporting.
  • Tests

    • Updated test expectations across the suite to align with the revised synchronization state names and ordering.

@coderabbitai

coderabbitai Bot commented Feb 21, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Removed the Initializing sync state; WaitForEvents is promoted as the default start state. FFI and core enum discriminants were renumbered, mappings and match arms updated, and test expectations across many sync managers and FFI tests were adjusted accordingly.

Changes

Cohort / File(s) Summary
FFI Header & Types
dash-spv-ffi/include/dash_spv_ffi.h, dash-spv-ffi/src/types.rs
Removed Initializing from FFISyncState; renumbered discriminants: WaitForEvents = 0, WaitingForConnections = 1, Syncing = 2, Synced = 3, Error = 4. Removed SyncState::InitializingFFISyncState::Initializing mapping.
FFI CLI
dash-spv-ffi/src/bin/ffi_cli.rs
Updated on_progress_update match arms to remove Initializing handling and to include WaitForEvents with new ordering.
FFI Tests
dash-spv-ffi/tests/test_types.rs
Adjusted assertions to expect WaitForEvents (and updated FFI variant values) instead of Initializing.
Core Sync State Implementation
dash-spv/src/sync/progress.rs
Removed Initializing from public SyncState; made WaitForEvents the default/empty state and updated observed-state priority and fallback logic.
Core Sync Tests (managers & coordinator)
dash-spv/src/sync/{block_headers,blocks,chainlock,filter_headers,filters,instantsend,masternodes}/manager.rs, dash-spv/src/sync/sync_coordinator.rs, dash-spv/src/sync/sync_manager.rs
Replaced test expectations of SyncState::Initializing with SyncState::WaitForEvents across manager initialization and progress tests; no production logic changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰
I hopped through enums with nimble feet,
Out went Initializing — a tidy feat,
WaitForEvents now leads the race,
Managers ready, finding their place,
A carrot-coded hop, a synchronized beat!

🚥 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 describes the main objective of this changeset: removing the SyncState::Initializing variant and replacing it with WaitForEvents as the default state.
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 refactor/drop-initializing-state

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.

Comment thread dash-spv-ffi/src/types.rs Outdated
WaitingForConnections = 1,
WaitForEvents = 2,
WaitForEvents = 1,
WaitingForConnections = 2,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Two things:

  • Why does the enum start in 1 right now??
  • WaitForEvents doesn't seem right, what about Idle??

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

  • Why does the enum start in 1 right now??

Missed that, fixed!

  • WaitForEvents doesn't seem right, what about Idle??

Thats out of scope here. Im not against it but i think WaitForEvents is fine too as thats what the managers actually do in that state.

@xdustinface
xdustinface force-pushed the refactor/drop-initializing-state branch from 1d16871 to b6d56fd Compare February 25, 2026 02:03
@xdustinface
xdustinface requested a review from ZocoLini February 25, 2026 02:03

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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/src/types.rs`:
- Around line 53-58: FFISyncState's numeric discriminants changed and break the
FFI ABI; restore the original explicit discriminant values used by the C header
so consumers don't need to recompile (or intentionally bump the ABI). Update the
enum FFISyncState declaration to assign the original numeric values for each
variant (e.g., ensure Syncing and Synced use the previous discriminants) so the
in-memory layout matches the generated cbindgen header.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1d16871 and b6d56fd.

📒 Files selected for processing (14)
  • dash-spv-ffi/include/dash_spv_ffi.h
  • dash-spv-ffi/src/bin/ffi_cli.rs
  • dash-spv-ffi/src/types.rs
  • dash-spv-ffi/tests/test_types.rs
  • dash-spv/src/sync/block_headers/manager.rs
  • dash-spv/src/sync/blocks/manager.rs
  • dash-spv/src/sync/chainlock/manager.rs
  • dash-spv/src/sync/filter_headers/manager.rs
  • dash-spv/src/sync/filters/manager.rs
  • dash-spv/src/sync/instantsend/manager.rs
  • dash-spv/src/sync/masternodes/manager.rs
  • dash-spv/src/sync/progress.rs
  • dash-spv/src/sync/sync_coordinator.rs
  • dash-spv/src/sync/sync_manager.rs
🚧 Files skipped from review as they are similar to previous changes (5)
  • dash-spv/src/sync/instantsend/manager.rs
  • dash-spv-ffi/tests/test_types.rs
  • dash-spv/src/sync/sync_manager.rs
  • dash-spv/src/sync/filter_headers/manager.rs
  • dash-spv/src/sync/sync_coordinator.rs

Comment thread dash-spv-ffi/src/types.rs
The `Initializing` state was only used as a default before
`initialize()` was called. Replace it with `WaitForEvents` as the
default state to simplify the state machine.
@xdustinface
xdustinface force-pushed the refactor/drop-initializing-state branch from b6d56fd to b05fa62 Compare February 25, 2026 02:12

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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/include/dash_spv_ffi.h`:
- Around line 23-27: The enum discriminants for WaitForEvents,
WaitingForConnections, Syncing, Synced, and Error were renumbered, which breaks
FFI/ABI consumers; revert to the original numeric values (or explicitly assign
the legacy integers) for the symbols in the header (the enum defined in
dash_spv_ffi.h) so precompiled clients interpret runtime states correctly, and
if you need different semantics change only the Rust-side state mapping rather
than the exported discriminant values.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b6d56fd and b05fa62.

📒 Files selected for processing (14)
  • dash-spv-ffi/include/dash_spv_ffi.h
  • dash-spv-ffi/src/bin/ffi_cli.rs
  • dash-spv-ffi/src/types.rs
  • dash-spv-ffi/tests/test_types.rs
  • dash-spv/src/sync/block_headers/manager.rs
  • dash-spv/src/sync/blocks/manager.rs
  • dash-spv/src/sync/chainlock/manager.rs
  • dash-spv/src/sync/filter_headers/manager.rs
  • dash-spv/src/sync/filters/manager.rs
  • dash-spv/src/sync/instantsend/manager.rs
  • dash-spv/src/sync/masternodes/manager.rs
  • dash-spv/src/sync/progress.rs
  • dash-spv/src/sync/sync_coordinator.rs
  • dash-spv/src/sync/sync_manager.rs
✅ Files skipped from review due to trivial changes (1)
  • dash-spv/src/sync/masternodes/manager.rs
🚧 Files skipped from review as they are similar to previous changes (7)
  • dash-spv/src/sync/sync_manager.rs
  • dash-spv/src/sync/filters/manager.rs
  • dash-spv/src/sync/sync_coordinator.rs
  • dash-spv/src/sync/filter_headers/manager.rs
  • dash-spv-ffi/src/bin/ffi_cli.rs
  • dash-spv/src/sync/block_headers/manager.rs
  • dash-spv-ffi/src/types.rs

Comment thread dash-spv-ffi/include/dash_spv_ffi.h
@xdustinface
xdustinface merged commit 812b6ff into v0.42-dev Feb 25, 2026
53 checks passed
@xdustinface
xdustinface deleted the refactor/drop-initializing-state branch February 25, 2026 22:09
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.

2 participants