21#include <validation.h>
23#include <test/util/blockindex.h>
24#include <test/util/random.h>
25#include <test/util/setup_common.h>
27#include <boost/test/unit_test.hpp>
31#include <unordered_map>
37 struct TestPeerManager {
41 return node.peerid == peerid;
46 auto &pendingNodesView = pm.
pendingNodes.get<by_nodeid>();
47 return pendingNodesView.find(nodeid) != pendingNodesView.end();
52 auto &pview = pm.
peers.get<by_proofid>();
53 auto it = pview.find(proofid);
54 return it == pview.end() ?
NO_PEER : it->peerid;
60 return getPeerIdForProofId(pm, proof->
getId());
63 static std::vector<uint32_t> getOrderedScores(
const PeerManager &pm) {
64 std::vector<uint32_t> scores;
66 auto &peerView = pm.
peers.get<by_score>();
67 for (
const Peer &peer : peerView) {
68 scores.push_back(peer.getScore());
74 static void cleanupDanglingProofs(
76 std::unordered_set<ProofRef, SaltedProofHasher> ®isteredProofs) {
80 static void cleanupDanglingProofs(
PeerManager &pm) {
81 std::unordered_set<ProofRef, SaltedProofHasher> dummy;
87 ProofPool::AddProofStatus::SUCCEED;
90 static std::optional<RemoteProof> getRemoteProof(
const PeerManager &pm,
93 auto it = pm.
remoteProofs.find(boost::make_tuple(proofid, nodeid));
97 return std::make_optional(*it);
100 static size_t getPeerCount(
const PeerManager &pm) {
101 return pm.
peers.size();
104 static std::optional<bool>
110 std::vector<PeerId> peerIds;
111 for (
auto &peer : pm.
peers) {
112 peerIds.push_back(peer.peerid);
114 for (
const PeerId &peerid : peerIds) {
136 uint32_t height = 100,
bool is_coinbase =
false) {
145 static COutPoint createUtxo(
Chainstate &chainstate,
const CKey &key,
147 uint32_t height = 100,
148 bool is_coinbase =
false) {
150 addCoin(chainstate, outpoint, key, amount, height, is_coinbase);
155 buildProof(
const CKey &key,
156 const std::vector<std::tuple<COutPoint, Amount>> &outpoints,
158 int64_t sequence = 1, uint32_t height = 100,
159 bool is_coinbase =
false, int64_t expirationTime = 0,
161 ProofBuilder pb(sequence, expirationTime, master, payoutScript);
162 for (
const auto &[outpoint, amount] : outpoints) {
163 BOOST_CHECK(pb.addUTXO(outpoint, amount, height, is_coinbase, key));
168 template <
typename... Args>
170 buildProofWithOutpoints(
const CKey &key,
171 const std::vector<COutPoint> &outpoints,
172 Amount amount, Args &&...args) {
173 std::vector<std::tuple<COutPoint, Amount>> outpointsWithAmount;
175 outpoints.begin(), outpoints.end(),
176 std::back_inserter(outpointsWithAmount),
177 [amount](
const auto &o) { return std::make_tuple(o, amount); });
178 return buildProof(key, outpointsWithAmount,
179 std::forward<Args>(args)...);
183 buildProofWithSequence(
const CKey &key,
184 const std::vector<COutPoint> &outpoints,
193struct PeerManagerFixture :
public TestChain100Setup {
194 PeerManagerFixture() {
197 ~PeerManagerFixture() {
204struct NoCoolDownFixture :
public PeerManagerFixture {
205 NoCoolDownFixture() {
208 ~NoCoolDownFixture() {
214BOOST_FIXTURE_TEST_SUITE(peermanager_tests, PeerManagerFixture)
222 const std::vector<Slot> oneslot = {{100, 100, 23}};
240 const std::vector<Slot> twoslots = {{100, 100, 69}, {300, 100, 42}};
269 std::vector<Slot> slots;
273 for (
int i = 0; i < 100; i++) {
274 slots.emplace_back(max, 1, i);
281 for (
int i = 0; i < 100; i++) {
289 slots[99] = slots[99].withScore(101);
290 max = slots[99].getStop();
293 for (
int i = 0; i < 100; i++) {
304 for (
int i = 0; i < 100; i++) {
305 slots[i] = slots[i].withStart(slots[i].getStart() + 100);
308 slots[0] =
Slot(1, slots[0].getStop() - 1, slots[0].getPeerId());
309 slots[99] = slots[99].withScore(1);
310 max = slots[99].getStop();
317 for (
int i = 0; i < 100; i++) {
324 for (
int c = 0; c < 1000; c++) {
325 size_t size = m_rng.randbits(10) + 1;
326 std::vector<Slot> slots;
329 uint64_t max = m_rng.randbits(3);
332 max += m_rng.randbits(3);
336 for (
size_t i = 0; i < size; i++) {
337 const uint64_t start = next();
338 const uint32_t score = m_rng.randbits(3);
340 slots.emplace_back(start, score, i);
343 for (
int k = 0; k < 100; k++) {
344 uint64_t s = max > 0 ? m_rng.randrange(max) : 0;
368 const NodeId node0 = 42, node1 = 69, node2 = 37;
378 std::unordered_map<PeerId, int> results = {};
379 for (
int i = 0; i < 10000; i++) {
385 BOOST_CHECK(abs(2 * results[0] - results[1]) < 500);
391 for (
int i = 0; i < 10000; i++) {
393 BOOST_CHECK(n == node0 || n == node1 || n == node2);
397 BOOST_CHECK(abs(results[0] - results[1] + results[2]) < 500);
408 std::array<PeerId, 8> peerids;
409 for (
int i = 0; i < 4; i++) {
411 peerids[i] = TestPeerManager::registerAndGetPeerId(pm, p);
419 for (
int i = 0; i < 100; i++) {
421 BOOST_CHECK(p == peerids[0] || p == peerids[1] || p == peerids[2] ||
436 for (
int i = 0; i < 100; i++) {
438 BOOST_CHECK(p == peerids[0] || p == peerids[1] || p == peerids[3]);
442 for (
int i = 0; i < 4; i++) {
444 peerids[i + 4] = TestPeerManager::registerAndGetPeerId(pm, p);
467 for (
int i = 0; i < 100; i++) {
469 BOOST_CHECK(p == peerids[1] || p == peerids[3] || p == peerids[4] ||
470 p == peerids[5] || p == peerids[6]);
485 std::array<PeerId, 4> peerids;
486 for (
int i = 0; i < 4; i++) {
489 peerids[i] = TestPeerManager::registerAndGetPeerId(pm, p);
495 for (
auto p : peerids) {
502 for (
int i = 0; i < 100; i++) {
517 const std::array<uint32_t, 4> scores{{10000, 20000, 30000, 40000}};
518 std::array<PeerId, 4> peerids;
519 for (
int i = 0; i < 4; i++) {
521 peerids[i] = TestPeerManager::registerAndGetPeerId(pm, p);
545 for (uint64_t slot = 0; slot < pm.
getSlotCount(); slot++) {
546 PeerId p = TestPeerManager::selectPeerFromSlot(pm, slot);
549 }
else if (slot < 40000) {
571 for (
int i = 0; i < 4; i++) {
576 for (
int i = 0; i < 100; i++) {
580 n, Now<SteadyMilliseconds>(), round++));
586 for (
int i = 0; i < 100; i++) {
590 n, Now<SteadyMilliseconds>(), round++));
595 1, Now<SteadyMilliseconds>() + std::chrono::hours(24), round++));
597 for (
int i = 0; i < 100; i++) {
601 n, Now<SteadyMilliseconds>(), round++));
608 int node3selected = 0;
609 for (
int i = 0; i < 100; i++) {
618 n, Now<SteadyMilliseconds>(), round++));
622 for (
int i = 0; i < 100; i++) {
649 for (
int i = 0; i < 10; i++) {
652 BOOST_CHECK(TestPeerManager::isNodePending(pm, i));
658 const PeerId peerid = TestPeerManager::registerAndGetPeerId(pm, proof);
659 BOOST_CHECK_NE(peerid,
NO_PEER);
660 for (
int i = 0; i < 10; i++) {
661 BOOST_CHECK(!TestPeerManager::isNodePending(pm, i));
662 BOOST_CHECK(TestPeerManager::nodeBelongToPeer(pm, i, peerid));
669 for (
int i = 0; i < 5; i++) {
671 BOOST_CHECK(!TestPeerManager::isNodePending(pm, i));
672 BOOST_CHECK(!TestPeerManager::nodeBelongToPeer(pm, i, peerid));
678 for (
int i = 0; i < 5; i++) {
680 BOOST_CHECK(!TestPeerManager::isNodePending(pm, i));
681 BOOST_CHECK(TestPeerManager::nodeBelongToPeer(pm, i, peerid));
687 const ProofId &alt_proofid = alt_proof->getId();
690 for (
int i = 0; i < 5; i++) {
693 BOOST_CHECK(TestPeerManager::isNodePending(pm, i));
694 BOOST_CHECK(!TestPeerManager::nodeBelongToPeer(pm, i, peerid));
701 const ProofId &alt2_proofid = alt2_proof->getId();
704 for (
int i = 0; i < 5; i++) {
707 BOOST_CHECK(TestPeerManager::isNodePending(pm, i));
713 for (
int i = 0; i < 5; i++) {
715 BOOST_CHECK(!TestPeerManager::isNodePending(pm, i));
716 BOOST_CHECK(TestPeerManager::nodeBelongToPeer(pm, i, peerid));
724 for (
int i = 0; i < 10; i++) {
725 BOOST_CHECK(TestPeerManager::isNodePending(pm, i));
726 BOOST_CHECK(!TestPeerManager::nodeBelongToPeer(pm, i, peerid));
733 for (
int i = 0; i < 10; i++) {
735 BOOST_CHECK(!TestPeerManager::isNodePending(pm, i));
736 BOOST_CHECK(!TestPeerManager::nodeBelongToPeer(pm, i, peerid));
752 PeerId peerid = TestPeerManager::registerAndGetPeerId(pm, proof);
753 BOOST_CHECK_NE(peerid,
NO_PEER);
757 for (
int i = 0; i < 10; i++) {
759 BOOST_CHECK(!TestPeerManager::isNodePending(pm, i));
760 BOOST_CHECK(TestPeerManager::nodeBelongToPeer(pm, i, peerid));
775 for (
int i = 0; i < 10; i++) {
776 BOOST_CHECK(TestPeerManager::isNodePending(pm, i));
777 BOOST_CHECK(!TestPeerManager::nodeBelongToPeer(pm, i, peerid));
797 peerid = TestPeerManager::registerAndGetPeerId(pm, proof);
798 BOOST_CHECK_NE(peerid,
NO_PEER);
799 for (
int i = 0; i < 10; i++) {
800 BOOST_CHECK(!TestPeerManager::isNodePending(pm, i));
801 BOOST_CHECK(TestPeerManager::nodeBelongToPeer(pm, i, peerid));
814 const int height = 100;
817 for (uint32_t i = 0; i < 10; i++) {
824 const auto getPeerId = [&](
const std::vector<COutPoint> &outpoints) {
825 return TestPeerManager::registerAndGetPeerId(
826 pm, buildProofWithOutpoints(key, outpoints, v, masterKey, 0, height,
831 const PeerId peer1 = getPeerId({COutPoint(txid1, 0)});
838 const PeerId peer2 = getPeerId({COutPoint(txid2, 0)});
842 const PeerId peer3 = getPeerId({COutPoint(txid1, 1)});
849 const PeerId peer4 = getPeerId({COutPoint(txid1, 2), COutPoint(txid2, 2)});
856 COutPoint o(txid1, 3);
859 !pm.
registerProof(TestProofBuilder::buildDuplicatedStakes(pb)));
881 int immatureHeight = 100;
883 auto registerImmature = [&](
const ProofRef &proof) {
889 auto checkImmature = [&](
const ProofRef &proof,
bool expectedImmature) {
906 std::vector<ProofRef> immatureProofs;
911 auto proof = buildProofWithOutpoints(
915 registerImmature(proof);
916 checkImmature(proof,
true);
917 immatureProofs.push_back(proof);
921 for (
auto i = 0; i < 100; i++) {
925 key, 0, immatureHeight);
928 registerImmature(proof);
929 checkImmature(proof,
true);
930 immatureProofs.push_back(proof);
932 immatureProofs.erase(immatureProofs.begin());
937 const COutPoint &outpoint =
938 immatureProofs.front()->getStakes()[0].getStake().getUTXO();
941 key, 1, immatureHeight);
942 registerImmature(proof);
943 checkImmature(proof,
true);
944 immatureProofs.push_back(proof);
946 immatureProofs.erase(immatureProofs.begin());
953 for (
const auto &proof : immatureProofs) {
954 checkImmature(proof,
false);
965 PeerId peerid = TestPeerManager::registerAndGetPeerId(pm, proof);
966 BOOST_CHECK_NE(peerid,
NO_PEER);
969 std::chrono::hours(24));
972 for (
int i = 0; i < 10; i++) {
982 for (
int i = 0; i < 10; i++) {
988 peerid = TestPeerManager::registerAndGetPeerId(pm, proof);
989 BOOST_CHECK_NE(peerid,
NO_PEER);
992 for (
int i = 0; i < 10; i++) {
996 i, [&](
const Node &n) { return n.nextRequestTime == theFuture; }));
1003 for (
int i = 0; i < 10; i++) {
1012 constexpr int numProofs = 10;
1014 std::vector<ProofRef> proofs;
1015 proofs.reserve(numProofs);
1016 for (
int i = 0; i < numProofs; i++) {
1021 for (
int i = 0; i < numProofs; i++) {
1029 ProofRegistrationResult::ALREADY_REGISTERED);
1032 for (
int added = 0; added <= i; added++) {
1033 auto proof = pm.
getProof(proofs[added]->getId());
1042 const std::string badProofHex(
1043 "96527eae083f1f24625f049d9e54bb9a21023beefdde700a6bc02036335b4df141c8b"
1044 "c67bb05a971f5ac2745fd683797dde3002321023beefdde700a6bc02036335b4df141"
1045 "c8bc67bb05a971f5ac2745fd683797dde3ac135da984db510334abe41134e3d4ef09a"
1046 "d006b1152be8bc413182bf6f947eac1f8580fe265a382195aa2d73935cabf86d90a8f"
1047 "666d0a62385ae24732eca51575");
1050 BOOST_CHECK(Proof::FromHex(*badProof, badProofHex, error));
1065 const COutPoint conflictingOutpoint = createUtxo(active_chainstate, key);
1066 const COutPoint outpointToSend = createUtxo(active_chainstate, key);
1069 buildProofWithSequence(key, {conflictingOutpoint, outpointToSend}, 20);
1073 buildProofWithSequence(key, {conflictingOutpoint}, 10);
1076 BOOST_CHECK(state.GetResult() == ProofRegistrationResult::CONFLICTING);
1098 const uint32_t height = 100;
1099 const bool is_coinbase =
false;
1105 auto conflictingOutpoint = createUtxo(active_chainstate, key, amount);
1107 auto proof_base = buildProofWithSequence(key, {conflictingOutpoint}, 10);
1110 auto checkPreferred = [&](
const ProofRef &candidate,
1111 const ProofRef &reference,
bool expectAccepted) {
1123 ProofRegistrationResult::CONFLICTING,
1137 checkPreferred(buildProofWithSequence(key, {conflictingOutpoint}, 9),
1140 checkPreferred(buildProofWithSequence(key, {conflictingOutpoint}, 11),
1143 auto buildProofFromAmounts = [&](
const CKey &master,
1144 std::vector<Amount> &&amounts) {
1145 std::vector<std::tuple<COutPoint, Amount>> outpointsWithAmount{
1146 {conflictingOutpoint, amount}};
1147 std::transform(amounts.begin(), amounts.end(),
1148 std::back_inserter(outpointsWithAmount),
1149 [&key, &active_chainstate](
const Amount amount) {
1150 return std::make_tuple(
1151 createUtxo(active_chainstate, key, amount),
1154 return buildProof(key, outpointsWithAmount, master, 0, height,
1158 auto proof_multiUtxo = buildProofFromAmounts(
1165 checkPreferred(buildProofFromAmounts(
1167 proof_multiUtxo,
false);
1171 proof_multiUtxo,
true);
1174 proof_multiUtxo,
true);
1179 proof_multiUtxo,
false);
1181 auto proofSimilar = buildProofFromAmounts(
1183 checkPreferred(proofSimilar, proof_multiUtxo,
1184 proofSimilar->getId() < proof_multiUtxo->getId());
1197 const COutPoint conflictingOutpoint = createUtxo(active_chainstate, key);
1198 const COutPoint matureOutpoint =
1201 auto immature10 = buildProofWithSequence(key, {conflictingOutpoint}, 10);
1203 buildProofWithSequence(key, {conflictingOutpoint, matureOutpoint}, 20);
1213 auto proof30 = buildProofWithOutpoints(key, {matureOutpoint},
1241 const COutPoint conflictingOutpoint =
1244 auto proofSeq10 = buildProofWithSequence(key, {conflictingOutpoint}, 10);
1245 auto proofSeq20 = buildProofWithSequence(key, {conflictingOutpoint}, 20);
1246 auto proofSeq30 = buildProofWithSequence(key, {conflictingOutpoint}, 30);
1273 auto now = GetTime<std::chrono::seconds>();
1277 for (
size_t i = 0; i < 10; i++) {
1284 PeerId peerid = TestPeerManager::registerAndGetPeerId(pm, proof);
1286 auto checkNextPossibleConflictTime = [&](std::chrono::seconds expected) {
1288 return p.nextPossibleConflictTime == expected;
1292 checkNextPossibleConflictTime(now);
1296 peerid, now - std::chrono::seconds{1}));
1297 checkNextPossibleConflictTime(now);
1300 peerid, now + std::chrono::seconds{1}));
1301 checkNextPossibleConflictTime(now + std::chrono::seconds{1});
1310 const COutPoint conflictingOutpoint =
1313 auto proofSeq10 = buildProofWithSequence(key, {conflictingOutpoint}, 10);
1314 auto proofSeq20 = buildProofWithSequence(key, {conflictingOutpoint}, 20);
1315 auto proofSeq30 = buildProofWithSequence(key, {conflictingOutpoint}, 30);
1344 for (
size_t i = 0; i < 10; i++) {
1347 !pm.
registerProof(proofSeq10, RegistrationMode::FORCE_ACCEPT));
1355 for (
size_t i = 0; i < 10; i++) {
1357 pm.
registerProof(proofSeq30, RegistrationMode::FORCE_ACCEPT));
1363 pm.
registerProof(proofSeq10, RegistrationMode::FORCE_ACCEPT));
1376 const COutPoint conflictingOutpoint =
1379 auto proofSeq10 = buildProofWithSequence(key, {conflictingOutpoint}, 10);
1380 auto proofSeq20 = buildProofWithSequence(key, {conflictingOutpoint}, 20);
1381 auto proofSeq30 = buildProofWithSequence(key, {conflictingOutpoint}, 30);
1408 const COutPoint conflictingOutpoint =
1411 auto proofSeq20 = buildProofWithSequence(key, {conflictingOutpoint}, 20);
1412 auto proofSeq30 = buildProofWithSequence(key, {conflictingOutpoint}, 30);
1413 auto proofSeq40 = buildProofWithSequence(key, {conflictingOutpoint}, 40);
1415 int64_t conflictingProofCooldown = 100;
1417 strprintf(
"%d", conflictingProofCooldown));
1421 auto increaseMockTime = [&](int64_t s) {
1425 increaseMockTime(0);
1430 auto checkRegistrationFailure = [&](
const ProofRef &proof,
1439 checkRegistrationFailure(proofSeq20,
1440 ProofRegistrationResult::COOLDOWN_NOT_ELAPSED);
1444 checkRegistrationFailure(proofSeq40,
1445 ProofRegistrationResult::COOLDOWN_NOT_ELAPSED);
1449 increaseMockTime(conflictingProofCooldown);
1452 checkRegistrationFailure(proofSeq20, ProofRegistrationResult::CONFLICTING);
1456 checkRegistrationFailure(proofSeq40,
1457 ProofRegistrationResult::COOLDOWN_NOT_ELAPSED);
1462 increaseMockTime(conflictingProofCooldown);
1483 const COutPoint conflictingOutpoint =
1485 const COutPoint immatureOutpoint = createUtxo(active_chainstate, key);
1488 auto proofSeq10 = buildProofWithOutpoints(
1490 auto proofSeq20 = buildProofWithOutpoints(
1492 auto immature30 = buildProofWithSequence(
1493 key, {conflictingOutpoint, immatureOutpoint}, 30);
1504 for (
size_t i = 0; i < 10; i++) {
1513 auto checkRejectDefault = [&](
const ProofId &proofid) {
1515 const bool isImmature = pm.
isImmature(proofid);
1522 auto checkRejectInvalidate = [&](
const ProofId &proofid) {
1529 checkRejectDefault(immature30->getId());
1532 checkRejectInvalidate(immature30->getId());
1535 checkRejectDefault(proofSeq10->getId());
1536 checkRejectInvalidate(proofSeq10->getId());
1543 checkRejectDefault(proofSeq20->getId());
1550 checkRejectInvalidate(proofSeq10->getId());
1577 for (
size_t i = 0; i < 10; i++) {
1584 for (
size_t i = 0; i < 10; i++) {
1590 auto cooldownTimepoint = Now<SteadyMilliseconds>() + 10s;
1595 for (
size_t i = 0; i < 10; i++) {
1597 BOOST_CHECK_NE(selectedId,
NO_NODE);
1599 selectedId, cooldownTimepoint, round++));
1608 for (
size_t i = 0; i < 10; i++) {
1624 TestPeerManager::cleanupDanglingProofs(pm);
1631 TestPeerManager::cleanupDanglingProofs(pm);
1635 for (
size_t i = 0; i < 10; i++) {
1649 for (
size_t i = 0; i < 10; i++) {
1660 TestPeerManager::cleanupDanglingProofs(pm);
1666 TestPeerManager::cleanupDanglingProofs(pm);
1684 std::vector<uint32_t> expectedScores(10);
1686 std::generate(expectedScores.rbegin(), expectedScores.rend(),
1687 [n = 1]()
mutable { return n++ * MIN_VALID_PROOF_SCORE; });
1689 std::vector<ProofRef> proofs;
1690 proofs.reserve(expectedScores.size());
1691 for (uint32_t score : expectedScores) {
1697 for (
auto &proof : proofs) {
1701 auto peersScores = TestPeerManager::getOrderedScores(pm);
1702 BOOST_CHECK_EQUAL_COLLECTIONS(peersScores.begin(), peersScores.end(),
1703 expectedScores.begin(), expectedScores.end());
1718 const COutPoint peer1ConflictingOutput =
1719 createUtxo(active_chainstate, key, amount1, 99);
1720 const COutPoint peer1SecondaryOutpoint =
1721 createUtxo(active_chainstate, key, amount2, 99);
1723 auto peer1Proof1 = buildProof(
1725 {{peer1ConflictingOutput, amount1}, {peer1SecondaryOutpoint, amount2}},
1728 buildProof(key, {{peer1ConflictingOutput, amount1}}, key, 20, 99);
1733 {{peer1ConflictingOutput, amount1},
1734 {createUtxo(active_chainstate, key, amount1), amount1}},
1737 const uint32_t peer1Score1 = Proof::amountToScore(amount1 + amount2);
1738 const uint32_t peer1Score2 = Proof::amountToScore(amount1);
1756 auto checkRejectDefault = [&](
const ProofId &proofid) {
1758 const bool isImmature = pm.
isImmature(proofid);
1765 auto checkRejectInvalidate = [&](
const ProofId &proofid) {
1772 checkRejectDefault(peer1Proof3->getId());
1776 checkRejectInvalidate(peer1Proof3->getId());
1780 checkRejectDefault(peer1Proof1->getId());
1781 checkRejectInvalidate(peer1Proof1->getId());
1790 checkRejectDefault(peer1Proof2->getId());
1797 checkRejectInvalidate(peer1Proof1->getId());
1807 PeerId peerid2 = TestPeerManager::registerAndGetPeerId(pm, peer2Proof1);
1818 TestPeerManager::getPeerIdForProofId(pm, peer1Proof2->getId());
1827 const auto checkScores = [&pm](uint32_t known, uint32_t connected) {
1841 PeerId peerid1 = TestPeerManager::registerAndGetPeerId(pm, proof1);
1842 checkScores(score1, 0);
1846 const ProofId &proofid1 = proof1->getId();
1847 const uint8_t nodesToAdd = 10;
1848 for (
int i = 0; i < nodesToAdd; i++) {
1851 checkScores(score1, score1);
1855 for (
int i = 0; i < nodesToAdd - 1; i++) {
1857 checkScores(score1, score1);
1862 checkScores(score1, 0);
1868 checkScores(score1, score1);
1872 PeerId peerid2 = TestPeerManager::registerAndGetPeerId(pm, proof2);
1873 checkScores(score1 + score2, score1);
1876 checkScores(score1 + score2, score1 + score2);
1881 checkScores(score1 + score2, score1 + score2);
1883 checkScores(score1 + score2, score2);
1887 checkScores(score2, score2);
1891 checkScores(score2, 0);
1900 peerid1 = TestPeerManager::registerAndGetPeerId(pm, proof1);
1901 checkScores(score1, 0);
1902 peerid2 = TestPeerManager::registerAndGetPeerId(pm, proof2);
1903 checkScores(score1 + score2, 0);
1906 checkScores(score1 + score2, score1);
1909 checkScores(score1 + score2, score1 + score2);
1912 checkScores(score1, score1);
1922 struct ProofComparatorById {
1927 using ProofSetById = std::set<ProofRef, ProofComparatorById>;
1929 ProofSetById expectedProofs;
1931 auto matchExpectedContent = [&](
const auto &tree) {
1932 auto it = expectedProofs.
begin();
1933 return tree.forEachLeaf([&](
auto pLeaf) {
1934 return it != expectedProofs.end() &&
1935 pLeaf->getId() == (*it++)->getId();
1940 const int64_t sequence = 10;
1945 for (
size_t i = 0; i < 10; i++) {
1946 auto outpoint = createUtxo(active_chainstate, key);
1947 auto proof = buildProofWithSequence(key, {{outpoint}}, sequence);
1949 expectedProofs.insert(std::move(proof));
1959 ProofSetById addedProofs;
1960 std::vector<COutPoint> outpointsToSpend;
1961 for (
size_t i = 0; i < 10; i++) {
1962 auto outpoint = createUtxo(active_chainstate, key);
1963 auto proof = buildProofWithSequence(key, {{outpoint}}, sequence);
1965 addedProofs.insert(std::move(proof));
1966 outpointsToSpend.push_back(std::move(outpoint));
1973 expectedProofs.
insert(addedProofs.begin(), addedProofs.end());
1980 for (
const auto &outpoint : outpointsToSpend) {
1992 for (
const auto &proof : addedProofs) {
1998 std::vector<ProofRef> conflictingProofs;
1999 std::vector<COutPoint> conflictingOutpoints;
2000 for (
size_t i = 0; i < 10; i++) {
2001 auto outpoint = createUtxo(active_chainstate, key);
2002 auto proof = buildProofWithSequence(key, {{outpoint}}, sequence);
2004 conflictingProofs.push_back(std::move(proof));
2005 conflictingOutpoints.push_back(std::move(outpoint));
2009 expectedProofs.
insert(conflictingProofs.begin(), conflictingProofs.end());
2013 for (
size_t i = 0; i < 10; i += 2) {
2016 key, {{conflictingOutpoints[i]}}, sequence - 1)));
2019 auto replacementProof = buildProofWithSequence(
2020 key, {{conflictingOutpoints[i + 1]}}, sequence + 1);
2023 BOOST_CHECK(expectedProofs.insert(replacementProof).second);
2037 auto addNode = [&](
NodeId nodeid) {
2045 for (
NodeId nodeid = 0; nodeid < 10; nodeid++) {
2062 const auto now = GetTime<std::chrono::seconds>();
2063 auto mocktime = now;
2065 auto elapseTime = [&](std::chrono::seconds seconds) {
2066 mocktime += seconds;
2073 const size_t numProofs = 10;
2075 std::vector<COutPoint> outpoints(numProofs);
2076 std::vector<ProofRef> proofs(numProofs);
2077 std::vector<ProofRef> conflictingProofs(numProofs);
2078 for (
size_t i = 0; i < numProofs; i++) {
2080 proofs[i] = buildProofWithSequence(key, {outpoints[i]}, 2);
2081 conflictingProofs[i] = buildProofWithSequence(key, {outpoints[i]}, 1);
2096 return peer.node_count;
2104 TestPeerManager::cleanupDanglingProofs(pm);
2105 for (
size_t i = 0; i < numProofs; i++) {
2112 TestPeerManager::cleanupDanglingProofs(pm);
2113 for (
size_t i = 0; i < numProofs; i++) {
2114 const bool hasNodeAttached = i % 2;
2132 conflictingProofs[0]->getId(),
2137 TestPeerManager::cleanupDanglingProofs(pm);
2138 for (
size_t i = 0; i < numProofs; i++) {
2139 const bool hasNodeAttached = i % 2;
2149 hasNodeAttached || i == 0);
2157 for (
size_t i = 1; i < numProofs; i += 2) {
2161 return peer.node_count == 0;
2166 conflictingProofs[0]->getId(),
2169 TestPeerManager::cleanupDanglingProofs(pm);
2170 for (
size_t i = 0; i < numProofs; i++) {
2171 const bool hadNodeAttached = i % 2;
2188 TestPeerManager::cleanupDanglingProofs(pm);
2190 for (
size_t i = 0; i < numProofs; i++) {
2207 BOOST_CHECK(state.GetResult() == ProofRegistrationResult::MISSING_UTXO);
2214 const int64_t tipTime =
2222 100,
false, tipTime + 1);
2224 1, 100,
false, tipTime + 2);
2236 for (int64_t i = 0; i < 6; i++) {
2237 SetMockTime(proofToExpire->getExpirationTime() + i);
2238 CreateAndProcessBlock({}, CScript());
2242 ->GetMedianTimePast(),
2243 proofToExpire->getExpirationTime());
2259 auto buildProofWithAmountAndPayout = [&](
Amount amount,
2260 const CScript &payoutScript) {
2262 COutPoint utxo = createUtxo(active_chainstate, key, amount);
2263 return buildProof(key, {{std::move(utxo), amount}},
2269 std::vector<std::pair<ProofId, CScript>> winners;
2275 auto now = GetTime<std::chrono::seconds>();
2277 prevBlock.
nTime = now.count();
2286 size_t numProofs = 8;
2287 std::vector<ProofRef> proofs;
2288 proofs.reserve(numProofs);
2289 for (
size_t i = 0; i < numProofs; i++) {
2295 PeerId peerid = TestPeerManager::registerAndGetPeerId(pm, proof);
2296 BOOST_CHECK_NE(peerid,
NO_PEER);
2301 proofs.emplace_back(std::move(proof));
2308 prevBlock.
nTime = now.count();
2314 BOOST_CHECK_LE(winners.size(), numProofs);
2317 for (
size_t i = 0; i < numProofs; i++) {
2318 BOOST_CHECK(TestPeerManager::isFlaky(pm, proofs[i]->getId()));
2320 BOOST_CHECK_LE(winners.size(), numProofs);
2325 BOOST_CHECK(!TestPeerManager::isFlaky(pm, proofs[i]->getId()));
2327 BOOST_CHECK_LE(winners.size(), numProofs - i);
2332 BOOST_CHECK_LE(winners.size(), 1);
2338 const size_t loop_iters =
2339 size_t(-1.0 * std::log(100000.0) /
2340 std::log((
double(numProofs) - 1) / numProofs)) +
2342 BOOST_CHECK_GT(loop_iters, numProofs);
2343 std::unordered_map<std::string, size_t> winningCounts;
2344 for (
size_t i = 0; i < loop_iters; i++) {
2355 for (
size_t i = 0; i < numProofs; i++) {
2356 for (
size_t j = 0; j < numProofs; j++) {
2364 BOOST_CHECK_GT(3. / numProofs, 0.3);
2365 for (
size_t i = 0; i < numProofs; i++) {
2369 proofs[(i - 1 + numProofs) % numProofs]->getId(), nodeid,
false));
2371 proofs[(i + numProofs) % numProofs]->getId(), nodeid,
false));
2373 proofs[(i + 1 + numProofs) % numProofs]->getId(), nodeid,
false));
2378 for (
const auto &proof : proofs) {
2384 for (
const auto &proof : proofs) {
2385 for (
NodeId nodeid = 0; nodeid <
NodeId(numProofs); nodeid++) {
2394 for (
size_t numWinner = 1; numWinner < 4; numWinner++) {
2396 CScript lastWinner = winners[numWinner - 1].second;
2400 for (
const auto &proof : proofs) {
2402 winnerProofId = proof->
getId();
2408 for (
NodeId nodeid = 0; nodeid <
NodeId(numProofs); nodeid++) {
2411 BOOST_CHECK(TestPeerManager::isFlaky(pm, winnerProofId));
2421 CScript lastWinner = winners[3].second;
2424 for (
const auto &proof : proofs) {
2426 winnerProofId = proof->
getId();
2432 for (
NodeId nodeid = 0; nodeid <
NodeId(numProofs); nodeid++) {
2441 for (
auto &proof : proofs) {
2456 PeerId peerid = TestPeerManager::registerAndGetPeerId(pm, proof);
2457 BOOST_CHECK_NE(peerid,
NO_PEER);
2483 prevBlock.
nTime = now.count();
2498 for (
size_t i = 0; i < 4; i++) {
2507 PeerId peerid = TestPeerManager::registerAndGetPeerId(pm, proof);
2508 BOOST_CHECK_NE(peerid,
NO_PEER);
2510 return peer.registration_time == now + i * 30min;
2518 proofs.push_back(proof);
2523 prevBlock.
nTime = now.count();
2531 prevBlock.
nTime = now.count();
2534 auto checkRegistrationTime =
2535 [&](
const std::pair<ProofId, CScript> &winner) {
2539 (now - 60min).count());
2550 prevBlock.
nTime = now.count();
2553 checkRegistrationTime(winners[0]);
2561 prevBlock.
nTime = now.count();
2563 BOOST_CHECK_LE(winners.size(), 3);
2564 checkRegistrationTime(winners[0]);
2572 prevBlock.
nTime = now.count();
2574 BOOST_CHECK_LE(winners.size(), 3);
2575 checkRegistrationTime(winners[0]);
2582 prevBlock.
nTime = now.count();
2584 BOOST_CHECK_LE(winners.size(), 2);
2585 checkRegistrationTime(winners[0]);
2591 prevBlock.
nTime = now.count();
2594 checkRegistrationTime(winners[0]);
2604 auto now = GetTime<std::chrono::seconds>();
2609 tip->
nTime = now.count();
2614 struct ContenderOption {
2616 bool invalid{
false};
2617 bool attachNode{
true};
2618 bool finalize{
true};
2619 bool knownForLongEnough{
true};
2623 auto makeEligibleContender = [&](
const ContenderOption &opt = {}) {
2632 opt.knownForLongEnough
2636 const PeerId peerid = TestPeerManager::registerAndGetPeerId(pm, proof);
2640 if (opt.attachNode) {
2644 if (opt.knownForLongEnough) {
2656 return std::make_tuple(proof, contenderId, peerid);
2667 auto [proof, contenderId, peerid] = makeEligibleContender();
2673 auto [proof, contenderId, peerid] =
2674 makeEligibleContender({.accept =
false});
2680 auto [proof, contenderId, peerid] =
2681 makeEligibleContender({.accept =
false,
2683 .attachNode =
false,
2685 .knownForLongEnough =
false});
2691 auto [proof, contenderId, peerid] =
2692 makeEligibleContender({.invalid =
true});
2699 const COutPoint conflictingOutpoint =
2700 createUtxo(active_chainstate, key);
2701 auto preferredProof =
2702 buildProofWithSequence(key, {conflictingOutpoint}, 20);
2703 auto conflictingProof =
2704 buildProofWithSequence(key, {conflictingOutpoint}, 10);
2718 auto [proof, contenderId, peerid] =
2719 makeEligibleContender({.attachNode =
false});
2722 tip->
nTime = now.count();
2723 TestPeerManager::cleanupDanglingProofs(pm);
2732 auto [proof, contenderId, peerid] =
2733 makeEligibleContender({.finalize =
false});
2739 auto [proof, contenderId, peerid] =
2740 makeEligibleContender({.knownForLongEnough =
false});
2749 auto mockTime = GetTime<std::chrono::seconds>();
2757 auto checkRemoteProof =
2759 const bool expectedPresent,
2760 const std::chrono::seconds &expectedlastUpdate) {
2764 TestPeerManager::getRemoteProof(pm, proofid, nodeid);
2770 expectedlastUpdate.count());
2837 checkRemoteProof(proofid, 0,
true, mockTime);
2853 checkRemoteProof(proofid, 0,
true, mockTime);
2863 std::vector<ProofRef> proofs;
2868 proofs.push_back(proof);
2881 checkRemoteProof(proofid, 0,
true, mockTime);
2911 auto mockTime = GetTime<std::chrono::seconds>();
2920 for (
NodeId nodeid = 0; nodeid < 12; nodeid++) {
2934 for (
NodeId nodeid = 0; nodeid < 5; nodeid++) {
2937 for (
NodeId nodeid = 5; nodeid < 12; nodeid++) {
2947 TestPeerManager::setLocalProof(pm, localProof);
2955 TestPeerManager::setLocalProof(pm,
ProofRef());
2961 for (
NodeId nodeid = 0; nodeid < 5; nodeid++) {
2964 for (
NodeId nodeid = 5; nodeid < 12; nodeid++) {
2980 for (
NodeId nodeid = 0; nodeid < 5; nodeid++) {
2983 for (
NodeId nodeid = 5; nodeid < 12; nodeid++) {
2991 for (
NodeId nodeid = 0; nodeid < 5; nodeid++) {
2994 for (
NodeId nodeid = 5; nodeid < 12; nodeid++) {
3001 TestPeerManager::clearPeers(pm);
3012 for (
NodeId nodeid = 1; nodeid < 6; nodeid++) {
3019 for (
NodeId nodeid = 1; nodeid < 6; nodeid++) {
3036 auto mockTime = GetTime<std::chrono::seconds>();
3040 std::vector<ProofRef> proofs;
3041 for (
size_t i = 0; i < 10; i++) {
3044 proofs.push_back(proof);
3048 TestPeerManager::cleanupDanglingProofs(pm);
3049 for (
const auto &proof : proofs) {
3059 TestPeerManager::cleanupDanglingProofs(pm);
3060 for (
const auto &proof : proofs) {
3066 for (
NodeId nodeid = 0; nodeid < 10; nodeid++) {
3073 for (
const auto &proof : proofs) {
3079 for (
const auto &proof : proofs) {
3085 std::unordered_set<ProofRef, SaltedProofHasher> registeredProofs;
3086 TestPeerManager::cleanupDanglingProofs(pm, registeredProofs);
3087 for (
const auto &proof : proofs) {
3095 for (
NodeId nodeid = 0; nodeid < 10; nodeid++) {
3096 for (
const auto &proof : proofs) {
3102 for (
const auto &proof : proofs) {
3104 !TestPeerManager::getRemotePresenceStatus(pm, proof->
getId())
3109 TestPeerManager::cleanupDanglingProofs(pm, registeredProofs);
3111 for (
const auto &proof : proofs) {
3120 TestPeerManager::cleanupDanglingProofs(pm, registeredProofs);
3122 for (
const auto &proof : proofs) {
3128 for (
NodeId nodeid = 0; nodeid < 10; nodeid++) {
3129 for (
const auto &proof : proofs) {
3134 TestPeerManager::cleanupDanglingProofs(pm, registeredProofs);
3135 for (
const auto &proof : proofs) {
3148 auto mockTime = GetTime<std::chrono::seconds>();
3151 std::vector<ProofRef> proofs;
3152 for (
size_t i = 0; i < 10; i++) {
3159 auto peerid = TestPeerManager::getPeerIdForProofId(pm, proof->getId());
3163 peerid, mockTime + std::chrono::seconds{100 + i}));
3170 proofs.push_back(proof);
3175 const fs::path testDumpPath =
"test_avapeers_dump.dat";
3178 TestPeerManager::clearPeers(pm);
3180 std::unordered_set<ProofRef, SaltedProofHasher> registeredProofs;
3184 auto findProofIndex = [&proofs](
const ProofId &proofid) {
3185 for (
size_t i = 0; i < proofs.size(); i++) {
3186 if (proofs[i]->getId() == proofid) {
3196 for (
const auto &proof : registeredProofs) {
3198 size_t i = findProofIndex(proofid);
3200 BOOST_CHECK_EQUAL(peer.hasFinalized, i < 5);
3201 BOOST_CHECK_EQUAL(peer.registration_time.count(),
3202 (mockTime + std::chrono::seconds{i}).count());
3204 peer.nextPossibleConflictTime.count(),
3205 (mockTime + std::chrono::seconds{100 + i}).count());
3211 TestPeerManager::clearPeers(pm);
3224 registeredProofs.insert(proofs[0]);
3234 file << static_cast<uint64_t>(-1);
3235 file << uint64_t{0};
3240 registeredProofs.insert(proofs[0]);
3251 const uint64_t now =
GetTime();
3253 file << static_cast<uint64_t>(1);
3254 file << uint64_t{2};
3271 proofs[0]->getId());
3283 auto utxo = createUtxo(active_chainstate, key);
3286 GetTime<std::chrono::seconds>().count() + 1000000);
3297 TestPeerManager::cleanupDanglingProofs(pm);
3335 TestPeerManager::cleanupDanglingProofs(pm);
3341 for (int64_t i = 0; i < 6; i++) {
3343 CreateAndProcessBlock({}, CScript());
3347 ->GetMedianTimePast(),
3365 auto danglingProof = buildProofWithSequence(key, {utxo}, 1);
3366 auto preferredProof = buildProofWithSequence(key, {utxo}, 2);
3374 TestPeerManager::cleanupDanglingProofs(pm);
3404 auto utxo = createUtxo(active_chainstate, key);
3405 auto lowSeqProof = buildProofWithSequence(key, {utxo}, 1);
3406 auto highSeqProof = buildProofWithSequence(key, {utxo}, 2);
3415 BOOST_CHECK(TestPeerManager::addDanglingProof(pm, highSeqProof));
3420 for (
NodeId nodeid = 0; nodeid < 10; nodeid++) {
3431 TestPeerManager::getRemotePresenceStatus(pm, highSeqProof->getId())
3434 !TestPeerManager::getRemotePresenceStatus(pm, lowSeqProof->getId())
3440 std::unordered_set<ProofRef, SaltedProofHasher> registeredProofs;
3441 TestPeerManager::cleanupDanglingProofs(pm, registeredProofs);
3453BOOST_AUTO_TEST_SUITE_END()
static constexpr PeerId NO_PEER
#define Assert(val)
Identity function.
void ForceSetArg(const std::string &strArg, const std::string &strValue)
void ClearForcedArg(const std::string &strArg)
Remove a forced arg setting, used only in testing.
Non-refcounted RAII wrapper for FILE*.
The block chain is a tree shaped structure starting with the genesis block at the root,...
const BlockHash * phashBlock
pointer to the hash of the block, if any.
BlockHash GetBlockHash() const
CCoinsView that adds a memory cache for transactions to another CCoinsView.
void AddCoin(const COutPoint &outpoint, Coin coin, bool possible_overwrite)
Add a coin.
bool SpendCoin(const COutPoint &outpoint, Coin *moveto=nullptr)
Spend a coin.
An encapsulated secp256k1 private key.
static CKey MakeCompressedKey()
Produce a valid compressed key.
CPubKey GetPubKey() const
Compute the public key from a private key.
An output of a transaction.
Chainstate stores and provides an API to update our local knowledge of the current best chain.
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(
bool InvalidateBlock(BlockValidationState &state, CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex
Mark a block as invalid.
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
SnapshotCompletionResult MaybeCompleteSnapshotValidation() EXCLUSIVE_LOCKS_REQUIRED(const CBlockIndex *GetSnapshotBaseBlock() const EXCLUSIVE_LOCKS_REQUIRED(Chainstate ActiveChainstate)() const
Once the background validation chainstate has reached the height which is the base of the UTXO snapsh...
RecursiveMutex & GetMutex() const LOCK_RETURNED(
Alias for cs_main.
CBlockIndex * ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
static RCUPtr make(Args &&...args)
Construct a new object that is owned by the pointer.
I randrange(I range) noexcept
Generate a random integer in the range [0..range), with range > 0.
bool selectStakingRewardWinner(const CBlockIndex *pprev, std::vector< std::pair< ProofId, CScript > > &winners)
Deterministically select a list of payout scripts based on the proof set and the previous block hash.
bool removeNode(NodeId nodeid)
bool setFinalized(PeerId peerid)
Latch on that this peer has a finalized proof.
bool dumpPeersToFile(const fs::path &dumpPath) const
RemoteProofSet remoteProofs
Remember which node sent which proof so we have an image of the proof set of our peers.
uint64_t getFragmentation() const
uint32_t getConnectedPeersScore() const
bool updateNextRequestTimeForResponse(NodeId nodeid, const Response &response)
bool isDangling(const ProofId &proofid) const
bool addNode(NodeId nodeid, const ProofId &proofid, size_t max_elements)
Node API.
std::optional< bool > getRemotePresenceStatus(const ProofId &proofid) const
Get the presence remote status of a proof.
bool shouldRequestMoreNodes()
Returns true if we encountered a lack of node since the last call.
bool exists(const ProofId &proofid) const
Return true if the (valid) proof exists, but only for non-dangling proofs.
size_t getNodeCount() const
PendingNodeSet pendingNodes
bool verify() const
Perform consistency check on internal data structures.
bool forNode(NodeId nodeid, Callable &&func) const
bool hasRemoteProofStatus(const ProofId &proofid) const
bool forPeer(const ProofId &proofid, Callable &&func) const
void clearRemoteProofs(NodeId nodeid)
uint32_t getTotalPeersScore() const
bool latchAvaproofsSent(NodeId nodeid)
Flag that a node did send its compact proofs.
bool updateNextRequestTimeForPoll(NodeId nodeid, SteadyMilliseconds timeout, uint64_t round)
uint64_t getSlotCount() const
bool loadPeersFromFile(const fs::path &dumpPath, std::unordered_set< ProofRef, SaltedProofHasher > ®isteredProofs)
std::unordered_set< ProofRef, SaltedProofHasher > updatedBlockTip()
Update the peer set when a new block is connected.
const ProofRadixTree & getShareableProofsSnapshot() const
bool isBoundToPeer(const ProofId &proofid) const
size_t getPendingNodeCount() const
bool saveRemoteProof(const ProofId &proofid, const NodeId nodeid, const bool present)
uint64_t compact()
Trigger maintenance of internal data structures.
std::vector< Slot > slots
ProofPool danglingProofPool
void forEachPeer(Callable &&func) const
void setInvalid(const ProofId &proofid)
int getStakeContenderStatus(const StakeContenderId &contenderId, BlockHash &prevblockhashout) const
bool isFlaky(const ProofId &proofid) const
bool removePeer(const PeerId peerid)
Remove an existing peer.
bool isImmature(const ProofId &proofid) const
bool rejectProof(const ProofId &proofid, RejectionMode mode=RejectionMode::DEFAULT)
RegistrationMode
Registration mode.
static constexpr size_t MAX_REMOTE_PROOFS
void addStakeContender(const ProofRef &proof)
PeerId selectPeer() const
Randomly select a peer to poll.
bool isInConflictingPool(const ProofId &proofid) const
bool isRemotelyPresentProof(const ProofId &proofid) const
void cleanupDanglingProofs(std::unordered_set< ProofRef, SaltedProofHasher > ®isteredProofs)
void acceptStakeContender(const StakeContenderId &contenderId)
ProofRef getProof(const ProofId &proofid) const
bool registerProof(const ProofRef &proof, ProofRegistrationState ®istrationState, RegistrationMode mode=RegistrationMode::DEFAULT)
bool updateNextPossibleConflictTime(PeerId peerid, const std::chrono::seconds &nextTime)
Proof and Peer related API.
bool addUTXO(COutPoint utxo, Amount amount, uint32_t height, bool is_coinbase, CKey key)
int64_t getExpirationTime() const
const CScript & getPayoutScript() const
const ProofId & getId() const
AddProofStatus addProofIfPreferred(const ProofRef &proof, ConflictingProofSet &conflictingProofs)
Attempt to add a proof to the pool.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
static const uint256 ZERO
static void addCoin(const Amount nValue, const CWallet &wallet, std::vector< std::unique_ptr< CWalletTx > > &wtxs)
std::string FormatScript(const CScript &script)
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
bool FileCommit(FILE *file)
Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsyn...
static RPCHelpMan generate()
static constexpr Amount PROOF_DUST_THRESHOLD
Minimum amount per utxo.
static constexpr uint32_t AVALANCHE_MAX_IMMATURE_PROOFS
Maximum number of immature proofs the peer manager will accept from the network.
const CScript UNSPENDABLE_ECREG_PAYOUT_SCRIPT
ProofRef buildRandomProof(Chainstate &active_chainstate, uint32_t score, int height, const CKey &masterKey)
constexpr uint32_t MIN_VALID_PROOF_SCORE
PeerId selectPeerImpl(const std::vector< Slot > &slots, const uint64_t slot, const uint64_t max)
Internal methods that are exposed for testing purposes.
RCUPtr< const Proof > ProofRef
FILE * fopen(const fs::path &p, const char *mode)
static constexpr NodeId NO_NODE
Special NodeId that represent no node.
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK(expr)
static void addNodeWithScore(Chainstate &active_chainstate, avalanche::PeerManager &pm, NodeId node, uint32_t score)
BOOST_AUTO_TEST_CASE(select_peer_linear)
BOOST_FIXTURE_TEST_CASE(conflicting_proof_rescan, NoCoolDownFixture)
static constexpr size_t DEFAULT_AVALANCHE_MAX_ELEMENT_POLL
Maximum item that can be polled at once.
void Shuffle(I first, I last, R &&rng)
More efficient than using std::shuffle on a FastRandomContext.
uint256 GetRandHash() noexcept
========== CONVENIENCE FUNCTIONS FOR COMMONLY USED RANDOMNESS ==========
CScript GetScriptForRawPubKey(const CPubKey &pubKey)
Generate a P2PK script for the given pubkey.
CScript GetScriptForDestination(const CTxDestination &dest)
Generate a Bitcoin scriptPubKey for the given CTxDestination.
A BlockHash is a unqiue identifier for a block.
bool insert(const RCUPtr< T > &value)
Insert a value into the tree.
A TxId is the identifier of a transaction.
Compare conflicting proofs.
std::chrono::seconds registration_time
static constexpr auto DANGLING_TIMEOUT
Consider dropping the peer if no node is attached after this timeout expired.
StakeContenderIds are unique for each block to ensure that the peer polling for their acceptance has ...
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
int64_t GetTime()
DEPRECATED Use either ClockType::now() or Now<TimePointType>() if a cast is needed.
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.
std::chrono::time_point< std::chrono::steady_clock, std::chrono::milliseconds > SteadyMilliseconds