From d516a21d54aed18aa678b4f556fe28758b6b286b Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 11 Jul 2020 11:10:15 -0400 Subject: [PATCH] Create setter to modify blocktime consensus params at run-time --- src/chainparams.cpp | 8 ++++++++ src/chainparams.h | 1 + src/main.cpp | 12 +++++------- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 0a2b819e7..f14e2d9ef 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -544,6 +544,14 @@ int32_t MAX_BLOCK_SIZE(int32_t height) else return(2000000); } +// Change the Hush blocktime at run-time(!) +void hush_changeblocktime() +{ + pCurrentParams->consensus.nMaxFutureBlockTime = 7 * ASSETCHAINS_BLOCKTIME; + pCurrentParams->consensus.nPowTargetSpacing = ASSETCHAINS_BLOCKTIME; + fprintf(stderr,"HUSH blocktime changing to %d seconds\n",ASSETCHAINS_BLOCKTIME); +} + void komodo_setactivation(int32_t height) { pCurrentParams->consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight = height; diff --git a/src/chainparams.h b/src/chainparams.h index daa16af8c..7bd1057ec 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core 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. diff --git a/src/main.cpp b/src/main.cpp index 00d470573..d4426e181 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -85,6 +85,7 @@ int32_t komodo_block2pubkey33(uint8_t *pubkey33,CBlock *block); //void komodo_broadcast(CBlock *pblock,int32_t limit); bool Getscriptaddress(char *destaddr,const CScript &scriptPubKey); void komodo_setactivation(int32_t height); +void hush_changeblocktime(); void komodo_pricesupdate(int32_t height,CBlock *pblock); BlockMap mapBlockIndex; @@ -3233,9 +3234,8 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex int nHeight = pindex->pprev->GetHeight(); if (ishush3 && (ASSETCHAINS_BLOCKTIME != 150) && (nHeight < nFirstHalvingHeight)) { LogPrintf("%s: Setting blocktime to 150s at height %d!\n",__func__,nHeight); - ASSETCHAINS_BLOCKTIME = 150; - Params.GetConsensus().nMaxFutureBlockTime = 7 * ASSETCHAINS_BLOCKTIME; - Params.GetConsensus().nPowTargetSpacing = ASSETCHAINS_BLOCKTIME; + ASSETCHAINS_BLOCKTIME = 150; + hush_changeblocktime(); } @@ -3388,8 +3388,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin if (ishush3 && (ASSETCHAINS_BLOCKTIME != 75) && (chainActive.Height() >= nFirstHalvingHeight)) { LogPrintf("%s: Blocktime halving to 75s at height %d!\n",__func__,pindex->GetHeight()); ASSETCHAINS_BLOCKTIME = 75; - Params.GetConsensus().nMaxFutureBlockTime = 7 * ASSETCHAINS_BLOCKTIME; - Params.GetConsensus().nPowTargetSpacing = ASSETCHAINS_BLOCKTIME; + hush_changeblocktime(); } bool fExpensiveChecks = true; @@ -3992,8 +3991,7 @@ void static UpdateTip(CBlockIndex *pindexNew) { if (ASSETCHAINS_BLOCKTIME != 75 && (chainActive.Height() >= nFirstHalvingHeight)) { LogPrintf("%s: Blocktime halving to 75s at height %d!\n",__func__,chainActive.Height()); ASSETCHAINS_BLOCKTIME = 75; - Params.GetConsensus().nMaxFutureBlockTime = 7 * ASSETCHAINS_BLOCKTIME; - Params.GetConsensus().nPowTargetSpacing = ASSETCHAINS_BLOCKTIME; + hush_changeblocktime(); } }