diff --git a/src/komodo_bitcoind.h b/src/komodo_bitcoind.h index 84a84935b..e2bc2b7f2 100644 --- a/src/komodo_bitcoind.h +++ b/src/komodo_bitcoind.h @@ -1425,7 +1425,7 @@ arith_uint256 komodo_adaptivepow_target(int32_t height,arith_uint256 bnTarget,ui tipdiff = (nTime - tipindex->nTime); if ( tipdiff > 13*ASSETCHAINS_BLOCKTIME ) diff = tipdiff; - if ( diff >= 13 * ASSETCHAINS_BLOCKTIME ) + if ( diff >= 13 * ASSETCHAINS_BLOCKTIME && (height < 3000 || tipdiff > 2*ASSETCHAINS_BLOCKTIME) ) { mult = diff - 12 * ASSETCHAINS_BLOCKTIME; mult = (mult / ASSETCHAINS_BLOCKTIME) * ASSETCHAINS_BLOCKTIME + ASSETCHAINS_BLOCKTIME / 2; diff --git a/src/main.cpp b/src/main.cpp index c47ae67cf..14c8e05ac 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5288,10 +5288,23 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta } // Check timestamp against prev - if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast()) + if ( ASSETCHAINS_ADAPTIVEPOW == 0 || nHeight < 3000 ) { - return state.Invalid(error("%s: block's timestamp is too early", __func__), - REJECT_INVALID, "time-too-old"); + if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast() ) + { + fprintf(stderr,"ht.%d too early %u vs %u\n",(int32_t)nHeight,(uint32_t)block.GetBlockTime(),(uint32_t)pindexPrev->GetMedianTimePast()); + return state.Invalid(error("%s: block's timestamp is too early", __func__), + REJECT_INVALID, "time-too-old"); + } + } + else + { + if ( block.GetBlockTime() <= pindexPrev->GetMedianTimePast() + 2*ASSETCHAINS_ADAPTIVEPOW*ASSETCHAINS_BLOCKTIME ) + { + fprintf(stderr,"ht.%d too early2 %u vs %u\n",(int32_t)nHeight,(uint32_t)block.GetBlockTime(),(uint32_t)pindexPrev->GetMedianTimePast()); + return state.Invalid(error("%s: block's timestamp is too early2", __func__), + REJECT_INVALID, "time-too-old"); + } } // Check that timestamp is not too far in the future diff --git a/src/miner.cpp b/src/miner.cpp index 6d404161f..fe7ca068a 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -123,7 +123,7 @@ public: void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev) { - pblock->nTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + pblock->nTime = std::max(pindexPrev->GetMedianTimePast()+1 + 2*ASSETCHAINS_ADAPTIVEPOW*ASSETCHAINS_BLOCKTIME, GetAdjustedTime()); // Updating time can change work required on testnet: if (consensusParams.nPowAllowMinDifficultyBlocksAfterHeight != boost::none) { @@ -567,7 +567,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 nLastBlockTx = nBlockTx; nLastBlockSize = nBlockSize; - blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1+ 2*ASSETCHAINS_ADAPTIVEPOW*ASSETCHAINS_BLOCKTIME, GetAdjustedTime()); //pblock->nTime = blocktime + 1; pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); @@ -596,8 +596,6 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 else { blocktime = GetAdjustedTime(); - //if ( blocktime > pindexPrev->GetMedianTimePast()+60 ) - // blocktime = pindexPrev->GetMedianTimePast() + 60; siglen = komodo_staked(txStaked, pblock->nBits, &blocktime, &txtime, &utxotxid, &utxovout, &utxovalue, utxosig); // if you skip this check it will create a block too far into the future and not pass ProcessBlock or AcceptBlock. // This has been moved from the mining loop to save CPU, and to also make ac_staked work with the verus miner. @@ -642,7 +640,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 txNew.vout[0].nValue = GetBlockSubsidy(nHeight,consensusParams) + nFees; //fprintf(stderr,"mine ht.%d with %.8f\n",nHeight,(double)txNew.vout[0].nValue/COIN); txNew.nExpiryHeight = 0; - txNew.nLockTime = std::max(pindexPrev->GetMedianTimePast()+1, GetAdjustedTime()); + txNew.nLockTime = std::max(pindexPrev->GetMedianTimePast()+1+ 2*ASSETCHAINS_ADAPTIVEPOW*ASSETCHAINS_BLOCKTIME, GetAdjustedTime()); if ( ASSETCHAINS_SYMBOL[0] == 0 && IS_KOMODO_NOTARY != 0 && My_notaryid >= 0 ) txNew.vout[0].nValue += 5000; diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 4814d34dd..e31dbd396 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -837,7 +837,10 @@ UniValue getblocktemplate(const UniValue& params, bool fHelp) result.push_back(Pair("PoSperc", (int64_t)PoSperc)); result.push_back(Pair("ac_staked", (int64_t)ASSETCHAINS_STAKED)); result.push_back(Pair("origtarget", hashTarget.GetHex())); - } else result.push_back(Pair("target", hashTarget.GetHex())); + } + else if ( ASSETCHAINS_ADAPTIVEPOW != 0 ) + result.push_back(Pair("target",komodo_adaptivepow_target((int32_t)(pindexPrev->GetHeight()+1),hashTarget,pblock->nTime).GetHex())); + else result.push_back(Pair("target", hashTarget.GetHex())); result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1)); result.push_back(Pair("mutable", aMutable)); result.push_back(Pair("noncerange", "00000000ffffffff"));