Repository navigation
fix(spv): fall back to h-3c signatures when tip chainlock is missing in QRInfo validation - #203
pauldelucia wants to merge 2 commits into
Conversation
WalkthroughCollects 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
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 fallbackThe new
rotating_sigslogic correctly:
- Requires
sigm2,sigm1, andsigm0(with indices 2, 1, 0 bound toh‑2c,h‑c, andhblock hashes) before proceeding.- Prefers
sigmtipwhen present, yielding[sigm2, sigm1, sigm0, sigmtip].- Falls back to
sigm3from h‑3c (index 3, with the correctmn_list_diff_at_h_minus_3c_block_hash) whensigmtipis 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
RequiredRotatedChainLockSigNotPresentmore straightforward, but the current implementation is logically sound.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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 underquorum_validationlooks correctConditionally binding
mn_list_diff_at_h_minus_3c_block_hashandmaybe_sigm3while keeping the non‑quorum_validationpath as a plainapply_diffcall preserves prior behavior but now retains the h‑3c chain‑lock signature for later rotation checks.mn_list_diff_at_h_minus_3cis still applied exactly once on each cfg path, so there’s no risk of double‑applying the diff or missing the snapshot insertion above.
There was a problem hiding this comment.
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. Sinceblock_hashis 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
📒 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_hashmap, 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_diffreturn 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_hashmap is correctly initialized only whenquorum_validationfeature is enabled, which matches the usage pattern throughout the function.
| 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, | ||
| ), | ||
| )?; | ||
| ))?; |
There was a problem hiding this comment.
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.
| 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.
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-0was logged but it was actually the chainlock at the chain tip that was missing, not the chainlock at the QR height.Solution:
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.