Skip to content

Conversation

@promag
Copy link
Contributor

@promag promag commented Jun 15, 2020

This change removes some unlock/lock and lock/lock cases regarding GetWalletTx and IsMine overloads.

Copy link
Contributor Author

@promag promag Jun 15, 2020

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.

@maflcko
Copy link
Member

maflcko commented Jun 15, 2020

Is this a refactor or a bugfix or a potential bugfix?

@promag
Copy link
Contributor Author

promag commented Jun 16, 2020

I'd say refactor. Only change in behavior is that now some races aren't possible, for instance, some import against MakeWalletTx. But I don't see these as bugfix.

Edit: well, without this change, if some transaction has multiple inputs/outputs for the same key, and this key is imported concurrently to MakeWalletTx, then the resulting WalletTx can be wrong. But this is very unlikely I think.

@promag promag force-pushed the 2020-06-wallet-less-locks branch from b8282e2 to 20fa4f1 Compare June 16, 2020 00:19
@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 16, 2020

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

Conflicts

Reviewers, 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.

@promag
Copy link
Contributor Author

promag commented Jul 14, 2020

@meshcollider ping.

@promag promag force-pushed the 2020-06-wallet-less-locks branch from 20fa4f1 to d8441f3 Compare August 16, 2020 23:06
@promag
Copy link
Contributor Author

promag commented Aug 16, 2020

Removed 20fa4f1512c85bb967a3cb9edda9f80f46d5b11f to make this a light bug fix.

Copy link
Contributor

@meshcollider meshcollider left a 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

Copy link
Contributor

@ryanofsky ryanofsky left a 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);
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will look into it.

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in #19773.

Copy link
Contributor

@ryanofsky ryanofsky left a 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

@fanquake fanquake requested a review from meshcollider August 25, 2020 07:06
@laanwj
Copy link
Member

laanwj commented Aug 27, 2020

Code review ACK b8405b8

@laanwj laanwj merged commit 91af7ef into bitcoin:master Aug 27, 2020
@promag promag deleted the 2020-06-wallet-less-locks branch August 27, 2020 14:26
@promag
Copy link
Contributor Author

promag commented Aug 27, 2020

Thanks

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 28, 2020
… 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
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Sep 14, 2021
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
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Sep 14, 2021
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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants