Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2020-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.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>12#include <algorithm>13#include <cassert>14#include <cstdint>15#include <optional>16#include <vector>18FUZZ_TARGET(node_eviction)19{20FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};21std::vector<NodeEvictionCandidate> eviction_candidates;22LIMITED_WHILE (fuzzed_data_provider.ConsumeBool(), 10000) {23eviction_candidates.push_back({24/*id=*/fuzzed_data_provider.ConsumeIntegral<NodeId>(),25/*m_connected=*/ConsumeTime(fuzzed_data_provider),26/*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/*m_last_block_time=*/ConsumeTime(fuzzed_data_provider).time_since_epoch(),28/*m_last_tx_time=*/ConsumeTime(fuzzed_data_provider).time_since_epoch(),29/*fRelevantServices=*/fuzzed_data_provider.ConsumeBool(),30/*m_relay_txs=*/fuzzed_data_provider.ConsumeBool(),31/*fBloomFilter=*/fuzzed_data_provider.ConsumeBool(),32/*nKeyedNetGroup=*/fuzzed_data_provider.ConsumeIntegral<uint64_t>(),33/*prefer_evict=*/fuzzed_data_provider.ConsumeBool(),34/*m_is_local=*/fuzzed_data_provider.ConsumeBool(),35/*m_network=*/fuzzed_data_provider.PickValueInArray(ALL_NETWORKS),36/*m_noban=*/fuzzed_data_provider.ConsumeBool(),37/*m_conn_type=*/fuzzed_data_provider.PickValueInArray(ALL_CONNECTION_TYPES),38});39}40// Make a copy since eviction_candidates may be in some valid but otherwise41// indeterminate state after the SelectNodeToEvict(&&) call.42const std::vector<NodeEvictionCandidate> eviction_candidates_copy = eviction_candidates;43const std::optional<NodeId> node_to_evict = SelectNodeToEvict(std::move(eviction_candidates));44if (node_to_evict) {45assert(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; }));46}47}
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.