Changeset View
Changeset View
Standalone View
Standalone View
src/net_processing.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
Show First 20 Lines • Show All 685 Lines • ▼ Show 20 Lines | private: | ||||
/** | /** | ||||
* Map of all Peer objects, keyed by peer id. This map is protected | * Map of all Peer objects, keyed by peer id. This map is protected | ||||
* by the m_peer_mutex. Once a shared pointer reference is | * by the m_peer_mutex. Once a shared pointer reference is | ||||
* taken, the lock may be released. Individual fields are protected by | * taken, the lock may be released. Individual fields are protected by | ||||
* their own locks. | * their own locks. | ||||
*/ | */ | ||||
std::map<NodeId, PeerRef> m_peer_map GUARDED_BY(m_peer_mutex); | std::map<NodeId, PeerRef> m_peer_map GUARDED_BY(m_peer_mutex); | ||||
/** Number of nodes with fSyncStarted. */ | |||||
int nSyncStarted GUARDED_BY(cs_main) = 0; | |||||
/** | |||||
* Sources of received blocks, saved to be able to punish them when | |||||
* processing happens afterwards. | |||||
* Set mapBlockSource[hash].second to false if the node should not be | |||||
* punished if the block is invalid. | |||||
*/ | |||||
std::map<BlockHash, std::pair<NodeId, bool>> | |||||
mapBlockSource GUARDED_BY(cs_main); | |||||
/** Number of outbound peers with m_chain_sync.m_protect. */ | |||||
int m_outbound_peers_with_protect_from_disconnect GUARDED_BY(cs_main) = 0; | |||||
/** | /** | ||||
* Checks if address relay is permitted with peer. If needed, initializes | * Checks if address relay is permitted with peer. If needed, initializes | ||||
* the m_addr_known bloom filter and sets m_addr_relay_enabled to true. | * the m_addr_known bloom filter and sets m_addr_relay_enabled to true. | ||||
* | * | ||||
* @return True if address relay is enabled with peer | * @return True if address relay is enabled with peer | ||||
* False if address relay is disallowed | * False if address relay is disallowed | ||||
*/ | */ | ||||
bool SetupAddressRelay(CNode &node, Peer &peer); | bool SetupAddressRelay(CNode &node, Peer &peer); | ||||
}; | }; | ||||
} // namespace | } // namespace | ||||
namespace { | namespace { | ||||
/** Number of nodes with fSyncStarted. */ | |||||
int nSyncStarted GUARDED_BY(cs_main) = 0; | |||||
/** | |||||
* Sources of received blocks, saved to be able to punish them when processing | |||||
* happens afterwards. | |||||
* Set mapBlockSource[hash].second to false if the node should not be punished | |||||
* if the block is invalid. | |||||
*/ | |||||
std::map<BlockHash, std::pair<NodeId, bool>> mapBlockSource GUARDED_BY(cs_main); | |||||
/** | /** | ||||
* Filter for transactions that were recently rejected by AcceptToMemoryPool. | * Filter for transactions that were recently rejected by AcceptToMemoryPool. | ||||
* These are not rerequested until the chain tip changes, at which point the | * These are not rerequested until the chain tip changes, at which point the | ||||
* entire filter is reset. | * entire filter is reset. | ||||
* | * | ||||
* Without this filter we'd be re-requesting txs from each of our peers, | * Without this filter we'd be re-requesting txs from each of our peers, | ||||
* increasing bandwidth consumption considerably. For instance, with 100 peers, | * increasing bandwidth consumption considerably. For instance, with 100 peers, | ||||
* half of which relay a tx we don't accept, that might be a 50x bandwidth | * half of which relay a tx we don't accept, that might be a 50x bandwidth | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | |||||
std::list<NodeId> lNodesAnnouncingHeaderAndIDs GUARDED_BY(cs_main); | std::list<NodeId> lNodesAnnouncingHeaderAndIDs GUARDED_BY(cs_main); | ||||
/** Number of preferable block download peers. */ | /** Number of preferable block download peers. */ | ||||
int nPreferredDownload GUARDED_BY(cs_main) = 0; | int nPreferredDownload GUARDED_BY(cs_main) = 0; | ||||
/** Number of peers from which we're downloading blocks. */ | /** Number of peers from which we're downloading blocks. */ | ||||
int nPeersWithValidatedDownloads GUARDED_BY(cs_main) = 0; | int nPeersWithValidatedDownloads GUARDED_BY(cs_main) = 0; | ||||
/** Number of outbound peers with m_chain_sync.m_protect. */ | |||||
int g_outbound_peers_with_protect_from_disconnect GUARDED_BY(cs_main) = 0; | |||||
/** When our tip was last updated. */ | /** When our tip was last updated. */ | ||||
std::atomic<int64_t> g_last_tip_update(0); | std::atomic<int64_t> g_last_tip_update(0); | ||||
/** Relay map. */ | /** Relay map. */ | ||||
typedef std::map<uint256, CTransactionRef> MapRelay; | typedef std::map<uint256, CTransactionRef> MapRelay; | ||||
MapRelay mapRelay GUARDED_BY(cs_main); | MapRelay mapRelay GUARDED_BY(cs_main); | ||||
/** | /** | ||||
* Expiration-time ordered list of (expire time, relay map entry) pairs, | * Expiration-time ordered list of (expire time, relay map entry) pairs, | ||||
▲ Show 20 Lines • Show All 847 Lines • ▼ Show 20 Lines | fUpdateConnectionTime = false; | ||||
mapBlocksInFlight.erase(entry.hash); | mapBlocksInFlight.erase(entry.hash); | ||||
} | } | ||||
EraseOrphansFor(nodeid); | EraseOrphansFor(nodeid); | ||||
m_txrequest.DisconnectedPeer(nodeid); | m_txrequest.DisconnectedPeer(nodeid); | ||||
nPreferredDownload -= state->fPreferredDownload; | nPreferredDownload -= state->fPreferredDownload; | ||||
nPeersWithValidatedDownloads -= | nPeersWithValidatedDownloads -= | ||||
(state->nBlocksInFlightValidHeaders != 0); | (state->nBlocksInFlightValidHeaders != 0); | ||||
assert(nPeersWithValidatedDownloads >= 0); | assert(nPeersWithValidatedDownloads >= 0); | ||||
g_outbound_peers_with_protect_from_disconnect -= | m_outbound_peers_with_protect_from_disconnect -= | ||||
state->m_chain_sync.m_protect; | state->m_chain_sync.m_protect; | ||||
assert(g_outbound_peers_with_protect_from_disconnect >= 0); | assert(m_outbound_peers_with_protect_from_disconnect >= 0); | ||||
mapNodeState.erase(nodeid); | mapNodeState.erase(nodeid); | ||||
if (mapNodeState.empty()) { | if (mapNodeState.empty()) { | ||||
// Do a consistency check after the last peer is removed. | // Do a consistency check after the last peer is removed. | ||||
assert(mapBlocksInFlight.empty()); | assert(mapBlocksInFlight.empty()); | ||||
assert(nPreferredDownload == 0); | assert(nPreferredDownload == 0); | ||||
assert(nPeersWithValidatedDownloads == 0); | assert(nPeersWithValidatedDownloads == 0); | ||||
assert(g_outbound_peers_with_protect_from_disconnect == 0); | assert(m_outbound_peers_with_protect_from_disconnect == 0); | ||||
assert(m_txrequest.Size() == 0); | assert(m_txrequest.Size() == 0); | ||||
} | } | ||||
} | } | ||||
WITH_LOCK(cs_proofrequest, m_proofrequest.DisconnectedPeer(nodeid)); | WITH_LOCK(cs_proofrequest, m_proofrequest.DisconnectedPeer(nodeid)); | ||||
LogPrint(BCLog::NET, "Cleared nodestate for peer=%d\n", nodeid); | LogPrint(BCLog::NET, "Cleared nodestate for peer=%d\n", nodeid); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,382 Lines • ▼ Show 20 Lines | if (!m_chainman.ProcessNewBlockHeaders(config, headers, state, | ||||
// If this is an outbound full-relay peer, check to see if we should | // If this is an outbound full-relay peer, check to see if we should | ||||
// protect it from the bad/lagging chain logic. | // protect it from the bad/lagging chain logic. | ||||
// Note that outbound block-relay peers are excluded from this | // Note that outbound block-relay peers are excluded from this | ||||
// protection, and thus always subject to eviction under the bad/lagging | // protection, and thus always subject to eviction under the bad/lagging | ||||
// chain logic. | // chain logic. | ||||
// See ChainSyncTimeoutState. | // See ChainSyncTimeoutState. | ||||
if (!pfrom.fDisconnect && pfrom.IsFullOutboundConn() && | if (!pfrom.fDisconnect && pfrom.IsFullOutboundConn() && | ||||
nodestate->pindexBestKnownBlock != nullptr) { | nodestate->pindexBestKnownBlock != nullptr) { | ||||
if (g_outbound_peers_with_protect_from_disconnect < | if (m_outbound_peers_with_protect_from_disconnect < | ||||
MAX_OUTBOUND_PEERS_TO_PROTECT_FROM_DISCONNECT && | MAX_OUTBOUND_PEERS_TO_PROTECT_FROM_DISCONNECT && | ||||
nodestate->pindexBestKnownBlock->nChainWork >= | nodestate->pindexBestKnownBlock->nChainWork >= | ||||
::ChainActive().Tip()->nChainWork && | ::ChainActive().Tip()->nChainWork && | ||||
!nodestate->m_chain_sync.m_protect) { | !nodestate->m_chain_sync.m_protect) { | ||||
LogPrint(BCLog::NET, | LogPrint(BCLog::NET, | ||||
"Protecting outbound peer=%d from eviction\n", | "Protecting outbound peer=%d from eviction\n", | ||||
pfrom.GetId()); | pfrom.GetId()); | ||||
nodestate->m_chain_sync.m_protect = true; | nodestate->m_chain_sync.m_protect = true; | ||||
++g_outbound_peers_with_protect_from_disconnect; | ++m_outbound_peers_with_protect_from_disconnect; | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Reconsider orphan transactions after a parent has been accepted to the | * Reconsider orphan transactions after a parent has been accepted to the | ||||
* mempool. | * mempool. | ||||
▲ Show 20 Lines • Show All 3,932 Lines • Show Last 20 Lines |