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

libbitcoin / libbitcoin-node / 47053482638

03 Dec 2026 06:53AM UTC coverage: 89.006% (-0.009%) from 89.015%
47053482638

push

github

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

Pool updates and optimizations.

94 of 107 new or added lines in 15 files covered. (87.85%)

1 existing line in 1 file now uncovered.

5489 of 6167 relevant lines covered (89.01%)

4178.98 hits per line

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

95.28
/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,375 ✔
35
{
36
    return session_->archive();
50,375 ✔
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
42 ✔
45
{
46
    return session_->system_settings();
42 ✔
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
220 ✔
65
{
66
    return session_->is_current_chain(confirmed);
220 ✔
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
1 ✔
75
{
76
    return is_current_chain(true) ? node_settings().pool.minimum_fee_rate_() :
1 ✔
77
        system_settings().max_money();
1 ✔
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

NEW
98
void protocol::get_template(bool detailed,
×
99
    block_template_handler&& handler) NOEXCEPT
100
{
NEW
101
    session_->get_template(detailed, std::move(handler));
×
102
}
×
103

104
void protocol::demand_template(bool demand) NOEXCEPT
1 ✔
105
{
106
    session_->demand_template(demand);
1 ✔
107
}
1 ✔
108

109
uint64_t protocol::template_generation() const NOEXCEPT
1 ✔
110
{
111
    return session_->template_generation();
1 ✔
112
}
113

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

120
void protocol::get_confirmable_txs(confirmable_txs_handler&& handler) NOEXCEPT
1 ✔
121
{
122
    session_->get_confirmable_txs(std::move(handler));
1 ✔
123
}
1 ✔
124

125
void protocol::get_confirmable_fees(confirmable_fees_handler&& handler) NOEXCEPT
1 ✔
126
{
127
    session_->get_confirmable_fees(std::move(handler));
1 ✔
128
}
1 ✔
129

130
void protocol::get_unconfirmed_totals(const pool_receipts_cptr& receipts,
1 ✔
131
    unconfirmed_totals_handler&& handler) NOEXCEPT
132
{
133
    session_->get_unconfirmed_totals(receipts, std::move(handler));
1 ✔
134
}
1 ✔
135

136
// Events subscription.
137
// ----------------------------------------------------------------------------
138

139
size_t protocol::address_count() const NOEXCEPT
1 ✔
140
{
141
    return session_->address_count();
1 ✔
142
}
143

144
void protocol::connect(const network::config::endpoint& endpoint) NOEXCEPT
1 ✔
145
{
146
    session_->connect(endpoint);
1 ✔
147
}
1 ✔
148

149
void protocol::connect(const network::config::endpoint& endpoint,
1 ✔
150
    network::net::channel_notifier&& handler) NOEXCEPT
151
{
152
    session_->connect(endpoint, std::move(handler));
1 ✔
153
}
1 ✔
154

155
bool protocol::suspended() const NOEXCEPT
2 ✔
156
{
157
    return session_->suspended();
2 ✔
158
}
159

160
void protocol::suspend(const code& ec) NOEXCEPT
1 ✔
161
{
162
    session_->suspend(ec);
1 ✔
163
}
1 ✔
164

165
bool protocol::resume() NOEXCEPT
1 ✔
166
{
167
    return session_->resume();
1 ✔
168
}
169

170
// Organizers.
171
// ----------------------------------------------------------------------------
172

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

179
void protocol::organize(const system::chain::header::cptr& header,
6,010 ✔
180
    bool milestone, organize_handler&& handler) NOEXCEPT
181
{
182
    session_->organize(header, milestone, std::move(handler));
6,010 ✔
183
}
6,010 ✔
184

185
void protocol::organize_compact(const system::chain::header::cptr& header,
10 ✔
186
    organize_handler&& handler) NOEXCEPT
187
{
188
    session_->organize_compact(header, std::move(handler));
10 ✔
189
}
10 ✔
190

191
void protocol::organize_submitted(const system::chain::header::cptr& header,
1 ✔
192
    bool milestone, organize_handler&& handler) NOEXCEPT
193
{
194
    session_->organize_submitted(header, milestone, std::move(handler));
1 ✔
195
}
1 ✔
196

197
void protocol::prioritize(const system::hash_digest& hash,
2 ✔
198
    organize_handler&& handler) NOEXCEPT
199
{
200
    session_->prioritize(hash, std::move(handler));
2 ✔
201
}
2 ✔
202

203
void protocol::get_minimum_work(work_handler&& handler) NOEXCEPT
80 ✔
204
{
205
    session_->get_minimum_work(std::move(handler));
80 ✔
206
}
80 ✔
207

208
void protocol::submit(const system::chain::transactions_cptr& txs, bool test,
1 ✔
209
    submit_handler&& handler) NOEXCEPT
210
{
211
    session_->submit(txs, test, std::move(handler));
1 ✔
212
}
1 ✔
213

214
void protocol::submit_announced(const system::chain::transactions_cptr& txs,
27 ✔
215
    size_t slot, submit_handler&& handler) NOEXCEPT
216
{
217
    session_->submit_announced(txs, slot, std::move(handler));
27 ✔
218
}
27 ✔
219

220
void protocol::submit_compact(const system::chain::transactions_cptr& txs,
4 ✔
221
    database::tx_links&& links, const database::header_link& link,
222
    submit_handler&& handler) NOEXCEPT
223
{
224
    session_->submit_compact(txs, std::move(links), link, std::move(handler));
4 ✔
225
}
4 ✔
226

227
bool protocol::archive_block(code& ec,
6 ✔
228
    const system::chain::view::block::cptr& block,
229
    const database::header_link& link, bool strong, bool bypass, size_t height,
230
    bool prune, network::result_handler&& handler) NOEXCEPT
231
{
232
    return session_->archive_block(ec, block, link, strong, bypass, height,
6 ✔
233
        prune, std::move(handler));
6 ✔
234
}
235

236
void protocol::subscribe_chase(event_notifier&& handler) NOEXCEPT
545 ✔
237
{
238
    // This is a shared instance multiply-derived from network::protocol.
239
    const auto self = dynamic_cast<network::protocol&>(*this)
×
240
        .shared_from_sibling<node::protocol, network::protocol>();
545 ✔
241

242
    event_completer completer = std::bind(&protocol::handle_subscribed, self,
1,090 ✔
243
        _1, _2);
545 ✔
244

245
    session_->subscribe_chase(std::move(handler),
545 ✔
246
        std::bind(&protocol::handle_subscribe,
545 ✔
247
            self, _1, _2, std::move(completer)));
545 ✔
248
}
545 ✔
249

250
// private
251
void protocol::handle_subscribe(const code& ec, object_key key,
545 ✔
252
    const event_completer& complete) NOEXCEPT
253
{
254
    // The key member is protected by one event subscription per protocol.
255
    BC_ASSERT_MSG(is_zero(key_), "unsafe access");
545 ✔
256

257
    // Protocol stop is thread safe.
258
    if (ec)
545 ✔
259
    {
260
        channel_->stop(ec);
4 ✔
261
        return;
4 ✔
262
    }
263

264
    key_ = key;
541 ✔
265
    complete(ec, key_);
541 ✔
266
}
267

268
void protocol::handle_subscribed(const code& ec, object_key key) NOEXCEPT
541 ✔
269
{
270
    // This is a shared instance multiply-derived from network::protocol.
271
    const auto self = dynamic_cast<network::protocol&>(*this)
×
272
        .shared_from_sibling<node::protocol, network::protocol>();
541 ✔
273

274
    network::io::post(channel_->strand(),
541 ✔
275
        std::bind(&protocol::subscribed, self, ec, key));
1,082 ✔
276
}
541 ✔
277

278
void protocol::subscribed(const code& ec, object_key) NOEXCEPT
388 ✔
279
{
280
    BC_ASSERT(channel_->stranded());
388 ✔
281

282
    // Unsubscriber race is ok.
283
    if (channel_->stopped() || ec)
388 ✔
284
        unsubscribe_chase();
×
285
}
388 ✔
286

287
// As this has no completion handler resubscription is not allowed.
288
void protocol::unsubscribe_chase() NOEXCEPT
702 ✔
289
{
290
    session_->unsubscribe_chase(key_);
702 ✔
291
    key_ = {};
702 ✔
292
}
702 ✔
293

294
object_key protocol::events_key() const NOEXCEPT
36 ✔
295
{
296
    return key_;
36 ✔
297
}
298

299
void protocol::notify(const code& ec, event_value value) const NOEXCEPT
38 ✔
300
{
301
    session_->notify(ec, value);
38 ✔
302
}
38 ✔
303

304
void protocol::notify_one(object_key key, const code& ec,
1 ✔
305
    event_value value) const NOEXCEPT
306
{
307
    session_->notify_one(key, ec, value);
1 ✔
308
}
1 ✔
309

310
} // namespace node
311
} // 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