| 2429 | } |
| 2430 | |
| 2431 | void PrintBlockTree() { |
| 2432 | AssertLockHeld(cs_main); |
| 2433 | // pre-compute tree structure |
| 2434 | map<CBlockIndex *, vector<CBlockIndex *> > mapNext; |
| 2435 | for (map<uint256, CBlockIndex *>::iterator mi = mapBlockIndex.begin(); mi != mapBlockIndex.end(); ++mi) { |
| 2436 | CBlockIndex *pIndex = (*mi).second; |
| 2437 | mapNext[pIndex->pprev].push_back(pIndex); |
| 2438 | } |
| 2439 | |
| 2440 | vector<pair<int32_t, CBlockIndex *> > vStack; |
| 2441 | vStack.push_back(make_pair(0, chainActive.Genesis())); |
| 2442 | |
| 2443 | int32_t nPrevCol = 0; |
| 2444 | while (!vStack.empty()) { |
| 2445 | int32_t nCol = vStack.back().first; |
| 2446 | CBlockIndex *pIndex = vStack.back().second; |
| 2447 | vStack.pop_back(); |
| 2448 | |
| 2449 | // print split or gap |
| 2450 | if (nCol > nPrevCol) { |
| 2451 | for (int32_t i = 0; i < nCol - 1; i++) |
| 2452 | LogPrint(BCLog::INFO, "| "); |
| 2453 | LogPrint(BCLog::INFO, "|\\\n"); |
| 2454 | } else if (nCol < nPrevCol) { |
| 2455 | for (int32_t i = 0; i < nCol; i++) |
| 2456 | LogPrint(BCLog::INFO, "| "); |
| 2457 | LogPrint(BCLog::INFO, "|\n"); |
| 2458 | } |
| 2459 | nPrevCol = nCol; |
| 2460 | |
| 2461 | // print columns |
| 2462 | for (int32_t i = 0; i < nCol; i++) |
| 2463 | LogPrint(BCLog::INFO, "| "); |
| 2464 | |
| 2465 | // print item |
| 2466 | CBlock block; |
| 2467 | ReadBlockFromDisk(pIndex, block); |
| 2468 | LogPrint(BCLog::INFO, "%d (blk%05u.dat:0x%x) %s tx %u\n", |
| 2469 | pIndex->height, |
| 2470 | pIndex->GetBlockPos().nFile, pIndex->GetBlockPos().nPos, |
| 2471 | DateTimeStrFormat("%Y-%m-%d %H:%M:%S", block.GetBlockTime()), |
| 2472 | block.vptx.size()); |
| 2473 | |
| 2474 | // put the main time-chain first |
| 2475 | vector<CBlockIndex *> &vNext = mapNext[pIndex]; |
| 2476 | for (uint32_t i = 0; i < vNext.size(); i++) { |
| 2477 | if (chainActive.Next(vNext[i])) { |
| 2478 | swap(vNext[0], vNext[i]); |
| 2479 | break; |
| 2480 | } |
| 2481 | } |
| 2482 | |
| 2483 | // iterate children |
| 2484 | for (uint32_t i = 0; i < vNext.size(); i++) |
| 2485 | vStack.push_back(make_pair(nCol + i, vNext[i])); |
| 2486 | } |
| 2487 | } |
| 2488 |
no test coverage detected