diff --git a/src/coins.h b/src/coins.h index fcc32caae..85cb69d5c 100644 --- a/src/coins.h +++ b/src/coins.h @@ -267,6 +267,14 @@ public: } return ret; } + + int64_t TotalTxValue() const { + int64_t total = 0; + BOOST_FOREACH(const CTxOut &out, vout) { + total += out.nValue; + } + return total; + } }; class CCoinsKeyHasher diff --git a/src/main.cpp b/src/main.cpp index fb9301225..7a8d2c2b1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2057,9 +2057,9 @@ namespace Consensus { REJECT_INVALID, "bad-txns-premature-spend-of-coinbase"); } - // ensure that zeroth output of coinbases are not still time locked - uint64_t unlockTime = tx.UnlockTime(0); - if (nSpendHeight >= unlockTime) { + // ensure that output of coinbases are not still time locked + uint64_t unlockTime = komodo_block_unlocktime(coins->nHeight); + if (nSpendHeight < unlockTime && coins->TotalTxValue() >= ASSETCHAINS_TIMELOCKGTE) { return state.Invalid( error("CheckInputs(): tried to spend coinbase that is timelocked until block %d", unlockTime), REJECT_INVALID, "bad-txns-premature-spend-of-coinbase"); @@ -2563,17 +2563,20 @@ void PartitionCheck(bool (*initialDownloadCheck)(), CCriticalSection& cs, const const int FIFTY_YEARS = 50*365*24*60*60; double alertThreshold = 1.0 / (FIFTY_YEARS / SPAN_SECONDS); - if (p <= alertThreshold && nBlocks < BLOCKS_EXPECTED) + if (bestHeader->nHeight > BLOCKS_EXPECTED) { - // Many fewer blocks than expected: alert! - strWarning = strprintf(_("WARNING: check your network connection, %d blocks received in the last %d hours (%d expected)"), - nBlocks, SPAN_HOURS, BLOCKS_EXPECTED); - } - else if (p <= alertThreshold && nBlocks > BLOCKS_EXPECTED) - { - // Many more blocks than expected: alert! - strWarning = strprintf(_("WARNING: abnormally high number of blocks generated, %d blocks received in the last %d hours (%d expected)"), - nBlocks, SPAN_HOURS, BLOCKS_EXPECTED); + if (p <= alertThreshold && nBlocks < BLOCKS_EXPECTED) + { + // Many fewer blocks than expected: alert! + strWarning = strprintf(_("WARNING: check your network connection, %d blocks received in the last %d hours (%d expected)"), + nBlocks, SPAN_HOURS, BLOCKS_EXPECTED); + } + else if (p <= alertThreshold && nBlocks > BLOCKS_EXPECTED) + { + // Many more blocks than expected: alert! + strWarning = strprintf(_("WARNING: abnormally high number of blocks generated, %d blocks received in the last %d hours (%d expected)"), + nBlocks, SPAN_HOURS, BLOCKS_EXPECTED); + } } if (!strWarning.empty()) { diff --git a/src/miner.cpp b/src/miner.cpp index 7f05d6009..6df7482c6 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -792,21 +792,9 @@ void static BitcoinMiner_noeq() fprintf(stderr,"Mining %s with %s\n", ASSETCHAINS_SYMBOL, ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO]); while (true) { - if (chainparams.MiningRequiresPeers()) - { - miningTimer.stop(); - do { - bool fvNodesEmpty; - { - LOCK(cs_vNodes); - fvNodesEmpty = vNodes.empty(); - } - if (!fvNodesEmpty ) - break; - MilliSleep(1000); - } while (true); - miningTimer.start(); - } + miningTimer.stop(); + waitForPeers(chainparams); + miningTimer.start(); // Create new block unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();