mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-09 11:27:28 -03:00
net_processing: use CNode::DisconnectMsg helper
This is not a pure refactor: 1. It slightly changes the log messages, as reflected in the test changes 2. It adds the IP address to all disconnect logging (when fLogIPs is set)
This commit is contained in:
parent
ad224429f8
commit
937ef9eb40
5 changed files with 53 additions and 50 deletions
|
@ -2238,7 +2238,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, disconnect peer=%d\n", pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "historical block serving limit reached, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
|
@ -2247,7 +2247,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, disconnect peer=%d\n", pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "Ignore block request below NODE_NETWORK_LIMITED threshold, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
//disconnect node and prevent it from stalling (would otherwise wait for the missing block)
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
|
@ -2270,9 +2270,9 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
|
|||
std::vector<uint8_t> block_data;
|
||||
if (!m_chainman.m_blockman.ReadRawBlockFromDisk(block_data, block_pos)) {
|
||||
if (WITH_LOCK(m_chainman.GetMutex(), return m_chainman.m_blockman.IsBlockPruned(*pindex))) {
|
||||
LogDebug(BCLog::NET, "Block was pruned before it could be read, disconnect peer=%s\n", pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "Block was pruned before it could be read, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
} else {
|
||||
LogError("Cannot load block from disk, disconnect peer=%d\n", pfrom.GetId());
|
||||
LogError("Cannot load block from disk, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
}
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
|
@ -2284,9 +2284,9 @@ void PeerManagerImpl::ProcessGetBlockData(CNode& pfrom, Peer& peer, const CInv&
|
|||
std::shared_ptr<CBlock> pblockRead = std::make_shared<CBlock>();
|
||||
if (!m_chainman.m_blockman.ReadBlockFromDisk(*pblockRead, block_pos)) {
|
||||
if (WITH_LOCK(m_chainman.GetMutex(), return m_chainman.m_blockman.IsBlockPruned(*pindex))) {
|
||||
LogDebug(BCLog::NET, "Block was pruned before it could be read, disconnect peer=%s\n", pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "Block was pruned before it could be read, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
} else {
|
||||
LogError("Cannot load block from disk, disconnect peer=%d\n", pfrom.GetId());
|
||||
LogError("Cannot load block from disk, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
}
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
|
@ -2788,7 +2788,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()) {
|
||||
LogPrintf("Disconnecting outbound peer %d -- headers chain has insufficient work\n", pfrom.GetId());
|
||||
LogInfo("outbound peer headers chain has insufficient work, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
pfrom.fDisconnect = true;
|
||||
}
|
||||
}
|
||||
|
@ -3111,8 +3111,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 %d requested unsupported block filter type: %d\n",
|
||||
node.GetId(), static_cast<uint8_t>(filter_type));
|
||||
LogDebug(BCLog::NET, "peer requested unsupported block filter type: %d, %s\n",
|
||||
static_cast<uint8_t>(filter_type), node.DisconnectMsg(fLogIPs));
|
||||
node.fDisconnect = true;
|
||||
return false;
|
||||
}
|
||||
|
@ -3123,8 +3123,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 %d requested invalid block hash: %s\n",
|
||||
node.GetId(), stop_hash.ToString());
|
||||
LogDebug(BCLog::NET, "peer requested invalid block hash: %s, %s\n",
|
||||
stop_hash.ToString(), node.DisconnectMsg(fLogIPs));
|
||||
node.fDisconnect = true;
|
||||
return false;
|
||||
}
|
||||
|
@ -3132,15 +3132,15 @@ bool PeerManagerImpl::PrepareBlockFilterRequest(CNode& node, Peer& peer,
|
|||
|
||||
uint32_t stop_height = stop_index->nHeight;
|
||||
if (start_height > stop_height) {
|
||||
LogDebug(BCLog::NET, "peer %d sent invalid getcfilters/getcfheaders with "
|
||||
"start height %d and stop height %d\n",
|
||||
node.GetId(), 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));
|
||||
node.fDisconnect = true;
|
||||
return false;
|
||||
}
|
||||
if (stop_height - start_height >= max_height_diff) {
|
||||
LogDebug(BCLog::NET, "peer %d requested too many cfilters/cfheaders: %d / %d\n",
|
||||
node.GetId(), stop_height - start_height + 1, 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));
|
||||
node.fDisconnect = true;
|
||||
return false;
|
||||
}
|
||||
|
@ -3407,14 +3407,17 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
}
|
||||
if (pfrom.ExpectServicesFromConn() && !HasAllDesirableServiceFlags(nServices))
|
||||
{
|
||||
LogDebug(BCLog::NET, "peer=%d does not offer the expected services (%08x offered, %08x expected); disconnecting\n", pfrom.GetId(), nServices, GetDesirableServiceFlags(nServices));
|
||||
LogDebug(BCLog::NET, "peer does not offer the expected services (%08x offered, %08x expected), %s\n",
|
||||
nServices,
|
||||
GetDesirableServiceFlags(nServices),
|
||||
pfrom.DisconnectMsg(fLogIPs));
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (nVersion < MIN_PEER_PROTO_VERSION) {
|
||||
// disconnect from peers older than this proto version
|
||||
LogDebug(BCLog::NET, "peer=%d using obsolete version %i; disconnecting\n", pfrom.GetId(), nVersion);
|
||||
LogDebug(BCLog::NET, "peer using obsolete version %i, %s\n", nVersion, pfrom.DisconnectMsg(fLogIPs));
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
|
@ -3591,7 +3594,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
|
||||
// Feeler connections exist only to verify if address is online.
|
||||
if (pfrom.IsFeelerConn()) {
|
||||
LogDebug(BCLog::NET, "feeler connection completed peer=%d; disconnecting\n", pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "feeler connection completed, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
pfrom.fDisconnect = true;
|
||||
}
|
||||
return;
|
||||
|
@ -3695,7 +3698,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
if (msg_type == NetMsgType::WTXIDRELAY) {
|
||||
if (pfrom.fSuccessfullyConnected) {
|
||||
// Disconnect peers that send a wtxidrelay message after VERACK.
|
||||
LogDebug(BCLog::NET, "wtxidrelay received after verack from peer=%d; disconnecting\n", pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "wtxidrelay received after verack, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
|
@ -3717,7 +3720,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
if (msg_type == NetMsgType::SENDADDRV2) {
|
||||
if (pfrom.fSuccessfullyConnected) {
|
||||
// Disconnect peers that send a SENDADDRV2 message after VERACK.
|
||||
LogDebug(BCLog::NET, "sendaddrv2 received after verack from peer=%d; disconnecting\n", pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "sendaddrv2 received after verack, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
|
@ -3730,19 +3733,19 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
// from switching announcement protocols after the connection is up.
|
||||
if (msg_type == NetMsgType::SENDTXRCNCL) {
|
||||
if (!m_txreconciliation) {
|
||||
LogPrintLevel(BCLog::NET, BCLog::Level::Debug, "sendtxrcncl from peer=%d ignored, as our node does not have txreconciliation enabled\n", pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "sendtxrcncl from peer=%d ignored, as our node does not have txreconciliation enabled\n", pfrom.GetId());
|
||||
return;
|
||||
}
|
||||
|
||||
if (pfrom.fSuccessfullyConnected) {
|
||||
LogPrintLevel(BCLog::NET, BCLog::Level::Debug, "sendtxrcncl received after verack from peer=%d; disconnecting\n", pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "sendtxrcncl received after verack, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Peer must not offer us reconciliations if we specified no tx relay support in VERSION.
|
||||
if (RejectIncomingTxs(pfrom)) {
|
||||
LogPrintLevel(BCLog::NET, BCLog::Level::Debug, "sendtxrcncl received from peer=%d to which we indicated no tx relay; disconnecting\n", pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "sendtxrcncl received to which we indicated no tx relay, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
|
@ -3752,7 +3755,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
// 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)) {
|
||||
LogPrintLevel(BCLog::NET, BCLog::Level::Debug, "sendtxrcncl received from peer=%d which indicated no tx relay to us; disconnecting\n", pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "sendtxrcncl received which indicated no tx relay to us, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
|
@ -3765,16 +3768,16 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
peer_txreconcl_version, remote_salt);
|
||||
switch (result) {
|
||||
case ReconciliationRegisterResult::NOT_FOUND:
|
||||
LogPrintLevel(BCLog::NET, BCLog::Level::Debug, "Ignore unexpected txreconciliation signal from peer=%d\n", pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "Ignore unexpected txreconciliation signal from peer=%d\n", pfrom.GetId());
|
||||
break;
|
||||
case ReconciliationRegisterResult::SUCCESS:
|
||||
break;
|
||||
case ReconciliationRegisterResult::ALREADY_REGISTERED:
|
||||
LogPrintLevel(BCLog::NET, BCLog::Level::Debug, "txreconciliation protocol violation from peer=%d (sendtxrcncl received from already registered peer); disconnecting\n", pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "txreconciliation protocol violation (sendtxrcncl received from already registered peer), %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
case ReconciliationRegisterResult::PROTOCOL_VIOLATION:
|
||||
LogPrintLevel(BCLog::NET, BCLog::Level::Debug, "txreconciliation protocol violation from peer=%d; disconnecting\n", pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "txreconciliation protocol violation, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
|
@ -3877,7 +3880,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
|
||||
// AddrFetch: Require multiple addresses to avoid disconnecting on self-announcements
|
||||
if (pfrom.IsAddrFetchConn() && vAddr.size() > 1) {
|
||||
LogDebug(BCLog::NET, "addrfetch connection completed peer=%d; disconnecting\n", pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "addrfetch connection completed, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
pfrom.fDisconnect = true;
|
||||
}
|
||||
return;
|
||||
|
@ -3927,7 +3930,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
}
|
||||
} else if (inv.IsGenTxMsg()) {
|
||||
if (reject_tx_invs) {
|
||||
LogDebug(BCLog::NET, "transaction (%s) inv sent in violation of protocol, disconnecting peer=%d\n", inv.hash.ToString(), pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "transaction (%s) inv sent in violation of protocol, %s\n", inv.hash.ToString(), pfrom.DisconnectMsg(fLogIPs));
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
|
@ -4004,7 +4007,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
vRecv >> locator >> hashStop;
|
||||
|
||||
if (locator.vHave.size() > MAX_LOCATOR_SZ) {
|
||||
LogDebug(BCLog::NET, "getblocks locator size %lld > %d, disconnect peer=%d\n", locator.vHave.size(), MAX_LOCATOR_SZ, pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "getblocks locator size %lld > %d, %s\n", locator.vHave.size(), MAX_LOCATOR_SZ, pfrom.DisconnectMsg(fLogIPs));
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
|
@ -4126,7 +4129,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
vRecv >> locator >> hashStop;
|
||||
|
||||
if (locator.vHave.size() > MAX_LOCATOR_SZ) {
|
||||
LogDebug(BCLog::NET, "getheaders locator size %lld > %d, disconnect peer=%d\n", locator.vHave.size(), MAX_LOCATOR_SZ, pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "getheaders locator size %lld > %d, %s\n", locator.vHave.size(), MAX_LOCATOR_SZ, pfrom.DisconnectMsg(fLogIPs));
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
|
@ -4667,7 +4670,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
{
|
||||
if (!pfrom.HasPermission(NetPermissionFlags::NoBan))
|
||||
{
|
||||
LogDebug(BCLog::NET, "mempool request with bloom filters disabled, disconnect peer=%d\n", pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "mempool request with bloom filters disabled, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
pfrom.fDisconnect = true;
|
||||
}
|
||||
return;
|
||||
|
@ -4677,7 +4680,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
{
|
||||
if (!pfrom.HasPermission(NetPermissionFlags::NoBan))
|
||||
{
|
||||
LogDebug(BCLog::NET, "mempool request with bandwidth limit reached, disconnect peer=%d\n", pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "mempool request with bandwidth limit reached, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
pfrom.fDisconnect = true;
|
||||
}
|
||||
return;
|
||||
|
@ -4767,7 +4770,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
|
||||
if (msg_type == NetMsgType::FILTERLOAD) {
|
||||
if (!(peer->m_our_services & NODE_BLOOM)) {
|
||||
LogDebug(BCLog::NET, "filterload received despite not offering bloom services from peer=%d; disconnecting\n", pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "filterload received despite not offering bloom services, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
|
@ -4792,7 +4795,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
|
||||
if (msg_type == NetMsgType::FILTERADD) {
|
||||
if (!(peer->m_our_services & NODE_BLOOM)) {
|
||||
LogDebug(BCLog::NET, "filteradd received despite not offering bloom services from peer=%d; disconnecting\n", pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "filteradd received despite not offering bloom services, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
|
@ -4820,7 +4823,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
|
|||
|
||||
if (msg_type == NetMsgType::FILTERCLEAR) {
|
||||
if (!(peer->m_our_services & NODE_BLOOM)) {
|
||||
LogDebug(BCLog::NET, "filterclear received despite not offering bloom services from peer=%d; disconnecting\n", pfrom.GetId());
|
||||
LogDebug(BCLog::NET, "filterclear received despite not offering bloom services, %s\n", pfrom.DisconnectMsg(fLogIPs));
|
||||
pfrom.fDisconnect = true;
|
||||
return;
|
||||
}
|
||||
|
@ -5041,7 +5044,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!
|
||||
LogPrintf("Disconnecting outbound peer %d for old chain, best known block = %s\n", pto.GetId(), state.pindexBestKnownBlock != nullptr ? state.pindexBestKnownBlock->GetBlockHash().ToString() : "<none>");
|
||||
LogInfo("Outbound peer has old chain, best known block = %s, %s\n", state.pindexBestKnownBlock != nullptr ? state.pindexBestKnownBlock->GetBlockHash().ToString() : "<none>", pto.DisconnectMsg(fLogIPs));
|
||||
pto.fDisconnect = true;
|
||||
} else {
|
||||
assert(state.m_chain_sync.m_work_header);
|
||||
|
@ -5442,7 +5445,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
|
|||
const auto current_time{GetTime<std::chrono::microseconds>()};
|
||||
|
||||
if (pto->IsAddrFetchConn() && current_time - pto->m_connected > 10 * AVG_ADDRESS_BROADCAST_INTERVAL) {
|
||||
LogDebug(BCLog::NET, "addrfetch connection timeout; disconnecting peer=%d\n", pto->GetId());
|
||||
LogDebug(BCLog::NET, "addrfetch connection timeout, %s\n", pto->DisconnectMsg(fLogIPs));
|
||||
pto->fDisconnect = true;
|
||||
return true;
|
||||
}
|
||||
|
@ -5786,7 +5789,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
|
|||
// 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.
|
||||
LogPrintf("Peer=%d%s is stalling block download, disconnecting\n", pto->GetId(), fLogIPs ? strprintf(" peeraddr=%s", pto->addr.ToStringAddrPort()) : "");
|
||||
LogInfo("Peer is stalling block download, %s\n", pto->DisconnectMsg(fLogIPs));
|
||||
pto->fDisconnect = true;
|
||||
// Increase timeout for the next peer so that we don't disconnect multiple peers if our own
|
||||
// bandwidth is insufficient.
|
||||
|
@ -5805,7 +5808,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
|
|||
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)) {
|
||||
LogPrintf("Timeout downloading block %s from peer=%d%s, disconnecting\n", queuedBlock.pindex->GetBlockHash().ToString(), pto->GetId(), fLogIPs ? strprintf(" peeraddr=%s", pto->addr.ToStringAddrPort()) : "");
|
||||
LogInfo("Timeout downloading block %s, %s\n", queuedBlock.pindex->GetBlockHash().ToString(), pto->DisconnectMsg(fLogIPs));
|
||||
pto->fDisconnect = true;
|
||||
return true;
|
||||
}
|
||||
|
@ -5821,11 +5824,11 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
|
|||
// disconnect our sync peer for stalling; we have bigger
|
||||
// problems if we can't get any outbound peers.
|
||||
if (!pto->HasPermission(NetPermissionFlags::NoBan)) {
|
||||
LogPrintf("Timeout downloading headers from peer=%d%s, disconnecting\n", pto->GetId(), fLogIPs ? strprintf(" peeraddr=%s", pto->addr.ToStringAddrPort()) : "");
|
||||
LogInfo("Timeout downloading headers, %s\n", pto->DisconnectMsg(fLogIPs));
|
||||
pto->fDisconnect = true;
|
||||
return true;
|
||||
} else {
|
||||
LogPrintf("Timeout downloading headers from noban peer=%d%s, not disconnecting\n", pto->GetId(), fLogIPs ? strprintf(" peeraddr=%s", pto->addr.ToStringAddrPort()) : "");
|
||||
LogInfo("Timeout downloading headers from noban peer, not %s\n", pto->DisconnectMsg(fLogIPs));
|
||||
// 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
|
||||
|
|
|
@ -122,7 +122,7 @@ class MaxUploadTest(BitcoinTestFramework):
|
|||
assert_equal(len(self.nodes[0].getpeerinfo()), 3)
|
||||
# At most a couple more tries should succeed (depending on how long
|
||||
# the test has been running so far).
|
||||
with self.nodes[0].assert_debug_log(expected_msgs=["historical block serving limit reached, disconnect peer"]):
|
||||
with self.nodes[0].assert_debug_log(expected_msgs=["historical block serving limit reached, disconnecting peer=0"]):
|
||||
for _ in range(3):
|
||||
p2p_conns[0].send_message(getdata_request)
|
||||
p2p_conns[0].wait_for_disconnect()
|
||||
|
@ -147,7 +147,7 @@ class MaxUploadTest(BitcoinTestFramework):
|
|||
|
||||
# But if p2p_conns[1] tries for an old block, it gets disconnected too.
|
||||
getdata_request.inv = [CInv(MSG_BLOCK, big_old_block)]
|
||||
with self.nodes[0].assert_debug_log(expected_msgs=["historical block serving limit reached, disconnect peer"]):
|
||||
with self.nodes[0].assert_debug_log(expected_msgs=["historical block serving limit reached, disconnecting peer=1"]):
|
||||
p2p_conns[1].send_message(getdata_request)
|
||||
p2p_conns[1].wait_for_disconnect()
|
||||
assert_equal(len(self.nodes[0].getpeerinfo()), 1)
|
||||
|
@ -197,7 +197,7 @@ class MaxUploadTest(BitcoinTestFramework):
|
|||
assert_equal(peer_info[0]['permissions'], ['download'])
|
||||
|
||||
self.log.info("Peer gets disconnected for a mempool request after limit is reached")
|
||||
with self.nodes[0].assert_debug_log(expected_msgs=["mempool request with bandwidth limit reached, disconnect peer"]):
|
||||
with self.nodes[0].assert_debug_log(expected_msgs=["mempool request with bandwidth limit reached, disconnecting peer=0"]):
|
||||
peer.send_message(msg_mempool())
|
||||
peer.wait_for_disconnect()
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ class AddrTest(BitcoinTestFramework):
|
|||
def run_test(self):
|
||||
self.log.info('Check disconnection when sending sendaddrv2 after verack')
|
||||
conn = self.nodes[0].add_p2p_connection(P2PInterface())
|
||||
with self.nodes[0].assert_debug_log(['sendaddrv2 received after verack from peer=0; disconnecting']):
|
||||
with self.nodes[0].assert_debug_log(['sendaddrv2 received after verack, disconnecting peer=0']):
|
||||
conn.send_message(msg_sendaddrv2())
|
||||
conn.wait_for_disconnect()
|
||||
|
||||
|
|
|
@ -172,7 +172,7 @@ class P2PLeakTest(BitcoinTestFramework):
|
|||
|
||||
self.log.info('Check that old peers are disconnected')
|
||||
p2p_old_peer = self.nodes[0].add_p2p_connection(P2PInterface(), send_version=False, wait_for_verack=False)
|
||||
with self.nodes[0].assert_debug_log(["using obsolete version 31799; disconnecting"]):
|
||||
with self.nodes[0].assert_debug_log(["using obsolete version 31799, disconnecting peer=5"]):
|
||||
p2p_old_peer.send_message(self.create_old_version(31799))
|
||||
p2p_old_peer.wait_for_disconnect()
|
||||
|
||||
|
|
|
@ -168,7 +168,7 @@ class SendTxRcnclTest(BitcoinTestFramework):
|
|||
with self.nodes[0].assert_debug_log(["received: sendtxrcncl"]):
|
||||
peer.send_message(create_sendtxrcncl_msg())
|
||||
self.log.info('second SENDTXRCNCL triggers a disconnect')
|
||||
with self.nodes[0].assert_debug_log(["(sendtxrcncl received from already registered peer); disconnecting"]):
|
||||
with self.nodes[0].assert_debug_log(["(sendtxrcncl received from already registered peer), disconnecting peer=0"]):
|
||||
peer.send_message(create_sendtxrcncl_msg())
|
||||
peer.wait_for_disconnect()
|
||||
|
||||
|
@ -226,7 +226,7 @@ class SendTxRcnclTest(BitcoinTestFramework):
|
|||
self.log.info('SENDTXRCNCL if block-relay-only triggers a disconnect')
|
||||
peer = self.nodes[0].add_outbound_p2p_connection(
|
||||
PeerNoVerack(), wait_for_verack=False, p2p_idx=0, connection_type="block-relay-only")
|
||||
with self.nodes[0].assert_debug_log(["we indicated no tx relay; disconnecting"]):
|
||||
with self.nodes[0].assert_debug_log(["we indicated no tx relay, disconnecting peer=5"]):
|
||||
peer.send_message(create_sendtxrcncl_msg())
|
||||
peer.wait_for_disconnect()
|
||||
|
||||
|
|
Loading…
Reference in a new issue