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

libbitcoin / libbitcoin-node / 45530165848

25 Nov 2026 02:03AM UTC coverage: 89.415% (-1.2%) from 90.659%
45530165848

push

github

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

Advance pool chain state by header, querying only at start/reorg.

32 of 33 new or added lines in 4 files covered. (96.97%)

247 existing lines in 18 files now uncovered.

5102 of 5706 relevant lines covered (89.41%)

4440.97 hits per line

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

76.61
/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,371 ✔
35
{
36
    return session_->archive();
50,371 ✔
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
41 ✔
45
{
46
    return session_->system_settings();
41 ✔
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
11 ✔
60
{
61
    return session_->node_settings();
11 ✔
62
}
63

64
bool protocol::is_current_chain(bool confirmed) const NOEXCEPT
217 ✔
65
{
66
    return session_->is_current_chain(confirmed);
217 ✔
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

UNCOV
74
uint64_t protocol::minimum_fee_rate() const NOEXCEPT
×
75
{
UNCOV
76
    return is_current_chain(true) ? node_settings().pool.minimum_fee_rate_() :
×
UNCOV
77
        system_settings().max_money();
×
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(block_template_handler&& handler) NOEXCEPT
×
99
{
100
    session_->get_template(std::move(handler));
×
101
}
×
102

UNCOV
103
void protocol::demand_template(bool demand) NOEXCEPT
×
104
{
UNCOV
105
    session_->demand_template(demand);
×
UNCOV
106
}
×
107

UNCOV
108
uint64_t protocol::template_generation() const NOEXCEPT
×
109
{
UNCOV
110
    return session_->template_generation();
×
111
}
112

113
void protocol::estimate(size_t target, estimate_mode mode,
1 ✔
114
    estimate_handler&& handler) NOEXCEPT
115
{
116
    session_->estimate(target, mode, std::move(handler));
1 ✔
117
}
1 ✔
118

UNCOV
119
void protocol::get_confirmable_txs(confirmable_txs_handler&& handler) NOEXCEPT
×
120
{
UNCOV
121
    session_->get_confirmable_txs(std::move(handler));
×
UNCOV
122
}
×
123

UNCOV
124
void protocol::get_confirmable_fees(confirmable_fees_handler&& handler) NOEXCEPT
×
125
{
UNCOV
126
    session_->get_confirmable_fees(std::move(handler));
×
UNCOV
127
}
×
128

129
// Events subscription.
130
// ----------------------------------------------------------------------------
131

132
size_t protocol::address_count() const NOEXCEPT
1 ✔
133
{
134
    return session_->address_count();
1 ✔
135
}
136

137
void protocol::connect(const network::config::endpoint& endpoint) NOEXCEPT
1 ✔
138
{
139
    session_->connect(endpoint);
1 ✔
140
}
1 ✔
141

142
void protocol::connect(const network::config::endpoint& endpoint,
1 ✔
143
    network::net::channel_notifier&& handler) NOEXCEPT
144
{
145
    session_->connect(endpoint, std::move(handler));
1 ✔
146
}
1 ✔
147

148
bool protocol::suspended() const NOEXCEPT
2 ✔
149
{
150
    return session_->suspended();
2 ✔
151
}
152

153
void protocol::suspend(const code& ec) NOEXCEPT
1 ✔
154
{
155
    session_->suspend(ec);
1 ✔
156
}
1 ✔
157

158
bool protocol::resume() NOEXCEPT
1 ✔
159
{
160
    return session_->resume();
1 ✔
161
}
162

163
// Organizers.
164
// ----------------------------------------------------------------------------
165

166
void protocol::organize(const system::chain::header::cptr& header,
1 ✔
167
    organize_handler&& handler) NOEXCEPT
168
{
169
    session_->organize(header, std::move(handler));
1 ✔
170
}
1 ✔
171

172
void protocol::organize(const system::chain::header::cptr& header,
6,010 ✔
173
    bool milestone, organize_handler&& handler) NOEXCEPT
174
{
175
    session_->organize(header, milestone, std::move(handler));
6,010 ✔
176
}
6,010 ✔
177

178
void protocol::organize_compact(const system::chain::header::cptr& header,
10 ✔
179
    organize_handler&& handler) NOEXCEPT
180
{
181
    session_->organize_compact(header, std::move(handler));
10 ✔
182
}
10 ✔
183

UNCOV
184
void protocol::organize_submitted(const system::chain::header::cptr& header,
×
185
    organize_handler&& handler) NOEXCEPT
186
{
UNCOV
187
    session_->organize_submitted(header, std::move(handler));
×
188
}
×
189

190
void protocol::prioritize(const system::hash_digest& hash,
1 ✔
191
    organize_handler&& handler) NOEXCEPT
192
{
193
    session_->prioritize(hash, std::move(handler));
1 ✔
194
}
1 ✔
195

196
void protocol::get_minimum_work(work_handler&& handler) NOEXCEPT
79 ✔
197
{
198
    session_->get_minimum_work(std::move(handler));
79 ✔
199
}
79 ✔
200

UNCOV
201
void protocol::submit(const system::chain::transactions_cptr& txs, bool test,
×
202
    submit_handler&& handler) NOEXCEPT
203
{
UNCOV
204
    session_->submit(txs, test, std::move(handler));
×
UNCOV
205
}
×
206

207
void protocol::submit_announced(const system::chain::transactions_cptr& txs,
27 ✔
208
    size_t slot, submit_handler&& handler) NOEXCEPT
209
{
210
    session_->submit_announced(txs, slot, std::move(handler));
27 ✔
211
}
27 ✔
212

213
void protocol::submit_compact(const system::chain::transactions_cptr& txs,
4 ✔
214
    const database::tx_links& links, const database::header_link& link,
215
    submit_handler&& handler) NOEXCEPT
216
{
217
    session_->submit_compact(txs, links, link, std::move(handler));
4 ✔
218
}
4 ✔
219

220
bool protocol::archive_block(code& ec,
6 ✔
221
    const system::chain::view::block::cptr& block,
222
    const database::header_link& link, bool strong, bool bypass, size_t height,
223
    bool prune, network::result_handler&& handler) NOEXCEPT
224
{
225
    return session_->archive_block(ec, block, link, strong, bypass, height,
6 ✔
226
        prune, std::move(handler));
6 ✔
227
}
228

229
void protocol::subscribe_chase(event_notifier&& handler) NOEXCEPT
535 ✔
230
{
231
    // This is a shared instance multiply-derived from network::protocol.
UNCOV
232
    const auto self = dynamic_cast<network::protocol&>(*this)
×
233
        .shared_from_sibling<node::protocol, network::protocol>();
535 ✔
234

235
    event_completer completer = std::bind(&protocol::handle_subscribed, self,
1,070 ✔
236
        _1, _2);
535 ✔
237

238
    session_->subscribe_chase(std::move(handler),
535 ✔
239
        std::bind(&protocol::handle_subscribe,
535 ✔
240
            self, _1, _2, std::move(completer)));
535 ✔
241
}
535 ✔
242

243
// private
244
void protocol::handle_subscribe(const code& ec, object_key key,
535 ✔
245
    const event_completer& complete) NOEXCEPT
246
{
247
    // The key member is protected by one event subscription per protocol.
248
    BC_ASSERT_MSG(is_zero(key_), "unsafe access");
535 ✔
249

250
    // Protocol stop is thread safe.
251
    if (ec)
535 ✔
252
    {
253
        channel_->stop(ec);
4 ✔
254
        return;
4 ✔
255
    }
256

257
    key_ = key;
531 ✔
258
    complete(ec, key_);
531 ✔
259
}
260

261
void protocol::handle_subscribed(const code& ec, object_key key) NOEXCEPT
531 ✔
262
{
263
    // This is a shared instance multiply-derived from network::protocol.
UNCOV
264
    const auto self = dynamic_cast<network::protocol&>(*this)
×
265
        .shared_from_sibling<node::protocol, network::protocol>();
531 ✔
266

267
    network::io::post(channel_->strand(),
531 ✔
268
        std::bind(&protocol::subscribed, self, ec, key));
1,062 ✔
269
}
531 ✔
270

271
void protocol::subscribed(const code& ec, object_key) NOEXCEPT
380 ✔
272
{
273
    BC_ASSERT(channel_->stranded());
380 ✔
274

275
    // Unsubscriber race is ok.
276
    if (channel_->stopped() || ec)
380 ✔
UNCOV
277
        unsubscribe_chase();
×
278
}
380 ✔
279

280
// As this has no completion handler resubscription is not allowed.
281
void protocol::unsubscribe_chase() NOEXCEPT
688 ✔
282
{
283
    session_->unsubscribe_chase(key_);
688 ✔
284
    key_ = {};
688 ✔
285
}
688 ✔
286

287
object_key protocol::events_key() const NOEXCEPT
36 ✔
288
{
289
    return key_;
36 ✔
290
}
291

292
void protocol::notify(const code& ec, event_value value) const NOEXCEPT
38 ✔
293
{
294
    session_->notify(ec, value);
38 ✔
295
}
38 ✔
296

UNCOV
297
void protocol::notify_one(object_key key, const code& ec,
×
298
    event_value value) const NOEXCEPT
299
{
UNCOV
300
    session_->notify_one(key, ec, value);
×
UNCOV
301
}
×
302

303
} // namespace node
304
} // 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