-
Notifications
You must be signed in to change notification settings - Fork 118
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
fix(consensus): Verify the lock times of mempool transactions #6027
Conversation
5734fb5
to
788bc57
Compare
788bc57
to
81a0b87
Compare
81a0b87
to
0af4c1a
Compare
This PR needs 2 reviewers, so I've tagged everyone else who is working on Zebra for a review. If you're the second reviewer, you can take the third person off! |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #6027 +/- ##
==========================================
- Coverage 78.04% 77.92% -0.12%
==========================================
Files 312 312
Lines 39036 39418 +382
==========================================
+ Hits 30464 30717 +253
- Misses 8572 8701 +129 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, it should work as-is but I left a few optional comments for clean up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you for the fix!
I left a do-not-merge
label in case anyone else is currently reviewing this, feel free to remove it when you want this to embark on the merge train.
I would like two reviews, because this is consensus-critical concurrent code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me.
… - manually delete getblocktemplate-rpcs * Implement the BestChainNextMedianTimePast state request * Verify the lock times of mempool transactions * Document that the mempool already handles lock time rejections correctly * Fix existing tests * Add new mempool lock time success and failure tests
Motivation
We need to check that mempool transaction lock times are valid, so the block templates created by Zebra are also valid.
Closes #5984
Specifications
Mempool Transaction Verification
https://zips.z.cash/protocol/protocol.pdf#blockheader
https://developer.bitcoin.org/devguide/transactions.html#locktime-and-sequence-number
If the transaction's lock time is less than the median-time-past, it will always be less than the next block's time, because the next block's time is strictly greater than the median-time-past.
This is the rule implemented by
zcashd
:https://github.com/zcash/zcash/blob/9e1efad2d13dca5ee094a38e6aa25b0f2464da94/src/main.cpp#L776-L784
https://github.com/zcash/zcash/blob/9e1efad2d13dca5ee094a38e6aa25b0f2464da94/src/main.cpp#L735
Mempool Updates on State Tip Changes
When a new block is added to the state tip:
Complex Code or Requirements
This PR modifies async code, and state code that runs concurrently with block writes.
Solution
This is a mempool consensus rule bug, so we don't want these changes behind a feature flag.
Testing
Review
I marked this as a high priority because it is blocking most of our testing work.
Because it is a high priority, I'd like to avoid doing refactors in this PR.
Reviewer Checklist