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:
- Antoine Riard first pointed out this issue in #19645. His implementation uses the existing mempool validation code to replace by BIP125 rules. He has indicated that he isn’t planning to return to this work in the near future (in #l2-onchain-support): https://gist.github.com/glozow/d362100715e9a3e2e61cb4b600663377#file-package-relay-meeting-log-txt-L329
- We discussed approach and use cases in #l2-onchain-support: https://gist.github.com/ariard/32b51ecceccc5c6f647bae86d083c442#file-l2-onchain-support-meeting2-txt-L202
- #22253 implements step 1 of this work, by distinguishing between a same-txid-different-witness and same exact transaction already in mempool
Here are the rough steps of this project (in my view):
- Take a look at #19645 to get a good grasp of the issue. Read through BIP125 and go through the
MemPoolAccept
code. - Review #22253 - you’ll likely want to build on top of it.
- Determine what “rules” (similar to BIP125) witness replacement may need. Think about what kinds of test cases are appropriate.
- Try to implement witness replacement in
AcceptSingleTransaction
. Perhaps try aCTxMemPool::SwapWitness
function? We always prefer the minimally invasive way. - 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!
- Open a PR!