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): check contextual validity of getblocktemplate response #5630

Closed
wants to merge 12 commits into from

Conversation

arya2
Copy link
Contributor

@arya2 arya2 commented Nov 15, 2022

Motivation

The getblocktemplate response must be contextually valid based on the best tip in the state.

Needs other getblocktemplate fields for testing the success case.

Closes #5376

Solution

  • Add a new state request for checking the contextual validity of a prepared block without committing it.
  • Make a prepared block with default nonce and solution fields to use the new state request.
  • Update vectors and snapshot tests to use a MockService that returns a Validated response.

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?

@arya2 arya2 added A-consensus Area: Consensus rule updates A-rust Area: Updates to Rust code C-enhancement Category: This is an improvement A-rpc Area: Remote Procedure Call interfaces do-not-merge Tells Mergify not to merge this PR C-feature Category: New features labels Nov 15, 2022
@arya2 arya2 self-assigned this Nov 15, 2022
@arya2 arya2 requested a review from oxarbitrage November 15, 2022 00:11
@arya2 arya2 force-pushed the check-contextual-validity-request branch from fa1b535 to b3bc9cf Compare November 16, 2022 21:52
@arya2 arya2 force-pushed the check-contextual-validity-request branch from b3bc9cf to a6eb045 Compare November 16, 2022 22:41
@codecov
Copy link

codecov bot commented Nov 17, 2022

Codecov Report

Merging #5630 (fada9d7) into main (a2f2a14) will decrease coverage by 0.00%.
The diff coverage is 50.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5630      +/-   ##
==========================================
- Coverage   78.72%   78.72%   -0.01%     
==========================================
  Files         305      305              
  Lines       38503    38503              
==========================================
- Hits        30313    30310       -3     
- Misses       8190     8193       +3     

) -> Result<(), crate::ValidateContextError> {
if let Some(best_chain) = self.latest_non_finalized_state().best_chain() {
let best_chain_latest_non_finalized_state = NonFinalizedState::build(self.network)
.insert_chain(Arc::clone(best_chain))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

qualifying the Arc::clone so it's obvious that nothing's being copied without looking at the type.

@arya2
Copy link
Contributor Author

arya2 commented Nov 18, 2022

@Mergifyio update

@arya2 arya2 marked this pull request as ready for review November 18, 2022 18:07
@arya2 arya2 requested a review from a team as a code owner November 18, 2022 18:07
@mergify
Copy link
Contributor

mergify bot commented Nov 18, 2022

update

✅ Branch has been successfully updated

@arya2 arya2 removed the do-not-merge Tells Mergify not to merge this PR label Nov 18, 2022
@oxarbitrage
Copy link
Contributor

This one will conflict with #5659 in the tests as i added some stuff from this PR there. I will prefer #5659 to go first just because i have another PR to push that is based on it and it will be easier for me to do it that way.

@arya2
Copy link
Contributor Author

arya2 commented Nov 21, 2022

This one will conflict with #5659 in the tests as i added some stuff from this PR there. I will prefer #5659 to go first just because i have another PR to push that is based on it and it will be easier for me to do it that way.

Sounds good, I'd also prefer #5659 go first so this PR could use the populated target field for the difficulty_threshold of the prepared block.

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 think the ticket for this PR was a bit confusing. We need to change how the mempool checks transactions, so it always uses the best chain.

If we wait until the transactions are in the getblocktemplate response, it is too late, because all we can do is return an error to the caller. We don't know which transactions to remove to make the block valid.

Edit: It is also going to be tricky to verify the block, because the solution in the header requires Proof of Work. (Correct equihash solutions are expensive to create, so we can't do that in tests or in the RPC.)

We might want to turn this PR into a ticket, because the code looks like it could be useful for testing.

I'll add some specific notes to the ticket about where we want to change things.

@arya2
Copy link
Contributor Author

arya2 commented Nov 21, 2022

I think the ticket for this PR was a bit confusing. We need to change how the mempool checks transactions, so it always uses the best chain.

If we wait until the transactions are in the getblocktemplate response, it is too late, because all we can do is return an error to the caller. We don't know which transactions to remove to make the block valid.

Oops. 🤦 I thought I just hadn't come across the code that was checking the nullifiers, I understand now.

It is also going to be tricky to verify the block, because the solution in the header requires Proof of Work. (Correct equihash solutions are expensive to create, so we can't do that in tests or in the RPC.)

The code looks like it could be useful for testing.

I believe the solution in the header is only checked by the block verifier. I created issue #5681 for adding this as a test.

I'm closing this because it would needlessly hurt performance in production.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-consensus Area: Consensus rule updates 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Do contextual validation on mempool transactions using the state best tip
3 participants