-
Notifications
You must be signed in to change notification settings - Fork 38.3k
rpc, wallet: Do not return "keypoololdest" for blank descriptor wallets #23348
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
Conversation
lsilva01
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review and Tested ACK 303ee60
nit: Maybe the comment in DescriptorScriptPubKeyMan::GetOldestKeyPoolTime() can be updated.
|
Concept ACK Another solution would be to make |
In that case, |
|
Agree with @laanwj's suggestion, and |
303ee60 to
324172e
Compare
src/wallet/wallet.cpp
Outdated
| std::optional<int64_t> oldest_key = std::nullopt; | ||
| for (const auto& spk_man_pair : m_spk_managers) { | ||
| oldestKey = std::min(oldestKey, spk_man_pair.second->GetOldestKeyPoolTime()); | ||
| if (!oldest_key.has_value()) { | ||
| oldest_key = spk_man_pair.second->GetOldestKeyPoolTime(); | ||
| continue; | ||
| } | ||
| if (!spk_man_pair.second->GetOldestKeyPoolTime().has_value()) { | ||
| continue; | ||
| } | ||
| oldest_key = std::min(oldest_key.value(), spk_man_pair.second->GetOldestKeyPoolTime().value()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a behaviour change: Previously, it would return 0 if any of the m_spk_managers returned 0. With the new semantics, it should prefer std::nullopt over a value.
If this change is intentional, please document why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Updated.
324172e to
da5f866
Compare
|
Updated 324172e -> da5f866 (pr23348.02 -> pr23348.03, diff): |
This change gets rid of the magic number 0 in the DescriptorScriptPubKeyMan::GetOldestKeyPoolTime() function. No behavior change.
This change suppress the "keypoololdest" field in the getwalletinfo RPC response for blank descriptor wallets.
da5f866 to
ee03c78
Compare
|
Updated da5f866 -> ee03c78 (pr23348.03 -> pr23348.04, diff):
|
| std::optional<int64_t> oldest_key{std::numeric_limits<int64_t>::max()}; | ||
| for (const auto& spk_man_pair : m_spk_managers) { | ||
| oldestKey = std::min(oldestKey, spk_man_pair.second->GetOldestKeyPoolTime()); | ||
| oldest_key = std::min(oldest_key, spk_man_pair.second->GetOldestKeyPoolTime()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't you get a nullopt in here? (If not, why change this block at all?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't you get a nullopt in here?
Sorry, I did not get your question. What do you mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spk_man_pair.second->GetOldestKeyPoolTime() could return std::nullopt. Is it well-defined what std::min will do here, and is it the desired behaviour?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::min() uses operator<, which is well-defined for std::optional.
lsilva01
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-ACK ee03c78
Tested std::min() with null value std::optional <int64_t> and it worked as expected.
stratospher
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK ee03c78.
- 3e4f069
- The return type of all the
GetOldestKeyPoolTime()is changed fromint64_ttooptional<int64_t>. - DescriptorScriptPubKeyMan’s
GetOldestKeyPoolTime()returnsnulloptinstead of 0 and changes were made ingetwalletinfo()to handle this.
- The return type of all the
- ee03c78
- In CWallet’s
GetOldestKeyPoolTime(), If m_spk_managers is not present,nulloptis returned(previously it returnednumeric_limits<int64_t>::max()) and handles the case for blank descriptor wallets.
- In CWallet’s
meshcollider
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK ee03c78
…lank descriptor wallets ee03c78 wallet: Make GetOldestKeyPoolTime return nullopt for blank wallets (Hennadii Stepanov) 3e4f069 wallet, refactor: Make GetOldestKeyPoolTime return type std::optional (Hennadii Stepanov) Pull request description: The "keypoololdest" field in the `getwalletinfo` RPC response should be used for legacy wallets only. Th current implementation (04437ee) assumes that `CWallet::GetOldestKeyPoolTime()` always return `0` for descriptor wallets. This assumption is wrong for _blank_ descriptor wallets, when `m_spk_managers` is empty. As a result: ``` $ src/bitcoin-cli -signet -rpcwallet=211024-d-DPK getwalletinfo { "walletname": "211024-d-DPK", "walletversion": 169900, "format": "sqlite", "balance": 0.00000000, "unconfirmed_balance": 0.00000000, "immature_balance": 0.00000000, "txcount": 0, "keypoololdest": 9223372036854775807, "keypoolsize": 0, "keypoolsize_hd_internal": 0, "paytxfee": 0.00000000, "private_keys_enabled": false, "avoid_reuse": false, "scanning": false, "descriptors": true } ``` This PR fixes this issue with direct checking of the `WALLET_FLAG_DESCRIPTORS` flag. ACKs for top commit: lsilva01: re-ACK ee03c78 stratospher: ACK ee03c78. meshcollider: Code review ACK ee03c78 Tree-SHA512: 9852f9f8ed5c08c07507274d7714f039bbfda66da6df65cf98f67bf11a600167d0f7f872680c95775399477f4df9ba9fce80ec0cbe0adb7f2bb33c3bd65b15df
…lank descriptor wallets ee03c78 wallet: Make GetOldestKeyPoolTime return nullopt for blank wallets (Hennadii Stepanov) 3e4f069 wallet, refactor: Make GetOldestKeyPoolTime return type std::optional (Hennadii Stepanov) Pull request description: The "keypoololdest" field in the `getwalletinfo` RPC response should be used for legacy wallets only. Th current implementation (04437ee) assumes that `CWallet::GetOldestKeyPoolTime()` always return `0` for descriptor wallets. This assumption is wrong for _blank_ descriptor wallets, when `m_spk_managers` is empty. As a result: ``` $ src/bitcoin-cli -signet -rpcwallet=211024-d-DPK getwalletinfo { "walletname": "211024-d-DPK", "walletversion": 169900, "format": "sqlite", "balance": 0.00000000, "unconfirmed_balance": 0.00000000, "immature_balance": 0.00000000, "txcount": 0, "keypoololdest": 9223372036854775807, "keypoolsize": 0, "keypoolsize_hd_internal": 0, "paytxfee": 0.00000000, "private_keys_enabled": false, "avoid_reuse": false, "scanning": false, "descriptors": true } ``` This PR fixes this issue with direct checking of the `WALLET_FLAG_DESCRIPTORS` flag. ACKs for top commit: lsilva01: re-ACK ee03c78 stratospher: ACK ee03c78. meshcollider: Code review ACK ee03c78 Tree-SHA512: 9852f9f8ed5c08c07507274d7714f039bbfda66da6df65cf98f67bf11a600167d0f7f872680c95775399477f4df9ba9fce80ec0cbe0adb7f2bb33c3bd65b15df
The "keypoololdest" field in the
getwalletinfoRPC response should be used for legacy wallets only.Th current implementation (04437ee) assumes that
CWallet::GetOldestKeyPoolTime()always return0for descriptor wallets. This assumption is wrong for blank descriptor wallets, whenm_spk_managersis empty. As a result:This PR fixes this issue with direct checking of the
WALLET_FLAG_DESCRIPTORSflag.