• 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

89.77
/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
55 ✔
33
{
34
    session_->get_hashes(std::move(handler));
55 ✔
35
}
55 ✔
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(
126 ✔
50
    channel_peer::downloader&& handler) NOEXCEPT
51
{
52
    channel_->set_downloader(std::move(handler));
126 ✔
53
}
126 ✔
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
bool protocol_peer::request_mempool() const NOEXCEPT
68 ✔
72
{
73
    return session_->request_mempool();
68 ✔
74
}
75

76
bool protocol_peer::reserve_relay() NOEXCEPT
88 ✔
77
{
78
    const auto slot = session_->reserve_relay();
88 ✔
79
    channel_->set_relay_slot(slot);
88 ✔
80
    return slot < relay_slots;
88 ✔
81
}
82

83
void protocol_peer::activate_relay(object_key key) NOEXCEPT
88 ✔
84
{
85
    session_->activate_relay(channel_->relay_slot(), key);
88 ✔
86
}
88 ✔
87

88
void protocol_peer::release_relay() NOEXCEPT
88 ✔
89
{
90
    const auto slot = channel_->relay_slot();
88 ✔
91
    channel_->set_relay_slot(relay_slots);
88 ✔
92
    session_->release_relay(slot);
88 ✔
93
}
88 ✔
94

95
size_t protocol_peer::relay_slot() const NOEXCEPT
154 ✔
96
{
97
    return channel_->relay_slot();
154 ✔
98
}
99

100
void protocol_peer::set_relay_rate(uint64_t rate) NOEXCEPT
5 ✔
101
{
102
    session_->set_relay_rate(channel_->relay_slot(), rate);
5 ✔
103
}
5 ✔
104

105
void protocol_peer::set_relayed(const database::tx_links& links) NOEXCEPT
2 ✔
106
{
107
    session_->set_relayed(channel_->relay_slot(), links);
2 ✔
108
}
2 ✔
109

110
void protocol_peer::relay_pool() NOEXCEPT
7 ✔
111
{
112
    session_->relay_pool(channel_->relay_slot());
7 ✔
113
}
7 ✔
114

115
// Methods.
116
// ----------------------------------------------------------------------------
117

118
void protocol_peer::performance(uint64_t speed,
4 ✔
119
    network::result_handler&& handler) const NOEXCEPT
120
{
121
    // Passed protocol->session->full_node->check_chaser.post->do_update.
122
    session_->performance(events_key(), speed, std::move(handler));
4 ✔
123
}
4 ✔
124

UNCOV
125
code protocol_peer::fault(const code& ec) NOEXCEPT
×
126
{
127
    // Short-circuit self stop.
UNCOV
128
    stop(ec);
×
129

130
    // Stop all other channels and suspend all connectors/acceptors.
UNCOV
131
    session_->fault(ec);
×
UNCOV
132
    return ec;
×
133
}
134

135
// Announcements.
136
// ----------------------------------------------------------------------------
137

138
void protocol_peer::set_announced(const system::hash_digest& hash) NOEXCEPT
50,080 ✔
139
{
140
    channel_->set_announced(hash);
50,080 ✔
141
}
50,080 ✔
142

143
void protocol_peer::set_current(bool value) NOEXCEPT
5 ✔
144
{
145
    channel_->set_current(value);
5 ✔
146
}
5 ✔
147

148
bool protocol_peer::was_announced(const system::hash_digest& hash) const NOEXCEPT
50,104 ✔
149
{
150
    return channel_->was_announced(hash);
50,104 ✔
151
}
152

153
void protocol_peer::set_silenced(bool value) NOEXCEPT
73 ✔
154
{
155
    channel_->set_silenced(value);
73 ✔
156
}
73 ✔
157

158
bool protocol_peer::silenced() const NOEXCEPT
49 ✔
159
{
160
    return channel_->silenced();
49 ✔
161
}
162

163
// Compact blocks (bip152 version 2).
164
// ----------------------------------------------------------------------------
165

166
network::messages::peer::compact_block::cptr protocol_peer::make_compact_block(
4 ✔
167
    const database::header_link& link) const NOEXCEPT
168
{
169
    using namespace network::messages::peer;
170
    const auto& query = archive();
4 ✔
171
    const auto header = query.get_header(link);
4 ✔
172
    const auto txs = query.to_transactions(link);
4 ✔
173
    if (!header || txs.empty())
4 ✔
174
        return {};
2 ✔
175

176
    const auto coinbase = query.get_transaction(txs.front(), true);
2 ✔
177
    const auto wtxids = query.get_wtxids(link);
2 ✔
178
    if (!coinbase || wtxids.size() != txs.size())
2 ✔
UNCOV
179
        return {};
×
180

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

184
    compact_block::short_id_list ids{};
2 ✔
185
    ids.reserve(sub1(wtxids.size()));
2 ✔
186
    for (auto it = std::next(wtxids.cbegin()); it != wtxids.cend(); ++it)
4 ✔
187
    {
UNCOV
188
        if (*it == null_hash)
×
UNCOV
189
            return {};
×
190

UNCOV
191
        const auto id = chain::short_id::to_id(key, *it);
×
UNCOV
192
        ids.push_back(chain::short_id::to_mini(id));
×
193
    }
194

195
    return to_shared(compact_block
8 ✔
196
    {
197
        header,
198
        nonce,
199
        std::move(ids),
2 ✔
200
        compact_block_items{ compact_block_item{ zero, coinbase } }
2 ✔
201
    });
2 ✔
202
}
6 ✔
203

204
} // namespace node
205
} // 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