Skip to content

Commit 81f9a94

Browse files
committed
fix: remove orphan transactions that fix the blocktemplate functionality for miners.
1 parent 88f125e commit 81f9a94

1 file changed

Lines changed: 48 additions & 40 deletions

File tree

src/miner.cpp

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -240,40 +240,44 @@ CBlock* CreateNewBlock(CReserveKey& reservekey, bool fProofOfStake, int64_t* pFe
240240

241241
if (!txPrev.ReadFromDisk(txdb, txin.prevout, txindex))
242242
{
243-
// This should never happen; all transactions in the memory
244-
// pool should connect to either transactions in the chain
245-
// or other transactions in the memory pool.
246-
if (!mempool.mapTx.count(txin.prevout.hash))
247-
{
248-
LogPrintf("ERROR: mempool transaction missing input\n");
249-
250-
if (fDebug)
243+
#ifdef ENABLE_ORPHAN_TRANSACTIONS
244+
// This should never happen; all transactions in the memory
245+
// pool should connect to either transactions in the chain
246+
// or other transactions in the memory pool.
247+
if (!mempool.mapTx.count(txin.prevout.hash))
251248
{
252-
assert("mempool transaction missing input" == 0);
253-
}
254-
255-
fMissingInputs = true;
256-
257-
if (porphan)
249+
LogPrintf("ERROR: mempool transaction missing input\n");
250+
251+
if (fDebug)
252+
{
253+
assert("mempool transaction missing input" == 0);
254+
}
255+
256+
fMissingInputs = true;
257+
258+
if (porphan)
259+
{
260+
vOrphan.pop_back();
261+
}
262+
263+
break;
264+
}
265+
266+
// Has to wait for dependencies
267+
if (!porphan)
258268
{
259-
vOrphan.pop_back();
269+
// Use list for automatic deletion
270+
vOrphan.push_back(COrphan(&tx));
271+
porphan = &vOrphan.back();
260272
}
261273

262-
break;
263-
}
264-
265-
// Has to wait for dependencies
266-
if (!porphan)
267-
{
268-
// Use list for automatic deletion
269-
vOrphan.push_back(COrphan(&tx));
270-
porphan = &vOrphan.back();
271-
}
272-
273-
mapDependers[txin.prevout.hash].push_back(porphan);
274-
porphan->setDependsOn.insert(txin.prevout.hash);
275-
nTotalIn += mempool.mapTx[txin.prevout.hash].vout[txin.prevout.n].nValue;
276-
274+
mapDependers[txin.prevout.hash].push_back(porphan);
275+
porphan->setDependsOn.insert(txin.prevout.hash);
276+
nTotalIn += mempool.mapTx[txin.prevout.hash].vout[txin.prevout.n].nValue;
277+
#else // ENABLE_ORPHAN_TRANSACTIONS
278+
fMissingInputs = true;
279+
#endif // ENABLE_ORPHAN_TRANSACTIONS
280+
277281
continue;
278282
}
279283

@@ -297,16 +301,20 @@ CBlock* CreateNewBlock(CReserveKey& reservekey, bool fProofOfStake, int64_t* pFe
297301
// client code rounds up the size to the nearest 1K. That's good, because it gives an
298302
// incentive to create smaller transactions.
299303
double dFeePerKb = double(nTotalIn-tx.GetValueOut()) / (double(nTxSize)/1000.0);
300-
301-
if (porphan)
302-
{
303-
porphan->dPriority = dPriority;
304-
porphan->dFeePerKb = dFeePerKb;
305-
}
306-
else
307-
{
308-
vecPriority.push_back(TxPriority(dPriority, dFeePerKb, &(*mi).second));
309-
}
304+
305+
#ifdef ENABLE_ORPHAN_TRANSACTIONS
306+
if (porphan)
307+
{
308+
porphan->dPriority = dPriority;
309+
porphan->dFeePerKb = dFeePerKb;
310+
}
311+
else
312+
{
313+
vecPriority.push_back(TxPriority(dPriority, dFeePerKb, &(*mi).second));
314+
}
315+
#else // ENABLE_ORPHAN_TRANSACTIONS
316+
vecPriority.push_back(TxPriority(dPriority, dFeePerKb, &(*mi).second));
317+
#endif // ENABLE_ORPHAN_TRANSACTIONS
310318
}
311319

312320
// Collect transactions into block

0 commit comments

Comments
 (0)