Use LogBlockHeader for compact blocks

The only behavior change is that the block height is now added to the log message.
This commit is contained in:
Sjors Provoost 2025-02-21 15:34:29 +01:00
parent d47ed74bd3
commit fcf369df4b
No known key found for this signature in database
GPG key ID: 57FF9BDBCC301009

View file

@ -1042,7 +1042,7 @@ private:
void AddAddressKnown(Peer& peer, const CAddress& addr) EXCLUSIVE_LOCKS_REQUIRED(g_msgproc_mutex); 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 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 const CNodeState* PeerManagerImpl::State(NodeId pnode) const
@ -2952,7 +2952,7 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer,
assert(pindexLast); assert(pindexLast);
if (processed && received_new_header) { 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. // Consider fetching more headers if we are not using our headers-sync mechanism.
@ -3380,7 +3380,7 @@ void PeerManagerImpl::ProcessCompactBlockTxns(CNode& pfrom, Peer& peer, const Bl
return; 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 // To prevent log spam, this function should only be called after it was determined that a
// header is both new and valid. // header is both new and valid.
// //
@ -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 // Having this log by default when not in IBD ensures broad availability of
// this data in case investigation is merited. // this data in case investigation is merited.
const auto msg = strprintf( 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.GetBlockHash().ToString(),
index.nHeight, index.nHeight,
peer.GetId(), peer.GetId(),
@ -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) { if (received_new_header) {
LogInfo("Saw new cmpctblock header hash=%s peer=%d\n", LogBlockHeader(*pindex, pfrom, /*via_compact_block=*/true);
blockhash.ToString(), pfrom.GetId());
} }
bool fProcessBLOCKTXN = false; bool fProcessBLOCKTXN = false;
@ -4375,8 +4377,6 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
{ {
LOCK(cs_main); LOCK(cs_main);
// If AcceptBlockHeader returned true, it set pindex
assert(pindex);
UpdateBlockAvailability(pfrom.GetId(), pindex->GetBlockHash()); UpdateBlockAvailability(pfrom.GetId(), pindex->GetBlockHash());
CNodeState *nodestate = State(pfrom.GetId()); CNodeState *nodestate = State(pfrom.GetId());