From 75c3442091e8285c6133ad14025800d142d50857 Mon Sep 17 00:00:00 2001 From: blondfrogs Date: Thu, 2 Aug 2018 14:49:44 -0600 Subject: [PATCH 1/2] Fix sync issue caused by DGW --- src/pow.cpp | 36 +++++++++++++++++++++++++++++++----- src/pow.h | 1 + src/validation.cpp | 2 +- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/pow.cpp b/src/pow.cpp index fa3680d018..e9a451e4e1 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -12,6 +12,7 @@ #include "uint256.h" #include "util.h" #include "validation.h" +#include "chainparams.h" unsigned int static DarkGravityWave(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { /* current difficulty formula, dash - DarkGravity v3, written by Evan Duffield - evan@dash.org */ @@ -123,16 +124,19 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead int dgw = DarkGravityWave(pindexLast, pblock, params); int btc = GetNextWorkRequiredBTC(pindexLast, pblock, params); int64_t nPrevBlockTime = (pindexLast->pprev ? pindexLast->pprev->GetBlockTime() : pindexLast->GetBlockTime()); - if (AreAssetsDeployed()) { - LogPrintf("Block %s: found next work required using DGW: [%s] (BTC would have been [%s]\t(%+d)\t(%0.3f%%)\t(%s sec))\n", - pindexLast->nHeight, dgw, btc, btc - dgw, (float)(btc - dgw) * 100.0 / (float)dgw, pindexLast->GetBlockTime() - nPrevBlockTime); + + int version = (pblock->nVersion & 0xF0000000) >> 28; + if (version >= 3 && !CheckPOWHeightAssets(pindexLast->nHeight + 1)) { + LogPrintf("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); return dgw; } else { - LogPrintf("Block %s: found next work required using BTC: [%s] (DGW would have been [%s]\t(%+d)\t(%0.3f%%)\t(%s sec))\n", - pindexLast->nHeight, btc, dgw, dgw - btc, (float)(dgw - btc) * 100.0 / (float)btc, pindexLast->GetBlockTime() - nPrevBlockTime); + LogPrintf("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); return btc; } + } unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params& params) @@ -178,3 +182,25 @@ bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params& return true; } + +// Used to determine if one of these block heights is failing the check because these were mined with block version of 3 before RIP2 was active. +bool CheckPOWHeightAssets(const int height) +{ + if (Params().NetworkIDString() == "test") { + return (height == 319456 || + height == 319468 || + height == 319469 || + height == 319494 || + height == 319500 || + height == 319501 || + height == 319502 || + height == 319520 || + height == 319522 || + height == 319532 || + height == 319533); + } else { + return false; + } + + +} diff --git a/src/pow.h b/src/pow.h index 537d828e1b..cb60404e09 100644 --- a/src/pow.h +++ b/src/pow.h @@ -17,6 +17,7 @@ class uint256; unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params&); unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params&); +bool CheckPOWHeightAssets(const int height); /** Check whether a block hash satisfies the proof-of-work requirement specified by nBits */ bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params&); diff --git a/src/validation.cpp b/src/validation.cpp index dd5481fea0..8c0a664626 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3359,7 +3359,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::P for (const auto& tx : block.vtx) if (!CheckTransaction(*tx, state, passets, false)) return state.Invalid(false, state.GetRejectCode(), state.GetRejectReason(), - strprintf("Transaction check failed (tx hash %s) %s", tx->GetHash().ToString(), state.GetDebugMessage())); + strprintf("Transaction check failed (tx hash %s) %s %s", tx->GetHash().ToString(), state.GetDebugMessage(), state.GetRejectReason())); unsigned int nSigOps = 0; for (const auto& tx : block.vtx) From f000fcc88d1203d8155e86ef646555d68feabdcc Mon Sep 17 00:00:00 2001 From: blondfrogs Date: Thu, 2 Aug 2018 17:47:34 -0600 Subject: [PATCH 2/2] Add mining logs to debug=net --- configure.ac | 2 +- src/pow.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 0f691a0472..f8660f8f27 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N) AC_PREREQ([2.60]) define(_CLIENT_VERSION_MAJOR, 2) define(_CLIENT_VERSION_MINOR, 0) -define(_CLIENT_VERSION_REVISION, 1) +define(_CLIENT_VERSION_REVISION, 2) define(_CLIENT_VERSION_BUILD, 0) define(_CLIENT_VERSION_IS_RELEASE, true) define(_COPYRIGHT_YEAR, 2018) diff --git a/src/pow.cpp b/src/pow.cpp index e9a451e4e1..6828cb8e14 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -13,6 +13,7 @@ #include "util.h" #include "validation.h" #include "chainparams.h" +#include "tinyformat.h" unsigned int static DarkGravityWave(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { /* current difficulty formula, dash - DarkGravity v3, written by Evan Duffield - evan@dash.org */ @@ -127,12 +128,12 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead int version = (pblock->nVersion & 0xF0000000) >> 28; if (version >= 3 && !CheckPOWHeightAssets(pindexLast->nHeight + 1)) { - LogPrintf("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); + 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); return dgw; } else { - LogPrintf("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", + 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); return btc; }