• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

libbitcoin / libbitcoin-server / 46108256844

28 Nov 2026 04:35AM UTC coverage: 93.413% (-0.4%) from 93.797%
46108256844

push

github

web-flow
Merge pull request #1244 from echennells/fix/sv2-max-target

Bound the stratum v2 target by the channel max_target.

18 of 18 new or added lines in 2 files covered. (100.0%)

114 existing lines in 5 files now uncovered.

15614 of 16715 relevant lines covered (93.41%)

446.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

99.16
/src/server_node.cpp
1
/**
2
 * Copyright (c) 2011-2026 libbitcoin developers
3
 *
4
 * This file is part of libbitcoin.
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Affero General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU Affero General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Affero General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
#include <bitcoin/server/server_node.hpp>
20

21
#include <bitcoin/server/define.hpp>
22
#include <bitcoin/server/sessions/sessions.hpp>
23

24
namespace libbitcoin {
25
namespace server {
26

27
using namespace system;
28
using namespace database;
29
using namespace network;
30
using namespace node;
31
using namespace std::placeholders;
32

33
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
34

35
// net::strand() is safe to call from constructor (non-virtual).
36
server_node::server_node(query& query, const configuration& configuration,
2,060 ✔
37
    const logger& log) NOEXCEPT
2,060 ✔
38
  : full_node(query, configuration, log),
39
    config_(configuration),
2,060 ✔
40
    extranonces_(emplace_shared<extranonces>()),
2,060 ✔
41
    miners_(emplace_shared<miners>())
2,060 ✔
42
{
43
}
2,060 ✔
44

45
server_node::~server_node() NOEXCEPT
4,120 ✔
46
{
47
}
2,060 ✔
48

49
// Properties.
50
// ----------------------------------------------------------------------------
51

52
extranonces::prefix server_node::allocate_prefix(size_t size) NOEXCEPT
134 ✔
53
{
54
    return extranonces_->allocate(size);
134 ✔
55
}
56

57
const miners::ptr& server_node::mining() const NOEXCEPT
288 ✔
58
{
59
    return miners_;
288 ✔
60
}
61

62
const configuration& server_node::server_config() const NOEXCEPT
1 ✔
63
{
64
    return config_;
1 ✔
65
}
66

67
const settings& server_node::server_settings() const NOEXCEPT
1 ✔
68
{
69
    return config_.server;
1 ✔
70
}
71

72
// Sequences.
73
// ----------------------------------------------------------------------------
74

75
void server_node::run(result_handler&& handler) NOEXCEPT
2,058 ✔
76
{
77
    // Base (net) invokes do_run().
78
    full_node::run(std::move(handler));
2,058 ✔
79
}
2,058 ✔
80

81
void server_node::do_run(const result_handler& handler) NOEXCEPT
2,058 ✔
82
{
83
    BC_ASSERT(stranded());
2,058 ✔
84

85
    // Start services after node is running.
86
    full_node::do_run(std::bind(&server_node::start_admin, this, _1, handler));
2,058 ✔
87
}
2,058 ✔
88

89
void server_node::start_admin(const code& ec,
2,058 ✔
90
    const result_handler& handler) NOEXCEPT
91
{
92
    BC_ASSERT(stranded());
2,058 ✔
93

94
    if (ec)
2,058 ✔
95
    {
96
        handler(ec);
1 ✔
97
        return;
1 ✔
98
    }
99

100
    attach_admin_session()->start(
6,171 ✔
101
        std::bind(&server_node::start_native, this, _1, handler));
4,114 ✔
102
}
103

104
void server_node::start_native(const code& ec,
2,057 ✔
105
    const result_handler& handler) NOEXCEPT
106
{
107
    BC_ASSERT(stranded());
2,057 ✔
108

109
    if (ec)
2,057 ✔
110
    {
111
        handler(ec);
1 ✔
112
        return;
1 ✔
113
    }
114

115
    attach_native_session()->start(
6,168 ✔
116
        std::bind(&server_node::start_bitcoind, this, _1, handler));
4,112 ✔
117
}
118

119
void server_node::start_bitcoind(const code& ec,
2,056 ✔
120
    const result_handler& handler) NOEXCEPT
121
{
122
    BC_ASSERT(stranded());
2,056 ✔
123

124
    if (ec)
2,056 ✔
125
    {
126
        handler(ec);
1 ✔
127
        return;
1 ✔
128
    }
129

130
    attach_bitcoind_session()->start(
6,165 ✔
131
        std::bind(&server_node::start_btcd, this, _1, handler));
4,110 ✔
132
}
133

134
void server_node::start_btcd(const code& ec,
2,055 ✔
135
    const result_handler& handler) NOEXCEPT
136
{
137
    BC_ASSERT(stranded());
2,055 ✔
138

139
    if (ec)
2,055 ✔
140
    {
141
        handler(ec);
1 ✔
142
        return;
1 ✔
143
    }
144

145
    attach_btcd_session()->start(
6,162 ✔
146
        std::bind(&server_node::start_electrum, this, _1, handler));
4,108 ✔
147
}
148

149
void server_node::start_electrum(const code& ec,
2,054 ✔
150
    const result_handler& handler) NOEXCEPT
151
{
152
    BC_ASSERT(stranded());
2,054 ✔
153

154
    if (ec)
2,054 ✔
155
    {
156
        handler(ec);
1 ✔
157
        return;
1 ✔
158
    }
159

160
    attach_electrum_session()->start(
6,159 ✔
161
        std::bind(&server_node::start_sparrow, this, _1, handler));
4,106 ✔
162
}
163

164
void server_node::start_sparrow(const code& ec,
2,053 ✔
165
    const result_handler& handler) NOEXCEPT
166
{
167
    BC_ASSERT(stranded());
2,053 ✔
168

169
    if (ec)
2,053 ✔
170
    {
171
        handler(ec);
1 ✔
172
        return;
1 ✔
173
    }
174

175
    attach_sparrow_session()->start(
6,156 ✔
176
        std::bind(&server_node::start_esplora, this, _1, handler));
4,104 ✔
177
}
178

179
void server_node::start_esplora(const code& ec,
2,052 ✔
180
    const result_handler& handler) NOEXCEPT
181
{
182
    BC_ASSERT(stranded());
2,052 ✔
183

184
    if (ec)
2,052 ✔
185
    {
186
        handler(ec);
1 ✔
187
        return;
1 ✔
188
    }
189

190
    attach_esplora_session()->start(
6,153 ✔
191
        std::bind(&server_node::start_stratum_v1, this, _1, handler));
4,102 ✔
192
}
193

194
void server_node::start_stratum_v1(const code& ec,
2,051 ✔
195
    const result_handler& handler) NOEXCEPT
196
{
197
    BC_ASSERT(stranded());
2,051 ✔
198

199
    if (ec)
2,051 ✔
200
    {
201
        handler(ec);
1 ✔
202
        return;
1 ✔
203
    }
204

205
    const auto& stratum = config_.server.stratum_v1;
2,050 ✔
206
    const auto& wallet = config_.server.wallet;
207
    system::chain::script payout{};
2,050 ✔
208
    if (stratum.enabled() && !stratum.payout_address.empty() &&
2,050 ✔
209
        output_script(payout, stratum.payout_address, wallet.p2kh_prefix,
2,053 ✔
210
            wallet.p2sh_prefix, wallet.witness_prefix))
3 ✔
211
    {
UNCOV
212
        handler(network::error::invalid_configuration);
×
213
        return;
214
    }
215

216
    attach_stratum_v1_session()->start(
4,100 ✔
217
        std::bind(&server_node::start_stratum_v2, this, _1, handler));
4,100 ✔
218
}
2,050 ✔
219

220
void server_node::start_stratum_v2(const code& ec,
2,050 ✔
221
    const result_handler& handler) NOEXCEPT
222
{
223
    BC_ASSERT(stranded());
2,050 ✔
224

225
    if (ec)
2,050 ✔
226
    {
227
        handler(ec);
1 ✔
228
        return;
1 ✔
229
    }
230

231
    attach_stratum_v2_session()->start(
6,147 ✔
232
        std::bind(&server_node::start_zmq, this, _1, handler));
4,098 ✔
233
}
234

235
void server_node::start_zmq(const code& ec,
2,049 ✔
236
    const result_handler& handler) NOEXCEPT
237
{
238
    BC_ASSERT(stranded());
2,049 ✔
239

240
    if (ec)
2,049 ✔
241
    {
242
        handler(ec);
1 ✔
243
        return;
1 ✔
244
    }
245

246
    attach_zmq_session()->start(move_copy(handler));
2,048 ✔
247
}
248

249
// Session attachments.
250
// ----------------------------------------------------------------------------
251

252
session_admin::ptr server_node::attach_admin_session() NOEXCEPT
2,057 ✔
253
{
254
    return net::attach<session_admin>(*this, config_,
255
        config_.server.admin);
2,057 ✔
256
}
257

258
session_native::ptr server_node::attach_native_session() NOEXCEPT
2,056 ✔
259
{
260
    return net::attach<session_native>(*this, config_,
261
        config_.server.native);
2,056 ✔
262
}
263

264
session_bitcoind::ptr server_node::attach_bitcoind_session() NOEXCEPT
2,055 ✔
265
{
266
    return net::attach<session_bitcoind>(*this, config_,
267
        config_.server.bitcoind);
2,055 ✔
268
}
269

270
session_btcd::ptr server_node::attach_btcd_session() NOEXCEPT
2,054 ✔
271
{
272
    return net::attach<session_btcd>(*this, config_,
273
        config_.server.btcd);
2,054 ✔
274
}
275

276
session_electrum::ptr server_node::attach_electrum_session() NOEXCEPT
2,053 ✔
277
{
278
    return net::attach<session_electrum>(*this, config_,
279
        config_.server.electrum);
2,053 ✔
280
}
281

282
session_sparrow::ptr server_node::attach_sparrow_session() NOEXCEPT
2,052 ✔
283
{
284
    return net::attach<session_sparrow>(*this, config_,
285
        config_.server.sparrow);
2,052 ✔
286
}
287

288
session_esplora::ptr server_node::attach_esplora_session() NOEXCEPT
2,051 ✔
289
{
290
    return net::attach<session_esplora>(*this, config_,
291
        config_.server.esplora);
2,051 ✔
292
}
293

294
session_stratum_v1::ptr server_node::attach_stratum_v1_session() NOEXCEPT
2,050 ✔
295
{
296
    return net::attach<session_stratum_v1>(*this, config_,
297
        config_.server.stratum_v1);
2,050 ✔
298
}
299

300
session_stratum_v2::ptr server_node::attach_stratum_v2_session() NOEXCEPT
2,049 ✔
301
{
302
    return net::attach<session_stratum_v2>(*this, config_,
303
        config_.server.stratum_v2);
2,049 ✔
304
}
305

306
session_zmq::ptr
307
server_node::attach_zmq_session() NOEXCEPT
2,048 ✔
308
{
309
    return net::attach<session_zmq>(*this, config_,
310
        config_.server.zmq);
2,048 ✔
311
}
312

313
BC_POP_WARNING()
314

315
} // namespace server
316
} // namespace libbitcoin
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc