Bitcoin Core Fuzz Coverage Report

Coverage Report

Created: 2026-05-28 15:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/Users/brunogarcia/projects/bitcoin-core-dev/src/private_broadcast.cpp
Line
Count
Source
1
// Copyright (c) 2023-present The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or https://opensource.org/license/mit/.
4
5
#include <private_broadcast.h>
6
#include <util/check.h>
7
8
#include <algorithm>
9
10
11
bool PrivateBroadcast::Add(const CTransactionRef& tx)
12
    EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
13
5.42k
{
14
5.42k
    LOCK(m_mutex);
Line
Count
Source
268
5.42k
#define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__)
Line
Count
Source
11
5.42k
#define UNIQUE_NAME(name) PASTE2(name, __COUNTER__)
Line
Count
Source
9
5.42k
#define PASTE2(x, y) PASTE(x, y)
Line
Count
Source
8
5.42k
#define PASTE(x, y) x ## y
15
5.42k
    const bool inserted{m_transactions.try_emplace(tx).second};
16
5.42k
    return inserted;
17
5.42k
}
18
19
std::optional<size_t> PrivateBroadcast::Remove(const CTransactionRef& tx)
20
    EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
21
0
{
22
0
    LOCK(m_mutex);
Line
Count
Source
268
0
#define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__)
Line
Count
Source
11
0
#define UNIQUE_NAME(name) PASTE2(name, __COUNTER__)
Line
Count
Source
9
0
#define PASTE2(x, y) PASTE(x, y)
Line
Count
Source
8
0
#define PASTE(x, y) x ## y
23
0
    const auto handle{m_transactions.extract(tx)};
24
0
    if (handle) {
25
0
        const auto p{DerivePriority(handle.mapped().send_statuses)};
26
0
        return p.num_confirmed;
27
0
    }
28
0
    return std::nullopt;
29
0
}
30
31
std::optional<CTransactionRef> PrivateBroadcast::PickTxForSend(const NodeId& will_send_to_nodeid, const CService& will_send_to_address)
32
    EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
33
251
{
34
251
    LOCK(m_mutex);
Line
Count
Source
268
251
#define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__)
Line
Count
Source
11
251
#define UNIQUE_NAME(name) PASTE2(name, __COUNTER__)
Line
Count
Source
9
251
#define PASTE2(x, y) PASTE(x, y)
Line
Count
Source
8
251
#define PASTE(x, y) x ## y
35
36
251
    const auto it{std::ranges::max_element(
37
251
            m_transactions,
38
251
            [](const auto& a, const auto& b) 
{ return a < b; }43
,
39
251
            [](const auto& el) 
{ return DerivePriority(el.second.send_statuses); }86
)};
40
41
251
    if (it != m_transactions.end()) {
42
251
        auto& [tx, state]{*it};
43
251
        state.send_statuses.emplace_back(will_send_to_nodeid, will_send_to_address, NodeClock::now());
44
251
        return tx;
45
251
    }
46
47
0
    return std::nullopt;
48
251
}
49
50
std::optional<CTransactionRef> PrivateBroadcast::GetTxForNode(const NodeId& nodeid)
51
    EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
52
690
{
53
690
    LOCK(m_mutex);
Line
Count
Source
268
690
#define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__)
Line
Count
Source
11
690
#define UNIQUE_NAME(name) PASTE2(name, __COUNTER__)
Line
Count
Source
9
690
#define PASTE2(x, y) PASTE(x, y)
Line
Count
Source
8
690
#define PASTE(x, y) x ## y
54
690
    const auto tx_and_status{GetSendStatusByNode(nodeid)};
55
690
    if (tx_and_status.has_value()) {
56
690
        return tx_and_status.value().tx;
57
690
    }
58
0
    return std::nullopt;
59
690
}
60
61
void PrivateBroadcast::NodeConfirmedReception(const NodeId& nodeid)
62
    EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
63
1
{
64
1
    LOCK(m_mutex);
Line
Count
Source
268
1
#define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__)
Line
Count
Source
11
1
#define UNIQUE_NAME(name) PASTE2(name, __COUNTER__)
Line
Count
Source
9
1
#define PASTE2(x, y) PASTE(x, y)
Line
Count
Source
8
1
#define PASTE(x, y) x ## y
65
1
    const auto tx_and_status{GetSendStatusByNode(nodeid)};
66
1
    if (tx_and_status.has_value()) {
67
1
        tx_and_status.value().send_status.confirmed = NodeClock::now();
68
1
    }
69
1
}
70
71
bool PrivateBroadcast::DidNodeConfirmReception(const NodeId& nodeid)
72
    EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
73
2.66k
{
74
2.66k
    LOCK(m_mutex);
Line
Count
Source
268
2.66k
#define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__)
Line
Count
Source
11
2.66k
#define UNIQUE_NAME(name) PASTE2(name, __COUNTER__)
Line
Count
Source
9
2.66k
#define PASTE2(x, y) PASTE(x, y)
Line
Count
Source
8
2.66k
#define PASTE(x, y) x ## y
75
2.66k
    const auto tx_and_status{GetSendStatusByNode(nodeid)};
76
2.66k
    if (tx_and_status.has_value()) {
77
251
        return tx_and_status.value().send_status.confirmed.has_value();
78
251
    }
79
2.41k
    return false;
80
2.66k
}
81
82
bool PrivateBroadcast::HavePendingTransactions()
83
    EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
84
2.66k
{
85
2.66k
    LOCK(m_mutex);
Line
Count
Source
268
2.66k
#define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__)
Line
Count
Source
11
2.66k
#define UNIQUE_NAME(name) PASTE2(name, __COUNTER__)
Line
Count
Source
9
2.66k
#define PASTE2(x, y) PASTE(x, y)
Line
Count
Source
8
2.66k
#define PASTE(x, y) x ## y
86
2.66k
    return !m_transactions.empty();
87
2.66k
}
88
89
std::vector<CTransactionRef> PrivateBroadcast::GetStale() const
90
    EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
91
0
{
92
0
    LOCK(m_mutex);
Line
Count
Source
268
0
#define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__)
Line
Count
Source
11
0
#define UNIQUE_NAME(name) PASTE2(name, __COUNTER__)
Line
Count
Source
9
0
#define PASTE2(x, y) PASTE(x, y)
Line
Count
Source
8
0
#define PASTE(x, y) x ## y
93
0
    const auto now{NodeClock::now()};
94
0
    std::vector<CTransactionRef> stale;
95
0
    for (const auto& [tx, state] : m_transactions) {
96
0
        const Priority p{DerivePriority(state.send_statuses)};
97
0
        if (p.num_confirmed == 0) {
98
0
            if (state.time_added < now - INITIAL_STALE_DURATION) stale.push_back(tx);
99
0
        } else {
100
0
            if (p.last_confirmed < now - STALE_DURATION) stale.push_back(tx);
101
0
        }
102
0
    }
103
0
    return stale;
104
0
}
105
106
std::vector<PrivateBroadcast::TxBroadcastInfo> PrivateBroadcast::GetBroadcastInfo() const
107
    EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
108
0
{
109
0
    LOCK(m_mutex);
Line
Count
Source
268
0
#define LOCK(cs) UniqueLock UNIQUE_NAME(criticalblock)(MaybeCheckNotHeld(cs), #cs, __FILE__, __LINE__)
Line
Count
Source
11
0
#define UNIQUE_NAME(name) PASTE2(name, __COUNTER__)
Line
Count
Source
9
0
#define PASTE2(x, y) PASTE(x, y)
Line
Count
Source
8
0
#define PASTE(x, y) x ## y
110
0
    std::vector<TxBroadcastInfo> entries;
111
0
    entries.reserve(m_transactions.size());
112
113
0
    for (const auto& [tx, state] : m_transactions) {
114
0
        std::vector<PeerSendInfo> peers;
115
0
        peers.reserve(state.send_statuses.size());
116
0
        for (const auto& status : state.send_statuses) {
117
0
            peers.emplace_back(PeerSendInfo{.address = status.address, .sent = status.picked, .received = status.confirmed});
118
0
        }
119
0
        entries.emplace_back(TxBroadcastInfo{.tx = tx, .time_added = state.time_added, .peers = std::move(peers)});
120
0
    }
121
122
0
    return entries;
123
0
}
124
125
PrivateBroadcast::Priority PrivateBroadcast::DerivePriority(const std::vector<SendStatus>& sent_to)
126
86
{
127
86
    Priority p;
128
86
    p.num_picked = sent_to.size();
129
86
    for (const auto& send_status : sent_to) {
130
1
        p.last_picked = std::max(p.last_picked, send_status.picked);
131
1
        if (send_status.confirmed.has_value()) {
132
0
            ++p.num_confirmed;
133
0
            p.last_confirmed = std::max(p.last_confirmed, send_status.confirmed.value());
134
0
        }
135
1
    }
136
86
    return p;
137
86
}
138
139
std::optional<PrivateBroadcast::TxAndSendStatusForNode> PrivateBroadcast::GetSendStatusByNode(const NodeId& nodeid)
140
    EXCLUSIVE_LOCKS_REQUIRED(m_mutex)
141
3.35k
{
142
3.35k
    AssertLockHeld(m_mutex);
Line
Count
Source
144
3.35k
#define AssertLockHeld(cs) AssertLockHeldInternal(#cs, __FILE__, __LINE__, &cs)
143
5.33k
    for (auto& [tx, state] : m_transactions) {
144
5.33k
        for (auto& send_status : state.send_statuses) {
145
963
            if (send_status.nodeid == nodeid) {
146
942
                return TxAndSendStatusForNode{.tx = tx, .send_status = send_status};
147
942
            }
148
963
        }
149
5.33k
    }
150
2.41k
    return std::nullopt;
151
3.35k
}