Based on on @Fi3’s https://github.com/bitcoin/bitcoin/compare/master...Fi3:bitcoin:PatchTemplates which is based on @ccdle12’s #27854. I rebased it and re-wrote the commit history. See the original branch for the evolution of the spec.
See docs/stratum-v2.md for a brief description of Stratum v2 and the role of Bitcoin Core in that system..
What to test and review?
See the testing guide for various ways to test this PR. This branch is actively used by (testnet) pools, so it should be ready for high level review.
I’ll make separate pull requests for parts that are ready for detailed review. Probably starting with ECDH and the Noise Protocol.
Implementation notes
Silent Payments also needs the ECDH module, so I cherry-picked the commit from #28122. It uses ECDH is a slightly different way, but perhaps there’s more overlap to be had.
Contributing
If you want to help out with any of the issues below, please open a PR to my fork. I will then squash your commits into my own where needed.
Upstream issues
Spec
- modify spec to use
ProvideMissingTransactions
? (followup?) - pick a good default for
default_coinbase_tx_additional_output_size
(seegetblocktemplate
RPC)
Noise
- use EllSwift https://github.com/stratum-mining/sv2-spec/pull/66, implemented in https://github.com/Sjors/bitcoin/pull/28
- certificate signing issue: https://github.com/stratum-mining/stratum/issues/717, fix in https://github.com/Sjors/bitcoin/pull/29
Networking
- add
-sv2bind
and-sv2allowip
- persist static key (needs #29229)
- optional
-sv2cert
- create
Sv2Transport
subclass similar toV2Transport
: https://github.com/Sjors/bitcoin/pull/27 - drop
Sv2TemplateProvider::SendBuf
, reuse p2p socket handling if possible - limit number of connected clients
- maybe limit (number of)
coinbase_output_max_additional_size
- TMP / TODO comments at the top of
sv2_messages.h
- adjust base58 encoding of authority public key https://github.com/stratum-mining/stratum/issues/721
Testing
- expand sv2_template_provider_tests
- add transport fuzzer
- add template provider fuzzer
Template generation and updating
- hold on to templates a bit after a block is found https://github.com/stratum-mining/stratum/issues/709 (in case of race to prevent downstream crashes, though we still wouldn’t relay it without additional changes)
- hold on to template transactions even if the mempool drops them (for some time)
- group templates with the same
coinbase_tx_additional_output_size
- don’t generate templates when no client is connected
Misc
- move / refactor
GetMerklePathForCoinbase
helper (see Future Work in original PR, and https://github.com/stratum-mining/stratum/issues/567) - truncate long trace messages
Potential followups
- implement Noise protocol and mock client in Python, add functional tests (based on
test/sv2_template_provider_tests.cpp
) - use process separation, e.g. a
bitcoin-tp
binary, see multiprocess.md - make template updates push based, on top of Cluster Mempool, see docs/stratum-v2.md (for new blocks it’s already push based)
- push empty template for the next block (downstream can ignore or use, https://github.com/stratum-mining/stratum/issues/715)
- send prevhash for this template as soon as any new block arrives
- push optimistic template for the next block
- send prevhash if and only if our template won (i.e. we got a
SubmitSolution
message)
- send prevhash if and only if our template won (i.e. we got a