Motivation
In Internal interface guidelines
It’s stated that
Interface method definitions should wrap existing functionality instead of implementing new functionality. Any substantial new node or wallet functionality should be implemented in src/node/ or src/wallet/ and just exposed in src/interfaces/ instead of being implemented there, so it can be more modular and accessible to unit tests.
However the some methods in the newly added BlockTemplateImpl
and MinerImpl
classes partially enforces this guideline, as the implementations of the submitSolution
, waitNext
, and waitTipChanged
methods reside within the class itself.
What the PR Does
This PR introduces a simple refactor by moving certain method implementations from BlockTemplateImpl
into the miner module. It introduces three new functions:
-
AddMerkleRootAndCoinbase
: Computes the block’s Merkle root, inserts the coinbase transaction, and sets the Merkle root in the block. This function is called bysubmitSolution
before the block is submitted for processing. -
WaitNext
: Returns a new block template either when transaction fees reach a certain threshold or when a new tip is detected. If a timeout is reached, it returnsnullopt
. ThewaitNext
method inBlockTemplateImpl
now simply wraps this function. -
ChainTipChanged
: Returnstrue
when the chain tip changes, orfalse
if a timeout or interrupt occurs. ThewaitTipChanged
method inMinerImpl
now callsGetTip
after invokingChainTipChanged
, and returnstrue
.
Behavior Change
- We now only
Assert
for a valid chainman and notifications pointer once at the top of the functions.