Coverage Report

Created: 2026-08-25 19:22

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
856
{
20
856
    FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
21
856
    std::vector<NodeEvictionCandidate> eviction_candidates;
22
488k
    LIMITED_WHILE (fuzzed_data_provider.ConsumeBool(), 10000) {
23
488k
        eviction_candidates.push_back({
24
488k
            /*id=*/fuzzed_data_provider.ConsumeIntegral<NodeId>(),
25
488k
            /*m_connected=*/ConsumeTime(fuzzed_data_provider),
26
488k
            /*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()),
27
488k
            /*m_last_block_time=*/ConsumeTime(fuzzed_data_provider).time_since_epoch(),
28
488k
            /*m_last_tx_time=*/ConsumeTime(fuzzed_data_provider).time_since_epoch(),
29
488k
            /*fRelevantServices=*/fuzzed_data_provider.ConsumeBool(),
30
488k
            /*m_relay_txs=*/fuzzed_data_provider.ConsumeBool(),
31
488k
            /*fBloomFilter=*/fuzzed_data_provider.ConsumeBool(),
32
488k
            /*nKeyedNetGroup=*/fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
33
488k
            /*prefer_evict=*/fuzzed_data_provider.ConsumeBool(),
34
488k
            /*m_is_local=*/fuzzed_data_provider.ConsumeBool(),
35
488k
            /*m_network=*/fuzzed_data_provider.PickValueInArray(ALL_NETWORKS),
36
488k
            /*m_noban=*/fuzzed_data_provider.ConsumeBool(),
37
488k
            /*m_conn_type=*/fuzzed_data_provider.PickValueInArray(ALL_CONNECTION_TYPES),
38
488k
        });
39
488k
    }
40
    // Make a copy since eviction_candidates may be in some valid but otherwise
41
    // indeterminate state after the SelectNodeToEvict(&&) call.
42
856
    const std::vector<NodeEvictionCandidate> eviction_candidates_copy = eviction_candidates;
43
856
    const std::optional<NodeId> node_to_evict = SelectNodeToEvict(std::move(eviction_candidates));
44
856
    if (node_to_evict) {
  Branch (44:9): [True: 552, False: 304]
45
        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 (45:9): [True: 552, False: 0]
46
552
    }
47
856
}