-
Notifications
You must be signed in to change notification settings - Fork 9
fix: masternode list around height #407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughWalkthroughRefactors quorum lookup to use masternode lists returned by Changes
Sequence DiagramsequenceDiagram
participant Caller
participant Engine as MasternodeListEngine
participant ML as MasternodeList
participant FFI as FFI / Client Logic
participant Output as ResultBuffer
Caller->>Engine: masternode_lists_around_height(requested_height)
Engine-->>Caller: ml or None
alt ml found
Caller->>FFI: ml (with known_height)
FFI->>FFI: list_height = ml.known_height
FFI->>FFI: lookup ml.quorums for (llmq_type, quorum_hash)
alt quorum found
FFI->>Output: write 48-byte quorum_public_key
Output-->>Caller: success
else quorum not found
FFI-->>Caller: ValidationError (list_height, requested_height, quorum_hash, quorum_count)
end
else ml not found
FFI-->>Caller: QuorumLookupError (no list at/before requested_height)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@dash-spv/src/client/queries.rs`:
- Around line 117-122: The error string passed to SpvError::QuorumLookupError is
inconsistent with the tracing::warn message semantics; update the
QuorumLookupError message (the Err(...) returned where
SpvError::QuorumLookupError is constructed) to say "No masternode list found at
or before height {height}" (or otherwise match the tracing::warn text) so both
the log and the returned error consistently reference "at or before height" and
include the height variable.
🧹 Nitpick comments (2)
dash-spv/src/client/queries.rs (1)
90-101: Minor: Consider consistent hex encoding approach.The error message construction and logging are informative. One minor note: line 96 uses
hex::encode(quorum_hash)which produces lowercase hex. This is fine, but note that the FFI counterpart uses{:x}format specifier. Keeping consistent formatting across both modules would aid debugging when comparing error messages.dash-spv-ffi/src/platform_integration.rs (1)
139-158: Consider extracting shared quorum lookup logic.The quorum lookup and error handling logic here closely mirrors
get_quorum_at_heightinqueries.rs. While some duplication in FFI code is acceptable for explicitness, the error message formatting differs slightly ({:x}here vshex::encodein queries.rs, line 146 vs queries.rs line 96).If these modules evolve independently, maintaining consistent error messages may become difficult. Consider whether a shared helper for error message formatting would be beneficial.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
dash-spv/src/client/queries.rs (1)
63-64:⚠️ Potential issue | 🟡 MinorDocumentation inconsistency with function signature.
The doc comment states "Returns None if the quorum is not found" but the function actually returns
Result<QualifiedQuorumEntry>, returning anErrvariant on failure.📝 Proposed fix
/// Get a quorum entry by type and hash at a specific block height. -/// Returns None if the quorum is not found. +/// Returns an error if the quorum is not found or no masternode list exists at or before the height. pub fn get_quorum_at_height(
🧹 Nitpick comments (1)
dash-spv/src/client/queries.rs (1)
99-99: Consider using format string for tracing macro.Passing a
Stringdirectly totracing::warn!works but using a format string is more idiomatic and avoids potential clippy warnings about format string security.♻️ Suggested change
- tracing::warn!(message); + tracing::warn!("{}", message);
b9a6c8b to
40b0d94
Compare
e42d26b to
daaaace
Compare
|
This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them. |
f6c8c7c to
5474618
Compare
39c8fa3 to
a45aa37
Compare
5474618 to
05763c2
Compare
|
This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them. |
478e397 to
b18b9c7
Compare
a45aa37 to
eb617f7
Compare
Summary
Align quorum lookup semantics to use the masternode list at or before the requested height.
Apply the same rule in both Rust API (dash-spv) and FFI (dash-spv-ffi) so platform integration behaves consistently.
Why
Masternode lists are stored at diff heights (sparse), so exact-height lookup will likely fail after sync. For “active at height” logic, the list at or before the requested height is authoritative, and must be used. It was not previously.
What changed
queries.rs: get_quorum_at_height now uses the nearest list at or below height only (no fallback to newer list).
platform_integration.rs: ffi_dash_spv_get_quorum_public_key uses the same “at or before” rule.
Behavioral notes
If there is no masternode list at/before the requested height, return a clear error.
If the list exists but the quorum is missing, return a quorum-not-found error tied to that list height.
This should not be a breaking change, makes usage more flexible.
Testing
cargo fmt
cargo check
I intend to test this in DET soon.
Summary by CodeRabbit