-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Sapling support for z_listunspent #3510
Conversation
@LarryRuane What needs to be added to the rpc test? Any blockers? PR might need a rebase too. |
@bitcartel @arcalinea, I rebased to latest master (but not pushed to github yet), so the test can do the (necessary) I can't test setting the So I think the test is good, but it may be finding an actual pre-Sapling bug relating to So I've written a minimal test to demonstrate this bug (if it is a bug). Interestingly, But I probably should go ahead right now and push (to Jay's branch) the test as it is (cleaned up), which does test Sapling |
@LarryRuane Go for it and please continue investigation. I'm testing and fiddling with the other PR right now, z_listreceivedbyaddress, and pushed some commits there. |
@bitcartel I just pushed (not forced) my updates to the RPC test (to this PR). |
src/wallet/rpcwallet.cpp
Outdated
libzcash::SproutPaymentAddress addr = boost::get<libzcash::SproutPaymentAddress>(zaddr); | ||
if (!fIncludeWatchonly && !pwalletMain->HaveSproutSpendingKey(addr)) { | ||
// TODO: Add visitor to handle support for Sprout and Sapling addrs. | ||
if (boost::get<libzcash::SproutPaymentAddress>(&zaddr) != nullptr){ |
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.
should there be 4-space indenting here (and in other places)?
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 can list sapling notes, but a few tweaks needed:
- Rebase onto master (I did this locally, you just need some minor fixes)
- Change "jsoutindex" to "outindex" for Sapling shielded outputs
- When calling
z_listunspent 0
, the output note has not been confirmed yet, but it still shows as being spendable, even though it cannot be spent until it has been confirmed (I can't recall if this same issue impacts Sprout shielded notes or not)
"confirmations": 0,
"spendable": true,
- The change flag is always false
As for comment #3, the same issue should have affected Sprout txs before as well, because |
@arcalinea Thanks, sound like its fine as is if |
So by adding |
@arcalinea I don't think it's essential since it should be obvious from looking at the address. Could be something we add later in a future release. |
I tried testing but ran into errors importing an extended spending key. I think this PR needs a rebase. |
bd603fd
to
e10ec0f
Compare
@bitcartel I just force-pushed a rebase with zcash master. The new rpc test added as part of this PR, Once #3499 is merged, we may want to combine their (currently separate) rpc unit tests, or at least make them more consistent. |
@zkbot try |
Sapling support for z_listunspent Needs to be rebased on master, after Larry adds rest of the RPC test Closes #3378.
☀️ Test successful - pr-try |
@@ -2473,7 +2473,8 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) | |||
" {\n" | |||
" \"txid\" : \"txid\", (string) the transaction id \n" | |||
" \"jsindex\" : n (numeric) the joinsplit index\n" | |||
" \"jsoutindex\" : n (numeric) the output index of the joinsplit\n" | |||
" \"jsoutindex\" (sprout) : n (numeric) the output index of the joinsplit\n" | |||
" \"outindex\" (sapling) : n (numeric) the output index\n" |
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.
Do we need to say something to indicate that you will get either one or the other of these two fields?
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.
Should be fine as is (for now).
@@ -2463,7 +2463,7 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) | |||
"1. minconf (numeric, optional, default=1) The minimum confirmations to filter\n" | |||
"2. maxconf (numeric, optional, default=9999999) The maximum confirmations to filter\n" | |||
"3. includeWatchonly (bool, optional, default=false) Also include watchonly addresses (see 'z_importviewingkey')\n" | |||
"4. \"addresses\" (string) A json array of zaddrs to filter on. Duplicate addresses not allowed.\n" | |||
"4. \"addresses\" (string) A json array of zaddrs (both Sprout and Sapling) to filter on. Duplicate addresses not allowed.\n" |
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.
IMO the default should be both Sprout and Sapling and we should only say something if this is not the case.
src/wallet/rpcwallet.cpp
Outdated
assert(boost::get<libzcash::SproutPaymentAddress>(&zaddr) != nullptr); | ||
libzcash::SproutPaymentAddress addr = boost::get<libzcash::SproutPaymentAddress>(zaddr); | ||
if (!fIncludeWatchonly && !pwalletMain->HaveSproutSpendingKey(addr)) { | ||
// TODO: Add visitor to handle support for Sprout and Sapling addrs. |
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 this particular case, this has already been done see class HaveSpendingKeyForPaymentAddress : public boost::static_visitor<bool>
in wallet.h
It would be good to reuse that below as this could replace this whole if .. else if .. else block.
src/wallet/rpcwallet.cpp
Outdated
@@ -2583,7 +2603,27 @@ UniValue z_listunspent(const UniValue& params, bool fHelp) | |||
} | |||
results.push_back(obj); | |||
} | |||
|
|||
// TODO: Sapling |
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 comment can be removed.
Yes, I will back it out, give me a minute; I didn't realize use of that visitor had been added. UPDATE: it's now backed out. |
9448204
to
5f57bab
Compare
assert_equal(1, len(unspent_cb)) | ||
assert_equal(False, unspent_cb[0]['change']) | ||
assert_equal(txid_1, unspent_cb[0]['txid']) | ||
assert_equal(True, unspent_cb[0]['spendable']) |
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.
Just to note: There is assert_true
and assert_false
in util.py
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, didn't know about that. I think in this case it's more consistent to keep it as-is because then all the assertions in this group have the same format: compare an expected value with an actual value. Less thinking for the reader.
obj.push_back(Pair("spendable", hasSaplingSpendingKey)); | ||
obj.push_back(Pair("address", EncodePaymentAddress(entry.address))); | ||
obj.push_back(Pair("amount", ValueFromAmount(CAmount(entry.note.value())))); // note.value() is equivalent to plaintext.value() | ||
obj.push_back(Pair("memo", HexStr(entry.memo))); |
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 sprout we do:
std::string data(entry.plaintext.memo().begin(), entry.plaintext.memo().end());
obj.push_back(Pair("memo", HexStr(data)));
Sapling note entry memo is defined as std::array<unsigned char, ZC_MEMO_SIZE> memo;
Sprout note entry plain plaintext memo is defined as std::array<unsigned char, ZC_MEMO_SIZE> memo_;
In sapling we just pass in the memo without making a string of it. Is this correct?
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, should be correct with the end result being the same. The Sprout code path could be simplified with HexStr(entry.plaintext.memo())
:
Line 103 in 0f091f2
inline std::string HexStr(const T& vch, bool fSpaces=false) |
Line 105 in 0f091f2
return HexStr(vch.begin(), vch.end(), fSpaces); |
# but this requires Sapling support for those RPCs | ||
|
||
if __name__ == '__main__': | ||
WalletListNotes().main() |
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.
My comment on this test is that we seem to be testing a lot of the sprout logic (Which I would expect to be tested elsewhere). We do not test the sapling note change logic (but I think this is tested as part of the update to z_listreceivedbyarrdess), we do not test that we use outindex rather than jsindex/jsoutindex, and we do not test the memo field. These are the differences between sprout/sapling, and therefore, I was expecting them to be tested.
That being said, in the cpp file these look good. Please look at the comment regarding the memo and once that is verified this should be ackable.
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.
Filed #3562
utACK |
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.
NACK per this comment:
@arcalinea & @LarryRuane Has it been ensured that other tests exercise this new Sapling flow, if it is needed?
Specifically:
BOOST_AUTO_TEST_CASE(rpc_z_listunspent_parameters)
wallet_protectcoinbase.py
In regards to |
@LarryRuane Did you put your improvements into a new PR so we don't forget? |
@zkbot r+ |
📌 Commit 5f57bab has been approved by |
⌛ Testing commit 5f57bab with merge 38446a44e83795775e1b61079a9fa25854c0dce8... |
💔 Test failed - pr-merge |
Two test failures:
|
I'm taking a look at those failures |
ACK on the fix commit. Also @LarryRuane has locally verified that the qa tests pass with the fix above. @zkbot r+ |
📌 Commit 27a6a99 has been approved by |
Sapling support for z_listunspent Closes #3378.
Closes #3378.