Skip to content
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

change(rpc): add validateaddress method #6086

Merged
merged 9 commits into from
Feb 3, 2023
Merged

change(rpc): add validateaddress method #6086

merged 9 commits into from
Feb 3, 2023

Conversation

arya2
Copy link
Contributor

@arya2 arya2 commented Feb 1, 2023

Motivation

Mining pools may use this RPC to check addresses.

Closes #5722.

This method returns isvalid: false in zcashd for shielded addresses, it currently checks Sapling addresses in Zebra but not Sprout, Orchard, or Unified addresses.

Specifications

https://zcash.github.io/rpc/validateaddress.html

Solution

  • Add zcash_address to parse raw address
  • Add Address enum in zebra-chain for converting ZcashAddress
  • Add response type for validate address

Review

Part of regular scheduled work.

Reviewer Checklist

  • Will the PR name make sense to users?
    • Does it need extra CHANGELOG info? (new features, breaking changes, large changes)
  • Are the PR labels correct?
  • Does the code do what the ticket and PR says?
    • Does it change concurrent code, unsafe code, or consensus rules?
  • How do you know it works? Does it have tests?

Follow Up Work

  • Add support for Sprout/Orchard/Unified addresses in primitives::Address
  • Add pubkey and scriptPubKey fields

@arya2 arya2 added C-enhancement Category: This is an improvement P-Medium ⚡ A-rpc Area: Remote Procedure Call interfaces labels Feb 1, 2023
@arya2 arya2 self-assigned this Feb 1, 2023
@arya2 arya2 requested review from a team as code owners February 1, 2023 22:36
@arya2 arya2 requested review from natalieesk and removed request for a team February 1, 2023 22:36
@github-actions github-actions bot added the C-feature Category: New features label Feb 1, 2023
@arya2 arya2 requested a review from teor2345 February 1, 2023 22:44
Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, I like the design here!

This method returns isvalid: false in zcashd for shielded addresses, it currently checks Sapling addresses in Zebra but not Sprout, Orchard, or Unified addresses.

I think we might want to match zcashd's behaviour for Sapling?

Otherwise nodes might try to build a transparent coinbase transaction with a Sapling address, which could cause them to fail or crash.

@teor2345
Copy link
Contributor

teor2345 commented Feb 1, 2023

Also there seems to be a merge conflict, can you rebase when you do your fixes?

@arya2
Copy link
Contributor Author

arya2 commented Feb 1, 2023

I think we might want to match zcashd's behaviour for Sapling?

I'm not sure and that's safer, so, fixed in fde96d5.

Also there seems to be a merge conflict, can you rebase when you do your fixes?

Yep, I resolved those too (albeit with a merge).

@arya2 arya2 requested a review from teor2345 February 1, 2023 23:28
@codecov
Copy link

codecov bot commented Feb 2, 2023

Codecov Report

Merging #6086 (a45bff8) into main (1b12011) will decrease coverage by 0.01%.
The diff coverage is n/a.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6086      +/-   ##
==========================================
- Coverage   78.06%   78.05%   -0.01%     
==========================================
  Files         304      304              
  Lines       39027    39027              
==========================================
- Hits        30465    30462       -3     
- Misses       8562     8565       +3     

teor2345
teor2345 previously approved these changes Feb 2, 2023
Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@teor2345 teor2345 dismissed their stale review February 2, 2023 03:24

Needs further testing

@teor2345
Copy link
Contributor

teor2345 commented Feb 2, 2023

Can you please do a zcash-rpc-diff for this new RPC?

(Maybe we should have a testing checklist somewhere.)

@arya2
Copy link
Contributor Author

arya2 commented Feb 2, 2023

Can you please do a zcash-rpc-diff for this new RPC?

Yep:

Request:
validateaddress t3hgskquvKKoCtvxw86yN7q8bzwRxNgUZmc

Querying zebrad main chain at height >=1970386...

real    0m0.002s
user    0m0.002s
sys     0m0.000s

Querying zcashd main chain at height >=1830188...

real    0m0.003s
user    0m0.000s
sys     0m0.002s


Response diff between zebrad and zcashd:
--- /tmp/tmp.CZTvJsjeXg.rpc-diff/zebrad-main-1970386-validateaddress.json       2023-02-02 16:02:12.119542563 -0500
+++ /tmp/tmp.CZTvJsjeXg.rpc-diff/zcashd-main-1830188-validateaddress.json       2023-02-02 16:02:12.129542563 -0500
@@ -1,5 +1,8 @@
 {
   "isvalid": true,
   "address": "t3hgskquvKKoCtvxw86yN7q8bzwRxNgUZmc",
+  "scriptPubKey": "a914fdaa2e848fa9813b6bbc7e5f8cbd9c0724dca7d087",
+  "ismine": false,
+  "iswatchonly": false,
   "isscript": true
 }
Request:
validateaddress zs1knzgnu5l7h62qexv8mwv8dysr9qum9e5mtxju7hazz9qk8cpgw5uf3c3qd4n62qhdfy7q53z2c0

Querying zebrad main chain at height >=1970389...

real    0m0.002s
user    0m0.002s
sys     0m0.000s

Querying zcashd main chain at height >=1830504...

real    0m0.002s
user    0m0.002s
sys     0m0.000s


Response diff between zebrad and zcashd:
RPC responses were identical

/tmp/tmp.DmkpELZsdx.rpc-diff/zebrad-main-1970389-validateaddress.json:
{
  "isvalid": false
}

This brought my attention to a mismatch where Zebra was returning conversion errors.

Fixed in a45bff8.

@arya2 arya2 requested a review from teor2345 February 2, 2023 21:05
Copy link
Contributor

@teor2345 teor2345 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the testing!

mergify bot added a commit that referenced this pull request Feb 3, 2023
@mergify mergify bot merged commit 0793eaf into main Feb 3, 2023
@mergify mergify bot deleted the add-validate-address branch February 3, 2023 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rpc Area: Remote Procedure Call interfaces C-enhancement Category: This is an improvement C-feature Category: New features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement validateaddress RPC
2 participants