💬 ryanofsky commented on pull request "wallet: Add `createwalletdescriptor` and `gethdkeys` RPCs for adding new automatically generated descriptors":
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435355508)
In commit "desc spkm: Add functions to retrieve specific private keys" (484711baa994d482110edaf510377181b8b2b465)
It looks like this function would be a little more flexible and efficient if took a CKeyID parameter instead of a CPubKey
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435355508)
In commit "desc spkm: Add functions to retrieve specific private keys" (484711baa994d482110edaf510377181b8b2b465)
It looks like this function would be a little more flexible and efficient if took a CKeyID parameter instead of a CPubKey
💬 ryanofsky commented on pull request "wallet: Add `createwalletdescriptor` and `gethdkeys` RPCs for adding new automatically generated descriptors":
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435366492)
In commit "wallet, rpc: Add gethdkeys RPC" (5deafad2f61f626b50b6c173558ac7236cceff13)
Would suggest making these name-only parameters to avoid different bool options being confused with each other, and to leave room to add new positional parameters in the future. You could do this with:
```diff
--- a/src/rpc/client.cpp
+++ b/src/rpc/client.cpp
@@ -274,8 +274,9 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "logging", 1, "exclude" },
{ "disconnectnode", 1, "nodeid"
...
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435366492)
In commit "wallet, rpc: Add gethdkeys RPC" (5deafad2f61f626b50b6c173558ac7236cceff13)
Would suggest making these name-only parameters to avoid different bool options being confused with each other, and to leave room to add new positional parameters in the future. You could do this with:
```diff
--- a/src/rpc/client.cpp
+++ b/src/rpc/client.cpp
@@ -274,8 +274,9 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "logging", 1, "exclude" },
{ "disconnectnode", 1, "nodeid"
...
💬 ryanofsky commented on pull request "wallet: Add `createwalletdescriptor` and `gethdkeys` RPCs for adding new automatically generated descriptors":
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435368965)
In commit "wallet, rpc: Add gethdkeys RPC" (5deafad2f61f626b50b6c173558ac7236cceff13)
Note: This is better than what I suggested. I was originally thinking this default should be true, to make it more convenient to get active hd key and ignore other keys. But defaulting to false is actually better, because it's still easy to get the active hd key with an option, and it's probably more confusing to see missing keys than extra keys. Also this default makes `gethdkeys` output more consistent wit
...
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435368965)
In commit "wallet, rpc: Add gethdkeys RPC" (5deafad2f61f626b50b6c173558ac7236cceff13)
Note: This is better than what I suggested. I was originally thinking this default should be true, to make it more convenient to get active hd key and ignore other keys. But defaulting to false is actually better, because it's still easy to get the active hd key with an option, and it's probably more confusing to see missing keys than extra keys. Also this default makes `gethdkeys` output more consistent wit
...
💬 ryanofsky commented on pull request "wallet: Add `createwalletdescriptor` and `gethdkeys` RPCs for adding new automatically generated descriptors":
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435372329)
In commit "wallet, rpc: Add gethdkeys RPC" (5deafad2f61f626b50b6c173558ac7236cceff13)
This is just general style feedback, but I think where possible it's better to use `auto&` or `auto*` instead of bare `auto` because with bare `auto` in c++, you don't know if a potentially expensive object copy will happen without manually checking the type. With `auto&` or `auto*` you know there won't be an big copy without having to think about it. Up to you though if you prefer less verbosity instead
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435372329)
In commit "wallet, rpc: Add gethdkeys RPC" (5deafad2f61f626b50b6c173558ac7236cceff13)
This is just general style feedback, but I think where possible it's better to use `auto&` or `auto*` instead of bare `auto` because with bare `auto` in c++, you don't know if a potentially expensive object copy will happen without manually checking the type. With `auto&` or `auto*` you know there won't be an big copy without having to think about it. Up to you though if you prefer less verbosity instead
💬 ryanofsky commented on pull request "wallet: Add `createwalletdescriptor` and `gethdkeys` RPCs for adding new automatically generated descriptors":
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435369940)
In commit "wallet, rpc: Add gethdkeys RPC" (5deafad2f61f626b50b6c173558ac7236cceff13)
Could use `Assert(desc_spkm)` to avoid undefined behavior if it is null.
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435369940)
In commit "wallet, rpc: Add gethdkeys RPC" (5deafad2f61f626b50b6c173558ac7236cceff13)
Could use `Assert(desc_spkm)` to avoid undefined behavior if it is null.
💬 ryanofsky commented on pull request "wallet: Add `createwalletdescriptor` and `gethdkeys` RPCs for adding new automatically generated descriptors":
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435375318)
In commit "wallet, rpc: Add gethdkeys RPC" (5deafad2f61f626b50b6c173558ac7236cceff13)
It seems like theoretically there could be a race condition if the wallet became locked during this loop. Also the code ignores other potential errors. Would maybe suggest:
```c++
if (priv && desc_spkm->HasPrivKey(xpub.pubkey)) {
wallet_xprvs[xpub] = CExtKey(xpub, *CHECK_NONFATAL(desc_spkm->GetKey(xpub.pubkey)));
}
```
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435375318)
In commit "wallet, rpc: Add gethdkeys RPC" (5deafad2f61f626b50b6c173558ac7236cceff13)
It seems like theoretically there could be a race condition if the wallet became locked during this loop. Also the code ignores other potential errors. Would maybe suggest:
```c++
if (priv && desc_spkm->HasPrivKey(xpub.pubkey)) {
wallet_xprvs[xpub] = CExtKey(xpub, *CHECK_NONFATAL(desc_spkm->GetKey(xpub.pubkey)));
}
```
💬 ryanofsky commented on pull request "wallet: Add `createwalletdescriptor` and `gethdkeys` RPCs for adding new automatically generated descriptors":
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435376241)
In commit "wallet, rpc: Add gethdkeys RPC" (5deafad2f61f626b50b6c173558ac7236cceff13)
Not important but I think I would suggest switching to `auto&` in the loops above and using `std::move(desc)` here to avoid copying strings when not necessary.
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435376241)
In commit "wallet, rpc: Add gethdkeys RPC" (5deafad2f61f626b50b6c173558ac7236cceff13)
Not important but I think I would suggest switching to `auto&` in the loops above and using `std::move(desc)` here to avoid copying strings when not necessary.
💬 ryanofsky commented on pull request "wallet: Add `createwalletdescriptor` and `gethdkeys` RPCs for adding new automatically generated descriptors":
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435381067)
In commit "wallet: Refactor function for single DescSPKM setup" (280d26b19e9222afa902ad09cd7b42c2eb3e0044)
Seems like the &batch argument option is replaced with nullptr here. This seems like a bug, but if it is intended behavior should definitely have a comment explaining the nullptr.
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435381067)
In commit "wallet: Refactor function for single DescSPKM setup" (280d26b19e9222afa902ad09cd7b42c2eb3e0044)
Seems like the &batch argument option is replaced with nullptr here. This seems like a bug, but if it is intended behavior should definitely have a comment explaining the nullptr.
💬 ryanofsky commented on pull request "wallet: Add `createwalletdescriptor` and `gethdkeys` RPCs for adding new automatically generated descriptors":
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435377746)
In commit "wallet, rpc: Add gethdkeys RPC" (5deafad2f61f626b50b6c173558ac7236cceff13)
Could use std::move here and on line 906 as well to avoid copying univalue objects. I will stop commenting about copies, though. I don't think they are important, I just figure it's very easy to avoid copying and we don't need 3 copies of each descriptor string so why not avoid it.
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435377746)
In commit "wallet, rpc: Add gethdkeys RPC" (5deafad2f61f626b50b6c173558ac7236cceff13)
Could use std::move here and on line 906 as well to avoid copying univalue objects. I will stop commenting about copies, though. I don't think they are important, I just figure it's very easy to avoid copying and we don't need 3 copies of each descriptor string so why not avoid it.
💬 achow101 commented on pull request "wallet: Add `createwalletdescriptor` and `gethdkeys` RPCs for adding new automatically generated descriptors":
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435423974)
`cs_wallet` is being held earlier, and that will prevent the wallet from locked.
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435423974)
`cs_wallet` is being held earlier, and that will prevent the wallet from locked.
💬 achow101 commented on pull request "wallet: Add `createwalletdescriptor` and `gethdkeys` RPCs for adding new automatically generated descriptors":
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435436394)
Done
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435436394)
Done
💬 achow101 commented on pull request "wallet: Add `createwalletdescriptor` and `gethdkeys` RPCs for adding new automatically generated descriptors":
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435436422)
Done as suggested
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435436422)
Done as suggested
💬 achow101 commented on pull request "wallet: Add `createwalletdescriptor` and `gethdkeys` RPCs for adding new automatically generated descriptors":
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435436471)
Added a `CHECK_NONFATAL`.
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435436471)
Added a `CHECK_NONFATAL`.
💬 achow101 commented on pull request "wallet: Add `createwalletdescriptor` and `gethdkeys` RPCs for adding new automatically generated descriptors":
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435436629)
Done
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435436629)
Done
💬 achow101 commented on pull request "wallet: Add `createwalletdescriptor` and `gethdkeys` RPCs for adding new automatically generated descriptors":
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435436652)
Done
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435436652)
Done
💬 achow101 commented on pull request "wallet: Add `createwalletdescriptor` and `gethdkeys` RPCs for adding new automatically generated descriptors":
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435436670)
Done
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435436670)
Done
💬 achow101 commented on pull request "wallet: Add `createwalletdescriptor` and `gethdkeys` RPCs for adding new automatically generated descriptors":
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435436690)
Indeed, fixed.
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435436690)
Indeed, fixed.
💬 achow101 commented on pull request "wallet: Add `createwalletdescriptor` and `gethdkeys` RPCs for adding new automatically generated descriptors":
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435436779)
Done
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435436779)
Done
💬 achow101 commented on pull request "wallet: Add `createwalletdescriptor` and `gethdkeys` RPCs for adding new automatically generated descriptors":
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435436813)
Moved to the right commit.
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435436813)
Moved to the right commit.
💬 achow101 commented on pull request "wallet: Add `createwalletdescriptor` and `gethdkeys` RPCs for adding new automatically generated descriptors":
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435437218)
This function was intended to only return a `CExtPubKey` if all active descriptors shared the same xpub, so if they differed, it would return `std::nullopt`. The comment was stating what it was attempting to do, not what it was expecting.
In any case, having the caller determine what to do if there is more than one xpub in the active descriptors is probably better, so I've changed it to do that and this comment is no longer relevant.
(https://github.com/bitcoin/bitcoin/pull/29130#discussion_r1435437218)
This function was intended to only return a `CExtPubKey` if all active descriptors shared the same xpub, so if they differed, it would return `std::nullopt`. The comment was stating what it was attempting to do, not what it was expecting.
In any case, having the caller determine what to do if there is more than one xpub in the active descriptors is probably better, so I've changed it to do that and this comment is no longer relevant.