| 16 | #include <vector> |
| 17 | |
| 18 | FUZZ_TARGET(node_eviction) |
| 19 | { |
| 20 | FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()}; |
| 21 | std::vector<NodeEvictionCandidate> eviction_candidates; |
| 22 | LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) |
| 23 | { |
| 24 | eviction_candidates.push_back({ |
| 25 | /*id=*/fuzzed_data_provider.ConsumeIntegral<NodeId>(), |
| 26 | /*m_connected=*/ConsumeTime(fuzzed_data_provider), |
| 27 | /*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 | /*m_last_block_time=*/ConsumeTime(fuzzed_data_provider).time_since_epoch(), |
| 29 | /*m_last_tx_time=*/ConsumeTime(fuzzed_data_provider).time_since_epoch(), |
| 30 | /*fRelevantServices=*/fuzzed_data_provider.ConsumeBool(), |
| 31 | /*m_relay_txs=*/fuzzed_data_provider.ConsumeBool(), |
| 32 | /*fBloomFilter=*/fuzzed_data_provider.ConsumeBool(), |
| 33 | /*nKeyedNetGroup=*/fuzzed_data_provider.ConsumeIntegral<uint64_t>(), |
| 34 | /*prefer_evict=*/fuzzed_data_provider.ConsumeBool(), |
| 35 | /*m_is_local=*/fuzzed_data_provider.ConsumeBool(), |
| 36 | /*m_network=*/fuzzed_data_provider.PickValueInArray(ALL_NETWORKS), |
| 37 | /*m_noban=*/fuzzed_data_provider.ConsumeBool(), |
| 38 | /*m_conn_type=*/fuzzed_data_provider.PickValueInArray(ALL_CONNECTION_TYPES), |
| 39 | }); |
| 40 | } |
| 41 | // Make a copy since eviction_candidates may be in some valid but otherwise |
| 42 | // indeterminate state after the SelectNodeToEvict(&&) call. |
| 43 | const std::vector<NodeEvictionCandidate> eviction_candidates_copy = eviction_candidates; |
| 44 | const std::optional<NodeId> node_to_evict = SelectNodeToEvict(std::move(eviction_candidates)); |
| 45 | if (node_to_evict) { |
| 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; })); |
| 47 | } |
| 48 | } |
nothing calls this directly
no test coverage detected