Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 2,891 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::INV) { | ||||
::ChainActive().GetLocator( | ::ChainActive().GetLocator( | ||||
pindexBestHeader), | pindexBestHeader), | ||||
hash)); | hash)); | ||||
LogPrint(BCLog::NET, "getheaders (%d) %s to peer=%d\n", | LogPrint(BCLog::NET, "getheaders (%d) %s to peer=%d\n", | ||||
pindexBestHeader->nHeight, hash.ToString(), | pindexBestHeader->nHeight, hash.ToString(), | ||||
pfrom.GetId()); | pfrom.GetId()); | ||||
} | } | ||||
} else { | } else { | ||||
pfrom.AddInventoryKnown(inv); | const TxId txid(inv.hash); | ||||
pfrom.AddKnownTx(txid); | |||||
if (fBlocksOnly) { | if (fBlocksOnly) { | ||||
LogPrint(BCLog::NET, | LogPrint(BCLog::NET, | ||||
"transaction (%s) inv sent in violation of " | "transaction (%s) inv sent in violation of " | ||||
"protocol, disconnecting peer=%d\n", | "protocol, disconnecting peer=%d\n", | ||||
inv.hash.ToString(), pfrom.GetId()); | txid.ToString(), pfrom.GetId()); | ||||
pfrom.fDisconnect = true; | pfrom.fDisconnect = true; | ||||
return true; | return true; | ||||
} else if (!fAlreadyHave && !fImporting && !fReindex && | } else if (!fAlreadyHave && !fImporting && !fReindex && | ||||
!::ChainstateActive().IsInitialBlockDownload()) { | !::ChainstateActive().IsInitialBlockDownload()) { | ||||
RequestTx(State(pfrom.GetId()), TxId(inv.hash), | RequestTx(State(pfrom.GetId()), txid, current_time); | ||||
current_time); | |||||
} | } | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
if (msg_type == NetMsgType::GETDATA) { | if (msg_type == NetMsgType::GETDATA) { | ||||
std::vector<CInv> vInv; | std::vector<CInv> vInv; | ||||
▲ Show 20 Lines • Show All 250 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::TX) { | ||||
pfrom.fDisconnect = true; | pfrom.fDisconnect = true; | ||||
return true; | return true; | ||||
} | } | ||||
CTransactionRef ptx; | CTransactionRef ptx; | ||||
vRecv >> ptx; | vRecv >> ptx; | ||||
const CTransaction &tx = *ptx; | const CTransaction &tx = *ptx; | ||||
const TxId &txid = tx.GetId(); | const TxId &txid = tx.GetId(); | ||||
pfrom.AddKnownTx(txid); | |||||
CInv inv(MSG_TX, txid); | |||||
pfrom.AddInventoryKnown(inv); | |||||
LOCK2(cs_main, g_cs_orphans); | LOCK2(cs_main, g_cs_orphans); | ||||
TxValidationState state; | TxValidationState state; | ||||
CNodeState *nodestate = State(pfrom.GetId()); | CNodeState *nodestate = State(pfrom.GetId()); | ||||
nodestate->m_tx_download.m_tx_announced.erase(txid); | nodestate->m_tx_download.m_tx_announced.erase(txid); | ||||
nodestate->m_tx_download.m_tx_in_flight.erase(txid); | nodestate->m_tx_download.m_tx_in_flight.erase(txid); | ||||
EraseTxRequest(txid); | EraseTxRequest(txid); | ||||
if (!AlreadyHave(inv) && | if (!AlreadyHave(CInv(MSG_TX, txid)) && | ||||
AcceptToMemoryPool(config, g_mempool, state, ptx, | AcceptToMemoryPool(config, g_mempool, state, ptx, | ||||
false /* bypass_limits */, | false /* bypass_limits */, | ||||
Amount::zero() /* nAbsurdFee */)) { | Amount::zero() /* nAbsurdFee */)) { | ||||
g_mempool.check(&::ChainstateActive().CoinsTip()); | g_mempool.check(&::ChainstateActive().CoinsTip()); | ||||
RelayTransaction(tx.GetId(), connman); | RelayTransaction(tx.GetId(), connman); | ||||
for (size_t i = 0; i < tx.vout.size(); i++) { | for (size_t i = 0; i < tx.vout.size(); i++) { | ||||
auto it_by_prev = | auto it_by_prev = | ||||
mapOrphanTransactionsByPrev.find(COutPoint(txid, i)); | mapOrphanTransactionsByPrev.find(COutPoint(txid, i)); | ||||
Show All 26 Lines | if (msg_type == NetMsgType::TX) { | ||||
} | } | ||||
} | } | ||||
if (!fRejectedParents) { | if (!fRejectedParents) { | ||||
const auto current_time = GetTime<std::chrono::microseconds>(); | const auto current_time = GetTime<std::chrono::microseconds>(); | ||||
for (const CTxIn &txin : tx.vin) { | for (const CTxIn &txin : tx.vin) { | ||||
// FIXME: MSG_TX should use a TxHash, not a TxId. | // FIXME: MSG_TX should use a TxHash, not a TxId. | ||||
const TxId _txid = txin.prevout.GetTxId(); | const TxId _txid = txin.prevout.GetTxId(); | ||||
CInv _inv(MSG_TX, _txid); | pfrom.AddKnownTx(_txid); | ||||
pfrom.AddInventoryKnown(_inv); | if (!AlreadyHave(CInv(MSG_TX, _txid))) { | ||||
if (!AlreadyHave(_inv)) { | |||||
RequestTx(State(pfrom.GetId()), _txid, current_time); | RequestTx(State(pfrom.GetId()), _txid, current_time); | ||||
} | } | ||||
} | } | ||||
AddOrphanTx(ptx, pfrom.GetId()); | AddOrphanTx(ptx, pfrom.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,009 Lines • Show Last 20 Lines |