Skip to content

Commit ffe87db

Browse files
committed
Cleanup received_new_header calculation to use WITH_LOCK
1 parent 6d95cd3 commit ffe87db

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

src/net_processing.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,7 +2420,6 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer,
24202420
return;
24212421
}
24222422

2423-
bool received_new_header = false;
24242423
const CBlockIndex *pindexLast = nullptr;
24252424

24262425
// Do these headers connect to something in our block index?
@@ -2444,15 +2443,9 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer,
24442443
return;
24452444
}
24462445

2447-
{
2448-
LOCK(cs_main);
2449-
2450-
// If we don't have the last header, then they'll have given us
2451-
// something new (if these headers are valid).
2452-
if (!m_chainman.m_blockman.LookupBlockIndex(headers.back().GetHash())) {
2453-
received_new_header = true;
2454-
}
2455-
}
2446+
// If we don't have the last header, then this peer will have given us
2447+
// something new (if these headers are valid).
2448+
bool received_new_header{WITH_LOCK(::cs_main, return m_chainman.m_blockman.LookupBlockIndex(headers.back().GetHash()) == nullptr)};
24562449

24572450
BlockValidationState state;
24582451
if (!m_chainman.ProcessNewBlockHeaders(headers, state, &pindexLast)) {

0 commit comments

Comments
 (0)