Browse Source

Fixed RegTest download timeout.

cn_mining
Jianping Wu 6 years ago
parent
commit
0b30d4911c
  1. 4
      src/chainparams.cpp
  2. 4
      src/net_processing.cpp
  3. 20
      src/rpc/mining.cpp

4
src/chainparams.cpp

@ -284,8 +284,8 @@ public: @@ -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

4
src/net_processing.cpp

@ -3561,9 +3561,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto, std::atomic<bool>& interruptM @@ -3561,9 +3561,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto, std::atomic<bool>& 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;

20
src/rpc/mining.cpp

@ -300,6 +300,24 @@ UniValue CN_JSONRPCError(int code, const std::string& message) @@ -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) @@ -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)

Loading…
Cancel
Save