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

add(mempool): Verify orphaned mempool transactions #8857

Open
wants to merge 53 commits into
base: main
Choose a base branch
from

Conversation

arya2
Copy link
Contributor

@arya2 arya2 commented Sep 9, 2024

Motivation

We want to verify transactions in the mempool that spend the transparent outputs of other transactions in the mempool.

Closes #8777.

Solution

  • Adds a handle to the mempool service in the transaction verifier
  • Adds AwaitOutput request in the mempool service
  • Updates the spent_utxos() method in the transaction verifier to try querying the mempool for spent outpoints before returning a TransparentInputNotFound error.
  • Polls the mempool service from the transaction verifier after verifying a mempool transaction that creates new UTXOs (in case they're spent by other mempool transactions that are still being verified)
  • Updates 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 selected

Tests

Added tests to check that:

  • Inserting a transaction also updates the transaction dependencies tracked in the verified set
  • The Storage.remove() method works as expected (the rest of evict_one() should be covered already)
  • The mempool responds to AwaitOutput requests when the output for the queried outpoint is:
    • Added to the mempool
    • Already available in the mempool
  • The transaction verifier:
    • Calls the mempool with AwaitOutput requests as expected and processes UnspentOutput responses correctly
    • Polls the mempool after verifying a mempool transaction that creates new transparent outputs
    • Includes all of the expected spent_mempool_outpoints in its response
  • Long poll ids remaining consistent as long the mempool contents are unchanged (and everything else is unchanged)
  • ZIP-317 mempool transaction selection excludes transactions that have dependencies unless their dependencies have already been selected

If needed, this PR could also add tests for:

  • ZIP-317 mempool transaction selection always returns the right order of transactions (this could be unnecessary since they’re sorted afterwards anyway but it could be a good sanity check)
  • The getblocktemplate method returns transactions with dependencies in the right order when the transaction hashes would have them sorted in the wrong order
  • Ideally at least a basic acceptance test that checks that it all works via RPCs

Follow 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

  • The PR name will make sense to users.
  • The PR provides a CHANGELOG summary.
  • The solution is tested.
  • The documentation is up to date.
  • The PR has a priority label.

PR Reviewer's Checklist

  • The PR Author's checklist is complete.
  • The PR resolves the issue.

… mempool setup argument, adds and uses an `init_test()` fn for passing a closed channel receiver in tests where no mempool service is needed in the transaction verifier.
…nd a `new_for_tests()` constructor for convenience)
…nsparent outputs has been verified.

adds a TODO for adding a `pending_outputs` field to the mempool Storage
…ng outputs requests when inserting new transactions into the mempool's verified set
@arya2 arya2 added A-mempool Area: Memory pool transactions P-Medium ⚡ labels Sep 9, 2024
@arya2 arya2 self-assigned this Sep 9, 2024
@github-actions github-actions bot added C-trivial Category: A trivial change that is not worth mentioning in the CHANGELOG labels Sep 9, 2024
… and zip317 mod's dependencies_depth() method
… shorter timeout for mempool output lookups, adds a `poll_count` to MockService, and updates `mempool_request_with_unmined_output_spends_is_accepted` to check that the transaction verifier polls the mempool after verifying a mempool transaction with transparent outputs
…an `unmined_transactions_in_blocks()` method on network
…ol Storage test module and replaces calls to it with calls to the new test method on Network
@arya2 arya2 marked this pull request as ready for review September 27, 2024 01:10
@arya2 arya2 requested review from a team as code owners September 27, 2024 01:10
@arya2 arya2 requested review from oxarbitrage and removed request for a team September 27, 2024 01:10
@arya2 arya2 added A-consensus Area: Consensus rule updates A-concurrency Area: Async code, needs extra work to make it work properly. labels Sep 27, 2024
@arya2 arya2 requested a review from upbqdn September 30, 2024 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-concurrency Area: Async code, needs extra work to make it work properly. A-consensus Area: Consensus rule updates A-mempool Area: Memory pool transactions C-trivial Category: A trivial change that is not worth mentioning in the CHANGELOG P-Medium ⚡
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: support orphan transactions in the mempool
1 participant