Skip to content

sv2-tp: exit when mining backend disconnects - #115

Merged
Sjors merged 3 commits into
stratum-mining:masterfrom
enochaz:07_26_clean_disconnect
Aug 19, 2026
Merged

Sjors merged 3 commits into
stratum-mining:masterfrom
enochaz:07_26_clean_disconnect

Conversation

@enochaz

@enochaz enochaz commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

This implements the simpler approach discussed in #101.

Previously, when the mining backend IPC connection was lost, sv2-tp remained running even though it could no longer provide new templates.

Instead of reconnecting and preserving existing client connections, sv2-tp now probes the mining interface, detects the disconnect, and exits cleanly. Shutdown avoids making further calls through the lost IPC connection.

Also added an integration test scenario that now stops the mingn backend and checks that sv2-tp reports the disconnect and exits successfully.

Closes #97.

@enochaz
enochaz force-pushed the 07_26_clean_disconnect branch from 598e6b8 to 590a100 Compare July 28, 2026 14:22
@Sjors

Sjors commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Concept ACK

@Sjors Sjors left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review 590a100

This is a lot simpler than #101.

I checked that the integration test fails without the fix in this PR.

Couple of suggestions for improvement.

Comment thread src/sv2/template_provider.h Resolved
Comment thread src/sv2/template_provider.cpp Resolved
Comment thread ci/test/04_run_stratum_v2_scenario.sh Resolved
Comment thread ci/test/04_run_stratum_v2_scenario.sh Resolved
enochaz added 3 commits July 29, 2026 14:53
Interrupt() is called during shutdown and again by destructor
cleanup.

Return after the first call so backend and network interrupts are not
repeated.
A closed mining backend IPC connection left sv2-tp running without a
source of new templates.

Probe the mining interface from the main loop and shut down when the
call reports a disconnect. Stop IBD handling on the same error and
avoid issuing remote interrupts after the connection is gone.
The SRI scenario previously left the mining backend running until
cleanup, so it could not catch regressions in sv2-tp's runtime
disconnect path.

Stop the Bitcoin Core backend after mining succeeds and require
sv2-tp to report the lost backend connection and exit cleanly within
30 seconds.
@enochaz
enochaz force-pushed the 07_26_clean_disconnect branch from 590a100 to 6abc365 Compare July 29, 2026 13:57
@enochaz

enochaz commented Jul 29, 2026

Copy link
Copy Markdown
Contributor Author

Couple of suggestions for improvement.

Addressed the suggestions made

You might notice that the commits were restructured a bit. While introducing BackendDisconnected i noticed the first commit added the local connection state variable, that the second commit immediately replaced with a member variable.

I did not like that code churn, so i restructured the commit, the first commit now only ensures repeated calls to Interrupt are safe, while the second introduces the member variable, the BackendDisconnected() method and the disconnect handling. I think this should make the changes easier to follow

@Sjors

Sjors commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

ACK 6abc365

@Sjors
Sjors merged commit 5c1c939 into stratum-mining:master Aug 19, 2026
20 checks passed
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.

sv2-tp does not exit or reconnect when bitcoin core disconnects

2 participants