-
Notifications
You must be signed in to change notification settings - Fork 38.7k
wallet: GetWalletTx and IsMine require cs_wallet lock #19289
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
Conversation
src/interfaces/wallet.cpp
Outdated
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.
Below IsMine is called for each input and output.
|
Is this a refactor or a bugfix or a potential bugfix? |
|
I'd say refactor. Only change in behavior is that now some races aren't possible, for instance, some import against Edit: well, without this change, if some transaction has multiple inputs/outputs for the same key, and this key is imported concurrently to |
b8282e2 to
20fa4f1
Compare
|
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. |
|
@meshcollider ping. |
20fa4f1 to
d8441f3
Compare
|
Removed 20fa4f1512c85bb967a3cb9edda9f80f46d5b11f to make this a light bug fix. |
meshcollider
left a comment
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 d8441f3
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 d8441f3. This is good. Simple changes that make cs_wallet locks simpler and safer. Left suggestions below, maybe for followups, fine to ignore them here
| nFee = nDebit - nValueOut; | ||
| } | ||
|
|
||
| LOCK(pwallet->cs_wallet); |
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 "wallet: IsMine overloads require cs_wallet lock" (d8441f3)
Maybe with this expanded lock scope. EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) could be added to IsChange(), and that method wouldn't need to lock cs_wallet recursively. Not sure how much extra work that is, however, so maybe it is a suggestion for a followup
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.
Will look into it.
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.
Pushed b8405b8 which touches IsChange and GetChange only.
| if (!InMempool()) return false; | ||
|
|
||
| // Trusted if all inputs are from us and are in the mempool: | ||
| LOCK(pwallet->cs_wallet); |
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 "wallet: GetWalletTx requires cs_wallet lock" (a13cafc)
Adding a lock here doesn't seem like the best thing because this is a recursive function. So code above can run unlocked during the base call but locked during recursive calls, which is confusing and could make it harder to detect bugs.
Maybe instead of locking here, IsTrusted could get an EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) annotation. It seems like IsTrusted is only called a few places, and with cs_wallet already locked, so it wouldn't be a big change.
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.
Good point, will address, thanks!
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.
Done in #19773.
ryanofsky
left a comment
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 b8405b8. Just new commit since last review changing IsChange GetChange locks and adding annotations
|
Code review ACK b8405b8 |
|
Thanks |
… lock b8405b8 wallet: IsChange requires cs_wallet lock (João Barbosa) d8441f3 wallet: IsMine overloads require cs_wallet lock (João Barbosa) a13cafc wallet: GetWalletTx requires cs_wallet lock (João Barbosa) Pull request description: This change removes some unlock/lock and lock/lock cases regarding `GetWalletTx` and `IsMine` overloads. ACKs for top commit: laanwj: Code review ACK b8405b8 ryanofsky: Code review ACK b8405b8. Just new commit since last review changing IsChange GetChange locks and adding annotations Tree-SHA512: 40d37c4fe5d10a1407f57d899d5822bb285633d8dbfad8afcf15a9b41b428ed9971a9a7b1aae84318371155132df3002699a15dab56e004527d50c889829187d
Summary: PR description: > This change removes some unlock/lock and lock/lock cases regarding GetWalletTx and IsMine overloads. This is a backport of [[bitcoin/bitcoin#19289 | core#19289]] [1/3] bitcoin/bitcoin@a13cafc Test Plan: With TSAN: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D10095
Summary: This is a backport of [[bitcoin/bitcoin#19289 | core#19289]] [2/3] bitcoin/bitcoin@d8441f3 Depends on D10095 Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Subscribers: Fabien Differential Revision: https://reviews.bitcoinabc.org/D10096
This change removes some unlock/lock and lock/lock cases regarding
GetWalletTxandIsMineoverloads.