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

feat(rpc): introduce getblocktemplate-rpcs feature #5357

Merged
merged 12 commits into from Oct 19, 2022
Merged

feat(rpc): introduce getblocktemplate-rpcs feature #5357

merged 12 commits into from Oct 19, 2022

Conversation

oxarbitrage
Copy link
Contributor

@oxarbitrage oxarbitrage commented Oct 6, 2022

Motivation

We want to support mining rpc calls but as an isolated rust feature. Can close #5305 with some more work. It also implement partially get_block_count (#5303) so we can have something to test with.

Also closes #5303.

Solution

PR attempts to do the supertrait suggested implementation. It looks good and we can make tests but something is missing. When calling the rpc with curl:

$ curl --silent --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblockcount", "params": [] }' -H 'Content-type: application/json' http://127.0.0.1:8232/ | jq
{
  "error": {
    "code": -32601,
    "message": "Method not found"
  },
  "id": "curltest"
}
$ 

Review

I will like @teor2345 to take a look

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

@github-actions github-actions bot added the C-feature Category: New features label Oct 6, 2022
@teor2345 teor2345 added the do-not-merge Tells Mergify not to merge this PR label Oct 6, 2022
@teor2345
Copy link
Contributor

teor2345 commented Oct 6, 2022

New features are blocked until we tag the first release candidate.

@codecov
Copy link

codecov bot commented Oct 6, 2022

Codecov Report

Merging #5357 (3891e77) into main (7207f9d) will decrease coverage by 0.13%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5357      +/-   ##
==========================================
- Coverage   79.19%   79.06%   -0.14%     
==========================================
  Files         308      308              
  Lines       39560    39289     -271     
==========================================
- Hits        31329    31062     -267     
+ Misses       8231     8227       -4     

@oxarbitrage
Copy link
Contributor Author

Why the optional tag was added if as far as i know it was decided we want to have the mining calls in a feature ?

I think the optional tag discourage developers to keep working on a pull request when used unilaterally as it has been done here (and pretty much everywhere else).

@teor2345
Copy link
Contributor

Why the optional tag was added if as far as i know it was decided we want to have the mining calls in a feature ?

I added the optional tag because this work isn't scheduled for this sprint, and we have the release candidate and getblocktemplate analysis work as a higher priority.

I added the "do not merge" tag because we can't merge new features until we've tagged the release candidate.

Sorry I didn't explain that to start with, I've been busy trying to fix CI and get the release candidate working.

@teor2345
Copy link
Contributor

teor2345 commented Oct 10, 2022

It looks good and we can make tests but something is missing.

When the getblocktemplate-rpcs feature is activated, we need to start the server using the GetBlockTemplateRpc implementation:

let (rpc_impl, rpc_tx_queue_task_handle) = RpcImpl::new(

I'm guessing you did this already, but we also need to compile zebrad with --features getblocktemplate-rpcs.

@teor2345
Copy link
Contributor

I'm guessing you did this already, but we also need to compile zebrad with --features getblocktemplate-rpcs.

This might need a getblocktemplate-rpcs feature on zebrad as well, here's how you set it up:

proptest-impl = ["proptest", "proptest-derive", "zebra-chain/proptest-impl", "zebra-state/proptest-impl", "zebra-consensus/proptest-impl", "zebra-network/proptest-impl"]

@oxarbitrage
Copy link
Contributor Author

The do not merge is enough here for knowing we can't merge into main for the release candidate. I removed the optional because i think it is not.

@teor2345 teor2345 removed the do-not-merge Tells Mergify not to merge this PR label Oct 13, 2022
@teor2345
Copy link
Contributor

We tagged the release candidate, so new features can merge now.

Can you add a priority label to this ticket?

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, looking forward to getting it working!

zebra-rpc/src/methods/getblocktemplate.rs Outdated Show resolved Hide resolved
zebra-rpc/src/methods/getblocktemplate.rs Outdated Show resolved Hide resolved
zebra-rpc/Cargo.toml Show resolved Hide resolved
zebra-rpc/src/methods/tests/vectors.rs Outdated Show resolved Hide resolved
zebra-rpc/src/methods/tests/vectors.rs Show resolved Hide resolved
zebra-rpc/src/methods.rs Show resolved Hide resolved
@teor2345
Copy link
Contributor

This new RPC needs a snapshot test and a manual zcash-rpc-diff test.

Can you post the results of zcash-rpc-diff as a comment on this PR?

zebra-rpc/src/server.rs Outdated Show resolved Hide resolved
@oxarbitrage
Copy link
Contributor Author

oxarbitrage commented Oct 13, 2022

I highligthed the issue a bit more in b1a6918 and added comments about it at #5357 (review)

@oxarbitrage
Copy link
Contributor Author

Diffs are different because zcashd and zebrad are at different heights locally.

$ ./zcash-rpc-diff 6666 getblockcount
Checking first node release info...
Checking second node release info...
Connected to zebrad (port 6666) and zcashd (zcash-cli zcash.conf port).

Checking zebrad network and tip height...
Checking zcashd network and tip height...

WARNING: comparing RPC responses from different heights:
zcashd is at: 15784
zebrad is at: 88152

Request:
getblockcount

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

real	0m0,002s
user	0m0,001s
sys	0m0,000s

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

real	0m0,002s
user	0m0,001s
sys	0m0,000s


Response diff between zcashd and zebrad:
--- /tmp/tmp.bWNHZfXNvz.rpc-diff/zebrad-main-88152-getblockcount.json	2022-10-17 17:12:54.993989666 -0300
+++ /tmp/tmp.bWNHZfXNvz.rpc-diff/zcashd-main-15784-getblockcount.json	2022-10-17 17:12:54.993989666 -0300
@@ -1 +1 @@
-88152
+15784
$ 

@oxarbitrage
Copy link
Contributor Author

Output of zebra when quering the getblockcount method in a build with no getblocktemplate-rpcs feature:

$ curl --silent --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblockcount", "params": [] }' -H 'Content-type: application/json' http://127.0.0.1:8232/ | jq
{
  "error": {
    "code": 0,
    "message": "RPC method is not implemented for zebra builds without `getblocktemplate-rpcs` feature"
  },
  "id": "curltest"
}

The same call but in a build with getblocktemplate-rpcs feature:

$ curl --silent --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getblockcount", "params": [] }' -H 'Content-type: application/json' http://127.0.0.1:8232/ | jq
{
  "result": 84896,
  "id": "curltest"
}

@oxarbitrage oxarbitrage marked this pull request as ready for review October 17, 2022 21:29
@oxarbitrage oxarbitrage requested a review from a team as a code owner October 17, 2022 21:29
@oxarbitrage oxarbitrage requested review from arya2 and removed request for a team October 17, 2022 21:29
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.

This looks great, thank you!

It may be worth initializing a second object with the fields we need in order to separate the new code into a second trait definition at some point, but I think we can move forward with this for now.

I suggested a fix to a small typo, and we should promptly follow-up with #5405 because there are sometimes issues in CI that we don't see locally.

zebra-rpc/src/methods/tests/vectors.rs Outdated Show resolved Hide resolved
zebra-rpc/src/methods/tests/vectors.rs Outdated Show resolved Hide resolved
arya2
arya2 previously approved these changes Oct 18, 2022
Co-authored-by: Arya <aryasolhi@gmail.com>
@oxarbitrage
Copy link
Contributor Author

Thanks @arya2 , i added the suggested typo fix. Can you re approve ? Thanks.

arya2
arya2 previously approved these changes Oct 18, 2022
zebra-rpc/src/methods.rs Outdated Show resolved Hide resolved
* adds minimal new object for the get block template methods

* updated TODO comment
mergify bot added a commit that referenced this pull request Oct 19, 2022
@mergify mergify bot merged commit d81a5fc into main Oct 19, 2022
@mergify mergify bot deleted the issue5305 branch October 19, 2022 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature Category: New features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a getblocktemplate-rpcs feature to zebra-rpc Add support for getblockcount RPC call
4 participants