Skip to content

Stratum v2 Template Provider via IPC interface (multiprocess)#48

Closed
Sjors wants to merge 25 commits into2024/07/sv2-tp-commonfrom
sv2-ipc
Closed

Stratum v2 Template Provider via IPC interface (multiprocess)#48
Sjors wants to merge 25 commits into2024/07/sv2-tp-commonfrom
sv2-ipc

Conversation

@Sjors
Copy link
Owner

@Sjors Sjors commented Jul 17, 2024

This is an alternative approach to #68. Rather than integrating the Template Provider directly into Bitcoin Core, we make it an entirely separate application that communicates via IPC, see design/multiprocess.md.

Usage

Compile as usual, multiprocess is enabled by default.

Alternatively get a recent binary, see (unofficial, by me) releases ending in "ICP".

Start node:

build/src/bitcoin-node -chain=testnet4 -ipcbind=unix

Start the Template Provider:

build/bin/bitcoin-mine -chain=testnet4 -debug=sv2 -loglevel=sv2:trace

See general Stratum v2 usage instructions in bitcoin#29432.

Rationale, PRs this builds on

Upstream PRs used:

There are multiple ways to create such an application. It could be built from scratch in Rust, using bits and pieces of the Stratum Reference Implementation SRI. It could be a c++ application built from scratch, perhaps using some libraries from Bitcoin Core.

But this PR goes about in a slightly different way. Similar to Elements or Knots it's a set of patches on top of the full Bitcoin Core codebase. This allows me to leverage the build system, subclass Transport and use various other useful bits.

This lets me reuse almost all code from the integrated Template Provider bitcoin#29432. Both build direct on:

I modified the guix script to only produce bitcoin-node (for now) and bitcoin-mine binaries.

Goal

The goal is to drop bitcoin-node from the release here. Ideally users would install Bitcoin Core in the manner they're familiar with. They would then install bitcoin-mine separately and it should just work(tm), at most having to add a line to bitcoin.conf to turn IPC on.

This won't work until we ship a release with multiprocess and the mining interface. See bitcoin#30437 for progress towards that.

Rebase hint

Rebase hint:

git reset --hard 2024/07/sv2-tp-common
git fetch ryanofsky
git merge ryanofsky/pr/mine

git cherry-pick sjors/sv2-ipc~12^..sjors/sv2-ipc

@Sjors
Copy link
Owner Author

Sjors commented Jul 17, 2024

@ryanofsky I slightly mangled e3736422b87e9f5b67d058fc278fe0838e073e07 because of bitcoin@4e1a434#r1681193702. I'll clean that up later.

@Sjors
Copy link
Owner Author

Sjors commented Jul 17, 2024

Incorporated the changes from bitcoin#30437 (comment) and cleaned up commit history.

@Sjors
Copy link
Owner Author

Sjors commented Jul 18, 2024

@ryanofsky do you have a commit somewhere that adds libmultiprocess to the guix build?

@Sjors Sjors force-pushed the sv2-ipc branch 2 times, most recently from c75792b to 91720b7 Compare July 18, 2024 09:26
@Sjors
Copy link
Owner Author

Sjors commented Jul 18, 2024

Getting a cryptic error: '__NVCC___WORKAROUND_GUARD' is not defined error for the multiprocess job: https://cirrus-ci.com/task/4940413969104896?logs=ci#L2225

Somehow related to the Template Provider depending on boost/multi_index via its use of the mempool.

I can't make sense of the personality(old_personality | ADDR_NO_RANDOMIZE) error thrown by MSAN and TSAN, but it's possible that's related to my self-hosted CI setup and/or the modification in 33196682f15caf6fb54d05ed4c53a0d711a91241.

@Sjors Sjors force-pushed the 2024/07/sv2-tp-common branch 2 times, most recently from db58076 to 1ff4660 Compare July 18, 2024 12:24
@Sjors Sjors force-pushed the sv2-ipc branch 3 times, most recently from 4354e96 to 3aa6f0a Compare July 18, 2024 13:11
@Sjors Sjors force-pushed the 2024/07/sv2-tp-common branch from 1ff4660 to ee010f5 Compare July 18, 2024 13:16
@ryanofsky
Copy link

re: #48 (comment)

@ryanofsky do you have a commit somewhere that adds libmultiprocess to the guix build?

I don't, since I haven't really experimented with the guix build. Maybe simplest approach to start with would enable the multiprocess build option and build and package all the multiprocess executables including bitcoin-tp and bitcoin-node. I know in the longer run you want to have separate releases as described in bitcoin#30437 (comment).

re: #48 (comment)

Getting a cryptic error: '__NVCC___WORKAROUND_GUARD' is not defined error for the multiprocess job: https://cirrus-ci.com/task/4940413969104896?logs=ci#L2225

Somehow related to the Template Provider depending on boost/multi_index via its use of the mempool.

This is a -Wundef error caused by bitcoin#29876 that happens when a boost header is included from a source file that is compiled with -I /path/to/boost/headers rather than -isystem /path/to/boost/headers. The fix for this is probably:

-bitcoin_mine_CPPFLAGS = $(bitcoin_bin_cppflags)
+bitcoin_mine_CPPFLAGS = $(bitcoin_bin_cppflags) $(BOOST_CPPFLAGS)

to add the right -isystem option.

I can't make sense of the personality(old_personality | ADDR_NO_RANDOMIZE) error thrown by MSAN and TSAN, but it's possible that's related to my self-hosted CI setup and/or the modification in 3319668.

Not sure about this error. Link seems to be https://cirrus-ci.com/task/4759864851824640?logs=ci#L2486

@Sjors Sjors force-pushed the 2024/07/sv2-tp-common branch 2 times, most recently from 19cc9f1 to dabc32c Compare July 19, 2024 08:59
@Sjors Sjors force-pushed the sv2-ipc branch 3 times, most recently from 6c24b45 to a8bb152 Compare July 19, 2024 13:55
@Sjors
Copy link
Owner Author

Sjors commented Jul 19, 2024

I'm getting the MSAN / TSAN error inconsistently on my self-hosted CI. Does not seem related to this PR. Trying to reproduce in isolation in #51.

ryanofsky and others added 9 commits August 18, 2025 06:54
Add a MakeBasicInit() function so simpler standalone IPC clients like
bitcoin-mine in bitcoin#30437 and bitcoin-cli in bitcoin#32297 that only initiate IPC
connections without exposing any IPC interfaces themselves can to avoid needing
to implement their own specialized interfaces::Init subclasses.
Expose ENABLE_IPC build option to function tests so new tests for bitcoin-mine
in bitcoin#30437 and bitcoin-cli in bitcoin#32297 can test IPC-only features.
Set new `BitcoinTestFramework.binary_paths.bitcoin_bin` property with path to
the `bitcoin` wrapper binary. This allows new tests for `bitcoin-mine` in
bitcoin#30437 and `bitcoin-cli` in bitcoin#32297 to find the `bitcoin` binary and call
`bitcoin -m` to start nodes with IPC support. This way the new tests can run
whenever the ENABLE_IPC build option is enabled, instead of only running when
the `BITCOIN_CMD` environment variable is set to `bitcoin -m`
With this change, tests can specify `self.extra_init = [{ipcbind: True}]` to
start a node listening on an IPC socket, instead of needing to choose which
node binary to invoke and what `self.extra_args=[["-ipcbind=..."]]` value to
pass to it.

The eliminates boilerplate code bitcoin#30437 (interface_ipc_mining.py), bitcoin#32297
(interface_ipc_cli.py), and bitcoin#33201 (interface_ipc.py) previously needed in
their test setup.
Allows InitError and InitWarning to be used by other executables beside
bitcoind and bitcoin-node.
See src/bitcoin-mine.cpp for usage information.

Co-authored-by: Sjors Provoost <sjors@sprovoost.nl>
Co-authored-by: Sjors Provoost <sjors@sprovoost.nl>
Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
Suggested by Sjors Provoost <sjors@sprovoost.nl> in
bitcoin#30437 (comment)
Sjors added 16 commits August 25, 2025 16:59
For now also build bitcoin-node.
The Template Provider binary:
* won't have a wallet
* probably won't have a gui
* doesn't use the functional test framework

Disable some CI stuff to speed it up.

This is not a complete list, because:
1. That would be too hard to rebase
2. Some things might be added later, e.g. tracepoints
1b8d4a6f1e Merge bitcoin-core/libmultiprocess#194: mpgen: Work around c++20 / capnproto 0.8 incompatibility
f1fad396bf Merge bitcoin-core/libmultiprocess#195: ci: Add openbsd
eed42f210d ci: Bump all tasks to actions/checkout@v5
486a510bbe ci: Remove ancient and problematic -lstdc++fs in mpexample
dd40897efe Add missing thread include
98414e7d28 ci: Add openbsd
dc3ba22046 cmake, doc: Add check for CVE-2022-46149
cb170d4913 Merge bitcoin-core/libmultiprocess#193: build: require CapnProto 0.7.0 or better
8ceeaa6ae4 ci: Add olddeps job to test old dependencies versions
c4cb758ecc mpgen: Work around c++20 / capnproto 0.8 incompatibility
30930dff7b build: require CapnProto 0.7.0 or better

git-subtree-dir: src/ipc/libmultiprocess
git-subtree-split: 1b8d4a6f1e54b92708bd2ad627ec6d440a1daf3d
@Sjors
Copy link
Owner Author

Sjors commented Aug 25, 2025

bitcoin#31802 landed!

Last rebase before I'm going to split off the sv2 functionality into a fresh codebase.

@Sjors
Copy link
Owner Author

Sjors commented Aug 27, 2025

This code is now part of https://github.com/Sjors/sv2-tp; feedback and pull requests are welcome there!

I'll be tagging a release shortly. Usage will be the same as in this PR, except:

  1. the bitcoin-mine command was renamed to sv2-tp
  2. you need to bring your own Bitcoin Core node (I'll make a preview release of v30)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants