diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1704,16 +1704,16 @@ } }); - if (g_avalanche && - (!g_avalanche->isQuorumEstablished() || - g_avalanche->withPeerManager([&](avalanche::PeerManager &pm) { - return pm.shouldRequestMoreNodes(); - }))) { - // Randomly select an avalanche outbound peer to send the getavaaddr - // message to - if (!avanode_outbound_ids.empty()) { - Shuffle(avanode_outbound_ids.begin(), avanode_outbound_ids.end(), - FastRandomContext()); + Shuffle(avanode_outbound_ids.begin(), avanode_outbound_ids.end(), + FastRandomContext()); + + if (g_avalanche && !avanode_outbound_ids.empty()) { + if (!g_avalanche->isQuorumEstablished() || + g_avalanche->withPeerManager([&](avalanche::PeerManager &pm) { + return pm.shouldRequestMoreNodes(); + })) { + // Randomly select an avalanche outbound peer to send the getavaaddr + // message to const NodeId avanodeId = avanode_outbound_ids.front(); m_connman.ForNode(avanodeId, [&](CNode *pavanode) { @@ -1729,6 +1729,18 @@ return true; }); } + + // Send a getavaproofs to one of our peers + const NodeId avanodeId = avanode_outbound_ids.back(); + + m_connman.ForNode(avanodeId, [&](CNode *pavanode) { + LogPrint(BCLog::AVALANCHE, + "Requesting compact proofs from peer %d\n", avanodeId); + m_connman.PushMessage(pavanode, + CNetMsgMaker(pavanode->GetCommonVersion()) + .Make(NetMsgType::GETAVAPROOFS)); + return true; + }); } // Schedule next run for 2-5 minutes in the future. diff --git a/test/functional/abc_p2p_compactproofs.py b/test/functional/abc_p2p_compactproofs.py --- a/test/functional/abc_p2p_compactproofs.py +++ b/test/functional/abc_p2p_compactproofs.py @@ -105,6 +105,25 @@ assert all([p.message_count.get( "getavaproofs", 0) == 0 for p in inbound_avapeers]) + self.log.info( + "Check we send periodic getavaproofs message to one of our peers") + + def count_outbounds_getavaproofs(): + return sum([p.message_count.get("getavaproofs", 0) + for p in outbound_avapeers]) + + outbounds_getavaproofs = count_outbounds_getavaproofs() + for i in range(12): + node.mockscheduler(AVALANCHE_MAX_PERIODIC_NETWORKING_INTERVAL) + self.wait_until(lambda: count_outbounds_getavaproofs() + == outbounds_getavaproofs + 1) + outbounds_getavaproofs += 1 + + assert all([p.message_count.get( + "getavaproofs", 0) == 0 for p in non_avapeers]) + assert all([p.message_count.get( + "getavaproofs", 0) == 0 for p in inbound_avapeers]) + def test_send_manual_getavaproofs(self): self.log.info( "Check we send a getavaproofs message to our manually connected peers that support avalanche")