mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 23:03:45 +01:00
Merge bitcoin/bitcoin#27826: validation: log which peer sent us a header
abe43dfadddoc: release note for #27826 (Sjors Provoost)f9fa28788eUse LogBlockHeader for compact blocks (Sjors Provoost)bad7c91479Log which peer sent us a header (Sjors Provoost)9d3e39c29cLog block header in net_processing (Sjors Provoost) Pull request description: Fixes #27744 Since #27278 we log received headers. For compact blocks we also log which peer sent it (e5ce857634), but not for regular headers. That required an additional refactor, which this PR provides. Move the logging from validation to net_processing. This also reduces the number of log entries (under default configuration) per compact block header from 3 to 2: one for the header and one for the connected tip. The PR introduces a new helper method `LogBlockHeader`. When receiving a _compact block_ we call `LogBlockHeader` from the exact same place as where we previously logged. So that log message doesn't change. What does change is that we no longer _also_ log from `AcceptBlockHeader`. When receiving a regular header(s) message, _we only log the last one_. This is a change in behaviour because it was simpler to implement, but it's probably better anyway. It does mean that if a peer sends of a bunch of headers of which _any_ is invalid, we won't log it (here). Lastly I expanded the code comment explaining why we log this. It initially only covered selfish mining, but we also care about peers sending us headers but not following up (see e.g. #27626). Example log: ``` 2023-06-05T13:12:21Z Saw new header hash=000000000000000000045910263ef84b575ae3af151865238f1e5c619e69c330 height=792964 peer=0 2023-06-05T13:12:23Z UpdateTip: new best=000000000000000000045910263ef84b575ae3af151865238f1e5c619e69c330 height=792964 version=0x20000000 log2_work=94.223098 tx=848176824 date='2023-06-05T13:11:49Z' progress=1.000000 cache=6.4MiB(54615txo) 2023-06-05T13:14:05Z Saw new cmpctblock header hash=00000000000000000003c6fd4ef2e1246a3f9e1fffab7247344f94cadb9de979 height=792965 peer=0 2023-06-05T13:14:05Z UpdateTip: new best=00000000000000000003c6fd4ef2e1246a3f9e1fffab7247344f94cadb9de979 height=792965 version=0x20000000 log2_work=94.223112 tx=848179461 date='2023-06-05T13:13:58Z' progress=1.000000 cache=7.2MiB(61275txo) 2023-06-05T13:14:41Z Saw new header hash=000000000000000000048e6d69c8399992782d08cb57f5d6cbc81a9f996c3f43 height=792966 peer=8 2023-06-05T13:14:42Z UpdateTip: new best=000000000000000000048e6d69c8399992782d08cb57f5d6cbc81a9f996c3f43 height=792966 version=0x2db3c000 log2_work=94.223126 tx=848182944 date='2023-06-05T13:14:35Z' progress=1.000000 cache=8.0MiB(69837txo) ``` ACKs for top commit: danielabrozzoni: tACKabe43dfaddachow101: ACKabe43dfaddvasild: ACKabe43dfaddTree-SHA512: 081e0de62cbd8a0b35cf54daaa09e3e6991d0cc9f706ef3eb50908752fe7815de69b367f7313381c90cd8d5de0ae5f532d1cd54948c5c1133b1832f266d9c232
This commit is contained in:
@@ -4376,23 +4376,6 @@ 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 (IsInitialBlockDownload()) {
|
||||
LogPrintLevel(BCLog::VALIDATION, BCLog::Level::Debug, "%s\n", msg);
|
||||
} else {
|
||||
LogPrintf("%s\n", msg);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user