Update chainActive and related internal data structures.
| 1307 | |
| 1308 | // Update chainActive and related internal data structures. |
| 1309 | void static UpdateTip(CBlockIndex *pIndexNew, const CBlock &block) { |
| 1310 | chainActive.SetTip(pIndexNew, &block); |
| 1311 | |
| 1312 | SyncTransaction(uint256(), nullptr, &block); |
| 1313 | |
| 1314 | // Update best block in wallet (so we can detect restored wallets) |
| 1315 | bool fIsInitialDownload = IsInitialBlockDownload(); |
| 1316 | if ((chainActive.Height() % 20160) == 0 || (!fIsInitialDownload && (chainActive.Height() % 144) == 0)) |
| 1317 | g_signals.SetBestChain(chainActive.GetLocator()); |
| 1318 | |
| 1319 | // New best block |
| 1320 | SysCfg().SetBestRecvTime(GetTime()); |
| 1321 | LogPrint(BCLog::INFO, "[%d] %s blkTxCnt=%d fuelRate=%d ts=%s\n", |
| 1322 | chainActive.Height(), chainActive.Tip()->GetBlockHash().ToString(), |
| 1323 | block.vptx.size(), chainActive.Tip()->nFuelRate, |
| 1324 | DateTimeStrFormat("%Y-%m-%d %H:%M:%S", chainActive.Tip()->GetBlockTime())); |
| 1325 | |
| 1326 | // Check the version of the last 100 blocks to see if we need to upgrade: |
| 1327 | if (!fIsInitialDownload) { |
| 1328 | int32_t nUpgraded = 0; |
| 1329 | const CBlockIndex *pIndex = chainActive.Tip(); |
| 1330 | for (int32_t i = 0; i < 100 && pIndex != nullptr; i++) { |
| 1331 | if (pIndex->nVersion > CBlock::CURRENT_VERSION) |
| 1332 | ++nUpgraded; |
| 1333 | pIndex = pIndex->pprev; |
| 1334 | } |
| 1335 | if (nUpgraded > 0) |
| 1336 | LogPrint(BCLog::INFO, "SetBestChain: %d of last 100 blocks above version %d\n", nUpgraded, (int32_t)CBlock::CURRENT_VERSION); |
| 1337 | if (nUpgraded > 100 / 2) |
| 1338 | // strMiscWarning is read by GetWarnings(), called by Qt and the JSON-RPC code to warn the user: |
| 1339 | strMiscWarning = _("Warning: This version is obsolete, upgrade required!"); |
| 1340 | } |
| 1341 | } |
| 1342 | |
| 1343 | // Disconnect chainActive's tip. |
| 1344 | bool DisconnectTip(CValidationState &state) { |
no test coverage detected