Changeset View
Changeset View
Standalone View
Standalone View
src/test/net_tests.cpp
Show First 20 Lines • Show All 775 Lines • ▼ Show 20 Lines | for (int id = 0; id < n_candidates; ++id) { | ||||
candidates.push_back({ | candidates.push_back({ | ||||
/* id */ id, | /* id */ id, | ||||
/* nTimeConnected */ | /* nTimeConnected */ | ||||
static_cast<int64_t>(random_context.randrange(100)), | static_cast<int64_t>(random_context.randrange(100)), | ||||
/* nMinPingUsecTime */ | /* nMinPingUsecTime */ | ||||
static_cast<int64_t>(random_context.randrange(100)), | static_cast<int64_t>(random_context.randrange(100)), | ||||
/* nLastBlockTime */ | /* nLastBlockTime */ | ||||
static_cast<int64_t>(random_context.randrange(100)), | static_cast<int64_t>(random_context.randrange(100)), | ||||
/* nLastProofTime */ | |||||
static_cast<int64_t>(random_context.randrange(100)), | |||||
/* nLastTXTime */ | /* nLastTXTime */ | ||||
static_cast<int64_t>(random_context.randrange(100)), | static_cast<int64_t>(random_context.randrange(100)), | ||||
/* fRelevantServices */ random_context.randbool(), | /* fRelevantServices */ random_context.randbool(), | ||||
/* fRelayTxes */ random_context.randbool(), | /* fRelayTxes */ random_context.randbool(), | ||||
/* fBloomFilter */ random_context.randbool(), | /* fBloomFilter */ random_context.randbool(), | ||||
/* nKeyedNetGroup */ random_context.randrange(100), | /* nKeyedNetGroup */ random_context.randrange(100), | ||||
/* prefer_evict */ random_context.randbool(), | /* prefer_evict */ random_context.randbool(), | ||||
/* m_is_local */ random_context.randbool(), | /* m_is_local */ random_context.randbool(), | ||||
▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | for (int i = 0; i < NODE_EVICTION_TEST_ROUNDS; ++i) { | ||||
// into our mempool should be protected from eviction. | // into our mempool should be protected from eviction. | ||||
BOOST_CHECK(!IsEvicted( | BOOST_CHECK(!IsEvicted( | ||||
number_of_nodes, | number_of_nodes, | ||||
[number_of_nodes](NodeEvictionCandidate &candidate) { | [number_of_nodes](NodeEvictionCandidate &candidate) { | ||||
candidate.nLastTXTime = number_of_nodes - candidate.id; | candidate.nLastTXTime = number_of_nodes - candidate.id; | ||||
}, | }, | ||||
{0, 1, 2, 3}, random_context)); | {0, 1, 2, 3}, random_context)); | ||||
// Four nodes that most recently sent us novel proofs accepted | |||||
// into our proof pool should be protected from eviction. | |||||
BOOST_CHECK(!IsEvicted( | |||||
number_of_nodes, | |||||
[number_of_nodes](NodeEvictionCandidate &candidate) { | |||||
candidate.nLastProofTime = number_of_nodes - candidate.id; | |||||
}, | |||||
{0, 1, 2, 3}, random_context)); | |||||
// Up to eight non-tx-relay peers that most recently sent us novel | // Up to eight non-tx-relay peers that most recently sent us novel | ||||
// blocks should be protected from eviction. | // blocks should be protected from eviction. | ||||
BOOST_CHECK(!IsEvicted( | BOOST_CHECK(!IsEvicted( | ||||
number_of_nodes, | number_of_nodes, | ||||
[number_of_nodes](NodeEvictionCandidate &candidate) { | [number_of_nodes](NodeEvictionCandidate &candidate) { | ||||
candidate.nLastBlockTime = number_of_nodes - candidate.id; | candidate.nLastBlockTime = number_of_nodes - candidate.id; | ||||
if (candidate.id <= 7) { | if (candidate.id <= 7) { | ||||
candidate.fRelayTxes = false; | candidate.fRelayTxes = false; | ||||
Show All 34 Lines | for (int i = 0; i < NODE_EVICTION_TEST_ROUNDS; ++i) { | ||||
number_of_nodes - candidate.id; // 4 protected | number_of_nodes - candidate.id; // 4 protected | ||||
candidate.nLastBlockTime = | candidate.nLastBlockTime = | ||||
number_of_nodes - candidate.id; // 4 protected | number_of_nodes - candidate.id; // 4 protected | ||||
}, | }, | ||||
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, | {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, | ||||
10, 11, 12, 13, 14, 15, 16, 17, 18, 19}, | 10, 11, 12, 13, 14, 15, 16, 17, 18, 19}, | ||||
random_context)); | random_context)); | ||||
// An eviction is expected given >= 29 random eviction candidates. | // An eviction is expected given >= 33 random eviction candidates. | ||||
// The eviction logic protects at most four peers by net group, | // The eviction logic protects at most four peers by net group, | ||||
// eight by lowest ping time, four by last time of novel tx, up to | // eight by lowest ping time, four by last time of novel tx, four by | ||||
// eight non-tx-relay peers by last novel block time, and four more | // last time of novel proof, up to eight non-tx-relay peers by last | ||||
// peers by last novel block time. | // novel block time, and four more peers by last novel block time. | ||||
if (number_of_nodes >= 29) { | if (number_of_nodes >= 33) { | ||||
BOOST_CHECK(SelectNodeToEvict(GetRandomNodeEvictionCandidates( | BOOST_CHECK(SelectNodeToEvict(GetRandomNodeEvictionCandidates( | ||||
number_of_nodes, random_context))); | number_of_nodes, random_context))); | ||||
} | } | ||||
// No eviction is expected given <= 20 random eviction candidates. | // No eviction is expected given <= 24 random eviction candidates. | ||||
// The eviction logic protects at least four peers by net group, | // The eviction logic protects at least four peers by net group, | ||||
// eight by lowest ping time, four by last time of novel tx and four | // eight by lowest ping time, four by last time of novel tx, four by | ||||
// peers by last novel block time. | // last time of novel proof, four peers by last novel block time. | ||||
if (number_of_nodes <= 20) { | if (number_of_nodes <= 24) { | ||||
BOOST_CHECK(!SelectNodeToEvict(GetRandomNodeEvictionCandidates( | BOOST_CHECK(!SelectNodeToEvict(GetRandomNodeEvictionCandidates( | ||||
number_of_nodes, random_context))); | number_of_nodes, random_context))); | ||||
} | } | ||||
// Cases left to test: | // Cases left to test: | ||||
// * "Protect the half of the remaining nodes which have been | // * "Protect the half of the remaining nodes which have been | ||||
// connected the longest. [...]" | // connected the longest. [...]" | ||||
// * "Pick out up to 1/4 peers that are localhost, sorted by longest | // * "Pick out up to 1/4 peers that are localhost, sorted by longest | ||||
Show All 10 Lines |