Skip to content

Commit

Permalink
Remove NOTFOUND transactions from in-flight data structures
Browse files Browse the repository at this point in the history
This prevents a bug where the in-flight queue for our peers will not be
drained, resulting in not downloading any new transactions from our peers.

Thanks to ajtowns for reporting this bug.
  • Loading branch information
sdaftuar committed Apr 26, 2019
1 parent 23163b7 commit e32e084
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/net_processing.cpp
Expand Up @@ -3120,8 +3120,27 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
}

if (strCommand == NetMsgType::NOTFOUND) {
// We do not care about the NOTFOUND message, but logging an Unknown Command
// message would be undesirable as we transmit it ourselves.
// Remove the NOTFOUND transactions from the peer
LOCK(cs_main);
CNodeState *state = State(pfrom->GetId());
std::vector<CInv> vInv;
vRecv >> vInv;
if (vInv.size() <= MAX_PEER_TX_IN_FLIGHT + MAX_BLOCKS_IN_TRANSIT_PER_PEER) {
for (CInv &inv : vInv) {
if (inv.type == MSG_TX || inv.type == MSG_WITNESS_TX) {
// If we receive a NOTFOUND message for a txid we requested, erase
// it from our data structures for this peer.
auto in_flight_it = state->m_tx_download.m_tx_in_flight.find(inv.hash);
if (in_flight_it == state->m_tx_download.m_tx_in_flight.end()) {
// Skip any further work if this is a spurious NOTFOUND
// message.
continue;
}
state->m_tx_download.m_tx_in_flight.erase(in_flight_it);
state->m_tx_download.m_tx_announced.erase(inv.hash);
}
}
}
return true;
}

Expand Down

0 comments on commit e32e084

Please sign in to comment.