@ -3078,15 +3078,6 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
try {
try {
// This takes over fileIn and calls fclose() on it in the CBufferedFile destructor
// This takes over fileIn and calls fclose() on it in the CBufferedFile destructor
CBufferedFile blkdat ( fileIn , 2 * MAX_BLOCK_SIZE , MAX_BLOCK_SIZE + 8 , SER_DISK , CLIENT_VERSION ) ;
CBufferedFile blkdat ( fileIn , 2 * MAX_BLOCK_SIZE , MAX_BLOCK_SIZE + 8 , SER_DISK , CLIENT_VERSION ) ;
uint64_t nStartByte = 0 ;
if ( dbp ) {
// (try to) skip already indexed part
CBlockFileInfo info ;
if ( pblocktree - > ReadBlockFileInfo ( dbp - > nFile , info ) ) {
nStartByte = info . nSize ;
blkdat . Seek ( info . nSize ) ;
}
}
uint64_t nRewind = blkdat . GetPos ( ) ;
uint64_t nRewind = blkdat . GetPos ( ) ;
while ( ! blkdat . eof ( ) ) {
while ( ! blkdat . eof ( ) ) {
boost : : this_thread : : interruption_point ( ) ;
boost : : this_thread : : interruption_point ( ) ;
@ -3114,40 +3105,32 @@ bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp)
try {
try {
// read block
// read block
uint64_t nBlockPos = blkdat . GetPos ( ) ;
uint64_t nBlockPos = blkdat . GetPos ( ) ;
if ( nBlockPos < nStartByte ) // skip already indexed part
continue ;
if ( dbp )
if ( dbp )
dbp - > nPos = nBlockPos ;
dbp - > nPos = nBlockPos ;
blkdat . SetLimit ( nBlockPos + nSize ) ;
blkdat . SetLimit ( nBlockPos + nSize ) ;
blkdat . SetPos ( nBlockPos ) ;
// read block header
CBlock block ;
CBlockHeader blockhdr ;
blkdat > > block ;
blkdat > > blockhdr ;
nRewind = blkdat . GetPos ( ) ;
nRewind = blkdat . GetPos ( ) ;
// process block head er
// detect out of order blocks, and store them for lat er
uint256 hash = block hdr . GetHash ( ) ;
uint256 hash = block . GetHash ( ) ;
if ( hash ! = Params ( ) . HashGenesisBlock ( ) & & mapBlockIndex . find ( block hdr . hashPrevBlock ) = = mapBlockIndex . end ( ) ) {
if ( hash ! = Params ( ) . HashGenesisBlock ( ) & & mapBlockIndex . find ( block . hashPrevBlock ) = = mapBlockIndex . end ( ) ) {
LogPrint ( " reindex " , " %s: Out of order block %s, parent %s not known \n " , __func__ , hash . ToString ( ) ,
LogPrint ( " reindex " , " %s: Out of order block %s, parent %s not known \n " , __func__ , hash . ToString ( ) ,
block hdr . hashPrevBlock . ToString ( ) ) ;
block . hashPrevBlock . ToString ( ) ) ;
if ( dbp )
if ( dbp )
mapBlocksUnknownParent . insert ( std : : make_pair ( blockhdr . hashPrevBlock , * dbp ) ) ;
mapBlocksUnknownParent . insert ( std : : make_pair ( block . hashPrevBlock , * dbp ) ) ;
// TODO a slight optimization would be: blkdat.Skip(nSize - 80)
continue ;
continue ;
}
}
// read block
// process in case the block isn't known yet
blkdat . SetPos ( nBlockPos ) ;
if ( mapBlockIndex . count ( hash ) = = 0 ) {
CBlock block ;
blkdat > > block ;
nRewind = blkdat . GetPos ( ) ;
// process block
CValidationState state ;
CValidationState state ;
if ( ProcessBlock ( state , NULL , & block , dbp ) )
if ( ProcessBlock ( state , NULL , & block , dbp ) )
nLoaded + + ;
nLoaded + + ;
if ( state . IsError ( ) )
if ( state . IsError ( ) )
break ;
break ;
}
// Recursively process earlier encountered successors of this block
// Recursively process earlier encountered successors of this block
deque < uint256 > queue ;
deque < uint256 > queue ;