diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -1739,6 +1739,12 @@ }); } + if (m_chainman.ActiveChainstate().IsInitialBlockDownload()) { + // Don't request proofs while in IBD. We're likely to orphan them + // because we don't have the UTXOs. + goto scheduleLater; + } + // Send a getavaproofs to one of our peers m_connman.ForNode(avanode_outbound_ids.back(), [&](CNode *pavanode) { LogPrint(BCLog::AVALANCHE, "Requesting compact proofs from peer %d\n", @@ -3732,7 +3738,8 @@ WITH_LOCK(peer->m_addr_token_bucket_mutex, peer->m_addr_token_bucket += GetMaxAddrToSend()); - if (pfrom.m_proof_relay) { + if (pfrom.m_proof_relay && + !m_chainman.ActiveChainstate().IsInitialBlockDownload()) { m_connman.PushMessage( &pfrom, msgMaker.Make(NetMsgType::GETAVAPROOFS)); pfrom.m_proof_relay->compactproofs_requested = true; diff --git a/test/functional/abc_p2p_avalanche_quorum.py b/test/functional/abc_p2p_avalanche_quorum.py --- a/test/functional/abc_p2p_avalanche_quorum.py +++ b/test/functional/abc_p2p_avalanche_quorum.py @@ -111,11 +111,13 @@ peer['node'] = avapeer addavalanchenode(node, peer) - avapeer.wait_until( - lambda: avapeer.last_message.get("getavaproofs")) - avapeer.send_and_ping(msg_avaproofs()) - avapeer.wait_until( - lambda: avapeer.last_message.get("avaproofsreq")) + # There is no compact proof request if the node is in IBD state + if not node.getblockchaininfo()['initialblockdownload']: + avapeer.wait_until( + lambda: avapeer.last_message.get("getavaproofs")) + avapeer.send_and_ping(msg_avaproofs()) + avapeer.wait_until( + lambda: avapeer.last_message.get("avaproofsreq")) return avapeer 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 @@ -494,6 +494,40 @@ lambda: all( proof.proofid in proofids for proof in get_proof_ids(requester))) + def test_no_compactproofs_during_ibs(self): + self.log.info( + "Check the node don't request compact proofs during IBD") + + node = self.nodes[0] + + chainwork = int(node.getblockchaininfo()['chainwork'], 16) + self.restart_node( + 0, + extra_args=self.extra_args[0] + + [f'-minimumchainwork={chainwork + 2:#x}']) + + assert node.getblockchaininfo()['initialblockdownload'] + + peer = P2PInterface() + node.add_outbound_p2p_connection( + peer, + p2p_idx=0, + connection_type="avalanche", + services=NODE_NETWORK | NODE_AVALANCHE, + ) + + # Force the node to process the sending loop + peer.sync_send_with_ping() + with p2p_lock: + assert_equal(peer.message_count.get("getavaproofs", 0), 0) + + # Make sure there is no message sent as part as the periodic network + # messaging either + node.mockscheduler(AVALANCHE_MAX_PERIODIC_NETWORKING_INTERVAL) + peer.sync_send_with_ping() + with p2p_lock: + assert_equal(peer.message_count.get("getavaproofs", 0), 0) + def run_test(self): # Most if the tests only need a single node, let the other ones start # the node when required @@ -505,6 +539,7 @@ self.test_request_missing_proofs() self.test_send_missing_proofs() self.test_compact_proofs_download_on_connect() + self.test_no_compactproofs_during_ibs() if __name__ == '__main__':