2021-12-30 19:36:57 +02:00
|
|
|
// Copyright (c) 2020-2021 The Bitcoin Core developers
|
2020-09-18 13:47:00 +00:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include <net.h>
|
|
|
|
#include <protocol.h>
|
|
|
|
#include <test/fuzz/FuzzedDataProvider.h>
|
|
|
|
#include <test/fuzz/fuzz.h>
|
|
|
|
#include <test/fuzz/util.h>
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <optional>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
FUZZ_TARGET(node_eviction)
|
|
|
|
{
|
|
|
|
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
|
|
|
std::vector<NodeEvictionCandidate> eviction_candidates;
|
2021-10-25 19:48:22 +00:00
|
|
|
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
|
2020-09-18 13:47:00 +00:00
|
|
|
eviction_candidates.push_back({
|
2021-09-14 16:56:34 +02:00
|
|
|
/*id=*/fuzzed_data_provider.ConsumeIntegral<NodeId>(),
|
2021-12-13 12:32:28 +01:00
|
|
|
/*m_connected=*/std::chrono::seconds{fuzzed_data_provider.ConsumeIntegral<int64_t>()},
|
2021-09-14 16:56:34 +02:00
|
|
|
/*m_min_ping_time=*/std::chrono::microseconds{fuzzed_data_provider.ConsumeIntegral<int64_t>()},
|
2021-12-13 12:32:28 +01:00
|
|
|
/*m_last_block_time=*/std::chrono::seconds{fuzzed_data_provider.ConsumeIntegral<int64_t>()},
|
|
|
|
/*m_last_tx_time=*/std::chrono::seconds{fuzzed_data_provider.ConsumeIntegral<int64_t>()},
|
2021-09-14 16:56:34 +02:00
|
|
|
/*fRelevantServices=*/fuzzed_data_provider.ConsumeBool(),
|
|
|
|
/*fRelayTxes=*/fuzzed_data_provider.ConsumeBool(),
|
|
|
|
/*fBloomFilter=*/fuzzed_data_provider.ConsumeBool(),
|
|
|
|
/*nKeyedNetGroup=*/fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
|
|
|
|
/*prefer_evict=*/fuzzed_data_provider.ConsumeBool(),
|
|
|
|
/*m_is_local=*/fuzzed_data_provider.ConsumeBool(),
|
|
|
|
/*m_network=*/fuzzed_data_provider.PickValueInArray(ALL_NETWORKS),
|
2020-09-18 13:47:00 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
// Make a copy since eviction_candidates may be in some valid but otherwise
|
|
|
|
// indeterminate state after the SelectNodeToEvict(&&) call.
|
|
|
|
const std::vector<NodeEvictionCandidate> eviction_candidates_copy = eviction_candidates;
|
2021-03-15 10:41:30 +08:00
|
|
|
const std::optional<NodeId> node_to_evict = SelectNodeToEvict(std::move(eviction_candidates));
|
2020-09-18 13:47:00 +00:00
|
|
|
if (node_to_evict) {
|
|
|
|
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; }));
|
|
|
|
}
|
|
|
|
}
|