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 proposal capability to getblocktemplate #5870

Merged
merged 30 commits into from
Jan 11, 2023

Conversation

arya2
Copy link
Contributor

@arya2 arya2 commented Dec 15, 2022

Motivation

We want to support using the getblocktemplate RPC in proposal mode to use in our acceptance test.

Closes #5684.

Complex Code or Requirements

The new CheckValidBlock state request needs to check the block against all of the usual acceptance rules.

Solution

  • Add a state request that checks the contextual validity of a block by calling validate_and_commit with a clone of the non-finalized state
  • Use a request enum in the chain/block verifiers with a CheckProposal variant that skips checking the solution and calls the state with CheckValidBlock instead of CommitBlock
  • Check the mode and data fields of the getblocktemplate parameters
    • Deserialize the block bytes in the data field and call chain verifier with a CheckProposal request

Related changes:

  • Fixes formatting in prop tests for checks in state service
  • Accepts and ignores optional workid parameter

Review

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

@github-actions github-actions bot added C-enhancement Category: This is an improvement C-feature Category: New features labels Dec 15, 2022
@arya2 arya2 self-assigned this Dec 15, 2022
@arya2 arya2 added A-consensus Area: Consensus rule updates A-rust Area: Updates to Rust code P-Optional ✨ A-rpc Area: Remote Procedure Call interfaces labels Dec 15, 2022
@teor2345
Copy link
Contributor

@arya2 can you please rebase this PR on the latest main branch?

The diff currently shows changes from other PRs, which makes it hard to review.

@arya2 arya2 force-pushed the gbt-proposal-mode branch 3 times, most recently from ee8e0d2 to f7c5941 Compare December 15, 2022 23:47
@arya2 arya2 requested a review from conradoplg December 16, 2022 00:26
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!

This is a large and risky change, but if we make some changes we can do it without breaking production code, or diverging from the consensus rules.

zebra-consensus/src/block.rs Show resolved Hide resolved
zebra-consensus/src/block.rs Outdated Show resolved Hide resolved
zebra-consensus/src/block.rs Outdated Show resolved Hide resolved
zebra-consensus/src/block/request.rs Outdated Show resolved Hide resolved
zebra-consensus/src/block/request.rs Outdated Show resolved Hide resolved
zebra-state/src/service.rs Outdated Show resolved Hide resolved
zebra-state/src/service.rs Outdated Show resolved Hide resolved
zebra-state/src/service.rs Outdated Show resolved Hide resolved
zebra-state/src/service.rs Outdated Show resolved Hide resolved
zebra-state/src/service.rs Outdated Show resolved Hide resolved
@teor2345 teor2345 added A-state Area: State / database changes A-concurrency Area: Async code, needs extra work to make it work properly. and removed A-rust Area: Updates to Rust code C-enhancement Category: This is an improvement labels Dec 16, 2022
@codecov
Copy link

codecov bot commented Dec 16, 2022

Codecov Report

Merging #5870 (5a0850c) into main (6e61066) will decrease coverage by 0.21%.
The diff coverage is 52.10%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5870      +/-   ##
==========================================
- Coverage   78.23%   78.02%   -0.22%     
==========================================
  Files         310      311       +1     
  Lines       38837    38919      +82     
==========================================
- Hits        30383    30365      -18     
- Misses       8454     8554     +100     

@github-actions github-actions bot added the C-enhancement Category: This is an improvement label Dec 16, 2022
@arya2 arya2 force-pushed the gbt-proposal-mode branch from 096dab3 to 8420b75 Compare December 16, 2022 19:01
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.

I'm really happy with the way you've made this change clearer and more consistent, and made it easier to see that we are following the consensus rules.

For testing, I'd like to see a diff between a Zebra and zcashd block proposal response. I'm also happy to do that test, if you don't have synced instances ready.

This PR took me a while to review, because it changes about 40 files. We might want to think about how to split up future large changes into stages, or how we can avoid unnecessary changes. (This is a general comment, there's no need to split this PR!)

For example, I think we could have done the FinalizedState to ZebraDb change in another PR, which would have split out about 10 files from this PR.

zebra-consensus/src/block/check.rs Outdated Show resolved Hide resolved
zebra-rpc/src/methods/get_block_template_rpcs.rs Outdated Show resolved Hide resolved
zebra-state/src/service.rs Outdated Show resolved Hide resolved
zebra-state/src/service.rs Outdated Show resolved Hide resolved
zebra-state/src/service.rs Outdated Show resolved Hide resolved
zebra-consensus/src/block/request.rs Show resolved Hide resolved
zebra-state/src/service/check.rs Outdated Show resolved Hide resolved
zebra-state/src/service/write.rs Outdated Show resolved Hide resolved
@teor2345
Copy link
Contributor

For testing, I'd like to see a diff between a Zebra and zcashd block proposal response. I'm also happy to do that test, if you don't have synced instances ready.

This is now handled in ticket #5803, so it doesn't need to block this PR or the CI tests.

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.

I'm happy for anyone to approve once we've fixed the previous block hash check.

@arya2
Copy link
Contributor Author

arya2 commented Jan 10, 2023

This PR took me a while to review, because it changes about 40 files. We might want to think about how to split up future large changes into stages, or how we can avoid unnecessary changes. (This is a general comment, there's no need to split this PR!)

I agree with splitting changes into multiple PRs. I also liked how you organized the getblocktemplate refactor in PR #5837 for when there are a lot of changes in one PR.

@arya2 arya2 force-pushed the gbt-proposal-mode branch from 31afa3a to c8a35e6 Compare January 10, 2023 17:57
@arya2 arya2 force-pushed the gbt-proposal-mode branch from c8a35e6 to 9ce7d8a Compare January 10, 2023 18:37
@arya2
Copy link
Contributor Author

arya2 commented Jan 10, 2023

An expect_request in the snapshot timed out:

---- methods::tests::snapshot::test_rpc_response_data stdout ----

The application panicked (crashed).
Message: timeout while waiting for a request
in zebra_test::mock_service::MockService<zebra_node_services::mempool::Request, zebra_node_services::mempool::Response, zebra_test::mock_service::PanicAssertion, alloc::boxed::Box<dyn core::error::Error+core::marker::Sync+core::marker::Send>>

https://github.com/ZcashFoundation/zebra/actions/runs/3886245054/jobs/6631117711#step:14:3001

Update: I made issue #5940 for fixing the test.

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 fixing up my suggestions!

mergify bot added a commit that referenced this pull request Jan 11, 2023
mergify bot added a commit that referenced this pull request Jan 11, 2023
@arya2
Copy link
Contributor Author

arya2 commented Jan 11, 2023

Thanks for fixing up my suggestions!

Thanks for the excellent suggestions!

@teor2345
Copy link
Contributor

Same network error as #5938 (comment)

@teor2345
Copy link
Contributor

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented Jan 11, 2023

update

✅ Branch has been successfully updated

@mergify mergify bot merged commit 3cbee94 into main Jan 11, 2023
@mergify mergify bot deleted the gbt-proposal-mode branch January 11, 2023 23:39
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 C-feature Category: New features no-review-reminders Turn off review reminders
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for block proposals to getblocktemplate method
3 participants