mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-08 14:47:31 +02:00
Merge bitcoin/bitcoin#34389: net/log: standardize peer+addr log formatting via LogPeer
22335474d7net: format peer+addr logs with `LogPeer` (Lőrinc)e55ea534f7test: add pre-`LogPeer` net log assertion (Lőrinc)736b17c0f0log: fix minor formatting in debug logs (Lőrinc)9cf82bed32log: show placeholders for missing peer fields (Lőrinc) Pull request description: This is an alternative to #34293, but aims to address the remaining logging inconsistencies more broadly. It extends the example fixed there to every instance, restores the original separator behavior, applies it consistently via a single helper, and adds tests for `logips` (covering both current and new behavior). ### Problem After #28521 centralized peer address logging into `CNode::LogIP()`, the original comma separator before `peeraddr=` was lost, resulting in inconsistent formatting across net (and recent private broadcast) logs. Some lines also had double spaces, empty fields, or mismatched format specifiers. ### Fix Introduces `CNode::LogPeer(bool)` which always emits `peer=<id>` and, when `-logips=1`, appends `, peeraddr=<addr>`. This eliminates hand-rolled separators and makes peer identification predictable. Minor issues (double spaces, empty placeholders, format specifiers) are fixed along the way in separate commits. ### Reproducer Run with `-debug=net -logips=1` and observe peer log lines now show `peer=<id>, peeraddr=<addr>` (comma-separated). The new assertion in `feature_logging.py` automates this check. ACKs for top commit: naiyoma: ACK22335474d7vasild: ACK22335474d7sedited: ACK22335474d7Tree-SHA512: 562262a58c3042f139099ff4c41e3fc6a97505fe9603c2bf700a97fd0aa052954b47c14da0e50c1fc311db1ae6c04e6a92156c9b85e25c777a637b7766c1dafe
This commit is contained in:
@@ -2377,7 +2377,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
|
||||
(((m_chainman.m_best_header != nullptr) && (m_chainman.m_best_header->GetBlockTime() - pindex->GetBlockTime() > HISTORICAL_BLOCK_AGE)) || inv.IsMsgFilteredBlk()) &&
|
||||
!pfrom.HasPermission(NetPermissionFlags::Download) // nodes with the download permission may exceed target
|
||||
) {
|
||||
LogDebug(BCLog::NET, "historical block serving limit reached, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "historical block serving limit reached, %s", pfrom.DisconnectMsg());
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
@@ -2386,7 +2386,7 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
|
||||
if (!pfrom.HasPermission(NetPermissionFlags::NoBan) && (
|
||||
(((peer.m_our_services & NODE_NETWORK_LIMITED) == NODE_NETWORK_LIMITED) && ((peer.m_our_services & NODE_NETWORK) != NODE_NETWORK) && (tip->nHeight - pindex->nHeight > (int)NODE_NETWORK_LIMITED_MIN_BLOCKS + 2 /* add two blocks buffer extension for possible races */) )
|
||||
)) {
|
||||
LogDebug(BCLog::NET, "Ignore block request below NODE_NETWORK_LIMITED threshold, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "Ignore block request below NODE_NETWORK_LIMITED threshold, %s", pfrom.DisconnectMsg());
|
||||
//disconnect node and prevent it from stalling (would otherwise wait for the missing block)
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
@@ -2410,9 +2410,9 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
|
||||
MakeAndPushMessage(pfrom, NetMsgType::BLOCK, std::span{*block_data});
|
||||
} else {
|
||||
if (WITH_LOCK(m_chainman.GetMutex(), return m_chainman.m_blockman.IsBlockPruned(*pindex))) {
|
||||
LogDebug(BCLog::NET, "Block was pruned before it could be read, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "Block was pruned before it could be read, %s", pfrom.DisconnectMsg());
|
||||
} else {
|
||||
LogError("Cannot load block from disk, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
LogError("Cannot load block from disk, %s", pfrom.DisconnectMsg());
|
||||
}
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
@@ -2423,9 +2423,9 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
|
||||
std::shared_ptr<CBlock> pblockRead = std::make_shared<CBlock>();
|
||||
if (!m_chainman.m_blockman.ReadBlock(*pblockRead, block_pos, inv.hash)) {
|
||||
if (WITH_LOCK(m_chainman.GetMutex(), return m_chainman.m_blockman.IsBlockPruned(*pindex))) {
|
||||
LogDebug(BCLog::NET, "Block was pruned before it could be read, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "Block was pruned before it could be read, %s", pfrom.DisconnectMsg());
|
||||
} else {
|
||||
LogError("Cannot load block from disk, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
LogError("Cannot load block from disk, %s", pfrom.DisconnectMsg());
|
||||
}
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
@@ -2878,8 +2878,8 @@ void PeerManagerImpl::HeadersDirectFetchBlocks(CNode& pfrom, const Peer& peer, c
|
||||
uint32_t nFetchFlags = GetFetchFlags(peer);
|
||||
vGetData.emplace_back(MSG_BLOCK | nFetchFlags, pindex->GetBlockHash());
|
||||
BlockRequested(pfrom.GetId(), *pindex);
|
||||
LogDebug(BCLog::NET, "Requesting block %s from peer=%d\n",
|
||||
pindex->GetBlockHash().ToString(), pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "Requesting block %s from peer=%d",
|
||||
pindex->GetBlockHash().ToString(), pfrom.GetId());
|
||||
}
|
||||
if (vGetData.size() > 1) {
|
||||
LogDebug(BCLog::NET, "Downloading blocks toward %s (%d) via headers direct fetch\n",
|
||||
@@ -2937,7 +2937,7 @@ void PeerManagerImpl::UpdatePeerStateForReceivedHeaders(CNode& pfrom, Peer& peer
|
||||
// the minimum chain work, even if a peer has a chain past our tip,
|
||||
// as an anti-DoS measure.
|
||||
if (pfrom.IsOutboundOrBlockRelayConn()) {
|
||||
LogInfo("outbound peer headers chain has insufficient work, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
LogInfo("outbound peer headers chain has insufficient work, %s", pfrom.DisconnectMsg());
|
||||
pfrom.fDisconnect = true;
|
||||
}
|
||||
}
|
||||
@@ -3272,8 +3272,8 @@ bool PeerManagerImpl::PrepareBlockFilterRequest(CNode& node, Peer& peer,
|
||||
(filter_type == BlockFilterType::BASIC &&
|
||||
(peer.m_our_services & NODE_COMPACT_FILTERS));
|
||||
if (!supported_filter_type) {
|
||||
LogDebug(BCLog::NET, "peer requested unsupported block filter type: %d, %s\n",
|
||||
static_cast<uint8_t>(filter_type), node.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "peer requested unsupported block filter type: %d, %s",
|
||||
static_cast<uint8_t>(filter_type), node.DisconnectMsg());
|
||||
node.fDisconnect = true;
|
||||
return false;
|
||||
}
|
||||
@@ -3284,8 +3284,8 @@ bool PeerManagerImpl::PrepareBlockFilterRequest(CNode& node, Peer& peer,
|
||||
|
||||
// Check that the stop block exists and the peer would be allowed to fetch it.
|
||||
if (!stop_index || !BlockRequestAllowed(*stop_index)) {
|
||||
LogDebug(BCLog::NET, "peer requested invalid block hash: %s, %s\n",
|
||||
stop_hash.ToString(), node.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "peer requested invalid block hash: %s, %s",
|
||||
stop_hash.ToString(), node.DisconnectMsg());
|
||||
node.fDisconnect = true;
|
||||
return false;
|
||||
}
|
||||
@@ -3294,14 +3294,14 @@ bool PeerManagerImpl::PrepareBlockFilterRequest(CNode& node, Peer& peer,
|
||||
uint32_t stop_height = stop_index->nHeight;
|
||||
if (start_height > stop_height) {
|
||||
LogDebug(BCLog::NET, "peer sent invalid getcfilters/getcfheaders with "
|
||||
"start height %d and stop height %d, %s\n",
|
||||
start_height, stop_height, node.DisconnectMsg(fLogIPs));
|
||||
"start height %d and stop height %d, %s",
|
||||
start_height, stop_height, node.DisconnectMsg());
|
||||
node.fDisconnect = true;
|
||||
return false;
|
||||
}
|
||||
if (stop_height - start_height >= max_height_diff) {
|
||||
LogDebug(BCLog::NET, "peer requested too many cfilters/cfheaders: %d / %d, %s\n",
|
||||
stop_height - start_height + 1, max_height_diff, node.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "peer requested too many cfilters/cfheaders: %d / %d, %s",
|
||||
stop_height - start_height + 1, max_height_diff, node.DisconnectMsg());
|
||||
node.fDisconnect = true;
|
||||
return false;
|
||||
}
|
||||
@@ -3540,12 +3540,11 @@ void PeerManagerImpl::LogBlockHeader(const CBlockIndex& index, const CNode& peer
|
||||
// Having this log by default when not in IBD ensures broad availability of
|
||||
// this data in case investigation is merited.
|
||||
const auto msg = strprintf(
|
||||
"Saw new %sheader hash=%s height=%d peer=%d%s",
|
||||
"Saw new %sheader hash=%s height=%d %s",
|
||||
via_compact_block ? "cmpctblock " : "",
|
||||
index.GetBlockHash().ToString(),
|
||||
index.nHeight,
|
||||
peer.GetId(),
|
||||
peer.LogIP(fLogIPs)
|
||||
peer.LogPeer()
|
||||
);
|
||||
if (m_chainman.IsInitialBlockDownload()) {
|
||||
LogDebug(BCLog::VALIDATION, "%s", msg);
|
||||
@@ -3560,15 +3559,15 @@ void PeerManagerImpl::PushPrivateBroadcastTx(CNode& node)
|
||||
|
||||
const auto opt_tx{m_tx_for_private_broadcast.PickTxForSend(node.GetId(), CService{node.addr})};
|
||||
if (!opt_tx) {
|
||||
LogDebug(BCLog::PRIVBROADCAST, "Disconnecting: no more transactions for private broadcast (connected in vain), peer=%d%s", node.GetId(), node.LogIP(fLogIPs));
|
||||
LogDebug(BCLog::PRIVBROADCAST, "Disconnecting: no more transactions for private broadcast (connected in vain), %s", node.LogPeer());
|
||||
node.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
const CTransactionRef& tx{*opt_tx};
|
||||
|
||||
LogDebug(BCLog::PRIVBROADCAST, "P2P handshake completed, sending INV for txid=%s%s, peer=%d%s",
|
||||
LogDebug(BCLog::PRIVBROADCAST, "P2P handshake completed, sending INV for txid=%s%s, %s",
|
||||
tx->GetHash().ToString(), tx->HasWitness() ? strprintf(", wtxid=%s", tx->GetWitnessHash().ToString()) : "",
|
||||
node.GetId(), node.LogIP(fLogIPs));
|
||||
node.LogPeer());
|
||||
|
||||
MakeAndPushMessage(node, NetMsgType::INV, std::vector<CInv>{{CInv{MSG_TX, tx->GetHash().ToUint256()}}});
|
||||
}
|
||||
@@ -3612,17 +3611,17 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
}
|
||||
if (pfrom.ExpectServicesFromConn() && !HasAllDesirableServiceFlags(nServices))
|
||||
{
|
||||
LogDebug(BCLog::NET, "peer does not offer the expected services (%08x offered, %08x expected), %s\n",
|
||||
LogDebug(BCLog::NET, "peer does not offer the expected services (%08x offered, %08x expected), %s",
|
||||
nServices,
|
||||
GetDesirableServiceFlags(nServices),
|
||||
pfrom.DisconnectMsg(fLogIPs));
|
||||
pfrom.DisconnectMsg());
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (nVersion < MIN_PEER_PROTO_VERSION) {
|
||||
// disconnect from peers older than this proto version
|
||||
LogDebug(BCLog::NET, "peer using obsolete version %i, %s\n", nVersion, pfrom.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "peer using obsolete version %i, %s", nVersion, pfrom.DisconnectMsg());
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
@@ -3696,17 +3695,17 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
}
|
||||
|
||||
const auto mapped_as{m_connman.GetMappedAS(pfrom.addr)};
|
||||
LogDebug(BCLog::NET, "receive version message: %s: version %d, blocks=%d, us=%s, txrelay=%d, peer=%d%s%s\n",
|
||||
cleanSubVer, pfrom.nVersion,
|
||||
peer.m_starting_height, addrMe.ToStringAddrPort(), fRelay, pfrom.GetId(),
|
||||
pfrom.LogIP(fLogIPs), (mapped_as ? strprintf(", mapped_as=%d", mapped_as) : ""));
|
||||
LogDebug(BCLog::NET, "receive version message: %s: version %d, blocks=%d, us=%s, txrelay=%d, %s%s",
|
||||
cleanSubVer.empty() ? "<no user agent>" : cleanSubVer, pfrom.nVersion,
|
||||
peer.m_starting_height, addrMe.ToStringAddrPort(), fRelay, pfrom.LogPeer(),
|
||||
(mapped_as ? strprintf(", mapped_as=%d", mapped_as) : ""));
|
||||
|
||||
if (pfrom.IsPrivateBroadcastConn()) {
|
||||
if (fRelay) {
|
||||
MakeAndPushMessage(pfrom, NetMsgType::VERACK);
|
||||
} else {
|
||||
LogDebug(BCLog::PRIVBROADCAST, "Disconnecting: does not support transaction relay (connected in vain), peer=%d%s",
|
||||
pfrom.GetId(), pfrom.LogIP(fLogIPs));
|
||||
LogDebug(BCLog::PRIVBROADCAST, "Disconnecting: does not support transaction relay (connected in vain), %s",
|
||||
pfrom.LogPeer());
|
||||
pfrom.fDisconnect = true;
|
||||
}
|
||||
return;
|
||||
@@ -3806,7 +3805,7 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
|
||||
// Feeler connections exist only to verify if address is online.
|
||||
if (pfrom.IsFeelerConn()) {
|
||||
LogDebug(BCLog::NET, "feeler connection completed, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "feeler connection completed, %s", pfrom.DisconnectMsg());
|
||||
pfrom.fDisconnect = true;
|
||||
}
|
||||
return;
|
||||
@@ -3826,11 +3825,11 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
|
||||
auto new_peer_msg = [&]() {
|
||||
const auto mapped_as{m_connman.GetMappedAS(pfrom.addr)};
|
||||
return strprintf("New %s peer connected: transport: %s, version: %d, blocks=%d peer=%d%s%s\n",
|
||||
return strprintf("New %s peer connected: transport: %s, version: %d, blocks=%d, %s%s",
|
||||
pfrom.ConnectionTypeAsString(),
|
||||
TransportTypeAsString(pfrom.m_transport->GetInfo().transport_type),
|
||||
pfrom.nVersion.load(), peer.m_starting_height,
|
||||
pfrom.GetId(), pfrom.LogIP(fLogIPs),
|
||||
pfrom.LogPeer(),
|
||||
(mapped_as ? strprintf(", mapped_as=%d", mapped_as) : ""));
|
||||
};
|
||||
|
||||
@@ -3927,7 +3926,7 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
if (msg_type == NetMsgType::WTXIDRELAY) {
|
||||
if (pfrom.fSuccessfullyConnected) {
|
||||
// Disconnect peers that send a wtxidrelay message after VERACK.
|
||||
LogDebug(BCLog::NET, "wtxidrelay received after verack, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "wtxidrelay received after verack, %s", pfrom.DisconnectMsg());
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
@@ -3949,7 +3948,7 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
if (msg_type == NetMsgType::SENDADDRV2) {
|
||||
if (pfrom.fSuccessfullyConnected) {
|
||||
// Disconnect peers that send a SENDADDRV2 message after VERACK.
|
||||
LogDebug(BCLog::NET, "sendaddrv2 received after verack, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "sendaddrv2 received after verack, %s", pfrom.DisconnectMsg());
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
@@ -3967,14 +3966,14 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
}
|
||||
|
||||
if (pfrom.fSuccessfullyConnected) {
|
||||
LogDebug(BCLog::NET, "sendtxrcncl received after verack, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "sendtxrcncl received after verack, %s", pfrom.DisconnectMsg());
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Peer must not offer us reconciliations if we specified no tx relay support in VERSION.
|
||||
if (RejectIncomingTxs(pfrom)) {
|
||||
LogDebug(BCLog::NET, "sendtxrcncl received to which we indicated no tx relay, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "sendtxrcncl received to which we indicated no tx relay, %s", pfrom.DisconnectMsg());
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
@@ -3984,7 +3983,7 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
// eliminates them, so that this flag fully represents what we are looking for.
|
||||
const auto* tx_relay = peer.GetTxRelay();
|
||||
if (!tx_relay || !WITH_LOCK(tx_relay->m_bloom_filter_mutex, return tx_relay->m_relay_txs)) {
|
||||
LogDebug(BCLog::NET, "sendtxrcncl received which indicated no tx relay to us, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "sendtxrcncl received which indicated no tx relay to us, %s", pfrom.DisconnectMsg());
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
@@ -4002,11 +4001,11 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
case ReconciliationRegisterResult::SUCCESS:
|
||||
break;
|
||||
case ReconciliationRegisterResult::ALREADY_REGISTERED:
|
||||
LogDebug(BCLog::NET, "txreconciliation protocol violation (sendtxrcncl received from already registered peer), %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "txreconciliation protocol violation (sendtxrcncl received from already registered peer), %s", pfrom.DisconnectMsg());
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
case ReconciliationRegisterResult::PROTOCOL_VIOLATION:
|
||||
LogDebug(BCLog::NET, "txreconciliation protocol violation, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "txreconciliation protocol violation, %s", pfrom.DisconnectMsg());
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
@@ -4020,7 +4019,7 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
|
||||
if (pfrom.IsPrivateBroadcastConn()) {
|
||||
if (msg_type != NetMsgType::PONG && msg_type != NetMsgType::GETDATA) {
|
||||
LogDebug(BCLog::PRIVBROADCAST, "Ignoring incoming message '%s', peer=%d%s", msg_type, pfrom.GetId(), pfrom.LogIP(fLogIPs));
|
||||
LogDebug(BCLog::PRIVBROADCAST, "Ignoring incoming message '%s', %s", msg_type, pfrom.LogPeer());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -4116,7 +4115,7 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
|
||||
// AddrFetch: Require multiple addresses to avoid disconnecting on self-announcements
|
||||
if (pfrom.IsAddrFetchConn() && vAddr.size() > 1) {
|
||||
LogDebug(BCLog::NET, "addrfetch connection completed, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "addrfetch connection completed, %s", pfrom.DisconnectMsg());
|
||||
pfrom.fDisconnect = true;
|
||||
}
|
||||
return;
|
||||
@@ -4152,7 +4151,7 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
|
||||
if (inv.IsMsgBlk()) {
|
||||
const bool fAlreadyHave = AlreadyHaveBlock(inv.hash);
|
||||
LogDebug(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "got inv: %s %s peer=%d", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId());
|
||||
|
||||
UpdateBlockAvailability(pfrom.GetId(), inv.hash);
|
||||
if (!fAlreadyHave && !m_chainman.m_blockman.LoadingBlocks() && !IsBlockRequested(inv.hash)) {
|
||||
@@ -4166,7 +4165,7 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
}
|
||||
} else if (inv.IsGenTxMsg()) {
|
||||
if (reject_tx_invs) {
|
||||
LogDebug(BCLog::NET, "transaction (%s) inv sent in violation of protocol, %s\n", inv.hash.ToString(), pfrom.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "transaction (%s) inv sent in violation of protocol, %s", inv.hash.ToString(), pfrom.DisconnectMsg());
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
@@ -4175,7 +4174,7 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
|
||||
if (!m_chainman.IsInitialBlockDownload()) {
|
||||
const bool fAlreadyHave{m_txdownloadman.AddTxAnnouncement(pfrom.GetId(), gtxid, current_time)};
|
||||
LogDebug(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "got inv: %s %s peer=%d", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId());
|
||||
}
|
||||
} else {
|
||||
LogDebug(BCLog::NET, "Unknown inv type \"%s\" received from peer=%d\n", inv.ToString(), pfrom.GetId());
|
||||
@@ -4231,8 +4230,8 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
if (pfrom.IsPrivateBroadcastConn()) {
|
||||
const auto pushed_tx_opt{m_tx_for_private_broadcast.GetTxForNode(pfrom.GetId())};
|
||||
if (!pushed_tx_opt) {
|
||||
LogDebug(BCLog::PRIVBROADCAST, "Disconnecting: got GETDATA without sending an INV, peer=%d%s",
|
||||
pfrom.GetId(), fLogIPs ? strprintf(", peeraddr=%s", pfrom.addr.ToStringAddrPort()) : "");
|
||||
LogDebug(BCLog::PRIVBROADCAST, "Disconnecting: got GETDATA without sending an INV, %s",
|
||||
pfrom.LogPeer());
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
@@ -4248,8 +4247,8 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
peer.m_ping_queued = true; // Ensure a ping will be sent: mimic a request via RPC.
|
||||
MaybeSendPing(pfrom, peer, GetTime<std::chrono::microseconds>());
|
||||
} else {
|
||||
LogDebug(BCLog::PRIVBROADCAST, "Disconnecting: got an unexpected GETDATA message, peer=%d%s",
|
||||
pfrom.GetId(), fLogIPs ? strprintf(", peeraddr=%s", pfrom.addr.ToStringAddrPort()) : "");
|
||||
LogDebug(BCLog::PRIVBROADCAST, "Disconnecting: got an unexpected GETDATA message, %s",
|
||||
pfrom.LogPeer());
|
||||
pfrom.fDisconnect = true;
|
||||
}
|
||||
return;
|
||||
@@ -4270,7 +4269,7 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
vRecv >> locator >> hashStop;
|
||||
|
||||
if (locator.vHave.size() > MAX_LOCATOR_SZ) {
|
||||
LogDebug(BCLog::NET, "getblocks locator size %lld > %d, %s\n", locator.vHave.size(), MAX_LOCATOR_SZ, pfrom.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "getblocks locator size %lld > %d, %s", locator.vHave.size(), MAX_LOCATOR_SZ, pfrom.DisconnectMsg());
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
@@ -4308,7 +4307,7 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
{
|
||||
if (pindex->GetBlockHash() == hashStop)
|
||||
{
|
||||
LogDebug(BCLog::NET, " getblocks stopping at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString());
|
||||
LogDebug(BCLog::NET, " getblocks stopping at %d %s", pindex->nHeight, pindex->GetBlockHash().ToString());
|
||||
break;
|
||||
}
|
||||
// If pruning, don't inv blocks unless we have on disk and are likely to still have
|
||||
@@ -4322,7 +4321,7 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
if (--nLimit <= 0) {
|
||||
// When this block is requested, we'll send an inv that'll
|
||||
// trigger the peer to getblocks the next batch of inventory.
|
||||
LogDebug(BCLog::NET, " getblocks stopping at limit %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString());
|
||||
LogDebug(BCLog::NET, " getblocks stopping at limit %d %s", pindex->nHeight, pindex->GetBlockHash().ToString());
|
||||
WITH_LOCK(peer.m_block_inv_mutex, {peer.m_continuation_block = pindex->GetBlockHash();});
|
||||
break;
|
||||
}
|
||||
@@ -4397,7 +4396,7 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
vRecv >> locator >> hashStop;
|
||||
|
||||
if (locator.vHave.size() > MAX_LOCATOR_SZ) {
|
||||
LogDebug(BCLog::NET, "getheaders locator size %lld > %d, %s\n", locator.vHave.size(), MAX_LOCATOR_SZ, pfrom.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "getheaders locator size %lld > %d, %s", locator.vHave.size(), MAX_LOCATOR_SZ, pfrom.DisconnectMsg());
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
@@ -4472,7 +4471,7 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
|
||||
if (msg_type == NetMsgType::TX) {
|
||||
if (RejectIncomingTxs(pfrom)) {
|
||||
LogDebug(BCLog::NET, "transaction sent in violation of protocol, %s", pfrom.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "transaction sent in violation of protocol, %s", pfrom.DisconnectMsg());
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
@@ -4493,8 +4492,8 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
|
||||
if (const auto num_broadcasted{m_tx_for_private_broadcast.Remove(ptx)}) {
|
||||
LogDebug(BCLog::PRIVBROADCAST, "Received our privately broadcast transaction (txid=%s) from the "
|
||||
"network from peer=%d%s; stopping private broadcast attempts",
|
||||
txid.ToString(), pfrom.GetId(), pfrom.LogIP(fLogIPs));
|
||||
"network from %s; stopping private broadcast attempts",
|
||||
txid.ToString(), pfrom.LogPeer());
|
||||
if (NUM_PRIVATE_BROADCAST_PER_TX > num_broadcasted.value()) {
|
||||
// Not all of the initial NUM_PRIVATE_BROADCAST_PER_TX connections were needed.
|
||||
// Tell CConnman it does not need to start the remaining ones.
|
||||
@@ -4944,7 +4943,7 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
{
|
||||
if (!pfrom.HasPermission(NetPermissionFlags::NoBan))
|
||||
{
|
||||
LogDebug(BCLog::NET, "mempool request with bloom filters disabled, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "mempool request with bloom filters disabled, %s", pfrom.DisconnectMsg());
|
||||
pfrom.fDisconnect = true;
|
||||
}
|
||||
return;
|
||||
@@ -4954,7 +4953,7 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
{
|
||||
if (!pfrom.HasPermission(NetPermissionFlags::NoBan))
|
||||
{
|
||||
LogDebug(BCLog::NET, "mempool request with bandwidth limit reached, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "mempool request with bandwidth limit reached, %s", pfrom.DisconnectMsg());
|
||||
pfrom.fDisconnect = true;
|
||||
}
|
||||
return;
|
||||
@@ -5008,8 +5007,8 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
pfrom.PongReceived(ping_time);
|
||||
if (pfrom.IsPrivateBroadcastConn()) {
|
||||
m_tx_for_private_broadcast.NodeConfirmedReception(pfrom.GetId());
|
||||
LogDebug(BCLog::PRIVBROADCAST, "Got a PONG (the transaction will probably reach the network), marking for disconnect, peer=%d%s",
|
||||
pfrom.GetId(), pfrom.LogIP(fLogIPs));
|
||||
LogDebug(BCLog::PRIVBROADCAST, "Got a PONG (the transaction will probably reach the network), marking for disconnect, %s",
|
||||
pfrom.LogPeer());
|
||||
pfrom.fDisconnect = true;
|
||||
}
|
||||
} else {
|
||||
@@ -5050,7 +5049,7 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
|
||||
if (msg_type == NetMsgType::FILTERLOAD) {
|
||||
if (!(peer.m_our_services & NODE_BLOOM)) {
|
||||
LogDebug(BCLog::NET, "filterload received despite not offering bloom services, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "filterload received despite not offering bloom services, %s", pfrom.DisconnectMsg());
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
@@ -5075,7 +5074,7 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
|
||||
if (msg_type == NetMsgType::FILTERADD) {
|
||||
if (!(peer.m_our_services & NODE_BLOOM)) {
|
||||
LogDebug(BCLog::NET, "filteradd received despite not offering bloom services, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "filteradd received despite not offering bloom services, %s", pfrom.DisconnectMsg());
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
@@ -5103,7 +5102,7 @@ void PeerManagerImpl::ProcessMessage(Peer& peer, CNode& pfrom, const std::string
|
||||
|
||||
if (msg_type == NetMsgType::FILTERCLEAR) {
|
||||
if (!(peer.m_our_services & NODE_BLOOM)) {
|
||||
LogDebug(BCLog::NET, "filterclear received despite not offering bloom services, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "filterclear received despite not offering bloom services, %s", pfrom.DisconnectMsg());
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
@@ -5325,7 +5324,7 @@ void PeerManagerImpl::ConsiderEviction(CNode& pto, Peer& peer, std::chrono::seco
|
||||
// message to give the peer a chance to update us.
|
||||
if (state.m_chain_sync.m_sent_getheaders) {
|
||||
// They've run out of time to catch up!
|
||||
LogInfo("Outbound peer has old chain, best known block = %s, %s\n", state.pindexBestKnownBlock != nullptr ? state.pindexBestKnownBlock->GetBlockHash().ToString() : "<none>", pto.DisconnectMsg(fLogIPs));
|
||||
LogInfo("Outbound peer has old chain, best known block = %s, %s", state.pindexBestKnownBlock != nullptr ? state.pindexBestKnownBlock->GetBlockHash().ToString() : "<none>", pto.DisconnectMsg());
|
||||
pto.fDisconnect = true;
|
||||
} else {
|
||||
assert(state.m_chain_sync.m_work_header);
|
||||
@@ -5492,7 +5491,7 @@ void PeerManagerImpl::MaybeSendPing(CNode& node_to, Peer& peer, std::chrono::mic
|
||||
{
|
||||
// The ping timeout is using mocktime. To disable the check during
|
||||
// testing, increase -peertimeout.
|
||||
LogDebug(BCLog::NET, "ping timeout: %fs, %s", 0.000001 * count_microseconds(now - peer.m_ping_start.load()), node_to.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "ping timeout: %fs, %s", 0.000001 * count_microseconds(now - peer.m_ping_start.load()), node_to.DisconnectMsg());
|
||||
node_to.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
@@ -5741,15 +5740,15 @@ bool PeerManagerImpl::SendMessages(CNode& node)
|
||||
// not sent. This here is just an optimization.
|
||||
if (node.IsPrivateBroadcastConn()) {
|
||||
if (node.m_connected + PRIVATE_BROADCAST_MAX_CONNECTION_LIFETIME < current_time) {
|
||||
LogDebug(BCLog::PRIVBROADCAST, "Disconnecting: did not complete the transaction send within %d seconds, peer=%d%s",
|
||||
count_seconds(PRIVATE_BROADCAST_MAX_CONNECTION_LIFETIME), node.GetId(), node.LogIP(fLogIPs));
|
||||
LogDebug(BCLog::PRIVBROADCAST, "Disconnecting: did not complete the transaction send within %d seconds, %s",
|
||||
count_seconds(PRIVATE_BROADCAST_MAX_CONNECTION_LIFETIME), node.LogPeer());
|
||||
node.fDisconnect = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (node.IsAddrFetchConn() && current_time - node.m_connected > 10 * AVG_ADDRESS_BROADCAST_INTERVAL) {
|
||||
LogDebug(BCLog::NET, "addrfetch connection timeout, %s\n", node.DisconnectMsg(fLogIPs));
|
||||
LogDebug(BCLog::NET, "addrfetch connection timeout, %s", node.DisconnectMsg());
|
||||
node.fDisconnect = true;
|
||||
return true;
|
||||
}
|
||||
@@ -6097,7 +6096,7 @@ bool PeerManagerImpl::SendMessages(CNode& node)
|
||||
// Stalling only triggers when the block download window cannot move. During normal steady state,
|
||||
// the download window should be much larger than the to-be-downloaded set of blocks, so disconnection
|
||||
// should only happen during initial block download.
|
||||
LogInfo("Peer is stalling block download, %s\n", node.DisconnectMsg(fLogIPs));
|
||||
LogInfo("Peer is stalling block download, %s", node.DisconnectMsg());
|
||||
node.fDisconnect = true;
|
||||
// Increase timeout for the next peer so that we don't disconnect multiple peers if our own
|
||||
// bandwidth is insufficient.
|
||||
@@ -6116,7 +6115,7 @@ bool PeerManagerImpl::SendMessages(CNode& node)
|
||||
QueuedBlock &queuedBlock = state.vBlocksInFlight.front();
|
||||
int nOtherPeersWithValidatedDownloads = m_peers_downloading_from - 1;
|
||||
if (current_time > state.m_downloading_since + std::chrono::seconds{consensusParams.nPowTargetSpacing} * (BLOCK_DOWNLOAD_TIMEOUT_BASE + BLOCK_DOWNLOAD_TIMEOUT_PER_PEER * nOtherPeersWithValidatedDownloads)) {
|
||||
LogInfo("Timeout downloading block %s, %s\n", queuedBlock.pindex->GetBlockHash().ToString(), node.DisconnectMsg(fLogIPs));
|
||||
LogInfo("Timeout downloading block %s, %s", queuedBlock.pindex->GetBlockHash().ToString(), node.DisconnectMsg());
|
||||
node.fDisconnect = true;
|
||||
return true;
|
||||
}
|
||||
@@ -6132,11 +6131,11 @@ bool PeerManagerImpl::SendMessages(CNode& node)
|
||||
// disconnect our sync peer for stalling; we have bigger
|
||||
// problems if we can't get any outbound peers.
|
||||
if (!node.HasPermission(NetPermissionFlags::NoBan)) {
|
||||
LogInfo("Timeout downloading headers, %s\n", node.DisconnectMsg(fLogIPs));
|
||||
LogInfo("Timeout downloading headers, %s", node.DisconnectMsg());
|
||||
node.fDisconnect = true;
|
||||
return true;
|
||||
} else {
|
||||
LogInfo("Timeout downloading headers from noban peer, not %s\n", node.DisconnectMsg(fLogIPs));
|
||||
LogInfo("Timeout downloading headers from noban peer, not %s", node.DisconnectMsg());
|
||||
// Reset the headers sync state so that we have a
|
||||
// chance to try downloading from a different peer.
|
||||
// Note: this will also result in at least one more
|
||||
|
||||
Reference in New Issue
Block a user