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

wallet: LearnRelatedScripts only if KeepDestination #17237

Merged
merged 2 commits into from
Nov 22, 2019

Conversation

promag
Copy link
Contributor

@promag promag commented Oct 24, 2019

Only mutates the wallet if the reserved key is kept.

First commit is a refactor that makes the address type a class member.

The second commit moves LearnRelatedScripts from GetReservedDestination to KeepDestination to avoid an unnecessary call to AddCScript - which in turn prevents multiple entries of the same script in the wallet DB.

@promag promag force-pushed the 2019-10-wallet-reservedestination branch from c2edd41 to d4643bf Compare October 24, 2019 08:50
@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 24, 2019

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #17537 (wallet: Cleanup and move opportunistic and superfluous TopUp()s by achow101)
  • #17526 (Use Single Random Draw In addition to knapsack as coin selection fallback by achow101)
  • #17373 (wallet: Various fixes and cleanup to keypool handling in LegacyScriptPubKeyMan and CWallet by achow101)
  • #17331 (Use effective values throughout coin selection by achow101)
  • #17219 (wallet: allow transaction without change if keypool is empty by Sjors)

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.

@laanwj
Copy link
Member

laanwj commented Oct 24, 2019

Can you elaborate a bit, what the difference is here? Does it fix an issue, or is it just a conceptual refactor?

@promag
Copy link
Contributor Author

promag commented Oct 25, 2019

This is not a refactor, it prevents a call to CWallet::AddCScript if CWallet::CreateTransaction fails for any reason - avoiding multiple entries of the same script in the wallet db.

Updated OP.

I'll see if I can add a test that fails without this change.

@achow101
Copy link
Member

Code review ACK d4643bf

@promag promag force-pushed the 2019-10-wallet-reservedestination branch from d4643bf to ee9fc9b Compare November 1, 2019 23:50
@promag promag force-pushed the 2019-10-wallet-reservedestination branch from ee9fc9b to c108c0d Compare November 2, 2019 00:31
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 3958295. I like this change. The new behavior makes more sense, and the change makes the code clearer, since the current LearnRelatedScripts call is hard to understand and explain. (Personally, I'd like it if this PR were merged before #17373 or that PR was rebased on top of this one so it would be less confusing.)

re: #17237 (comment)

I'll see if I can add a test that fails without this change.

A test would be nice to have either here or in a followup PR. I think we really need to get out of the habit of making behavior changes in the wallet without corresponding test changes. Not having tests is dangerous and also impedes code review because test changes can make it easier to see what code changes are doing.

@achow101
Copy link
Member

Re-ACK 3958295

@ryanofsky
Copy link
Contributor

@Sjors do you want to review this? I'm not sure who else would be familiar

@Sjors
Copy link
Member

Sjors commented Nov 20, 2019

ACK 3958295

A test could, I'll just shamelessly plug #12134 again, create a pre-segwit wallet, open it on master, draft a transaction with a SegWit change address, cancel it, downgrade to pre-segwit bitcoin core wallet, and then check that older wallet version don't see the key. But I don't think that's terribly useful.

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.

utACK 3958295

meshcollider added a commit that referenced this pull request Nov 22, 2019
3958295 wallet: LearnRelatedScripts only if KeepDestination (João Barbosa)
55295fb wallet: Lock address type in ReserveDestination (João Barbosa)

Pull request description:

  Only mutates the wallet if the reserved key is kept.

  First commit is a refactor that makes the address type a class member.

  The second commit moves `LearnRelatedScripts` from `GetReservedDestination` to `KeepDestination` to avoid an unnecessary call to `AddCScript` - which in turn prevents multiple entries of the same script in the wallet DB.

ACKs for top commit:
  achow101:
    Re-ACK 3958295
  Sjors:
    ACK 3958295
  ryanofsky:
    Code review ACK 3958295. I like this change. The new behavior makes more sense, and the change makes the code clearer, since the current LearnRelatedScripts call is hard to understand and explain. (Personally, I'd like it if this PR were merged before #17373 or that PR was rebased on top of this one so it would be less confusing.)
  meshcollider:
    utACK 3958295

Tree-SHA512: 49a5f4b022b28042ad37ea309b28378a3983cb904e234a25795b5a360356652e0f8e60f15e3e64d85094ea63af9be01812d90ccfc08ca4f1dd927fdd8566e33f
@meshcollider meshcollider merged commit 3958295 into bitcoin:master Nov 22, 2019
@promag promag deleted the 2019-10-wallet-reservedestination branch November 22, 2019 20:45
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Nov 22, 2019
3958295 wallet: LearnRelatedScripts only if KeepDestination (João Barbosa)
55295fb wallet: Lock address type in ReserveDestination (João Barbosa)

Pull request description:

  Only mutates the wallet if the reserved key is kept.

  First commit is a refactor that makes the address type a class member.

  The second commit moves `LearnRelatedScripts` from `GetReservedDestination` to `KeepDestination` to avoid an unnecessary call to `AddCScript` - which in turn prevents multiple entries of the same script in the wallet DB.

ACKs for top commit:
  achow101:
    Re-ACK 3958295
  Sjors:
    ACK 3958295
  ryanofsky:
    Code review ACK 3958295. I like this change. The new behavior makes more sense, and the change makes the code clearer, since the current LearnRelatedScripts call is hard to understand and explain. (Personally, I'd like it if this PR were merged before bitcoin#17373 or that PR was rebased on top of this one so it would be less confusing.)
  meshcollider:
    utACK 3958295

Tree-SHA512: 49a5f4b022b28042ad37ea309b28378a3983cb904e234a25795b5a360356652e0f8e60f15e3e64d85094ea63af9be01812d90ccfc08ca4f1dd927fdd8566e33f
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Sep 30, 2020
Summary:
bitcoin/bitcoin@55295fb

Partial backport of Core [[bitcoin/bitcoin#17237 | PR17237]]

Test Plan:
  ninja check check-functional

Reviewers: #bitcoin_abc, jasonbcox, deadalnix

Reviewed By: #bitcoin_abc, jasonbcox, deadalnix

Subscribers: jasonbcox

Differential Revision: https://reviews.bitcoinabc.org/D7689
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 1, 2020
Summary:
bitcoin/bitcoin@3958295

Depends on D7689

Concludes backport of Core [[bitcoin/bitcoin#17237 | PR17237]]

Test Plan:
  ninja check check-functional

Reviewers: #bitcoin_abc, deadalnix, jasonbcox

Reviewed By: #bitcoin_abc, deadalnix, jasonbcox

Subscribers: deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D7690
sidhujag pushed a commit to syscoin-core/syscoin that referenced this pull request Nov 10, 2020
3958295 wallet: LearnRelatedScripts only if KeepDestination (João Barbosa)
55295fb wallet: Lock address type in ReserveDestination (João Barbosa)

Pull request description:

  Only mutates the wallet if the reserved key is kept.

  First commit is a refactor that makes the address type a class member.

  The second commit moves `LearnRelatedScripts` from `GetReservedDestination` to `KeepDestination` to avoid an unnecessary call to `AddCScript` - which in turn prevents multiple entries of the same script in the wallet DB.

ACKs for top commit:
  achow101:
    Re-ACK 3958295
  Sjors:
    ACK 3958295
  ryanofsky:
    Code review ACK 3958295. I like this change. The new behavior makes more sense, and the change makes the code clearer, since the current LearnRelatedScripts call is hard to understand and explain. (Personally, I'd like it if this PR were merged before bitcoin#17373 or that PR was rebased on top of this one so it would be less confusing.)
  meshcollider:
    utACK 3958295

Tree-SHA512: 49a5f4b022b28042ad37ea309b28378a3983cb904e234a25795b5a360356652e0f8e60f15e3e64d85094ea63af9be01812d90ccfc08ca4f1dd927fdd8566e33f
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Dec 16, 2021
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.

7 participants