Skip to content

Conversation

@achow101
Copy link
Member

  • The TopUp() in CWallet::GetNewChangeDestination is unnecessary as currently m_spk_man calls TopUp further down the call stack inside LegacyScriptPubKeyMan::ReserveKeyFromKeyPool (called by LegacyScriptPubKeyMan::GetReservedDestination). This also lets us prepare for future changes with multiple ScriptPubKeyMans in the wallet.
  • An opportunistic TopUp() is moved from LegacyScriptPubKeyMan::GetNewDestination to CWallet::GetNewDestination.
  • Another opportunistic TopUp() is moved from LegacyScriptPubKeyMan::ReserveKeyFromKeyPool

Moving opportunistic TopUps ensures that ScriptPubKeyMans will always be topped up before requesting Destinations from them as we cannot always rely on future ScriptPubKeyMan implementaions topping up internally.

See also: #17373 (comment)

@ryanofsky
Copy link
Contributor

To round this out I think it could also be good:

  • To move TopUp call up the stack from LegacyScriptPubKeyMan::MarkUnusedAddresses by having that method return whether it removed any keypool entries.
  • To add a note to ScriptPubKeyMan::TopUp header declaration saying that after initialization, individual ScriptPubKeyMan implementations shouldn't need to call this internally. External wallet code is responsible for topping up so key pools get managed in a uniform way across implementations.

@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 20, 2019

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

Conflicts

No conflicts as of last run.

@achow101
Copy link
Member Author

* To move TopUp call up the stack from `LegacyScriptPubKeyMan::MarkUnusedAddresses` by having that method return whether it removed any keypool entries.

That would be a behavior change. Since the TopUp is currently done as each key is checked, it would be possible that the next key to be checked is added by the TopUp from the previous key.

* To add a note to `ScriptPubKeyMan::TopUp` header declaration saying that after initialization, individual ScriptPubKeyMan implementations shouldn't need to call this internally. External wallet code is responsible for topping up so key pools get managed in a uniform way across implementations.

I've added a comment to say it should be used sparingly and that the wallet handles calling TopUp for fetching new addresses.

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 a805c97b83d99ec3e0f48272131cfec92aaf82f5. Looks great! Simple change that provides more clarity now and should lead to more consistency in the future.

  • To move TopUp call up the stack from LegacyScriptPubKeyMan::MarkUnusedAddresses by having that method return whether it removed any keypool entries.

That would be a behavior change. Since the TopUp is currently done as each key is checked, it would be possible that the next key to be checked is added by the TopUp from the previous key.

Oops, sorry for the bad suggestion. It seems like the right way to handle this without changing behavior would be to move GetAffectedKeys and MarkUnusedAddresses code out of the legacy keyman and back into the wallet, and have wallet code just call a new keyman MarkKeysAsUsed(CKeyID) method followed by a topup call. This would simplify the legacy keyman and remove more duplicate functionality and reduce chances for bugs and inconsistencies between keyman implementations.

@meshcollider
Copy link
Contributor

Code review ACK a805c97b83d99ec3e0f48272131cfec92aaf82f5

This does not change behavior. This TopUp() is unnecessary as currently
m_spk_man calls TopUp further down the call stack inside
LegacyScriptPubKeyMan::ReserveKeyFromKeyPool (called by LegacyScriptPubKeyMan::GetReservedDestination)

By removing this here, we also prepare for future changes where CWallet
has multiple ScriptPubKeyMans instead of m_spk_man.
…let and ReserveDestination

An opportunistic TopUp is moved from LegacyScriptPubKeyMan::GetNewDestination
to CWallet::GetNewDestination. Another opportunistic TopUp is moved from
LegacyScriptPubKeyMan::ReserveKeyFromKeyPool (called by LegacyScriptPubKeyMan::GetReservedDestination)
to ReserveDestination::GetReservedDestination.

Moving opportunistic TopUps ensures that ScriptPubKeyMans will always
be topped up before requesting Destinations from them as we cannot
always rely on future ScriptPubKeyMan implementaions topping up internally.
As such, it is also unnecessary to keep the TopUp calls in the
LegacyScriptPubKeyMan functions so they are moved.

This does not change behavior as TopUp calls are moved up the call stack.
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 778158576dcfe3412001e1c6d48cb9f00711bfbf. No changes since last review, just simple rebase

Copy link
Member

@instagibbs instagibbs left a comment

Choose a reason for hiding this comment

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

utACK contingent on clarification of comment commit

Copy link
Member

Choose a reason for hiding this comment

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

This is a vaguely unactionable comment.

Can we give a positive statement about when it's to be used? The last two uses appear to be when the old keypool is being blown away.

Copy link
Member Author

Choose a reason for hiding this comment

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

Expanded the comment a bit more.

It's kind of hard to say when it should and should not be used. I'm just trying to avoid the previous behavior of sprinkling TopUps everywhere.

Copy link
Member

Choose a reason for hiding this comment

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

fair enough.

@instagibbs
Copy link
Member

utACK 6e77a7b only change is slight elaboration on comment

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 6e77a7b. Only the comment changed since my previous review.

Copy link
Contributor

@promag promag 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 6e77a7b. Verified that

  • first commit removes unnecessary calls as they are already made later
  • second commit moves the calls near to where the address pool is changed.

fanquake added a commit that referenced this pull request Dec 17, 2019
…TopUp()s

6e77a7b keypool: Add comment about TopUp and when to use it (Andrew Chow)
ea50e34 keypool: Move opportunistic TopUps from LegacyScriptPubKeyMan to CWallet and ReserveDestination (Andrew Chow)
bb2c8ce keypool: Remove  superfluous topup from CWallet::GetNewChangeDestination (Andrew Chow)

Pull request description:

  * The `TopUp()` in `CWallet::GetNewChangeDestination` is unnecessary as currently m_spk_man calls TopUp further down the call stack inside LegacyScriptPubKeyMan::ReserveKeyFromKeyPool (called by LegacyScriptPubKeyMan::GetReservedDestination). This also lets us prepare for future changes with multiple ScriptPubKeyMans in the wallet.
  * An opportunistic `TopUp()` is moved from `LegacyScriptPubKeyMan::GetNewDestination` to `CWallet::GetNewDestination`.
  * Another opportunistic `TopUp()` is moved from `LegacyScriptPubKeyMan::ReserveKeyFromKeyPool`

  Moving opportunistic TopUps ensures that ScriptPubKeyMans will always be topped up before requesting Destinations from them as we cannot  always rely on future ScriptPubKeyMan implementaions topping up internally.

  See also: #17373 (comment)

ACKs for top commit:
  instagibbs:
    utACK 6e77a7b only change is slight elaboration on comment
  ryanofsky:
    Code review ACK 6e77a7b. Only the comment changed since my previous review.

Tree-SHA512: bdfc8d303842c3fb7c3d40af7abfa6d9dac4ef71a24922bb92229674ee89bfe3113ebb46d3903ac48ef99f0a7d6eaac33282495844f2b31f91b8df55084c421f
@fanquake fanquake merged commit 6e77a7b into bitcoin:master Dec 17, 2019
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Dec 17, 2019
…fluous TopUp()s

6e77a7b keypool: Add comment about TopUp and when to use it (Andrew Chow)
ea50e34 keypool: Move opportunistic TopUps from LegacyScriptPubKeyMan to CWallet and ReserveDestination (Andrew Chow)
bb2c8ce keypool: Remove  superfluous topup from CWallet::GetNewChangeDestination (Andrew Chow)

Pull request description:

  * The `TopUp()` in `CWallet::GetNewChangeDestination` is unnecessary as currently m_spk_man calls TopUp further down the call stack inside LegacyScriptPubKeyMan::ReserveKeyFromKeyPool (called by LegacyScriptPubKeyMan::GetReservedDestination). This also lets us prepare for future changes with multiple ScriptPubKeyMans in the wallet.
  * An opportunistic `TopUp()` is moved from `LegacyScriptPubKeyMan::GetNewDestination` to `CWallet::GetNewDestination`.
  * Another opportunistic `TopUp()` is moved from `LegacyScriptPubKeyMan::ReserveKeyFromKeyPool`

  Moving opportunistic TopUps ensures that ScriptPubKeyMans will always be topped up before requesting Destinations from them as we cannot  always rely on future ScriptPubKeyMan implementaions topping up internally.

  See also: bitcoin#17373 (comment)

ACKs for top commit:
  instagibbs:
    utACK bitcoin@6e77a7b only change is slight elaboration on comment
  ryanofsky:
    Code review ACK 6e77a7b. Only the comment changed since my previous review.

Tree-SHA512: bdfc8d303842c3fb7c3d40af7abfa6d9dac4ef71a24922bb92229674ee89bfe3113ebb46d3903ac48ef99f0a7d6eaac33282495844f2b31f91b8df55084c421f
jasonbcox pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 1, 2020
…us TopUp()s

Summary:
6e77a7b65cda1b46ce42f0c99ca91562255aeb28 keypool: Add comment about TopUp and when to use it (Andrew Chow)
ea50e34b287e0da0806c1116bb55ade730e8ff6c keypool: Move opportunistic TopUps from LegacyScriptPubKeyMan to CWallet and ReserveDestination (Andrew Chow)
bb2c8ce23c9d7ba8d0e5538243e07218443c85b4 keypool: Remove  superfluous topup from CWallet::GetNewChangeDestination (Andrew Chow)

Pull request description:

  * The `TopUp()` in `CWallet::GetNewChangeDestination` is unnecessary as currently m_spk_man calls TopUp further down the call stack inside LegacyScriptPubKeyMan::ReserveKeyFromKeyPool (called by LegacyScriptPubKeyMan::GetReservedDestination). This also lets us prepare for future changes with multiple ScriptPubKeyMans in the wallet.
  * An opportunistic `TopUp()` is moved from `LegacyScriptPubKeyMan::GetNewDestination` to `CWallet::GetNewDestination`.
  * Another opportunistic `TopUp()` is moved from `LegacyScriptPubKeyMan::ReserveKeyFromKeyPool`

  Moving opportunistic TopUps ensures that ScriptPubKeyMans will always be topped up before requesting Destinations from them as we cannot  always rely on future ScriptPubKeyMan implementaions topping up internally.

  See also: bitcoin/bitcoin#17373 (comment)

---

Backport of Core [[bitcoin/bitcoin#17537 | PR17537]]

Test Plan:
  ninja all check check-functional

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D7722
sidhujag pushed a commit to syscoin-core/syscoin that referenced this pull request Nov 10, 2020
…fluous TopUp()s

6e77a7b keypool: Add comment about TopUp and when to use it (Andrew Chow)
ea50e34 keypool: Move opportunistic TopUps from LegacyScriptPubKeyMan to CWallet and ReserveDestination (Andrew Chow)
bb2c8ce keypool: Remove  superfluous topup from CWallet::GetNewChangeDestination (Andrew Chow)

Pull request description:

  * The `TopUp()` in `CWallet::GetNewChangeDestination` is unnecessary as currently m_spk_man calls TopUp further down the call stack inside LegacyScriptPubKeyMan::ReserveKeyFromKeyPool (called by LegacyScriptPubKeyMan::GetReservedDestination). This also lets us prepare for future changes with multiple ScriptPubKeyMans in the wallet.
  * An opportunistic `TopUp()` is moved from `LegacyScriptPubKeyMan::GetNewDestination` to `CWallet::GetNewDestination`.
  * Another opportunistic `TopUp()` is moved from `LegacyScriptPubKeyMan::ReserveKeyFromKeyPool`

  Moving opportunistic TopUps ensures that ScriptPubKeyMans will always be topped up before requesting Destinations from them as we cannot  always rely on future ScriptPubKeyMan implementaions topping up internally.

  See also: bitcoin#17373 (comment)

ACKs for top commit:
  instagibbs:
    utACK bitcoin@6e77a7b only change is slight elaboration on comment
  ryanofsky:
    Code review ACK 6e77a7b. Only the comment changed since my previous review.

Tree-SHA512: bdfc8d303842c3fb7c3d40af7abfa6d9dac4ef71a24922bb92229674ee89bfe3113ebb46d3903ac48ef99f0a7d6eaac33282495844f2b31f91b8df55084c421f
@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.

7 participants