-
Notifications
You must be signed in to change notification settings - Fork 36.6k
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
refactor: split CWallet::Create #20773
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
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. |
78ad825
to
0f4d56d
Compare
0f4d56d
to
9b57578
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice PR! This helps more clearly separate CWallet creation from syncing so duplicate wallet tool code can be removed without changing behavior. Would suggest a few changes, though:
-
It would be good to squash 5th commit into 1st commit. No need to add a method and enum in one commit and then change the signature and drop the enum right after.
-
I think 4th and 7th commits should probably be dropped, but see specific comments below.
Reviewed:
- 4398236 refactor: Add CWallet:::AttachChain method (1/7)
- b528485 refactor: Track first run state in CWallet (2/7)
- b20c1e5 refactor: Handle first run in CWallet::AttachChain (3/7)
- eabcd95 refactor: Move chain checks into CWallet::AttachChain (4/7)
- 847588a refactor: Update CWallet::AttachChain signature (5/7)
- 190317a CWallet::Create move chain init message up into calling code (6/7)
- 9b57578 CWallet::Create move CWallet::AttachChain up into calling code (7/7)
@@ -3955,11 +3955,6 @@ std::shared_ptr<CWallet> CWallet::Create(interfaces::Chain& chain, const std::st | |||
_("This is the transaction fee you will pay if you send a transaction.")); | |||
} | |||
walletInstance->m_pay_tx_fee = CFeeRate(nFeePerK, 1000); | |||
if (walletInstance->m_pay_tx_fee < chain.relayMinFee()) { | |||
error = strprintf(_("Invalid amount for -paytxfee=<amount>: '%s' (must be at least %s)"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "refactor: Move chain checks into CWallet::AttachChain" (eabcd95)
I think this commit is not an improvement and that it would be better to drop. Safer and clearer to check these values for errors early as they are initialized, than to initialize one place and do checking later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in a general comment below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "refactor: Move chain checks into CWallet::AttachChain" (88f1982)
I still think this commit is not an improvement and should be dropped because it makes the already complicated handling of these fee options and errors more complicated and less transparent. Instead of handling the settings in one place in Create
, it splits up handling between two functions Create
and AttachChain
, when the code doesn't actually have anything to do with attaching to the chain. It is true that this code currently depends on some chain methods. But this should be fixed in the future by making the chain object less monolithic and by improving options handling in general.
I understand the motivation for this commit which is stated at #20773 (comment) and is basically to help implement the subsequent commit "wallet: make chain optional for CWallet::Create" (37b55f3).
But I don't think a good way to make the chain optional is to move these checks to an unrelated place where they don't belong. The simplest and clearest way to make the chain optional for now is simply to skip these checks if the chain pointer is null. And in the future, these checks can be updated to not use the chain interface at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm... thanks for mentioning that the dependency on the chain is accidental. I didn't look deep into it before.
I'm much more happy to drop that commit now, but should we explore other options as well?
It looks like we're just comparing one arg against other args. paytxfee and maxtxfee against minRelayFee
, plus minRelayFee
against some constant. There should be a better place for those checks rather than wallet creation code. I'm not familiar with the codebase enough to say where it belongs.
@ryanofsky and @fjahr could you help me locate a better place for those checks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ryanofsky and @fjahr could you help me locate a better place for those checks?
I think the checks are in a good place. Good to validate settings in the same place where they are parsed. There are just other ways this code could access ::minRelayTxFee
value other than by calling a chain method. It could passed as a create option or be part of a different struct or interface. Simply changing the check to if (chain && walletInstance->m_pay_tx_fee < chain->relayMinFee())
seems good for now though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And in the future, these checks can be updated to not use the chain interface at all.
For the chain
topic this seems a good solution going forward.
Otherwise, I am not sure why you are interested in moving this code. These are checks that can make the wallet creation process fail or at least print a warning. So this seems to be a good place for it. Fee options are part of the wallet "world". Maybe the confusion is because these are config options and not args of createwallet
? Or you don't see the direct connection between fee options and the wallet? These options are only relevant to the wallet and thus are only checked once the user wants to create a wallet because only then weird numbers there can be dangerous for the user.
On a smaller, organizational scale some of these checks could probably be helper functions and overall the fee part of wallet create can probably be encapsulated similar to AttachChain
. If, however, you want to challenge that fee checks are done at all during wallet creation, that would require a lot more conceptual discussion. After that conceptual discussion, there could be a decision on where to put it. But the chances of a significant change in this regard are slim because this would be a huge behavior change I think, potentially breaking compatibility with any program that uses the wallet because these options will need to be set and checked in some kind of way.
Just some first thoughts by someone also not very familiar with the codebase :) If you have ideas or want to challenge this in general as I teased above I would recommend you to bring that as a topic to one of the next wallet IRC meetings, this Friday for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the confusion is because these are config options and not args of createwallet?
yes, and
and thus are only checked once the user wants to create a wallet.
Shouldn't we check them earlier? They are from the wallet "world" but have nothing to do with the wallet creation. Especially chain.relayMinFee().GetFeePerK() > HIGH_TX_FEE_PER_KB
. It seems just a coincidence that the option parsing is done during wallet creation process.
Nevermind, I've dropped the commit. Thanks for your time and patience.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we check them earlier? They are from the wallet "world" but have nothing to do with the wallet creation.
Yes, these settings could be WalletContext
members and shared across multiple CWallet
instances instead of being CWallet
members. (Or maybe if we want keep these as global settings but allow individual wallet overrides they could be members of both CWallet
and WalletContext
, with CWallet
copying the WalletContext
values on construction.) There's a general issue about wallet setting in #13044 for background & discussion about these things. And #19101 is another PR moving more variables to WalletContext
.
My only reason for wanting to drop the commit is wanting to keep options parsing and option validation code together. I wouldn't want to move the checks without also moving the IsArgSet
/GetArg
code they are a part of. But all of this code could run before wallet creation if settings were stored outside CWallet
in a place like WalletContext
.
Especially
chain.relayMinFee().GetFeePerK() > HIGH_TX_FEE_PER_KB
. It seems just a coincidence that the option parsing is done during wallet creation process.
I'm not sure. This is also a warning passed back to the loadwallet
and createwallet
RPCs. It seems like a reasonable thing to warn user about when they are loading a wallet, but maybe it could happen at another time. It's more of a UX question than a code organization question, I think.
9b57578
to
a481665
Compare
@ryanofsky greatly appreciate your review.
I squashed handling first run and changing signature commits into adding
I believe it's good to discuss a bit the design and future of I'd like to know what do you think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK a481665. Overall is this is a very good change, but I'd still encourage dropping the 3th and 5th commits (or moving them to another PR where they can be better motivated). I think they complicate things unnecessarily and are based on an incorrect assumption.
- 6f8b907 refactor: Track first run state in CWallet (1/5)
- 2a9fbc4 refactor: Add CWallet:::AttachChain method (2/5)
- a888db2 refactor: Move chain checks into CWallet::AttachChain (3/5)
- 2b77279 CWallet::Create move chain init message up into calling code (4/5)
- a481665 CWallet::Create move CWallet::AttachChain up into calling code (5/5)
I believe it's good to discuss a bit the design and future of
CWallet
before moving forward. I made those changes based on the following assumptions:
A) a wallet instance is not dependent on a chain object and could exist without a chain
B) a wallet instance could be later attached to a chain if required
Those assumption are based on my observation of thewallet tool
which operates completely "offline". In my opinion this provides nice and clear wallet lifecycle and delineation of concerns. Thus we would removechain
argument fromCWallet
ctr andCreate
methods in the future. It would require changing how tx are loaded, but I think it's doable and would simplify the code.I'd like to know what do you think.
This is well put. Basically I just think the second assumption is wrong and complicates things unnecessarily. The only change we need to make to remove duplicate code in wallet tool is to tweak the wallet create function to take a null chain and stop requiring a non-null chain. There's no need to allow a different chain to be swapped in after the wallet is created.
Trying to separate creation from loading seems like all cost and no benefit. Callers have to do more work, settings parsing gets separated from settings validation, and the benefit is __? Maybe there could be a benefit in a future PR, but the 3rd and 5th commits seem a bit messy and out of place here to me. I don't think they cause much harm though, so if you really think they improve things then please do keep them! Thanks for working on this!
EDIT: Fixed references to 3rd and 5th commits instead of 4th and 5th commits
ISTM there are 5 main components of What I had envisioned for splitting up I agree with @ryanofsky that the assumption that changing the attached chain later is incorrect. I don't think it makes sense that the wallet would want to be able to change to a new chain after being initialized. However it does make sense that we would want to create a wallet with no chain for the offline mode stuff. |
a481665
to
f71618c
Compare
Thanks ryanofsky and achow101, I have a better understanding now and adjusted my PR accordingly:
I kept the 3rd commit which moves chain related checks to Thanks for your reviews, I'm more satisfied with how this PR looks right now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK f71618c. Looks very good and thanks again! I still think commit 3 "refactor: Move chain checks into CWallet::AttachChain" (fcf56ee) is a little worse for code organization and error handling and would be better to drop, but it seems fine to keep if you just prefer it or think having fewer null chain checks justifies it.
Changes since last review: tweaking AttachChain call in second commit to fix interim compile error, replacing last commit with new commit making CWallet::Create chain argument optional & adding test case for this invocation.
Would encourage other reviewers to review this. No behavior is changing here, just a big clumsy Create function being broken up and made more sane.
This commit just moves code without making any changes. It can be reviewed with `git log -p -n1 --color-moved=dimmed_zebra` Motivation for this change is to make wallet.cpp/h less monolithic and start to make wallet transaction state tracking comprehensible so bugs in https://github.com/bitcoin-core/bitcoin-devwiki/wiki/Wallet-Transaction-Conflict-Tracking can be fixed safely without introducing new problems. This commit moves wallet classes and methods that deal with transactions out of wallet.cpp/.h into better organized files: - transaction.cpp/.h - CWalletTx and CMerkleTX class definitions - receive.cpp/.h - functions checking received transactions and computing balances - spend.cpp/.h - functions creating transactions and finding spendable coins After bitcoin#20773, when loading is separated from syncing it will also be possible to move more wallet.cpp/.h functions to: - sync.cpp/.h - functions handling chain notifications and rescanning This commit arranges receive.cpp and spend.cpp functions in dependency order so it's possible to skim receive.cpp and get an idea of how computing balances works, and skim spend.cpp and get an idea of how transactions are created, without having to jump all over wallet.cpp where functions are not in order and there is a lot of unrelated uncode. Followup commit "refactor: Detach wallet transaction methods" in pr/txstate follows up this PR and tweaks function names and arguments to reflect new locations. The two commits are split into separate PRs because this commit is more work to maintain and less work to review, while the other commit is less work to maintain and more work to review, so hopefully this commit can be merged earlier.
This commit just moves code without making any changes. It can be reviewed with `git log -p -n1 --color-moved=dimmed_zebra` Motivation for this change is to make wallet.cpp/h less monolithic and start to make wallet transaction state tracking comprehensible so bugs in https://github.com/bitcoin-core/bitcoin-devwiki/wiki/Wallet-Transaction-Conflict-Tracking can be fixed safely without introducing new problems. This commit moves wallet classes and methods that deal with transactions out of wallet.cpp/.h into better organized files: - transaction.cpp/.h - CWalletTx and CMerkleTX class definitions - receive.cpp/.h - functions checking received transactions and computing balances - spend.cpp/.h - functions creating transactions and finding spendable coins After bitcoin#20773, when loading is separated from syncing it will also be possible to move more wallet.cpp/.h functions to: - sync.cpp/.h - functions handling chain notifications and rescanning This commit arranges receive.cpp and spend.cpp functions in dependency order so it's possible to skim receive.cpp and get an idea of how computing balances works, and skim spend.cpp and get an idea of how transactions are created, without having to jump all over wallet.cpp where functions are not in order and there is a lot of unrelated uncode. Followup commit "refactor: Detach wallet transaction methods" in bitcoin#21206 follows up this PR and tweaks function names and arguments to reflect new locations. The two commits are split into separate PRs because this commit is more work to maintain and less work to review, while the other commit is less work to maintain and more work to review, so hopefully this commit can be merged earlier.
This commit just moves code without making any changes. It can be reviewed with `git log -p -n1 --color-moved=dimmed_zebra` Motivation for this change is to make wallet.cpp/h less monolithic and start to make wallet transaction state tracking comprehensible so bugs in https://github.com/bitcoin-core/bitcoin-devwiki/wiki/Wallet-Transaction-Conflict-Tracking can be fixed safely without introducing new problems. This commit moves wallet classes and methods that deal with transactions out of wallet.cpp/.h into better organized files: - transaction.cpp/.h - CWalletTx and CMerkleTX class definitions - receive.cpp/.h - functions checking received transactions and computing balances - spend.cpp/.h - functions creating transactions and finding spendable coins After bitcoin#20773, when loading is separated from syncing it will also be possible to move more wallet.cpp/.h functions to: - sync.cpp/.h - functions handling chain notifications and rescanning This commit arranges receive.cpp and spend.cpp functions in dependency order so it's possible to skim receive.cpp and get an idea of how computing balances works, and skim spend.cpp and get an idea of how transactions are created, without having to jump all over wallet.cpp where functions are not in order and there is a lot of unrelated uncode. Followup commit "refactor: Detach wallet transaction methods" in bitcoin#21206 follows up this PR and tweaks function names and arguments to reflect new locations. The two commits are split into separate PRs because this commit is more work to maintain and less work to review, while the other commit is less work to maintain and more work to review, so hopefully this commit can be merged earlier.
This commit just moves functions without making any changes. It can be reviewed with `git log -p -n1 --color-moved=dimmed_zebra` Motivation for this change is to make wallet.cpp/h less monolithic and start to make wallet transaction state tracking comprehensible so bugs in https://github.com/bitcoin-core/bitcoin-devwiki/wiki/Wallet-Transaction-Conflict-Tracking can be fixed safely without introducing new problems. This commit moves wallet classes and methods that deal with transactions out of wallet.cpp/.h into better organized files: - transaction.cpp/.h - CWalletTx and CMerkleTx class definitions - receive.cpp/.h - functions checking received transactions and computing balances - spend.cpp/.h - functions creating transactions and finding spendable coins After bitcoin#20773, when loading is separated from syncing it will also be possible to move more wallet.cpp/.h functions to: - sync.cpp/.h - functions handling chain notifications and rescanning This commit arranges receive.cpp and spend.cpp functions in dependency order so it's possible to skim receive.cpp and get an idea of how computing balances works, and skim spend.cpp and get an idea of how transactions are created, without having to jump all over wallet.cpp where functions are not in order and there is a lot of unrelated code. Followup commit "refactor: Detach wallet transaction methods" in bitcoin#21206 follows up this PR and tweaks function names and arguments to reflect new locations. The two commits are split into separate PRs because this commit is more work to maintain and less work to review, while the other commit is less work to maintain and more work to review, so hopefully this commit can be merged earlier.
f71618c
to
0d6f367
Compare
This commit just moves functions without making any changes. It can be reviewed with `git log -p -n1 --color-moved=dimmed_zebra` Motivation for this change is to make wallet.cpp/h less monolithic and start to make wallet transaction state tracking comprehensible so bugs in https://github.com/bitcoin-core/bitcoin-devwiki/wiki/Wallet-Transaction-Conflict-Tracking can be fixed safely without introducing new problems. This commit moves wallet classes and methods that deal with transactions out of wallet.cpp/.h into better organized files: - transaction.cpp/.h - CWalletTx and CMerkleTx class definitions - receive.cpp/.h - functions checking received transactions and computing balances - spend.cpp/.h - functions creating transactions and finding spendable coins After bitcoin#20773, when loading is separated from syncing it will also be possible to move more wallet.cpp/.h functions to: - sync.cpp/.h - functions handling chain notifications and rescanning This commit arranges receive.cpp and spend.cpp functions in dependency order so it's possible to skim receive.cpp and get an idea of how computing balances works, and skim spend.cpp and get an idea of how transactions are created, without having to jump all over wallet.cpp where functions are not in order and there is a lot of unrelated code. Followup commit "refactor: Detach wallet transaction methods" in bitcoin#21206 follows up this PR and tweaks function names and arguments to reflect new locations. The two commits are split into separate PRs because this commit is more work to maintain and less work to review, while the other commit is less work to maintain and more work to review, so hopefully this commit can be merged earlier.
84980ae
to
37b55f3
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK 37b55f3
I agree with @ryanofsky that the 3rd commit should be dropped but it's not a blocker.
Code Review ACK 37b55f3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK 37b55f3. I still would really like to drop the third commit "refactor: Move chain checks into CWallet::AttachChain" 88f1982 (see reasoning and suggested alternative below), but I think this PR is great overall and all the other parts are a lot more significant than the one questionable commit.
Changes since last review: rebase due to conflicts, cleverly dropping m_first_run while still dropping first_run output arguments, adding assert to make sure AttachChain is called correctly, tweaking AttachChain signature
{ | ||
LOCK(walletInstance->cs_wallet); | ||
// allow setting the chain if it hasn't been set already but prevent changing it | ||
assert(!walletInstance->m_chain || walletInstance->m_chain == &chain); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "refactor: Add CWallet:::AttachChain method" (491feef)
Not very important but I wonder if you could drop the || walletInstance->m_chain == &chain
condition. It seems like it would be a bug to call attachchain more than once, even with the same chain pointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m_chain
is initialized in the CWallet ctr. I've tried to drop it originally, but there were some issues, so I decided to leave it for the follow up.
@@ -3955,11 +3955,6 @@ std::shared_ptr<CWallet> CWallet::Create(interfaces::Chain& chain, const std::st | |||
_("This is the transaction fee you will pay if you send a transaction.")); | |||
} | |||
walletInstance->m_pay_tx_fee = CFeeRate(nFeePerK, 1000); | |||
if (walletInstance->m_pay_tx_fee < chain.relayMinFee()) { | |||
error = strprintf(_("Invalid amount for -paytxfee=<amount>: '%s' (must be at least %s)"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "refactor: Move chain checks into CWallet::AttachChain" (88f1982)
I still think this commit is not an improvement and should be dropped because it makes the already complicated handling of these fee options and errors more complicated and less transparent. Instead of handling the settings in one place in Create
, it splits up handling between two functions Create
and AttachChain
, when the code doesn't actually have anything to do with attaching to the chain. It is true that this code currently depends on some chain methods. But this should be fixed in the future by making the chain object less monolithic and by improving options handling in general.
I understand the motivation for this commit which is stated at #20773 (comment) and is basically to help implement the subsequent commit "wallet: make chain optional for CWallet::Create" (37b55f3).
But I don't think a good way to make the chain optional is to move these checks to an unrelated place where they don't belong. The simplest and clearest way to make the chain optional for now is simply to skip these checks if the chain pointer is null. And in the future, these checks can be updated to not use the chain interface at all.
This commit does not change behavior, it just moves code from CWallet::CreateWalletFromFile to CWallet:::AttachChain so it can be updated in the next commit. This commit is most easily reviewed with "git diff -w --color-moved=dimmed_zebra" or by diffing CWallet:::AttachChain against the previous code with an external diff tool.
37b55f3
to
489ebb7
Compare
I've dropped "refactor: Move chain checks into CWallet::AttachChain" (88f1982) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK 489ebb7. Only changes since last review were adding a const variable declaration, and implementing suggestion not to move feerate option checks to AttachChain. Thanks for updates and fast responses!
This commit just moves functions without making any changes. It can be reviewed with `git log -p -n1 --color-moved=dimmed_zebra` Motivation for this change is to make wallet.cpp/h less monolithic and start to make wallet transaction state tracking comprehensible so bugs in https://github.com/bitcoin-core/bitcoin-devwiki/wiki/Wallet-Transaction-Conflict-Tracking can be fixed safely without introducing new problems. This commit moves wallet classes and methods that deal with transactions out of wallet.cpp/.h into better organized files: - transaction.cpp/.h - CWalletTx and CMerkleTx class definitions - receive.cpp/.h - functions checking received transactions and computing balances - spend.cpp/.h - functions creating transactions and finding spendable coins After bitcoin#20773, when loading is separated from syncing it will also be possible to move more wallet.cpp/.h functions to: - sync.cpp/.h - functions handling chain notifications and rescanning This commit arranges receive.cpp and spend.cpp functions in dependency order so it's possible to skim receive.cpp and get an idea of how computing balances works, and skim spend.cpp and get an idea of how transactions are created, without having to jump all over wallet.cpp where functions are not in order and there is a lot of unrelated code. Followup commit "refactor: Detach wallet transaction methods" in bitcoin#21206 follows up this PR and tweaks function names and arguments to reflect new locations. The two commits are split into separate PRs because this commit is more work to maintain and less work to review, while the other commit is less work to maintain and more work to review, so hopefully this commit can be merged earlier.
This commit just moves functions without making any changes. It can be reviewed with `git log -p -n1 --color-moved=dimmed_zebra` Motivation for this change is to make wallet.cpp/h less monolithic and start to make wallet transaction state tracking comprehensible so bugs in https://github.com/bitcoin-core/bitcoin-devwiki/wiki/Wallet-Transaction-Conflict-Tracking can be fixed safely without introducing new problems. This commit moves wallet classes and methods that deal with transactions out of wallet.cpp/.h into better organized files: - transaction.cpp/.h - CWalletTx and CMerkleTx class definitions - receive.cpp/.h - functions checking received transactions and computing balances - spend.cpp/.h - functions creating transactions and finding spendable coins After bitcoin#20773, when loading is separated from syncing it will also be possible to move more wallet.cpp/.h functions to: - sync.cpp/.h - functions handling chain notifications and rescanning This commit arranges receive.cpp and spend.cpp functions in dependency order so it's possible to skim receive.cpp and get an idea of how computing balances works, and skim spend.cpp and get an idea of how transactions are created, without having to jump all over wallet.cpp where functions are not in order and there is a lot of unrelated code. Followup commit "refactor: Detach wallet transaction methods" in bitcoin#21206 follows up this PR and tweaks function names and arguments to reflect new locations. The two commits are split into separate PRs because this commit is more work to maintain and less work to review, while the other commit is less work to maintain and more work to review, so hopefully this commit can be merged earlier.
This commit just moves functions without making any changes. It can be reviewed with `git log -p -n1 --color-moved=dimmed_zebra` Motivation for this change is to make wallet.cpp/h less monolithic and start to make wallet transaction state tracking comprehensible so bugs in https://github.com/bitcoin-core/bitcoin-devwiki/wiki/Wallet-Transaction-Conflict-Tracking can be fixed safely without introducing new problems. This commit moves wallet classes and methods that deal with transactions out of wallet.cpp/.h into better organized files: - transaction.cpp/.h - CWalletTx and CMerkleTx class definitions - receive.cpp/.h - functions checking received transactions and computing balances - spend.cpp/.h - functions creating transactions and finding spendable coins After bitcoin#20773, when loading is separated from syncing it will also be possible to move more wallet.cpp/.h functions to: - sync.cpp/.h - functions handling chain notifications and rescanning This commit arranges receive.cpp and spend.cpp functions in dependency order so it's possible to skim receive.cpp and get an idea of how computing balances works, and skim spend.cpp and get an idea of how transactions are created, without having to jump all over wallet.cpp where functions are not in order and there is a lot of unrelated code. Followup commit "refactor: Detach wallet transaction methods" in bitcoin#21206 follows up this PR and tweaks function names and arguments to reflect new locations. The two commits are split into separate PRs because this commit is more work to maintain and less work to review, while the other commit is less work to maintain and more work to review, so hopefully this commit can be merged earlier.
This commit just moves functions without making any changes. It can be reviewed with `git log -p -n1 --color-moved=dimmed_zebra` Motivation for this change is to make wallet.cpp/h less monolithic and start to make wallet transaction state tracking comprehensible so bugs in https://github.com/bitcoin-core/bitcoin-devwiki/wiki/Wallet-Transaction-Conflict-Tracking can be fixed safely without introducing new problems. This commit moves wallet classes and methods that deal with transactions out of wallet.cpp/.h into better organized files: - transaction.cpp/.h - CWalletTx and CMerkleTx class definitions - receive.cpp/.h - functions checking received transactions and computing balances - spend.cpp/.h - functions creating transactions and finding spendable coins After bitcoin#20773, when loading is separated from syncing it will also be possible to move more wallet.cpp/.h functions to: - sync.cpp/.h - functions handling chain notifications and rescanning This commit arranges receive.cpp and spend.cpp functions in dependency order so it's possible to skim receive.cpp and get an idea of how computing balances works, and skim spend.cpp and get an idea of how transactions are created, without having to jump all over wallet.cpp where functions are not in order and there is a lot of unrelated code. Followup commit "refactor: Detach wallet transaction methods" in bitcoin#21206 follows up this PR and tweaks function names and arguments to reflect new locations. The two commits are split into separate PRs because this commit is more work to maintain and less work to review, while the other commit is less work to maintain and more work to review, so hopefully this commit can be merged earlier.
This commit just moves functions without making any changes. It can be reviewed with `git log -p -n1 --color-moved=dimmed_zebra` Motivation for this change is to make wallet.cpp/h less monolithic and start to make wallet transaction state tracking comprehensible so bugs in https://github.com/bitcoin-core/bitcoin-devwiki/wiki/Wallet-Transaction-Conflict-Tracking can be fixed safely without introducing new problems. This commit moves wallet classes and methods that deal with transactions out of wallet.cpp/.h into better organized files: - transaction.cpp/.h - CWalletTx and CMerkleTx class definitions - receive.cpp/.h - functions checking received transactions and computing balances - spend.cpp/.h - functions creating transactions and finding spendable coins After bitcoin#20773, when loading is separated from syncing it will also be possible to move more wallet.cpp/.h functions to: - sync.cpp/.h - functions handling chain notifications and rescanning This commit arranges receive.cpp and spend.cpp functions in dependency order so it's possible to skim receive.cpp and get an idea of how computing balances works, and skim spend.cpp and get an idea of how transactions are created, without having to jump all over wallet.cpp where functions are not in order and there is a lot of unrelated code. Followup commit "refactor: Detach wallet transaction methods" in bitcoin#21206 follows up this PR and tweaks function names and arguments to reflect new locations. The two commits are split into separate PRs because this commit is more work to maintain and less work to review, while the other commit is less work to maintain and more work to review, so hopefully this commit can be merged earlier.
This commit just moves functions without making any changes. It can be reviewed with `git log -p -n1 --color-moved=dimmed_zebra` Motivation for this change is to make wallet.cpp/h less monolithic and start to make wallet transaction state tracking comprehensible so bugs in https://github.com/bitcoin-core/bitcoin-devwiki/wiki/Wallet-Transaction-Conflict-Tracking can be fixed safely without introducing new problems. This commit moves wallet classes and methods that deal with transactions out of wallet.cpp/.h into better organized files: - transaction.cpp/.h - CWalletTx and CMerkleTx class definitions - receive.cpp/.h - functions checking received transactions and computing balances - spend.cpp/.h - functions creating transactions and finding spendable coins After bitcoin#20773, when loading is separated from syncing it will also be possible to move more wallet.cpp/.h functions to: - sync.cpp/.h - functions handling chain notifications and rescanning This commit arranges receive.cpp and spend.cpp functions in dependency order so it's possible to skim receive.cpp and get an idea of how computing balances works, and skim spend.cpp and get an idea of how transactions are created, without having to jump all over wallet.cpp where functions are not in order and there is a lot of unrelated code. Followup commit "refactor: Detach wallet transaction methods" in bitcoin#21206 follows up this PR and tweaks function names and arguments to reflect new locations. The two commits are split into separate PRs because this commit is more work to maintain and less work to review, while the other commit is less work to maintain and more work to review, so hopefully this commit can be merged earlier.
c7bd584 MOVEONLY: CWallet transaction code out of wallet.cpp/.h (Russell Yanofsky) Pull request description: This commit just moves function without making any changes. It can be reviewed with `git log -p -n1 --color-moved=dimmed_zebra` Motivation for this change is to make `wallet.cpp/h` less monolithic and start to make wallet transaction state tracking comprehensible so bugs in https://github.com/bitcoin-core/bitcoin-devwiki/wiki/Wallet-Transaction-Conflict-Tracking can be fixed safely without introducing new problems. This moves wallet classes and methods that deal with transactions out of `wallet.cpp/.h` into better organized files: - `transaction.cpp/.h` - CWalletTx and CMerkleTx class definitions - `receive.cpp/.h` - functions checking received transactions and computing balances - `spend.cpp/.h` - functions creating transactions and finding spendable coins After #20773, when loading is separated from syncing it will also be possible to move more `wallet.cpp/.h` functions to: - `sync.cpp/.h` - functions handling chain notifications and rescanning This commit arranges `receive.cpp` and `spend.cpp` functions in dependency order so it's possible to skim `receive.cpp` and get an idea of how computing balances works, and skim `spend.cpp` and get an idea of how transactions are created, without having to jump all over `wallet.cpp` where functions are not in order and there is a lot of unrelated code. Followup commit "refactor: Detach wallet transaction methods" in #21206 follows up this PR and tweaks function names and arguments to reflect new locations. The two commits are split into separate PRs because this commit is more work to maintain and less work to review, while the other commit is less work to maintain and more work to review, so hopefully this commit can be merged earlier. ACKs for top commit: Sjors: re-utACK c7bd584 fjahr: utACK c7bd584 promag: Code review ACK c7bd584, verified move only claim. meshcollider: Dimmed-zebra-check and functional test run ACK c7bd584 Tree-SHA512: 4981de6911cb1196774db375494355cc9af59b52456129c002d264a77cd9ed6175f8ecbb6b2f492a59a4d5a0def21a39d96fa79c9f4d99be0992985f553be32f
This commit just moves functions without making any changes. It can be reviewed with `git log -p -n1 --color-moved=dimmed_zebra` Motivation for this change is to make wallet.cpp/h less monolithic and start to make wallet transaction state tracking comprehensible so bugs in https://github.com/bitcoin-core/bitcoin-devwiki/wiki/Wallet-Transaction-Conflict-Tracking can be fixed safely without introducing new problems. This commit moves wallet classes and methods that deal with transactions out of wallet.cpp/.h into better organized files: - transaction.cpp/.h - CWalletTx and CMerkleTx class definitions - receive.cpp/.h - functions checking received transactions and computing balances - spend.cpp/.h - functions creating transactions and finding spendable coins After bitcoin#20773, when loading is separated from syncing it will also be possible to move more wallet.cpp/.h functions to: - sync.cpp/.h - functions handling chain notifications and rescanning This commit arranges receive.cpp and spend.cpp functions in dependency order so it's possible to skim receive.cpp and get an idea of how computing balances works, and skim spend.cpp and get an idea of how transactions are created, without having to jump all over wallet.cpp where functions are not in order and there is a lot of unrelated code. Followup commit "refactor: Detach wallet transaction methods" in bitcoin#21206 follows up this PR and tweaks function names and arguments to reflect new locations. The two commits are split into separate PRs because this commit is more work to maintain and less work to review, while the other commit is less work to maintain and more work to review, so hopefully this commit can be merged earlier.
This is a followup for #20365 (comment)
First part of a refactoring with overall goal to simplify
CWallet
and de-duplicate code withwallettool
Rationale: split
CWallet::Create
and createCWallet::AttachChain
.CWallet::AttachChain
takes chain as first parameter on purpose. In future I suggest we can removechain
fromCWallet
constructor.The second commit is based on be164f9 from #15719 (thanks ryanofsky)
cc ryanofsky achow101