@@ -3046,27 +3046,24 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer,
30463046 // something new (if these headers are valid).
30473047 bool received_new_header{last_received_header == nullptr };
30483048
3049- // Now process all the headers.
3050- BlockValidationState state;
3051- const bool processed{m_chainman.ProcessNewBlockHeaders (headers,
3049+ // Now process all the headers and return the block validation state.
3050+ BlockValidationState state{m_chainman.ProcessNewBlockHeaders (headers,
30523051 /* min_pow_checked=*/ true ,
3053- state, &pindexLast)};
3054- if (!processed) {
3055- if (state.IsInvalid ()) {
3056- if (!pfrom.IsInboundConn () && state.GetResult () == BlockValidationResult::BLOCK_CACHED_INVALID) {
3057- // Warn user if outgoing peers send us headers of blocks that we previously marked as invalid.
3058- LogWarning (" %s (received from peer=%i). "
3059- " If this happens with all peers, consider database corruption (that -reindex may fix) "
3060- " or a potential consensus incompatibility." ,
3061- state.GetDebugMessage (), pfrom.GetId ());
3062- }
3063- MaybePunishNodeForBlock (pfrom.GetId (), state, via_compact_block, " invalid header received" );
3064- return ;
3065- }
3052+ &pindexLast)};
3053+ if (state.IsInvalid ()) {
3054+ if (!pfrom.IsInboundConn () && state.GetResult () == BlockValidationResult::BLOCK_CACHED_INVALID) {
3055+ // Warn user if outgoing peers send us headers of blocks that we previously marked as invalid.
3056+ LogWarning (" %s (received from peer=%i). "
3057+ " If this happens with all peers, consider database corruption (that -reindex may fix) "
3058+ " or a potential consensus incompatibility." ,
3059+ state.GetDebugMessage (), pfrom.GetId ());
3060+ }
3061+ MaybePunishNodeForBlock (pfrom.GetId (), state, via_compact_block, " invalid header received" );
3062+ return ;
30663063 }
30673064 assert (pindexLast);
30683065
3069- if (processed && received_new_header) {
3066+ if (state. IsValid () && received_new_header) {
30703067 LogBlockHeader (*pindexLast, pfrom, /* via_compact_block=*/ false );
30713068 }
30723069
@@ -4558,12 +4555,10 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
45584555 }
45594556
45604557 const CBlockIndex *pindex = nullptr ;
4561- BlockValidationState state;
4562- if (!m_chainman.ProcessNewBlockHeaders ({{cmpctblock.header }}, /* min_pow_checked=*/ true , state, &pindex)) {
4563- if (state.IsInvalid ()) {
4564- MaybePunishNodeForBlock (pfrom.GetId (), state, /* via_compact_block=*/ true , " invalid header via cmpctblock" );
4565- return ;
4566- }
4558+ BlockValidationState state{m_chainman.ProcessNewBlockHeaders ({{cmpctblock.header }}, /* min_pow_checked=*/ true , &pindex)};
4559+ if (state.IsInvalid ()) {
4560+ MaybePunishNodeForBlock (pfrom.GetId (), state, /* via_compact_block=*/ true , " invalid header via cmpctblock" );
4561+ return ;
45674562 }
45684563
45694564 // If AcceptBlockHeader returned true, it set pindex
0 commit comments