Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 601 Lines • ▼ Show 20 Lines | struct Peer { | ||||
/** Protects misbehavior data members */ | /** Protects misbehavior data members */ | ||||
Mutex m_misbehavior_mutex; | Mutex m_misbehavior_mutex; | ||||
/** Accumulated misbehavior score for this peer */ | /** Accumulated misbehavior score for this peer */ | ||||
int m_misbehavior_score GUARDED_BY(m_misbehavior_mutex){0}; | int m_misbehavior_score GUARDED_BY(m_misbehavior_mutex){0}; | ||||
/** Whether this peer should be disconnected and marked as discouraged | /** Whether this peer should be disconnected and marked as discouraged | ||||
* (unless it has the noban permission). */ | * (unless it has the noban permission). */ | ||||
bool m_should_discourage GUARDED_BY(m_misbehavior_mutex){false}; | bool m_should_discourage GUARDED_BY(m_misbehavior_mutex){false}; | ||||
/** | |||||
* Set of txids to reconsider once their parent transactions have been | |||||
* accepted | |||||
*/ | |||||
std::set<TxId> m_orphan_work_set; | |||||
Peer(NodeId id) : m_id(id) {} | Peer(NodeId id) : m_id(id) {} | ||||
}; | }; | ||||
using PeerRef = std::shared_ptr<Peer>; | using PeerRef = std::shared_ptr<Peer>; | ||||
/** | /** | ||||
* Map of all Peer objects, keyed by peer id. This map is protected | * Map of all Peer objects, keyed by peer id. This map is protected | ||||
* by the global g_peer_mutex. Once a shared pointer reference is | * by the global g_peer_mutex. Once a shared pointer reference is | ||||
▲ Show 20 Lines • Show All 2,245 Lines • ▼ Show 20 Lines | void PeerManager::ProcessMessage(const Config &config, CNode &pfrom, | ||||
LogPrint(BCLog::NET, "received: %s (%u bytes) peer=%d\n", | LogPrint(BCLog::NET, "received: %s (%u bytes) peer=%d\n", | ||||
SanitizeString(msg_type), vRecv.size(), pfrom.GetId()); | SanitizeString(msg_type), vRecv.size(), pfrom.GetId()); | ||||
if (gArgs.IsArgSet("-dropmessagestest") && | if (gArgs.IsArgSet("-dropmessagestest") && | ||||
GetRand(gArgs.GetArg("-dropmessagestest", 0)) == 0) { | GetRand(gArgs.GetArg("-dropmessagestest", 0)) == 0) { | ||||
LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n"); | LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n"); | ||||
return; | return; | ||||
} | } | ||||
PeerRef peer = GetPeerRef(pfrom.GetId()); | |||||
if (peer == nullptr) { | |||||
return; | |||||
} | |||||
if (IsAvalancheMessageType(msg_type)) { | if (IsAvalancheMessageType(msg_type)) { | ||||
if (!g_avalanche) { | if (!g_avalanche) { | ||||
LogPrint(BCLog::AVALANCHE, | LogPrint(BCLog::AVALANCHE, | ||||
"Avalanche is not initialized, ignoring %s message\n", | "Avalanche is not initialized, ignoring %s message\n", | ||||
msg_type); | msg_type); | ||||
return; | return; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 773 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::TX) { | ||||
// about any requests for it. | // about any requests for it. | ||||
m_txrequest.ForgetInvId(tx.GetId()); | m_txrequest.ForgetInvId(tx.GetId()); | ||||
RelayTransaction(tx.GetId(), m_connman); | RelayTransaction(tx.GetId(), m_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)); | ||||
if (it_by_prev != mapOrphanTransactionsByPrev.end()) { | if (it_by_prev != mapOrphanTransactionsByPrev.end()) { | ||||
for (const auto &elem : it_by_prev->second) { | for (const auto &elem : it_by_prev->second) { | ||||
pfrom.m_orphan_work_set.insert(elem->first); | peer->m_orphan_work_set.insert(elem->first); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
pfrom.nLastTXTime = GetTime(); | pfrom.nLastTXTime = GetTime(); | ||||
LogPrint(BCLog::MEMPOOL, | LogPrint(BCLog::MEMPOOL, | ||||
"AcceptToMemoryPool: peer=%d: accepted %s " | "AcceptToMemoryPool: peer=%d: accepted %s " | ||||
"(poolsz %u txn, %u kB)\n", | "(poolsz %u txn, %u kB)\n", | ||||
pfrom.GetId(), tx.GetId().ToString(), m_mempool.size(), | pfrom.GetId(), tx.GetId().ToString(), m_mempool.size(), | ||||
m_mempool.DynamicMemoryUsage() / 1000); | m_mempool.DynamicMemoryUsage() / 1000); | ||||
// Recursively process any orphan transactions that depended on this | // Recursively process any orphan transactions that depended on this | ||||
// one | // one | ||||
ProcessOrphanTx(config, pfrom.m_orphan_work_set); | ProcessOrphanTx(config, peer->m_orphan_work_set); | ||||
} else if (state.GetResult() == TxValidationResult::TX_MISSING_INPUTS) { | } else if (state.GetResult() == TxValidationResult::TX_MISSING_INPUTS) { | ||||
// It may be the case that the orphans parents have all been | // It may be the case that the orphans parents have all been | ||||
// rejected. | // rejected. | ||||
bool fRejectedParents = false; | bool fRejectedParents = false; | ||||
// Deduplicate parent txids, so that we don't have to loop over | // Deduplicate parent txids, so that we don't have to loop over | ||||
// the same parent txid more than once down below. | // the same parent txid more than once down below. | ||||
std::vector<TxId> unique_parents; | std::vector<TxId> unique_parents; | ||||
▲ Show 20 Lines • Show All 1,151 Lines • ▼ Show 20 Lines | bool PeerManager::ProcessMessages(const Config &config, CNode *pfrom, | ||||
// (4) message start | // (4) message start | ||||
// (12) command | // (12) command | ||||
// (4) size | // (4) size | ||||
// (4) checksum | // (4) checksum | ||||
// (x) data | // (x) data | ||||
// | // | ||||
bool fMoreWork = false; | bool fMoreWork = false; | ||||
PeerRef peer = GetPeerRef(pfrom->GetId()); | |||||
if (peer == nullptr) { | |||||
return false; | |||||
} | |||||
if (!pfrom->vRecvGetData.empty()) { | if (!pfrom->vRecvGetData.empty()) { | ||||
ProcessGetData(config, *pfrom, m_connman, m_mempool, interruptMsgProc); | ProcessGetData(config, *pfrom, m_connman, m_mempool, interruptMsgProc); | ||||
} | } | ||||
if (!pfrom->m_orphan_work_set.empty()) { | if (!peer->m_orphan_work_set.empty()) { | ||||
LOCK2(cs_main, g_cs_orphans); | LOCK2(cs_main, g_cs_orphans); | ||||
ProcessOrphanTx(config, pfrom->m_orphan_work_set); | ProcessOrphanTx(config, peer->m_orphan_work_set); | ||||
} | } | ||||
if (pfrom->fDisconnect) { | if (pfrom->fDisconnect) { | ||||
return false; | return false; | ||||
} | } | ||||
// this maintains the order of responses and prevents vRecvGetData from | // this maintains the order of responses and prevents vRecvGetData from | ||||
// growing unbounded | // growing unbounded | ||||
if (!pfrom->vRecvGetData.empty()) { | if (!pfrom->vRecvGetData.empty()) { | ||||
return true; | return true; | ||||
} | } | ||||
if (!pfrom->m_orphan_work_set.empty()) { | if (!peer->m_orphan_work_set.empty()) { | ||||
return true; | return true; | ||||
} | } | ||||
// Don't bother if send buffer is too full to respond anyway | // Don't bother if send buffer is too full to respond anyway | ||||
if (pfrom->fPauseSend) { | if (pfrom->fPauseSend) { | ||||
return false; | return false; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,109 Lines • Show Last 20 Lines |