Skip to content

Commit d2b88f9

Browse files
committed
Move orphan-conflict removal from main logic into a callback
This makes the orphan map a part of net-processing logic instead of main logic.
1 parent 97e2802 commit d2b88f9

File tree

2 files changed

+29
-28
lines changed

2 files changed

+29
-28
lines changed

src/main.cpp

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3085,34 +3085,6 @@ bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams,
30853085
}
30863086
// When we reach this point, we switched to a new tip (stored in pindexNewTip).
30873087

3088-
// Remove orphan transactions with cs_main
3089-
{
3090-
LOCK(cs_main);
3091-
for(unsigned int i = 0; i < txChanged.size(); i++) {
3092-
std::vector<uint256> vOrphanErase;
3093-
const CTransaction& tx = std::get<0>(txChanged[i]);
3094-
// Which orphan pool entries must we evict?
3095-
for (size_t j = 0; j < tx.vin.size(); j++) {
3096-
auto itByPrev = mapOrphanTransactionsByPrev.find(tx.vin[j].prevout);
3097-
if (itByPrev == mapOrphanTransactionsByPrev.end()) continue;
3098-
for (auto mi = itByPrev->second.begin(); mi != itByPrev->second.end(); ++mi) {
3099-
const CTransaction& orphanTx = (*mi)->second.tx;
3100-
const uint256& orphanHash = orphanTx.GetHash();
3101-
vOrphanErase.push_back(orphanHash);
3102-
}
3103-
}
3104-
3105-
// Erase orphan transactions include or precluded by this block
3106-
if (vOrphanErase.size()) {
3107-
int nErased = 0;
3108-
BOOST_FOREACH(uint256 &orphanHash, vOrphanErase) {
3109-
nErased += EraseOrphanTx(orphanHash);
3110-
}
3111-
LogPrint("mempool", "Erased %d orphan tx included or conflicted by block\n", nErased);
3112-
}
3113-
}
3114-
}
3115-
31163088
// Notifications/callbacks that can run without cs_main
31173089

31183090
// throw all transactions though the signal-interface
@@ -4752,6 +4724,34 @@ PeerLogicValidation::PeerLogicValidation(CConnman* connmanIn) : connman(connmanI
47524724
recentRejects.reset(new CRollingBloomFilter(120000, 0.000001));
47534725
}
47544726

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