diff --git a/src/chainparams.cpp b/src/chainparams.cpp index c92bfe44b8f..87ad89716a4 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -309,15 +309,20 @@ void *chainparams_commandline(void *ptr) (20000, uint256S("0xb0e8cb9f77aaa7ff5bd90d6c08d06f4c4bf03e00c2b8a35a042e760845590c8a")) (30000, uint256S("0xf2112ca577338ad7104bf905fa6a63d36b17a86f914c97b73cd31d43fcd7557c")) (40000, uint256S("0x00000000008f83378dab727864b763ce91a4ea5f75d55939c0c1390cfb8c38f1")) - (49170, uint256S("0x2add646c0089871ec2379f02f7cd60b3af6efd9c152a6f16fc10925458c270cc")), - (int64_t)1529910234, // * UNIX timestamp of last checkpoint block - (int64_t)63661, // * total number of transactions between genesis and last checkpoint + (49170, uint256S("0x2add646c0089871ec2379f02f7cd60b3af6efd9c152a6f16fc10925458c270cc")) + (800200, uint256S("0xfa2d5e5f5fb42af9d6343fa93bbc776761341fd754a7e078004132bcd8403dd2")) + (1053660, uint256S("0x0000000000182c0fcba3ae9360417848dd03a8e0cb153f1ee8b4b8f72376de2b")) + (1796400, uint256S("0xeead7e4b5236de7c9fd782d28efa0a288d9188fd40ba7ca9804983035435caec")) + (2549420, uint256S("0x000000000000e1d2915791640dcee0bf36141cc58d436e158fcf126e529083a3")) + (2802250, uint256S("0x000000000002a5c44fd73dab43b2e0cac0dd2b5be6a22d03df5283ca8ee1f8bc")), + (int64_t)1700525524, // * UNIX timestamp of last checkpoint block + (int64_t)6318742, // * total number of transactions between genesis and last checkpoint // (the tx=... number in the SetBestChain debug.log lines) - (double)2777 // * estimated number of transactions per day after checkpoint + (double)1298 // * estimated number of transactions per day after checkpoint // total number of tx / (checkpoint block height / (24 * 24)) }; - mainParams.consensus.nMinimumChainWork = uint256S("0x000000000000000000000000000000000000000000000001a8f4f23f8b2d1f7e"); + mainParams.consensus.nMinimumChainWork = uint256S("0x00000000000d798fd9fc9c92867f40a7000000026e5624a2f47b71ea49cda473"); } else { diff --git a/src/checkpoints.cpp b/src/checkpoints.cpp index 75597436646..5ba83acd5f3 100644 --- a/src/checkpoints.cpp +++ b/src/checkpoints.cpp @@ -59,7 +59,7 @@ namespace Checkpoints { fWorkAfter = nExpensiveAfter*fSigcheckVerificationFactor; } - return fWorkBefore / (fWorkBefore + fWorkAfter); + return std::min(fWorkBefore / (fWorkBefore + fWorkAfter), 1.0); } int GetTotalBlocksEstimate(const CChainParams::CCheckpointData& data) diff --git a/src/main.cpp b/src/main.cpp index ff004e80e7d..f6aa5f20670 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7728,6 +7728,14 @@ bool RewindBlockIndex(const CChainParams& chainparams, bool& clearWitnessCaches) PruneBlockIndexCandidates(); + // Ensure that pindexBestHeader points to the block index entry with the most work; + // setBlockIndexCandidates entries are sorted by work, highest at the end. + { + std::set::reverse_iterator it = setBlockIndexCandidates.rbegin(); + assert(it != setBlockIndexCandidates.rend()); + pindexBestHeader = *it; + } + CheckBlockIndex(chainparams.GetConsensus()); if (!FlushStateToDisk(state, FLUSH_STATE_ALWAYS)) { @@ -8821,9 +8829,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, bool fAlreadyHave = AlreadyHave(inv); LogPrint("net", "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom->id); - if (!fAlreadyHave && !fImporting && !fReindex && inv.type != MSG_BLOCK) - pfrom->AskFor(inv); - if (inv.type == MSG_BLOCK) { UpdateBlockAvailability(pfrom->GetId(), inv.hash); if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count(inv.hash)) { @@ -8990,7 +8995,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, } - else if (strCommand == "tx") + else if (strCommand == "tx" && !IsInitialBlockDownload(chainparams)) { // Stop processing the transaction early if // We are in blocks only mode and peer is either not whitelisted or whitelistrelay is off @@ -9194,6 +9199,18 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, return true; } + // If we already know the last header in the message, then it contains + // no new information for us. In this case, we do not request + // more headers later. This prevents multiple chains of redundant + // getheader requests from running in parallel if triggered by incoming + // blocks while the node is still in initial headers sync. + // + // (Allow disabling optimization in case there are unexpected problems.) + bool hasNewHeaders = true; + if (GetBoolArg("-optimize-getheaders", true) && IsInitialBlockDownload(chainparams)) { + hasNewHeaders = (mapBlockIndex.count(headers.back().GetHash()) == 0); + } + CBlockIndex *pindexLast = NULL; BOOST_FOREACH(const CBlockHeader& header, headers) { /* @@ -9265,7 +9282,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, if (pindexLast) UpdateBlockAvailability(pfrom->GetId(), pindexLast->GetBlockHash()); - if (nCount == MAX_HEADERS_RESULTS && pindexLast) { + // Temporary, until we're sure the optimization works + if (nCount == MAX_HEADERS_RESULTS && pindexLast && !hasNewHeaders) { + LogPrint("net", "NO more getheaders (%d) to send to peer=%d (startheight:%d)\n", pindexLast->GetHeight(), pfrom->id, pfrom->nStartingHeight); + } + + if (nCount == MAX_HEADERS_RESULTS && pindexLast && hasNewHeaders) { // Headers message had its maximum size; the peer may have more headers. // TODO: optimize: if pindexLast is an ancestor of chainActive.Tip or pindexBestHeader, continue // from there instead. @@ -9540,7 +9562,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, // message would be undesirable as we transmit it ourselves. } - else { + else if (!(strCommand == "tx" || strCommand == "block" || strCommand == "headers" || strCommand == "alert")) { // Ignore unknown commands for extensibility LogPrint("net", "Unknown command \"%s\" from peer=%d\n", SanitizeString(strCommand), pfrom->id); }