Skip to content

Wallet: Clear -newwallet and -rescan after the startup scan - #2011

Open
reubenyap wants to merge 1 commit into
masterfrom
claude/dreamy-mayer-c0c708
Open

reubenyap wants to merge 1 commit into
masterfrom
claude/dreamy-mayer-c0c708

Conversation

@reubenyap

@reubenyap reubenyap commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

PR intention

-newwallet and -rescan are startup options, but they stayed set for the whole process, and CWallet::ScanForWalletTransactions reads them on every call. Two bugs follow:

  • After "Create new wallet" in Qt (-newwallet=1): every later rescan returns early, so importaddress, importpubkey, importmulti and the BIP47 rescan import nothing, and importmulti dereferences the null scan result. Repro: firod -regtest -newwallet=1, generate 10, importmulti '[{"scriptPubKey":"76a914000000000000000000000000000000000000000088ac","timestamp":0,"watchonly":true,"internal":true}]' → SIGSEGV.
  • With -rescan=1 (soft-set on every mnemonic first run, or passed by the user): every later rescan ignores its own start block and starts at nMnemonicBlock (222400 on mainnet; genesis for non-mnemonic wallets). Imported history before that block is missed, and each import or BIP47 rescan re-reads the chain from there while holding cs_main and cs_wallet. Upstream only reads -rescan for the startup scan.

Code changes brief

  • CreateWalletFromFile: clear both args right after the startup scan, which is itself unchanged. ForceSetArg(…, "0"), because an empty value reads as true. The two clears belong together: with only -newwallet cleared, the BIP47 rescan after "Create new wallet" would start at nMnemonicBlock.
  • importmulti: a null scan result (shutdown during the scan, unreadable last block) now checks every key against the tip and reports "Failed to rescan before time …" instead of crashing.
  • New qa/rpc-tests/wallet_startup_scan_args.py: a node started with -newwallet=1 -rescan must find another node's payment through importmulti, and that scan must not start at block 0. It fails on master (crash) and with the -rescan clear removed (scan from block 0).
  • -wcdate leaks the same way; Wallet: Stop restore args leaking past their use #2015 clears it at the same spot, and the two branches merge cleanly.

Testing

Linux Release build with GUI and tests. ctest passes except WalletUiTests::themeTintColors, which fails on master too.

Regtest, old vs. new firod (100 blocks dated 2020, then 10 dated 2021; importmulti with a 2021 timestamp, so it should start at block 101):

Scenario Old New
Create session: importaddress, importpubkey no scan from block 0 (whole chain, as upstream)
Create session: importmulti SIGSEGV from block 101
Mnemonic first run: importmulti from block 0 from block 101
Restart with -rescan: startup scan / importmulti 0 / 0 0 / 101

qa tests passing: the new one plus notifications, transactions_verification_after_restart, zapwallettxes, importprunedfunds, wallet, wallet-hd, wallet-dump, bip47-walletrestore, consolidation, listtransactions. Not exercised: the Qt BIP47 rescan itself; it is the same ScanForWalletTransactions call.

🤖 Generated with Claude Code

-newwallet=1, set by the Qt "Create new wallet" path, stayed set for
the whole session. Every later ScanForWalletTransactions returned early
("Created new wallet, no need to scan"), so the rescans of
importaddress, importpubkey, importmulti and the BIP47 rescan did
nothing. importmulti then dereferenced the null scannedRange and
crashed (SIGSEGV on regtest).

-rescan=1, soft-set on every mnemonic first run and also passed by
users, stayed set too. ScanForWalletTransactions reads it, so every
later rescan ignored its own start block and began at nMnemonicBlock
(genesis for non-mnemonic wallets). Mnemonic wallets missed imported
history before that block, and forward rescans re-read the chain from
there while holding cs_main and cs_wallet. -rescan is documented as a
startup option, and upstream only reads it for the startup scan.

Clear both in CreateWalletFromFile right after the startup scan. They
go together: with only -newwallet cleared, the BIP47 rescan in a Create
session would scan from nMnemonicBlock. Also make importmulti check
keys against the tip when the scan returns null (shutdown, unreadable
last blocks) instead of crashing.

Tests: add wallet_startup_scan_args.py. It fails on the old code
(importmulti crash) and without the -rescan clear (scan from block 0).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codeant-ai

codeant-ai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

🤖 CodeAnt AI — Review Status

Status Commit Started (UTC) Finished (UTC)
✅ Reviewed your PR 571ce39 Oct 19, 2026 · 15:41 15:45

@codeant-ai

codeant-ai Bot commented Oct 19, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T15:43:11.689516Z 571ce39 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: b334274e-4526-4149-a199-f6609f876770
📥 Commits

Reviewing files that changed from the base of the PR and between 8246465 and 571ce39.

📒 Files selected for processing: 4
  • qa/pull-tester/rpc-tests.py
  • qa/rpc-tests/wallet_startup_scan_args.py
  • src/wallet/rpcdump.cpp
  • src/wallet/wallet.cpp

Included review availability: This review used your included allowance. 4 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.

Summary by CodeRabbit

  • Bug Fixes
    • Wallet imports now handle cases where a rescan returns no scanned block, including when a scan is interrupted, without relying on missing scan data.
    • Startup scan options are reset after wallet startup, so they do not carry over to subsequent operations.
  • Tests
    • Added coverage for importing a watch-only address after wallet startup and confirming that the transaction is found without rescanning from the beginning of the chain.

Walkthrough

The change clears -newwallet and -rescan after wallet startup, uses the active chain tip when importmulti receives no scanned block, and adds a default RPC test for startup scan arguments and watch-only imports.

Changes

Wallet startup scan handling

Layer / File(s) Summary
Clear startup scan arguments
src/wallet/wallet.cpp
After startup processing, CreateWalletFromFile sets -newwallet and -rescan to "0".
Handle imports after startup scan
src/wallet/rpcdump.cpp, qa/rpc-tests/wallet_startup_scan_args.py, qa/pull-tester/rpc-tests.py
When a scan returns no block, importmulti uses the active chain tip as scannedRange. The RPC test checks watch-only import success, transaction retrieval, and that the last matching rescan log entry is not from block 0. The default RPC test list includes this test.

Priority: ➖ Normal

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

Change: Bug fix

Suggested reviewers: levonpetrosyan93

Merge Risk: ⚪ Minimal · up to 571ce

No actionable merge-blocking risk remains; the startup scan regression is covered by the new test.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: clearing -newwallet and -rescan after the startup scan.
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.
Description check Passed The pull request description includes both required sections. It clearly states the intent, affected behaviors, code changes, regression test, and testing results. It is complete and aligned with the …
Full details: Description check

Explanation

The pull request description includes both required sections. It clearly states the intent, affected behaviors, code changes, regression test, and testing results. It is complete and aligned with the pull request objectives.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@codeant-ai codeant-ai Bot added the size:M This PR changes 30-99 lines, ignoring generated files label Oct 19, 2026
@codeant-ai

codeant-ai Bot commented Oct 19, 2026

Copy link
Copy Markdown

CodeAnt-AI Description

Keep startup scan settings from disrupting later wallet imports

What Changed

  • Startup scan settings no longer skip later rescans or force them to start from the beginning, so imports and BIP47 scans use their own scan range.
  • importmulti no longer crashes when a scan returns no scanned range; it checks imported keys against the chain tip.
  • Added a regression test for later imports after startup scans.

Impact

✅ Wallet imports rescan after new-wallet startup
✅ Imported history scans from the requested range
✅ Fewer importmulti crashes when scans stop early

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

@codeant-ai

codeant-ai Bot commented Oct 19, 2026

Copy link
Copy Markdown

CodeAnt PR Risk: Medium Risk

  • The PR needs attention before merging because its startup-argument handling has an unresolved multi-wallet risk.
  • The global -newwallet and -rescan flags are reset inside wallet creation, so later wallets may not receive them; confirm the intended behavior for multi-wallet startup.

Assessed commit: 571ce395fd6e

This branch has not been deployed

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

Labels

size:M This PR changes 30-99 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant