Slight cleanup following #16944
This should allow future scriptpubkeymans to transparently work, since the current plan is to have ismine always be spendable.
Slight cleanup following #16944
This should allow future scriptpubkeymans to transparently work, since the current plan is to have ismine always be spendable.
conversation ensued on IRC after reading #16373 (review) since this pattern should be followed in each place we use this behavior for LegacyScriptPubKeyMan
2168 | @@ -2169,8 +2169,8 @@ std::map<CTxDestination, std::vector<COutput>> CWallet::ListCoins(interfaces::Ch 2169 | std::vector<COutPoint> lockedCoins; 2170 | ListLockedCoins(lockedCoins); 2171 | // Include watch-only for wallets without private keys 2172 | - const bool include_watch_only = IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS); 2173 | - const isminetype is_mine_filter = include_watch_only ? ISMINE_WATCH_ONLY : ISMINE_SPENDABLE; 2174 | + const bool include_watch_only = GetLegacyScriptPubKeyMan() && IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS); 2175 | + const isminetype is_mine_filter = include_watch_only ? ISMINE_ALL : ISMINE_SPENDABLE;
Note to other reviewers: ISMINE_ALL = ISMINE_WATCH_ONLY | ISMINE_SPENDABLE. When WALLET_FLAG_DISABLE_PRIVATE_KEYS is set, no coins can be ISMINE_SPENDABLE. Therefore ISMINE_ALL leads to the same behavior as ISMINE_WATCH_ONLY
Code review ACK 7f8046e
This isn't quite what I was thinking.
The thought was that you would do either checking for LegacyScrriptPubKeyMan or ISMINE_ALL, not both. Since ISMINE_WATCHONLY is not intended to be used outside of LegacyScriptPubKeyMan, you could just check for whether it's LegacySPKM and set ISMINE_WATCHONLY if it is. Otherwise you just use ISMINE_SPENDABLE.
Alternatively, because ISMINE_ALL is ISMINE_WATCHONLY | ISMINE_SPENDABLE, for all watch only wallets (disabled private keys), you can have the filter be ISMINE_ALL. That will be sufficient to cover LegacySPKM and future ScriptPubKeyMans which will exclusively use ISMINE SPENDABLE. Of course all of the watch only stuff will need to check for disabled private keys, but we already do that.
I don't think doing both of those things are necessary.
If I have to choose, I'll stick with the Legacy check + ISMINE_WATCH_ONLY since it's easier for me to understand the purpose/scope of the code. Updated.
ACK 6beb900c0cdf86f40ca5e75f3c77b3d0461ea7a3
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
No conflicts as of last run.
652 | @@ -653,7 +653,7 @@ void SendCoinsDialog::useAvailableBalance(SendCoinsEntry* entry)
653 | }
654 |
655 | // Include watch-only for wallets without private key
Suggestion:
- // Include watch-only for wallets without private key
+ // Include watch-only for LegacyScriptPubKeyMan wallets without private keys.
652 | @@ -653,7 +653,7 @@ void SendCoinsDialog::useAvailableBalance(SendCoinsEntry* entry) 653 | } 654 | 655 | // Include watch-only for wallets without private key 656 | - coin_control.fAllowWatchOnly = model->privateKeysDisabled(); 657 | + coin_control.fAllowWatchOnly = model->hasLegacyScriptPubKeyMan() && model->privateKeysDisabled();
In addition to here in SendCoinsDialog::useAvailableBalance(), should this be updated in SendCoinsDialog::updateCoinControlState() as well? https://github.com/bitcoin/bitcoin/blob/6beb900c0cdf86f40ca5e75f3c77b3d0461ea7a3/src/qt/sendcoinsdialog.cpp#L711
oh, good catch. Will update.
Do we want to also do similar gating in https://github.com/bitcoin/bitcoin/pull/16944/files#diff-76b18bd21ccf64e256f029a8198ecdd7R190 ?
cc @achow101
Gating should really only apply to anything that guards ismine filters. We want to have the watch only behavior apply to any watch only wallet. The gating is just to use the correct ismine filters.
to be clear, you are saying we should remove the change above at line 656, rather than add another check at 711?
After looking at everywhere that fAllowWatchOnly is being used, yes, I think we should remove this change. Instead we need to check everywhere that we conditionally set a filter for ISMINE_WATCHONLY and add a check for LegacySPKM at each place.
2168 | @@ -2169,7 +2169,7 @@ std::map<CTxDestination, std::vector<COutput>> CWallet::ListCoins(interfaces::Ch
2169 | std::vector<COutPoint> lockedCoins;
2170 | ListLockedCoins(lockedCoins);
2171 | // Include watch-only for wallets without private keys
Suggestion:
- // Include watch-only for wallets without private keys
+ // Include watch-only for LegacyScriptPubKeyMan wallets without private keys.
ACK 6beb900 modulo question and suggestions below. Code review/built/ran tests. Would test coverage be helpful here?
Reduced changes as per discussion to just affecting the ismine filter, rather than fAllowWatchOnly.
ACK e1e1442f3eadc1d139380e71c1b60b86d8d6bdee
Code review ACK e1e1442f3eadc1d139380e71c1b60b86d8d6bdee
This smaller diff in e1e1442f3eadc1d139380e71c1b60b86d8d6bdee seems good and the build/tests pass. Started looking at a test which, per @instagibbs suggestion, would define a new spk_man, add watchonly coins, then check they aren't returned by ListCoins.
Code review ACK e1e1442f3eadc1d139380e71c1b60b86d8d6bdee