Skip to content

fix(consensus): rebuild short rotating quorum quarters faithfully after quarter_steps activation - #8012

Draft
UdjinM6 wants to merge 8 commits into
dashpay:developfrom
UdjinM6:rotation-quarter-steps
Draft

UdjinM6 wants to merge 8 commits into
dashpay:developfrom
UdjinM6:rotation-quarter-steps

Conversation

@UdjinM6

@UdjinM6 UdjinM6 commented Nov 1, 2026 •

Copy link
Copy Markdown

Issue being fixed or feature implemented

Rotating LLMQs (DIP0024) are built from four quarters, one per DKG cycle. When a cycle can't fill a quarter because too few eligible masternodes are left outside that quorum index's previous three quarters, the builder correctly selects fewer members. But neither legacy snapshot mode records quarter lengths, so when later cycles rebuild that quarter from its snapshot, GetQuorumQuarterMembersBySnapshot fills it up to quarterSize by continuing around the candidate list. That adds members that were never selected, and they can repeat members of the quorum's other quarters. Separately, some builder early returns store no snapshot at all, and a missing snapshot makes later cycles stop loading their older quarters.

In regtest with 3 masternodes this produces compositions like [4a61 | 4a61 | 4a61 | dd15]. The DKG maps a proTxHash to a single member index, so a repeated masternode's extra slots never record a contribution; they are treated as non-contributing members, which leads to complaints and PoSe penalties for an honest masternode. This is what made feature_llmq_dkgerrors.py fail intermittently.

A second, related path: when the builder collects previous members into CDeterministicMNLists with AddMN, unique-property conflicts between historical member states (e.g. an address reused after service updates) throw and are silently swallowed. The member drops out of its index's exclusion set and can be selected again ([A, B, A]), and a candidate can be blocked by a conflict with a previous member's old state.

Mainnet history never hit the short-quarter case: a -reindex-chainstate replay with a build that logs every short quarter and early return found none. Testnet did: an early return at h=838,368 (7 enabled masternodes) and short quarters in 12 cycles (h=901,152–903,168 and h=1,366,560–1,367,136, with 47–57 candidates). A testnet replay with an ungated version of this fix stopped at h=841,634 (bad-cb-payee), so the change has to be gated.

What was done?

The consensus changes to quarter selection and snapshot interpretation are gated by a new EHF deployment, quarter_steps (version bit 15). Whether a cycle uses them is decided by DeploymentActiveAt(cycleBase), and every rebuild of a quarter uses the state at that quarter's own cycle base. Cycles before activation are built and rebuilt exactly as before.

  • refactor(llmq): the existing selection and rebuild loops move unchanged into WalkLegacyQuarters / ReplayLegacyQuarters, with tests pinning their output, including the skip-list quirk where a first skip at position 0 is treated as unset, and the serialized snapshot bytes.

  • feat(llmq): WalkNewQuarters / ReplayNewQuarters record skips as walk step numbers in the existing mnSkipList: the first entry is the absolute step, each later entry is the positive delta from the previous skip. A quarter ends when full or after list.size() consecutive skips, so the rebuild reproduces exactly what was selected, including short and empty quarters. The decoder rejects malformed, unconsumed or duplicate-position lists. The snapshot serialization and qrinfo formats are unchanged.

  • feat: the quarter_steps deployment (mainnet/testnet parameters are NEVER_ACTIVE placeholders until the release sets them; devnet/regtest copy evo_shares), and a regtest-only -llmqtestdip0024params=<size>:<threshold> that sets the LLMQ_TEST_DIP0024 size and sets minSize, threshold and dkgBadVotesThreshold to <threshold>; the size must be a positive multiple of 4 within the supported maximum.

  • feat(llmq):

    • Gated (after activation):
      • the builder's insufficient-candidate and no-progress exits no longer apply, so successful builds store a snapshot even with short or empty quarters (encoder overflow aborts without storing one; predictions never store);
      • membership exclusion is by proTxHash only, which closes the AddMN conflict path.
    • Not gated:
      • ComputeRotationQuarters exposes each index's four quarters;
      • GetAllQuorumMembers handles an empty rotation result safely;
      • quorum dkginfo gains an additional known: false case, with a specific reason, when the deployment state at a future cycle base can't be settled from its work block under a conservative state/window rule (LOCKED_IN is always treated as unknown).

    Includes a release note describing the rule for SPV implementers.

  • test: DashTestFramework activates quarter_steps by default (vbparams=quarter_steps:-1:...), with a per-test switch to turn it off, and gains a configurable rotating-quorum minimum size and optional "predictions must be known" checks.

  • llmq: rotation composition debug logs print 16-character proTxHash prefixes instead of 4.

  • test: new feature_llmq_rotation_short_quarters.py.

How Has This Been Tested?

Tested on macOS (Apple Silicon), depends build, configured with --enable-debug --enable-werror --enable-crash-hooks.

  • Unit tests (src/test/llmq_utils_tests.cpp, llmq_params_tests.cpp, evo_snapshot_tests.cpp), full test_dash suite passing:
    • pinned legacy encoder/decoder output;
    • an exhaustive encoder/decoder round trip over small candidate lists and per-index used sets, including a collision case the old position-based encoding can't distinguish;
    • malformed-input rejection;
    • builder vs rebuild across cycles;
    • zero candidates still storing a snapshot;
    • prediction writing no snapshot;
    • the activation boundary;
    • the prediction rule for all deployment states and representative window sizes;
    • proTxHash-only exclusion, including the [A, B, A] case.
  • New functional test feature_llmq_rotation_short_quarters.py (3 masternodes, -llmqtestdip0024params=8:3):
    • repeated members before activation, and a below-minimum cycle that forms no quorum;
    • EHF activation landing one block after a cycle base, checked with getdeploymentinfo;
    • post-activation quarters equal to the builder's logged selections;
    • the quarter built at the last legacy cycle following the legacy rule (simulated exactly);
    • short quorums forming with accepted commitments, and a post-activation below-minimum cycle;
    • a reorg across activation and a cold restart.
  • Fails without the fix:
    • forcing the rule off makes the functional test fail at the composition check;
    • an off-by-one variant of the activation predicate fails both the unit boundary test and the functional test;
    • routing the post-activation path through the old AddMN sets fails the new exclusion unit tests.
  • Functional regression runs on this branch, all passing: feature_llmq_rotation.py, feature_llmq_chainlocks.py, feature_llmq_is_cl_conflicts.py, feature_llmq_is_retroactive.py, rpc_verifyislock.py, feature_llmq_connections.py, feature_llmq_simplepose.py, feature_llmq_signing.py, feature_llmq_dkgerrors.py (8 parallel runs), feature_mnehf.py, feature_evo_shares_activation.py, interface_rest.py, feature_asset_locks.py, feature_dip3_deterministicmns.py, feature_llmq_evo.py, rpc_masternode.py, p2p_quorum_data.py, feature_llmq_data_recovery.py, rpc_blockchain.py. Not run locally: interface_zmq_dash.py (no Python zmq module in my environment).
  • Replays: mainnet and testnet -reindex-chainstate with a logging-only build, used for the findings above. -reindex-chainstate replays of mainnet and testnet with this branch (0d96bafed4), offline from the existing block files: both reached their existing tips with a single active chain tip and no rejected blocks or consensus errors in debug.log, including the testnet short-quarter cycles listed above where the ungated fix had failed. quarter_steps is NEVER_ACTIVE on both networks, so history replays under the legacy rule unchanged.

Breaking Changes

Consensus change, inactive until quarter_steps activates; mainnet/testnet dates are not set yet. After activation:

  • the meaning of mnSkipList changes for affected cycles (same serialized format);
  • membership exclusion is by proTxHash only.

Quarters built before activation keep the legacy rebuild, so repeated members remain possible during the transition. The first quorum made up entirely of new-rule quarters comes three cycles after the first cycle that uses the new rule. Quorum sizes, minimum sizes and thresholds are unchanged; the fix only keeps short compositions as selected, and the existing DKG and commitment rules still decide whether they form a quorum.

SPV clients that rebuild rotating quorums from qrinfo must implement the rule described in doc/release-notes-8012.md before activation. Devnets running this build will activate it on their own once masternodes signal it.

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

@thepastaclaw

thepastaclaw commented Nov 1, 2026 •

Copy link
Copy Markdown
Collaborator

🕓 Review not started yet because this PR is a draft.

  • Request normal review — click when the PR is ready for review.
  • Request priority review — click to move this review to the front of the queue.

Commit 76a8bbc. Normal review starts when eligible; priority review starts as soon as a slot is available.

UdjinM6 and others added 8 commits November 1, 2026 21:19
…steps

Once quarter_steps is active at a cycle's base block, the builder records the
cycle's new quarters with the step-encoded walk and always stores a snapshot,
and every rebuild of that cycle replays the steps, so short and empty quarters
are rebuilt exactly as selected instead of being padded with invented members.
Cycles before activation keep the legacy encoding byte for byte.

Predictions of a future cycle take the rule from the deployment state after
the work block and report the cycle as unknown while it is still STARTED or
LOCKED_IN. ReplayNewQuarters also rejects a skip list that would repeat a
position within one quarter, which the walk never produces.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The QuorumComposition, QuarterComposition, sortedCombinedMns and
DKGComposition debug logs identified masternodes by the first 4 hex
characters of their proTxHash, which collide often enough to make
log-based checks of these compositions ambiguous. Use 16 characters.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@UdjinM6
UdjinM6 force-pushed the rotation-quarter-steps branch from 0d96baf to 76a8bbc Compare November 1, 2026 18:43
Comment thread doc/release-notes-8012.md
Consensus changes
-----------------

- A new EHF deployment, `quarter_steps` (version bit 15), changes how rotating LLMQs (DIP0024) record and

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A testnet replay with an ungated version of this fix stopped at h=841,634 (bad-cb-payee), so the change has to be gated.

Instead introduction of fork, better to add exception for testnet for that specific block hashes.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown

This pull request has conflicts, please rebase.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants