Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
Show First 20 Lines • Show All 2,999 Lines • ▼ Show 20 Lines | if (msg_type == NetMsgType::INV) { | ||||
fBlocksOnly = false; | fBlocksOnly = false; | ||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
const auto current_time = GetTime<std::chrono::microseconds>(); | const auto current_time = GetTime<std::chrono::microseconds>(); | ||||
std::optional<BlockHash> best_block; | std::optional<BlockHash> best_block; | ||||
auto logInv = [&](const CInv &inv, bool fAlreadyHave) { | |||||
LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), | |||||
fAlreadyHave ? "have" : "new", pfrom.GetId()); | |||||
}; | |||||
for (CInv &inv : vInv) { | for (CInv &inv : vInv) { | ||||
if (interruptMsgProc) { | if (interruptMsgProc) { | ||||
return; | return; | ||||
} | } | ||||
if (inv.IsMsgBlk()) { | if (inv.IsMsgBlk()) { | ||||
const bool fAlreadyHave = AlreadyHaveBlock(BlockHash(inv.hash)); | const bool fAlreadyHave = AlreadyHaveBlock(BlockHash(inv.hash)); | ||||
LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", | logInv(inv, fAlreadyHave); | ||||
inv.ToString(), fAlreadyHave ? "have" : "new", | |||||
pfrom.GetId()); | |||||
const BlockHash hash{inv.hash}; | const BlockHash hash{inv.hash}; | ||||
UpdateBlockAvailability(pfrom.GetId(), hash); | UpdateBlockAvailability(pfrom.GetId(), hash); | ||||
if (!fAlreadyHave && !fImporting && !fReindex && | if (!fAlreadyHave && !fImporting && !fReindex && | ||||
!mapBlocksInFlight.count(hash)) { | !mapBlocksInFlight.count(hash)) { | ||||
// Headers-first is the primary method of announcement on | // Headers-first is the primary method of announcement on | ||||
// the network. If a node fell back to sending blocks by | // the network. If a node fell back to sending blocks by | ||||
// inv, it's probably for a re-org. The final block hash | // inv, it's probably for a re-org. The final block hash | ||||
// provided should be the highest, so send a getheaders and | // provided should be the highest, so send a getheaders and | ||||
// then fetch the blocks we need to catch up. | // then fetch the blocks we need to catch up. | ||||
best_block = std::move(hash); | best_block = std::move(hash); | ||||
} | } | ||||
} else if (inv.IsMsgTx()) { | } else if (inv.IsMsgTx()) { | ||||
const TxId txid(inv.hash); | const TxId txid(inv.hash); | ||||
const bool fAlreadyHave = AlreadyHaveTx(txid, m_mempool); | const bool fAlreadyHave = AlreadyHaveTx(txid, m_mempool); | ||||
LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", | logInv(inv, fAlreadyHave); | ||||
inv.ToString(), fAlreadyHave ? "have" : "new", | |||||
pfrom.GetId()); | |||||
pfrom.AddKnownTx(txid); | 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", | ||||
txid.ToString(), pfrom.GetId()); | txid.ToString(), pfrom.GetId()); | ||||
pfrom.fDisconnect = true; | pfrom.fDisconnect = true; | ||||
▲ Show 20 Lines • Show All 2,450 Lines • Show Last 20 Lines |