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 707 Lines • ▼ Show 20 Lines | std::map<BlockHash, std::pair<NodeId, bool>> | ||||
mapBlockSource GUARDED_BY(cs_main); | mapBlockSource GUARDED_BY(cs_main); | ||||
/** Number of outbound peers with m_chain_sync.m_protect. */ | /** Number of outbound peers with m_chain_sync.m_protect. */ | ||||
int m_outbound_peers_with_protect_from_disconnect GUARDED_BY(cs_main) = 0; | int m_outbound_peers_with_protect_from_disconnect GUARDED_BY(cs_main) = 0; | ||||
bool AlreadyHaveTx(const TxId &txid) EXCLUSIVE_LOCKS_REQUIRED(cs_main); | bool AlreadyHaveTx(const TxId &txid) EXCLUSIVE_LOCKS_REQUIRED(cs_main); | ||||
/** | /** | ||||
* Filter for transactions that were recently rejected by | * Filter for transactions that were recently rejected by the mempool. | ||||
* AcceptToMemoryPool. These are not rerequested until the chain tip | * These are not rerequested until the chain tip changes, at which point | ||||
* changes, at which point the entire filter is reset. | * the entire filter is reset. | ||||
* | * | ||||
* Without this filter we'd be re-requesting txs from each of our peers, | * Without this filter we'd be re-requesting txs from each of our peers, | ||||
* increasing bandwidth consumption considerably. For instance, with 100 | * increasing bandwidth consumption considerably. For instance, with 100 | ||||
* peers, half of which relay a tx we don't accept, that might be a 50x | * peers, half of which relay a tx we don't accept, that might be a 50x | ||||
* bandwidth increase. A flooding attacker attempting to roll-over the | * bandwidth increase. A flooding attacker attempting to roll-over the | ||||
* filter using minimum-sized, 60byte, transactions might manage to send | * filter using minimum-sized, 60byte, transactions might manage to send | ||||
* 1000/sec if we have fast peers, so we pick 120,000 to give our peers a | * 1000/sec if we have fast peers, so we pick 120,000 to give our peers a | ||||
* two minute window to send invs to us. | * two minute window to send invs to us. | ||||
▲ Show 20 Lines • Show All 1,304 Lines • ▼ Show 20 Lines | switch (state.GetResult()) { | ||||
// Conflicting (but not necessarily invalid) data or different policy: | // Conflicting (but not necessarily invalid) data or different policy: | ||||
case TxValidationResult::TX_RECENT_CONSENSUS_CHANGE: | case TxValidationResult::TX_RECENT_CONSENSUS_CHANGE: | ||||
case TxValidationResult::TX_INPUTS_NOT_STANDARD: | case TxValidationResult::TX_INPUTS_NOT_STANDARD: | ||||
case TxValidationResult::TX_NOT_STANDARD: | case TxValidationResult::TX_NOT_STANDARD: | ||||
case TxValidationResult::TX_MISSING_INPUTS: | case TxValidationResult::TX_MISSING_INPUTS: | ||||
case TxValidationResult::TX_PREMATURE_SPEND: | case TxValidationResult::TX_PREMATURE_SPEND: | ||||
case TxValidationResult::TX_CONFLICT: | case TxValidationResult::TX_CONFLICT: | ||||
case TxValidationResult::TX_MEMPOOL_POLICY: | case TxValidationResult::TX_MEMPOOL_POLICY: | ||||
case TxValidationResult::TX_NO_MEMPOOL: | |||||
break; | break; | ||||
} | } | ||||
if (message != "") { | if (message != "") { | ||||
LogPrint(BCLog::NET, "peer=%d: %s\n", nodeid, message); | LogPrint(BCLog::NET, "peer=%d: %s\n", nodeid, message); | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,051 Lines • ▼ Show 20 Lines | while (!orphan_work_set.empty()) { | ||||
orphan_work_set.erase(orphan_work_set.begin()); | orphan_work_set.erase(orphan_work_set.begin()); | ||||
const auto [porphanTx, from_peer] = m_orphanage.GetTx(orphanTxId); | const auto [porphanTx, from_peer] = m_orphanage.GetTx(orphanTxId); | ||||
if (porphanTx == nullptr) { | if (porphanTx == nullptr) { | ||||
continue; | continue; | ||||
} | } | ||||
const MempoolAcceptResult result = | const MempoolAcceptResult result = | ||||
AcceptToMemoryPool(m_chainman.ActiveChainstate(), config, m_mempool, | m_chainman.ProcessTransaction(porphanTx); | ||||
porphanTx, false /* bypass_limits */); | |||||
const TxValidationState &state = result.m_state; | const TxValidationState &state = result.m_state; | ||||
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) { | if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) { | ||||
LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", | LogPrint(BCLog::MEMPOOL, " accepted orphan tx %s\n", | ||||
orphanTxId.ToString()); | orphanTxId.ToString()); | ||||
RelayTransaction(orphanTxId); | RelayTransaction(orphanTxId); | ||||
m_orphanage.AddChildrenToWorkSet(*porphanTx, orphan_work_set); | m_orphanage.AddChildrenToWorkSet(*porphanTx, orphan_work_set); | ||||
m_orphanage.EraseTx(orphanTxId); | m_orphanage.EraseTx(orphanTxId); | ||||
break; | break; | ||||
▲ Show 20 Lines • Show All 1,242 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::TX) { | ||||
LogPrintf("Force relaying tx %s from peer=%d\n", | LogPrintf("Force relaying tx %s from peer=%d\n", | ||||
tx.GetId().ToString(), pfrom.GetId()); | tx.GetId().ToString(), pfrom.GetId()); | ||||
RelayTransaction(tx.GetId()); | RelayTransaction(tx.GetId()); | ||||
} | } | ||||
} | } | ||||
return; | return; | ||||
} | } | ||||
const MempoolAcceptResult result = | const MempoolAcceptResult result = m_chainman.ProcessTransaction(ptx); | ||||
AcceptToMemoryPool(m_chainman.ActiveChainstate(), config, m_mempool, | |||||
ptx, false /* bypass_limits */); | |||||
const TxValidationState &state = result.m_state; | const TxValidationState &state = result.m_state; | ||||
if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) { | if (result.m_result_type == MempoolAcceptResult::ResultType::VALID) { | ||||
CChainState &active_chainstate = m_chainman.ActiveChainstate(); | CChainState &active_chainstate = m_chainman.ActiveChainstate(); | ||||
m_mempool.check(active_chainstate.CoinsTip(), | m_mempool.check(active_chainstate.CoinsTip(), | ||||
active_chainstate.m_chain.Height() + 1); | active_chainstate.m_chain.Height() + 1); | ||||
// As this version of the transaction was acceptable, we can forget | // As this version of the transaction was acceptable, we can forget | ||||
// about any requests for it. | // about any requests for it. | ||||
m_txrequest.ForgetInvId(tx.GetId()); | m_txrequest.ForgetInvId(tx.GetId()); | ||||
RelayTransaction(tx.GetId()); | RelayTransaction(tx.GetId()); | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::TX) { | ||||
m_txrequest.ForgetInvId(tx.GetId()); | m_txrequest.ForgetInvId(tx.GetId()); | ||||
if (RecursiveDynamicUsage(*ptx) < 100000) { | if (RecursiveDynamicUsage(*ptx) < 100000) { | ||||
AddToCompactExtraTransactions(ptx); | AddToCompactExtraTransactions(ptx); | ||||
} | } | ||||
} | } | ||||
// If a tx has been detected by recentRejects, we will have reached | // If a tx has been detected by recentRejects, we will have reached | ||||
// this point and the tx will have been ignored. Because we haven't run | // this point and the tx will have been ignored. Because we haven't | ||||
// the tx through AcceptToMemoryPool, we won't have computed a DoS | // submitted the tx to our mempool, we won't have computed a DoS | ||||
// score for it or determined exactly why we consider it invalid. | // score for it or determined exactly why we consider it invalid. | ||||
// | // | ||||
// This means we won't penalize any peer subsequently relaying a DoSy | // This means we won't penalize any peer subsequently relaying a DoSy | ||||
// tx (even if we penalized the first peer who gave it to us) because | // tx (even if we penalized the first peer who gave it to us) because | ||||
// we have to account for recentRejects showing false positives. In | // we have to account for recentRejects showing false positives. In | ||||
// other words, we shouldn't penalize a peer if we aren't *sure* they | // other words, we shouldn't penalize a peer if we aren't *sure* they | ||||
// submitted a DoSy tx. | // submitted a DoSy tx. | ||||
// | // | ||||
▲ Show 20 Lines • Show All 2,699 Lines • Show Last 20 Lines |