Connect to peers signaling NODE_NETWORK_LIMITED when out-of-IBD

This commit is contained in:
Jonas Schnelli 2017-10-13 21:48:00 -07:00
parent 31c45a927e
commit 6fe57bdaac
No known key found for this signature in database
GPG key ID: 1EB776BB03C7922D
5 changed files with 18 additions and 2 deletions

View file

@ -2710,6 +2710,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn
fOneShot = false; fOneShot = false;
m_manual_connection = false; m_manual_connection = false;
fClient = false; // set by version message fClient = false; // set by version message
m_limited_node = false; // set by version message
fFeeler = false; fFeeler = false;
fSuccessfullyConnected = false; fSuccessfullyConnected = false;
fDisconnect = false; fDisconnect = false;

View file

@ -643,6 +643,7 @@ public:
bool fOneShot; bool fOneShot;
bool m_manual_connection; bool m_manual_connection;
bool fClient; bool fClient;
bool m_limited_node; //after BIP159
const bool fInbound; const bool fInbound;
std::atomic_bool fSuccessfullyConnected; std::atomic_bool fSuccessfullyConnected;
std::atomic_bool fDisconnect; std::atomic_bool fDisconnect;

View file

@ -892,6 +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;
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;
@ -1642,7 +1643,13 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
pfrom->cleanSubVer = cleanSubVer; pfrom->cleanSubVer = cleanSubVer;
} }
pfrom->nStartingHeight = nStartingHeight; pfrom->nStartingHeight = nStartingHeight;
pfrom->fClient = !(nServices & NODE_NETWORK);
// set nodes not relaying blocks and tx and not serving (parts) of the historical blockchain as "clients"
pfrom->fClient = (!(nServices & NODE_NETWORK) && !(nServices & NODE_NETWORK_LIMITED));
// set nodes not capable of serving the complete blockchain history as "limited nodes"
pfrom->m_limited_node = (!(nServices & NODE_NETWORK) && (nServices & NODE_NETWORK_LIMITED));
{ {
LOCK(pfrom->cs_filter); LOCK(pfrom->cs_filter);
pfrom->fRelayTxes = fRelay; // set to true after we get the first filter* message pfrom->fRelayTxes = fRelay; // set to true after we get the first filter* message
@ -3611,7 +3618,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto, std::atomic<bool>& interruptM
// Message: getdata (blocks) // Message: getdata (blocks)
// //
std::vector<CInv> vGetData; std::vector<CInv> vGetData;
if (!pto->fClient && (fFetch || !IsInitialBlockDownload()) && state.nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) { if (!pto->fClient && ((fFetch && !pto->m_limited_node) || !IsInitialBlockDownload()) && state.nBlocksInFlight < MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
std::vector<const CBlockIndex*> vToDownload; std::vector<const CBlockIndex*> vToDownload;
NodeId staller = -1; NodeId staller = -1;
FindNextBlocksToDownload(pto->GetId(), MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight, vToDownload, staller, consensusParams); FindNextBlocksToDownload(pto->GetId(), MAX_BLOCKS_IN_TRANSIT_PER_PEER - state.nBlocksInFlight, vToDownload, staller, consensusParams);

View file

@ -12,6 +12,8 @@
# include <arpa/inet.h> # include <arpa/inet.h>
#endif #endif
std::atomic<bool> g_initial_block_download_completed(false);
namespace NetMsgType { namespace NetMsgType {
const char *VERSION="version"; const char *VERSION="version";
const char *VERACK="verack"; const char *VERACK="verack";

View file

@ -15,6 +15,7 @@
#include <uint256.h> #include <uint256.h>
#include <version.h> #include <version.h>
#include <atomic>
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
@ -277,6 +278,7 @@ 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.
* *
@ -302,6 +304,9 @@ enum ServiceFlags : uint64_t {
* 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) { static 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); return ServiceFlags(NODE_NETWORK | NODE_WITNESS);
} }