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

libbitcoin / libbitcoin-node / 44690193668

20 Nov 2026 06:46AM UTC coverage: 90.659% (-0.2%) from 90.883%
44690193668

push

github

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

Refactor sources, remove dead code, regen, style.

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

206 existing lines in 12 files now uncovered.

4523 of 4989 relevant lines covered (90.66%)

4834.63 hits per line

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

89.09
/src/protocols/protocol.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/node/protocols/protocol.hpp>
20

21
#include <bitcoin/node/configuration.hpp>
22
#include <bitcoin/node/define.hpp>
23

24
namespace libbitcoin {
25
namespace node {
26

27
#define CLASS protocol
28

29
using namespace std::placeholders;
30

31
// Properties.
32
// ----------------------------------------------------------------------------
33

34
query& protocol::archive() const NOEXCEPT
50,396 ✔
35
{
36
    return session_->archive();
50,396 ✔
37
}
38

39
const node::configuration& protocol::node_config() const NOEXCEPT
1 ✔
40
{
41
    return session_->node_config();
1 ✔
42
}
43

44
const system::settings& protocol::system_settings() const NOEXCEPT
39 ✔
45
{
46
    return session_->system_settings();
39 ✔
47
}
48

49
const database::settings& protocol::database_settings() const NOEXCEPT
4 ✔
50
{
51
    return session_->database_settings();
4 ✔
52
}
53

54
////const network::settings& protocol::network_settings() const NOEXCEPT
55
////{
56
////    return session_->network_settings();
57
////}
58

59
const node::settings& protocol::node_settings() const NOEXCEPT
66 ✔
60
{
61
    return session_->node_settings();
66 ✔
62
}
63

64
bool protocol::is_current_chain(bool confirmed) const NOEXCEPT
190 ✔
65
{
66
    return session_->is_current_chain(confirmed);
190 ✔
67
}
68

69
bool protocol::is_current_time(uint32_t timestamp) const NOEXCEPT
15 ✔
70
{
71
    return session_->is_current_time(timestamp);
15 ✔
72
}
73

74
uint64_t protocol::minimum_fee_rate() const NOEXCEPT
58 ✔
75
{
76
    return is_current_chain(true) ? node_settings().pool.minimum_fee_rate_() :
58 ✔
77
        system_settings().max_money();
3 ✔
78
}
79

80
time_t protocol::start_time() const NOEXCEPT
1 ✔
81
{
82
    return session_->start_time();
1 ✔
83
}
84

85
size_t protocol::channel_count() const NOEXCEPT
1 ✔
86
{
87
    return session_->channel_count();
1 ✔
88
}
89

90
size_t protocol::inbound_channel_count() const NOEXCEPT
1 ✔
91
{
92
    return session_->inbound_channel_count();
1 ✔
93
}
94

95
// Methods.
96
// ----------------------------------------------------------------------------
97

98
void protocol::get_template(template_handler&& handler) NOEXCEPT
×
99
{
100
    session_->get_template(std::move(handler));
×
101
}
×
102

103
void protocol::estimate(size_t target, estimate_mode mode,
1 ✔
104
    estimate_handler&& handler) NOEXCEPT
105
{
106
    session_->estimate(target, mode, std::move(handler));
1 ✔
107
}
1 ✔
108

109
void protocol::get_confirmable_txs(confirmable_txs_handler&& handler) NOEXCEPT
5 ✔
110
{
111
    session_->get_confirmable_txs(std::move(handler));
5 ✔
112
}
5 ✔
113

UNCOV
114
void protocol::get_confirmable_fees(confirmable_fees_handler&& handler) NOEXCEPT
×
115
{
UNCOV
116
    session_->get_confirmable_fees(std::move(handler));
×
UNCOV
117
}
×
118

119
// Events subscription.
120
// ----------------------------------------------------------------------------
121

122
size_t protocol::address_count() const NOEXCEPT
1 ✔
123
{
124
    return session_->address_count();
1 ✔
125
}
126

127
void protocol::connect(const network::config::endpoint& endpoint) NOEXCEPT
1 ✔
128
{
129
    session_->connect(endpoint);
1 ✔
130
}
1 ✔
131

132
void protocol::connect(const network::config::endpoint& endpoint,
1 ✔
133
    network::net::channel_notifier&& handler) NOEXCEPT
134
{
135
    session_->connect(endpoint, std::move(handler));
1 ✔
136
}
1 ✔
137

138
bool protocol::suspended() const NOEXCEPT
2 ✔
139
{
140
    return session_->suspended();
2 ✔
141
}
142

143
void protocol::suspend(const code& ec) NOEXCEPT
1 ✔
144
{
145
    session_->suspend(ec);
1 ✔
146
}
1 ✔
147

148
bool protocol::resume() NOEXCEPT
1 ✔
149
{
150
    return session_->resume();
1 ✔
151
}
152

153
// Organizers.
154
// ----------------------------------------------------------------------------
155

156
void protocol::organize(const system::chain::header::cptr& header,
1 ✔
157
    organize_handler&& handler) NOEXCEPT
158
{
159
    session_->organize(header, std::move(handler));
1 ✔
160
}
1 ✔
161

162
void protocol::organize(const system::chain::header::cptr& header,
6,010 ✔
163
    bool milestone, organize_handler&& handler) NOEXCEPT
164
{
165
    session_->organize(header, milestone, std::move(handler));
6,010 ✔
166
}
6,010 ✔
167

168
void protocol::organize_compact(const system::chain::header::cptr& header,
10 ✔
169
    organize_handler&& handler) NOEXCEPT
170
{
171
    session_->organize_compact(header, std::move(handler));
10 ✔
172
}
10 ✔
173

174
void protocol::prioritize(const system::hash_digest& hash,
1 ✔
175
    organize_handler&& handler) NOEXCEPT
176
{
177
    session_->prioritize(hash, std::move(handler));
1 ✔
178
}
1 ✔
179

180
void protocol::get_minimum_work(work_handler&& handler) NOEXCEPT
77 ✔
181
{
182
    session_->get_minimum_work(std::move(handler));
77 ✔
183
}
77 ✔
184

UNCOV
185
void protocol::submit(const system::chain::transactions_cptr& txs, bool test,
×
186
    submit_handler&& handler) NOEXCEPT
187
{
UNCOV
188
    session_->submit(txs, test, std::move(handler));
×
UNCOV
189
}
×
190

191
void protocol::submit_announced(const system::chain::transactions_cptr& txs,
25 ✔
192
    submit_handler&& handler) NOEXCEPT
193
{
194
    session_->submit_announced(txs, std::move(handler));
25 ✔
195
}
25 ✔
196

197
void protocol::submit_compact(const system::chain::transactions_cptr& txs,
4 ✔
198
    const database::tx_links& links, const database::header_link& link,
199
    submit_handler&& handler) NOEXCEPT
200
{
201
    session_->submit_compact(txs, links, link, std::move(handler));
4 ✔
202
}
4 ✔
203

204
bool protocol::archive_block(code& ec,
6 ✔
205
    const system::chain::view::block::cptr& block,
206
    const database::header_link& link, bool strong, bool bypass, size_t height,
207
    bool prune, network::result_handler&& handler) NOEXCEPT
208
{
209
    return session_->archive_block(ec, block, link, strong, bypass, height,
6 ✔
210
        prune, std::move(handler));
6 ✔
211
}
212

213
void protocol::subscribe_chase(event_notifier&& handler) NOEXCEPT
488 ✔
214
{
215
    // This is a shared instance multiply-derived from network::protocol.
UNCOV
216
    const auto self = dynamic_cast<network::protocol&>(*this)
×
217
        .shared_from_sibling<node::protocol, network::protocol>();
488 ✔
218

219
    event_completer completer = std::bind(&protocol::handle_subscribed, self,
976 ✔
220
        _1, _2);
488 ✔
221

222
    session_->subscribe_chase(std::move(handler),
488 ✔
223
        std::bind(&protocol::handle_subscribe,
488 ✔
224
            self, _1, _2, std::move(completer)));
488 ✔
225
}
488 ✔
226

227
// private
228
void protocol::handle_subscribe(const code& ec, object_key key,
488 ✔
229
    const event_completer& complete) NOEXCEPT
230
{
231
    // The key member is protected by one event subscription per protocol.
232
    BC_ASSERT_MSG(is_zero(key_), "unsafe access");
488 ✔
233

234
    // Protocol stop is thread safe.
235
    if (ec)
488 ✔
236
    {
237
        channel_->stop(ec);
4 ✔
238
        return;
4 ✔
239
    }
240

241
    key_ = key;
484 ✔
242
    complete(ec, key_);
484 ✔
243
}
244

245
void protocol::handle_subscribed(const code& ec, object_key key) NOEXCEPT
484 ✔
246
{
247
    // This is a shared instance multiply-derived from network::protocol.
UNCOV
248
    const auto self = dynamic_cast<network::protocol&>(*this)
×
249
        .shared_from_sibling<node::protocol, network::protocol>();
484 ✔
250

251
    network::io::post(channel_->strand(),
484 ✔
252
        std::bind(&protocol::subscribed, self, ec, key));
968 ✔
253
}
484 ✔
254

255
void protocol::subscribed(const code& ec, object_key) NOEXCEPT
423 ✔
256
{
257
    BC_ASSERT(channel_->stranded());
423 ✔
258

259
    // Unsubscriber race is ok.
260
    if (channel_->stopped() || ec)
423 ✔
UNCOV
261
        unsubscribe_chase();
×
262
}
423 ✔
263

264
// As this has no completion handler resubscription is not allowed.
265
void protocol::unsubscribe_chase() NOEXCEPT
626 ✔
266
{
267
    session_->unsubscribe_chase(key_);
626 ✔
268
    key_ = {};
626 ✔
269
}
626 ✔
270

271
object_key protocol::events_key() const NOEXCEPT
34 ✔
272
{
273
    return key_;
34 ✔
274
}
275

276
} // namespace node
277
} // 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