From 0b30d4911cc1f3a97996f2ac57f8e6838e9e1287 Mon Sep 17 00:00:00 2001 From: Jianping Wu Date: Wed, 27 Mar 2019 22:07:00 -0700 Subject: [PATCH] Fixed RegTest download timeout. --- src/chainparams.cpp | 4 ++-- src/net_processing.cpp | 4 +--- src/rpc/mining.cpp | 20 +++++++++++++++++++- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 39a924785..944ef2ae9 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -284,8 +284,8 @@ public: consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in rpc activation tests) consensus.BIP66Height = 1251; // BIP66 activated on regtest (Used in rpc activation tests) consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"); - consensus.nPowTargetTimespan = 20; // 20 second - consensus.nPowTargetSpacing = 20; // 20 second + consensus.nPowTargetTimespan = 2.0 * 60; // Two minutes + consensus.nPowTargetSpacing = 2.0 * 60; // Two minutes consensus.fPowAllowMinDifficultyBlocks = true; consensus.fPowNoRetargeting = true; consensus.nRuleChangeActivationThreshold = 108; // 75% for testchains diff --git a/src/net_processing.cpp b/src/net_processing.cpp index f11affbd1..7d17147ca 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -3561,9 +3561,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto, std::atomic& interruptM if (state.vBlocksInFlight.size() > 0) { QueuedBlock &queuedBlock = state.vBlocksInFlight.front(); int nOtherPeersWithValidatedDownloads = nPeersWithValidatedDownloads - (state.nBlocksInFlightValidHeaders > 0); - // Increase the block downloading timeout for RegTest, as Cryptonight hashing takes more time. - int64_t powTargetSpacing = (consensusParams.nPowTargetSpacing == 20) ? 40 : consensusParams.nPowTargetSpacing; - if (nNow > state.nDownloadingSince + powTargetSpacing * (BLOCK_DOWNLOAD_TIMEOUT_BASE + BLOCK_DOWNLOAD_TIMEOUT_PER_PEER * nOtherPeersWithValidatedDownloads)) { + if (nNow > state.nDownloadingSince + consensusParams.nPowTargetSpacing * (BLOCK_DOWNLOAD_TIMEOUT_BASE + BLOCK_DOWNLOAD_TIMEOUT_PER_PEER * nOtherPeersWithValidatedDownloads)) { LogPrintf("Timeout downloading block %s from peer=%d, disconnecting\n", queuedBlock.hash.ToString(), pto->GetId()); pto->fDisconnect = true; return true; diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 33a2ad5cf..61498ac7b 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -300,6 +300,24 @@ UniValue CN_JSONRPCError(int code, const std::string& message) // NOTE: Assumes a conclusive result; if result is inconclusive, it must be handled by caller static UniValue BIP22ValidationResult(const CValidationState& state) +{ + if (state.IsValid()) + return NullUniValue; + + std::string strRejectReason = state.GetRejectReason(); + if (state.IsError()) + throw JSONRPCError(RPC_VERIFY_ERROR, strRejectReason); + if (state.IsInvalid()) + { + if (strRejectReason.empty()) + return "rejected"; + return strRejectReason; + } + // Should be impossible + return "valid?"; +} + +static UniValue BIP22ValidationResult_CN(const CValidationState& state) { if (state.IsValid()) { UniValue result(UniValue::VOBJ); @@ -1194,7 +1212,7 @@ UniValue submitblock(const JSONRPCRequest& request) if (!sc.found) { throw CN_JSONRPCError(CORE_RPC_ERROR_CODE_BLOCK_NOT_ACCEPTED, "inconclusive"); } - return BIP22ValidationResult(sc.state); + return BIP22ValidationResult_CN(sc.state); } UniValue estimatefee(const JSONRPCRequest& request)