Skip to content

fix(spv): fall back to h-3c signatures when tip chainlock is missing in QRInfo validation - #203

Closed
pauldelucia wants to merge 2 commits into
v0.41-devfrom
fix/mnlist
Closed

pauldelucia wants to merge 2 commits into
v0.41-devfrom
fix/mnlist

Conversation

@pauldelucia

@pauldelucia pauldelucia commented Nov 23, 2025 •

Copy link
Copy Markdown
Member

Problem:
Masternode list download was stalling with "Failed to feed QRInfo to engine: Required rotated chain lock sig at h - 0 not present for masternode diff block hash". The error message itself was wrong (and so were the others). h-0 was logged but it was actually the chainlock at the chain tip that was missing, not the chainlock at the QR height.

Solution:

  • Re-adds capture of the mn_list_diff_at_h_minus_3c chain-lock signature when feeding QRInfo so the masternode list engine always keeps four rotation signatures available.
  • When building last_commitment_per_index, uses the tip signature when present but falls back to the stored h-3c signature to handle QRInfos whose tip diff contains no rotating quorums; missing signatures now map to the correct diff height.
  • Result: rotated quorum validation no longer fails with “Required rotated chain lock sig at h - 0…” during SPV sync.

Summary by CodeRabbit

  • Refactor
    • Improved chain lock signature handling and rotating-signature verification to collect and reuse signatures across historical and tip updates, enabling a 4-signature rotating path.
    • Enhanced rotation validation to rely on previously collected signatures and improved error reporting for missing rotated signatures, increasing robustness of masternode list validation.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Nov 23, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Collects ChainLock signatures per block hash during historical and tip diff processing in feed_qr_info (under quorum_validation), stores them in a map, and uses that registry to assemble the rotating 4-sig VerifyingChainLockSignaturesType for rotation verification instead of relying solely on immediate apply_diff return values.

Changes

Cohort / File(s) Summary
ChainLock rotation & signature registry
dash/src/sml/masternode_list_engine/mod.rs
Add optional chainlock_sigs_by_block_hash when quorum_validation is enabled; record produced ChainLock signatures for historical diffs (h-4c..tip) into the map; construct rotating signature set by looking up signatures in the map keyed by block hashes; adjust rotating-path error messages and verification to use collected signatures; store tip signature when produced.

Sequence Diagram

sequenceDiagram
    participant Feed as feed_qr_info
    participant QF as quorum_validation flag
    participant Diffs as Diff Application
    participant Map as chainlock_sigs_by_block_hash (registry)
    participant Build as Rotating Sig Builder
    participant Verify as Rotation Verifier

    rect `#E8F6FF`
    Feed->>QF: is quorum_validation enabled?
    QF-->>Feed: yes
    end

    rect `#F3F9E8`
    note over Feed,Map: collect signatures while applying diffs
    Feed->>Diffs: apply historical diffs (h-4c..h, tip)
    Diffs-->>Feed: maybe produced sig + block_hash (for each diff)
    Feed->>Map: store sig under block_hash (if produced)
    end

    rect `#FFF4E6`
    Feed->>Build: request rotating sigs for [h-2c,h-c,h,tip]
    Build->>Map: lookup sig for each block_hash
    Map-->>Build: return found/missing sigs
    Build-->>Verify: supply VerifyingChainLockSignaturesType::Rotating([sig2,sig1,sig0,sigmtip])
    end

    rect `#F6EEF8`
    Verify->>Verify: validate rotating sigs (error if missing)
    Verify-->>Feed: verification result
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Review points:
    • correctness of where and when signatures are inserted into chainlock_sigs_by_block_hash
    • lookups for rotated signatures using precise block hashes (h-2c, h-c, h, tip)
    • updated error messages and codes for missing rotated signatures
    • ensure tip-signature storage occurs on the signed-tip code path

Poem

🐰 I hopped through diffs and caught each sign,
Stashed them by block, one per little line.
Four sigs now turn in ordered cheer,
Rotating locks make validation clear —
A rabbit nods: the chain is fine.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title directly addresses the main fix: adding fallback to h-3c signatures for missing tip chainlock in QRInfo validation. It clearly describes the primary change and matches the stated problem in the PR description.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/mnlist

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.

@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: 0

🧹 Nitpick comments (1)
dash/src/sml/masternode_list_engine/mod.rs (1)

641-677: Rotating signature construction and error mapping match the intended tip‑vs‑h‑3c fallback

The new rotating_sigs logic correctly:

  • Requires sigm2, sigm1, and sigm0 (with indices 2, 1, 0 bound to h‑2c, h‑c, and h block hashes) before proceeding.
  • Prefers sigmtip when present, yielding [sigm2, sigm1, sigm0, sigmtip].
  • Falls back to sigm3 from h‑3c (index 3, with the correct mn_list_diff_at_h_minus_3c_block_hash) when sigmtip is absent, yielding [sigm3, sigm2, sigm1, sigm0].

This aligns with the PR goal of using the tip signature when available and otherwise using the stored h‑3c signature, and should prevent the “Required rotated chain lock sig at h - 0…” failure for QRInfos whose tip diff has no rotating quorums.

You might consider a brief comment or helper that documents which indices (3,2,1,0) correspond to which diff heights (h‑3c, h‑2c, h‑c, h) to make future debugging of RequiredRotatedChainLockSigNotPresent more straightforward, but the current implementation is logically sound.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4e9ef04 and 7ad02be.

📒 Files selected for processing (1)
  • dash/src/sml/masternode_list_engine/mod.rs (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (20)
  • GitHub Check: fuzz (hashes_sha1)
  • GitHub Check: fuzz (hashes_sha512_256)
  • GitHub Check: fuzz (hashes_ripemd160)
  • GitHub Check: fuzz (hashes_sha256)
  • GitHub Check: fuzz (dash_deserialize_witness)
  • GitHub Check: fuzz (hashes_sha512)
  • GitHub Check: fuzz (hashes_cbor)
  • GitHub Check: fuzz (hashes_json)
  • GitHub Check: fuzz (dash_deserialize_script)
  • GitHub Check: fuzz (dash_deserialize_address)
  • GitHub Check: fuzz (dash_script_bytes_to_asm_fmt)
  • GitHub Check: fuzz (dash_deserialize_block)
  • GitHub Check: fuzz (dash_deserialize_amount)
  • GitHub Check: fuzz (dash_deser_net_msg)
  • GitHub Check: RPC Tests (stable, true)
  • GitHub Check: fuzz (dash_outpoint_string)
  • GitHub Check: Core Components Tests
  • GitHub Check: Strict Warnings and Clippy Checks
  • GitHub Check: Key Wallet Components Tests
  • GitHub Check: SPV Components Tests
🔇 Additional comments (1)
dash/src/sml/masternode_list_engine/mod.rs (1)

599-606: Restoring h‑3c rotation signature capture under quorum_validation looks correct

Conditionally binding mn_list_diff_at_h_minus_3c_block_hash and maybe_sigm3 while keeping the non‑quorum_validation path as a plain apply_diff call preserves prior behavior but now retains the h‑3c chain‑lock signature for later rotation checks. mn_list_diff_at_h_minus_3c is still applied exactly once on each cfg path, so there’s no risk of double‑applying the diff or missing the snapshot insertion above.

@pauldelucia pauldelucia changed the title fix(spv): restore h-3c rotated signatures for QRInfo validation fix(spv): in QRInfo validation, fall back to h-3c signatures when tip chainlock is missing Nov 27, 2025
@pauldelucia pauldelucia changed the title fix(spv): in QRInfo validation, fall back to h-3c signatures when tip chainlock is missing fix(spv): fall back to h-3c signatures when tip chainlock is missing in QRInfo validation Nov 27, 2025
@pauldelucia
pauldelucia marked this pull request as draft November 27, 2025 10:19

@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

🧹 Nitpick comments (1)
dash/src/sml/masternode_list_engine/mod.rs (1)

568-572: Redundant conditional compilation blocks.

Both #[cfg(feature = "quorum_validation")] and #[cfg(not(feature = "quorum_validation"))] perform the identical assignment. Since block_hash is used unconditionally on line 572, simplify to a single unconditional binding.

-            #[cfg(feature = "quorum_validation")]
-            let block_hash = diff.block_hash;
-            #[cfg(not(feature = "quorum_validation"))]
             let block_hash = diff.block_hash;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7ad02be and b2fc989.

📒 Files selected for processing (1)
  • dash/src/sml/masternode_list_engine/mod.rs (3 hunks)
🔇 Additional comments (3)
dash/src/sml/masternode_list_engine/mod.rs (3)

621-631: LGTM - h-3c signature capture added correctly.

The h-3c chainlock signature is now properly captured into the chainlock_sigs_by_block_hash map, which aligns with the PR objective to maintain four rotation signatures for fallback purposes.


664-679: LGTM - Tip diff processing and signature collection.

The sigs array is correctly built from the immediate apply_diff return values for passing to the tip diff processing. The tip signature is also properly stored in the map when available.


559-562: Appropriate use of feature-gated collection for chainlock signatures.

The chainlock_sigs_by_block_hash map is correctly initialized only when quorum_validation feature is enabled, which matches the usage pattern throughout the function.

Comment on lines +714 to +719
let sigmtip = chainlock_sigs_by_block_hash
.get(&mn_list_diff_tip_block_hash)
.ok_or(QuorumValidationError::RequiredRotatedChainLockSigNotPresent(
3,
mn_list_diff_tip_block_hash,
),
)?;
))?;

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.

⚠️ Potential issue | 🔴 Critical

Missing fallback to h-3c signature when tip chainlock is not present.

The PR description states: "prefer the tip signature when present but fall back to the stored h-3c signature to handle QRInfos whose tip diff contains no rotating quorums." However, this fallback is not implemented. If the tip diff doesn't produce a chainlock signature, this code will error out instead of using the h-3c signature.

Apply this diff to implement the described fallback:

                     let sigmtip = chainlock_sigs_by_block_hash
                         .get(&mn_list_diff_tip_block_hash)
+                        .or_else(|| chainlock_sigs_by_block_hash.get(&mn_list_diff_at_h_minus_3c_block_hash))
                         .ok_or(QuorumValidationError::RequiredRotatedChainLockSigNotPresent(
                             3,
                             mn_list_diff_tip_block_hash,
                         ))?;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let sigmtip = chainlock_sigs_by_block_hash
.get(&mn_list_diff_tip_block_hash)
.ok_or(QuorumValidationError::RequiredRotatedChainLockSigNotPresent(
3,
mn_list_diff_tip_block_hash,
),
)?;
))?;
let sigmtip = chainlock_sigs_by_block_hash
.get(&mn_list_diff_tip_block_hash)
.or_else(|| chainlock_sigs_by_block_hash.get(&mn_list_diff_at_h_minus_3c_block_hash))
.ok_or(QuorumValidationError::RequiredRotatedChainLockSigNotPresent(
3,
mn_list_diff_tip_block_hash,
))?;
🤖 Prompt for AI Agents
In dash/src/sml/masternode_list_engine/mod.rs around lines 714-719, the code
currently bails if the tip chainlock sig is missing; instead, try to get the tip
signature first and if that returns None, fall back to the stored h-3c signature
(mn_list_diff_h_3c_block_hash) and only return
QuorumValidationError::RequiredRotatedChainLockSigNotPresent if both lookups
fail. Assign the chosen signature to sigmtip (tip if present, otherwise h-3c)
and keep the same error type/parameters when both are absent.

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