Skip to content

Commit

Permalink
Move safe TX checks into TestForBlock and TestPackageTransactions
Browse files Browse the repository at this point in the history
Otherwise we'll miss checks for ancestors.
  • Loading branch information
codablock committed Mar 7, 2019
1 parent 4d3365d commit 041a1c2
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,15 @@ bool BlockAssembler::TestPackage(uint64_t packageSize, unsigned int packageSigOp

// Perform transaction-level checks before adding to block:
// - transaction finality (locktime)
// - safe TXs in regard to ChainLocks
bool BlockAssembler::TestPackageTransactions(const CTxMemPool::setEntries& package)
{
BOOST_FOREACH (const CTxMemPool::txiter it, package) {
if (!IsFinalTx(it->GetTx(), nHeight, nLockTimeCutoff))
return false;
if (!llmq::chainLocksHandler->IsTxSafeForMining(it->GetTx().GetHash())) {
return false;
}
}
return true;
}
Expand Down Expand Up @@ -333,6 +337,10 @@ bool BlockAssembler::TestForBlock(CTxMemPool::txiter iter)
if (!IsFinalTx(iter->GetTx(), nHeight, nLockTimeCutoff))
return false;

if (!llmq::chainLocksHandler->IsTxSafeForMining(iter->GetTx().GetHash())) {
return false;
}

return true;
}

Expand Down Expand Up @@ -454,12 +462,6 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
continue;
}

if (mi != mempool.mapTx.get<ancestor_score>().end() &&
!llmq::chainLocksHandler->IsTxSafeForMining(mi->GetTx().GetHash())) {
++mi;
continue;
}

// Now that mi is not stale, determine which transaction to evaluate:
// the next entry from mapTx, or the best from mapModifiedTx?
bool fUsingModified = false;
Expand Down Expand Up @@ -530,7 +532,7 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
onlyUnconfirmed(ancestors);
ancestors.insert(iter);

// Test if all tx's are Final
// Test if all tx's are Final and safe
if (!TestPackageTransactions(ancestors)) {
if (fUsingModified) {
mapModifiedTx.get<ancestor_score>().erase(modit);
Expand Down Expand Up @@ -608,10 +610,6 @@ void BlockAssembler::addPriorityTxs()
continue;
}

if (!llmq::chainLocksHandler->IsTxSafeForMining(iter->GetTx().GetHash())) {
continue;
}

// If this tx fits in the block add it, otherwise keep looping
if (TestForBlock(iter)) {
AddToBlock(iter);
Expand Down

0 comments on commit 041a1c2

Please sign in to comment.