Coverage Report

Created: 2026-06-09 19:51

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/bitcoin/src/test/fuzz/node_eviction.cpp
Line
Count
Source
1
// Copyright (c) 2020-present The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#include <net.h>
6
#include <protocol.h>
7
#include <test/fuzz/FuzzedDataProvider.h>
8
#include <test/fuzz/fuzz.h>
9
#include <test/fuzz/util.h>
10
#include <test/fuzz/util/net.h>
11
12
#include <algorithm>
13
#include <cassert>
14
#include <cstdint>
15
#include <optional>
16
#include <vector>
17
18
FUZZ_TARGET(node_eviction)
19
0
{
20
0
    FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
21
0
    std::vector<NodeEvictionCandidate> eviction_candidates;
22
0
    LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000)
23
0
    {
24
0
        eviction_candidates.push_back({
25
0
            /*id=*/fuzzed_data_provider.ConsumeIntegral<NodeId>(),
26
0
            /*m_connected=*/ConsumeTime(fuzzed_data_provider),
27
0
            /*m_min_ping_time=*/ConsumeDuration<decltype(NodeEvictionCandidate::m_min_ping_time)>(fuzzed_data_provider, /*min=*/std::chrono::years{-1}, /*max=*/decltype(CNode::m_min_ping_time.load())::max()),
28
0
            /*m_last_block_time=*/ConsumeTime(fuzzed_data_provider).time_since_epoch(),
29
0
            /*m_last_tx_time=*/ConsumeTime(fuzzed_data_provider).time_since_epoch(),
30
0
            /*fRelevantServices=*/fuzzed_data_provider.ConsumeBool(),
31
0
            /*m_relay_txs=*/fuzzed_data_provider.ConsumeBool(),
32
0
            /*fBloomFilter=*/fuzzed_data_provider.ConsumeBool(),
33
0
            /*nKeyedNetGroup=*/fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
34
0
            /*prefer_evict=*/fuzzed_data_provider.ConsumeBool(),
35
0
            /*m_is_local=*/fuzzed_data_provider.ConsumeBool(),
36
0
            /*m_network=*/fuzzed_data_provider.PickValueInArray(ALL_NETWORKS),
37
0
            /*m_noban=*/fuzzed_data_provider.ConsumeBool(),
38
0
            /*m_conn_type=*/fuzzed_data_provider.PickValueInArray(ALL_CONNECTION_TYPES),
39
0
        });
40
0
    }
41
    // Make a copy since eviction_candidates may be in some valid but otherwise
42
    // indeterminate state after the SelectNodeToEvict(&&) call.
43
0
    const std::vector<NodeEvictionCandidate> eviction_candidates_copy = eviction_candidates;
44
0
    const std::optional<NodeId> node_to_evict = SelectNodeToEvict(std::move(eviction_candidates));
45
0
    if (node_to_evict) {
  Branch (45:9): [True: 0, False: 0]
46
        assert(std::any_of(eviction_candidates_copy.begin(), eviction_candidates_copy.end(), [&node_to_evict](const NodeEvictionCandidate& eviction_candidate) { return *node_to_evict == eviction_candidate.id; }));
  Branch (46:9): [True: 0, False: 0]
47
0
    }
48
0
}