Cluster mempool followups #33591

pull sdaftuar wants to merge 89 commits into bitcoin:master from sdaftuar:2025-10-rebase-cluster-mempool changing 70 files +2180 −3482
  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)
    • #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)
    • #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)
    • #30342 (kernel, logging: Pass Logger instances to kernel objects by ryanofsky)
    • #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:

    • to to -> to [duplicate “to” makes the sentence awkward/confusing] Context: “for singleton transactions (that are in clusters by themselves) it’s sufficient for a replacement to to have a higher fee and feerate than the original.” (release notes)

    • 5). -> 5. or (5) [extra closing parenthesis; may confuse the reference to rule 5] Context: “analogous to regular replacement rule 5).”

    • with more -> with more [double space between words; minor but unnecessary and can interrupt reading] Context: “Check Package RBF cannot conflict with more than MAX_REPLACEMENT_CANDIDATES clusters” (test text)

    No other added lines contain typographic/grammatical errors that render the English invalid or incomprehensible.

    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. sdaftuar force-pushed on Oct 14, 2025
  8. DrahtBot removed the label Needs rebase on Oct 14, 2025
  9. sdaftuar force-pushed on Oct 16, 2025
  10. sdaftuar force-pushed on Oct 31, 2025
  11. Allow moving CTxMemPoolEntry objects, disallow copying 92b0079fe3
  12. Make CTxMemPoolEntry derive from TxGraph::Ref 29a94d5b2f
  13. Create a txgraph inside CTxMemPool c18c68a950
  14. Add sigops adjusted weight calculator 1bf3b51396
  15. Add accessor for sigops-adjusted weight d5ed9cb3eb
  16. sdaftuar force-pushed on Nov 10, 2025
  17. Add transactions to txgraph, but without cluster dependencies
    Effectively this is treating all transactions in txgraph as being in a cluster
    of size 1.
    ffe34a81a5
  18. Add new (unused) limits for cluster size/count 1498de3631
  19. 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.
    0880e68a33
  20. [test] rework/delete feature_rbf tests requiring large clusters 496579fd8e
  21. 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.
    da5ddd2002
  22. Check cluster limits when using -walletrejectlongchains 06b29ff2ee
  23. Rework miner_tests to not require large cluster limit 0c84bec5c9
  24. 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.
    4ac7e8e3c0
  25. bench: rewrite ComplexMemPool to not create oversized clusters 1cdf13ef9d
  26. Select transactions for blocks based on chunk feerate
    Co-Authored-By: Gregory Sanders <gsanders87@gmail.com>
    c5bdbf4b20
  27. test: rewrite PopulateMempool to not violate mempool policy (cluster size) limits 80e0dffded
  28. 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.
    4fe6f02170
  29. 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>
    017b21286a
  30. Remove the ancestor and descendant indices from the mempool 1c6efd1db8
  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.
    43451108bf
  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>
    7011cc5c6b
  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.
    9009457cb5
  34. [squashme] Use outputs and structured bindings for CalculateAncestorData() 572ab3660c
  35. rpc: Calculate ancestor data from scratch for mempool rpc calls 5a62c4b0da
  36. Remove dependency on cached ancestor data in mini-miner ee7cae6578
  37. Stop enforcing ancestor size/count limits
    The cluster limits should be sufficient.
    
    Co-Authored-By: Gregory Sanders <gsanders87@gmail.com>
    f93cf0cb52
  38. Add test case for cluster size limits to TRUC logic 5ce114b983
  39. 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.
    613da125fb
  40. Calculate descendant information for mempool RPC output on-the-fly
    This is in preparation for removing the cached descendant state from the
    mempool.
    2cd0c60797
  41. test: remove rbf carveout test from mempool_limit.py b828d27a93
  42. Stop enforcing descendant size/count limits
    Cluster size limits should be enough.
    140a9fe44e
  43. 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.
    c9efae8a00
  44. wallet: Replace max descendantsize with cluster_count
    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.
    cec2620373
  45. mempool: Remove unused function CalculateDescendantMaximum 5b3c72e982
  46. Eliminate use of cached ancestor data in miniminer_tests and truc_policy 1eddff0b0a
  47. mempool: eliminate accessors to mempool entry ancestor/descendant cached state 2f39360d64
  48. Remove unused members from CTxMemPoolEntry c60f9269e8
  49. Remove mempool logic designed to maintain ancestor/descendant state 0144d26fd4
  50. mempool: addUnchecked no longer needs ancestors f02ff83700
  51. Remove unused limits from CalculateMemPoolAncestors 3c5b86cbc5
  52. Make removeConflicts private abd59d3541
  53. 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.
    96c375a077
  54. Use txgraph to calculate ancestors e8404ce56a
  55. Use txgraph to calculate descendants b069f57bb2
  56. Rework truc_policy to use descendants, not children c26e796a1b
  57. 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 (note that it's fine to calculate
      ancestors of in-mempool transactions, if the number of such calls is
      reasonably bounded).
    - 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().
    9c9a9cfe05
  58. Make getting parents/children a function of the mempool, not a mempool entry 3e72e6e0f1
  59. Eliminate CheckPackageLimits, which no longer does anything e013297f24
  60. Fix miniminer_tests to work with cluster limits 03413d2681
  61. Rewrite GatherClusters to use the txgraph implementation 57cb99c825
  62. Stop tracking parents/children outside of txgraph 545dadbbb1
  63. 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
    0fab5df382
  64. bench: add more mempool benchmarks
    Add benchmarks for:
    
      - adding a transaction
      - calculating mempool ancestors/descendants
    8641efa1c7
  65. fuzz: try to add more code coverage for mempool fuzzing
    Including test coverage for mempool eviction and expiry
    e788f2295c
  66. Expose cluster information via rpc
    Co-authored-by: glozow <gloriajzhao@gmail.com>
    14dcabb677
  67. squashme: only output weight, not vsize, for cluster/chunk information ccf7c5ac41
  68. doc: Update mempool_replacements.md to reflect feerate diagram checks b6024299e6
  69. test: add functional test for new cluster mempool RPCs
    Co-authored-by: glozow <gloriajzhao@gmail.com>
    d60a4fb4f2
  70. fuzz: remove comparison between mini_miner block construction and miner
    After cluster mempool, the mini_miner will no longer match the miner's block
    construction. Eventually mini_miner should be reworked to directly use
    linearizations done in the mempool.
    bf7dabfccb
  71. Invoke TxGraph::DoWork() at appropriate times d4cf674644
  72. Update comments for CTxMemPool class dc0b0d5db8
  73. Add check that GetSortedScoreWithTopology() agrees with CompareMiningScoreWithTopology()
    We use CompareMiningScoreWithTopology() for sorting transaction announcements
    during tx relay, and we use GetSortedScoreWithTopology() in
    CTxMemPool::check().
    d6d50bc485
  74. doc: update policy/packages.md for new package acceptance logic 4c44208c9f
  75. test: extend package rbf functional test to larger clusters
    Co-Authored-By: Gregory Sanders <gsanders87@gmail.com>
    4ef2596254
  76. Sanity check `GetFeerateDiagram()` in CTxMemPool::check() 1d13468a8a
  77. Use cluster size limit for -maxmempool bound, and allow -maxmempool=0 in general
    Previously we would sanity check the -maxmempool configuration based on a
    multiple of the descendant size limit, but with cluster mempool the maximum
    evicted size is now the cluster size limit, so use that instead.
    
    Also allow -maxmempool=0 in general (and not just if
    -limitdescendantsize/-limitclustersize is set to 0).
    5b5a41b943
  78. DrahtBot added the label Needs rebase on Nov 12, 2025
  79. DrahtBot commented at 4:59 pm on November 12, 2025: contributor
    🐙 This pull request conflicts with the target branch and needs rebase.
  80. ==== FOLLOWUPS ==== ee9b8c7b76
  81. Remove unused variable (cacheMap) in mempool 5eb38793c4
  82. Remove unused argument to RemoveStaged be5649f55a
  83. Simplify removeRecursive 2a2f115361
  84. 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-
    a079948fa9
  85. Rewrite removeForReorg to avoid using sets 390fbdef94
  86. Rewrite GetChildren without sets 416f5ddb32
  87. Invoke removeUnchecked() directly in removeForBlock() 2d68166c62
  88. Warn user if using -limitancestorsize/-limitdescendantsize that the options have no effect 9224f72c3a
  89. Remove ancestor and descendant vsize limits from MemPoolLimits e5683904a4
  90. Use cluster limits instead of ancestor/descendant limits when sanity checking package policy limits f9bc8e5b84
  91. Use cluster size limit instead of ancestor/descendant size limits when sanity checking TRUC policy limits a0a2d29e9e
  92. Use cluster size limit instead of ancestor size limit in txpackage unit test 680081a482
  93. Remove unused DEFAULT_ANCESTOR_SIZE_LIMIT_KVB and DEFAULT_DESCENDANT_SIZE_LIMIT_KVB 45d246a74c
  94. Add a GetFeePerVSize() accessor to CFeeRate, and use it in the BlockAssembler 302f02099e
  95. miner: replace "package" with "chunk"
    This makes the terminology consistent with other parts of the codebase, as part
    of the cluster mempool implementation.
    ca19677cec
  96. doc: Update mempool-limits.md for cluster mempool c672159e17
  97. doc: add design notes for cluster mempool
    For now, just link to the long writeups on delvingbitcoin.org
    ef4d9c7959
  98. doc: add release notes snippet for cluster mempool 48626186ff
  99. Avoid using mapTx.modify() to update modified fees
    Now that the mempool no longer keeps any feerate-based indices, we can modify
    feerates in mempool entries directly.
    8866c11931
  100. rpc: improve getmempoolcluster output 34c49f0782
  101. sdaftuar force-pushed on Nov 12, 2025

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-11-20 00:12 UTC

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