Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
test
fuzz
node_eviction.cpp
Go to the documentation of this file.
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
{
20
FuzzedDataProvider
fuzzed_data_provider{buffer.data(), buffer.size()};
21
std::vector<NodeEvictionCandidate> eviction_candidates;
22
LIMITED_WHILE
(fuzzed_data_provider.
ConsumeBool
(), 10000) {
23
eviction_candidates.push_back({
24
/*id=*/
fuzzed_data_provider.
ConsumeIntegral
<
NodeId
>(),
25
/*m_connected=*/
std::chrono::seconds{fuzzed_data_provider.
ConsumeIntegral
<int64_t>()},
26
/*m_min_ping_time=*/
std::chrono::microseconds{fuzzed_data_provider.
ConsumeIntegral
<int64_t>()},
27
/*m_last_block_time=*/
std::chrono::seconds{fuzzed_data_provider.
ConsumeIntegral
<int64_t>()},
28
/*m_last_tx_time=*/
std::chrono::seconds{fuzzed_data_provider.
ConsumeIntegral
<int64_t>()},
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 otherwise
41
// indeterminate state after the SelectNodeToEvict(&&) call.
42
const
std::vector<NodeEvictionCandidate> eviction_candidates_copy = eviction_candidates;
43
const
std::optional<NodeId> node_to_evict =
SelectNodeToEvict
(std::move(eviction_candidates));
44
if
(node_to_evict) {
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; }));
46
}
47
}
FuzzedDataProvider.h
FuzzedDataProvider
Definition
FuzzedDataProvider.h:32
FuzzedDataProvider::ConsumeBool
bool ConsumeBool()
Definition
FuzzedDataProvider.h:289
FuzzedDataProvider::PickValueInArray
T PickValueInArray(const T(&array)[size])
Definition
FuzzedDataProvider.h:304
FuzzedDataProvider::ConsumeIntegral
T ConsumeIntegral()
Definition
FuzzedDataProvider.h:195
SelectNodeToEvict
std::optional< NodeId > SelectNodeToEvict(std::vector< NodeEvictionCandidate > &&vEvictionCandidates)
Select an inbound peer to evict after filtering out (protecting) peers having distinct,...
Definition
eviction.cpp:178
fuzz.h
FUZZ_TARGET
#define FUZZ_TARGET(...)
Definition
fuzz.h:35
LIMITED_WHILE
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
Definition
fuzz.h:22
NodeId
int64_t NodeId
Definition
net.h:103
NodeEvictionCandidate
Definition
eviction.h:18
net.h
util.h
net.h
ALL_CONNECTION_TYPES
constexpr ConnectionType ALL_CONNECTION_TYPES[]
Definition
net.h:143
ALL_NETWORKS
constexpr auto ALL_NETWORKS
Definition
net.h:153
assert
assert(!tx.IsCoinBase())
Generated on
for Bitcoin Core by
1.17.0