Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
Rewrite CreateNewBlock #6898
WARNING: This hasn't been used for mainnet mining yet as far as I know.
The mempool is explicitly assumed to be responsible for maintaining consistency of transactions with respect to not spending non-existent outputs, not double spending, script validity and coinbase maturity. Only finality of transactions is checked before assembling a block.
A final call to TestBlockValidity is still performed. If an invalid block has been constructed, then an error is thrown
This code produces the same blocks as the code it replaces with the following exceptions:
Comparing this to the original code over 2000 calls to CreateNewBlock over the last 2 days.
The extra slowness in TestBlockValidity is because the cache used to be warmed up in the assembly code.
OK, this has been rewritten to use
Of course until #6357 is merged or some other decision is taken regarding priority, it will not sort by an accurate measure of priority.
I addressed @luke-jr 's comment about changing the method of failure return. I still modified it to give some extra state info. That commit and other fixes will get squashed.
Among the remaining outstanding items is to fix the constructor for CTxMemPoolEntry to not have any default arguments. It would be nice to know a merge order since this will conflict with #6357 and #6915 and involves tedious updating of a bunch of tests.
I rebased this and squashed fixes for comments so far.
I rebased it on top of #7008, because I needed to pick some path forward on how priority would be addressed in this PR. The first 3 commits are therefore part of that pull and not this one. If we decide to merge #6357 as well, then it should be an easy change.
I will continue testing, but I don't have any other changes planned right now.
Apologies for all the churn. Squashed again and rebased off a slightly modified index @sdaftuar created for #7062. This introduces one more minor difference from the original code in that fee rates are compared as doubles now.
If I correct for these differences:
Then I generate the exact same blocks as the old code modulo a few rare cases where double imprecision in the different priority calculation causes tx reordering in the priority space.
that was an expected merge conflict, will rebase shortly
@laanwj my warning about not having mined, was just a literal warning because i don't have sufficient hashpower to mine on mainnet. I have created 1000s upon 1000s of block templates that all pass TestBlockValidity both in code running this pull live for the past 2 weeks (and prior iterations for weeks before that) and in historical simulation over 6 weeks of data.
Store sum of legacy and P2SH sig op counts. This is calculated in AcceptToMemory pool and storing it saves redoing the expensive calculation in block template creation.
The score index is meant to represent the order of priority for being included in a block for miners. Initially this is set to the transactions modified (by any feeDelta) fee rate. Index improvements and unit tests by sdaftuar.
Use the score index on the mempool to only add sorted txs in order. Remove much of the validation while building the block, relying on mempool to be consistent and only contain txs that can be mined. The mempool is assumed to be consistent as far as not containing txs which spend non-existent outputs or double spends, and scripts are valid. Finality of txs is still checked (except not coinbase maturity, assumed in mempool). Still TestBlockValidity in case mempool consistency breaks and return error state if an invalid block was created. Unit tests are modified to realize that invalid blocks can now be constructed if the mempool breaks its consistency assumptions and also updated to have the right fees, since the cached value is now used for block construction. Conflicts: src/miner.cpp
553cad9 Rewrite CreateNewBlock (Alex Morcos) 5f12263 Expose FormatStateMessage (Alex Morcos) 1f09287 Make accessing mempool parents and children public (Alex Morcos) 7230187 Add TxPriority class and comparator (Alex Morcos) f3fe836 Add a score index to the mempool. (Alex Morcos) c49d5bc Store the total sig op count of a tx. (Alex Morcos)
The priority area is often our only defense against spam, so disabling it should not be encouraged. Additionally, the only benefit for disabling it is performance, which is no longer an issue with bitcoin#6898. While there may be arguably better policies for handling priority, these are not yet supported (nor even evaluated theoretically or tested in practice). Until those are implemented and tested, we shouldn't regress default policy.