Skip to content

Commit 93566e0

Browse files
committed
Merge #8930: Move orphan processing to ActivateBestChain
d2b88f9 Move orphan-conflict removal from main logic into a callback (Matt Corallo) 97e2802 Erase orphans per-transaction instead of per-block (Matt Corallo) ec4525c Move orphan processing to ActivateBestChain (Matt Corallo)
2 parents 407d923 + d2b88f9 commit 93566e0

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

src/main.cpp

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,7 +2460,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
24602460

24612461
CCheckQueueControl<CScriptCheck> control(fScriptChecks && nScriptCheckThreads ? &scriptcheckqueue : NULL);
24622462

2463-
std::vector<uint256> vOrphanErase;
24642463
std::vector<int> prevheights;
24652464
CAmount nFees = 0;
24662465
int nInputs = 0;
@@ -2491,17 +2490,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
24912490
prevheights[j] = view.AccessCoins(tx.vin[j].prevout.hash)->nHeight;
24922491
}
24932492

2494-
// Which orphan pool entries must we evict?
2495-
for (size_t j = 0; j < tx.vin.size(); j++) {
2496-
auto itByPrev = mapOrphanTransactionsByPrev.find(tx.vin[j].prevout);
2497-
if (itByPrev == mapOrphanTransactionsByPrev.end()) continue;
2498-
for (auto mi = itByPrev->second.begin(); mi != itByPrev->second.end(); ++mi) {
2499-
const CTransaction& orphanTx = (*mi)->second.tx;
2500-
const uint256& orphanHash = orphanTx.GetHash();
2501-
vOrphanErase.push_back(orphanHash);
2502-
}
2503-
}
2504-
25052493
if (!SequenceLocks(tx, nLockTimeFlags, &prevheights, *pindex)) {
25062494
return state.DoS(100, error("%s: contains a non-BIP68-final transaction", __func__),
25072495
REJECT_INVALID, "bad-txns-nonfinal");
@@ -2591,14 +2579,6 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
25912579
GetMainSignals().UpdatedTransaction(hashPrevBestCoinBase);
25922580
hashPrevBestCoinBase = block.vtx[0]->GetHash();
25932581

2594-
// Erase orphan transactions include or precluded by this block
2595-
if (vOrphanErase.size()) {
2596-
int nErased = 0;
2597-
BOOST_FOREACH(uint256 &orphanHash, vOrphanErase) {
2598-
nErased += EraseOrphanTx(orphanHash);
2599-
}
2600-
LogPrint("mempool", "Erased %d orphan tx included or conflicted by block\n", nErased);
2601-
}
26022582

26032583
int64_t nTime6 = GetTimeMicros(); nTimeCallbacks += nTime6 - nTime5;
26042584
LogPrint("bench", " - Callbacks: %.2fms [%.2fs]\n", 0.001 * (nTime6 - nTime5), nTimeCallbacks * 0.000001);
@@ -4747,6 +4727,34 @@ PeerLogicValidation::PeerLogicValidation(CConnman* connmanIn) : connman(connmanI
47474727
recentRejects.reset(new CRollingBloomFilter(120000, 0.000001));
47484728
}
47494729

4730+
void PeerLogicValidation::SyncTransaction(const CTransaction& tx, const CBlockIndex* pindex, int nPosInBlock) {
4731+
if (nPosInBlock == CMainSignals::SYNC_TRANSACTION_NOT_IN_BLOCK)
4732+
return;
4733+
4734+
LOCK(cs_main);
4735+
4736+
std::vector<uint256> vOrphanErase;
4737+
// Which orphan pool entries must we evict?
4738+
for (size_t j = 0; j < tx.vin.size(); j++) {
4739+
auto itByPrev = mapOrphanTransactionsByPrev.find(tx.vin[j].prevout);
4740+
if (itByPrev == mapOrphanTransactionsByPrev.end()) continue;
4741+
for (auto mi = itByPrev->second.begin(); mi != itByPrev->second.end(); ++mi) {
4742+
const CTransaction& orphanTx = (*mi)->second.tx;
4743+
const uint256& orphanHash = orphanTx.GetHash();
4744+
vOrphanErase.push_back(orphanHash);
4745+
}
4746+
}
4747+
4748+
// Erase orphan transactions include or precluded by this block
4749+
if (vOrphanErase.size()) {
4750+
int nErased = 0;
4751+
BOOST_FOREACH(uint256 &orphanHash, vOrphanErase) {
4752+
nErased += EraseOrphanTx(orphanHash);
4753+
}
4754+
LogPrint("mempool", "Erased %d orphan tx included or conflicted by block\n", nErased);
4755+
}
4756+
}
4757+
47504758
void PeerLogicValidation::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) {
47514759
const int nNewHeight = pindexNew->nHeight;
47524760
connman->SetBestHeight(nNewHeight);

src/main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ class PeerLogicValidation : public CValidationInterface {
560560
public:
561561
PeerLogicValidation(CConnman* connmanIn);
562562

563+
virtual void SyncTransaction(const CTransaction& tx, const CBlockIndex* pindex, int nPosInBlock);
563564
virtual void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload);
564565
virtual void BlockChecked(const CBlock& block, const CValidationState& state);
565566
};

0 commit comments

Comments
 (0)