From 310ed2a4347bee6003a04e196afc2d9ffc079409 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 9 Dec 2020 20:49:23 -0500 Subject: [PATCH] This Shit Seems To Work --- src/main.cpp | 34 +++++++++++++++++++++++++--------- src/pow.cpp | 2 +- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 8d2e803c2..bc169ddf6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5234,16 +5234,32 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta int nHeight = pindexPrev->GetHeight()+1; + bool ishush3 = strncmp(SMART_CHAIN_SYMBOL, "HUSH3",5) == 0 ? true : false; // Check Proof-of-Work - if ( (SMART_CHAIN_SYMBOL[0] != 0 || nHeight < 235300 || nHeight > 236000) && block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams)) { - cout << "Incorrect Proof-of-Work! " << - block.nBits << " block.nBits vs. calc " << - GetNextWorkRequired(pindexPrev, &block, consensusParams) << - " for height " << nHeight << " " << - block.GetHash().ToString() << " with time " << - block.GetBlockTime() << endl; + if(ishush3) { + unsigned int nNextWork = GetNextWorkRequired(pindexPrev, &block, consensusParams); + unsigned int diffbits = nNextWork > block.nBits ? nNextWork-block.nBits : block.nBits-nNextWork; + + // The change of blocktime from 150s to 75s seems to have messed up our difficulty calc + if ((nHeight < 340000 || nHeight > 342500) && block.nBits != nNextWork) { + cout << "Incorrect HUSH Proof-of-Work at height " << nHeight << " " << block.nBits << " block.nBits vs. calc " << + nNextWork << " " << block.GetHash().ToString() << " @ " << block.GetBlockTime() << endl; + + return state.DoS(100, error("%s: Incorrect Proof-of-Work at height %d diffbits=%u", __func__, nHeight, diffbits), REJECT_INVALID, "bad-diffbits"); + } else { + fprintf(stderr,"%s: Ignoring weird nBits %u with diffbits %u for height %d\n", __func__, block.nBits, diffbits, nHeight); + } + } else { + // TODO: unify this with the code above + if ( block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams)) { + cout << "Incorrect Proof-of-Work! " << block.nBits << " block.nBits vs. calc " << + GetNextWorkRequired(pindexPrev, &block, consensusParams) << + " for height " << nHeight << " " << + block.GetHash().ToString() << " with time " << + block.GetBlockTime() << endl; - return state.DoS(100, error("%s: Incorrect Proof-of-Work at height %d", __func__, nHeight), REJECT_INVALID, "bad-diffbits"); + return state.DoS(100, error("%s: Incorrect Proof-of-Work at height %d", __func__, nHeight), REJECT_INVALID, "bad-diffbits"); + } } // Check timestamp against prev @@ -5409,7 +5425,7 @@ bool AcceptBlockHeader(int32_t *futureblockp,const CBlockHeader& block, CValidat return false; } if(fDebug) { - fprintf(stderr,"%s: ContextualCheckBlockHeader passed\n", hash.ToString()); + fprintf(stderr,"%s: ContextualCheckBlockHeader passed: %s\n", __func__, hash.ToString().c_str()); } if (pindex == NULL) { diff --git a/src/pow.cpp b/src/pow.cpp index 256f61c19..d18d75ca2 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -544,7 +544,7 @@ unsigned int CalculateNextWorkRequired(arith_uint256 bnAvg, LogPrint("pow", "After: %08x %s\n", bnNew.GetCompact(), bnNew.ToString()); if(fDebug) - fprintf(stderr,"%s: nbits=%u\n",__func__,nbits); + fprintf(stderr,"%s: nbits=%u\n",__func__,bnNew.GetCompact()); return bnNew.GetCompact(); }