MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / UpdateTip

Function UpdateTip

src/main.cpp:1309–1341  ·  view source on GitHub ↗

Update chainActive and related internal data structures.

Source from the content-addressed store, hash-verified

1307
1308// Update chainActive and related internal data structures.
1309void 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.
1344bool DisconnectTip(CValidationState &state) {

Callers 2

DisconnectTipFunction · 0.85
ConnectTipFunction · 0.85

Calls 15

SyncTransactionFunction · 0.85
IsInitialBlockDownloadFunction · 0.85
GetTimeFunction · 0.85
DateTimeStrFormatFunction · 0.85
_Function · 0.85
SetTipMethod · 0.80
HeightMethod · 0.80
SetBestChainMethod · 0.80
GetLocatorMethod · 0.80
SetBestRecvTimeMethod · 0.80
TipMethod · 0.80
uint256Class · 0.70

Tested by

no test coverage detected