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; }