From 2c3a90f663a61ee147d785167a2902494d81d34d Mon Sep 17 00:00:00 2001 From: James O'Beirne Date: Sun, 19 Mar 2023 10:02:08 -0400 Subject: [PATCH] log: on new valid header --- src/validation.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/validation.cpp b/src/validation.cpp index 5b3a099dfc358..df0c4f94c0a8e 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3832,6 +3832,23 @@ bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValida if (ppindex) *ppindex = pindex; + // Since this is the earliest point at which we have determined that a + // header is both new and valid, log here. + // + // These messages are valuable for detecting potential selfish mining behavior; + // if multiple displacing headers are seen near simultaneously across many + // nodes in the network, this might be an indication of selfish mining. 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", hash.ToString(), pindex->nHeight); + + if (ActiveChainstate().IsInitialBlockDownload()) { + LogPrintLevel(BCLog::VALIDATION, BCLog::Level::Debug, "%s\n", msg); + } else { + LogPrintf("%s\n", msg); + } + return true; }