Commit Graph

488 Commits

Author SHA1 Message Date
MarcoFalke
fa5f297748 scripted-diff: [doc] Unify stale copyright headers
-BEGIN VERIFY SCRIPT-

 sed --in-place --regexp-extended \
   's;( 20[0-2][0-9])(-20[0-2][0-9])? The Bitcoin Core developers;\1-present The Bitcoin Core developers;g' \
   $( git grep -l 'The Bitcoin Core developers' -- ':(exclude)COPYING' ':(exclude)src/ipc/libmultiprocess' ':(exclude)src/minisketch' )

-END VERIFY SCRIPT-
2025-12-16 22:21:15 +01:00
MarcoFalke
fa05181d90 scripted-diff: LogPrintf -> LogInfo
This refactor does not change behavior.

-BEGIN VERIFY SCRIPT-

 sed --in-place 's/\<LogPrintf\>/LogInfo/g' \
   $( git grep -l '\<LogPrintf\>' -- ./contrib/ ./src/ ./test/ ':(exclude)src/logging.h' )

-END VERIFY SCRIPT-
2025-12-04 19:52:49 +01:00
Suhas Daftuar
b8d279a81c doc: add comment to explain correctness of GatherClusters() 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
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
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
a5a7905d83 Simplify removeRecursive 2025-11-30 10:57:48 -05:00
Suhas Daftuar
01d8520038 Remove unused argument to RemoveStaged 2025-11-30 10:57:15 -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 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
9567eaa66d Invoke TxGraph::DoWork() at appropriate times 2025-11-21 19:31:58 -05:00
Suhas Daftuar
21693f031a Expose cluster information via rpc
Co-authored-by: glozow <gloriajzhao@gmail.com>
2025-11-18 11:14:52 -05:00
Suhas Daftuar
72e74e0d42 fuzz: try to add more code coverage for mempool fuzzing
Including test coverage for mempool eviction and expiry
2025-11-18 10:48:23 -05:00
Suhas Daftuar
84de685cf7 Stop tracking parents/children outside of txgraph 2025-11-18 10:48:23 -05:00
Suhas Daftuar
88672e205b Rewrite GatherClusters to use the txgraph implementation 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
19b8479868 Make getting parents/children a function of the mempool, not a mempool entry 2025-11-18 10:40:31 -05:00
Suhas Daftuar
a4458d6c40 Use txgraph to calculate descendants 2025-11-18 09:29:36 -05:00
Suhas Daftuar
c8b6f70d64 Use txgraph to calculate ancestors 2025-11-18 09:29:36 -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
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
cf3ab8e1d0 Stop enforcing descendant size/count limits
Cluster size limits should be enough.
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 Daftuar
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
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 Daftuar
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 Daftuar
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
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
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
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
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
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
Anthony Towns
b7b249d3ad Revert "[refactor] rewrite vTxHashes as a vector of CTransactionRef"
This reverts commit a03aef9cec.
2025-08-27 03:33:32 +10:00
marcofleon
f6c0d1d231 mempool, refactor: Convert uint256 to Txid 2025-08-11 16:26:35 +01:00
marcofleon
aeb0f78330 refactor: Convert mini_miner from uint256 to Txid 2025-08-11 16:12:42 +01:00