aboutsummaryrefslogtreecommitdiff
path: root/src/net_processing.cpp
diff options
context:
space:
mode:
authorSuhas Daftuar <sdaftuar@gmail.com>2022-02-08 17:43:38 -0500
committerSuhas Daftuar <sdaftuar@gmail.com>2022-06-28 15:53:25 -0400
commitffe87db247b19ffb8bfba329c5dd0be39ef5a53f (patch)
treeb5763d8c978db5d9077c5a148267f3fe3a97f87f /src/net_processing.cpp
parent6d95cd3e7444ebaaabb64a76783ea3551530f1d7 (diff)
downloadbitcoin-ffe87db247b19ffb8bfba329c5dd0be39ef5a53f.tar.xz
Cleanup received_new_header calculation to use WITH_LOCK
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r--src/net_processing.cpp13
1 files changed, 3 insertions, 10 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index 5f19f8b8ec..975ee16615 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -2420,7 +2420,6 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer,
return;
}
- bool received_new_header = false;
const CBlockIndex *pindexLast = nullptr;
// Do these headers connect to something in our block index?
@@ -2444,15 +2443,9 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer,
return;
}
- {
- LOCK(cs_main);
-
- // If we don't have the last header, then they'll have given us
- // something new (if these headers are valid).
- if (!m_chainman.m_blockman.LookupBlockIndex(headers.back().GetHash())) {
- received_new_header = true;
- }
- }
+ // If we don't have the last header, then this peer will have given us
+ // something new (if these headers are valid).
+ bool received_new_header{WITH_LOCK(::cs_main, return m_chainman.m_blockman.LookupBlockIndex(headers.back().GetHash()) == nullptr)};
BlockValidationState state;
if (!m_chainman.ProcessNewBlockHeaders(headers, state, &pindexLast)) {