Skip to content

Instantly share code, notes, and snippets.

@glozow
Created July 1, 2021 17:05
Show Gist options
  • Save glozow/d1ebe458ab2b6b60c3396ddcaef27bab to your computer and use it in GitHub Desktop.
Save glozow/d1ebe458ab2b6b60c3396ddcaef27bab to your computer and use it in GitHub Desktop.
Mempool Witness Replacement Project

Mempool Witness Replacement Project

Two transactions with the same non-witness data but different witnesses have the same txid but different wtxid, and the same fee but not necessarily the same feerate. Currently, in mempool validation, if we see a transaction that has the same txid as one in the mempool, we reject it as a duplicate. This shouldn’t pose a serious security risk except in transactions where multiple parties contribute to the inputs (which is also rare and usually involves trusted or somewhat trusted parties). However, the correct behavior should be to replace mempool transactions if a new transaction has a better feerate, with some caveats to avoid DoS attacks (similar to BIP125).

Previous work and discussion:

Here are the rough steps of this project (in my view):

  1. Take a look at #19645 to get a good grasp of the issue. Read through BIP125 and go through the MemPoolAccept code.
  2. Review #22253 - you’ll likely want to build on top of it.
  3. Determine what “rules” (similar to BIP125) witness replacement may need. Think about what kinds of test cases are appropriate.
  4. Try to implement witness replacement in AcceptSingleTransaction. Perhaps try a CTxMemPool::SwapWitness function? We always prefer the minimally invasive way.
  5. Write some functional tests (similar to test/functional/feature_rbf.py) hitting all your rules/cases. Be sure to test that ancestor/descendant values are correct after witness replacement!
  6. Open a PR!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment