-
Notifications
You must be signed in to change notification settings - Fork 117
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
Validate transaction lock times #3060
Validate transaction lock times #3060
Conversation
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.
I think the Bitcoin docs are wrong about the height check.
Also, we need to be careful to use the correct time field and comparison operators.
b34425c
to
55e88e6
Compare
Updated. Difference since last review can be seen here. I still haven't finished the tests, I'll try to do that on Monday. I'm not sure how to handle the mempool transactions. For the block height, I think it's currently using the current tip height plus one:
Should we add a tolerance of a few extra blocks? As for the block time, I think the options are:
The current implementation uses the third option using the local node time plus a two hours margin of error between the local node time and the network's block time, plus a tolerance of an hour. Should I use the state service in the mempool downloader to get the block time and pass it in the request instead of using the local time in the verifier itself? |
55e88e6
to
aaf4118
Compare
Let's try to limit the scope of this PR to essential NU5 tasks.
Can we split mempool validation into a separate PR? The mempool and lock time rules are completely undocumented for Zcash. The mempool is not consensus-critical, but we want to avoid usability bugs where Zebra rejects transactions that In that PR, we should consider:
I think |
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.
I'm concerned that the scope of this PR has become a lot larger.
Can we just do the NU5 changes and basic test vectors in the initial PR?
Then we can schedule other work in future sprints.
Returns a `LockTime` that is unlocked at the genesis block.
Prepare to return `None` for when a transaction has its lock time disabled.
Because a zero lock time means that the transaction was unlocked at the genesis block, so it was never actually locked.
Clarify that the check is not redundant, and is necessary for the genesis transaction. Co-authored-by: teor <[email protected]>
Retrieve a transparent input's sequence number.
Validate the consensus rule that the lock time is only enabled if at least one transparent input has a value different from `u32::MAX` as its sequence number.
Explain the Zcash specific lock time behaviors. Co-authored-by: teor <[email protected]>
The block time to use to check if the transaction was unlocked and allowed to be included in the block.
Returns the block time for the block that owns the transaction being validated or the current time plus a tolerance for mempool transactions.
If they are enabled by a transaction's transparent input sequence numbers, make sure that they are in the past.
Make it easier to map what part of the consensus rule each match arm is responsible for.
aaf4118
to
01d7e70
Compare
Updated. Since I removed the incomplete property tests, I think this PR is no longer blocked by it so can have its draft status removed. Changes since last review can be seen here. |
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.
Thanks, looks great!
I'm just about to fix up the unrelated coverage job failure.
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.
I merged the new errors from two different PRs.
Motivation
Transactions can have lock times configured so that they are only included in a block after a certain block height or date and time. This is a consensus rule inherited from Bitcoin and that Zebra must validate.
Specifications
https://developer.bitcoin.org/devguide/transactions.html#non-standard-transactions
Zcash-specific clarification:
zcash/zips#539
Interaction with Input Sequence Numbers
https://developer.bitcoin.org/devguide/transactions.html#locktime-and-sequence-number
Clarification:
zcash/zips#539
Solution
Transaction::lock_time
getterNone
is returnedzebra_consensus::transaction::check
moduleReview
@teor2345 and/or @oxarbitrage can review this. This is still in draft because I have only outlined the tests I want to add, but I haven't finished writing them yet.
Reviewer Checklist
Follow Up Work