From 4b2cf9258cc6239a31d836ed072fb67ecd9faa45 Mon Sep 17 00:00:00 2001 From: barrystyle Date: Mon, 10 Jun 2019 05:45:12 +0800 Subject: [PATCH] speed up sync, add more default seeds --- src/chainparamsseeds.h | 6 +++++- src/validation.cpp | 17 +++++++++++------ src/validation.h | 4 ++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/chainparamsseeds.h b/src/chainparamsseeds.h index 499508f4f..db8f37517 100644 --- a/src/chainparamsseeds.h +++ b/src/chainparamsseeds.h @@ -8,6 +8,10 @@ * IPv4 as well as onion addresses are wrapped inside an IPv6 address accordingly. */ static SeedSpec6 pnSeed6_main[] = { - {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x2d,0x4d,0xce,0x67}, 55555} + {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x2d,0x4d,0xce,0x67}, 55555}, + {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x6c,0x3d,0xd7,0x7d}, 55555}, + {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x9b,0x8a,0xa1,0xf6}, 55555}, + {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x9b,0x8a,0xea,0x49}, 55555}, + {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0x2d,0x3f,0x53,0xd0}, 55555} }; #endif diff --git a/src/validation.cpp b/src/validation.cpp index 4392b50cf..f171d28ac 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1065,7 +1065,7 @@ static bool WriteBlockToDisk(const CBlock& block, CDiskBlockPos& pos, const CMes return true; } -bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams) +bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, int nHeight, const Consensus::Params& consensusParams) { block.SetNull(); @@ -1082,8 +1082,10 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus: return error("%s: Deserialize or I/O error - %s at %s", __func__, e.what(), pos.ToString()); } - // Check the header - if (!CheckProofOfWork(block.GetPoWHash(), block.nBits, consensusParams)) + // The idea here is that we check 1/36 block; which is less than a reorg in the case of a bad node, + // while not having to smash the cpu each time we read a block in. + if (nHeight % 36 == 0) + if (!CheckProofOfWork(block.GetPoWHash(), block.nBits, consensusParams)) return error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString()); return true; @@ -1097,7 +1099,8 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus blockPos = pindex->GetBlockPos(); } - if (!ReadBlockFromDisk(block, blockPos, consensusParams)) + int nHeight = pindex->nHeight; + if (!ReadBlockFromDisk(block, blockPos, nHeight, consensusParams)) return false; if (block.GetHash() != pindex->GetBlockHash()) return error("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s", @@ -3077,7 +3080,8 @@ static bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos, static bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW = true) { // Check proof of work matches claimed amount - if (fCheckPOW && !CheckProofOfWork(block.GetPoWHash(), block.nBits, consensusParams)) + if (!IsInitialBlockDownload()) + if (fCheckPOW && !CheckProofOfWork(block.GetPoWHash(), block.nBits, consensusParams)) return state.DoS(50, false, REJECT_INVALID, "high-hash", false, "proof of work failed"); return true; @@ -4500,7 +4504,8 @@ bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskB while (range.first != range.second) { std::multimap::iterator it = range.first; std::shared_ptr pblockrecursive = std::make_shared(); - if (ReadBlockFromDisk(*pblockrecursive, it->second, chainparams.GetConsensus())) + const int nHeight = mapBlockIndex[it->first]->nHeight; + if (ReadBlockFromDisk(*pblockrecursive, it->second, nHeight, chainparams.GetConsensus())) { LogPrint(BCLog::REINDEX, "%s: Processing out of order child %s of %s\n", __func__, pblockrecursive->GetHash().ToString(), head.ToString()); diff --git a/src/validation.h b/src/validation.h index 65a378d8b..6b0f215b1 100644 --- a/src/validation.h +++ b/src/validation.h @@ -83,7 +83,7 @@ static const int MAX_SCRIPTCHECK_THREADS = 16; /** -par default (number of script-checking threads, 0 = auto) */ static const int DEFAULT_SCRIPTCHECK_THREADS = 0; /** Number of blocks that can be requested at any given time from a single peer. */ -static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 16; +static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 512; /** Timeout in seconds during which a peer must stall block download progress before being disconnected. */ static const unsigned int BLOCK_STALLING_TIMEOUT = 2; /** Number of headers sent in one getheaders result. We rely on the assumption that if a peer sends @@ -391,7 +391,7 @@ void InitScriptExecutionCache(); /** Functions for disk access for blocks */ -bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams); +bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, int nHeight, const Consensus::Params& consensusParams); bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams); bool ReadRawBlockFromDisk(std::vector& block, const CDiskBlockPos& pos, const CMessageHeader::MessageStartChars& message_start); bool ReadRawBlockFromDisk(std::vector& block, const CBlockIndex* pindex, const CMessageHeader::MessageStartChars& message_start);