Changeset View
Changeset View
Standalone View
Standalone View
src/avalanche/test/peermanager_tests.cpp
Show First 20 Lines • Show All 2,342 Lines • ▼ Show 20 Lines | for (size_t i = 0; i < numProofs; i++) { | ||||
// Finalize the proof | // Finalize the proof | ||||
BOOST_CHECK(pm.setFinalized(peerid)); | BOOST_CHECK(pm.setFinalized(peerid)); | ||||
proofs.emplace_back(std::move(proof)); | proofs.emplace_back(std::move(proof)); | ||||
} | } | ||||
// Make sure the proofs have been registered before the prev block was found | // Make sure the proofs have been registered before the prev block was found | ||||
// and before 2x the peer replacement cooldown. | // and before 4x the peer replacement cooldown. | ||||
now += 30min + 1s; | now += 4 * avalanche::Peer::DANGLING_TIMEOUT + 1s; | ||||
SetMockTime(now); | SetMockTime(now); | ||||
prevBlock.nTime = now.count(); | prevBlock.nTime = now.count(); | ||||
// At this stage we have a set of peers out of which none has any node | // At this stage we have a set of peers out of which none has any node | ||||
// attached, so they're all considered flaky. Note that we have no remote | // attached, so they're all considered flaky. Note that we have no remote | ||||
// proofs status yet. | // proofs status yet. | ||||
BOOST_CHECK(pm.selectStakingRewardWinner(&prevBlock, winners)); | BOOST_CHECK(pm.selectStakingRewardWinner(&prevBlock, winners)); | ||||
BOOST_CHECK_LE(winners.size(), numProofs); | BOOST_CHECK_LE(winners.size(), numProofs); | ||||
▲ Show 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | BOOST_CHECK(!pm.selectStakingRewardWinner(&prevBlock, winners)); | ||||
prevBlock.nTime = (now - 10min).count(); | prevBlock.nTime = (now - 10min).count(); | ||||
BOOST_CHECK(!pm.selectStakingRewardWinner(&prevBlock, winners)); | BOOST_CHECK(!pm.selectStakingRewardWinner(&prevBlock, winners)); | ||||
// 5. Now the proof has it all | // 5. Now the proof has it all | ||||
prevBlock.nTime = now.count(); | prevBlock.nTime = now.count(); | ||||
BOOST_CHECK(pm.selectStakingRewardWinner(&prevBlock, winners)); | BOOST_CHECK(pm.selectStakingRewardWinner(&prevBlock, winners)); | ||||
// With a single proof, it's easy to determine the winner | // With a single proof, it's easy to determine the winner | ||||
BOOST_CHECK_EQUAL(FormatScript(winners[0]), FormatScript(payoutScript)); | BOOST_CHECK_EQUAL(FormatScript(winners[0]), FormatScript(payoutScript)); | ||||
// Remove the proof | |||||
BOOST_CHECK(pm.rejectProof( | |||||
proof->getId(), avalanche::PeerManager::RejectionMode::INVALIDATE)); | |||||
} | |||||
{ | |||||
for (size_t i = 0; i < 2; i++) { | |||||
// Add a couple proofs | |||||
const CKey key = CKey::MakeCompressedKey(); | |||||
CScript payoutScript = GetScriptForRawPubKey(key.GetPubKey()); | |||||
auto proof = buildProofWithAmountAndPayout(PROOF_DUST_THRESHOLD, | |||||
payoutScript); | |||||
PeerId peerid = TestPeerManager::registerAndGetPeerId(pm, proof); | |||||
BOOST_CHECK_NE(peerid, NO_PEER); | |||||
BOOST_CHECK(pm.addNode(NodeId(i), proof->getId())); | |||||
BOOST_CHECK(pm.setFinalized(peerid)); | |||||
} | |||||
// The proofs has been registered > 30min from the previous block time, | |||||
// but less than 60min | |||||
now += 30min + 1s; | |||||
SetMockTime(now); | |||||
prevBlock.nTime = now.count(); | |||||
// Because they are both recently registered, both proofs are acceptable | |||||
BOOST_CHECK(pm.selectStakingRewardWinner(&prevBlock, winners)); | |||||
BOOST_CHECK_EQUAL(winners.size(), 2); | |||||
// The proofs has been registered > 60min from the previous block time | |||||
now += 30min; | |||||
SetMockTime(now); | |||||
prevBlock.nTime = now.count(); | |||||
// Now only one is acceptable | |||||
BOOST_CHECK(pm.selectStakingRewardWinner(&prevBlock, winners)); | |||||
BOOST_CHECK_EQUAL(winners.size(), 1); | |||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(remote_proof) { | BOOST_AUTO_TEST_CASE(remote_proof) { | ||||
ChainstateManager &chainman = *Assert(m_node.chainman); | ChainstateManager &chainman = *Assert(m_node.chainman); | ||||
avalanche::PeerManager pm(PROOF_DUST_THRESHOLD, chainman); | avalanche::PeerManager pm(PROOF_DUST_THRESHOLD, chainman); | ||||
auto mockTime = GetTime<std::chrono::seconds>(); | auto mockTime = GetTime<std::chrono::seconds>(); | ||||
▲ Show 20 Lines • Show All 508 Lines • Show Last 20 Lines |