Skip to content

Commit d70406e

Browse files
committed
Run Template Provider from bitcoin-mine
1 parent f49fd02 commit d70406e

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/bitcoin-mine.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
#include <chainparamsbase.h>
99
#include <clientversion.h>
1010
#include <common/args.h>
11+
#include <common/messages.h>
1112
#include <common/system.h>
1213
#include <compat/compat.h>
1314
#include <init/common.h>
1415
#include <interfaces/init.h>
1516
#include <interfaces/ipc.h>
1617
#include <logging.h>
18+
#include <node/sv2_template_provider.h>
1719
#include <tinyformat.h>
1820
#include <util/translation.h>
1921

@@ -22,6 +24,9 @@
2224
#include <signal.h>
2325
// #include <sys/stat.h>
2426
#endif
27+
28+
using common::InvalidPortErrMsg;
29+
2530
static const char* const HELP_USAGE{R"(
2631
bitcoin-mine is a test program for interacting with bitcoin-node via IPC.
2732
@@ -38,7 +43,7 @@ static const char* HELP_EXAMPLES{R"(
3843
bitcoin-mine -regtest
3944
4045
# Run with debug output.
41-
bitcoin-mine -regtest -debug
46+
bitcoin-mine -regtest -debug=sv2 -loglevel=sv2:trace
4247
)"};
4348

4449
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
@@ -110,6 +115,8 @@ MAIN_FUNCTION
110115
return EXIT_FAILURE;
111116
}
112117

118+
ECC_Context ecc_context{};
119+
113120
// Connect to existing bitcoin-node process or spawn new one.
114121
std::unique_ptr<interfaces::Init> mine_init{interfaces::MakeMineInit(argc, argv)};
115122
assert(mine_init);
@@ -128,6 +135,25 @@ MAIN_FUNCTION
128135
std::unique_ptr<interfaces::Mining> mining{node_init->makeMining()};
129136
assert(mining);
130137

138+
auto tp = std::make_unique<Sv2TemplateProvider>(*mining);
139+
140+
uint16_t sv2_port;
141+
const std::string sv2_port_arg = args.GetArg("-sv2port", "");
142+
143+
if (sv2_port_arg.empty()) {
144+
sv2_port = BaseParams().Sv2Port();
145+
} else {
146+
if (!ParseUInt16(sv2_port_arg, &sv2_port) || sv2_port == 0) {
147+
tfm::format(std::cerr, "%s\n", InvalidPortErrMsg("sv2port", sv2_port_arg).original);
148+
return EXIT_FAILURE;
149+
}
150+
}
151+
152+
if (!tp->Start(Sv2TemplateProviderOptions { .port = sv2_port })) {
153+
tfm::format(std::cerr, "Unable to start Stratum v2 Template Provider");
154+
return EXIT_FAILURE;
155+
}
156+
131157
#ifndef WIN32
132158
registerSignalHandler(SIGTERM, HandleSIGTERM);
133159
registerSignalHandler(SIGINT, HandleSIGTERM);
@@ -137,5 +163,9 @@ MAIN_FUNCTION
137163
UninterruptibleSleep(100ms);
138164
}
139165

166+
tp->Interrupt();
167+
tp->StopThreads();
168+
tp.reset();
169+
140170
return EXIT_SUCCESS;
141171
}

0 commit comments

Comments
 (0)