Skip to content

fix(ckbtc): clear the consolidation request when no transaction is submitted - #11622

Draft
Dfinity-Bjoern wants to merge 1 commit into
masterfrom
ckbtc-consolidation-hardnening
Draft

Dfinity-Bjoern wants to merge 1 commit into
masterfrom
ckbtc-consolidation-hardnening

Conversation

@Dfinity-Bjoern

@Dfinity-Bjoern Dfinity-Bjoern commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Change

consolidate_utxos records a CreatedConsolidateUtxosRequest, which sets current_consolidate_utxos_request, before it signs the Bitcoin transaction. finalize_transaction was the only place that cleared the field again.

This also clears it whenever no submitted or stuck transaction carries its block index, since such a request can no longer be finalized.

The condition is derived from the state rather than recorded as a new event, which avoids an event log format change and keeps replay and the live minter in agreement. eventlog.rs already uses replay-time derivation this way for dup_received and rejected_sent.

Clearing the field only in memory would not be enough: the event stays in the log, so a later request would trip the assert! in push_consolidate_utxos_request during replay. should_replay_new_request_on_top_of_orphaned_one covers that case.

last_consolidate_utxos_request_time_ns is intentionally left untouched, so the existing 24h interval still applies.

Reusing the new find_unfinalized_transaction also removes a duplicate scan in schedule_withdrawal_reimbursement.

Tests

Five tests, each verified to fail without the change:

  • should_clear_latch_when_rolling_back_unsubmitted_consolidation
  • should_keep_latch_while_submitted_transaction_can_still_be_finalized and the stuck variant
  • should_drop_orphaned_request_when_replaying_events
  • should_replay_new_request_on_top_of_orphaned_one
  • should_clear_consolidation_latch_when_signing_fails, end to end through sign_and_submit_request

Possible follow-ups

  • current_consolidate_utxos_request is not part of check_semantically_eq, so nothing machine-checks that replay and live state agree on it.
  • resubmit_transactions reads the field for information the loop variable already carries; removing that reader would make get_submitted_transaction unused.
  • Narrowing the field to a pending slot consumed by push_submitted_transaction would make the invariant structural. Larger change, touches the shared SentBtcTransaction replay arm.

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

The cleanup logic is consistent across live rollback and event replay, with focused regression coverage.

Pull request overview

Clears orphaned ckBTC UTXO-consolidation requests after signing failures while preserving submitted or stuck transactions.

Changes:

  • Detects and clears dangling consolidation requests during rollback and replay.
  • Reuses transaction lookup logic for reimbursement checks.
  • Adds state-level, replay, and signing-failure tests.
File summaries
File Description
rs/bitcoin/ckbtc/minter/src/tests.rs Tests signing-failure rollback.
rs/bitcoin/ckbtc/minter/src/state/tests.rs Tests latch clearing and replay behavior.
rs/bitcoin/ckbtc/minter/src/state/eventlog.rs Clears orphaned requests after replay.
rs/bitcoin/ckbtc/minter/src/state.rs Implements dangling-request detection and cleanup.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

…bmitted

`consolidate_utxos` records a `CreatedConsolidateUtxosRequest` before it
signs the Bitcoin transaction, and `finalize_transaction` was the only
place that cleared `current_consolidate_utxos_request` again. Clear it
also when no submitted or stuck transaction carries its block index,
since such a request can no longer be finalized.

Deriving the condition from the state rather than recording a new event
keeps replay and the live minter in agreement without changing the event
log format.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Dfinity-Bjoern
Dfinity-Bjoern force-pushed the ckbtc-consolidation-hardnening branch from fcf847f to ce23431 Compare September 18, 2026 21:01
@Dfinity-Bjoern Dfinity-Bjoern changed the title fix(ckbtc): clear the consolidation request when signing fails fix(ckbtc): clear the consolidation request when no transaction is submitted Sep 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants