After compact blocks (BIP 152), including recently received transactions in a block may lead to propagation delays relative to blocks without such transactions, because recently received transactions may not yet be in peers’ mempools.
Account for this in CreateNewBlock()
by adding two new parameters:
-recenttxwindow
defines a “recent transaction” as having been received less than this many milliseconds ago-recenttxstalerate
models the additional likelihood of a block being stale because it includes a recent transaction.
Briefly, if I_0
is the block income you’d receive using only non-recent transactions, and I_1
is the income including recently received transactions, and s
is the value being used for -recenttxstalerate
, then CreateNewBlock
is now going to choose the block that doesn’t include recent transactions if I_0 >= (1-s) * I_1
.
Notes for reviewers:
- I struggled to name and explain these two parameters, so suggestions on alternate/less confusing parameter names and explanation would be appreciated! @ryanofsky suggested
-recenttxblockdiscount
or-recenttxminingpenalty
to try to describe what I called the stale rate; I think those are reasonable suggestions as well. - Suggestions are also welcome for what the defaults should be (in particular, should this be enabled at all by default?)
- In my most recent performance measurements of a slightly earlier version of this patch, I measured an approximately 3ms slowdown (~ 7ms -> ~ 10ms) in the transaction selection portion of
CreateNewBlock()
. I suspect we can optimizeCreateNewBlock
further, but I’d like to save that for a future PR as this is already a lengthy patch. - The idea in this PR is to produce two block candidates, one with recent transactions and one without, and then compare block income and pick a winner. The candidate which does not include recent transactions is not going to be as good in general as the regular ancestor-feerate-mining algorithm being called on a mempool that doesn’t contain any recent transactions, because for performance reasons we might continue to include low-fee ancestors of recent transactions (ie, we kick out recent transactions from the block, but not their ancestors). Despite this, I think for most reasonable parameters we will be overwhelmingly choosing the block that doesn’t include recent transactions, so I don’t think this is a big deal at the moment. We could try to improve this in the future, however (possibly by adding a smart caching layer on top).
- This PR includes a (slow) functional test for the mining code, which I’ve added to the extended test suite.
Thanks @JeremyRubin and @ryanofsky for feedback on an earlier version of this patch.