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 submitblock RPC method #5526

Merged
merged 20 commits into from
Nov 4, 2022
Merged

change(rpc): add submitblock RPC method #5526

merged 20 commits into from
Nov 4, 2022

Conversation

arya2
Copy link
Contributor

@arya2 arya2 commented Nov 1, 2022

Motivation

Introduces basic support for the submitblock rpc method used by mining pools.

Closes #5236 as part of #5234

Designs

Data flow diagram

Specifications

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

Solution

  • Add field for the block verifier to the GetBlockTemplateRpcImpl struct
  • Call the block verifier with the submitted block

Review

This PR is 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?
  • How do you know it works? Does it have tests?

Follow Up Work

@arya2 arya2 added A-rust Area: Updates to Rust code C-enhancement Category: This is an improvement P-Medium ⚡ A-rpc Area: Remote Procedure Call interfaces C-feature Category: New features labels Nov 1, 2022
@arya2 arya2 requested a review from a team as a code owner November 1, 2022 19:59
@arya2 arya2 requested review from dconnolly and removed request for a team November 1, 2022 19:59
@arya2 arya2 changed the title adds submitblock rpc method change(rpc): add submitblock RPC method Nov 1, 2022
@arya2 arya2 requested review from teor2345, oxarbitrage and a team and removed request for dconnolly November 1, 2022 20:05
@arya2 arya2 force-pushed the submitblock branch 2 times, most recently from 60ec68d to 618a33d Compare November 1, 2022 20:14
@arya2 arya2 mentioned this pull request Nov 1, 2022
@codecov
Copy link

codecov bot commented Nov 1, 2022

Codecov Report

Merging #5526 (2ebe202) into main (34313b8) will increase coverage by 0.08%.
The diff coverage is 50.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5526      +/-   ##
==========================================
+ Coverage   78.76%   78.85%   +0.08%     
==========================================
  Files         305      305              
  Lines       38114    38116       +2     
==========================================
+ Hits        30022    30057      +35     
+ Misses       8092     8059      -33     

@teor2345
Copy link
Contributor

teor2345 commented Nov 2, 2022

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Nov 2, 2022

update

✅ Branch has been successfully updated

@teor2345
Copy link
Contributor

teor2345 commented Nov 2, 2022

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Nov 2, 2022

update

✅ Branch has been successfully updated

@teor2345
Copy link
Contributor

teor2345 commented Nov 2, 2022

Looks great!

I think we might need to fix a few things before we merge:

  • use the null JSON value rather than the string "null" for Accepted blocks
  • add a snapshot test that submits an invalid block (an empty vector is ok!)

I also opened a PR with a refactor that simplifies this code a bit, with some minor doc bug fixes:

@teor2345
Copy link
Contributor

teor2345 commented Nov 2, 2022

Here are some details:

I think submit_block::Response::Accepted will return a JSON string:
https://docs.rs/serde_json/latest/src/serde_json/ser.rs.html#213

"null"

But what is actually expected is the JSON null value:
https://docs.rs/serde_json/latest/src/serde_json/ser.rs.html#203

null

It looks like the easiest way to generate a null is by returning a Result<Option<RejectionReason>> from the RPC, and making Accepted into Ok(None):
https://docs.rs/serde_json/latest/src/serde_json/ser.rs.html#270

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.

I think it looks great. I added a few minor comments while the only really blocking is the test failure.

I was not able to run submitblock test locally yet but i will.

zebra-rpc/src/methods/get_block_template_rpcs.rs Outdated Show resolved Hide resolved
zebra-rpc/src/methods/tests/snapshot.rs Outdated Show resolved Hide resolved
zebra-rpc/src/methods/tests/vectors.rs Show resolved Hide resolved
zebrad/tests/common/getblocktemplate.rs Outdated Show resolved Hide resolved
zebrad/tests/acceptance.rs Show resolved Hide resolved
@arya2
Copy link
Contributor Author

arya2 commented Nov 2, 2022

use the null JSON value rather than the string "null" for Accepted blocks

🤦 Oops.

It looks like the easiest way to generate a null is by returning a Result<Option>

I used an untagged enum which behaves the same way, let me know if you think Option makes more sense.

add a snapshot test that submits an invalid block (an empty vector is ok!)

The empty hexdata gives a deserialization error. 😐 I could try using Mainnet and BAD_BLOCK_MAINNET_202_BYTES (https://github.com/ZcashFoundation/zebra/blob/v1.0.0-rc.0/zebra-test/src/vectors/block.rs#L337) if that's more in line with what you had in mind.

@teor2345
Copy link
Contributor

teor2345 commented Nov 2, 2022

add a snapshot test that submits an invalid block (an empty vector is ok!)

The empty hexdata gives a deserialization error. 😐 I could try using Mainnet and BAD_BLOCK_MAINNET_202_BYTES (https://github.com/ZcashFoundation/zebra/blob/v1.0.0-rc.0/zebra-test/src/vectors/block.rs#L337) if that's more in line with what you had in mind.

Both tests seem good!

Let's name the snapshot files after the kind of failure we expect?

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!

There are a bunch of minor changes we can do, but none of them are blockers.

I've made some suggestions for cleaning up the acceptance test, but I'd like to deal with any further revisions in another PR. (When we do #5015 for this acceptance test.)

zebra-rpc/src/methods/get_block_template_rpcs.rs Outdated Show resolved Hide resolved
zebra-rpc/src/methods/tests/vectors.rs Outdated Show resolved Hide resolved
zebra-rpc/src/server.rs Outdated Show resolved Hide resolved
zebrad/tests/acceptance.rs Show resolved Hide resolved
zebra-rpc/src/methods/get_block_template_rpcs.rs Outdated Show resolved Hide resolved
zebrad/tests/common/get_block_template_rpcs.rs Outdated Show resolved Hide resolved
zebrad/tests/common/get_block_template_rpcs.rs Outdated Show resolved Hide resolved
zebrad/tests/common/get_block_template_rpcs.rs Outdated Show resolved Hide resolved
zebrad/tests/common/get_block_template_rpcs.rs Outdated Show resolved Hide resolved
zebrad/tests/common/get_block_template_rpcs.rs Outdated Show resolved Hide resolved
@oxarbitrage
Copy link
Contributor

please fix conflicts, thanks :)

zebra-rpc/src/errors.rs Outdated Show resolved Hide resolved
oxarbitrage
oxarbitrage previously approved these changes Nov 3, 2022
zebra-rpc/src/errors.rs Outdated Show resolved Hide resolved
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.

Is the RPC JSON response in the expected format?

All my other suggestions are optional.

…nd removes the unrelated make_server_error refactor for now
@arya2
Copy link
Contributor Author

arya2 commented Nov 4, 2022

Is the RPC JSON response in the expected format?

They are, but the snapshot test was not.

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!

@teor2345
Copy link
Contributor

teor2345 commented Nov 4, 2022

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Nov 4, 2022

update

✅ Branch has been successfully updated

@mergify mergify bot merged commit 2f3b05f into main Nov 4, 2022
@mergify mergify bot deleted the submitblock branch November 4, 2022 03:57
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 A-rust Area: Updates to Rust code C-enhancement Category: This is an improvement C-feature Category: New features C-trivial Category: A trivial change that is not worth mentioning in the CHANGELOG
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add basic support for the submitblock RPC call
3 participants