100 Commits
Author SHA1 Message Date
Suhas Daftuar 40735450c0 Remove unused epochguard.h 2026-01-22 21:51:13 -05:00
Suhas DaftuarandPieter Wuille 1a8494d16c Rework CTxMemPool::GetChildren() to not use epochs
This is likely slightly slower, but this was the last place we were using
epochs instead of sets to deduplicate, and this is only used by the RPC code
and in tests, and should not be CPU-performance critical. Eliminating this
allows us to save 8 bytes in CTxMemPoolEntry.

Co-Authored-By: Pieter Wuille <bitcoin-dev@wuille.net>
2026-01-22 21:51:13 -05:00
Suhas Daftuar b8d279a81c doc: add comment to explain correctness of GatherClusters() 2025-12-01 10:53:22 -05:00
Suhas Daftuar aba7500a30 Fix parameter name in getmempoolcluster rpc 2025-12-01 10:53:22 -05:00
Suhas Daftuarandglozow 6c1325a091 Rename weight -> clusterweight in RPC output, and add doc explaining mempool terminology
Co-authored-by: glozow <gloriajzhao@gmail.com>
2025-12-01 10:53:22 -05:00
Suhas Daftuar bc2eb931da Require mempool lock to be held when invoking TRUC checks 2025-12-01 10:53:22 -05:00
Suhas Daftuar 957ae23241 Improve comments for getTransactionAncestry to reference cluster counts instead of descendants 2025-12-01 10:53:22 -05:00
Suhas Daftuar d97d6199ce Fix comment to reference cluster limits, not chain limits 2025-12-01 10:53:22 -05:00
Suhas Daftuar a1b341ef98 Sanity check feerate diagram in CTxMemPool::check()
Also switch Assume()'s to assert()'s, so that failures in this function are
always caught.
2025-12-01 10:53:22 -05:00
Suhas Daftuar 23d6f457c4 rpc: improve getmempoolcluster output 2025-12-01 10:53:19 -05:00
Suhas Daftuar d2dcd37aac 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.
2025-12-01 10:50:05 -05:00
Suhas Daftuar d84ffc24d2 doc: add release notes snippet for cluster mempool 2025-12-01 10:49:38 -05:00
Suhas Daftuar b0417ba944 doc: Add design notes for cluster mempool and explain new mempool limits 2025-12-01 10:42:39 -05:00
Suhas Daftuar 2d88966e43 miner: replace "package" with "chunk"
This makes the terminology consistent with other parts of the codebase, as part
of the cluster mempool implementation.
2025-11-30 13:50:04 -05:00
Suhas Daftuar 6f3e8eb300 Add a GetFeePerVSize() accessor to CFeeRate, and use it in the BlockAssembler 2025-11-30 13:50:04 -05:00
Suhas Daftuar b5f245f6f2 Remove unused DEFAULT_ANCESTOR_SIZE_LIMIT_KVB and DEFAULT_DESCENDANT_SIZE_LIMIT_KVB 2025-11-30 13:50:04 -05:00
Suhas Daftuar 1dac54d506 Use cluster size limit instead of ancestor size limit in txpackage unit test 2025-11-30 13:50:04 -05:00
Suhas Daftuar 04f65488ca Use cluster size limit instead of ancestor/descendant size limits when sanity checking TRUC policy limits 2025-11-30 13:50:04 -05:00
Suhas Daftuar 634291a7dc Use cluster limits instead of ancestor/descendant limits when sanity checking package policy limits 2025-11-30 13:50:04 -05:00
Suhas Daftuar fc18ef1f3f Remove ancestor and descendant vsize limits from MemPoolLimits 2025-11-30 13:50:04 -05:00
Suhas Daftuar ed8e819121 Warn user if using -limitancestorsize/-limitdescendantsize that the options have no effect
Also update the help text for -limitancestorcount/-limitdescendantcount to
explain they no longer affect the mempool, and are only used by the wallet for
coin selection.
2025-11-30 13:50:00 -05:00
Suhas Daftuar 80d8df2d47 Invoke removeUnchecked() directly in removeForBlock() 2025-11-30 11:02:08 -05:00
Suhas Daftuar 9292570f4c Rewrite GetChildren without sets 2025-11-30 11:02:08 -05:00
Suhas Daftuar 3e39ea8c30 Rewrite removeForReorg to avoid using sets
Also improve test coverage for removeForReorg by creating a scenario where
there are in-mempool descendants that are only invalidated due to an in-mempool
parent no longer spending a mature coin.
2025-11-30 11:01:57 -05:00
Suhas Daftuar a3c31dfd71 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-
2025-11-30 10:57:48 -05:00
Suhas Daftuar a5a7905d83 Simplify removeRecursive 2025-11-30 10:57:48 -05:00
Suhas Daftuar bc64013e6f Remove unused variable (cacheMap) in mempool 2025-11-25 10:46:14 -05:00
Suhas Daftuar 17cf9ff7ef 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).
2025-11-21 22:02:07 -05:00
Suhas Daftuar 315e43e5d8 Sanity check GetFeerateDiagram() in CTxMemPool::check() 2025-11-21 22:02:07 -05:00
Suhas DaftuarandGregory Sanders de2e9a24c4 test: extend package rbf functional test to larger clusters
Co-Authored-By: Gregory Sanders <gsanders87@gmail.com>
2025-11-21 22:02:07 -05:00
Suhas Daftuar 4ef4ddb504 doc: update policy/packages.md for new package acceptance logic 2025-11-21 22:02:07 -05:00
Suhas Daftuar 79f73ad713 Add check that GetSortedScoreWithTopology() agrees with CompareMiningScoreWithTopology()
We use CompareMiningScoreWithTopology() for sorting transaction announcements
during tx relay, and we use GetSortedScoreWithTopology() in
CTxMemPool::check().
2025-11-21 22:02:07 -05:00
Suhas Daftuar a86ac11768 Update comments for CTxMemPool class 2025-11-21 22:02:07 -05:00
Suhas Daftuar 9567eaa66d Invoke TxGraph::DoWork() at appropriate times 2025-11-21 19:31:58 -05:00
Suhas Daftuarandglozow 6c5c44f774 test: add functional test for new cluster mempool RPCs
Co-authored-by: glozow <gloriajzhao@gmail.com>
2025-11-18 11:14:52 -05:00
Suhas Daftuar 72f60c877e doc: Update mempool_replacements.md to reflect feerate diagram checks 2025-11-18 11:14:52 -05:00
Suhas Daftuarandglozow 21693f031a Expose cluster information via rpc
Co-authored-by: glozow <gloriajzhao@gmail.com>
2025-11-18 11:14:52 -05:00
Suhas Daftuar f107417490 bench: add more mempool benchmarks
Add benchmarks for:

  - adding a transaction
  - calculating mempool ancestors/descendants
2025-11-18 10:48:23 -05:00
Suhas Daftuar 7976eb1ae7 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
2025-11-18 10:48:23 -05:00
Suhas Daftuar 1ca4f01090 Fix miniminer_tests to work with cluster limits 2025-11-18 10:48:23 -05:00
Suhas Daftuar 1902111e0f Eliminate CheckPackageLimits, which no longer does anything 2025-11-18 10:48:23 -05:00
Suhas Daftuar 3a646ec462 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().
2025-11-18 10:48:22 -05:00
Suhas Daftuar 5560913e51 Rework truc_policy to use descendants, not children 2025-11-18 10:35:19 -05:00
Suhas Daftuar 241a3e666b 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.
2025-11-18 09:29:36 -05:00
Suhas Daftuar b9cec7f0a1 Make removeConflicts private 2025-11-18 09:29:36 -05:00
Suhas Daftuar 0402e6c780 Remove unused limits from CalculateMemPoolAncestors 2025-11-18 09:29:35 -05:00
Suhas Daftuar 08be765ac2 Remove mempool logic designed to maintain ancestor/descendant state 2025-11-18 09:28:31 -05:00
Suhas Daftuar fc4e3e6bc1 Remove unused members from CTxMemPoolEntry 2025-11-18 09:28:31 -05:00
Suhas Daftuar ff3b398d12 mempool: eliminate accessors to mempool entry ancestor/descendant cached state 2025-11-18 09:28:31 -05:00
Suhas Daftuar ba09fc9774 mempool: Remove unused function CalculateDescendantMaximum 2025-11-18 09:02:48 -05:00
Suhas Daftuar 8e49477e86 wallet: Replace max descendant count 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.
2025-11-18 09:02:48 -05:00
Suhas Daftuar e031085fd4 Eliminate Single-Conflict RBF Carve Out
The new cluster mempool RBF rules take into account clusters sizes exactly, so
with the removal of descendant count enforcement this idea is obsolete.
2025-11-18 09:02:05 -05:00
Suhas Daftuar cf3ab8e1d0 Stop enforcing descendant size/count limits
Cluster size limits should be enough.
2025-11-18 08:57:51 -05:00
Suhas Daftuar 89ae38f489 test: remove rbf carveout test from mempool_limit.py 2025-11-18 08:57:51 -05:00
Suhas Daftuar c0bd04d18f Calculate descendant information for mempool RPC output on-the-fly
This is in preparation for removing the cached descendant state from the
mempool.
2025-11-18 08:57:51 -05:00
Suhas Daftuar bdcefb8a8b 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.
2025-11-18 08:57:51 -05:00
Suhas DaftuarandGregory Sanders 9cda64b86c Stop enforcing ancestor size/count limits
The cluster limits should be sufficient.

Co-Authored-By: Gregory Sanders <gsanders87@gmail.com>
2025-11-18 08:57:51 -05:00
Suhas Daftuar 1f93227a84 Remove dependency on cached ancestor data in mini-miner 2025-11-18 08:57:51 -05:00
Suhas Daftuar 9fbe0a4ac2 rpc: Calculate ancestor data from scratch for mempool rpc calls 2025-11-18 08:57:51 -05:00
Suhas Daftuar 7961496dda Reimplement GetTransactionAncestry() to not rely on cached data
In preparation for removing ancestor data from CTxMemPoolEntry, recalculate the
ancestor statistics on demand wherever needed.
2025-11-18 08:57:51 -05:00
Suhas DaftuarandPieter Wuille feceaa42e8 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>
2025-11-18 08:53:59 -05:00
Suhas Daftuar 21b5cea588 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.
2025-11-18 08:53:59 -05:00
Suhas Daftuar 6445aa7d97 Remove the ancestor and descendant indices from the mempool 2025-11-18 08:53:59 -05:00
Suhas DaftuarandGregory Sanders <gsanders87@gmail.com>, glozow 216e693729 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>
2025-11-18 08:53:59 -05:00
Suhas Daftuar ff8f115dec 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.
2025-11-18 08:53:59 -05:00
Suhas Daftuar c3f1afc934 test: rewrite PopulateMempool to not violate mempool policy (cluster size) limits 2025-11-18 08:53:59 -05:00
Suhas DaftuarandGregory Sanders 47ab32fdb1 Select transactions for blocks based on chunk feerate
Co-Authored-By: Gregory Sanders <gsanders87@gmail.com>
2025-11-18 08:53:58 -05:00
Suhas Daftuar dec138d1dd 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.
2025-11-18 08:53:58 -05:00
Suhas Daftuar 6c2bceb200 bench: rewrite ComplexMemPool to not create oversized clusters 2025-11-18 08:53:58 -05:00
Suhas Daftuar 1ad4590f63 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.
2025-11-18 08:53:58 -05:00
Suhas Daftuar b11c89cab2 Rework miner_tests to not require large cluster limit 2025-11-18 08:53:58 -05:00
Suhas Daftuar 95a8297d48 Check cluster limits when using -walletrejectlongchains 2025-11-18 08:53:58 -05:00
Suhas Daftuar 95762e6759 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.
2025-11-18 08:53:58 -05:00
Suhas Daftuar 435fd56711 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.
2025-11-18 08:53:58 -05:00
Suhas Daftuar 34e32985e8 Add new (unused) limits for cluster size/count 2025-11-18 08:53:58 -05:00
Suhas Daftuar 838d7e3553 Add transactions to txgraph, but without cluster dependencies
Effectively this is treating all transactions in txgraph as being in a cluster
of size 1.
2025-11-18 08:53:58 -05:00
Suhas Daftuar d5ed9cb3eb Add accessor for sigops-adjusted weight 2025-11-10 16:01:34 -05:00
Suhas Daftuar 1bf3b51396 Add sigops adjusted weight calculator 2025-11-10 15:55:43 -05:00
Suhas Daftuar c18c68a950 Create a txgraph inside CTxMemPool 2025-11-10 15:54:53 -05:00
Suhas Daftuar 29a94d5b2f Make CTxMemPoolEntry derive from TxGraph::Ref 2025-11-10 15:46:11 -05:00
Suhas Daftuar 92b0079fe3 Allow moving CTxMemPoolEntry objects, disallow copying 2025-11-10 15:45:55 -05:00
Suhas Daftuar 6c73e47448 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.
2025-10-14 14:03:42 -04:00
Suhas Daftuar 51430680ec Allow moving an Epoch::Marker 2025-10-14 14:03:42 -04:00
Suhas Daftuar a4ec07f194 doc: add comments for CTxMemPool::ChangeSet 2024-11-13 13:27:01 -05:00
Suhas Daftuar 83f814b1d1 Remove m_all_conflicts from SubPackageState 2024-11-13 13:27:01 -05:00
Suhas Daftuar d3c8e7dfb6 Ensure that we don't add duplicate transactions in rbf fuzz tests 2024-11-13 13:27:01 -05:00
Suhas Daftuar d7dc9fd2f7 Move CalculateChunksForRBF() to the mempool changeset 2024-11-13 13:27:01 -05:00
Suhas Daftuar 284a1d33f1 Move prioritisation into changeset 2024-11-13 13:27:01 -05:00
Suhas Daftuar 446b08b599 Don't distinguish between direct conflicts and all conflicts when doing cluster-size-2-rbf checks 2024-11-13 13:27:01 -05:00
Suhas Daftuar b53041021a Duplicate transactions are not permitted within a changeset 2024-11-13 13:27:01 -05:00
Suhas Daftuar 2b30f4d36c Make RemoveStaged() private 2024-11-13 13:27:01 -05:00
Suhas Daftuar 18829194ca Enforce that there is only one changeset at a time 2024-11-13 13:27:01 -05:00
Suhas Daftuar 7fb62f7db6 Apply mempool changeset transactions directly into the mempool
Rather than individually calling addUnchecked for each transaction added in a
changeset (after removing all the to-be-removed transactions), instead we can
take advantage of boost::multi_index's splicing features to extract and insert
entries directly from the staging multi_index into mapTx.

This has the immediate advantage of saving allocation overhead for mempool
entries which have already been allocated once. This also means that the memory
locations of mempool entries will not change when transactions go from staging
to the main mempool.

Additionally, eliminate addUnchecked and require all new transactions to enter
the mempool via a CTxMemPoolChangeSet.
2024-11-13 13:26:56 -05:00
Suhas Daftuar 34b6c5833d Clean up FinalizeSubpackage to avoid workspace-specific information
Also, use the "package hash" for logging replacements in the package rbf
setting.
2024-11-13 13:19:58 -05:00
Suhas Daftuar 57983b8add Move LimitMempoolSize to take place outside FinalizeSubpackage 2024-11-13 13:17:28 -05:00
Suhas Daftuar 01e145b975 Move changeset from workspace to subpackage
Removes a redundant check that mempool limits will not be violated during
package acceptance.
2024-11-13 13:17:27 -05:00
Suhas Daftuar 802214c083 Introduce mempool changesets
Introduce the CTxMemPool::ChangeSet, a wrapper for creating (potential) new
mempool entries and removing conflicts.
2024-11-13 13:15:12 -05:00
Suhas Daftuar 87d92fa340 test: Add unit test coverage of package rbf + prioritisetransaction 2024-11-13 13:10:57 -05:00
Suhas Daftuar 15d982f91e Add package hash to package-rbf log message 2024-11-13 13:10:57 -05:00
Suhas Daftuar f8a141c2da test: Don't rely on incentive incompatible replacement in mempool_accept_v3.py 2024-04-29 12:15:30 -04:00