This implements “Child-pays-for-parent” transaction selection in CreateNewBlock
, where we sort the mempool using (modified) feerate with ancestors and consider transactions in that order during block creation. As transactions are selected, a separate map is used to track the new feerate-with-ancestors value to use for in-mempool descendants that haven’t yet been selected.
This is almost strictly better (ie, results in higher-fee blocks) than the existing mining algorithm, with some small variance due to edge cases around which transactions might get selected as the new block’s size approaches the maximum allowed. Moreover the performance impact on CreateNewBlock
is minimal – I observed that the total run time of the function actually slightly improved, apparently due to TestBlockValidity
being on average slightly faster (a somewhat surprising result).
The actual fee improvements observed were fairly low in the time period I looked at (October 2015), roughly a 1% fee improvement overall. I think that is driven first and foremost by blocks not really being full for a large bulk of the time period, so on a large number of data points the results were identical. Additionally, my guess is that user behavior may not have adapted to this type of transaction selection being widely deployed, and so in the future perhaps we might expect to see larger differences. I did note a handful of instances where the implementation here notably outperformed the existing algorithm, in some instances more than 20% better, but those were the exception and not the rule.
For comparison, I found no examples where the old algorithm produced a block with 0.5% or more in fees than the new algorithm (and few examples where the old algorithm’s block had more fees at all, around 1% of samples).
I’ve labeled this PR as a work-in-progress for now, as it builds off two other open PR’s (#7594 and #7598). Once those are reviewed and merged, I’ll rebase this and remove the WIP label. I opened this now to help motivate the work in those two PRs.
One open question I have is whether it’s worth keeping around the old transaction selection algorithm. The refactor in #7598 that this builds on makes it easy to leave it around, and I don’t think it would be hard to add command line arguments for policy configuration that would enable using the older algorithm. But I don’t know if that’s of interest to anyone, so for now I figure we can let people mull it over and decide what to do in a future PR.
A related question to that is whether to get rid of the existing mempool “score” index. The ancestor tracking pull adds a new ancestor feerate index without removing the old feerate index, but if we decide to get rid of the mining algorithm that uses that index, then perhaps we could also eliminate this mempool index as well.
To do: