Clean fix and speedup

This commit is contained in:
jl777
2018-04-13 18:44:18 +03:00
parent d4f13ed801
commit f796b1fb8f
3 changed files with 180 additions and 119 deletions

View File

@@ -53,6 +53,7 @@ using namespace std;
CCriticalSection cs_main;
extern uint8_t NOTARY_PUBKEY33[33];
extern int32_t KOMODO_LOADINGBLOCKS;
BlockMap mapBlockIndex;
CChain chainActive;
@@ -4037,6 +4038,7 @@ bool CheckDiskSpace(uint64_t nAdditionalBytes)
FILE* OpenDiskFile(const CDiskBlockPos &pos, const char *prefix, bool fReadOnly)
{
static int32_t didinit; long fsize,fpos; int32_t incr = 16*1024*1024;
if (pos.IsNull())
return NULL;
boost::filesystem::path path = GetBlockPosFilename(pos, prefix);
@@ -4048,6 +4050,27 @@ FILE* OpenDiskFile(const CDiskBlockPos &pos, const char *prefix, bool fReadOnly)
LogPrintf("Unable to open file %s\n", path.string());
return NULL;
}
if ( didinit == 0 && strcmp(prefix,(char *)"blk") == 0 )
{
fpos = ftell(file);
fseek(file,0,SEEK_END);
fsize = ftell(file);
if ( fsize > incr )
{
char *ignore = (char *)malloc(incr);
if ( ignore != 0 )
{
rewind(file);
while ( fread(ignore,1,incr,file) == incr )
fprintf(stderr,".");
free(ignore);
fprintf(stderr,"loaded %ld bytes set fpos.%ld loading.%d\n",(long)ftell(file),(long)fpos,KOMODO_LOADINGBLOCKS);
}
}
fseek(file,fpos,SEEK_SET);
KOMODO_LOADINGBLOCKS = 0;
didinit = 1;
}
if (pos.nPos) {
if (fseek(file, pos.nPos, SEEK_SET)) {
LogPrintf("Unable to seek to position %u of %s\n", pos.nPos, path.string());
@@ -4491,7 +4514,6 @@ void UnloadBlockIndex()
bool LoadBlockIndex()
{
extern int32_t KOMODO_LOADINGBLOCKS;
// Load block index from databases
KOMODO_LOADINGBLOCKS = 1;
if (!fReindex && !LoadBlockIndexDB())