Skip to content

dash-spv: get_quorum_at_height should tell a height its retained masternode lists do not cover from a quorum that is absent #1396

In progress

Description

@shumkov

Problem

DashSpvClient::get_quorum_at_height(height, llmq_type, quorum_hash)
(dash-spv/src/client/queries.rs) returns one error,
SpvError::QuorumLookupError(String), for every miss. A caller cannot tell
two different situations apart:

  1. The quorum is absent. The engine holds the masternode lists that would
    contain the quorum at height, and none of them has it. The response that
    named the quorum is wrong, and a client verifying it should treat the node
    that sent it as faulty.
  2. The engine cannot say. It no longer holds, or never held, the lists
    that would contain the quorum at height. Nothing is known about the
    quorum, and the node that sent the response may be honest.

Dash Platform verifies proofs with these keys (dashpay/platform#3417). Its SDK
bans a node whose proof fails to verify, so treating case 2 as case 1 bans
honest nodes. This happens for any proof at a height below the engine's
retained history. fetch_blocks and fetch_owner_transactions_in_block ask
for old heights on purpose. It also happens just after a catch-up, at heights
between two retained lists.

Why a caller cannot work it out today

At c9aeac0d (and at dev 089fee2a; these files are unchanged):

  • quorum_entry_for_hash_at_or_before_height
    (sml_engine/helpers.rs) searches
    masternode_lists.range(height - 4 * active_window ..= height), newest
    first. An empty range and a quorum missing from the lists in range both give
    None.
  • prune_after_extending drops lists below tip - retention_window(). It
    keeps the diff base and the next QRInfo's base and their cycles.
  • sml_engine, storage and sync are private modules, and
    masternode_list_engine() is pub(crate).
  • The public API exposes only the newest list (latest_masternode_list[_blocking],
    latest_coinbase) and headers. Headers are not pruned along with lists.
  • MasternodesProgress has no oldest-list height.
  • SyncEvent::MasternodeStateUpdated { height } reports new heights only. It
    does not report pruning, or the lists restored on start.

A caller that rebuilt the retention rule from LLMQ parameters would copy a
private policy. That copy would drift, and it would still be wrong, because
the stored lists are sparse.

Proposal

The engine decides, in one place, whether its lists cover a lookup, and
get_quorum_at_height reports a third outcome:

pub enum SpvError {
    // …
    /// The retained masternode lists do not cover `height` for this quorum
    /// type, so whether the quorum exists there is unknown.
    QuorumHistoryNotCovered { height: u32, llmq_type: LLMQType, oldest_retained: Option<u32> },
    // QuorumLookupError keeps meaning: covered, and the quorum is absent.
}

A lookup at height is covered only if both edges hold:

  • Lower edge: the oldest retained list is at or below
    height - 4 * active_window(llmq_type), the start of the walk-back. A quorum
    that was already retired by height is found only in older lists.
  • Upper edge: the newest list at or below height is at or after the end
    of the last mining window of llmq_type that ends at or below height.
    An update diffs from the newest list straight to the header tip, QRInfo
    history keeps one list per cycle, truncate_above drops lists above a fork
    point, and a restart restores only the stored lists. So without this edge, a
    quorum mined between that list and height reads as absent. A height
    above the newest list is not covered.

An alternative is a public oldest_masternode_list_height(). It is weaker:
the caller would also need the walk-back width and the mining windows, both of
which are engine internals, so the engine is the right place to decide.

Tests

  • Below the lower edge: a lookup below the lower edge after
    prune_after_extending returns QuorumHistoryNotCovered.
  • Gap between lists: take two retained lists L1 < L2 and a quorum mined
    between them. A lookup at a height in (L1, L2) whose last mining window ends
    after L1 returns QuorumHistoryNotCovered. At L2 it finds the quorum.
  • Above the newest list: a lookup there returns
    QuorumHistoryNotCovered.
  • Covered and absent: a lookup inside covered history for a quorum no list
    holds still returns QuorumLookupError.
  • After a restart: restored lists only. Lookups outside them are not
    covered.

Platform side, after it lands (for the #3417 follow-up, not for the issue)

  • platform-wallet keeps the distinction. SpvRuntime::get_quorum_public_key
    maps QuorumHistoryNotCovered to its own error variant instead of
    stringifying it into SpvError, and SpvQuorumSource reports a distinct
    ContextProviderError variant.
  • The height cannot decide this on its own. It comes from the response
    before that response is verified. If "not covered" simply became
    QuorumSourceUnavailable, a malicious node could name height = 1 and
    never be banned: the SDK only steps over it for 2 s.
  • Each SDK call site decides:
    • Block queries that ask for old heights on purpose spare the node:
      verify_block_answer, used by fetch_blocks and
      fetch_owner_transactions_in_block.
    • Current-state verification keeps banning, because an honest node's height
      is near the tip: verify_fetching_quorum_key.
  • Strict SPV still fails closed and never falls back to trusted keys.
    Auto with SPV ready never asks trusted on an SPV miss today. Sending "not
    covered" to trusted in Auto would not weaken Auto's documented guarantee,
    but it is a separate decision.
  • Rejected: mapping every miss while SPV runs to
    QuorumSourceUnavailable, because of the ban evasion above.
  • Test: a historical block proof below retained history bans no node in
    strict SPV, and a current-state proof naming an uncovered height still bans
    it.

Activity

  1. lklimek commented on Nov 26, 2026

    @lklimek
    Contributor

    Possibly related: #1534 reports intermittent "Quorum not found" and Skipped(NotMarkedForVerification) results for platform quorums on a fast-rotating devnet, with log lines (dash-spv f0ddfd45).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions