The Stratum v2 protocol allows pushing out templates as fees in the mempool increase. This interface lets us know when it’s time to do so.
I split the implementation into two parts because I’m not sure if we should include the second commit now, or wait until cluster mempool #30289 is merged.
The first commit contains a mock implementation very similiar to how longpolling in getblocktemplate
works. It calls getTransactionsUpdated
once per second. This returns true
anytime a transaction is added to the mempool, even if it has no impact on fees in the best block.
The second commit creates a new block template so it can actually measure the fees. It’s slightly faster getNewBlock()
because it skips verification.
On my 2019 Intel MacBook Pro it takes about 20ms to generate a block template. The waitFeesChanged()
waits 1 second between each CreateNewBlock
call so as to not burden the node too much. But on (very) low end hardware this may still be problematic.
The second commit does not change the interface, so it could be left out if people prefer that. I’m not sure what performance increase to expect from cluster mempool.
The interface intentionally does not return the resulting template, so that the implementation can be optimized further. Downside is that the caller needs to do another getNewBlock()
.
The changes here can use to make longpolling getblocktemplate
more efficient, by only returning the RPC call when template fees actually increased. However this PR does not touch that RPC code.