Open arya2 opened 2 months ago
This is a complex PR (not your fault, it's a complex issue). I've been reviewing it for a while but it feels I could spend ages reviewing this to be 100% sure. I'm OK with approving it but do you think we should ask for someone else to take a look?
In hindsight, it probably should've been split into multiple PRs. A second review would be ideal since it involves concurrency and consensus changes, though it has also gone through a few rounds of self-review.
I think a second review of just the changes to ZIP 317 block production would be okay.
Also, did you manage to test it for the use case we wish to address (i.e. sending to tex addresses?)
I haven't, and there's no acceptance test that tries to submit an orphaned transaction, I'll try doing that now.
I'm also still reviewing. A bunch of other things took precedence in the meantime, unfortunately.
What do you mean by "orphaned" transactions in the title?
Transactions that spend outputs that are missing in the chain state, though I'm not sure if "orphan transactions" is the right term if those outputs can still be found in the mempool.
This PR is still missing an acceptance test for the use case we're trying to address (testing it manually with zcashd seems difficult, and a test that creates transactions could provide a valuable reference for other tests in the future), but I think it's fine to merge it without an acceptance test since each component has unit tests (though I'm happy to prioritize writing that test if anyone disagrees).
What do you mean by "orphaned" transactions in the title?
Transactions that spend outputs that are missing in the chain state, though I'm not sure if "orphan transactions" is the right term if those outputs can still be found in the mempool.
This RFC, https://github.com/zcashfoundation/zebra/blob/257567b559dba0359519d61684e80daac52cc434/book/src/dev/rfcs/0005-state-updates.md#L62, defines orphaned blocks as those that are no longer included in the best chain, which implies they were mined at some point. I'd assume orphaned txs are those in such blocks, but this PR doesn't apply to them. Maybe something like "Verify transactions spending mempool UTXOs"?
I'm trying to figure out what happens if someone submits txs containing a circular dependency. We should make sure we can handle such cases well.
The transaction verifier would return an TransparentInputNotFound
error for both because (unlike pending_utxos in the state service) the mempool only responds to AwaitOutput
requests once the transaction creating that output has been added to the mempool's verified set.
A similar question around ordering the transactions in block templates caused me some strife (the code should work as expected there too, and it's been excluded from release compilations, but it was difficult to reason about). That exact question may have also caused me some strife a little earlier, as well as what happens to long chains of dependent transactions.
@mergify refresh
refresh
Motivation
We want to verify transactions in the mempool that spend the transparent outputs of other transactions in the mempool.
Closes #8777.
Solution
AwaitOutput
request in the mempool servicespent_utxos()
method in the transaction verifier to try querying the mempool for spent outpoints before returning aTransparentInputNotFound
error.getblocktemplate
method and ZIP-317 transaction selection to include transactions that spent the outputs of other transactions in the mempool when all of their dependencies have been selectedTests
Added tests to check that:
Storage.remove()
method works as expected (the rest ofevict_one()
should be covered already)AwaitOutput
requests when the output for the queried outpoint is:AwaitOutput
requests as expected and processesUnspentOutput
responses correctlyspent_mempool_outpoints
in its responseIf needed, this PR could also add tests for:
getblocktemplate
method returns transactions with dependencies in the right order when the transaction hashes would have them sorted in the wrong orderFollow Up Work
The mempool's
Downloads
sends a result to the response channel too early, it should wait until the transaction is being inserted into the mempool's verified set.PR Author's Checklist
PR Reviewer's Checklist