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

libbitcoin / libbitcoin-server / 45130211835

23 Nov 2026 07:19AM UTC coverage: 91.147% (-2.3%) from 93.468%
45130211835

push

github

web-flow
Merge pull request #1219 from evoskuil/master

Add embedded page and network smoke CI.

250 of 694 new or added lines in 15 files covered. (36.02%)

2 existing lines in 2 files now uncovered.

13652 of 14978 relevant lines covered (91.15%)

446.43 hits per line

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

96.14
/src/settings.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/settings.hpp>
20

21
#include <filesystem>
22
#include <bitcoin/server/define.hpp>
23
#include <bitcoin/server/utilities/utilities.hpp>
24

25
using namespace bc::system;
26
using namespace bc::network;
27

28
namespace libbitcoin {
29

30
// log
31
// ----------------------------------------------------------------------------
32

33
namespace log {
34

35
// Log states default to network compiled states or explicit false.
36
settings::settings() NOEXCEPT
1,868 ✔
37
  : application{ levels::application_defined },
1,868 ✔
38
    news{ levels::news_defined },
1,868 ✔
39
    session{ levels::session_defined },
1,868 ✔
40
    protocol{ false /*levels::protocol_defined*/ },
1,868 ✔
41
    proxy{ false /*levels::proxy_defined*/ },
1,868 ✔
42
    remote{ levels::remote_defined },
1,868 ✔
43
    fault{ levels::fault_defined },
1,868 ✔
44
    quitting{ false /*levels::quitting_defined*/ },
1,868 ✔
45
    objects{ false /*levels::objects_defined*/ },
1,868 ✔
46
    verbose{ false /*levels::verbose_defined*/ },
1,868 ✔
47
    console{ true },
1,868 ✔
48
    events{ true },
1,868 ✔
49
    thread_priority{ false },
1,868 ✔
50
    limit{ 1'000'000_u32 }
1,868 ✔
51
{
52
}
1,868 ✔
53

54
settings::settings(chain::selection) NOEXCEPT
1,867 ✔
55
  : settings()
1,867 ✔
56
{
57
}
1,867 ✔
58

59
processing_priority settings::thread_priority_() const NOEXCEPT
1 ✔
60
{
61
    // medium is "normal" (os default).
62
    return thread_priority ? processing_priority::medium :
1 ✔
63
        processing_priority::low;
1 ✔
64
}
65

66
std::filesystem::path settings::log_file1() const NOEXCEPT
2 ✔
67
{
68
    BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
69
    return console_path / "console_new.log";
2 ✔
70
    BC_POP_WARNING()
71
}
72

73
std::filesystem::path settings::log_file2() const NOEXCEPT
1 ✔
74
{
75
    BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
76
    return console_path / "console_old.log";
1 ✔
77
    BC_POP_WARNING()
78
}
79

80
std::filesystem::path settings::events_file() const NOEXCEPT
1 ✔
81
{
82
    BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)
83
    return events_path / "events.log";
1 ✔
84
    BC_POP_WARNING()
85
}
86

87
} // namespace log
88

89
// server
90
// ----------------------------------------------------------------------------
91

92
namespace server {
93

94
using namespace system::wallet;
95

96
// settings::settings
97
settings::settings(system::chain::selection context,
1,897 ✔
98
    const embedded_pages& native_pages,
99
    const embedded_pages& admin_pages) NOEXCEPT
1,897 ✔
100
  : network(context),
1,897 ✔
101
    wallet(context),
1,897 ✔
102
    admin("admin", admin_pages),
1,897 ✔
103
    native("native", native_pages)
3,794 ✔
104
{
105
    // Admin is enabled by default, for the local machine only.
106
    admin.connections = 10;
1,897 ✔
107
    admin.binds.emplace_back(system::ip::ipv4::loopback(), 0_u16);
1,897 ✔
108

109
    // Admin may accumulate a large amount of log backlog.
110
    admin.maximum_backlog = 1024 * network::megabyte;
1,897 ✔
111

112
    // Admin sessions are held open for monitoring, so they do not expire.
113
    admin.inactivity_minutes = 0;
1,897 ✔
114
    admin.expiration_minutes = 0;
1,897 ✔
115

116
    // The largest btcd notification is a filtered block.
117
    btcd.maximum_backlog = 20 * network::megabyte;
1,897 ✔
118

119
    // btcd reports json-rpc errors in the response body only.
120
    btcd.error_status = false;
1,897 ✔
121

122
    // Raw block publications drop beyond the bound, eight blocks deep.
123
    zmq.maximum_backlog = 32 * network::megabyte;
1,897 ✔
124

125
    // Subscribers send nothing after subscribing, so publishers do not expire.
126
    zmq.inactivity_minutes = 0;
1,897 ✔
127
    zmq.expiration_minutes = 0;
1,897 ✔
128

129
    // A submitted block is base16 encoded within a json envelope.
130
    constexpr auto encoded = 2 * network::max_payload + 4 * network::kilobyte;
131
    bitcoind.maximum_request = encoded;
1,897 ✔
132
    btcd.maximum_request = encoded;
1,897 ✔
133

134
    // A broadcast transaction package is base16 encoded within a json envelope.
135
    electrum.maximum_request = encoded;
1,897 ✔
136
    sparrow.maximum_request = encoded;
1,897 ✔
137
    esplora.maximum_request = encoded;
1,897 ✔
138
}
1,897 ✔
139

140
// The service contexts are read from configured files, once, at startup.
141
code settings::initialize() NOEXCEPT
1,831 ✔
142
{
143
    // Service ports are offset by chain.
144
    const auto port = [this](uint16_t base) NOEXCEPT
34,789 ✔
145
    {
146
        switch (network)
34,789 ✔
147
        {
148
            case system::chain::selection::testnet3:
×
149
                return possible_narrow_cast<uint16_t>(base + 10000_u32);
×
150
            case system::chain::selection::regtest:
95 ✔
151
                return possible_narrow_cast<uint16_t>(base + 20000_u32);
95 ✔
152
            case system::chain::selection::signet:
×
153
                return possible_narrow_cast<uint16_t>(base + 30000_u32);
×
154
            case system::chain::selection::testnet4:
57 ✔
155
                return possible_narrow_cast<uint16_t>(base + 40000_u32);
57 ✔
156
            case system::chain::selection::testnet5:
19 ✔
157
                return possible_narrow_cast<uint16_t>(base + 50000_u32);
19 ✔
158
            default:
159
                return base;
160
        }
161
    };
1,831 ✔
162

163
    admin.bind_port = port(8080);
1,831 ✔
164
    admin.safe_port = port(8043);
1,831 ✔
165
    native.bind_port = port(8180);
1,831 ✔
166
    native.safe_port = port(8143);
1,831 ✔
167
    bitcoind.bind_port = port(8280);
1,831 ✔
168
    bitcoind.safe_port = port(8243);
1,831 ✔
169
    zmq.bind_port = port(8380);
1,831 ✔
170
    zmq.safe_port = port(8343);
1,831 ✔
171
    btcd.bind_port = port(8480);
1,831 ✔
172
    btcd.safe_port = port(8443);
1,831 ✔
173
    electrum.bind_port = port(8580);
1,831 ✔
174
    electrum.safe_port = port(8543);
1,831 ✔
175
    sparrow.bind_port = port(8680);
1,831 ✔
176
    sparrow.safe_port = port(8643);
1,831 ✔
177
    esplora.bind_port = port(8780);
1,831 ✔
178
    esplora.safe_port = port(8743);
1,831 ✔
179
    stratum_v1.bind_port = port(8880);
1,831 ✔
180
    stratum_v1.safe_port = port(8843);
1,831 ✔
181
    stratum_v2.bind_port = port(8980);
1,831 ✔
182

183
    // Service bindings without a port take the service's default port.
184
    admin.default_ports();
1,831 ✔
185
    native.default_ports();
1,831 ✔
186
    bitcoind.default_ports();
1,831 ✔
187
    zmq.default_ports();
1,831 ✔
188
    btcd.default_ports();
1,831 ✔
189
    electrum.default_ports();
1,831 ✔
190
    sparrow.default_ports();
1,831 ✔
191
    esplora.default_ports();
1,831 ✔
192
    stratum_v1.default_ports();
1,831 ✔
193
    stratum_v2.default_ports();
1,831 ✔
194

195
    admin.default_buffers();
1,831 ✔
196
    native.default_buffers();
1,831 ✔
197
    bitcoind.default_buffers();
1,831 ✔
198
    zmq.default_buffers();
1,831 ✔
199
    btcd.default_buffers();
1,831 ✔
200
    electrum.default_buffers();
1,831 ✔
201
    sparrow.default_buffers();
1,831 ✔
202
    esplora.default_buffers();
1,831 ✔
203
    stratum_v1.default_buffers();
1,831 ✔
204
    stratum_v2.default_buffers();
1,831 ✔
205

206
    const auto initialize = [this](auto& service) NOEXCEPT
18,302 ✔
207
    {
208
        const auto ec = service.initialize_context();
18,302 ✔
209
        if (ec)
18,302 ✔
210
            failure = service.name;
1 ✔
211

212
        return ec;
18,302 ✔
213
    };
1,831 ✔
214

215
    if (const auto ec = initialize(admin)) return ec;
1,831 ✔
216
    if (const auto ec = initialize(native)) return ec;
1,831 ✔
217
    if (const auto ec = initialize(bitcoind)) return ec;
1,830 ✔
218
    if (const auto ec = initialize(btcd)) return ec;
1,830 ✔
219
    if (const auto ec = initialize(electrum)) return ec;
1,830 ✔
220
    if (const auto ec = initialize(sparrow)) return ec;
1,830 ✔
221
    if (const auto ec = initialize(esplora)) return ec;
1,830 ✔
222
    if (const auto ec = initialize(stratum_v1)) return ec;
1,830 ✔
223
    if (const auto ec = initialize(stratum_v2)) return ec;
1,830 ✔
224
    return initialize(zmq);
1,830 ✔
225
}
226

227
// settings::wallet_settings
228
settings::wallet_settings::wallet_settings() NOEXCEPT
1 ✔
229
  : wallet_settings(system::chain::selection::mainnet)
1 ✔
230
{
231
}
1 ✔
232

233
static const context& to_wallet_context(
3,758 ✔
234
    system::chain::selection context) NOEXCEPT
235
{
236
    switch (context)
3,758 ✔
237
    {
238
        case system::chain::selection::testnet3:
239
        case system::chain::selection::testnet4:
240
        case system::chain::selection::testnet5:
241
        case system::chain::selection::signet:
242
            return ctx::btc::test;
243
        case system::chain::selection::regtest:
13 ✔
244
            return ctx::btc::regtest;
13 ✔
245
        case system::chain::selection::mainnet:
3,723 ✔
246
        case system::chain::selection::none:
247
        default:
248
            return ctx::btc::main;
3,723 ✔
249
    }
250
}
251

252
settings::wallet_settings::wallet_settings(
3,758 ✔
253
    system::chain::selection context) NOEXCEPT
3,758 ✔
254
{
255
    const auto& value = to_wallet_context(context);
3,758 ✔
256
    p2kh_prefix = value.p2kh;
3,758 ✔
257
    p2sh_prefix = value.p2sh;
3,758 ✔
258
    wif_prefix = value.wif;
3,758 ✔
259
    witness_prefix = value.p2w;
3,758 ✔
260
    silent_prefix = value.sp;
3,758 ✔
261
    hd_private_prefix = value.hd.prv;
3,758 ✔
262
    hd_public_prefix = value.hd.pub;
3,758 ✔
263
}
3,758 ✔
264

265
context settings::wallet_settings::to_context() const NOEXCEPT
9,973 ✔
266
{
267
    return
268
    {
269
        { hd_private_prefix, hd_public_prefix },
9,973 ✔
270
        witness_prefix,
9,973 ✔
271
        p2kh_prefix,
9,973 ✔
272
        p2sh_prefix,
9,973 ✔
273
        wif_prefix,
9,973 ✔
274
        silent_prefix
9,973 ✔
275
    };
9,973 ✔
276
}
19,946 ✔
277

278
// settings::embedded_pages
279
span_value settings::embedded_pages::css()  const NOEXCEPT { return {}; }
3,641 ✔
280
span_value settings::embedded_pages::html() const NOEXCEPT { return {}; }
3,644 ✔
281
span_value settings::embedded_pages::ecma() const NOEXCEPT { return {}; }
3,641 ✔
282
span_value settings::embedded_pages::font() const NOEXCEPT { return {}; }
3,641 ✔
283
span_value settings::embedded_pages::icon() const NOEXCEPT { return {}; }
3,641 ✔
284
bool settings::embedded_pages::enabled() const NOEXCEPT
22 ✔
285
{
286
    return !html().empty();
22 ✔
287
}
288

289
// settings::html_server
290
settings::html_server::html_server(const std::string_view& logging_name,
3,795 ✔
291
    const embedded_pages& embedded) NOEXCEPT
3,795 ✔
292
  : network::settings::websocket_server(logging_name),
293
    pages(embedded)
3,795 ✔
294
{
295
}
3,795 ✔
296

297
// A weak tag, as each page may be sent in any content coding.
298
code settings::html_server::initialize_context() NOEXCEPT
3,662 ✔
299
{
300
    if (const auto ec = base::initialize_context())
3,662 ✔
301
        return ec;
1 ✔
302

303
    const auto tag = [](const span_value& page) NOEXCEPT -> std::string
18,305 ✔
304
    {
305
        if (page.empty())
18,305 ✔
306
            return {};
18,190 ✔
307

308
        const auto hash = accumulator<sha256>::hash(page.size(), page.data());
115 ✔
309
        return "W/\"" + encode_base16(hash) + "\"";
115 ✔
310
    };
311

312
    tags_ =
313
    {
314
        tag(pages.css()),
3,661 ✔
315
        tag(pages.html()),
3,661 ✔
316
        tag(pages.ecma()),
3,661 ✔
317
        tag(pages.font()),
3,661 ✔
318
        tag(pages.icon())
3,661 ✔
319
    };
3,661 ✔
320

321
    return network::error::success;
3,661 ✔
322
}
18,305 ✔
323

324
const settings::html_server::page_tags&
325
settings::html_server::tags() const NOEXCEPT
19 ✔
326
{
327
    return tags_;
19 ✔
328
}
329

330
// settings::bitcoind_server
331
code settings::bitcoind_server::initialize_context() NOEXCEPT
3,666 ✔
332
{
333
    using namespace interface::bitcoind;
334
    if (const auto ec = base::initialize_context())
3,666 ✔
335
        return ec;
×
336

337
    // Range bounded by implemented versions,
338
    // maximum floors to implemented version within range.
339
    if (protocol_minimum < minimum_version ||
7,331 ✔
340
        protocol_maximum > maximum_version ||
3,666 ✔
341
        to_value(version_floor(protocol_maximum)) < protocol_minimum)
3,664 ✔
342
        return network::error::invalid_configuration;
3 ✔
343

344
    if (enable_utxo)
3,663 ✔
345
    {
346
        inactivity_minutes = 0;
660 ✔
347
        expiration_minutes = 0;
660 ✔
348
    }
349

350
    return network::error::success;
3,663 ✔
351
}
352

353
// Tag and extranonce are each a single push within the coinbase script.
354
code settings::stratum_v1_server::initialize_context() NOEXCEPT
1,830 ✔
355
{
356
    using namespace system::chain;
357
    if (const auto ec = base::initialize_context())
1,830 ✔
NEW
358
        return ec;
×
359

360
    const size_t extranonce = add(uint8_t{ extranonce1_size },
1,830 ✔
361
        uint8_t{ extranonce2_size });
1,830 ✔
362
    const auto script = coinbase_script_size(coinbase_tag.size(), extranonce);
1,830 ✔
363
    if (is_zero(uint8_t{ extranonce1_size }) ||
1,830 ✔
364
        is_zero(uint8_t{ extranonce2_size }) ||
1,830 ✔
365
        coinbase_tag.size() > max_direct_push ||
1,830 ✔
366
        extranonce > max_direct_push || script > max_coinbase_size ||
3,660 ✔
367
        minimum_difficulty <= 0.0)
1,830 ✔
NEW
368
        return network::error::invalid_configuration;
×
369

370
    return network::error::success;
1,830 ✔
371
}
372

373
code settings::esplora_server::initialize_context() NOEXCEPT
1,835 ✔
374
{
375
    using namespace server::esplora;
376
    if (const auto ec = base::initialize_context())
1,835 ✔
377
        return ec;
×
378

379
    // The version floors to an implemented version.
380
    if (protocol_version < minimum_version ||
1,835 ✔
381
        protocol_version > maximum_version)
382
        return network::error::invalid_configuration;
2 ✔
383

384
    return network::error::success;
1,833 ✔
385
}
386

387
} // namespace server
388

389
// ----------------------------------------------------------------------------
390

391
} // 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