Skip to content

fix: erase the superseded mineable commitment when a better one replaces it - #8048

Closed
PastaPastaPasta wants to merge 1 commit into
dashpay:developfrom
PastaPastaPasta:fix/llmq-mineable-commitment-replace
Closed

PastaPastaPasta wants to merge 1 commit into
dashpay:developfrom
PastaPastaPasta:fix/llmq-mineable-commitment-replace

Conversation

@PastaPastaPasta

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

When a better final commitment (more signers) replaces the one a node has pooled for a quorum, the old commitment is never erased. AddMineableCommitment repoints the quorum's entry at the new hash first, and then erases through that same reference, so the erase targets the new hash, which is not in the map yet. It has been like this since commitments were first pooled in #2477.

Nothing points at the old entry afterwards, so it is never chosen for a block template. But HasMineableCommitment and GetMineableCommitmentByHash still find it, so the node keeps answering AlreadyHave for it and keeps serving it on GETDATA. It also holds the commitment for the life of the process, unless that exact commitment is later mined. The replacement runs when a DKG member's own finalization produces a commitment with more signers than one it already pooled.

What was done?

AddMineableCommitment now erases the old entry before repointing the quorum's entry at the new one. The reference is renamed from insertedQuorumHash to knownCommitmentHash, since it holds a commitment hash, not a quorum hash.

Why this can't change mining or validity:

  • GetMineableCommitments, which feeds block templates and quorum dkgstatus, only reads commitments through minableCommitmentsByQuorum, and that map's contents are unchanged.
  • The erased hash can't be referenced by any other quorum's entry, because a commitment's serialized hash covers its llmqType and quorumHash.
  • Block validation never reads the pool.

The only P2P difference is that a superseded hash is no longer "already have". A peer that announces it is handled the same way as any worse commitment the node never stored.

Related issues found while checking this, left for separate PRs:

  • ProcessCommitment erases the mined commitment's hash and the quorum's entry. If the mined commitment differs from the pool's best for that quorum, the pool's best is orphaned the same way.
  • The "already got a better one" pre-check in ProcessMessage is inverted. It drops an incoming commitment with at least as many signers as the pooled one, and sends a worse one on to full verification. So a pooled commitment is never upgraded over P2P. Fixing it changes which commitment gets mined, so it needs its own review.
  • Nothing prunes a pooled commitment when its mining window ends with only null commitments mined.
  • UndoBlock re-pools a commitment even when the mined record is kept for another chainstate. Background validation never disconnects a shared block, so this can't happen today; it belongs with the AssumeUTXO work.

How Has This Been Tested?

The new unit test llmq_blockprocessor_tests/superseded_mineable_commitment_is_dropped covers this. A better commitment replaces a worse one, after which the worse one is no longer found by HasMineableCommitment or GetMineableCommitmentByHash. Re-adding the worse one, or one with an equal signer count, neither displaces the kept commitment nor gets stored.

With the blockprocessor.cpp change reverted, the test fails on exactly the three checks for the superseded hash. With the change, it passes. The llmq_*, evo_cbtx_tests, evo_db_tests, evo_snapshot_tests, evo_simplifiedmns_tests, validation_chainstatemanager_tests and block_reward_reallocation_tests suites also pass, 153 cases in all, on a Linux x86_64 --enable-debug build.

Breaking Changes

None.

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 (if you have permission to set one)

🤖 Generated with Claude Code

@PastaPastaPasta PastaPastaPasta changed the title fix(llmq): erase the superseded mineable commitment when a better one replaces it fix: erase the superseded mineable commitment when a better one replaces it Nov 4, 2026
When AddMineableCommitment received a commitment with more signers than
the one already pooled for that quorum, it pointed the quorum's entry at
the new hash first and then erased by that same reference. The erase
therefore targeted the new hash, which was not in the map yet, and the
superseded commitment stayed in minableCommitments. This has been the
case since commitments were first pooled in dashpay#2477.

The replacement runs when a DKG member's own finalization yields a
commitment with more signers than one it already pooled. Nothing pointed
at the old entry afterwards, so it was never chosen for a block
template, but HasMineableCommitment and GetMineableCommitmentByHash
still found it: the node kept answering AlreadyHave for it and serving
it on GETDATA, and held it for the life of the process unless that
exact commitment was later mined.

Erase the old entry before repointing the quorum's entry at the new one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@PastaPastaPasta
PastaPastaPasta force-pushed the fix/llmq-mineable-commitment-replace branch from 7cc7e8d to 2d7a4f5 Compare November 4, 2026 05:51
@thepastaclaw

thepastaclaw commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit 2d7a4f5) · triage: low

@thepastaclaw thepastaclaw left a comment

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.

Final validation — Phase 1 + Phase 2

At head 2d7a4f5, erasing the superseded commitment before updating the quorum's stored hash correctly fixes the replacement leak without changing commitment selection or block validation. The regression test exercises the affected hash lookups and rejection of worse or tied submissions; no in-scope defects were found. Current GitHub checks show successful builds, tests, sanitizers, and lint with no pending or failed checks; no builds or tests were run locally, and the supplied base-drift evidence reports no conflicts or intervening changes to the touched files.

Review provenance

Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: dash-core-commit-history); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.1-sol (effort low) — The diff makes a small, contained map-update ordering fix in AddMineableCommitment and adds a focused regression test without changing consensus or commitment selection logic.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 98% left, weekly 58% left; passed over gemini-3.8-flash-high (antigravity quota lookup failed)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — dash-core-commit-history (completed, effort medium); agent phase2-reviewer
Out-of-scope follow-up suggestions (2)

These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.

  • Inverted better-commitment pre-check in ProcessMessage prevents normal P2P upgrades — At src/llmq/blockprocessor.cpp:181-193, the pre-check returns when the pooled commitment has fewer or equal signers than the incoming commitment. It therefore rejects a better incoming commitment while allowing a worse one through signature verification. This condition also exists in the parent commit and is independent of the replacement cleanup: correcting AddMineableCommitment does not require changing which peer commitments are accepted.
    • Follow-up: Track a separate fix for the comparison, with regression coverage showing that a valid better incoming commitment replaces the pooled one and an inferior commitment is rejected before expensive verification.
  • Mining a different commitment leaves the pooled best commitment orphaned — At src/llmq/blockprocessor.cpp:449-452, ProcessCommitment removes the quorum's lookup entry but erases only the mined commitment's hash. If the node pooled a different commitment for that quorum, its hash entry remains available through HasMineableCommitment and GetMineableCommitmentByHash without a corresponding quorum entry. The parent commit contains the same cleanup logic; this separate block-processing lifecycle defect is neither introduced nor worsened by the replacement fix.
    • Follow-up: Track a separate cleanup fix and unit test for mining a commitment whose hash differs from the locally pooled best commitment.

@thepastaclaw thepastaclaw added the pastaclaw:approved thepastaclaw's latest review approved this PR label Nov 4, 2026
@github-actions

Copy link
Copy Markdown

This pull request has conflicts, please rebase.

@PastaPastaPasta

Copy link
Copy Markdown
Member Author

Closing as superseded by #8085 (merged in 9c981d9). It moved minableCommitments.erase(insertedQuorumHash) ahead of insertedQuorumHash = commitmentHash in AddMineableCommitment, which is the same reordering this PR made. It also fixed the inverted pre-check in ProcessMessage, and its qfcommit_with_more_signers_replaces_stored_one test already checks that the superseded commitment is erased. After a rebase, this PR would only add a rename and a duplicate test.

Two follow-ups from this PR's description are still open on develop:

  • ProcessCommitment can leave the pool's best commitment orphaned when a different commitment for the same quorum is mined.
  • Nothing removes a pooled commitment when its mining window ends with only null commitments.

🤖 Posted autonomously by Claude on behalf of pasta.

@thepastaclaw thepastaclaw removed the pastaclaw:approved thepastaclaw's latest review approved this PR label Nov 11, 2026
PastaPastaPasta added a commit that referenced this pull request Nov 11, 2026
… rejected

3936953 fix: keep final commitments mineable when their block is rejected (pasta)

Pull request description:

  ## Issue being fixed or feature implemented
  `CQuorumBlockProcessor::ProcessCommitment()` removed a block's final commitments from the mineable pool while the block was still being validated. `ConnectBlock()` processes quorum commitments early, before inputs, scripts, the coinbase amount/payee checks and several special-transaction checks. A block carrying the commitment of a finished DKG that then failed one of those later checks was never connected, yet every node that validated it (compact blocks are relayed before validation) had dropped the commitment from its pool. Nothing re-adds it, so that quorum was not mined in that DKG cycle.

  ## What was done?
  - `ProcessCommitment()` no longer touches the mineable pool, apart from dropping its caches.
  - New `CQuorumBlockProcessor::RemoveMineableCommitmentsForBlock()` removes the same entries as before, called once `ConnectBlock()` has accepted the block (next to where the BLS scheme switch is committed) and in `RollforwardBlock()`.
  - Check-only validation (`fJustCheck` / `TestBlockValidity`) returns before that point and never touches the pool. `UndoBlock()` still re-adds the commitments of a disconnected block, so reorgs behave as before.

  Re-adding on the failure path instead was rejected: a block can fail partway through its commitments, which could re-pool a commitment that was never verified. This doesn't overlap with #8048, which changes `AddMineableCommitment` only.

  ## How Has This Been Tested?
  `feature_llmq_dkgerrors.py`: after the existing `invalidateblock` check, the test submits the same commitment-carrying block with the coinbase paying 1 duff too much, expects `bad-cb-amount`, and asserts the commitment is still listed as mineable in `quorum dkgstatus`. It fails on `develop` and passed three times with this change. A five-node reproduction also fails on `develop`; with the fix every node keeps the commitment and the quorum is mined within its window. `llmq_*`, `evo_*` and `validation_chainstatemanager_tests` unit tests pass, as do `feature_llmq_rotation.py`, `feature_llmq_is_cl_conflicts.py`, `feature_llmq_evo.py`, `feature_llmq_signing.py`, `feature_llmq_simplepose.py`, `feature_llmq_singlenode.py`, `feature_llmq_dkg_intake.py`, `feature_dip4_coinbasemerkleroots.py`, `feature_quorum_proof_chain.py`, `rpc_quorum.py`, `feature_new_quorum_type_activation.py` and `feature_abortnode.py`.

  ## Breaking Changes
  None.

  ## Checklist:
  - [x] 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 _(if you have permission to set one)_

  🤖 Generated with [Claude Code](https://claude.com/claude-code)

Top commit has no ACKs.

Tree-SHA512: a306a6fbf6613ca25dfce8665815c94833ebeb012642f492db882ea7154ac1a987bfe5c0afbebcc7d09762fcf8373e664ea3bb2a82e0c5921d87723426e2f4b6
PastaPastaPasta added a commit to PastaPastaPasta/dash that referenced this pull request Nov 12, 2026
…lock is rejected

3936953 fix: keep final commitments mineable when their block is rejected (pasta)

Pull request description:

  ## Issue being fixed or feature implemented
  `CQuorumBlockProcessor::ProcessCommitment()` removed a block's final commitments from the mineable pool while the block was still being validated. `ConnectBlock()` processes quorum commitments early, before inputs, scripts, the coinbase amount/payee checks and several special-transaction checks. A block carrying the commitment of a finished DKG that then failed one of those later checks was never connected, yet every node that validated it (compact blocks are relayed before validation) had dropped the commitment from its pool. Nothing re-adds it, so that quorum was not mined in that DKG cycle.

  ## What was done?
  - `ProcessCommitment()` no longer touches the mineable pool, apart from dropping its caches.
  - New `CQuorumBlockProcessor::RemoveMineableCommitmentsForBlock()` removes the same entries as before, called once `ConnectBlock()` has accepted the block (next to where the BLS scheme switch is committed) and in `RollforwardBlock()`.
  - Check-only validation (`fJustCheck` / `TestBlockValidity`) returns before that point and never touches the pool. `UndoBlock()` still re-adds the commitments of a disconnected block, so reorgs behave as before.

  Re-adding on the failure path instead was rejected: a block can fail partway through its commitments, which could re-pool a commitment that was never verified. This doesn't overlap with dashpay#8048, which changes `AddMineableCommitment` only.

  ## How Has This Been Tested?
  `feature_llmq_dkgerrors.py`: after the existing `invalidateblock` check, the test submits the same commitment-carrying block with the coinbase paying 1 duff too much, expects `bad-cb-amount`, and asserts the commitment is still listed as mineable in `quorum dkgstatus`. It fails on `develop` and passed three times with this change. A five-node reproduction also fails on `develop`; with the fix every node keeps the commitment and the quorum is mined within its window. `llmq_*`, `evo_*` and `validation_chainstatemanager_tests` unit tests pass, as do `feature_llmq_rotation.py`, `feature_llmq_is_cl_conflicts.py`, `feature_llmq_evo.py`, `feature_llmq_signing.py`, `feature_llmq_simplepose.py`, `feature_llmq_singlenode.py`, `feature_llmq_dkg_intake.py`, `feature_dip4_coinbasemerkleroots.py`, `feature_quorum_proof_chain.py`, `rpc_quorum.py`, `feature_new_quorum_type_activation.py` and `feature_abortnode.py`.

  ## Breaking Changes
  None.

  ## Checklist:
  - [x] 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 _(if you have permission to set one)_

  🤖 Generated with [Claude Code](https://claude.com/claude-code)

Top commit has no ACKs.

Tree-SHA512: a306a6fbf6613ca25dfce8665815c94833ebeb012642f492db882ea7154ac1a987bfe5c0afbebcc7d09762fcf8373e664ea3bb2a82e0c5921d87723426e2f4b6
v24.0.x adaptations: Chainstate has no m_special_tx member here, so
ConnectBlock() and RollforwardBlock() call the processor through
m_chain_helper->special_tx like the neighbouring special-tx calls.
CQuorumBlockProcessor keeps the v24.0.x GetCommitmentsFromBlock(), and
RemoveMineableCommitmentsForBlock()'s lock annotation drops
!m_commitment_payload_mutex, which only exists with dashpay#7936.

(cherry picked from commit ce9ef66)
PastaPastaPasta added a commit to PastaPastaPasta/dash that referenced this pull request Nov 12, 2026
…lock is rejected

3936953 fix: keep final commitments mineable when their block is rejected (pasta)

Pull request description:

  ## Issue being fixed or feature implemented
  `CQuorumBlockProcessor::ProcessCommitment()` removed a block's final commitments from the mineable pool while the block was still being validated. `ConnectBlock()` processes quorum commitments early, before inputs, scripts, the coinbase amount/payee checks and several special-transaction checks. A block carrying the commitment of a finished DKG that then failed one of those later checks was never connected, yet every node that validated it (compact blocks are relayed before validation) had dropped the commitment from its pool. Nothing re-adds it, so that quorum was not mined in that DKG cycle.

  ## What was done?
  - `ProcessCommitment()` no longer touches the mineable pool, apart from dropping its caches.
  - New `CQuorumBlockProcessor::RemoveMineableCommitmentsForBlock()` removes the same entries as before, called once `ConnectBlock()` has accepted the block (next to where the BLS scheme switch is committed) and in `RollforwardBlock()`.
  - Check-only validation (`fJustCheck` / `TestBlockValidity`) returns before that point and never touches the pool. `UndoBlock()` still re-adds the commitments of a disconnected block, so reorgs behave as before.

  Re-adding on the failure path instead was rejected: a block can fail partway through its commitments, which could re-pool a commitment that was never verified. This doesn't overlap with dashpay#8048, which changes `AddMineableCommitment` only.

  ## How Has This Been Tested?
  `feature_llmq_dkgerrors.py`: after the existing `invalidateblock` check, the test submits the same commitment-carrying block with the coinbase paying 1 duff too much, expects `bad-cb-amount`, and asserts the commitment is still listed as mineable in `quorum dkgstatus`. It fails on `develop` and passed three times with this change. A five-node reproduction also fails on `develop`; with the fix every node keeps the commitment and the quorum is mined within its window. `llmq_*`, `evo_*` and `validation_chainstatemanager_tests` unit tests pass, as do `feature_llmq_rotation.py`, `feature_llmq_is_cl_conflicts.py`, `feature_llmq_evo.py`, `feature_llmq_signing.py`, `feature_llmq_simplepose.py`, `feature_llmq_singlenode.py`, `feature_llmq_dkg_intake.py`, `feature_dip4_coinbasemerkleroots.py`, `feature_quorum_proof_chain.py`, `rpc_quorum.py`, `feature_new_quorum_type_activation.py` and `feature_abortnode.py`.

  ## Breaking Changes
  None.

  ## Checklist:
  - [x] 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 _(if you have permission to set one)_

  🤖 Generated with [Claude Code](https://claude.com/claude-code)

Top commit has no ACKs.

Tree-SHA512: a306a6fbf6613ca25dfce8665815c94833ebeb012642f492db882ea7154ac1a987bfe5c0afbebcc7d09762fcf8373e664ea3bb2a82e0c5921d87723426e2f4b6
v24.0.x adaptations: Chainstate has no m_special_tx member here, so
ConnectBlock() and RollforwardBlock() call the processor through
m_chain_helper->special_tx like the neighbouring special-tx calls.
CQuorumBlockProcessor keeps the v24.0.x GetCommitmentsFromBlock(), and
RemoveMineableCommitmentsForBlock()'s lock annotation drops
!m_commitment_payload_mutex, which only exists with dashpay#7936.

(cherry picked from commit ce9ef66)
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.

2 participants