| 49 | // being applied to nodes which send headers with sufficient |
| 50 | // work. |
| 51 | BOOST_AUTO_TEST_CASE(outbound_slow_chain_eviction) |
| 52 | { |
| 53 | const CChainParams& chainparams = Params(); |
| 54 | auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman); |
| 55 | // Disable inactivity checks for this test to avoid interference |
| 56 | static_cast<ConnmanTestMsg*>(connman.get())->SetPeerConnectTimeout(99999s); |
| 57 | auto peerLogic = PeerManager::make(chainparams, *connman, *m_node.addrman, nullptr, |
| 58 | *m_node.chainman, *m_node.mempool, false); |
| 59 | |
| 60 | // Mock an outbound peer |
| 61 | CAddress addr1(ip(0xa0b0c001), NODE_NONE); |
| 62 | CNode dummyNode1{id++, |
| 63 | ServiceFlags(NODE_NETWORK | NODE_WITNESS), |
| 64 | /*sock=*/nullptr, |
| 65 | addr1, |
| 66 | /*nKeyedNetGroupIn=*/0, |
| 67 | /*nLocalHostNonceIn=*/0, |
| 68 | CAddress(), |
| 69 | /*addrNameIn=*/"", |
| 70 | ConnectionType::OUTBOUND_FULL_RELAY, |
| 71 | /*inbound_onion=*/false}; |
| 72 | dummyNode1.SetCommonVersion(PROTOCOL_VERSION); |
| 73 | |
| 74 | peerLogic->InitializeNode(&dummyNode1); |
| 75 | dummyNode1.fSuccessfullyConnected = true; |
| 76 | |
| 77 | // This test requires that we have a chain with non-zero work. |
| 78 | { |
| 79 | LOCK(cs_main); |
| 80 | BOOST_CHECK(m_node.chainman->ActiveChain().Tip() != nullptr); |
| 81 | BOOST_CHECK(m_node.chainman->ActiveChain().Tip()->nChainWork > 0); |
| 82 | } |
| 83 | |
| 84 | // Test starts here |
| 85 | { |
| 86 | LOCK(dummyNode1.cs_sendProcessing); |
| 87 | BOOST_CHECK(peerLogic->SendMessages(&dummyNode1)); // should result in getheaders |
| 88 | } |
| 89 | { |
| 90 | LOCK(dummyNode1.cs_vSend); |
| 91 | BOOST_CHECK(dummyNode1.vSendMsg.size() > 0); |
| 92 | dummyNode1.vSendMsg.clear(); |
| 93 | } |
| 94 | |
| 95 | int64_t nStartTime = GetTime(); |
| 96 | // Wait 21 minutes |
| 97 | SetMockTime(nStartTime+21*60); |
| 98 | { |
| 99 | LOCK(dummyNode1.cs_sendProcessing); |
| 100 | BOOST_CHECK(peerLogic->SendMessages(&dummyNode1)); // should result in getheaders |
| 101 | } |
| 102 | { |
| 103 | LOCK(dummyNode1.cs_vSend); |
| 104 | BOOST_CHECK(dummyNode1.vSendMsg.size() > 0); |
| 105 | } |
| 106 | // Wait 3 more minutes |
| 107 | SetMockTime(nStartTime+24*60); |
| 108 | { |
nothing calls this directly
no test coverage detected