Simplify orphan processing in preparation for interruptibility
This commit is contained in:
parent
68520597cc
commit
9453018fdc
1 changed files with 53 additions and 55 deletions
|
@ -2342,8 +2342,8 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::deque<COutPoint> vWorkQueue;
|
std::set<uint256> orphan_work_set;
|
||||||
std::vector<uint256> vEraseQueue;
|
|
||||||
CTransactionRef ptx;
|
CTransactionRef ptx;
|
||||||
vRecv >> ptx;
|
vRecv >> ptx;
|
||||||
const CTransaction& tx = *ptx;
|
const CTransaction& tx = *ptx;
|
||||||
|
@ -2368,7 +2368,12 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
||||||
mempool.check(pcoinsTip.get());
|
mempool.check(pcoinsTip.get());
|
||||||
RelayTransaction(tx, connman);
|
RelayTransaction(tx, connman);
|
||||||
for (unsigned int i = 0; i < tx.vout.size(); i++) {
|
for (unsigned int i = 0; i < tx.vout.size(); i++) {
|
||||||
vWorkQueue.emplace_back(inv.hash, i);
|
auto it_by_prev = mapOrphanTransactionsByPrev.find(COutPoint(inv.hash, i));
|
||||||
|
if (it_by_prev != mapOrphanTransactionsByPrev.end()) {
|
||||||
|
for (const auto& elem : it_by_prev->second) {
|
||||||
|
orphan_work_set.insert(elem->first);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pfrom->nLastTXTime = GetTime();
|
pfrom->nLastTXTime = GetTime();
|
||||||
|
@ -2380,41 +2385,38 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
||||||
|
|
||||||
// Recursively process any orphan transactions that depended on this one
|
// Recursively process any orphan transactions that depended on this one
|
||||||
std::set<NodeId> setMisbehaving;
|
std::set<NodeId> setMisbehaving;
|
||||||
while (!vWorkQueue.empty()) {
|
while (!orphan_work_set.empty()) {
|
||||||
auto itByPrev = mapOrphanTransactionsByPrev.find(vWorkQueue.front());
|
const uint256 orphanHash = *orphan_work_set.begin();
|
||||||
vWorkQueue.pop_front();
|
orphan_work_set.erase(orphan_work_set.begin());
|
||||||
if (itByPrev == mapOrphanTransactionsByPrev.end())
|
|
||||||
continue;
|
auto orphan_it = mapOrphanTransactions.find(orphanHash);
|
||||||
for (auto mi = itByPrev->second.begin();
|
if (orphan_it == mapOrphanTransactions.end()) continue;
|
||||||
mi != itByPrev->second.end();
|
|
||||||
++mi)
|
const CTransactionRef porphanTx = orphan_it->second.tx;
|
||||||
{
|
|
||||||
const CTransactionRef& porphanTx = (*mi)->second.tx;
|
|
||||||
const CTransaction& orphanTx = *porphanTx;
|
const CTransaction& orphanTx = *porphanTx;
|
||||||
const uint256& orphanHash = orphanTx.GetHash();
|
NodeId fromPeer = orphan_it->second.fromPeer;
|
||||||
NodeId fromPeer = (*mi)->second.fromPeer;
|
|
||||||
bool fMissingInputs2 = false;
|
bool fMissingInputs2 = false;
|
||||||
// Use a dummy CValidationState so someone can't setup nodes to counter-DoS based on orphan
|
// Use a dummy CValidationState so someone can't setup nodes to counter-DoS based on orphan
|
||||||
// resolution (that is, feeding people an invalid transaction based on LegitTxX in order to get
|
// resolution (that is, feeding people an invalid transaction based on LegitTxX in order to get
|
||||||
// anyone relaying LegitTxX banned)
|
// anyone relaying LegitTxX banned)
|
||||||
CValidationState stateDummy;
|
CValidationState stateDummy;
|
||||||
|
|
||||||
|
if (setMisbehaving.count(fromPeer)) continue;
|
||||||
if (setMisbehaving.count(fromPeer))
|
|
||||||
continue;
|
|
||||||
if (AcceptToMemoryPool(mempool, stateDummy, porphanTx, &fMissingInputs2, &lRemovedTxn, false /* bypass_limits */, 0 /* nAbsurdFee */)) {
|
if (AcceptToMemoryPool(mempool, stateDummy, porphanTx, &fMissingInputs2, &lRemovedTxn, false /* bypass_limits */, 0 /* nAbsurdFee */)) {
|
||||||
LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", orphanHash.ToString());
|
LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", orphanHash.ToString());
|
||||||
RelayTransaction(orphanTx, connman);
|
RelayTransaction(orphanTx, connman);
|
||||||
for (unsigned int i = 0; i < orphanTx.vout.size(); i++) {
|
for (unsigned int i = 0; i < orphanTx.vout.size(); i++) {
|
||||||
vWorkQueue.emplace_back(orphanHash, i);
|
auto it_by_prev = mapOrphanTransactionsByPrev.find(COutPoint(orphanHash, i));
|
||||||
|
if (it_by_prev != mapOrphanTransactionsByPrev.end()) {
|
||||||
|
for (const auto& elem : it_by_prev->second) {
|
||||||
|
orphan_work_set.insert(elem->first);
|
||||||
}
|
}
|
||||||
vEraseQueue.push_back(orphanHash);
|
|
||||||
}
|
}
|
||||||
else if (!fMissingInputs2)
|
}
|
||||||
{
|
EraseOrphanTx(orphanHash);
|
||||||
|
} else if (!fMissingInputs2) {
|
||||||
int nDos = 0;
|
int nDos = 0;
|
||||||
if (stateDummy.IsInvalid(nDos) && nDos > 0)
|
if (stateDummy.IsInvalid(nDos) && nDos > 0) {
|
||||||
{
|
|
||||||
// Punish peer that gave us an invalid orphan tx
|
// Punish peer that gave us an invalid orphan tx
|
||||||
Misbehaving(fromPeer, nDos);
|
Misbehaving(fromPeer, nDos);
|
||||||
setMisbehaving.insert(fromPeer);
|
setMisbehaving.insert(fromPeer);
|
||||||
|
@ -2423,7 +2425,6 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
||||||
// Has inputs but not accepted to mempool
|
// Has inputs but not accepted to mempool
|
||||||
// Probably non-standard or insufficient fee
|
// Probably non-standard or insufficient fee
|
||||||
LogPrint(BCLog::MEMPOOL, " removed orphan tx %s\n", orphanHash.ToString());
|
LogPrint(BCLog::MEMPOOL, " removed orphan tx %s\n", orphanHash.ToString());
|
||||||
vEraseQueue.push_back(orphanHash);
|
|
||||||
if (!orphanTx.HasWitness() && !stateDummy.CorruptionPossible()) {
|
if (!orphanTx.HasWitness() && !stateDummy.CorruptionPossible()) {
|
||||||
// Do not use rejection cache for witness transactions or
|
// Do not use rejection cache for witness transactions or
|
||||||
// witness-stripped transactions, as they can have been malleated.
|
// witness-stripped transactions, as they can have been malleated.
|
||||||
|
@ -2431,14 +2432,11 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
|
||||||
assert(recentRejects);
|
assert(recentRejects);
|
||||||
recentRejects->insert(orphanHash);
|
recentRejects->insert(orphanHash);
|
||||||
}
|
}
|
||||||
|
EraseOrphanTx(orphanHash);
|
||||||
}
|
}
|
||||||
mempool.check(pcoinsTip.get());
|
mempool.check(pcoinsTip.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const uint256& hash : vEraseQueue)
|
|
||||||
EraseOrphanTx(hash);
|
|
||||||
}
|
|
||||||
else if (fMissingInputs)
|
else if (fMissingInputs)
|
||||||
{
|
{
|
||||||
bool fRejectedParents = false; // It may be the case that the orphans parents have all been rejected
|
bool fRejectedParents = false; // It may be the case that the orphans parents have all been rejected
|
||||||
|
|
Loading…
Reference in a new issue