From bb6565d9661e2405f6ff543ef5256bc8932709f3 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 24 Jun 2020 20:49:53 -0400 Subject: [PATCH] Block time halving at height 340000 --- src/main.cpp | 22 ++++++++++++++++++---- src/pow.cpp | 5 ++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 73f49eb38..5b70ed2fd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3350,6 +3350,8 @@ static int64_t nTimeTotal = 0; bool FindBlockPos(int32_t tmpflag,CValidationState &state, CDiskBlockPos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown = false); bool ReceivedBlockTransactions(const CBlock &block, CValidationState& state, CBlockIndex *pindexNew, const CDiskBlockPos& pos); +int32_t nFirstHalvingHeight = 340000; + bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& view, bool fJustCheck,bool fCheckPOW) { CDiskBlockPos blockPos; @@ -3362,15 +3364,20 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin AssertLockHeld(cs_main); bool ishush3 = strncmp(ASSETCHAINS_SYMBOL, "HUSH3",5) == 0 ? true : false; + + // At startup, HUSH3 doesn't know a block height yet and so we must wait until + // connecting a block to set our private/blocktime flags, which are height-dependent if(!ASSETCHAINS_PRIVATE && ishush3) { unsigned int nHeight = pindex->GetHeight(); - if(nHeight >= 340000) { - // At startup, HUSH3 doesn't know a block height yet and so we must wait until - // connecting a block - fprintf(stderr, "%s: Going full z2z at height %d!\n",__func__,nHeight); + if(nHeight >= nFirstHalvingHeight) { + fprintf(stderr, "%s: Going full z2z at height %d!\n",__func__,pindex->GetHeight()); ASSETCHAINS_PRIVATE = 1; } } + if (ishush3 && (ASSETCHAINS_BLOCKTIME != 75) && (chainActive.Height() >= nFirstHalvingHeight)) { + LogPrintf("%s: Blocktime halving to 75s at height %d!\n",__func__,pindex->GetHeight()); + ASSETCHAINS_BLOCKTIME = 75; + } bool fExpensiveChecks = true; if (fCheckpointsEnabled) { @@ -3968,6 +3975,13 @@ void static UpdateTip(CBlockIndex *pindexNew) { progress = (longestchain > 0 ) ? (double) chainActive.Height() / longestchain : 1.0; } + if(ishush3) { + if (ASSETCHAINS_BLOCKTIME != 75 && (chainActive.Height() >= nFirstHalvingHeight)) { + LogPrintf("%s: Blocktime halving to 75s at height %d!\n",__func__,chainActive.Height()); + ASSETCHAINS_BLOCKTIME = 75; + } + } + LogPrintf("%s: new best=%s height=%d log2_work=%.8g tx=%lu date=%s progress=%f cache=%.1fMiB(%utx)\n", __func__, chainActive.LastTip()->GetBlockHash().ToString(), chainActive.Height(), log(chainActive.Tip()->chainPower.chainWork.getdouble())/log(2.0), diff --git a/src/pow.cpp b/src/pow.cpp index 79c41feb4..6d0262699 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2019 The Hush developers +// Copyright (c) 2019-2020 The Hush developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. @@ -298,6 +298,9 @@ arith_uint256 zawy_TSA_EMA(int32_t height,int32_t tipdiff,arith_uint256 prevTarg unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params& params) { + if (pindexLast->GetHeight() == 340000) { + LogPrintf("%s: Using blocktime=%d\n",__func__,ASSETCHAINS_BLOCKTIME); + } if (ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH && ASSETCHAINS_STAKED == 0) return lwmaGetNextWorkRequired(pindexLast, pblock, params);