Skip to content

backport: bitcoin#35512 - #8138

Merged
PastaPastaPasta merged 1 commit into
dashpay:developfrom
PastaPastaPasta:backport/bitcoin-35512
Nov 14, 2026
Merged

PastaPastaPasta merged 1 commit into
dashpay:developfrom
PastaPastaPasta:backport/bitcoin-35512

Conversation

@PastaPastaPasta

Copy link
Copy Markdown
Member

Issue being fixed or feature implemented

ScanForWalletTransactions() reports a rescan from genesis as successful when it is aborted, or interrupted by shutdown, before its first block. The status check is guarded by block_height &&, and the height is still 0 at that point. Callers then treat a scan that read nothing as complete.

This is the fix Bitcoin Core made in bitcoin#35512. It is split out of #8068, which depends on it: that PR settles an owed rescan when a scan reports success.

What was done?

Merge bitcoin/bitcoin#35512, taken with cherry-pick -m1 of the upstream merge, including upstream's unit test.

Dash already reset fAbortRescan in WalletRescanReserver::reserve() and not in ScanForWalletTransactions(), so that line only moves to upstream's position and gains its comment. What changes in Dash is the dropped block_height && guard. The test passes Dash's extra fUpdate argument. No upstream hunk is omitted.

How Has This Been Tested?

test_dash --run_test=wallet_tests,walletdb_tests,walletload_tests,scriptpubkeyman_tests passes on macOS arm64 (depends build, --enable-debug --enable-werror, no GUI). That includes upstream's wallet_tests/scan_for_wallet_transactions_abort.

On an earlier revision of #8068 with this same commit, restoring the block_height && guard made that test fail with SUCCESS instead of USER_ABORT, and the functional tests wallet_import_rescan, wallet_importdescriptors, wallet_transactiontime_rescan, wallet_upgradetohd and wallet_startup passed. They were not rerun for this PR.

Breaking Changes

A rescan from genesis that is aborted or interrupted before its first block used to report success. It now reports an abort, as Bitcoin Core does:

  • rescanblockchain and the rescan in upgradetohd return "Rescan aborted." in that case.
  • A wallet whose load-time rescan from genesis is interrupted by shutdown before its first block fails to load instead of being recorded as scanned.

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

…nReserver reserve function

BACKPORT NOTE: Dash already reset fAbortRescan in WalletRescanReserver::reserve() and not in
ScanForWalletTransactions(), so the reset only moves to upstream's place and gains its comment.
What changes in Dash is the status of a scan from genesis that is aborted, or interrupted by
shutdown, before its first block: it was reported as SUCCESS and is now USER_ABORT.
- rescanblockchain and upgradetohd return "Rescan aborted." in that case.
- A wallet whose load-time rescan from genesis is interrupted by shutdown before its first block
  fails to load instead of being recorded as scanned.
- The test passes Dash's extra fUpdate argument.
---
2818a17 test: add abortscan unit test (Pol Espinasa)
bc30e95 wallet: move fAbortRescan reset into WalletRescanReserver reserve() (Pol Espinasa)

Pull request description:

  Follow-up of bitcoin#35179
  For extra context refer to the conversations bitcoin#35179 (comment) and comments bellow it.

  Long story short: currently `ScanForWalletTransactions()` resets the value of `fAbortRescan` before starting the rescan loop. This can cause a race condition where some function (e.g. `importdescriptors`) starts a rescan and at the same time the user aborts it manually. Could happen that the `abortrescan` call returns True (success) but the rescan continues running as the value is overwritten.

  This PR fixes this by resetting the value of `fAbortRescan` at the very beginning, when the wallet rescan is reserved, removing the race condition. Also adds a test for it.

ACKs for top commit:
  achow101:
    ACK 2818a17
  w0xlt:
    ACK 2818a17
  nebula-21:
    ACK 2818a17
  pablomartin4btc:
    ACK 2818a17
  pinheadmz:
    ACK 2818a17

Tree-SHA512: 5b64b9a16a209dd145ccf7b2d7c3a7205038b3b214b02c3d9f1cbda75a6a1c9a41ad5c42cbeda43af6141793965613c47e44300d758149be9bfdf458e85a5520

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@PastaPastaPasta PastaPastaPasta added this to the 24.1 milestone Nov 13, 2026
@coderabbitai

coderabbitai Bot commented Nov 13, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

A successful scan reservation now clears a leftover abort request before updating scan state. Abort and shutdown handling can set USER_ABORT when the scan is at height zero. A new test checks that an abort issued before reservation does not cancel a later scan, and that an abort issued after reservation but before scanning returns USER_ABORT without recording scanned or failed blocks.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: Minimal · up to 3f19f

This change makes an aborted rescan report an abort instead of success when it is interrupted before its first block. It also adds a unit test for abort timing. No merge-blocking risk was found.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Title check Inconclusive The title "backport: bitcoin#35512" names the upstream PR being backported, but it does not describe the change. A reader scanning history cannot tell that the change concerns rescan abort handling in… Rewrite the title to state the main change, for example: "wallet: report abort for rescan aborted before first block" (or keep the backport reference as a suffix). This lets a teammate scanning history see the fix without opening the PR.
Passed Passed checks: 3 passed

Check name Status Explanation
Description check Passed The description explains the bug in ScanForWalletTransactions(), where the block_height guard hides aborts and shutdowns before the first block. It describes the moved fAbortRescan reset, the test cov…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the bug in ScanForWalletTransactions(), where the block_height guard hides aborts and shutdowns before the first block. It describes the moved fAbortRescan reset, the test coverage, the test results, and the breaking behavior changes. It is directly related to the changeset.

Full details: Title check

Explanation

The title "backport: bitcoin#35512" names the upstream PR being backported, but it does not describe the change. A reader scanning history cannot tell that the change concerns rescan abort handling in the wallet. The title is brief and specific to the source reference, so it is not vague or generic. It is related to the changeset but does not state the main change.

Resolution

Rewrite the title to state the main change, for example: "wallet: report abort for rescan aborted before first block" (or keep the backport reference as a suffix). This lets a teammate scanning history see the fix without opening the PR.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 452c7c59-112b-4fc6-b08c-1e18e6bf1909
Commits

Reviewing files that changed from the base of the PR and between 5c34dcf and 3f19f5a.

Files selected for processing: 3

  • src/wallet/test/wallet_tests.cpp
  • src/wallet/wallet.cpp
  • src/wallet/wallet.h

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@thepastaclaw

thepastaclaw commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit 3f19f5a) · 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

The backport faithfully implements the intended wallet rescan behavior and includes the regression test. No blocking correctness issues were found; lint, cppcheck, ClangFormat, and cache checks passed, while the platform build checks remain queued. The user-visible behavior change should be documented in a release note.

💬 1 nitpick(s)

Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.

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: backport-reviewer); reviewer 4: 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) — This is a small, well-contained wallet rescan status fix with an accompanying unit test, and its correctness is straightforward to verify despite affecting load and rescan outcomes.
  • 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 — backport-reviewer (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — dash-core-commit-history (completed, effort medium); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.

In `src/wallet/wallet.cpp`:
- [NITPICK] src/wallet/wallet.cpp:2256-2261: Add a release note for the changed rescan-abort behavior
  This change alters user-visible behavior: a genesis rescan aborted before processing its first block now returns USER_ABORT, causing rescanblockchain and upgradetohd to report "Rescan aborted." and causing an interrupted load-time rescan to fail wallet loading. The PR explicitly documents these as breaking changes, and recent Dash backports use per-change files under doc/release-notes-<PR>.md. Add a release note, such as doc/release-notes-35512.md, describing the new behavior.

Comment thread src/wallet/wallet.cpp
Comment on lines +2256 to 2261
if (fAbortRescan) {
WalletLogPrintf("Rescan aborted at block %d. Progress=%f\n", block_height, progress_current);
result.status = ScanResult::USER_ABORT;
} else if (block_height && chain().shutdownRequested()) {
} else if (chain().shutdownRequested()) {
WalletLogPrintf("Rescan interrupted by shutdown request at block %d. Progress=%f\n", block_height, progress_current);
result.status = ScanResult::USER_ABORT;

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.

💬 Nitpick: Add a release note for the changed rescan-abort behavior

This change alters user-visible behavior: a genesis rescan aborted before processing its first block now returns USER_ABORT, causing rescanblockchain and upgradetohd to report "Rescan aborted." and causing an interrupted load-time rescan to fail wallet loading. The PR explicitly documents these as breaking changes, and recent Dash backports use per-change files under doc/release-notes-.md. Add a release note, such as doc/release-notes-35512.md, describing the new behavior.

source: glm-5.3-flash (phase1-reviewer: general)

@thepastaclaw thepastaclaw added the pastaclaw:approved thepastaclaw's latest review approved this PR label Nov 13, 2026

@PastaPastaPasta PastaPastaPasta left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Approved

@PastaPastaPasta
PastaPastaPasta merged commit 60f9e61 into dashpay:develop Nov 14, 2026
50 checks passed
@thepastaclaw thepastaclaw removed the pastaclaw:approved thepastaclaw's latest review approved this PR label Nov 14, 2026

@knst knst 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.

post-utACK 3f19f5a

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants