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

libbitcoin / libbitcoin-server / 44691724904

20 Nov 2026 06:59AM UTC coverage: 95.15% (+0.05%) from 95.102%
44691724904

push

github

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

Fix test, disable admin channel inactivity and expiration by default.

2 of 2 new or added lines in 1 file covered. (100.0%)

122 existing lines in 14 files now uncovered.

12792 of 13444 relevant lines covered (95.15%)

445.71 hits per line

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

96.86
/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

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

27
namespace libbitcoin {
28

29
// log
30
// ----------------------------------------------------------------------------
31

32
namespace log {
33

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

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

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

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

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

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

86
} // namespace log
87

88
// server
89
// ----------------------------------------------------------------------------
90

91
namespace server {
92

93
using namespace system::wallet;
94

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

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

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

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

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

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

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

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

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

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

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

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

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

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

211
        return ec;
17,232 ✔
212
    };
1,724 ✔
213

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

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

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

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

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

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

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

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

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

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

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

320
    return network::error::success;
3,447 ✔
321
}
17,235 ✔
322

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

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

336
    // The range is bounded by the implemented versions, and the maximum
337
    // floors to an implemented version within the range.
338
    if (protocol_minimum < minimum_version ||
6,899 ✔
339
        protocol_maximum > maximum_version ||
3,450 ✔
340
        to_value(version_floor(protocol_maximum)) < protocol_minimum)
3,448 ✔
341
        return network::error::invalid_configuration;
3 ✔
342

343
    return network::error::success;
3,447 ✔
344
}
345

346
code settings::esplora_server::initialize_context() NOEXCEPT
1,728 ✔
347
{
348
    using namespace server::esplora;
349
    if (const auto ec = base::initialize_context())
1,728 ✔
UNCOV
350
        return ec;
×
351

352
    // The version floors to an implemented version.
353
    if (protocol_version < minimum_version ||
1,728 ✔
354
        protocol_version > maximum_version)
355
        return network::error::invalid_configuration;
2 ✔
356

357
    return network::error::success;
1,726 ✔
358
}
359

360
} // namespace server
361

362
// ----------------------------------------------------------------------------
363

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