Skip to content

Commit

Permalink
Use LogBlockHeader for compact blocks
Browse files Browse the repository at this point in the history
The only behavior change is that the block height is now added to the log message.
  • Loading branch information
Sjors committed Feb 21, 2025
1 parent d47ed74 commit fcf369d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,7 @@ class PeerManagerImpl final : public PeerManager
void AddAddressKnown(Peer& peer, const CAddress& addr) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex);
void PushAddress(Peer& peer, const CAddress& addr) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex);

void LogBlockHeader(const CBlockIndex& index, const CNode& peer);
void LogBlockHeader(const CBlockIndex& index, const CNode& peer, bool via_compact_block);
};

const CNodeState* PeerManagerImpl::State(NodeId pnode) const
Expand Down Expand Up @@ -2952,7 +2952,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer,
assert(pindexLast);

if (processed && received_new_header) {
LogBlockHeader(*pindexLast, pfrom);
LogBlockHeader(*pindexLast, pfrom, /*via_compact_block=*/false);
}

// Consider fetching more headers if we are not using our headers-sync mechanism.
Expand Down Expand Up @@ -3380,7 +3380,7 @@ void PeerManagerImpl::ProcessCompactBlockTxns(CNode& pfrom, Peer& peer, const Bl
return;
}

void PeerManagerImpl::LogBlockHeader(const CBlockIndex& index, const CNode& peer) {
void PeerManagerImpl::LogBlockHeader(const CBlockIndex& index, const CNode& peer, bool via_compact_block) {
// To prevent log spam, this function should only be called after it was determined that a
// header is both new and valid.
//
Expand All @@ -3392,7 +3392,8 @@ void PeerManagerImpl::LogBlockHeader(const CBlockIndex& index, const CNode& peer
// Having this log by default when not in IBD ensures broad availability of
// this data in case investigation is merited.
const auto msg = strprintf(
"Saw new header hash=%s height=%d peer=%d%s",
"Saw new %sheader hash=%s height=%d peer=%d%s",
via_compact_block ? "cmpctblock " : "",
index.GetBlockHash().ToString(),
index.nHeight,
peer.GetId(),
Expand Down Expand Up @@ -4357,9 +4358,10 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
}
}

// If AcceptBlockHeader returned true, it set pindex
Assert(pindex);
if (received_new_header) {
LogInfo("Saw new cmpctblock header hash=%s peer=%d\n",
blockhash.ToString(), pfrom.GetId());
LogBlockHeader(*pindex, pfrom, /*via_compact_block=*/true);
}

bool fProcessBLOCKTXN = false;
Expand All @@ -4375,8 +4377,6 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,

{
LOCK(cs_main);
// If AcceptBlockHeader returned true, it set pindex
assert(pindex);
UpdateBlockAvailability(pfrom.GetId(), pindex->GetBlockHash());

CNodeState *nodestate = State(pfrom.GetId());
Expand Down

0 comments on commit fcf369d

Please sign in to comment.