Fix incorrect validations of block transactions

This commit is contained in:
miketout
2018-05-07 10:29:43 -07:00
parent b45d65b46c
commit 68334c8dae
3 changed files with 27 additions and 28 deletions

View File

@@ -267,6 +267,14 @@ public:
} }
return ret; return ret;
} }
int64_t TotalTxValue() const {
int64_t total = 0;
BOOST_FOREACH(const CTxOut &out, vout) {
total += out.nValue;
}
return total;
}
}; };
class CCoinsKeyHasher class CCoinsKeyHasher

View File

@@ -2057,9 +2057,9 @@ namespace Consensus {
REJECT_INVALID, "bad-txns-premature-spend-of-coinbase"); REJECT_INVALID, "bad-txns-premature-spend-of-coinbase");
} }
// ensure that zeroth output of coinbases are not still time locked // ensure that output of coinbases are not still time locked
uint64_t unlockTime = tx.UnlockTime(0); uint64_t unlockTime = komodo_block_unlocktime(coins->nHeight);
if (nSpendHeight >= unlockTime) { if (nSpendHeight < unlockTime && coins->TotalTxValue() >= ASSETCHAINS_TIMELOCKGTE) {
return state.Invalid( return state.Invalid(
error("CheckInputs(): tried to spend coinbase that is timelocked until block %d", unlockTime), error("CheckInputs(): tried to spend coinbase that is timelocked until block %d", unlockTime),
REJECT_INVALID, "bad-txns-premature-spend-of-coinbase"); REJECT_INVALID, "bad-txns-premature-spend-of-coinbase");
@@ -2563,6 +2563,8 @@ void PartitionCheck(bool (*initialDownloadCheck)(), CCriticalSection& cs, const
const int FIFTY_YEARS = 50*365*24*60*60; const int FIFTY_YEARS = 50*365*24*60*60;
double alertThreshold = 1.0 / (FIFTY_YEARS / SPAN_SECONDS); double alertThreshold = 1.0 / (FIFTY_YEARS / SPAN_SECONDS);
if (bestHeader->nHeight > BLOCKS_EXPECTED)
{
if (p <= alertThreshold && nBlocks < BLOCKS_EXPECTED) if (p <= alertThreshold && nBlocks < BLOCKS_EXPECTED)
{ {
// Many fewer blocks than expected: alert! // Many fewer blocks than expected: alert!
@@ -2575,6 +2577,7 @@ void PartitionCheck(bool (*initialDownloadCheck)(), CCriticalSection& cs, const
strWarning = strprintf(_("WARNING: abnormally high number of blocks generated, %d blocks received in the last %d hours (%d expected)"), strWarning = strprintf(_("WARNING: abnormally high number of blocks generated, %d blocks received in the last %d hours (%d expected)"),
nBlocks, SPAN_HOURS, BLOCKS_EXPECTED); nBlocks, SPAN_HOURS, BLOCKS_EXPECTED);
} }
}
if (!strWarning.empty()) if (!strWarning.empty())
{ {
strMiscWarning = strWarning; strMiscWarning = strWarning;

View File

@@ -791,22 +791,10 @@ void static BitcoinMiner_noeq()
try { try {
fprintf(stderr,"Mining %s with %s\n", ASSETCHAINS_SYMBOL, ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO]); fprintf(stderr,"Mining %s with %s\n", ASSETCHAINS_SYMBOL, ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO]);
while (true) while (true)
{
if (chainparams.MiningRequiresPeers())
{ {
miningTimer.stop(); miningTimer.stop();
do { waitForPeers(chainparams);
bool fvNodesEmpty;
{
LOCK(cs_vNodes);
fvNodesEmpty = vNodes.empty();
}
if (!fvNodesEmpty )
break;
MilliSleep(1000);
} while (true);
miningTimer.start(); miningTimer.start();
}
// Create new block // Create new block
unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();