For Stratum v2 custom job declaration to be bandwidth efficient, the pool can request1 only the transactions that it doesn’t know about.
The spec doesn’t specify how this is achieved, but one method is to call the getrawtransaction RPC on each transaction id listed in DeclareMiningJob (or a subset if the pool software maintains a cache). Using RPC is inefficient, made worse by the need to make multiple calls. It also doesn’t support queuing by witness id (yet, see #34013).
This PR introduces two new IPC methods:
getTransactions(): takes a list ofTxid’sgetTransactionsByWitnessID(): : takes a list ofWtxid’s
Both return a list of serialised transactions. An empty element is returned for transactions that were not found.
The Txid variant, just like its RPC counterpart, takes advantage of -txindex if enabled. The Wtxid variant can’t do that unless we add a -witnesstxindex, but at least sv2 has no use for that.
The RPC additionally allows providing a block_hash hint. I haven’t implemented that here because I don’t have a need or it. It can always be added later.
I thought about having a single (or overloaded) getTransactions() that works with both Txid and Wtxid, but I prefer that clients are intentional about which one they want.
A unit and functional test cover the new functionality.
Sv2 probably only needs getTransactionsByWitnessID(), but it’s easy enough to just add both.
TODO:
- figure out https://github.com/bitcoin-core/libmultiprocess/issues/235 (this PR is draft pending that, subtree linter failure is expected)
-
there’s two reasons the pool requests these transactions: to approve the template and to broadcast the block if a solution is found (the miner will also broadcast via their template provider). See also https://github.com/stratum-mining/sv2-spec/issues/170 ↩︎