| 1251 | } |
| 1252 | |
| 1253 | static void CheckForkWarningConditions() |
| 1254 | { |
| 1255 | AssertLockHeld(cs_main); |
| 1256 | // Before we get past initial download, we cannot reliably alert about forks |
| 1257 | // (we assume we don't get stuck on a fork before finishing our initial sync) |
| 1258 | if (IsInitialBlockDownload()) |
| 1259 | return; |
| 1260 | |
| 1261 | // If our best fork is no longer within 72 blocks (+/- 12 hours if no one mines it) |
| 1262 | // of our head, drop it |
| 1263 | if (pindexBestForkTip && chainActive.Height() - pindexBestForkTip->nHeight >= 72) |
| 1264 | pindexBestForkTip = nullptr; |
| 1265 | |
| 1266 | if (pindexBestForkTip || (pindexBestInvalid && pindexBestInvalid->nChainWork > chainActive.Tip()->nChainWork + (GetBlockProof(*chainActive.Tip()) * 6))) |
| 1267 | { |
| 1268 | if (!GetfLargeWorkForkFound() && pindexBestForkBase) |
| 1269 | { |
| 1270 | std::string warning = std::string("'Warning: Large-work fork detected, forking after block ") + |
| 1271 | pindexBestForkBase->phashBlock->ToString() + std::string("'"); |
| 1272 | AlertNotify(warning); |
| 1273 | } |
| 1274 | if (pindexBestForkTip && pindexBestForkBase) |
| 1275 | { |
| 1276 | LogPrintf("%s: Warning: Large valid fork found\n forking the chain at height %d (%s)\n lasting to height %d (%s).\nChain state database corruption likely.\n", __func__, |
| 1277 | pindexBestForkBase->nHeight, pindexBestForkBase->phashBlock->ToString(), |
| 1278 | pindexBestForkTip->nHeight, pindexBestForkTip->phashBlock->ToString()); |
| 1279 | SetfLargeWorkForkFound(true); |
| 1280 | } |
| 1281 | else |
| 1282 | { |
| 1283 | LogPrintf("%s: Warning: Found invalid chain at least ~6 blocks longer than our best chain.\nChain state database corruption likely.\n", __func__); |
| 1284 | SetfLargeWorkInvalidChainFound(true); |
| 1285 | } |
| 1286 | } |
| 1287 | else |
| 1288 | { |
| 1289 | SetfLargeWorkForkFound(false); |
| 1290 | SetfLargeWorkInvalidChainFound(false); |
| 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | static void CheckForkWarningConditionsOnNewFork(CBlockIndex* pindexNewForkTip) |
| 1295 | { |
no test coverage detected