-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Add Sapling support to z_importwallet and z_exportwallet #3491
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
Add Sapling support to z_importwallet and z_exportwallet #3491
Conversation
|
@Eirik0 Can you rebase on master? I rebased but building results in errors, such as: |
0c7c283 to
cf52125
Compare
|
Pushed a commit to fix the build errors. The issue was that the class GetSpendingKeyForPaymentAddress had moved in my PR and had moved and been updated in another. |
bitcartel
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.
Works in testing. I do have some review comments.
src/wallet/rpcdump.cpp
Outdated
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.
Why do we have a log parameter? If just for developer debugging, we should consider removing the parameter and the log messages associated with it.
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.
It is this way because z_importwallet logged each address before it imported it where as z_importkey didn't, and I wanted to be able to reuse the visitor we created for z_importkey.
I could change AddSpendingKeyToWallet to return a pair of the result and an optional address and remove the logging from inside the visitor which might be more correct, but feels clunkier. I'd also be happy to remove the logging, but I can see use cases where that might be helpful. Let me know what you think or if you have a better idea of how to do this.
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.
Ok, that makes sense. Looks good then.
src/wallet/rpcdump.cpp
Outdated
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.
You might be able to rebase and merge this with earlier commits "Add sapling spending keys to z_exportwallet" and/or "Move visitor class" to clean up the function GetSpendingKeyForPaymentAddress().
|
☔ The latest upstream changes (presumably #3492) made this pull request unmergeable. Please resolve the merge conflicts. |
|
This PR also needs to import and export SaplingExtendedSpendingKey. Currently, z_importkey and z_exportkey work with a SaplingSpendingKey. If the RPC interface will support both SaplingSpendingKey and SaplingExtendedSpendingKey, then import and export wallet should also support both. |
cf52125 to
bbf37c7
Compare
|
Rebased and force pushed to address conflicts with #3492. |
9dd7c15 to
3716a1c
Compare
|
See comments in #3218 regarding bitcoin/bitcoin#8323 |
src/wallet/rpcwallet.cpp
Outdated
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.
masterkeyid should not be here and is removed in a later commit
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.
If you end up rebasing the PR, please squash the later commit into this one.
42d53ca to
51c1c3d
Compare
src/wallet/rpcdump.cpp
Outdated
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.
For diversified addresses, this will print the same spending key multiple times, each with a different zaddr. That's probably fine, though it might be a little confusing to users who open the file.
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.
Would it be beneficial to include the diversifier along with the address?
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.
The address already includes the diversifier, so I don't think so.
src/wallet/rpcdump.cpp
Outdated
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.
If you're moving it for accessibility, please move it to the bottom of wallet.h / wallet.cpp with the other generalisations (see there for how to structure it).
src/wallet/rpcdump.cpp
Outdated
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.
If you rebase this PR to move AddSpendingKeyToWallet into wallet.h, please refactor this into the previous commit (that added SpendingKeyAddResult).
src/wallet/wallet.cpp
Outdated
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 needs to be modified to:
metadata.hdKeypath = "m/32'/" + std::to_string(Params().BIP44CoinType()) + "'/" + std::to_string(hdChain.saplingAccountCounter) + "'";
You could make Params().BIP44CoinType() a variable after auto m so you can reuse it.
src/wallet/wallet.cpp
Outdated
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.
Remove this comment (wasn't in the commit, and doesn't apply to us in the way it was intended upstream).
src/wallet/walletdb.h
Outdated
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 commit lost its authorship details, but it's pretty trivial, so meh.
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.
For this one it merged in just fine, but was not correct for zcash. I did a git cherry-pick ... -n, and a git commit -e. Not sure what happened...
src/wallet/rpcdump.cpp
Outdated
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.
I'd prefer to put this at the top of the file, as part of the header (i.e. after the * Best block... line), since this seed is what we would use for deterministic t-addrs if we bring that in, and as-is it will end up "stranded" in the middle-to-end of the backup file if the user's wallet contains many t-addrs. Sorry that it makes your test harder to write...
src/wallet/rpcdump.cpp
Outdated
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.
You should be able to set the four new parameters as defaults in the operator() declaration, so that you don't have to specify them in these other locations. Then again, we only use this visitor in these two locations, so maybe explicit is better...
src/wallet/rpcdump.cpp
Outdated
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.
What will this do if hdKeypath or seedFp are empty/null (as for a key imported via z_importkey)? If empty I assume we just get additional whitespace in the file, but seedFp.IsNull() is when it is the all-zeroes array, which I think would get printed out here. We might need to be more verbose here in order to only add these two if they are meaningfully-filled.
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.
In fact, I think the import logic will break with this as-is. hdKeypath will be empty, and thus nothing prints for it, but seedFp will print all-zeroes hex. Then on importing, seedFp will be parsed as the third item in the list, and thus be incorrectly interpreted as hdKeypath.
qa/rpc-tests/wallet_import_export.py
Outdated
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.
We should test importing a key with z_importkey before exporting with z_exportwallet; those keys should only have two parameters.
Zcash: modified for zip32
Zcash: modified for zip32
…Null() Zcash: modified for zip32
51c1c3d to
b37dc4e
Compare
|
Addressed @str4d's comments |
| { | ||
| AssertLockHeld(cs_wallet); // mapZKeyMetadata | ||
| AssertLockHeld(cs_wallet); // mapSproutZKeyMetadata | ||
| // TODO: Add Sapling support |
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.
Is this comment now stale?
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.
Yes it is, as we now use separate functions to generate Sprout and Sapling keys.
str4d
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.
ut(ACK+cov)
| // Don't throw error in case a key is already there | ||
| auto addr = sk.address(); | ||
| if (log){ | ||
| LogPrint("zrpc", "Importing zaddr %s...\n", EncodePaymentAddress(addr)); |
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.
Nit: this log line now always gets printed, instead of only when importing.
| auto addr = sk.DefaultAddress(); | ||
| { | ||
| if (log){ | ||
| LogPrint("zrpc", "Importing zaddr %s...\n", EncodePaymentAddress(addr)); |
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.
Ditto.
|
@zkbot r+ |
|
📌 Commit b37dc4e has been approved by |
Add Sapling support to z_importwallet and z_exportwallet Includes code adapted from upstream PR bitcoin/bitcoin#8323 Closes #3218.
Includes code adapted from upstream PR bitcoin/bitcoin#8323
Closes #3218.