Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2051,15 +2051,19 @@ std::optional<std::string> PeerManagerImpl::FetchBlock(NodeId peer_id, const uin
{
if (m_chainman.m_blockman.LoadingBlocks()) return "Loading blocks ...";

// The lock must be taken here before fetching Peer so another thread does
// not delete the CNodeState from under the current thread, causing an
// assertion failure in BlockRequested. This lock can be replaced with a
// net-specific lock when more of CNodeState is moved into Peer.
LOCK(cs_main);

// Ensure this peer exists and hasn't been disconnected
PeerRef peer = GetPeerRef(peer_id);
if (peer == nullptr) return "Peer does not exist";

// Ignore pre-segwit peers
if (!CanServeWitnesses(*peer)) return "Pre-SegWit peer";

LOCK(cs_main);

if (IsBlockRequestedFromPeer(hash, peer_id)) return "Already requested from this peer";

// Mark block as in-flight unless we don't have the header.
Expand Down