diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -537,6 +537,7 @@ add_library(server addrdb.cpp addrman.cpp + avalanche/avalanche.cpp avalanche/delegation.cpp avalanche/delegationbuilder.cpp avalanche/orphanproofpool.cpp diff --git a/src/avalanche/avalanche.h b/src/avalanche/avalanche.h --- a/src/avalanche/avalanche.h +++ b/src/avalanche/avalanche.h @@ -12,6 +12,8 @@ class Processor; } +class ArgsManager; + /** * Is avalanche enabled by default. */ @@ -27,4 +29,6 @@ */ extern std::unique_ptr g_avalanche; +bool isAvalancheEnabled(const ArgsManager &argsman); + #endif // BITCOIN_AVALANCHE_AVALANCHE_H diff --git a/src/avalanche/avalanche.cpp b/src/avalanche/avalanche.cpp new file mode 100644 --- /dev/null +++ b/src/avalanche/avalanche.cpp @@ -0,0 +1,11 @@ +// Copyright (c) 2021 The Bitcoin developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include + +#include + +bool isAvalancheEnabled(const ArgsManager &argsman) { + return argsman.GetBoolArg("-enableavalanche", AVALANCHE_DEFAULT_ENABLED); +} diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -2447,7 +2447,7 @@ return false; } - if (args.GetBoolArg("-enableavalanche", AVALANCHE_DEFAULT_ENABLED) && + if (isAvalancheEnabled(args) && g_avalanche->isAvalancheServiceAvailable()) { nLocalServices = ServiceFlags(nLocalServices | NODE_AVALANCHE); } diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2768,7 +2768,7 @@ return; } - if (!gArgs.GetBoolArg("-enableavalanche", AVALANCHE_DEFAULT_ENABLED)) { + if (!isAvalancheEnabled(gArgs)) { Misbehaving(pfrom, 20, "unsolicited-" + msg_type); return; } @@ -3003,7 +3003,7 @@ } if ((pfrom.nServices & NODE_AVALANCHE) && g_avalanche && - gArgs.GetBoolArg("-enableavalanche", AVALANCHE_DEFAULT_ENABLED)) { + isAvalancheEnabled(gArgs)) { if (g_avalanche->sendHello(&pfrom)) { LogPrint(BCLog::NET, "Send avahello to peer %d\n", pfrom.GetId()); @@ -3193,9 +3193,7 @@ const bool fAlreadyHave = AlreadyHaveProof(proofid); logInv(inv, fAlreadyHave); - if (!fAlreadyHave && g_avalanche && - gArgs.GetBoolArg("-enableavalanche", - AVALANCHE_DEFAULT_ENABLED)) { + if (!fAlreadyHave && g_avalanche && isAvalancheEnabled(gArgs)) { const bool preferred = isPreferredDownloadPeer(pfrom); LOCK(cs_proofrequest); diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2684,8 +2684,7 @@ InvalidChainFound(pindexNew); } - const bool fAvalancheEnabled = - gArgs.GetBoolArg("-enableavalanche", AVALANCHE_DEFAULT_ENABLED); + const bool fAvalancheEnabled = isAvalancheEnabled(gArgs); const bool fAutoUnpark = gArgs.GetBoolArg("-automaticunparking", !fAvalancheEnabled);