You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
…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]>
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.
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: 3 · 1
Failed checks: 1 inconclusive
Check name
Status
Explanation
Resolution
Title check
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 checks: 3 passed
Check name
Status
Explanation
Description check
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
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
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.
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.
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.
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.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 byblock_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 withcherry-pick -m1of the upstream merge, including upstream's unit test.Dash already reset
fAbortRescaninWalletRescanReserver::reserve()and not inScanForWalletTransactions(), so that line only moves to upstream's position and gains its comment. What changes in Dash is the droppedblock_height &&guard. The test passes Dash's extrafUpdateargument. No upstream hunk is omitted.How Has This Been Tested?
test_dash --run_test=wallet_tests,walletdb_tests,walletload_tests,scriptpubkeyman_testspasses on macOS arm64 (depends build,--enable-debug --enable-werror, no GUI). That includes upstream'swallet_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 withSUCCESSinstead ofUSER_ABORT, and the functional testswallet_import_rescan,wallet_importdescriptors,wallet_transactiontime_rescan,wallet_upgradetohdandwallet_startuppassed. 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:
rescanblockchainand the rescan inupgradetohdreturn "Rescan aborted." in that case.Checklist:
🤖 Generated with Claude Code