@@ -3078,15 +3078,6 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
30783078 try {
30793079 // This takes over fileIn and calls fclose() on it in the CBufferedFile destructor
30803080 CBufferedFile blkdat (fileIn, 2 *MAX_BLOCK_SIZE, MAX_BLOCK_SIZE+8 , SER_DISK, CLIENT_VERSION);
3081- uint64_t nStartByte = 0 ;
3082- if (dbp) {
3083- // (try to) skip already indexed part
3084- CBlockFileInfo info;
3085- if (pblocktree->ReadBlockFileInfo (dbp->nFile , info)) {
3086- nStartByte = info.nSize ;
3087- blkdat.Seek (info.nSize );
3088- }
3089- }
30903081 uint64_t nRewind = blkdat.GetPos ();
30913082 while (!blkdat.eof ()) {
30923083 boost::this_thread::interruption_point ();
@@ -3114,40 +3105,32 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
31143105 try {
31153106 // read block
31163107 uint64_t nBlockPos = blkdat.GetPos ();
3117- if (nBlockPos < nStartByte) // skip already indexed part
3118- continue ;
31193108 if (dbp)
31203109 dbp->nPos = nBlockPos;
31213110 blkdat.SetLimit (nBlockPos + nSize);
3122-
3123- // read block header
3124- CBlockHeader blockhdr;
3125- blkdat >> blockhdr;
3111+ blkdat.SetPos (nBlockPos);
3112+ CBlock block;
3113+ blkdat >> block;
31263114 nRewind = blkdat.GetPos ();
31273115
3128- // process block header
3129- uint256 hash = blockhdr .GetHash ();
3130- if (hash != Params ().HashGenesisBlock () && mapBlockIndex.find (blockhdr .hashPrevBlock ) == mapBlockIndex.end ()) {
3116+ // detect out of order blocks, and store them for later
3117+ uint256 hash = block .GetHash ();
3118+ if (hash != Params ().HashGenesisBlock () && mapBlockIndex.find (block .hashPrevBlock ) == mapBlockIndex.end ()) {
31313119 LogPrint (" reindex" , " %s: Out of order block %s, parent %s not known\n " , __func__, hash.ToString (),
3132- blockhdr .hashPrevBlock .ToString ());
3120+ block .hashPrevBlock .ToString ());
31333121 if (dbp)
3134- mapBlocksUnknownParent.insert (std::make_pair (blockhdr.hashPrevBlock , *dbp));
3135- // TODO a slight optimization would be: blkdat.Skip(nSize - 80)
3122+ mapBlocksUnknownParent.insert (std::make_pair (block.hashPrevBlock , *dbp));
31363123 continue ;
31373124 }
31383125
3139- // read block
3140- blkdat.SetPos (nBlockPos);
3141- CBlock block;
3142- blkdat >> block;
3143- nRewind = blkdat.GetPos ();
3144-
3145- // process block
3146- CValidationState state;
3147- if (ProcessBlock (state, NULL , &block, dbp))
3148- nLoaded++;
3149- if (state.IsError ())
3150- break ;
3126+ // process in case the block isn't known yet
3127+ if (mapBlockIndex.count (hash) == 0 ) {
3128+ CValidationState state;
3129+ if (ProcessBlock (state, NULL , &block, dbp))
3130+ nLoaded++;
3131+ if (state.IsError ())
3132+ break ;
3133+ }
31513134
31523135 // Recursively process earlier encountered successors of this block
31533136 deque<uint256> queue;
0 commit comments