@@ -1312,8 +1312,6 @@ bool CChainState::IsInitialBlockDownload() const
1312
1312
return false ;
1313
1313
}
1314
1314
1315
- static CBlockIndex *pindexBestForkTip = nullptr , *pindexBestForkBase = nullptr ;
1316
-
1317
1315
static void AlertNotify (const std::string& strMessage)
1318
1316
{
1319
1317
uiInterface.NotifyAlertChanged ();
@@ -1342,72 +1340,17 @@ static void CheckForkWarningConditions() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1342
1340
if (::ChainstateActive ().IsInitialBlockDownload ())
1343
1341
return ;
1344
1342
1345
- // If our best fork is no longer within 72 blocks (+/- 12 hours if no one mines it)
1346
- // of our head, drop it
1347
- if (pindexBestForkTip && ::ChainActive ().Height () - pindexBestForkTip->nHeight >= 72 )
1348
- pindexBestForkTip = nullptr ;
1349
-
1350
- if (pindexBestForkTip || (pindexBestInvalid && pindexBestInvalid->nChainWork > ::ChainActive ().Tip ()->nChainWork + (GetBlockProof (*::ChainActive ().Tip ()) * 6 )))
1343
+ if (pindexBestInvalid && pindexBestInvalid->nChainWork > ::ChainActive ().Tip ()->nChainWork + (GetBlockProof (*::ChainActive ().Tip ()) * 6 ))
1351
1344
{
1352
- if (!GetfLargeWorkForkFound () && pindexBestForkBase)
1353
- {
1354
- std::string warning = std::string (" 'Warning: Large-work fork detected, forking after block " ) +
1355
- pindexBestForkBase->phashBlock ->ToString () + std::string (" '" );
1356
- AlertNotify (warning);
1357
- }
1358
- if (pindexBestForkTip && pindexBestForkBase)
1359
- {
1360
- LogPrintf (" %s: Warning: Large valid fork found\n forking the chain at height %d (%s)\n lasting to height %d (%s).\n Chain state database corruption likely.\n " , __func__,
1361
- pindexBestForkBase->nHeight , pindexBestForkBase->phashBlock ->ToString (),
1362
- pindexBestForkTip->nHeight , pindexBestForkTip->phashBlock ->ToString ());
1363
- SetfLargeWorkForkFound (true );
1364
- }
1365
- else
1366
- {
1367
- LogPrintf (" %s: Warning: Found invalid chain at least ~6 blocks longer than our best chain.\n Chain state database corruption likely.\n " , __func__);
1368
- SetfLargeWorkInvalidChainFound (true );
1369
- }
1345
+ LogPrintf (" %s: Warning: Found invalid chain at least ~6 blocks longer than our best chain.\n Chain state database corruption likely.\n " , __func__);
1346
+ SetfLargeWorkInvalidChainFound (true );
1370
1347
}
1371
1348
else
1372
1349
{
1373
- SetfLargeWorkForkFound (false );
1374
1350
SetfLargeWorkInvalidChainFound (false );
1375
1351
}
1376
1352
}
1377
1353
1378
- static void CheckForkWarningConditionsOnNewFork (CBlockIndex* pindexNewForkTip) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1379
- {
1380
- AssertLockHeld (cs_main);
1381
- // If we are on a fork that is sufficiently large, set a warning flag
1382
- CBlockIndex* pfork = pindexNewForkTip;
1383
- CBlockIndex* plonger = ::ChainActive ().Tip ();
1384
- while (pfork && pfork != plonger)
1385
- {
1386
- while (plonger && plonger->nHeight > pfork->nHeight )
1387
- plonger = plonger->pprev ;
1388
- if (pfork == plonger)
1389
- break ;
1390
- pfork = pfork->pprev ;
1391
- }
1392
-
1393
- // We define a condition where we should warn the user about as a fork of at least 7 blocks
1394
- // with a tip within 72 blocks (+/- 12 hours if no one mines it) of ours
1395
- // We use 7 blocks rather arbitrarily as it represents just under 10% of sustained network
1396
- // hash rate operating on the fork.
1397
- // or a chain that is entirely longer than ours and invalid (note that this should be detected by both)
1398
- // We define it this way because it allows us to only store the highest fork tip (+ base) which meets
1399
- // the 7-block condition and from this always have the most-likely-to-cause-warning fork
1400
- if (pfork && (!pindexBestForkTip || pindexNewForkTip->nHeight > pindexBestForkTip->nHeight ) &&
1401
- pindexNewForkTip->nChainWork - pfork->nChainWork > (GetBlockProof (*pfork) * 7 ) &&
1402
- ::ChainActive ().Height() - pindexNewForkTip->nHeight < 72)
1403
- {
1404
- pindexBestForkTip = pindexNewForkTip;
1405
- pindexBestForkBase = pfork;
1406
- }
1407
-
1408
- CheckForkWarningConditions ();
1409
- }
1410
-
1411
1354
// Called both upon regular invalid block discovery *and* InvalidateBlock
1412
1355
void static InvalidChainFound (CBlockIndex* pindexNew) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1413
1356
{
@@ -2821,11 +2764,7 @@ bool CChainState::ActivateBestChainStep(BlockValidationState& state, const CChai
2821
2764
}
2822
2765
m_mempool.check (&CoinsTip ());
2823
2766
2824
- // Callbacks/notifications for a new best chain.
2825
- if (fInvalidFound )
2826
- CheckForkWarningConditionsOnNewFork (vpindexToConnect.back ());
2827
- else
2828
- CheckForkWarningConditions ();
2767
+ CheckForkWarningConditions ();
2829
2768
2830
2769
return true ;
2831
2770
}
0 commit comments