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): Update getblock RPC to more closely match zcashd #9006

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

conradoplg
Copy link
Collaborator

@conradoplg conradoplg commented Nov 8, 2024

Motivation

Currently zebra has partial support for getblock() and it mostly targets lightwalletd usage. For zcashd deprecation we want it to match zcashd more closely.

Specifications & References

zcashd RPC docs

Solution

Based on #8967

Since getblock() returns basically a superset of getblockheader(), I change our getblock() to call getblockheader() for all the shared fields.

Work on returning the additional non-header fields will be done in separate PRs.

I also changed getblockheader() return codes since whatever error it returns is now returned by getblock(), and we have committed to error codes in our snapshots. I also added the -5 error code which can also be returned by zcashd.

Since the previous behaviour can be still useful for performance reasons, I moved it to be carried out when verbosity=3 is used. It would be a simple change to lightwalletd. I'm not sure about the specific number though, should we use something farther off?

This also adds ZEBRAD_EXTRA_ARGS to zcash-rpc-diff because I was stubborn and wanted to make it work with cookie authentication 😆 Let me know if you'd prefer it in a separate PR, but it seems simple enough.

Tests

I adjusted the existing vectors.rs tests and updated the snapshots. I also tested it manually and with zcash-rpc-diff; the current diff is that size, blockcommitments authdataroot, chainhistoryroot, chainwork anchor, chainSupply and valuePools are not yet being filled; and verbosity=2 is still the same as 1 (i.e. tx is not expanded)

Follow-up Work

  • Check which of the remaining fields are truly required (some of them are undocumented). I'll ask the deprecation group.
  • Created issues for the fields we are going to work on

Additional information to put in Changelog

### Performance Regression

The `getblock()` change described below will impact lightwalletd operators who
back it with Zebra. The initial sync performance will drop unless you change
the `getblock()` call to use `verbosity=3`. See below for details.

### Changed

- The `getblock()` RPC now supports all the fields also returned by `getblockheader()`.
  The old partial support is now moved to `verbosity=3`; it might be useful for
  lightwalletd if you want to keep the same initial sync performance as before
  (you will need to changed lightwalletd source code to use `verbosity=3`)

PR Author's Checklist

  • The PR name will make sense to users.
  • The PR provides a CHANGELOG summary.
  • The solution is tested.
  • The documentation is up to date.
  • The PR has a priority label.

PR Reviewer's Checklist

  • The PR Author's checklist is complete.
  • The PR resolves the issue.

@conradoplg conradoplg requested a review from a team as a code owner November 8, 2024 19:18
@conradoplg conradoplg requested review from oxarbitrage and removed request for a team November 8, 2024 19:18
@github-actions github-actions bot added the C-trivial Category: A trivial change that is not worth mentioning in the CHANGELOG label Nov 8, 2024
@conradoplg conradoplg added P-Medium ⚡ and removed C-trivial Category: A trivial change that is not worth mentioning in the CHANGELOG labels Nov 8, 2024
@github-actions github-actions bot added the C-trivial Category: A trivial change that is not worth mentioning in the CHANGELOG label Nov 8, 2024
@conradoplg conradoplg force-pushed the get-block branch 2 times, most recently from e3b050b to 618beb3 Compare November 8, 2024 19:33
@arya2 arya2 changed the title change(rpc): update getblock() to closer match zcashd change(rpc): Update getblock RPC to more closely match zcashd Nov 9, 2024
@arya2
Copy link
Contributor

arya2 commented Nov 9, 2024

This is looking good! I left some suggestions in #9008.

Since the previous behaviour can be still useful for performance reasons, I moved it to be carried out when verbosity=3 is used. It would be a simple change to lightwalletd. I'm not sure about the specific number though, should we use something farther off?

The new behaviour seems performant enough for lightwalletd to continue using verbosity = 1. I don't think we need to mention a performance regression in the changelog either.

The performance issue before (fixed in #5307) was that it was reading all of the block's transactions, the database queries added here should be quick, and, if they still have a measurable impact on lightwalletd sync performance, can be optimized easily (like by parallelizing or unifying state requests and maybe using an iterator to get the block hashes at height/height.next()) .

(Though we should make sure to cache block sizes by hash in a new column family when adding that field to avoid reading, deserializing, and then serializing the entire block to get its size.)

@mpguerra mpguerra linked an issue Nov 13, 2024 that may be closed by this pull request
Base automatically changed from get-block-header to main November 18, 2024 12:16
@mergify mergify bot requested a review from a team as a code owner November 18, 2024 12:16
@mergify mergify bot requested review from upbqdn and removed request for a team November 18, 2024 12:16
oxarbitrage
oxarbitrage previously approved these changes Nov 18, 2024
Copy link
Contributor

@oxarbitrage oxarbitrage left a comment

Choose a reason for hiding this comment

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

It looks good, i made a few comments and documentation suggestions.

zebra-rpc/src/methods.rs Outdated Show resolved Hide resolved
@@ -154,16 +157,19 @@ pub trait Rpc {
/// # Parameters
///
/// - `hash_or_height`: (string, required, example="1") The hash or height for the block to be returned.
/// - `verbosity`: (number, optional, default=1, example=1) 0 for hex encoded data, 1 for a json object, and 2 for json object with transaction data.
/// - `verbosity`: (number, optional, default=1, example=1) 0 for hex encoded data, 1 for a json object, and 2 for json object with transaction data, and 3 for a partially filled json object (which is faster and useful for lightwalletd-only usage)
Copy link
Contributor

Choose a reason for hiding this comment

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

I am confused here. I only see the verbosity cases 0, 1 and 2 in the method code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Initially I introduced a new verbosity but Arya pointed out that wasn't needed, and I forgot to update this. Thanks! Fixed in 1013611

solution: Some(solution),
bits: Some(bits),
difficulty: Some(difficulty),
// TODO
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain more what are the todo here and in the next ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure! I removed the TODOs in 1013611 to make it less confusing (I forgot to clean them up) but they are:

zebra-rpc/src/methods.rs Outdated Show resolved Hide resolved
zebra-rpc/src/methods.rs Show resolved Hide resolved
zebra-rpc/src/methods.rs Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-trivial Category: A trivial change that is not worth mentioning in the CHANGELOG P-Medium ⚡
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update getblock RPC method
3 participants