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): Return from long polling immediately when the chain tip changes #5862

Merged
merged 11 commits into from
Dec 15, 2022

Conversation

teor2345
Copy link
Contributor

Motivation

Miners want to start mining on the new tip immediately, to avoid wasted hash power and chain forks.

Closes #5720

Depends-On: #5843

Complex Code or Requirements

This PR uses the block consensus rules - changing the previous block hash or block time makes previous work invalid.

It also changes the tokio watch channel API, and does some complex future implementations. (But mainly for testing.)

Solution

Related changes:

Review

Anyone can review this PR, it's mostly changes to trait implementations and a select!{} loop.

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

I think we're done here, we're doing what miners have told us is their top priority.

@teor2345 teor2345 added A-consensus Area: Consensus rule updates C-enhancement Category: This is an improvement P-Medium ⚡ I-slow Problems with performance or responsiveness A-rpc Area: Remote Procedure Call interfaces A-state Area: State / database changes A-concurrency Area: Async code, needs extra work to make it work properly. labels Dec 14, 2022
@teor2345 teor2345 self-assigned this Dec 14, 2022
@teor2345 teor2345 marked this pull request as ready for review December 14, 2022 03:19
@teor2345 teor2345 requested a review from a team as a code owner December 14, 2022 03:19
@teor2345 teor2345 requested review from arya2 and removed request for a team December 14, 2022 03:19
@teor2345 teor2345 marked this pull request as draft December 14, 2022 03:19
@teor2345
Copy link
Contributor Author

I need to write tests before we merge this PR.

@codecov
Copy link

codecov bot commented Dec 14, 2022

Codecov Report

Merging #5862 (7ac98eb) into main (f7011a9) will decrease coverage by 0.15%.
The diff coverage is 0.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5862      +/-   ##
==========================================
- Coverage   78.47%   78.32%   -0.16%     
==========================================
  Files         308      308              
  Lines       38709    38757      +48     
==========================================
- Hits        30378    30355      -23     
- Misses       8331     8402      +71     

@teor2345
Copy link
Contributor Author

The test failures are in the snapshots:

     38 │+  "submitold": null

https://github.com/ZcashFoundation/zebra/actions/runs/3691441568/jobs/6249438736#step:14:2473

submitold should be missing when it's None, rather than null. I'll fix this tomorrow.

I think I need to add #[serde(skip_serializing_if = "Option::is_none()")] and #[serde(default = "Option::None")]. And then check it doesn't serialize as Some(true):
https://serde.rs/field-attrs.html#skip_serializing_if
https://docs.rs/serde_with/latest/serde_with/attr.skip_serializing_none.html

@mpguerra
Copy link
Contributor

Can we evaluate this change in terms of how it will affect the code to be audited?

We had talked about keeping the getblocktemplate work self contained as much as possible so it didn't affect the stable release candidate series. This change might be fine as it's just making additions and not changing existing functionality in zebra-state and zebra-chain but I would just like us to be mindful of this.

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.

Good call adding submitold and the mark_as_seen method on ChainTip.

zebra-state/src/service/chain_tip.rs Show resolved Hide resolved
@arya2
Copy link
Contributor

arya2 commented Dec 14, 2022

Can we evaluate this change in terms of how it will affect the code to be audited?

We had talked about keeping the getblocktemplate work self contained as much as possible so it didn't affect the stable release candidate series. This change might be fine as it's just making additions and not changing existing functionality in zebra-state and zebra-chain but I would just like us to be mindful of this.

We should mark all of the new code here with #[cfg(feature = "getblocktemplate-rpcs")] too.

@teor2345
Copy link
Contributor Author

Can we evaluate this change in terms of how it will affect the code to be audited?
We had talked about keeping the getblocktemplate work self contained as much as possible so it didn't affect the stable release candidate series. This change might be fine as it's just making additions and not changing existing functionality in zebra-state and zebra-chain but I would just like us to be mindful of this.

We should mark all of the new code here with #[cfg(feature = "getblocktemplate-rpcs")] too.

There are only around 30 lines of added production code in this PR. The rest is comments, code that's already inside the feature, or tests.

I'm happy to put that code behind the feature after I write some tests. Just in case the API needs to change for the tests.

But I just wanted to let you know that it won't impact a significant amount of code. (A single hex serialisation implementation is larger, and we've been leaving them outside the feature.)

@teor2345
Copy link
Contributor Author

The test failures are in the snapshots:

     38 │+  "submitold": null

https://github.com/ZcashFoundation/zebra/actions/runs/3691441568/jobs/6249438736#step:14:2473

submitold should be missing when it's None, rather than null. I'll fix this tomorrow.

I think I need to add #[serde(skip_serializing_if = "Option::is_none()")] and #[serde(default = "Option::None")]. And then check it doesn't serialize as Some(true): https://serde.rs/field-attrs.html#skip_serializing_if https://docs.rs/serde_with/latest/serde_with/attr.skip_serializing_none.html

In 9a34243 I fixed the field serialization, made a separate snapshot that includes a submit old field, and changed the deserialized coinbase transaction format to RON. (Using JSON was a bit confusing due to the nulls.)

@teor2345
Copy link
Contributor Author

There are only around 30 lines of added production code in this PR.

Arya made a suggestion, and we're now down to around 20 lines of added production code. At this point, I don't think it matters if it is behind a feature. (But I'm happy to do that.)

@teor2345 teor2345 requested a review from arya2 December 14, 2022 23:36
@arya2
Copy link
Contributor

arya2 commented Dec 15, 2022

At this point, I don't think it matters if it is behind a feature. (But I'm happy to do that.)

I don't think so either.

This looks good to me if it's ready for review.

@teor2345
Copy link
Contributor Author

This looks good to me if it's ready for review.

I think it still needs more tests, even if they have to be manual tests, I want to do them.

Base automatically changed from wait-on-long-poll to main December 15, 2022 00:30
@teor2345 teor2345 force-pushed the async-state-long-poll branch from e72d0eb to 7ac98eb Compare December 15, 2022 07:26
@teor2345 teor2345 marked this pull request as ready for review December 15, 2022 07:26
@teor2345
Copy link
Contributor Author

I am happy with this PR, I did some tests as part of PR #5867. We can continue to test long polling in ticket #5686.

@mergify mergify bot merged commit 80a6d3c into main Dec 15, 2022
@mergify mergify bot deleted the async-state-long-poll branch December 15, 2022 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-concurrency Area: Async code, needs extra work to make it work properly. A-consensus Area: Consensus rule updates A-rpc Area: Remote Procedure Call interfaces A-state Area: State / database changes C-enhancement Category: This is an improvement I-slow Problems with performance or responsiveness
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support long polling in the getblocktemplate RPC (excluding mempool changes)
3 participants