• 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

84.31
/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
45 ✔
33
{
34
    session_->get_hashes(std::move(handler));
45 ✔
35
}
45 ✔
36

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

43
// Methods.
44
// ----------------------------------------------------------------------------
45

46
void protocol_peer::performance(uint64_t speed,
4 ✔
47
    network::result_handler&& handler) const NOEXCEPT
48
{
49
    // Passed protocol->session->full_node->check_chaser.post->do_update.
50
    session_->performance(events_key(), speed, std::move(handler));
4 ✔
51
}
4 ✔
52

53
code protocol_peer::fault(const code& ec) NOEXCEPT
1 ✔
54
{
55
    // Short-circuit self stop.
56
    stop(ec);
1 ✔
57

58
    // Stop all other channels and suspend all connectors/acceptors.
59
    session_->fault(ec);
1 ✔
60
    return ec;
1 ✔
61
}
62

63
// Announcements.
64
// ----------------------------------------------------------------------------
65

66
void protocol_peer::set_announced(const system::hash_digest& hash) NOEXCEPT
50,027 ✔
67
{
68
    channel_->set_announced(hash);
50,027 ✔
69
}
50,027 ✔
70

71
void protocol_peer::set_current(bool value) NOEXCEPT
5 ✔
72
{
73
    channel_->set_current(value);
5 ✔
74
}
5 ✔
75

76
bool protocol_peer::was_announced(const system::hash_digest& hash) const NOEXCEPT
25 ✔
77
{
78
    return channel_->was_announced(hash);
25 ✔
79
}
80

81
// Events notification.
82
// ----------------------------------------------------------------------------
83

84
void protocol_peer::notify(const code& ec, event_value value) const NOEXCEPT
28 ✔
85
{
86
    session_->notify(ec, value);
28 ✔
87
}
28 ✔
88

89
void protocol_peer::notify_one(object_key key, const code& ec,
×
90
    event_value value) const NOEXCEPT
91
{
92
    session_->notify_one(key, ec, value);
×
93
}
×
94

95
// Compact blocks (bip152 version 2).
96
// ----------------------------------------------------------------------------
97

98
network::messages::peer::compact_block::cptr protocol_peer::make_compact_block(
4 ✔
99
    const database::header_link& link) const NOEXCEPT
100
{
101
    using namespace network::messages::peer;
102
    const auto& query = archive();
4 ✔
103
    const auto header = query.get_header(link);
4 ✔
104
    const auto txs = query.to_transactions(link);
4 ✔
105
    if (!header || txs.empty())
4 ✔
106
        return {};
2 ✔
107

108
    const auto coinbase = query.get_transaction(txs.front(), true);
2 ✔
109
    const auto wtxids = query.get_wtxids(link);
2 ✔
110
    if (!coinbase || wtxids.size() != txs.size())
2 ✔
UNCOV
111
        return {};
×
112

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

116
    compact_block::short_id_list ids{};
2 ✔
117
    ids.reserve(sub1(wtxids.size()));
2 ✔
118
    for (auto it = std::next(wtxids.cbegin()); it != wtxids.cend(); ++it)
4 ✔
119
    {
120
        if (*it == null_hash)
×
121
            return {};
×
122

123
        const auto id = chain::short_id::to_id(key, *it);
×
124
        ids.push_back(chain::short_id::to_mini(id));
×
125
    }
126

127
    return to_shared(compact_block
8 ✔
128
    {
129
        header,
130
        nonce,
131
        std::move(ids),
2 ✔
132
        compact_block_items{ compact_block_item{ zero, coinbase } }
2 ✔
133
    });
2 ✔
134
}
6 ✔
135

136
} // namespace node
137
} // 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