fuzz: don’t allow adding duplicate transactions to the mempool #29990

pull sdaftuar wants to merge 1 commits into bitcoin:master from sdaftuar:2024-04-no-mempool-dups changing 1 files +1 −1
  1. sdaftuar commented at 7:49 pm on April 28, 2024: member

    Filter duplicate transaction ids from being added to the mempool in the partially_downloaded_block fuzz target.

    I think a prerequisite for calling CTxMemPool::addUnchecked should be that the underlying txid doesn’t already exist in the mempool (otherwise addUnchecked would need a way to return failure, which we don’t currently have).

  2. fuzz: don't allow adding duplicate transactions to the mempool cc15c5bfd1
  3. DrahtBot commented at 7:49 pm on April 28, 2024: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK maflcko, brunoerg, glozow, dergoegge

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

  4. DrahtBot added the label Tests on Apr 28, 2024
  5. maflcko approved
  6. maflcko commented at 7:53 am on April 29, 2024: member

    lgtm ACK cc15c5bfd1eb3903de246c124702a7c66c687008

    I guess this isn’t due to a fuzz crash, because the only thing that’s off is cachedInnerUsage (and friends), which are not checked in this fuzz target?

  7. maflcko requested review from dergoegge on Apr 29, 2024
  8. sdaftuar commented at 9:13 am on April 29, 2024: member

    I guess this isn’t due to a fuzz crash, because the only thing that’s off is cachedInnerUsage (and friends), which are not checked in this fuzz target?

    Correct, I didn’t see any fuzz crash on master, but this issue was leading to crashes in my cluster mempool branch, where the inconsistency manifested itself sooner.

  9. in src/test/fuzz/partially_downloaded_block.cpp:75 in cc15c5bfd1
    71@@ -72,7 +72,7 @@ FUZZ_TARGET(partially_downloaded_block, .init = initialize_pdb)
    72             available.insert(i);
    73         }
    74 
    75-        if (add_to_mempool) {
    76+        if (add_to_mempool && !pool.exists(GenTxid::Txid(tx->GetHash()))) {
    


    paplorinc commented at 12:15 pm on April 29, 2024:

    Considering the purpose of fuzzing is to test the combination of valid states, shouldn’t we include tests that involve sending duplicate transactions to the mempool?

    Or if that’s irrelevant, since the proposed change affects how the add_to_mempool flag behaves, would it be more transparent to redefine it to directly reflect whether a transaction can be added to the mempool, i.e. bool add_to_mempool = !pool.exists(GenTxid::Txid(tx->GetHash())) && fuzzed_data_provider.ConsumeBool();?


    brunoerg commented at 12:27 pm on April 29, 2024:

    Considering the purpose of fuzzing is to test the combination of valid states, shouldn’t we include tests that involve sending duplicate transactions to the mempool?

    In this case, it is calling addUnchecked directly that’s why it would be proper to check whether the transaction is in mempool before. Note that, in practice, this function is used in MemPoolAccept::Finalize which removes conflicting transactions from the mempool before adding.


    sdaftuar commented at 1:06 pm on April 29, 2024:

    In this case, it is calling addUnchecked directly that’s why it would be proper to check whether the transaction is in mempool before. Note that, in practice, this function is used in MemPoolAccept::Finalize which removes conflicting transactions from the mempool before adding.

    Yes exactly. The correct interface for code that is doing no sanity checking would be AcceptToMemoryPool(). Since we’re bypassing that in the fuzz tests, we should do something else to avoid putting the mempool into an inconsistent state.

  10. brunoerg commented at 12:20 pm on April 29, 2024: contributor
    Concept ACK
  11. brunoerg approved
  12. brunoerg commented at 3:02 pm on April 29, 2024: contributor
    ACK cc15c5bfd1eb3903de246c124702a7c66c687008
  13. glozow commented at 4:33 pm on April 29, 2024: member
    utACK cc15c5bfd1eb3903de246c124702a7c66c687008 makes sense to me
  14. dergoegge approved
  15. dergoegge commented at 8:38 am on April 30, 2024: member
    utACK cc15c5bfd1eb3903de246c124702a7c66c687008
  16. glozow merged this on Apr 30, 2024
  17. glozow closed this on Apr 30, 2024


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-09-28 22:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me