Skip to content

wallet: Follow-ups to create/load split (#32636) - #34490

Closed
davidgumberg wants to merge 3 commits into
bitcoin:masterfrom
davidgumberg:2026-02-02-create-load-refactor-followup
Closed

davidgumberg wants to merge 3 commits into
bitcoin:masterfrom
davidgumberg:2026-02-02-create-load-refactor-followup

Conversation

@davidgumberg

@davidgumberg davidgumberg commented Feb 3, 2026 •

Copy link
Copy Markdown
Contributor

This adds documentation for PopulateWalletFromDB() and improves documentation for LoadExisting() and CreateNew(), and makes WalletBatch::WriteVersion(int client_version) respect the argument that it's passed, addressing issues reviewers pointed in #32636.

@DrahtBot DrahtBot added the Wallet label Feb 3, 2026
@davidgumberg
davidgumberg marked this pull request as draft February 3, 2026 06:03
@DrahtBot

DrahtBot commented Feb 3, 2026 •

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
Concept ACK rkrux, w0xlt

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #34909 (wallet, refactor: modularise wallet by extracting out legacy wallet migration by rkrux)
  • #33034 (wallet: Store transactions in a separate sqlite table by achow101)
  • #32895 (wallet: Prepare for future upgrades by recording versions of last client to open and decrypt by achow101)
  • #28333 (wallet: Construct ScriptPubKeyMans with all data rather than loaded progressively by achow101)
  • #25722 (refactor: Use util::Result class for wallet loading by ryanofsky)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

LLM Linter (✨ experimental)

Possible typos and grammar issues:

  • std::nullptr -> nullptr [std::nullptr is not valid; the correct null pointer literal is nullptr. This appears in two added docs ("CreateNew" and "LoadExisting").]

2026-02-04 21:40:44

Previously would use global `CLIENT_VERSION` no matter what, but this is
one sense a refactor since all of the places where WriteVersion is
called currently call it with `CLIENT_VERSION` anyways. The
`client_version` argument is kept since future test code may want to
write other versions.

Addresses a review comment from bitcoin#32636:

bitcoin#32636 (comment)
@davidgumberg
davidgumberg force-pushed the 2026-02-02-create-load-refactor-followup branch from cdae75b to fedcd46 Compare February 4, 2026 21:40
@davidgumberg
davidgumberg marked this pull request as ready for review February 4, 2026 21:41
@davidgumberg

davidgumberg commented Feb 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Now that #32636 is merged this can be reviewed.

(soft ping @murchandamus, @enirox001, and @rkrux whose review comments are addressed in this PR)

Comment thread src/wallet/wallet.h
Comment on lines +801 to +803
* Pass-through to WalletBatch::LoadWallet() to initialize this CWallet from
* the records stored in CWallet::m_database. Primarily used by
* CWallet::LoadExisting.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I feel that this doesn’t answer why the method exists. I think this decorates LoadExisting with error handling, maybe that could be mentioned.

Comment thread src/wallet/wallet.cpp
}

// Make the local wallet
// Initialize the CWallet for the local wallet.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this comment is obsolete.

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.

Is any comment required here now?

The older comment might have been needed when CWallet::Create was called wherein it was not obvious in the caller whether the wallet would be created or loaded.

Reading CWallet::LoadExisting below seems pretty self explanatory to me.

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

Concept ACK fedcd46

Comment thread src/wallet/wallet.cpp
}

// Make the local wallet
// Initialize the CWallet for the local wallet.

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.

Is any comment required here now?

The older comment might have been needed when CWallet::Create was called wherein it was not obvious in the caller whether the wallet would be created or loaded.

Reading CWallet::LoadExisting below seems pretty self explanatory to me.

Comment thread src/wallet/walletdb.h
//! Write the given client_version.
bool WriteVersion(int client_version) { return m_batch->Write(DBKeys::VERSION, CLIENT_VERSION); }
/**
* Write the given `client_version` to #m_batch, indicating the last version

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.

#m_batch

Typo?

Comment thread src/wallet/wallet.h

/* Initializes, creates and returns a new CWallet; returns a null pointer in case of an error */
/**
* Create a new wallet.

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.

Nit: Can mention it writes stuff to the database.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure exactly what you think would be helpful here, could you be more specific?

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.

- * Create a new wallet.
+ * Create a new wallet and persist in the database. 

So that the reader doesn't assume that the wallet is created only in memory.

I guess the function pre-split influence was still present at the time I mentioned it because for the longest time the reader was not sure if the code was creating (writing to the disk) or loading (reading from the disk) the wallet.

This suggestion can be ignored if the presence of CreateNew name makes it obvious for everyone else.

@DrahtBot DrahtBot removed the CI failed label Feb 9, 2026
@w0xlt

w0xlt commented Feb 19, 2026

Copy link
Copy Markdown
Contributor

Concept ACK

@sedited

sedited commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

@davidgumberg can you address the comments here?

@davidgumberg

Copy link
Copy Markdown
Contributor Author

Looking again, given that the changes in this PR are documentation only I'm not sure it's justified so I'll close.

I apologize to reviewers who took the time to look and give feedback and whose original feedback from #32636 will be left unaddressed, but I think these comments can be improved when this area of the code is touched again, and anything in here is up for grabs.

@pablomartin4btc pablomartin4btc left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ACK ec5d196 wrong PR.

achow101 added a commit that referenced this pull request Aug 18, 2026
ec5d196 wallet: WalletBatch->WriteVersion respect argument. (David Gumberg)

Pull request description:

  > Previously would use global `CLIENT_VERSION` no matter what, but this is one sense a refactor since all of the places where WriteVersion is called currently call it with `CLIENT_VERSION` anyways. The `client_version` argument is kept since future test code may want to write other versions.

  > Addresses a review comment from [#32636](#32636 (comment)):

  This was originally pointed out in #32636 (comment), and the followup (#34490) was never merged. However I think it's confusing to have functions that take arguments but ignore them (and it's dead code), so I've cherry-picked the fix up from #34490.

ACKs for top commit:
  achow101:
    ACK ec5d196
  pablomartin4btc:
    ACK ec5d196
  w0xlt:
    ACK ec5d196

Tree-SHA512: 3ad82d979493ac14704975bef504c791ac72fe7910c25097f0019bf61e3d384b0e1646f90c730d2f655733428b14ccd0196c333df2d6153ff5b55ab41918a6dd
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.

7 participants