Skip to content

fix(dash-spv): defer a ChainLock until the masternode lists reach it - #1063

Merged
ZocoLini merged 1 commit into
devfrom
fix/chainlock-defer-until-signing-list
Sep 25, 2026
Merged

ZocoLini merged 1 commit into
devfrom
fix/chainlock-defer-until-signing-list

Conversation

@ZocoLini

@ZocoLini ZocoLini commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Once masternode sync was ready, process_chainlock verified every ChainLock against whatever lists the engine held and counted a failure as invalid for good. A ChainLock that arrives before the lists covering its signing quorum (newest list below its height) fails only because the engine lags, and it was never retried: pending_validation was filled only before the first MasternodeStateUpdated, and every later one was ignored.

That is how tests_chainlock::test_chainlock_promotes_in_block_tx times out on slower CI runners (macOS, Ubuntu ARM): the SPV held lists up to 410, the ChainLocks at 429 and 432 failed with Threshold signature ... is not valid, and the QRInfo that brought the list at 432 landed 9 s later with nothing left to validate, so best_validated_height stayed at 0.

Now a ChainLock that fails while the newest list is below its height is kept in pending_validation (the latest one replaces it, so a forged ChainLock at a far height cannot hold the slot) and retried on every MasternodeStateUpdated. It is rejected once the lists reach its height and it still fails, and never accepted without a valid signature. With no lists, or with lists already past it, a failure is rejected at once as before. A pending ChainLock at or below the best one is dropped.

Tests:

  • test_chainlock_signed_above_the_newest_list_is_not_accepted (fix(dash): reject a ChainLock the list below its signing height refuses #1059) now expects the ChainLock deferred instead of counted invalid; it is still not accepted.
  • test_deferred_chainlock_is_rejected_once_lists_reach_it: kept across an update that leaves the lists behind it, rejected once a list reaches it.
  • test_chainlock_below_the_newest_list_is_rejected_immediately.

The race did not reproduce locally (8/8 runs pinned to 2 cores pass with and without the fix), so the fix rests on the CI log and the unit tests.

Verified: fmt, clippy --workspace --all-features --all-targets -D warnings, dash-spv 573 + dashd_masternode 10 + dashd_sync 32, dash-spv-ffi 49 + dashd_sync 7.

PR Hygiene · 0781e07

  • Bots — coderabbitai ✓
  • Self-review — post /self-reviewed
  • Within your 5 open PRs
  • Build green
  • Approvals
    • dash-spv (dash-spv/src/sync/chainlock/manager.rs, dash-spv/src/sync/chainlock/sync_manager.rs) — QuantumExplorer or xdustinface

When every box is checked the PR Hygiene check passes and this can merge.

Once masternode sync was ready, `process_chainlock` verified every ChainLock
against whatever lists the engine held and counted a failure as invalid for
good. A ChainLock that arrives before the lists covering its signing quorum
(newest list below its height) fails only because the engine lags, and it was
never retried: `pending_validation` was filled only before the first
`MasternodeStateUpdated`, and every later one was ignored.

That is how `tests_chainlock::test_chainlock_promotes_in_block_tx` times out
on slower CI runners (macOS, Ubuntu ARM): the SPV held lists up to 410, the
ChainLocks at 429 and 432 failed with `Threshold signature ... is not valid`,
and the QRInfo that brought the list at 432 landed 9 s later with nothing left
to validate, so best_validated_height stayed at 0.

Now a ChainLock that fails while the newest list is below its height is kept
in `pending_validation` (the latest one replaces it, so a forged ChainLock at
a far height cannot hold the slot) and retried on every
`MasternodeStateUpdated`. It is rejected once the lists reach its height and
it still fails, and never accepted without a valid signature. With no lists,
or with lists already past it, a failure is rejected at once as before. A
pending ChainLock at or below the best one is dropped.

Tests:
- `test_chainlock_signed_above_the_newest_list_is_not_accepted` (#1059) now
  expects the ChainLock deferred instead of counted invalid; it is still not
  accepted.
- `test_deferred_chainlock_is_rejected_once_lists_reach_it`: kept across an
  update that leaves the lists behind it, rejected once a list reaches it.
- `test_chainlock_below_the_newest_list_is_rejected_immediately`.

The race did not reproduce locally (8/8 runs pinned to 2 cores pass with and
without the fix), so the fix rests on the CI log and the unit tests.

Verified: fmt, clippy --workspace --all-features --all-targets -D warnings,
dash-spv 573 + dashd_masternode 10 + dashd_sync 32,
dash-spv-ffi 49 + dashd_sync 7.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 45 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository: dashpay/rust-dashcore/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 3c7e3eab-8f8e-415f-9e64-c8b0a7bb269d

📥 Commits

Reviewing files that changed from the base of the PR and between fe353c0 and 0781e07.

📒 Files selected for processing (2)
  • dash-spv/src/sync/chainlock/manager.rs
  • dash-spv/src/sync/chainlock/sync_manager.rs

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.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Sep 25, 2026
@codecov

codecov Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.80952% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 77.48%. Comparing base (fe353c0) to head (0781e07).
⚠️ Report is 3 commits behind head on dev.

Files with missing lines Patch % Lines
dash-spv/src/sync/chainlock/manager.rs 98.78% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1063      +/-   ##
==========================================
+ Coverage   77.45%   77.48%   +0.02%     
==========================================
  Files         317      317              
  Lines       80680    80754      +74     
==========================================
+ Hits        62491    62569      +78     
+ Misses      18189    18185       -4     
Flag Coverage Δ
core 78.91% <ø> (ø)
ffi 51.43% <ø> (ø)
rpc 20.00% <ø> (ø)
spv 91.98% <98.80%> (+0.04%) ⬆️
wallet 80.22% <ø> (ø)
Files with missing lines Coverage Δ
dash-spv/src/sync/chainlock/sync_manager.rs 87.87% <100.00%> (+0.78%) ⬆️
dash-spv/src/sync/chainlock/manager.rs 95.42% <98.78%> (+1.62%) ⬆️

... and 3 files with indirect coverage changes

@ZocoLini

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@github-actions

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. and removed waiting-bots Waiting for the review bots to report on this head labels Sep 25, 2026
@ZocoLini

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@ZocoLini

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@ZocoLini

Copy link
Copy Markdown
Collaborator Author

@coderabbitai approve

@coderabbitai

coderabbitai Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Comments resolved and changes approved.

@github-actions

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot removed the bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. label Sep 25, 2026
@ZocoLini
ZocoLini merged commit de7c18d into dev Sep 25, 2026
38 of 39 checks passed
@ZocoLini
ZocoLini deleted the fix/chainlock-defer-until-signing-list branch September 25, 2026 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-self-review Waiting for the author to post /self-reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant