diff --git a/src/main.cpp b/src/main.cpp index 6876fc08e4..e04dd1c5d2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -47,6 +47,7 @@ uint256 hashBestChain = 0; CBlockIndex* pindexBest = NULL; set setBlockIndexValid; // may contain all CBlockIndex*'s that have validness >=BLOCK_VALID_TRANSACTIONS, and must contain those who aren't failed int64 nTimeBestReceived = 0; +int nAskedForBlocks = 0; int nScriptCheckThreads = 0; bool fImporting = false; bool fReindex = false; @@ -4876,9 +4877,14 @@ bool SendMessages(CNode* pto, bool fSendTrickle) } // Start block sync - if (pto->fStartSync && !fImporting && !fReindex) { - pto->fStartSync = false; - pto->PushGetBlocks(pindexBest, uint256(0)); + if (!pto->fAskedForBlocks && !fImporting && !fReindex && !pto->fClient && !pto->fOneShot && + !pto->fDisconnect && pto->fSuccessfullyConnected && + (pto->nStartingHeight > (nBestHeight - 144)) && + (pto->nVersion < NOBLKS_VERSION_START || pto->nVersion >= NOBLKS_VERSION_END)) { + nAskedForBlocks++; + pto->fAskedForBlocks = true; + if (pto->PushGetBlocks(pindexBest, uint256(0))) + printf("send initial getblocks peer=%d\n", pto->id); } // Resend wallet transactions that haven't gotten in a block yet diff --git a/src/main.h b/src/main.h index 5c263956f4..b0f9a686f3 100644 --- a/src/main.h +++ b/src/main.h @@ -121,6 +121,7 @@ extern bool fImporting; extern bool fReindex; extern bool fBenchmark; extern int nScriptCheckThreads; +extern int nAskedForBlocks; // Nodes sent a getblocks 0 extern bool fTxIndex; extern unsigned int nCoinCacheSize; extern CDarkSendPool darkSendPool; diff --git a/src/net.h b/src/net.h index 1cb9338cee..80d8e94559 100644 --- a/src/net.h +++ b/src/net.h @@ -194,6 +194,7 @@ public: bool fNetworkNode; bool fSuccessfullyConnected; bool fDisconnect; + bool fAskedForBlocks; // true when getblocks 0 sent // We use fRelayTxes for two purposes - // a) it allows us to not relay tx invs before receiving the peer's version message // b) the peer may tell us in their version message that we should not relay tx invs @@ -255,6 +256,7 @@ public: fSuccessfullyConnected = false; fDisconnect = false; hashCheckpointKnown = 0; + fAskedForBlocks = false; nRefCount = 0; nSendSize = 0; nSendOffset = 0;