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

Function LoadExternalBlockFile

src/main.cpp:2489–2558  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2487}
2488
2489bool LoadExternalBlockFile(FILE *fileIn, CDiskBlockPos *dbp) {
2490 int64_t nStart = GetTimeMillis();
2491 int32_t nLoaded = 0;
2492 try {
2493 CBufferedFile blkdat(fileIn, 2 * MAX_BLOCK_SIZE, MAX_BLOCK_SIZE + 8, SER_DISK, CLIENT_VERSION);
2494 uint64_t nStartByte = 0;
2495 if (dbp) {
2496 // (try to) skip already indexed part
2497 CBlockFileInfo info;
2498 if (pCdMan->pBlockIndexDb->ReadBlockFileInfo(dbp->nFile, info)) {
2499 nStartByte = info.nSize;
2500 blkdat.Seek(info.nSize);
2501 }
2502 }
2503 uint64_t nRewind = blkdat.GetPos();
2504 while (blkdat.good() && !blkdat.eof()) {
2505 boost::this_thread::interruption_point();
2506
2507 blkdat.SetPos(nRewind);
2508 nRewind++; // start one byte further next time, in case of failure
2509 blkdat.SetLimit(); // remove former limit
2510 uint32_t nSize = 0;
2511 try {
2512 // locate a header
2513 uint8_t buf[MESSAGE_START_SIZE];
2514 blkdat.FindByte(SysCfg().MessageStart()[0]);
2515 nRewind = blkdat.GetPos() + 1;
2516 blkdat >> FLATDATA(buf);
2517 if (memcmp(buf, SysCfg().MessageStart(), MESSAGE_START_SIZE))
2518 continue;
2519 // read size
2520 blkdat >> nSize;
2521 if (nSize < 80 || nSize > MAX_BLOCK_SIZE)
2522 continue;
2523 } catch (std::exception &e) {
2524 // no valid block header found; don't complain
2525 break;
2526 }
2527 try {
2528 // read block
2529 uint64_t nBlockPos = blkdat.GetPos();
2530 blkdat.SetLimit(nBlockPos + nSize);
2531 CBlock block;
2532 blkdat >> block;
2533 nRewind = blkdat.GetPos();
2534
2535 // process block
2536 if (nBlockPos >= nStartByte) {
2537 LOCK(cs_main);
2538 if (dbp)
2539 dbp->nPos = nBlockPos;
2540 CValidationState state;
2541 if (ProcessBlock(state, nullptr, &block, dbp))
2542 nLoaded++;
2543 if (state.IsError())
2544 break;
2545 }
2546 } catch (std::exception &e) {

Callers 1

ThreadImportFunction · 0.85

Calls 14

ProcessBlockFunction · 0.85
AbortNodeFunction · 0.85
_Function · 0.85
ReadBlockFileInfoMethod · 0.80
GetPosMethod · 0.80
SetPosMethod · 0.80
SetLimitMethod · 0.80
FindByteMethod · 0.80
IsErrorMethod · 0.80
GetTimeMillisFunction · 0.50
SeekMethod · 0.45
goodMethod · 0.45

Tested by

no test coverage detected