From 9fd33dad8fe89b55add75b35639b8b43083a5422 Mon Sep 17 00:00:00 2001 From: Corbin Fox Date: Tue, 7 Aug 2018 15:35:23 -0600 Subject: [PATCH] Switching to DGW at a specific block. Widens N from 60 to 180 minutes for DGW. Future block rejection changed from 120 min to 12 min for DGW. --- src/chain.h | 1 + src/chainparams.cpp | 9 +++++++++ src/chainparams.h | 4 ++++ src/pow.cpp | 9 ++++----- src/rpc/blockchain.cpp | 7 +++++++ src/validation.cpp | 16 ++++++++++++++-- src/validation.h | 2 ++ 7 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/chain.h b/src/chain.h index 45bb663b53..a92a462578 100644 --- a/src/chain.h +++ b/src/chain.h @@ -20,6 +20,7 @@ * current network-adjusted time before the block will be accepted. */ static const int64_t MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60; +static const int64_t MAX_FUTURE_BLOCK_TIME_DGW = MAX_FUTURE_BLOCK_TIME / 10; /** * Timestamp window used as a grace period by code that compares external diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 3f0e6e03b3..98b40c8b1e 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -218,6 +218,9 @@ class CMainParams : public CChainParams { //Global Burn Address strGlobalBurnAddress = "RXBurnXXXXXXXXXXXXXXXXXXXXXXWUo9FV"; + + // DGW Activation + nDGWActivationBlock = 341200; /** RVN End **/ } }; @@ -319,6 +322,9 @@ class CTestNetParams : public CChainParams { // Global Burn Address strGlobalBurnAddress = "n1BurnXXXXXXXXXXXXXXXXXXXXXXU1qejP"; + + // DGW Activation + nDGWActivationBlock = 345000; /** RVN End **/ } }; @@ -470,6 +476,9 @@ class CRegTestParams : public CChainParams { // Global Burn Address strGlobalBurnAddress = "n1BurnXXXXXXXXXXXXXXXXXXXXXXU1qejP"; + + // DGW Activation + nDGWActivationBlock = 200; /** RVN End **/ } }; diff --git a/src/chainparams.h b/src/chainparams.h index 91aed041e9..56279be0d6 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -100,6 +100,8 @@ class CChainParams const std::string& IssueSubAssetBurnAddress() const { return strIssueSubAssetBurnAddress; } const std::string& IssueUniqueAssetBurnAddress() const { return strIssueUniqueAssetBurnAddress; } const std::string& GlobalBurnAddress() const { return strGlobalBurnAddress; } + + unsigned int DGWActivationBlock() const { return nDGWActivationBlock; } /** RVN End **/ protected: @@ -136,6 +138,8 @@ class CChainParams // Global Burn Address std::string strGlobalBurnAddress; + + unsigned int nDGWActivationBlock; /** RVN End **/ }; diff --git a/src/pow.cpp b/src/pow.cpp index 6828cb8e14..ce0f2cfe36 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -21,7 +21,7 @@ unsigned int static DarkGravityWave(const CBlockIndex* pindexLast, const CBlockH unsigned int nProofOfWorkLimit = UintToArith256(params.powLimit).GetCompact(); const arith_uint256 bnPowLimit = UintToArith256(params.powLimit); - int64_t nPastBlocks = 60; + int64_t nPastBlocks = 180; // ~3hr // make sure we have at least (nPastBlocks + 1) blocks, otherwise just return powLimit if (!pindexLast || pindexLast->nHeight < nPastBlocks) { @@ -126,15 +126,14 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead int btc = GetNextWorkRequiredBTC(pindexLast, pblock, params); int64_t nPrevBlockTime = (pindexLast->pprev ? pindexLast->pprev->GetBlockTime() : pindexLast->GetBlockTime()); - int version = (pblock->nVersion & 0xF0000000) >> 28; - if (version >= 3 && !CheckPOWHeightAssets(pindexLast->nHeight + 1)) { + if (IsDGWActive(pindexLast->nHeight + 1)) { LogPrint(BCLog::NET, "Block %s - version: %s: found next work required using DGW: [%s] (BTC would have been [%s]\t(%+d)\t(%0.3f%%)\t(%s sec))\n", - pindexLast->nHeight, pblock->nVersion, dgw, btc, btc - dgw, (float)(btc - dgw) * 100.0 / (float)dgw, pindexLast->GetBlockTime() - nPrevBlockTime); + pindexLast->nHeight + 1, pblock->nVersion, dgw, btc, btc - dgw, (float)(btc - dgw) * 100.0 / (float)dgw, pindexLast->GetBlockTime() - nPrevBlockTime); return dgw; } else { LogPrint(BCLog::NET, "Block %s - version: %s: found next work required using BTC: [%s] (DGW would have been [%s]\t(%+d)\t(%0.3f%%)\t(%s sec))\n", - pindexLast->nHeight, pblock->nVersion, btc, dgw, dgw - btc, (float)(dgw - btc) * 100.0 / (float)btc, pindexLast->GetBlockTime() - nPrevBlockTime); + pindexLast->nHeight + 1, pblock->nVersion, btc, dgw, dgw - btc, (float)(dgw - btc) * 100.0 / (float)btc, pindexLast->GetBlockTime() - nPrevBlockTime); return btc; } diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 78038c50c6..90109944b3 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1389,6 +1389,12 @@ UniValue getblockchaininfo(const JSONRPCRequest& request) obj.push_back(Pair("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1)); obj.push_back(Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex())); obj.push_back(Pair("difficulty", (double)GetDifficulty())); + if (IsDGWActive(chainActive.Height())) { + obj.push_back(Pair("difficulty_algorithm", "DGW-180")); + } else { + obj.push_back(Pair("difficulty_algorithm", "BTC")); + obj.push_back(Pair("DGW_activation_height", (int)Params().DGWActivationBlock())); + } obj.push_back(Pair("mediantime", (int64_t)chainActive.Tip()->GetMedianTimePast())); obj.push_back(Pair("verificationprogress", GuessVerificationProgress(Params().TxData(), chainActive.Tip()))); obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex())); @@ -1414,6 +1420,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request) const Consensus::Params& consensusParams = Params().GetConsensus(); //CBlockIndex* tip = chainActive.Tip(); + UniValue softforks(UniValue::VARR); UniValue bip9_softforks(UniValue::VOBJ); // softforks.push_back(SoftForkDesc("bip34", 2, tip, consensusParams)); diff --git a/src/validation.cpp b/src/validation.cpp index 8c0a664626..ae31d7ce3c 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3467,8 +3467,16 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationSta return state.Invalid(false, REJECT_INVALID, "time-too-old", "block's timestamp is too early"); // Check timestamp - if (block.GetBlockTime() > nAdjustedTime + MAX_FUTURE_BLOCK_TIME) - return state.Invalid(false, REJECT_INVALID, "time-too-new", "block timestamp too far in the future"); + if (IsDGWActive(pindexPrev->nHeight+1)) + { + if (block.GetBlockTime() > nAdjustedTime + MAX_FUTURE_BLOCK_TIME_DGW) + return state.Invalid(false, REJECT_INVALID, "time-too-new", "block timestamp too far in the future"); + } + else + { + if (block.GetBlockTime() > nAdjustedTime + MAX_FUTURE_BLOCK_TIME) + return state.Invalid(false, REJECT_INVALID, "time-too-new", "block timestamp too far in the future"); + } // Reject outdated version blocks when 95% (75% on testnet) of the network has upgraded: // check for version 2, 3 and 4 upgrades @@ -5021,6 +5029,10 @@ bool AreAssetsDeployed() { return fAssetsIsActive; } + +bool IsDGWActive(unsigned int nBlockNumber) { + return nBlockNumber >= Params().DGWActivationBlock(); +} /** RVN END */ class CMainCleanup diff --git a/src/validation.h b/src/validation.h index 5bd86c2a8b..e43f38b2f1 100644 --- a/src/validation.h +++ b/src/validation.h @@ -521,6 +521,8 @@ bool LoadMempool(); /** RVN START */ bool AreAssetsDeployed(); + +bool IsDGWActive(unsigned int nBlockNumber); /** RVN END */ #endif // RAVEN_VALIDATION_H