Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests, bench: Fix issue with CWallet::LoadWallet() being called in the wrong places #29055

Merged
merged 2 commits into from
Dec 12, 2023

Conversation

achow101
Copy link
Member

CWallet::LoadWallet() expects to be called after a CWallet is constructed, but before any of its member functions called. Doing so invalidates pointers which causes issues with some PRs and branches that I am working on. This was being used incorrectly in a few tests and benchmarks, resulting in segfaults.

As a precaution for this kind of issue in the future, I've also added a few asserts to LoadWallet() so that developers will notice when it is used incorrectly.

As similar issue was fixed in #27666

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 11, 2023

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

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK furszy, S3RK

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #27865 (wallet: Track no-longer-spendable TXOs separately by achow101)
  • #27286 (wallet: Keep track of the wallet's own transaction outputs in memory by achow101)

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.

@DrahtBot DrahtBot changed the title tests, bench: Fix issue with CWalelt::LoadWallet() being called in the wrong places tests, bench: Fix issue with CWalelt::LoadWallet() being called in the wrong places Dec 11, 2023
@achow101 achow101 changed the title tests, bench: Fix issue with CWalelt::LoadWallet() being called in the wrong places tests, bench: Fix issue with CWallet::LoadWallet() being called in the wrong places Dec 11, 2023
LoadWallet() must only be called immediately after a CWallet is
constructed, or not at all. Doing so after any other CWallet member
functions have been called may cause pointers and other objects
setup by other those functions to become invalidated.

Since these tests and benchmarks are using completely new wallets with
mock databases, it's not necessary to call LoadWallet() anyways, so
these can be dropped.
LoadWallet() cannot be run after the wallet has been initialized. So
assert that to avoid making this mistake in the future.
Copy link
Member

@furszy furszy left a comment

Choose a reason for hiding this comment

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

ACK bd7f5d3

For a follow-up, we should make CWallet::LoadWallet() private and replace all those calls for CWallet::Create().

@S3RK
Copy link
Contributor

S3RK commented Dec 12, 2023

ACK bd7f5d3

@fanquake fanquake merged commit 60f6773 into bitcoin:master Dec 12, 2023
16 checks passed
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.

None yet

5 participants