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

fix(rpc): Add getblock RPC fields to support the latest version of zcash/lightwalletd #6134

Merged
merged 5 commits into from
Feb 14, 2023

Conversation

teor2345
Copy link
Contributor

@teor2345 teor2345 commented Feb 10, 2023

Motivation

The latest version of zcash/lightwalletd expects the getblock response to always contain the block hash field:
https://github.com/zcash/lightwalletd/blob/5d174f7feb702dc19aec5b09d8be8b3d5b17ce45/common/common.go#L282

This PR gets the hash if needed, using a state index lookup.

Close #6085.

Specifications

"hash" : "hash", (string) the block hash (same as provided hash)

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

The height to hash lookup isn't specified, but we can assume they want the hash at that height on the best chain.

Complex Code or Requirements

For consistency even if the chain changes, we look up the block hash first, then use the hash to look up the transaction IDs and block confirmations.

Solution

  • Stabilise the BestChainBlockHash state request
    • previously, it was behind the getblockchain-rpcs feature, but we need it for the hash lookup in production RPCs
  • Always include the block hash in the getblock RPC response
    • Since we always have the hash, it's easy to always get confirmations as well

Testing:

  • Update existing test vectors to always require the hash and confirmations fields
  • Update snapshots
  • Update lightwalletd integration test to work with zcash/lightwalletd

I manually checked that zcash/lightwalletd works with Zebra's integration tests. (In CI we use adityapk00/lightwalletd.)

Review

We might want to get this in the next release, but it's not a blocker.

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

We might want to test both lightwalletd forks in CI, to avoid issues like this in future.
@gustavovalverde can you put this in the CI review doc?

@teor2345 teor2345 added C-bug Category: This is a bug A-consensus Area: Consensus rule updates P-Medium ⚡ A-rpc Area: Remote Procedure Call interfaces A-state Area: State / database changes lightwalletd any work associated with lightwalletd A-compatibility Area: Compatibility with other nodes or wallets, or standard rules labels Feb 10, 2023
@teor2345 teor2345 self-assigned this Feb 10, 2023
@teor2345 teor2345 requested a review from a team as a code owner February 10, 2023 01:17
@teor2345 teor2345 requested review from upbqdn and removed request for a team February 10, 2023 01:17
@teor2345 teor2345 changed the title fix(rpc): Support the latest version of zcash/lightwalletd fix(rpc): Add getblock RPC fields to support the latest version of zcash/lightwalletd Feb 10, 2023
@codecov
Copy link

codecov bot commented Feb 10, 2023

Codecov Report

Merging #6134 (2f54a52) into main (4f28929) will decrease coverage by 0.11%.
The diff coverage is 53.19%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6134      +/-   ##
==========================================
- Coverage   78.14%   78.03%   -0.11%     
==========================================
  Files         304      304              
  Lines       39087    39125      +38     
==========================================
- Hits        30546    30533      -13     
- Misses       8541     8592      +51     

@teor2345 teor2345 requested review from arya2 and removed request for upbqdn February 12, 2023 20:32
Copy link
Contributor

@arya2 arya2 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 to me! Thank you for fixing this.

Is the 'A-consensus' label correct? (is it for the confirmations field?)

zebra-state/src/request.rs Show resolved Hide resolved
@teor2345
Copy link
Contributor Author

This blocks our next Zebra release because we want to be able to support this bug fix in lightwalletd:
adityapk00/lightwalletd#13

For the Zebra team: this is an example of a race condition where using a hash rather than a height matters.

@teor2345
Copy link
Contributor Author

Is the 'A-consensus' label correct? (is it for the confirmations field?)

I could go either way, it fixes a consensus bug in lightwalletd, but it's not really consensus-critical in Zebra. It's just re-using existing consensus rule implementations.

Feel free to take it off if you'd like?

mergify bot added a commit that referenced this pull request Feb 14, 2023
@mergify mergify bot merged commit ae21e36 into main Feb 14, 2023
@mergify mergify bot deleted the fix-get-block-lightwalletd branch February 14, 2023 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-compatibility Area: Compatibility with other nodes or wallets, or standard rules A-consensus Area: Consensus rule updates A-rpc Area: Remote Procedure Call interfaces A-state Area: State / database changes C-bug Category: This is a bug lightwalletd any work associated with lightwalletd
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Zebra returns "error: could not convert the input string to a hash or height" with zcash/lightwalletd
2 participants