Add setter for g_initial_block_download_completed

This commit is contained in:
Jonas Schnelli 2018-02-17 21:28:50 +11:00
parent 3f56df5b75
commit eb9183535d
No known key found for this signature in database
GPG Key ID: 1EB776BB03C7922D
3 changed files with 17 additions and 9 deletions

View File

@ -892,7 +892,7 @@ void PeerLogicValidation::UpdatedBlockTip(const CBlockIndex *pindexNew, const CB
const int nNewHeight = pindexNew->nHeight; const int nNewHeight = pindexNew->nHeight;
connman->SetBestHeight(nNewHeight); connman->SetBestHeight(nNewHeight);
g_initial_block_download_completed = !fInitialDownload; SetServiceFlagsIBDCache(!fInitialDownload);
if (!fInitialDownload) { if (!fInitialDownload) {
// Find the hashes of all blocks that weren't previously in the best chain. // Find the hashes of all blocks that weren't previously in the best chain.
std::vector<uint256> vHashes; std::vector<uint256> vHashes;

View File

@ -12,7 +12,7 @@
# include <arpa/inet.h> # include <arpa/inet.h>
#endif #endif
std::atomic<bool> g_initial_block_download_completed(false); static std::atomic<bool> g_initial_block_download_completed(false);
namespace NetMsgType { namespace NetMsgType {
const char *VERSION="version"; const char *VERSION="version";
@ -129,6 +129,17 @@ bool CMessageHeader::IsValid(const MessageStartChars& pchMessageStartIn) const
} }
ServiceFlags GetDesirableServiceFlags(ServiceFlags services) {
if ((services & NODE_NETWORK_LIMITED) && g_initial_block_download_completed) {
return ServiceFlags(NODE_NETWORK_LIMITED | NODE_WITNESS);
}
return ServiceFlags(NODE_NETWORK | NODE_WITNESS);
}
void SetServiceFlagsIBDCache(bool state) {
g_initial_block_download_completed = state;
}
CAddress::CAddress() : CService() CAddress::CAddress() : CService()
{ {

View File

@ -278,7 +278,6 @@ enum ServiceFlags : uint64_t {
// BIP process. // BIP process.
}; };
extern std::atomic<bool> g_initial_block_download_completed;
/** /**
* Gets the set of service flags which are "desirable" for a given peer. * Gets the set of service flags which are "desirable" for a given peer.
* *
@ -303,12 +302,10 @@ extern std::atomic<bool> g_initial_block_download_completed;
* If the NODE_NONE return value is changed, contrib/seeds/makeseeds.py * If the NODE_NONE return value is changed, contrib/seeds/makeseeds.py
* should be updated appropriately to filter for the same nodes. * should be updated appropriately to filter for the same nodes.
*/ */
static ServiceFlags GetDesirableServiceFlags(ServiceFlags services) { ServiceFlags GetDesirableServiceFlags(ServiceFlags services);
if ((services & NODE_NETWORK_LIMITED) && g_initial_block_download_completed) {
return ServiceFlags(NODE_NETWORK_LIMITED | NODE_WITNESS); /** Set the current IBD status in order to figure out the desirable service flags */
} void SetServiceFlagsIBDCache(bool status);
return ServiceFlags(NODE_NETWORK | NODE_WITNESS);
}
/** /**
* A shortcut for (services & GetDesirableServiceFlags(services)) * A shortcut for (services & GetDesirableServiceFlags(services))