• 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

87.5
/src/protocols/protocol_peer.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_peer.hpp>
20

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

23
namespace libbitcoin {
24
namespace node {
25

26
using namespace system;
27
using namespace network;
28

29
// Organizers.
30
// ----------------------------------------------------------------------------
31

32
void protocol_peer::get_hashes(map_handler&& handler) NOEXCEPT
53 ✔
33
{
34
    session_->get_hashes(std::move(handler));
53 ✔
35
}
53 ✔
36

37
void protocol_peer::put_hashes(const map_ptr& map,
27 ✔
38
    network::result_handler&& handler) NOEXCEPT
39
{
40
    session_->put_hashes(map, std::move(handler));
27 ✔
41
}
27 ✔
42

43
void protocol_peer::get_unfilled(header_t link,
5 ✔
44
    map_handler&& handler) NOEXCEPT
45
{
46
    session_->get_unfilled(link, std::move(handler));
5 ✔
47
}
5 ✔
48

49
void protocol_peer::set_downloader(
122 ✔
50
    channel_peer::downloader&& handler) NOEXCEPT
51
{
52
    channel_->set_downloader(std::move(handler));
122 ✔
53
}
122 ✔
54

55
bool protocol_peer::download(const map_ptr& map,
5 ✔
56
    const job::ptr& job) NOEXCEPT
57
{
58
    return channel_->download(map, job);
5 ✔
59
}
60

61
bool protocol_peer::reserve_compact() NOEXCEPT
3 ✔
62
{
63
    return session_->reserve_compact();
3 ✔
64
}
65

66
void protocol_peer::release_compact() NOEXCEPT
3 ✔
67
{
68
    session_->release_compact();
3 ✔
69
}
3 ✔
70

71
// Methods.
72
// ----------------------------------------------------------------------------
73

74
void protocol_peer::performance(uint64_t speed,
4 ✔
75
    network::result_handler&& handler) const NOEXCEPT
76
{
77
    // Passed protocol->session->full_node->check_chaser.post->do_update.
78
    session_->performance(events_key(), speed, std::move(handler));
4 ✔
79
}
4 ✔
80

81
code protocol_peer::fault(const code& ec) NOEXCEPT
1 ✔
82
{
83
    // Short-circuit self stop.
84
    stop(ec);
1 ✔
85

86
    // Stop all other channels and suspend all connectors/acceptors.
87
    session_->fault(ec);
1 ✔
88
    return ec;
1 ✔
89
}
90

91
// Announcements.
92
// ----------------------------------------------------------------------------
93

94
void protocol_peer::set_announced(const system::hash_digest& hash) NOEXCEPT
50,062 ✔
95
{
96
    channel_->set_announced(hash);
50,062 ✔
97
}
50,062 ✔
98

99
void protocol_peer::set_current(bool value) NOEXCEPT
5 ✔
100
{
101
    channel_->set_current(value);
5 ✔
102
}
5 ✔
103

104
bool protocol_peer::was_announced(const system::hash_digest& hash) const NOEXCEPT
51 ✔
105
{
106
    return channel_->was_announced(hash);
51 ✔
107
}
108

109
// Events notification.
110
// ----------------------------------------------------------------------------
111

112
void protocol_peer::notify(const code& ec, event_value value) const NOEXCEPT
36 ✔
113
{
114
    session_->notify(ec, value);
36 ✔
115
}
36 ✔
116

UNCOV
117
void protocol_peer::notify_one(object_key key, const code& ec,
×
118
    event_value value) const NOEXCEPT
119
{
120
    session_->notify_one(key, ec, value);
×
121
}
×
122

123
// Compact blocks (bip152 version 2).
124
// ----------------------------------------------------------------------------
125

126
network::messages::peer::compact_block::cptr protocol_peer::make_compact_block(
4 ✔
127
    const database::header_link& link) const NOEXCEPT
128
{
129
    using namespace network::messages::peer;
130
    const auto& query = archive();
4 ✔
131
    const auto header = query.get_header(link);
4 ✔
132
    const auto txs = query.to_transactions(link);
4 ✔
133
    if (!header || txs.empty())
4 ✔
134
        return {};
2 ✔
135

136
    const auto coinbase = query.get_transaction(txs.front(), true);
2 ✔
137
    const auto wtxids = query.get_wtxids(link);
2 ✔
138
    if (!coinbase || wtxids.size() != txs.size())
2 ✔
UNCOV
139
        return {};
×
140

141
    const auto nonce = maybe_random::next<uint64_t>(0, max_uint64);
2 ✔
142
    const auto key = chain::short_id::to_key(*header, nonce);
2 ✔
143

144
    compact_block::short_id_list ids{};
2 ✔
145
    ids.reserve(sub1(wtxids.size()));
2 ✔
146
    for (auto it = std::next(wtxids.cbegin()); it != wtxids.cend(); ++it)
4 ✔
147
    {
UNCOV
148
        if (*it == null_hash)
×
UNCOV
149
            return {};
×
150

UNCOV
151
        const auto id = chain::short_id::to_id(key, *it);
×
UNCOV
152
        ids.push_back(chain::short_id::to_mini(id));
×
153
    }
154

155
    return to_shared(compact_block
8 ✔
156
    {
157
        header,
158
        nonce,
159
        std::move(ids),
2 ✔
160
        compact_block_items{ compact_block_item{ zero, coinbase } }
2 ✔
161
    });
2 ✔
162
}
6 ✔
163

164
} // namespace node
165
} // 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