Cluster mempool followups #33591

pull sdaftuar wants to merge 87 commits into bitcoin:master from sdaftuar:2025-10-rebase-cluster-mempool changing 65 files +2029 −3370
  1. sdaftuar commented at 7:06 pm on October 9, 2025: member

    As suggested in the main cluster mempool PR (https://github.com/bitcoin/bitcoin/pull/28676#pullrequestreview-3177119367), I’ve pulled out some of the non-essential optimizations and cleanups into this separate PR.

    Will continue to add more commits here to address non-blocking suggestions/improvements as they come up.

  2. DrahtBot commented at 7:06 pm on October 9, 2025: contributor

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

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33591.

    Reviews

    See the guideline for information on the review process. A summary of reviews will appear here.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #33725 (ci, iwyu: Treat warnings as errors for src/init and src/policy by hebasto)
    • #33724 (refactor: Return uint64_t from GetSerializeSize by maflcko)
    • #33629 (Cluster mempool by sdaftuar)
    • #33616 (policy: don’t CheckEphemeralSpends on reorg by instagibbs)
    • #33421 (node: add BlockTemplateCache by ismaelsadeeq)
    • #33214 (rpc: require integer verbosity; remove boolean ‘verbose’ by fqlx)
    • #33192 (refactor: unify container presence checks by l0rinc)
    • #33191 (net: Provide block templates to peers on request by ajtowns)
    • #32587 (test: Fix reorg patterns in tests to use proper fork-based approach by yuvicc)
    • #31974 (Drop testnet3 by Sjors)
    • #31682 ([IBD] specialize CheckBlock’s input & coinbase checks by l0rinc)
    • #31382 (kernel: Flush in ChainstateManager destructor by TheCharlatan)
    • #30277 ([DO NOT MERGE] Erlay: bandwidth-efficient transaction relay protocol (Full implementation) by sr-gi)
    • #29641 (scripted-diff: Use LogInfo over LogPrintf [WIP, NOMERGE, DRAFT] by maflcko)
    • #28690 (build: Introduce internal kernel library by TheCharlatan)
    • #17783 (common: Disallow calling IsArgSet() on ALLOW_LIST options by ryanofsky)
    • #17581 (refactor: Remove settings merge reverse precedence code by ryanofsky)
    • #17580 (refactor: Add ALLOW_LIST flags and enforce usage in CheckArgFlags by ryanofsky)
    • #17493 (util: Forbid ambiguous multiple assignments in config file by ryanofsky)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

    LLM Linter (✨ experimental)

    Possible typos and grammar issues:

    • // Also store the first 10 transactions from each cluster as the // transactions we’ll “mine” in the the benchmark. -> … we’ll “mine” in the benchmark. [duplicate “the” makes the sentence awkward/redundant]

    drahtbot_id_5_m

  3. glozow added the label Mempool on Oct 9, 2025
  4. DrahtBot added the label Needs rebase on Oct 14, 2025
  5. Allow moving an Epoch::Marker 51430680ec
  6. mempool: Store iterators into mapTx in mapNextTx
    This takes the same amount of space as CTransaction pointers, and saves a map
    lookup in many common uses.
    6c73e47448
  7. Allow moving CTxMemPoolEntry objects, disallow copying cd0bea2197
  8. Make CTxMemPoolEntry derive from TxGraph::Ref c5706ea462
  9. Create a txgraph inside CTxMemPool 91d9bfcca6
  10. Use named constant for acceptable iters 83c8753abf
  11. Add sigops adjusted weight calculator f2eff17c6c
  12. Add accessor for sigops-adjusted weight 1d3b53bcf1
  13. Add transactions to txgraph, but without cluster dependencies
    Effectively this is treating all transactions in txgraph as being in a cluster
    of size 1.
    8c59aa56cb
  14. Add new (unused) limits for cluster size/count 2801e80528
  15. test: update feature_rbf.py replacement test
    Preparatory commit to the rbf functional test, before changes are made to the
    rbf rules as part of cluster mempool.
    429bdbecfd
  16. [test] rework/delete feature_rbf tests requiring large clusters 8d6c7e4401
  17. sdaftuar force-pushed on Oct 14, 2025
  18. DrahtBot removed the label Needs rebase on Oct 14, 2025
  19. Do not allow mempool clusters to exceed configured limits
    Include an adjustment to mempool_tests.cpp due to the additional memory used by
    txgraph.
    
    Includes a temporary change to the mempool_ephemeral_dust.py functional test,
    due to validation checks being reordered. This change will revert once the RBF
    rules are changed in a later commit.
    b9cbca7676
  20. Check cluster limits when using -walletrejectlongchains d2f75c555c
  21. Rework miner_tests to not require large cluster limit d7599f24a0
  22. Limit mempool size based on chunk feerate
    Rather than evicting the transactions with the lowest descendant feerate,
    instead evict transactions that have the lowest chunk feerate.
    
    Once mining is implemented based on choosing transactions with highest chunk
    feerate (see next commit), mining and eviction will be opposites, so that we
    will evict the transactions that would be mined last.
    bed2b5c91a
  23. bench: rewrite ComplexMemPool to not create oversized clusters 89005d8872
  24. Select transactions for blocks based on chunk feerate
    Co-Authored-By: Gregory Sanders <gsanders87@gmail.com>
    a8be743aeb
  25. test: rewrite PopulateMempool to not violate mempool policy (cluster size) limits afb9003bc6
  26. policy: Remove CPFP carveout rule
    The addition of a cluster size limit makes the CPFP carveout rule useless,
    because carveout cannot be used to bypass the cluster size limit. Remove this
    policy rule and update tests to no longer rely on the behavior.
    31a045700e
  27. Implement new RBF logic for cluster mempool
    With a total ordering on mempool transactions, we are now able to calculate a
    transaction's mining score at all times. Use this to improve the RBF logic:
    
    - we no longer enforce a "no new unconfirmed parents" rule
    
    - we now require that the mempool's feerate diagram must improve in order
      to accept a replacement
    
    - the topology restrictions for conflicts in the package rbf setting have been
      eliminated
    
    Revert the temporary change to mempool_ephemeral_dust.py that were previously
    made due to RBF validation checks being reordered.
    
    Co-authored-by: Gregory Sanders <gsanders87@gmail.com>, glozow <gloriajzhao@gmail.com>
    e6315c2432
  28. ==== END CLUSTER IMPLEMENTATION ==== b23cb5f35c
  29. ==== BEGIN MEMPOOL CLEANUP ==== 014e45cc81
  30. Remove the ancestor and descendant indices from the mempool 7c4cd86ad4
  31. Use cluster linearization for transaction relay sort order
    Previously, transaction batches were first sorted by ancestor count and then
    feerate, to ensure transactions are announced in a topologically valid order,
    while prioritizing higher feerate transactions. Ancestor count is a crude
    topological sort criteria, so replace this with linearization order so that the
    highest feerate transactions (as would be observed by the mining algorithm) are
    relayed before lower feerate ones, in a topologically valid way.
    
    This also fixes a test that only worked due to the ancestor-count-based sort
    order.
    936f04e770
  32. Remove CTxMemPool::GetSortedDepthAndScore
    The mempool clusters and linearization permit sorting the mempool topologically
    without making use of ancestor counts (as long as the graph is not oversized).
    
    Co-authored-by: Pieter Wuille <pieter@wuille.net>
    9b31836abf
  33. Reimplement GetTransactionAncestry() to not rely on cached data
    In preparation for removing ancestor data from CTxMemPoolEntry, recalculate the
    ancestor statistics on demand wherever needed.
    18cc90f91f
  34. rpc: Calculate ancestor data from scratch for mempool rpc calls 13598184f0
  35. Remove dependency on cached ancestor data in mini-miner 729cec4f6d
  36. Stop enforcing ancestor size/count limits
    The cluster limits should be sufficient.
    
    Co-Authored-By: Gregory Sanders <gsanders87@gmail.com>
    9bb87b82bc
  37. Add test case for cluster size limits to TRUC logic cf2f5211a8
  38. Use mempool/txgraph to determine if a tx has descendants
    Remove a reference to GetCountWithDescendants() in preparation for removing
    this function and the associated cached state from the mempool.
    b23b156c7b
  39. Calculate descendant information for mempool RPC output on-the-fly
    This is in preparation for removing the cached descendant state from the
    mempool.
    a9f6ea3088
  40. test: remove rbf carveout test from mempool_limit.py f163bf0abb
  41. Stop enforcing descendant size/count limits
    Cluster size limits should be enough.
    098236f8d9
  42. Eliminate RBF workaround for CPFP carveout transactions
    The new cluster mempool RBF rules take into account clusters sizes exactly, so
    with the removal of descendant count enforcement this idea is obsolete.
    1971a34a78
  43. wallet: Replace max descendantsize with clustersize
    With the descendant size limits removed, replace the concept of "max number of
    descendants of any ancestor of a given tx" with the cluster count of the cluster
    that the transaction belongs to.
    fb4202e67e
  44. mempool: Remove unused function CalculateDescendantMaximum 66c143ce7e
  45. Eliminate use of cached ancestor data in miniminer_tests and truc_policy 67b4294172
  46. mempool: eliminate accessors to mempool entry ancestor/descendant cached state 7b3da99f1e
  47. Remove unused members from CTxMemPoolEntry 276f2c5722
  48. Remove mempool logic designed to maintain ancestor/descendant state 34944b97fa
  49. mempool: addUnchecked no longer needs ancestors 697de05988
  50. Remove unused limits from CalculateMemPoolAncestors 967f782544
  51. Make removeConflicts private 1aaf9e9da1
  52. ==== END MEMPOOL CLEANUP ==== e63b0a1e4b
  53. ==== BEGIN OPTIMIZATIONS ==== 666ad3530c
  54. Simplify ancestor calculation functions
    Now that ancestor calculation never fails (due to ancestor/descendant limits
    being eliminated), we can eliminate the error handling from
    CalculateMemPoolAncestors.
    6711e11ac8
  55. Use txgraph to calculate ancestors 299fc4d22d
  56. Use txgraph to calculate descendants a83ced86f1
  57. Rework truc_policy to use descendants, not children 6e782bbcc8
  58. Make getting parents/children a function of the mempool, not a mempool entry 53f7140e9c
  59. Eliminate CheckPackageLimits, which no longer does anything 30cfdff840
  60. Fix miniminer_tests to work with cluster limits b554852f4f
  61. Rewrite GatherClusters to use the txgraph implementation d9006c54a0
  62. Stop tracking parents/children outside of txgraph 065de4b3cb
  63. ==== END OPTIMIZATIONS ==== 1d13b4b865
  64. ==== BEGIN DOCS/TESTING ==== 310555e555
  65. Avoid violating mempool policy limits in tests
    Changes AddToMempool() helper to only apply changes if the mempool limits are
    respected.
    
    Fix package_rbf fuzz target to handle mempool policy violations
    f20f0a08e5
  66. bench: add more mempool benchmarks
    Add benchmarks for:
    
      - mempool update time when blocks are found
      - adding a transaction
      - performing the mempool's RBF calculation
      - calculating mempool ancestors/descendants
    ebee3155d3
  67. fuzz: try to add more code coverage for mempool fuzzing
    Including test coverage for mempool eviction and expiry
    474d13fd9a
  68. Expose cluster information via rpc
    Co-authored-by: glozow <gloriajzhao@gmail.com>
    eb228c40cc
  69. doc: Update mempool_replacements.md to reflect feerate diagram checks fba5200d59
  70. test: add functional test for new cluster mempool RPCs
    Co-authored-by: glozow <gloriajzhao@gmail.com>
    8f62e9177b
  71. fuzz: remove comparison between mini_miner block construction and miner
    This is in preparation for eliminating the block template building happening in
    mini_miner, in favor of directly using the linearizations done in the mempool.
    c5ce987d5c
  72. Invoke TxGraph::DoWork() at appropriate times 009db6c3a4
  73. Update comments for CTxMemPool class 21b3ad422a
  74. Add check that GetSortedScoreWithTopology() agrees with CompareMiningScoreWithTopology()
    We use CompareMiningScoreWithTopology() for sorting transaction announcements
    during tx relay, and we use GetSortedScoreWithTopology() in
    CTxMemPool::check().
    33cacc3351
  75. Rework RBF and TRUC validation
    Calculating mempool ancestors for a new transaction should not be done until
    after cluster size limits have been enforced, to limit CPU DoS potential.
    
    Achieve this by reworking TRUC and RBF validation logic:
    
    - TRUC policy enforcement is now done using only mempool parents of
      new transactions, not all mempool ancestors.
    - RBF replacement checks are performed earlier (which allows for checking
      cluster size limits earlier, because cluster size checks cannot happen until
      after all conflicts are staged for removal).
    - Verifying that a new transaction doesn't conflict with an ancestor now
      happens later, in AcceptSingleTransaction() rather than in PreChecks(). This
      means that the test is not performed at all in AcceptMultipleTransactions(),
      but in package acceptance we already disallow RBF in situations where a
      package transaction has in-mempool parents.
    
    Also to ensure that all RBF validation logic is applied in both the single
    transaction and multiple transaction cases, remove the optimization that skips
    the PackageMempoolChecks() in the case of a single transaction being validated
    in AcceptMultipleTransactions().
    10872f7ec9
  76. ==== FOLLOWUPS ==== 8c11a30ae9
  77. Remove unused variable (cacheMap) in mempool 8427cad9ad
  78. Remove unused argument to RemoveStaged aea77fae04
  79. Simplify removeRecursive 999b30ab3f
  80. scripted-diff: rename AddToMempool -> TryAddToMempool
    -BEGIN VERIFY SCRIPT-
    find src/test -type f -exec sed -i 's/AddToMempool/TryAddToMempool/g' {} +
    find src/bench -type f -exec sed -i 's/AddToMempool/TryAddToMempool/g' {} +
    -END VERIFY SCRIPT-
    58f3bd08aa
  81. Rewrite removeForReorg to avoid using sets 8c48782e45
  82. Rewrite GetChildren without sets d3ff187048
  83. Invoke removeUnchecked() directly in removeForBlock() e5e29d8b41
  84. Warn user if using -limitancestorsize/-limitdescendantsize that the options have no effect 7ca665a615
  85. Use cluster limit rather than descendant limit to sanity check mempool max size 1566a00f0d
  86. Remove ancestor and descendant vsize limits from MemPoolLimits 54e2ee2fff
  87. Use cluster limits instead of ancestor/descendant limits when sanity checking package policy limits 4f2d741dff
  88. Use cluster size limit instead of ancestor/descendant size limits when sanity checking TRUC policy limits 2d167c1206
  89. Use cluster size limit instead of ancestor size limit in txpackage unit test 3b29fbc17a
  90. Remove unused DEFAULT_ANCESTOR_SIZE_LIMIT_KVB and DEFAULT_DESCENDANT_SIZE_LIMIT_KVB a4d342c29c
  91. Add a GetFeePerVSize() accessor to CFeeRate, and use it in the BlockAssembler ae580c3e8c
  92. doc: add note about retrying certain RBF failures in package context 6881d21c57
  93. sdaftuar force-pushed on Oct 16, 2025
  94. miner: Rename TestPackage() -> TestPackageBlockLimits() d7109669b5

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: 2025-10-30 21:13 UTC

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