A subtle (and minor) bug in how limits are calculated & checked in CalculateAncestorsAndCheckLimits
https://github.com/bitcoin/bitcoin/blob/master/src/txmempool.cpp#L207
This helper can be invoked in a few cases:
CTxMemPool::CalculateMemPoolAncestors
invokes it, iffSearchForParents
istrue
, andentry
is not in the mempool, thenCalculateAncestorsAndCheckLimits
will be exact/correct.CTxMemPool::CalculateMemPoolAncestors
invokes it, in the cases whereentry
is already in the mempool, we have an off-by-one error here https://github.com/bitcoin/bitcoin/blob/master/src/txmempool.cpp#L230 (becausestageit->GetCountWithDescendants()
will includeentry
in its count
So (2) highlights the case where there’s a bug, and it’s quite common.
We also need to think about how CTxMemPool::CheckPackageLimits
uses this helper. I think it works better in this case because we have the assumption:
0Calculate all in-mempool ancestors of a set of transactions not already in the mempool and
1* check ancestor and descendant limits
ie we know none of the txns in package
are in the mempool. So no double counting.
I doubt this is a serious bug, but I though it’s at least worth bringing up. It also seemed tricky to fix this with minimal/simple changes that works in all cases this helper is/may be used.
ie here https://github.com/bitcoin/bitcoin/blob/master/src/txmempool.cpp#L309, when fSearchForParents
is true
and one/some of the parents of this transaction are not in the mempool. Currently these parents (and any of their potential ancestors) are not included in the unconfirmed parents check. Again I don’t know if this actually matters, or if its unnecessary complexity, but want to check