fix: resolve just-retired quorum by walking earlier masternode lists#801
fix: resolve just-retired quorum by walking earlier masternode lists#801xdustinface wants to merge 1 commit into
Conversation
`get_quorum_at_height` and the FFI `ffi_dash_spv_get_quorum_public_key` resolved a quorum only through the single nearest masternode list at or below the lookup height. A Platform signing quorum is selected at a lagged height, so by the proof's `core_chain_locked_height` it can already have retired out of the active set. `apply_diff` drops a retired quorum from every later list, so the nearest list misses and the lookup fails with `Quorum not found`, surfacing downstream as `InvalidQuorum`. The failure is intermittent, firing only at the retirement edge. The full entry is not actually gone: `apply_diff` clones the base list without mutating earlier ones, and old per-height lists are retained, so the quorum still lives in every list from its mint height up to retirement. Add `MasternodeListEngine::quorum_entry_for_hash_at_or_before_height`, which walks `masternode_lists` backward from the lookup height and returns the first list still holding the quorum, skipping `Invalid` entries. Both consumer sites route through it, so the real full `QualifiedQuorumEntry` is returned with no synthesized data, no new storage, and no API change. The walk is floored at a few active windows below the height (derived from the type's `signing_active_quorum_count` and DKG interval): a legitimately referenced signing quorum cannot be older than that, so a miss scans a bounded span rather than every accumulated list. Closes #800.
📝 WalkthroughWalkthroughThis PR introduces a new quorum lookup API in ChangesQuorum hash-based lookup refactor
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@dash-spv/src/client/queries.rs`:
- Line 78: The tracing::warn!(message) call treats message as a structured
field; change the tracing::warn! invocation that references the variable message
to use a format string (e.g., tracing::warn!("{}", message)) or the formatter
shorthand (tracing::warn!(%message)) so the text is emitted as the event message
to match the tracing::debug(...) style; update the invocation where
tracing::warn! is called with the local variable message.
In `@dash/src/sml/masternode_list_engine/helpers.rs`:
- Around line 96-101: Remove the redundant QuorumHash import in the test module:
the tests module already brings QuorumHash into scope via use super::*, so
update the use crate::{BlockHash, QuorumHash}; line (inside #[cfg(test)] mod
tests) to only import BlockHash (e.g., use crate::BlockHash;) or otherwise omit
QuorumHash, leaving functions/structs that reference QuorumHash untouched;
reference the test module and the use statement near the top of helpers.rs to
locate and edit the import.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 3fa92136-d9bf-4610-a80f-1de727fbf6c4
📒 Files selected for processing (3)
dash-spv-ffi/src/platform_integration.rsdash-spv/src/client/queries.rsdash/src/sml/masternode_list_engine/helpers.rs
| height, | ||
| hex::encode(quorum_hash) | ||
| ); | ||
| tracing::warn!(message); |
There was a problem hiding this comment.
Inconsistent tracing macro usage.
tracing::warn!(message) treats message as a structured field name, producing output like message="Quorum not found: ..." rather than emitting the text as the event message. This differs from the tracing::debug!(...) call above which uses a format string.
Proposed fix
- tracing::warn!(message);
+ tracing::warn!("{}", message);📝 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.
| tracing::warn!(message); | |
| tracing::warn!("{}", message); |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@dash-spv/src/client/queries.rs` at line 78, The tracing::warn!(message) call
treats message as a structured field; change the tracing::warn! invocation that
references the variable message to use a format string (e.g.,
tracing::warn!("{}", message)) or the formatter shorthand
(tracing::warn!(%message)) so the text is emitted as the event message to match
the tracing::debug(...) style; update the invocation where tracing::warn! is
called with the local variable message.
| use super::*; | ||
| use crate::bls_sig_utils::{BLSPublicKey, BLSSignature}; | ||
| use crate::hash_types::QuorumVVecHash; | ||
| use crate::sml::quorum_validation_error::QuorumValidationError; | ||
| use crate::transaction::special_transaction::quorum_commitment::QuorumEntry; | ||
| use crate::{BlockHash, QuorumHash}; |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
Does rustc emit an "imported redundantly" unused_imports warning when an item brought in by use super::*is also explicitly re-imported with an explicituse in the same module?
💡 Result:
Yes, the Rust compiler (rustc) can emit a warning when an item is imported redundantly [1][2]. Specifically, if an item is already brought into scope via a wildcard import like use super::*;, and you additionally import that same item explicitly with its own use statement, rustc may flag this as a "redundant import" [1][2]. In modern versions of rustc, this is typically handled by the redundant_imports lint [1][2]. The compiler detects that the item is already available in the current scope (e.g., from a previous import or the prelude) and marks the explicit re-import as redundant [1][2]. While this was previously grouped under the unused_imports lint, recent improvements have aimed to provide clearer diagnostics for redundant imports [3][4]. Note that this behavior is distinct from the unused_imports warning, which triggers when an import is entirely unused in the module [5][6]. If you use an item brought in by use super::*, that wildcard import itself might still be flagged as unused if the compiler cannot prove it provides any necessary items that aren't already covered by other imports, or if it is entirely ignored [6][3]. In practice, use super::* is often used in test modules, where it can sometimes trigger warnings if all imported items are already provided by other means [6][7].
Citations:
- 1: https://doc.rust-lang.org/stable/nightly-rustc/rustc_lint/builtin/static.REDUNDANT_IMPORTS.html
- 2: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint_defs/builtin/static.REDUNDANT_IMPORTS.html
- 3: A warning about redundant imports should be separate from
unused_importsrust-lang/rust#121825 - 4: "item
TryFromis imported redundantly" doesn't have automatic fix rust-lang/rust#121315 - 5: https://github.com/rust-lang/rust/blob/024757fe/compiler/rustc_resolve/src/check_unused.rs
- 6: Warning about unused import in test module despite being used in a test rust-lang/rust#72522
- 7: Allow
use super::*;in test modules rust-lang/rust-clippy#5554
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="dash/src/sml/masternode_list_engine/helpers.rs"
echo "== file = $FILE"
wc -l "$FILE"
echo "== top of file (show module/parent imports)"
sed -n '1,140p' "$FILE" | nl -ba
echo "== targeted region (imports around lines 80-120)"
sed -n '70,130p' "$FILE" | nl -baRepository: dashpay/rust-dashcore
Length of output: 278
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="dash/src/sml/masternode_list_engine/helpers.rs"
echo "== file = $FILE"
wc -l "$FILE"
echo "== targeted region (imports around ~70-130) with line numbers"
sed -n '70,130p' "$FILE" | awk '{printf "%4d\t%s\n", NR+69, $0}'
echo
echo "== top of file (first ~1-80) with line numbers"
sed -n '1,80p' "$FILE" | awk '{printf "%4d\t%s\n", NR, $0}'
echo
echo "== occurrences of QuorumHash in this file"
rg -n "QuorumHash" "$FILE" || trueRepository: dashpay/rust-dashcore
Length of output: 8447
🏁 Script executed:
#!/bin/bash
set -euo pipefail
FILE="dash/src/sml/masternode_list_engine/helpers.rs"
rg -n "use\s+crate::.*BlockHash|use\s+crate::\{[^}]*BlockHash|BlockHash" "$FILE" | head -n 80Repository: dashpay/rust-dashcore
Length of output: 204
Fix redundant QuorumHash import in test module
In dash/src/sml/masternode_list_engine/helpers.rs (#[cfg(test)] mod tests, around lines 96-101), QuorumHash is already in scope via use super::*;, but it’s re-imported in use crate::{BlockHash, QuorumHash};, which can trip redundant_imports under -D warnings.
♻️ Proposed fix
- use crate::{BlockHash, QuorumHash};
+ use crate::BlockHash;📝 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.
| use super::*; | |
| use crate::bls_sig_utils::{BLSPublicKey, BLSSignature}; | |
| use crate::hash_types::QuorumVVecHash; | |
| use crate::sml::quorum_validation_error::QuorumValidationError; | |
| use crate::transaction::special_transaction::quorum_commitment::QuorumEntry; | |
| use crate::{BlockHash, QuorumHash}; | |
| use super::*; | |
| use crate::bls_sig_utils::{BLSPublicKey, BLSSignature}; | |
| use crate::hash_types::QuorumVVecHash; | |
| use crate::sml::quorum_validation_error::QuorumValidationError; | |
| use crate::transaction::special_transaction::quorum_commitment::QuorumEntry; | |
| use crate::BlockHash; |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@dash/src/sml/masternode_list_engine/helpers.rs` around lines 96 - 101, Remove
the redundant QuorumHash import in the test module: the tests module already
brings QuorumHash into scope via use super::*, so update the use
crate::{BlockHash, QuorumHash}; line (inside #[cfg(test)] mod tests) to only
import BlockHash (e.g., use crate::BlockHash;) or otherwise omit QuorumHash,
leaving functions/structs that reference QuorumHash untouched; reference the
test module and the use statement near the top of helpers.rs to locate and edit
the import.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #801 +/- ##
==========================================
+ Coverage 72.67% 72.75% +0.07%
==========================================
Files 322 322
Lines 71363 71454 +91
==========================================
+ Hits 51866 51986 +120
+ Misses 19497 19468 -29
|
get_quorum_at_heightand the FFIffi_dash_spv_get_quorum_public_keyresolved a quorum only through the single nearest masternode list at or below the lookup height. A Platform signing quorum is selected at a lagged height, so by the proof'score_chain_locked_heightit can already have retired out of the active set.apply_diffdrops a retired quorum from every later list, so the nearest list misses and the lookup fails withQuorum not found, surfacing downstream asInvalidQuorum. The failure is intermittent, firing only at the retirement edge.The full entry is not actually gone:
apply_diffclones the base list without mutating earlier ones, and old per-height lists are retained, so the quorum still lives in every list from its mint height up to retirement.Add
MasternodeListEngine::quorum_entry_for_hash_at_or_before_height, which walksmasternode_listsbackward from the lookup height and returns the first list still holding the quorum, skippingInvalidentries. Both consumer sites route through it, so the real fullQualifiedQuorumEntryis returned with no synthesized data, no new storage, and no API change. The walk is floored at a few active windows below the height (derived from the type'ssigning_active_quorum_countand DKG interval): a legitimately referenced signing quorum cannot be older than that, so a miss scans a bounded span rather than every accumulated list.Closes #800.
Summary by CodeRabbit
Release Notes