| 4188 | } |
| 4189 | |
| 4190 | bool LoadChainTip(const CChainParams& chainparams) |
| 4191 | { |
| 4192 | AssertLockHeld(cs_main); |
| 4193 | |
| 4194 | if (chainActive.Tip() && chainActive.Tip()->GetBlockHash() == pcoinsTip->GetBestBlock()) return true; |
| 4195 | |
| 4196 | if (pcoinsTip->GetBestBlock().IsNull() && mapBlockIndex.size() == 1) { |
| 4197 | // In case we just added the genesis block, connect it now, so |
| 4198 | // that we always have a chainActive.Tip() when we return. |
| 4199 | LogPrintf("%s: Connecting genesis block...\n", __func__); |
| 4200 | CValidationState state; |
| 4201 | if (!ActivateBestChain(state, chainparams)) { |
| 4202 | LogPrintf("%s: failed to activate chain (%s)\n", __func__, FormatStateMessage(state)); |
| 4203 | return false; |
| 4204 | } |
| 4205 | } |
| 4206 | |
| 4207 | // Load pointer to end of best chain |
| 4208 | CBlockIndex* pindex = LookupBlockIndex(pcoinsTip->GetBestBlock()); |
| 4209 | if (!pindex) { |
| 4210 | return false; |
| 4211 | } |
| 4212 | chainActive.SetTip(pindex); |
| 4213 | |
| 4214 | g_chainstate.PruneBlockIndexCandidates(); |
| 4215 | |
| 4216 | LogPrintf("Loaded best chain: hashBestChain=%s height=%d date=%s progress=%f\n", |
| 4217 | chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), |
| 4218 | FormatISO8601DateTime(chainActive.Tip()->GetBlockTime()), |
| 4219 | GuessVerificationProgress(chainparams.TxData(), chainActive.Tip())); |
| 4220 | return true; |
| 4221 | } |
| 4222 | |
| 4223 | CVerifyDB::CVerifyDB() |
| 4224 | { |
no test coverage detected