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(consensus) verify that mempool transaction UTXOs are in the best chain #5616

Merged
merged 6 commits into from
Nov 11, 2022

Conversation

arya2
Copy link
Contributor

@arya2 arya2 commented Nov 10, 2022

Motivation

The transaction verifier currently checks that spent UTXOs of mempool transactions are in the state queue or on any chain, but it needs to verify that those spent UTXOs are on the best chain so that mined blocks including those transactions will be contextually valid.

Closes #5386

Solution

  • Call state service with BestChainUtxo request instead of AwaitUtxo when verifying mempool transactions.
  • Add InputNotFound variant to TransactionError for when the spent UTXOs are not present on the best chain.

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

  • Add a retry_list in the mempool storage for transactions that weren't verified with InputNotFound?

@arya2 arya2 added C-bug Category: This is a bug A-consensus Area: Consensus rule updates A-rust Area: Updates to Rust code P-Medium ⚡ A-state Area: State / database changes labels Nov 10, 2022
@arya2 arya2 requested a review from a team as a code owner November 10, 2022 20:11
@arya2 arya2 requested review from dconnolly and removed request for a team November 10, 2022 20:11
@github-actions github-actions bot added the C-enhancement Category: This is an improvement label Nov 10, 2022
@arya2 arya2 self-assigned this Nov 10, 2022
@arya2 arya2 requested a review from teor2345 November 10, 2022 20:11
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, this looks good!

But I think we need to check for unspent outputs, not just any available output. See my detailed note on the request comment.

We might also want to add a TODO to rename AwaitUtxo to AwaitTransactionOutput (the U means "Unspent"). There is already a TODO to combine the Output, Utxo, and OrderedUtxo types, maybe we can add a rename to it as well. But I don't want to do a mass rename during an audit freeze.

zebra-consensus/src/error.rs Outdated Show resolved Hide resolved
zebra-consensus/src/transaction.rs Show resolved Hide resolved
zebra-consensus/src/transaction/tests.rs Show resolved Hide resolved
zebra-state/src/request.rs Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Nov 10, 2022

Codecov Report

Merging #5616 (ece1be5) into main (beb45fc) will decrease coverage by 0.00%.
The diff coverage is 79.09%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5616      +/-   ##
==========================================
- Coverage   78.75%   78.74%   -0.01%     
==========================================
  Files         305      305              
  Lines       38320    38407      +87     
==========================================
+ Hits        30177    30245      +68     
- Misses       8143     8162      +19     

@arya2 arya2 force-pushed the use-best-chain-utxo branch from cf84654 to ece1be5 Compare November 11, 2022 00:19
@arya2 arya2 requested a review from teor2345 November 11, 2022 00:51
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!

I particularly like how you re-used the utxo() function code.

mergify bot added a commit that referenced this pull request Nov 11, 2022
@mergify mergify bot merged commit 862600a into main Nov 11, 2022
@mergify mergify bot deleted the use-best-chain-utxo branch November 11, 2022 06:40
teor2345 added a commit that referenced this pull request Feb 6, 2023
…st chain (#5616) - manual merge to skip getblocktemplate-rpcs

* Uses BestChainUtxo to find utxos for mempool

* adds missing input test

* Apply suggestions from code review

Co-authored-by: teor <[email protected]>

* update other instances of the renamed InputNotFound error

* adds read::unspent_utxo fn

* adds test for success case

Co-authored-by: teor <[email protected]>
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-rust Area: Updates to Rust code A-state Area: State / database changes C-bug Category: This is a bug C-enhancement Category: This is an improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use BestChainUtxo rather than AwaitUtxo in the mempool transaction validator
2 participants