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

libbitcoin / libbitcoin-node / 41739527542

03 Nov 2026 11:29PM UTC coverage: 91.876% (-0.2%) from 92.07%
41739527542

push

github

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

Initialize bases and members in declaration order.

26 of 26 new or added lines in 12 files covered. (100.0%)

35 existing lines in 13 files now uncovered.

4275 of 4653 relevant lines covered (91.88%)

5183.64 hits per line

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

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

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

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

74
uint64_t protocol::minimum_fee_rate() const NOEXCEPT
38 ✔
75
{
76
    return is_current_chain(true) ? node_settings().minimum_fee_rate_() :
38 ✔
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::estimate(size_t target, estimator::mode mode,
1 ✔
99
    estimate_handler&& handler) NOEXCEPT
100
{
101
    session_->estimate(target, mode, std::move(handler));
1 ✔
102
}
1 ✔
103

104
// Events subscription.
105
// ----------------------------------------------------------------------------
106

107
size_t protocol::address_count() const NOEXCEPT
1 ✔
108
{
109
    return session_->address_count();
1 ✔
110
}
111

112
void protocol::connect(const network::config::endpoint& endpoint) NOEXCEPT
1 ✔
113
{
114
    session_->connect(endpoint);
1 ✔
115
}
1 ✔
116

117
void protocol::connect(const network::config::endpoint& endpoint,
1 ✔
118
    network::net::channel_notifier&& handler) NOEXCEPT
119
{
120
    session_->connect(endpoint, std::move(handler));
1 ✔
121
}
1 ✔
122

123
bool protocol::suspended() const NOEXCEPT
2 ✔
124
{
125
    return session_->suspended();
2 ✔
126
}
127

128
void protocol::suspend(const code& ec) NOEXCEPT
1 ✔
129
{
130
    session_->suspend(ec);
1 ✔
131
}
1 ✔
132

133
bool protocol::resume() NOEXCEPT
1 ✔
134
{
135
    return session_->resume();
1 ✔
136
}
137

138
// Organizers.
139
// ----------------------------------------------------------------------------
140

141
void protocol::organize(const system::chain::header::cptr& header,
1 ✔
142
    organize_handler&& handler) NOEXCEPT
143
{
144
    session_->organize(header, std::move(handler));
1 ✔
145
}
1 ✔
146

147
void protocol::organize(const system::chain::header::cptr& header,
6,010 ✔
148
    bool milestone, organize_handler&& handler) NOEXCEPT
149
{
150
    session_->organize(header, milestone, std::move(handler));
6,010 ✔
151
}
6,010 ✔
152

153
void protocol::organize_compact(const system::chain::header::cptr& header,
6 ✔
154
    organize_handler&& handler) NOEXCEPT
155
{
156
    session_->organize_compact(header, std::move(handler));
6 ✔
157
}
6 ✔
158

159
void protocol::prioritize(const system::hash_digest& hash,
1 ✔
160
    organize_handler&& handler) NOEXCEPT
161
{
162
    session_->prioritize(hash, std::move(handler));
1 ✔
163
}
1 ✔
164

165
void protocol::get_minimum_work(work_handler&& handler) NOEXCEPT
66 ✔
166
{
167
    session_->get_minimum_work(std::move(handler));
66 ✔
168
}
66 ✔
169

170
void protocol::submit(const system::chain::transactions_cptr& txs, bool test,
8 ✔
171
    submit_handler&& handler) NOEXCEPT
172
{
173
    session_->submit(txs, test, std::move(handler));
8 ✔
174
}
8 ✔
175

176
void protocol::submit_compact(const system::chain::transactions_cptr& txs,
3 ✔
177
    const database::tx_links& links, const database::header_link& link,
178
    submit_handler&& handler) NOEXCEPT
179
{
180
    session_->submit_compact(txs, links, link, std::move(handler));
3 ✔
181
}
3 ✔
182

183
void protocol::subscribe_chase(event_notifier&& handler) NOEXCEPT
391 ✔
184
{
185
    // This is a shared instance multiply-derived from network::protocol.
186
    const auto self = dynamic_cast<network::protocol&>(*this)
×
187
        .shared_from_sibling<node::protocol, network::protocol>();
391 ✔
188

189
    event_completer completer = std::bind(&protocol::handle_subscribed, self,
782 ✔
190
        _1, _2);
391 ✔
191

192
    session_->subscribe_chase(std::move(handler),
391 ✔
193
        std::bind(&protocol::handle_subscribe,
391 ✔
194
            self, _1, _2, std::move(completer)));
391 ✔
195
}
391 ✔
196

197
// private
198
void protocol::handle_subscribe(const code& ec, object_key key,
391 ✔
199
    const event_completer& complete) NOEXCEPT
200
{
201
    // The key member is protected by one event subscription per protocol.
202
    BC_ASSERT_MSG(is_zero(key_), "unsafe access");
391 ✔
203

204
    // Protocol stop is thread safe.
205
    if (ec)
391 ✔
206
    {
207
        channel_->stop(ec);
4 ✔
208
        return;
4 ✔
209
    }
210

211
    key_ = key;
387 ✔
212
    complete(ec, key_);
387 ✔
213
}
214

215
void protocol::handle_subscribed(const code& ec, object_key key) NOEXCEPT
387 ✔
216
{
217
    // This is a shared instance multiply-derived from network::protocol.
218
    const auto self = dynamic_cast<network::protocol&>(*this)
×
219
        .shared_from_sibling<node::protocol, network::protocol>();
387 ✔
220

221
    network::io::post(channel_->strand(),
387 ✔
222
        std::bind(&protocol::subscribed, self, ec, key));
774 ✔
223
}
387 ✔
224

225
void protocol::subscribed(const code& ec, object_key) NOEXCEPT
335 ✔
226
{
227
    BC_ASSERT(channel_->stranded());
335 ✔
228

229
    // Unsubscriber race is ok.
230
    if (channel_->stopped() || ec)
335 ✔
UNCOV
231
        unsubscribe_chase();
×
232
}
335 ✔
233

234
// As this has no completion handler resubscription is not allowed.
235
void protocol::unsubscribe_chase() NOEXCEPT
500 ✔
236
{
237
    session_->unsubscribe_chase(key_);
500 ✔
238
    key_ = {};
500 ✔
239
}
500 ✔
240

241
object_key protocol::events_key() const NOEXCEPT
27 ✔
242
{
243
    return key_;
27 ✔
244
}
245

246
} // namespace node
247
} // 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