Skip to content

Windows - #93

Draft
Sjors wants to merge 20 commits into
stratum-mining:masterfrom
Sjors:2026/04/windows
Draft

Sjors wants to merge 20 commits into
stratum-mining:masterfrom
Sjors:2026/04/windows

Conversation

@Sjors

@Sjors Sjors commented Apr 20, 2026 •

Copy link
Copy Markdown
Collaborator

@Sjors
Sjors force-pushed the 2026/04/windows branch 8 times, most recently from 7de24f7 to 2f549eb Compare April 20, 2026 20:44
@Sjors

Sjors commented Apr 20, 2026

Copy link
Copy Markdown
Collaborator Author

My agent decided to disable some tests. @ryanofsky does its explanation in 2f549eb make any sense?

The test still crash at the end: https://github.com/stratum-mining/sv2-tp/actions/runs/24689445756/job/72208417934?pr=93

Maybe c6cca2c fixes that.

@ryanofsky

Copy link
Copy Markdown
Contributor

The comment from 2f549eb "only TPTester teardown intermittently deadlocks in std::thread::join during libmultiprocess thread-local cleanup. This is a known libmultiprocess Windows issue, not specific to sv2-tp" doesn't seem right. The could be a problem like this but it isn't a known issue.

It seems like that commit is not actually disabling test but just disabling test cleanup, so maybe it is a reasonable workaround, but it would be good to find the underlying cause of the issue. If it is possible to get a stack trace when the deadlock happens, that is usually enough to diagnose.

c6cca2c just seems to be completing the initial workaround from 2f549eb, avoiding errors if the process exits with threads still running.

@Sjors
Sjors force-pushed the 2026/04/windows branch 3 times, most recently from d34fc0d to a20bfd8 Compare April 23, 2026 15:26
@Sjors
Sjors force-pushed the 2026/04/windows branch 5 times, most recently from b0efdd6 to c52dc06 Compare August 21, 2026 06:39
Sjors added a commit to Sjors/sv2-tp that referenced this pull request Aug 21, 2026
sv2-tp has no GUI and therefore no NSIS installer. Keep the Windows
release flow limited to installed binaries and a detached codesigning
archive.

Originally from stratum-mining#93.
Sjors added a commit to Sjors/sv2-tp that referenced this pull request Aug 21, 2026
Windows releases are distributed as zip archives and do not need an
NSIS installer. Remove the unused deploy target and its dependencies.

This also prepares the Windows CI configuration to build the install
target used by stratum-mining#93.
Sjors added a commit to Sjors/sv2-tp that referenced this pull request Aug 21, 2026
sv2-tp has no GUI and therefore no NSIS installer. Keep the Windows
release flow limited to installed binaries and a detached codesigning
archive.

Originally from stratum-mining#93.
Sjors added a commit to Sjors/sv2-tp that referenced this pull request Aug 21, 2026
Windows releases are distributed as zip archives and do not need an
NSIS installer. Remove the unused deploy target and its dependencies.

This also prepares the Windows CI configuration to build the install
target used by stratum-mining#93.
@Sjors

Sjors commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator Author

I was able to get this to work on Windows, connecting to Bitcoin Core via IPC and then running SRI pool and CPU miner.

@Sjors

Sjors commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator Author

Still having some test issues, see slop in last commit message.

Sjors added a commit to Sjors/sv2-tp that referenced this pull request Sep 28, 2026
sv2-tp has no GUI and therefore no NSIS installer. Keep the Windows
release flow limited to installed binaries and a detached codesigning
archive.

Originally from stratum-mining#93.
Sjors added a commit to Sjors/sv2-tp that referenced this pull request Sep 28, 2026
Windows releases are distributed as zip archives and do not need an
NSIS installer. Remove the unused deploy target and its dependencies.

This also prepares the Windows CI configuration to build the install
target used by stratum-mining#93.
Sjors added a commit to Sjors/sv2-tp that referenced this pull request Sep 28, 2026
sv2-tp has no GUI and therefore no NSIS installer. Keep the Windows
release flow limited to installed binaries and a detached codesigning
archive.

Backport of stratum-mining#93.
Sjors added a commit to Sjors/sv2-tp that referenced this pull request Sep 28, 2026
Windows releases are distributed as zip archives and do not need an
NSIS installer. Remove the unused deploy target and its dependencies.

This also prepares the Windows CI configuration to build the install
target used by stratum-mining#93.
@Sjors

Sjors commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased after #126. Added Windows integration test (native and cross-compiled). The native test found bitcoin-core/libmultiprocess#368, so now there's two subtree updates in the branch.

@Sjors
Sjors force-pushed the 2026/04/windows branch 3 times, most recently from a5c391d to 4fdceb4 Compare September 28, 2026 18:18
@Sjors
Sjors marked this pull request as draft October 7, 2026 15:36
Sjors added 5 commits October 7, 2026 17:49
Avoid capturing a reference to the Sv2Client object in the lambda
run by the per-client handler thread. The client iteration happens
under ForEachClient and the reference would dangle if the client
list mutates while the thread is running. Pass the id by value, as
ThreadSv2ClientHandler takes a size_t anyway.
Let tests set the shutdown flag before unblocking mock waitNext()
calls, so the handler exits instead of issuing another IPC request.
Wake blocked waitNext() calls when the mining interface is interrupted.
Replace the Unix-only socketpair() setup in TPTester with
mp::SocketPair(), and store the socket ids in a small
std::array<mp::SocketId, 2> initialised with mp::SocketError so the
code is valid when SocketId is an unsigned type (as on Windows).
Drops <sys/socket.h>/<unistd.h> from the test harness.
Stop the handler before releasing its IPC proxies, and hold the server
connection explicitly so teardown can destroy it on the event loop.
This avoids depending on socket disconnects to release the loop.

Keep all server connection access on the event-loop thread, including
the reset after a disconnect may already have destroyed it.
@Sjors Sjors mentioned this pull request Oct 7, 2026
Sjors and others added 15 commits October 7, 2026 18:17
Call SetupNetworking() from sv2-tp's own entry point. On Windows this
initializes Winsock for both IPC and SV2 sockets; on Unix it is a no-op.
c55cf6d892 ci: Enable -Wundef in default and llvm jobs
a46b8caa9c ci: Enable -Wunused-const-variable in GCC jobs
7cd2feb3c0 proxy-types: Avoid -Wundef error when KJ_NO_EXCEPTIONS is not defined
de403968c7 ci: add Windows cross-compilation config using MinGW and Wine
b1e297dd9e test: Add TCP SocketListener and Windows compat to socketlistener.h
360e8290c1 util: make pthreads optional on Windows to enable MSVC builds
77a7999534 util: Fix Windows SpawnProcess hang when child exits before connecting to named pipe
263adf8adc util: Make SocketError inline constexpr
1efc775e9a util: Add Windows support
977f39a5e4 util: Add Windows CommandLineFromArgv escaping function
18cccf243e util, test: guard Unix-only code for Windows build
79271e5a7b util, test: Replace UnixListener with SocketListener
dfcdf0fe2f util, test: Add CloseSocket, use SocketId
50b17337a2 util: Improve SpawnProcess API and documentation
REVERT: fcc569c2cf proxy-types: Avoid -Wundef error when KJ_NO_EXCEPTIONS is not defined
REVERT: fdeefd7aab util: Make SocketError inline constexpr

git-subtree-dir: src/ipc/libmultiprocess
git-subtree-split: c55cf6d8926944ac3c44c9d18c5bb27cd7b1885f
648bbd2bd0 proxy: clean up heap-owned thread contexts on MinGW
696ad34edf proxy: join workers off the event loop
fc29939952 proxy: defer thread-local client cleanup
69b0950941 proxy: allow async cleanup from other threads
fb89c830a1 proxy: move thread clients into heap-owned state
6412e3c52a proxy: centralize explicit thread-client release
745dce3a8f proxy: allow move-only async cleanup callbacks
e401a08319 test: share setup for no-op async calls

git-subtree-dir: src/ipc/libmultiprocess
git-subtree-split: 648bbd2bd0a077448b88abb34edcf354b165d74d
Backport of bitcoin/bitcoin#32387.

Various small fixes for making ENABLE_IPC build work on windows.

Keep sv2-tp's existing LogPrintf calls when adapting the process
changes. This does not enable Windows builds or change the default
platforms.
sv2-tp requires IPC on every platform. Stop defaulting NO_IPC to 1
for mingw hosts so cross builds include Cap'n Proto and libmultiprocess.
Restore x86_64-w64-mingw32 to the default guix-build host
set so release builders include the Windows artifacts again.
Add back the Linux->Windows cross-build job and a follow-up Windows
runner job that validates the sv2-tp manifest and runs the cross-built
test binaries. Build the install target instead of the unfinished
Windows deploy target, point the cross job at the existing sv2-tp
resource file, and gate the deploy helper on the bitcoin executable
so the cross-build stays focused on producing the executables needed
by the follow-up Windows test job.
Backport of bitcoin/bitcoin#32387.

sv2-tp requires IPC on every platform, so make Cap'n Proto an
unconditional dependency rather than copying Core's optional IPC
feature. Adapted from Ryan Ofsky's vcpkg change, originally
7d129f346b37c9b98f8b23a450e57bff113c7436.

Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
Backport of bitcoin/bitcoin#32387.

Keep sv2-tp's existing LogPrintf calls when adapting the socket
error reporting.
Backport of bitcoin/bitcoin#32387.

On Windows, connect() to a Unix domain socket path that doesn't exist
may return a WSA error code (e.g. WSAECONNREFUSED) that doesn't map to
std::errc::no_such_file_or_directory via std::system_category(), unlike
POSIX where ENOENT is returned. After a failed connect, explicitly check
if the socket path exists and throw the expected error if not.

Also add an fs::exists(path, ec) overload to fs.h: the file's existing
exists() wrappers shadow std::filesystem::exists(path, error_code&),
causing the new call in process.cpp to fail to compile under MinGW.
Backport of bitcoin/bitcoin#32387.

When the IPC socket file exists but no node is listening, ProcessImpl::connect
throws std::system_error(WSAECONNREFUSED, std::system_category()). MinGW
libstdc++'s system_category() does not map Winsock error values to std::errc
conditions, so the std::errc::connection_refused check in connectAddress fails
to catch it, and bitcoin-cli -ipcconnect=auto throws CConnectionFailed instead
of falling back to HTTP.

This is a workaround: the proper fix is for ProcessImpl::connect to throw
std::errc::connection_refused (using generic_category) rather than relying on
system_category() to map Winsock codes. As a workaround, check for
WSAECONNREFUSED explicitly in system_category on WIN32.

MSVC's STL does map WSAECONNREFUSED to errc::connection_refused, so this
check is redundant but harmless there.
Use the completed unsigned Windows build of 2cc1787 to replace
the inherited Bitcoin Core estimate. Measured sizes in KiB were:

  Source archive:      3056
  Windows output:     63620
  Build directory:   969624
  Total:            1036300

Allow 1.5 GiB for Windows to provide headroom above the measured total.
As with the other targets, this excludes shared dependency caches and
the Guix store and does not capture peak build usage. Remove the
comment deferring the Windows estimate until measurements exist.
Run the shared mining and backend-disconnect scenarios on separate
Windows jobs for MSVC and MinGW. Build SV2 TP natively for MSVC and reuse
the existing executable artifact for MinGW. Build Bitcoin Core and SRI
natively in both jobs. Keep native and Linux jobs independent of the
cross-build dependency.

Use Ninja Multi-Config and sccache for both native C++ builds, with
embedded debug information. Restore and save the local compiler cache
using the existing CI archive pattern, with saves limited to non-PR runs.

Run the MSVC unit suite once in the mining job; the existing Windows
unit job covers MinGW. Also run native Windows integration daily.

Only test the source-build case on Windows, since no Core release has
Windows IPC support yet. Temporarily use bitcoin/bitcoin#32387 and
sv2-apps#902, with TODOs to restore their upstream branches after merge.
Sjors added a commit to Sjors/sv2-tp that referenced this pull request Nov 11, 2026
Windows is currently unsupported by sv2-tp. Keep the upstream Windows
build changes as preparation for stratum-mining#93, and describe
the inherited build instructions as reference material.
Sjors added a commit to Sjors/sv2-tp that referenced this pull request Nov 11, 2026
Windows is currently unsupported by sv2-tp. Keep the upstream Windows
build changes as preparation for stratum-mining#93, and describe
the inherited build instructions as reference material.
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.

Windows support

2 participants