Skip to content

Conversation

achow101
Copy link
Member

SetHDChaiin, SetActiveScriptPubKeyMan, and SetWalletFlags have a memonly argument which is kind of confusing, as noted in #17681 (comment). This PR replaces those functions with Add* and Load* variants so that they follow the pattern used elsewhere in the wallet.

AddHDChain, AddActiveScriptPubKeyMan, and AddWalletFlags both set their respective variables in CWallet and writes them to disk. These functions are used by the actions which modify the wallet such as sethdseed, importdescriptors, and creating a new wallet.

LoadHDChain, LoadActiveScriptPubKeyMan, and LoadWalletFlags just set the CWallet variables. These functions are used by LoadWallet when loading the wallet from disk.

achow101 added 2 commits May 21, 2020 22:43
Remove the memonly bool and follow our typical Add and Load pattern.
Remove the memonly bool and follow the Add and Load pattern we use
everywhere else.
@laanwj
Copy link
Member

laanwj commented May 26, 2020

I agree that having separate Add/Load functions instead of a confusing boolean argument improves understandability of the code quite a bit.
Code review ACK f123374

@Empact
Copy link
Contributor

Empact commented May 26, 2020

Concept ACK

@DrahtBot
Copy link
Contributor

DrahtBot commented May 27, 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.

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 f123374. Contra #19046 (comment) it seems good to me that these methods now try to update the wallet database first and return early on failure before updating the state in memory. Haven't thought about it too much but it seems better if that there's an error writing to disk for some reason, operation just fails and wallet stays in the current state.

@jnewbery, you may be interested in this PR since it was inspired by your review comment

Remove memonly bool and follow typical Add and Load pattern used
everywhere else.
Copy link
Contributor

@jnewbery jnewbery 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 3a9aba2

One small typo in a comment if you feel like retouching.

bool CWallet::AddWalletFlags(uint64_t flags)
{
LOCK(cs_wallet);
// We should never be writing unknown onon-tolerable wallet flags
Copy link
Contributor

Choose a reason for hiding this comment

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

s/onon/non/

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops. I'll fix that if I have to push again.

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 3a9aba2. Only changes since last review tweaks making m_wallet_flags updates more safe

{
LOCK(cs_wallet);
// We should never be writing unknown onon-tolerable wallet flags
assert(!(((flags & KNOWN_WALLET_FLAGS) >> 32) ^ (flags >> 32)));
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 "Split SetWalletFlags into Add/LoadWalletFlags" (3a9aba2)

If you wind up updating check may be more readable as assert(((flags & KNOWN_WALLET_FLAGS) >> 32) == (flags >> 32))

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 3a9aba2

@meshcollider meshcollider merged commit 89899a3 into bitcoin:master Jul 11, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jul 11, 2020
… with Add/Load variants

3a9aba2 Split SetWalletFlags into Add/LoadWalletFlags (Andrew Chow)
d9cd095 Split SetActiveScriptPubKeyMan into Add/LoadActiveScriptPubKeyMan (Andrew Chow)
0122fba Split SetHDChain into AddHDChain and LoadHDChain (Andrew Chow)

Pull request description:

  `SetHDChaiin`, `SetActiveScriptPubKeyMan`, and `SetWalletFlags` have a `memonly` argument which is kind of confusing, as noted in bitcoin#17681 (comment). This PR replaces those functions with `Add*` and `Load*` variants so that they follow the pattern used elsewhere in the wallet.

  `AddHDChain`, `AddActiveScriptPubKeyMan`, and `AddWalletFlags` both set their respective variables in `CWallet` and writes them to disk. These functions are used by the actions which modify the wallet such as `sethdseed`, `importdescriptors`, and creating a new wallet.

  `LoadHDChain`, `LoadActiveScriptPubKeyMan`, and `LoadWalletFlags` just set the `CWallet` variables. These functions are used by `LoadWallet` when loading the wallet from disk.

ACKs for top commit:
  jnewbery:
    Code review ACK 3a9aba2
  ryanofsky:
    Code review ACK 3a9aba2. Only changes since last review tweaks making m_wallet_flags updates more safe
  meshcollider:
    utACK 3a9aba2

Tree-SHA512: 365aeaafc5ba42879c0eb797ec3beb29ab70e27f917dc880763f743420b3be6ddf797240996beed8a9ad70fb212c2590253c6b44c9dc244529c3939d9538983f
meshcollider added a commit that referenced this pull request Jul 12, 2020
facd7dd wallet: Fix typo in comments; Simplify assert (MarcoFalke)

Pull request description:

  Follow up to #19046 (comment) and #19046 (comment)

ACKs for top commit:
  practicalswift:
    ACK facd7dd
  jonatack:
    ACK facd7dd
  hebasto:
    ACK facd7dd, spelling verified with `test/lint/lint-spelling.sh`: all remaining warnings are false positive.

Tree-SHA512: 2b185d138058840db56726bb6bcc42e5288a954e2a410c49e04806a047fbbdaf0bb2decc70ecf7613c69caa766655705ca44151613e7ea5015b386d1e726d870
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jul 12, 2020
facd7dd wallet: Fix typo in comments; Simplify assert (MarcoFalke)

Pull request description:

  Follow up to bitcoin#19046 (comment) and bitcoin#19046 (comment)

ACKs for top commit:
  practicalswift:
    ACK facd7dd
  jonatack:
    ACK facd7dd
  hebasto:
    ACK facd7dd, spelling verified with `test/lint/lint-spelling.sh`: all remaining warnings are false positive.

Tree-SHA512: 2b185d138058840db56726bb6bcc42e5288a954e2a410c49e04806a047fbbdaf0bb2decc70ecf7613c69caa766655705ca44151613e7ea5015b386d1e726d870
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jun 7, 2021
Summary:
Remove the memonly bool and follow our typical Add and Load pattern.

This is a backport of [[bitcoin/bitcoin#19046 | core#19046]] [1/3]
bitcoin/bitcoin@0122fba

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Subscribers: majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9630
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jun 7, 2021
Summary:
Remove the memonly bool and follow the Add and Load pattern we use
everywhere else.

This is a backport of [[bitcoin/bitcoin#19046 | core#19046]] [2/3]
bitcoin/bitcoin@d9cd095

Depends on D9630

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9631
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jun 7, 2021
Summary:
Remove memonly bool and follow typical Add and Load pattern used
everywhere else.

This is a backport of [[bitcoin/bitcoin#19046 | core#19046]] [3/3]
bitcoin/bitcoin@3a9aba2

Depends on D9631

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9632
@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.

8 participants