Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
Show First 20 Lines • Show All 1,747 Lines • ▼ Show 20 Lines | if (!vExtraTxnForCompact.size()) { | ||||
vExtraTxnForCompact.resize(max_extra_txn); | vExtraTxnForCompact.resize(max_extra_txn); | ||||
} | } | ||||
vExtraTxnForCompact[vExtraTxnForCompactIt] = | vExtraTxnForCompact[vExtraTxnForCompactIt] = | ||||
std::make_pair(tx->GetHash(), tx); | std::make_pair(tx->GetHash(), tx); | ||||
vExtraTxnForCompactIt = (vExtraTxnForCompactIt + 1) % max_extra_txn; | vExtraTxnForCompactIt = (vExtraTxnForCompactIt + 1) % max_extra_txn; | ||||
} | } | ||||
bool AddOrphanTx(const CTransactionRef &tx, NodeId peer) | |||||
EXCLUSIVE_LOCKS_REQUIRED(g_cs_orphans) { | |||||
const TxId &txid = tx->GetId(); | |||||
if (mapOrphanTransactions.count(txid)) { | |||||
return false; | |||||
} | |||||
// Ignore big transactions, to avoid a send-big-orphans memory exhaustion | |||||
// attack. If a peer has a legitimate large transaction with a missing | |||||
// parent then we assume it will rebroadcast it later, after the parent | |||||
// transaction(s) have been mined or received. | |||||
// 100 orphans, each of which is at most 100,000 bytes big is at most 10 | |||||
// megabytes of orphans and somewhat more byprev index (in the worst case): | |||||
unsigned int sz = tx->GetTotalSize(); | |||||
if (sz > MAX_STANDARD_TX_SIZE) { | |||||
LogPrint(BCLog::MEMPOOL, | |||||
"ignoring large orphan tx (size: %u, hash: %s)\n", sz, | |||||
txid.ToString()); | |||||
return false; | |||||
} | |||||
auto ret = mapOrphanTransactions.emplace( | |||||
txid, COrphanTx{tx, peer, GetTime() + ORPHAN_TX_EXPIRE_TIME, | |||||
g_orphan_list.size()}); | |||||
assert(ret.second); | |||||
g_orphan_list.push_back(ret.first); | |||||
for (const CTxIn &txin : tx->vin) { | |||||
mapOrphanTransactionsByPrev[txin.prevout].insert(ret.first); | |||||
} | |||||
AddToCompactExtraTransactions(tx); | |||||
LogPrint(BCLog::MEMPOOL, "stored orphan tx %s (mapsz %u outsz %u)\n", | |||||
txid.ToString(), mapOrphanTransactions.size(), | |||||
mapOrphanTransactionsByPrev.size()); | |||||
return true; | |||||
} | |||||
void PeerManagerImpl::Misbehaving(const NodeId pnode, const int howmuch, | void PeerManagerImpl::Misbehaving(const NodeId pnode, const int howmuch, | ||||
const std::string &message) { | const std::string &message) { | ||||
assert(howmuch > 0); | assert(howmuch > 0); | ||||
PeerRef peer = GetPeerRef(pnode); | PeerRef peer = GetPeerRef(pnode); | ||||
if (peer == nullptr) { | if (peer == nullptr) { | ||||
return; | return; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 2,542 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::TX) { | ||||
for (const TxId &parent_txid : unique_parents) { | for (const TxId &parent_txid : unique_parents) { | ||||
// FIXME: MSG_TX should use a TxHash, not a TxId. | // FIXME: MSG_TX should use a TxHash, not a TxId. | ||||
pfrom.AddKnownTx(parent_txid); | pfrom.AddKnownTx(parent_txid); | ||||
if (!AlreadyHaveTx(parent_txid)) { | if (!AlreadyHaveTx(parent_txid)) { | ||||
AddTxAnnouncement(pfrom, parent_txid, current_time); | AddTxAnnouncement(pfrom, parent_txid, current_time); | ||||
} | } | ||||
} | } | ||||
AddOrphanTx(ptx, pfrom.GetId()); | |||||
if (OrphanageAddTx(ptx, pfrom.GetId())) { | |||||
AddToCompactExtraTransactions(ptx); | |||||
} | |||||
// Once added to the orphan pool, a tx is considered | // Once added to the orphan pool, a tx is considered | ||||
// AlreadyHave, and we shouldn't request it anymore. | // AlreadyHave, and we shouldn't request it anymore. | ||||
m_txrequest.ForgetInvId(tx.GetId()); | m_txrequest.ForgetInvId(tx.GetId()); | ||||
// DoS prevention: do not allow mapOrphanTransactions to grow | // DoS prevention: do not allow mapOrphanTransactions to grow | ||||
// unbounded (see CVE-2012-3789) | // unbounded (see CVE-2012-3789) | ||||
unsigned int nMaxOrphanTx = (unsigned int)std::max( | unsigned int nMaxOrphanTx = (unsigned int)std::max( | ||||
▲ Show 20 Lines • Show All 2,530 Lines • Show Last 20 Lines |