8000 wallet, bench: Move commonly used functions to their own file and fix a bug by achow101 · Pull Request #27666 · bitcoin/bitcoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

wallet, bench: Move commonly used functions to their own file and fix a bug #27666

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

Merged
merged 3 commits into from
May 30, 2023

Conversation

achow101
Copy link
Member

I have a few PRs and branches that use these two commits, probably makes sense to split them into a separate PR to be merged sooner.

The first commit contains some things that end up being commonly used in new wallet benchmarks. These are moved into wallet_common.{h/cpp}.

The second commit contains a bugfix for the wallet_balance benchmark where it calls LoadWallet in the wrong place. It's unnecessary to call that function in this benchmark. Although this does not cause any issues currently, it ends up causing issues in some PRs and branches that I'm working on.

@DrahtBot
Copy link
Contributor
DrahtBot commented May 15, 2023

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
ACK furszy, Sjors
Concept ACK fanquake

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

Conflicts

No conflicts as of last run.

Comment on lines 14 to 17
NotifyWalletLoaded(context, wallet);
if (context.chain) {
wallet->postInitProcess();
}
Copy link
Member

Choose a reason for hiding this comment

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

little topic:
it seems odd to re-use this two calls in other bench contexts.

NotifyWalletLoaded is looping over the wallet load callbacks, and postInitProcess syncs the wallet with the mempool, so guess that both will be no-op in most cases?.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I think they'll be no-op for the most part.

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.

Code ACK, small last topic:

Seems that BenchLoadWallet and BenchUnloadWallet are similar to TestLoadWallet and TestUnloadWallet from wallet_tests.cpp . The only diff seems to be in the db.

Maybe instead of creating a new file, we could move the bench functions to wallet/test/util.h and wallet/test/util.cpp so they are used equally for tests and benchmarks?

@achow101
Copy link
Member Author

Maybe instead of creating a new file, we could move the bench functions to wallet/test/util.h and wallet/test/util.cpp so they are used equally for tests and benchmarks?

Good point, made that change.

It required a few changes to the CreateWallet test since that wasn't expecting postInitProcess to be run, but should be straightforward to review.

achow101 added 3 commits May 25, 2023 14:40
The wallet tests and benchmarks both had helper functions for loading
and unloading the wallet for the test that were almost identical.
These functions are consolidated and reused.
This static address is usable for other wallet tests and benchmarks, so
make it available to them.
The WalletBalance benchmarks would incorrectly call LoadWallet after the
wallet has been setup. LoadWallet expects to be the first thing that is
called and for the CWallet to be in a fresh state. When it is not, it
results in bogus pointers which can cause segfaults during this
benchmark.
@achow101 achow101 force-pushed the wallet-bench-refactor branch from 8fa0111 to 7379a54 Compare May 25, 2023 18:40
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 7379a54

BOOST_CHECK_EQUAL(addtx_count, 2);
// Since mempool transactions are requested at the end of loading, there will
// be 2 additional AddToWallet calls, one from the previous test, and a duplicate for mempool_tx
BOOST_CHECK_EQUAL(addtx_count, 2 + 2);
Copy link
Member
@furszy furszy May 30, 2023

Choose a reason for hiding this comment

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

Not for this PR as it touches the wallet internals but the duplicated AddToWallet calls shouldn't be needed if the wallet wtx state is equal to the one in the event (e.g. TxStateInMempool).

@fanquake fanquake requested review from Sjors and josibake May 30, 2023 13:48
@fanquake
Copy link
Member

@furszy looks like you ACK'd the wrong commit here.

@furszy
Copy link
Member
furszy commented May 30, 2023

oops, fixed. That was the one from the comment. Thanks @fanquake.

@Sjors
Copy link
Member
Sjors commented May 30, 2023

utACK 7379a54

@DrahtBot DrahtBot removed the request for review from Sjors May 30, 2023 14:57
@fanquake fanquake merged commit 05ec664 into bitcoin:master May 30, 2023
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 30, 2023
…heir own file and fix a bug

7379a54 bench: Remove incorrect LoadWallet call in WalletBalance (Andrew Chow)
846b2fe tests: Move ADDRESS_BCRT1_UNSPENDABLE to wallet/test/util.h (Andrew Chow)
c61d3f0 tests, bench: Consolidate {Test,Bench}Un/LoadWallet helper (Andrew Chow)

Pull request description:

  I have a few PRs and branches that use these two commits, probably makes sense to split them into a separate PR to be merged sooner.

  The first commit contains some things that end up being commonly used in new wallet benchmarks. These are moved into `wallet_common.{h/cpp}`.

  The second commit contains a bugfix for the wallet_balance benchmark where it calls `LoadWallet` in the wrong place. It's unnecessary to call that function in this benchmark. Although this does not cause any issues currently, it ends up causing issues in some PRs and branches that I'm working on.

ACKs for top commit:
  Sjors:
    utACK 7379a54
  furszy:
    ACK 7379a54

Tree-SHA512: 47773887a16c69ac7121c699d3446a8c399bd792a6a31714998b7b7a19fea179c6d3b29cb898b04397b2962c1b4120d57009352b8460b8283e188d4cb480c9ba
fanquake added a commit that referenced this pull request Dec 12, 2023
…g called in the wrong places

bd7f5d3 wallet: Assert that the wallet is not initialized in LoadWallet (Andrew Chow)
fb0b6ca tests, bench: Remove incorrect LoadWallet() calls (Andrew Chow)

Pull request description:

  `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

ACKs for top commit:
  S3RK:
    ACK bd7f5d3
  furszy:
    ACK bd7f5d3

Tree-SHA512: 7664f12b8452994e7fc4d7d4f77697fb5f75edb0dba95ba99a4a23ec03d5b8e0ecbdcb7635547a0e8b4f89f708f98dcb5d039df0559e24b1ae411ed630e16e14
@bitcoin bitcoin locked and limited conversation to collaborators May 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0