txorphanage: Extract AddChildrenToWorkSet
Extract some common code into AddChildrenToWorkSet function. (It's a hard knock life)
This commit is contained in:
1 parent
38a11c355a
commit
ee135c8d5b
3 files changed
+16
-16
No files matched your search
+2
-16
@@ -2121,14 +2121,7 @@ void PeerManagerImpl::ProcessOrphanTx(std::set<uint256>& orphan_work_set)
|
|||||||
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
|
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
|
||||||
LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", orphanHash.ToString());
|
LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", orphanHash.ToString());
|
||||||
RelayTransaction(orphanHash, porphanTx->GetWitnessHash(), m_connman);
|
RelayTransaction(orphanHash, porphanTx->GetWitnessHash(), m_connman);
|
||||||
for (unsigned int i = 0; i < porphanTx->vout.size(); i++) {
|
AddChildrenToWorkSet(*porphanTx, orphan_work_set);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
EraseOrphanTx(orphanHash);
|
EraseOrphanTx(orphanHash);
|
||||||
for (const CTransactionRef& removedTx : result.m_replaced_transactions.value()) {
|
for (const CTransactionRef& removedTx : result.m_replaced_transactions.value()) {
|
||||||
AddToCompactExtraTransactions(removedTx);
|
AddToCompactExtraTransactions(removedTx);
|
||||||
@@ -3147,14 +3140,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||||||
m_txrequest.ForgetTxHash(tx.GetHash());
|
m_txrequest.ForgetTxHash(tx.GetHash());
|
||||||
m_txrequest.ForgetTxHash(tx.GetWitnessHash());
|
m_txrequest.ForgetTxHash(tx.GetWitnessHash());
|
||||||
RelayTransaction(tx.GetHash(), tx.GetWitnessHash(), m_connman);
|
RelayTransaction(tx.GetHash(), tx.GetWitnessHash(), m_connman);
|
||||||
for (unsigned int i = 0; i < tx.vout.size(); i++) {
|
AddChildrenToWorkSet(tx, peer->m_orphan_work_set);
|
||||||
auto it_by_prev = mapOrphanTransactionsByPrev.find(COutPoint(txid, i));
|
|
||||||
if (it_by_prev != mapOrphanTransactionsByPrev.end()) {
|
|
||||||
for (const auto& elem : it_by_prev->second) {
|
|
||||||
peer->m_orphan_work_set.insert(elem->first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pfrom.nLastTXTime = GetTime();
|
pfrom.nLastTXTime = GetTime();
|
||||||
|
|
||||||
|
|||||||
@@ -106,3 +106,16 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
|
|||||||
return nEvicted;
|
return nEvicted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AddChildrenToWorkSet(const CTransaction& tx, std::set<uint256>& orphan_work_set)
|
||||||
|
{
|
||||||
|
AssertLockHeld(g_cs_orphans);
|
||||||
|
for (unsigned int i = 0; i < tx.vout.size(); i++) {
|
||||||
|
const auto it_by_prev = mapOrphanTransactionsByPrev.find(COutPoint(tx.GetHash(), i));
|
||||||
|
if (it_by_prev != mapOrphanTransactionsByPrev.end()) {
|
||||||
|
for (const auto& elem : it_by_prev->second) {
|
||||||
|
orphan_work_set.insert(elem->first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -26,6 +26,7 @@ struct COrphanTx {
|
|||||||
int EraseOrphanTx(const uint256& txid) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
|
int EraseOrphanTx(const uint256& txid) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
|
||||||
void EraseOrphansFor(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
|
void EraseOrphansFor(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
|
||||||
unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
|
unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
|
||||||
|
void AddChildrenToWorkSet(const CTransaction& tx, std::set<uint256>& orphan_work_set) EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans);
|
||||||
|
|
||||||
/** Map from txid to orphan transaction record. Limited by
|
/** Map from txid to orphan transaction record. Limited by
|
||||||
* -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS */
|
* -maxorphantx/DEFAULT_MAX_ORPHAN_TRANSACTIONS */
|
||||||
|
|||||||
Reference in new issue
Block a user