diff --git a/src/avalanche/processor.h b/src/avalanche/processor.h --- a/src/avalanche/processor.h +++ b/src/avalanche/processor.h @@ -310,6 +310,11 @@ */ const Proof getProof() const; + /* + * Return whether the avalanche service flag should be set. + */ + bool isAvalancheServiceAvailable() { return !!peerData; } + std::vector getPeers() const; std::vector getNodeIdsForPeer(PeerId peerId) const; diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -2445,7 +2445,8 @@ return false; } - if (args.GetBoolArg("-enableavalanche", AVALANCHE_DEFAULT_ENABLED)) { + if (args.GetBoolArg("-enableavalanche", AVALANCHE_DEFAULT_ENABLED) && + g_avalanche->isAvalancheServiceAvailable()) { nLocalServices = ServiceFlags(nLocalServices | NODE_AVALANCHE); } diff --git a/test/functional/abc_p2p_avalanche.py b/test/functional/abc_p2p_avalanche.py --- a/test/functional/abc_p2p_avalanche.py +++ b/test/functional/abc_p2p_avalanche.py @@ -127,11 +127,6 @@ def run_test(self): node = self.nodes[0] - self.log.info("Check the node is signalling the avalanche service.") - assert_equal( - int(node.getnetworkinfo()['localservices'], 16) & NODE_AVALANCHE, - NODE_AVALANCHE) - # Build a fake quorum of nodes. def get_node(): n = TestNode() @@ -343,12 +338,22 @@ wait_until(has_parked_new_tip, timeout=15) assert_equal(node.getbestblockhash(), fork_tip) + self.log.info( + "Check the node is signalling the avalanche service bit only if there is a proof.") + assert_equal( + int(node.getnetworkinfo()['localservices'], 16) & NODE_AVALANCHE, + 0) + # Restart the node self.restart_node(0, self.extra_args[0] + [ "-avaproof={}".format(proof), "-avamasterkey=cND2ZvtabDbJ1gucx9GWH6XT9kgTAqfb6cotPt5Q5CyxVDhid2EN", ]) + assert_equal( + int(node.getnetworkinfo()['localservices'], 16) & NODE_AVALANCHE, + NODE_AVALANCHE) + self.log.info("Test the avahello signature") quorum = get_quorum() poll_node = quorum[0]