Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 5,182 Lines • ▼ Show 20 Lines | if (pingSend) { | ||||
pto->vBlockHashesToAnnounce.clear(); | pto->vBlockHashesToAnnounce.clear(); | ||||
} | } | ||||
// | // | ||||
// Message: inventory | // Message: inventory | ||||
// | // | ||||
std::vector<CInv> vInv; | std::vector<CInv> vInv; | ||||
{ | { | ||||
auto addInvAndMaybeFlush = [&](uint32_t type, const uint256 &hash) { | |||||
vInv.emplace_back(type, hash); | |||||
if (vInv.size() == MAX_INV_SZ) { | |||||
m_connman.PushMessage( | |||||
pto, msgMaker.Make(NetMsgType::INV, std::move(vInv))); | |||||
vInv.clear(); | |||||
} | |||||
}; | |||||
LOCK(pto->cs_inventory); | LOCK(pto->cs_inventory); | ||||
vInv.reserve(std::max<size_t>(pto->vInventoryBlockToSend.size(), | vInv.reserve(std::max<size_t>(pto->vInventoryBlockToSend.size(), | ||||
INVENTORY_BROADCAST_MAX_PER_MB * | INVENTORY_BROADCAST_MAX_PER_MB * | ||||
config.GetMaxBlockSize() / | config.GetMaxBlockSize() / | ||||
1000000)); | 1000000)); | ||||
// Add blocks | // Add blocks | ||||
for (const BlockHash &hash : pto->vInventoryBlockToSend) { | for (const BlockHash &hash : pto->vInventoryBlockToSend) { | ||||
vInv.push_back(CInv(MSG_BLOCK, hash)); | addInvAndMaybeFlush(MSG_BLOCK, hash); | ||||
if (vInv.size() == MAX_INV_SZ) { | |||||
m_connman.PushMessage(pto, | |||||
msgMaker.Make(NetMsgType::INV, vInv)); | |||||
vInv.clear(); | |||||
} | |||||
} | } | ||||
pto->vInventoryBlockToSend.clear(); | pto->vInventoryBlockToSend.clear(); | ||||
if (pto->m_tx_relay != nullptr) { | if (pto->m_tx_relay != nullptr) { | ||||
LOCK(pto->m_tx_relay->cs_tx_inventory); | LOCK(pto->m_tx_relay->cs_tx_inventory); | ||||
// Check whether periodic sends should happen | // Check whether periodic sends should happen | ||||
bool fSendTrickle = pto->HasPermission(PF_NOBAN); | bool fSendTrickle = pto->HasPermission(PF_NOBAN); | ||||
if (pto->m_tx_relay->nNextInvSend < current_time) { | if (pto->m_tx_relay->nNextInvSend < current_time) { | ||||
Show All 28 Lines | if (pingSend) { | ||||
LOCK(pto->m_tx_relay->cs_feeFilter); | LOCK(pto->m_tx_relay->cs_feeFilter); | ||||
filterrate = CFeeRate(pto->m_tx_relay->minFeeFilter); | filterrate = CFeeRate(pto->m_tx_relay->minFeeFilter); | ||||
} | } | ||||
LOCK(pto->m_tx_relay->cs_filter); | LOCK(pto->m_tx_relay->cs_filter); | ||||
for (const auto &txinfo : vtxinfo) { | for (const auto &txinfo : vtxinfo) { | ||||
const TxId &txid = txinfo.tx->GetId(); | const TxId &txid = txinfo.tx->GetId(); | ||||
CInv inv(MSG_TX, txid); | |||||
pto->m_tx_relay->setInventoryTxToSend.erase(txid); | pto->m_tx_relay->setInventoryTxToSend.erase(txid); | ||||
// Don't send transactions that peers will not put into | // Don't send transactions that peers will not put into | ||||
// their mempool | // their mempool | ||||
if (txinfo.fee < filterrate.GetFee(txinfo.vsize)) { | if (txinfo.fee < filterrate.GetFee(txinfo.vsize)) { | ||||
continue; | continue; | ||||
} | } | ||||
if (pto->m_tx_relay->pfilter && | if (pto->m_tx_relay->pfilter && | ||||
!pto->m_tx_relay->pfilter->IsRelevantAndUpdate( | !pto->m_tx_relay->pfilter->IsRelevantAndUpdate( | ||||
*txinfo.tx)) { | *txinfo.tx)) { | ||||
continue; | continue; | ||||
} | } | ||||
pto->m_tx_relay->filterInventoryKnown.insert(txid); | pto->m_tx_relay->filterInventoryKnown.insert(txid); | ||||
// Responses to MEMPOOL requests bypass the | // Responses to MEMPOOL requests bypass the | ||||
// m_recently_announced_invs filter. | // m_recently_announced_invs filter. | ||||
vInv.push_back(inv); | addInvAndMaybeFlush(MSG_TX, txid); | ||||
if (vInv.size() == MAX_INV_SZ) { | |||||
m_connman.PushMessage( | |||||
pto, msgMaker.Make(NetMsgType::INV, vInv)); | |||||
vInv.clear(); | |||||
} | |||||
} | } | ||||
pto->m_tx_relay->m_last_mempool_req = | pto->m_tx_relay->m_last_mempool_req = | ||||
GetTime<std::chrono::seconds>(); | GetTime<std::chrono::seconds>(); | ||||
} | } | ||||
// Determine transactions to relay | // Determine transactions to relay | ||||
if (fSendTrickle) { | if (fSendTrickle) { | ||||
// Produce a vector with all candidates for sending | // Produce a vector with all candidates for sending | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | if (pingSend) { | ||||
if (pto->m_tx_relay->pfilter && | if (pto->m_tx_relay->pfilter && | ||||
!pto->m_tx_relay->pfilter->IsRelevantAndUpdate( | !pto->m_tx_relay->pfilter->IsRelevantAndUpdate( | ||||
*txinfo.tx)) { | *txinfo.tx)) { | ||||
continue; | continue; | ||||
} | } | ||||
// Send | // Send | ||||
State(pto->GetId()) | State(pto->GetId()) | ||||
->m_recently_announced_invs.insert(txid); | ->m_recently_announced_invs.insert(txid); | ||||
vInv.push_back(CInv(MSG_TX, txid)); | addInvAndMaybeFlush(MSG_TX, txid); | ||||
nRelayedTransactions++; | nRelayedTransactions++; | ||||
{ | { | ||||
// Expire old relay messages | // Expire old relay messages | ||||
while (!vRelayExpiration.empty() && | while (!vRelayExpiration.empty() && | ||||
vRelayExpiration.front().first < nNow) { | vRelayExpiration.front().first < nNow) { | ||||
mapRelay.erase(vRelayExpiration.front().second); | mapRelay.erase(vRelayExpiration.front().second); | ||||
vRelayExpiration.pop_front(); | vRelayExpiration.pop_front(); | ||||
} | } | ||||
auto ret = mapRelay.insert( | auto ret = mapRelay.insert( | ||||
std::make_pair(txid, std::move(txinfo.tx))); | std::make_pair(txid, std::move(txinfo.tx))); | ||||
if (ret.second) { | if (ret.second) { | ||||
vRelayExpiration.push_back(std::make_pair( | vRelayExpiration.push_back(std::make_pair( | ||||
nNow + | nNow + | ||||
std::chrono::microseconds{ | std::chrono::microseconds{ | ||||
RELAY_TX_CACHE_TIME} | RELAY_TX_CACHE_TIME} | ||||
.count(), | .count(), | ||||
ret.first)); | ret.first)); | ||||
} | } | ||||
} | } | ||||
if (vInv.size() == MAX_INV_SZ) { | |||||
m_connman.PushMessage( | |||||
pto, msgMaker.Make(NetMsgType::INV, vInv)); | |||||
vInv.clear(); | |||||
} | |||||
pto->m_tx_relay->filterInventoryKnown.insert(txid); | pto->m_tx_relay->filterInventoryKnown.insert(txid); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (!vInv.empty()) { | if (!vInv.empty()) { | ||||
m_connman.PushMessage(pto, msgMaker.Make(NetMsgType::INV, vInv)); | m_connman.PushMessage(pto, msgMaker.Make(NetMsgType::INV, vInv)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 264 Lines • Show Last 20 Lines |