" -rescan " + _("Rescan the block chain for missing wallet transactions") + "\n" +
" -zapwallettxes " + _("Clear list of wallet transactions (diagnostic tool; implies -rescan)") + "\n" +
" -salvagewallet " + _("Attempt to recover private keys from a corrupt wallet.dat") + "\n" +
- " -checkblocks=<n> " + _("How many blocks to check at startup (default: 2500, 0 = all)") + "\n" +
+ " -checkblocks=<n> " + _("How many blocks to check at startup (default: 192, 0 = all)") + "\n" +
" -checklevel=<n> " + _("How thorough the block verification is (0-6, default: 1)") + "\n" +
" -par=N " + _("Set the number of script verification threads (1-16, 0=auto, default: 0)") + "\n" +
" -loadblock=<file> " + _("Imports blocks from external blk000?.dat file") + "\n" +
{
FILE *file = fopen(strFile.c_str(), "rb");
if (file)
- LoadExternalBlockFile(file);
+ LoadExternalBlockFile(file, uiInterface);
}
StartShutdown();
}
FILE *file = fopen(pathBootstrap.string().c_str(), "rb");
if (file) {
filesystem::path pathBootstrapOld = GetDataDir() / "bootstrap.dat.old";
- LoadExternalBlockFile(file);
+ LoadExternalBlockFile(file, uiInterface);
RenameOver(pathBootstrap, pathBootstrapOld);
}
}
}
}
-bool LoadExternalBlockFile(FILE* fileIn)
+bool LoadExternalBlockFile(FILE* fileIn, CClientUIInterface& uiInterface)
{
auto nStart = GetTimeMillis();
-
+ vector<uint8_t> pchData(10 * (8+MAX_BLOCK_SIZE));
int nLoaded = 0;
{
LOCK(cs_main);
try {
CAutoFile blkdat(fileIn, SER_DISK, CLIENT_VERSION);
- unsigned int nPos = 0;
+ uint32_t nPos = 0;
while (nPos != std::numeric_limits<uint32_t>::max() && blkdat.good() && !fRequestShutdown)
{
- unsigned char pchData[65536];
- do {
+ do
+ {
fseek(blkdat, nPos, SEEK_SET);
- size_t nRead = fread(pchData, 1, sizeof(pchData), blkdat);
+ auto nRead = fread(&pchData[0], 1, pchData.size(), blkdat);
if (nRead <= 8)
{
- nPos = std::numeric_limits<uint32_t>::max();
+ nPos = numeric_limits<uint32_t>::max();
break;
}
- void* nFind = memchr(pchData, pchMessageStart[0], nRead+1-sizeof(pchMessageStart));
- if (nFind)
+ auto it = pchData.begin();
+ while(it != pchData.end() && !fRequestShutdown)
{
- if (memcmp(nFind, pchMessageStart, sizeof(pchMessageStart))==0)
+ auto nBlockLength = *reinterpret_cast<const uint32_t*>(&(*(it+4)));
+ auto SeekToNext = [&pchData, &it, &nPos, &nBlockLength]() {
+ auto previt = it;
+ it = search(it+8, pchData.end(), BEGIN(pchMessageStart), END(pchMessageStart));
+ if (it != pchData.end())
+ nPos += (it - previt);
+ };
+ if (nBlockLength > 0)
{
- nPos += ((unsigned char*)nFind - pchData) + sizeof(pchMessageStart);
- break;
+ if (nBlockLength > pchData.end() - it)
+ {
+ SeekToNext();
+ break; // We've reached the end of buffer
+ }
+ else
+ {
+ CBlock block;
+ try
+ {
+ vector<unsigned char> vchBlockBytes(it+8, it+8+nBlockLength);
+ CDataStream blockData(vchBlockBytes, SER_NETWORK, PROTOCOL_VERSION);
+ blockData >> block;
+ }
+ catch (const std::exception&)
+ {
+ printf("LoadExternalBlockFile() : Deserialize error caught at the position %" PRId64 ", this block may be truncated.", nPos);
+ SeekToNext();
+ break;
+ }
+ if (ProcessBlock(NULL, &block))
+ nLoaded++;
+ it += (8 + nBlockLength);
+ nPos += (8 + nBlockLength);
+ {
+ static int64_t nLastUpdate = 0;
+ if (GetTimeMillis() - nLastUpdate > 1000)
+ {
+ uiInterface.InitMessage(strprintf(_("%" PRId64 " blocks were read."), nLoaded));
+ nLastUpdate = GetTimeMillis();
+ }
+ }
+ }
+ }
+ else
+ {
+ SeekToNext();
}
- nPos += ((unsigned char*)nFind - pchData) + 1;
- }
- else
- nPos += sizeof(pchData) - sizeof(pchMessageStart) + 1;
- } while(!fRequestShutdown);
- if (nPos == std::numeric_limits<uint32_t>::max())
- break;
- fseek(blkdat, nPos, SEEK_SET);
- unsigned int nSize;
- blkdat >> nSize;
- if (nSize > 0 && nSize <= MAX_BLOCK_SIZE)
- {
- CBlock block;
- blkdat >> block;
- if (ProcessBlock(NULL,&block))
- {
- nLoaded++;
- nPos += 4 + nSize;
}
}
+ while(!fRequestShutdown);
}
}
catch (const std::exception&) {
- printf("%s() : Deserialize or I/O error caught during load\n",
+ printf("%s() : I/O error caught during load\n",
BOOST_CURRENT_FUNCTION);
}
}
// The message start string is designed to be unlikely to occur in normal data.
// The characters are rarely used upper ASCII, not valid as UTF-8, and produce
// a large 4-byte int at any alignment.
-unsigned char pchMessageStart[4] = { 0xe4, 0xe8, 0xe9, 0xe5 };
+uint8_t pchMessageStart[4] = { 0xe4, 0xe8, 0xe9, 0xe5 };
bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
{
#include "net.h"
#include "script.h"
#include "scrypt.h"
+#include "ui_interface.h"
#include <limits>
#include <list>
extern int64_t nTimeBestReceived;
extern CCriticalSection cs_setpwalletRegistered;
extern set<CWallet*> setpwalletRegistered;
-extern unsigned char pchMessageStart[4];
+extern uint8_t pchMessageStart[4];
extern map<uint256, CBlock*> mapOrphanBlocks;
// Settings
CBlockIndex* FindBlockByHeight(int nHeight);
bool ProcessMessages(CNode* pfrom);
bool SendMessages(CNode* pto);
-bool LoadExternalBlockFile(FILE* fileIn);
+bool LoadExternalBlockFile(FILE* fileIn, CClientUIInterface& uiInterface);
// Run an instance of the script checking thread
void ThreadScriptCheck(void* parg);
uint256 GetBlockHash() const
{
- if (fUseFastIndex && (nTime < GetAdjustedTime() - nOneDay) && blockHash != 0)
+ if (fUseFastIndex && blockHash != 0)
return blockHash;
CBlock block;
#include "netbase.h"
#include <string>
#include <limits>
+#include <vector>
#include "uint256.h"
extern bool fTestNet;
return static_cast<unsigned short>(fTestNet ? 17777 : 7777);
}
-
-extern unsigned char pchMessageStart[4];
+extern uint8_t pchMessageStart[4];
/** Message header.
* (4) message start.
QT_TRANSLATE_NOOP("bitcoin-core", "Find peers using DNS lookup (default: 0)"),
QT_TRANSLATE_NOOP("bitcoin-core", "Find peers using internet relay chat (default: 1)"),
QT_TRANSLATE_NOOP("bitcoin-core", "Get help for a command"),
-QT_TRANSLATE_NOOP("bitcoin-core", "How many blocks to check at startup (default: 2500, 0 = all)"),
+QT_TRANSLATE_NOOP("bitcoin-core", "How many blocks to check at startup (default: 192, 0 = all)"),
QT_TRANSLATE_NOOP("bitcoin-core", "How thorough the block verification is (0-6, default: 1)"),
QT_TRANSLATE_NOOP("bitcoin-core", "Importing blockchain data file."),
QT_TRANSLATE_NOOP("bitcoin-core", "Importing bootstrap blockchain data file."),
</message>
<message>
<location filename="../bitcoinstrings.cpp" line="105"/>
- <source>How many blocks to check at startup (default: 2500, 0 = all)</source>
- <translation>How many blocks to check at startup (default: 2500, 0 = all)</translation>
+ <source>How many blocks to check at startup (default: 192, 0 = all)</source>
+ <translation>How many blocks to check at startup (default: 192, 0 = all)</translation>
</message>
<message>
<location filename="../bitcoinstrings.cpp" line="106"/>
</message>
<message>
<location filename="../bitcoinstrings.cpp" line="105"/>
- <source>How many blocks to check at startup (default: 2500, 0 = all)</source>
- <translation>Сколько блоков проверять при запуске (по умолчанию: 2500, 0 = все)</translation>
+ <source>How many blocks to check at startup (default: 192, 0 = all)</source>
+ <translation>Сколько блоков проверять при запуске (по умолчанию: 192, 0 = все)</translation>
</message>
<message>
<location filename="../bitcoinstrings.cpp" line="106"/>
</message>
<message>
<location filename="../bitcoinstrings.cpp" line="105"/>
- <source>How many blocks to check at startup (default: 2500, 0 = all)</source>
- <translation>Скільки блоків перевіряти під час запуску (типово: 2500, 0 = всі)</translation>
+ <source>How many blocks to check at startup (default: 192, 0 = all)</source>
+ <translation>Скільки блоків перевіряти під час запуску (типово: 192, 0 = всі)</translation>
</message>
<message>
<location filename="../bitcoinstrings.cpp" line="106"/>
// Verify blocks in the best chain
int nCheckLevel = GetArgInt("-checklevel", 1);
- int nCheckDepth = GetArgInt( "-checkblocks", 2500);
+ int nCheckDepth = GetArgInt( "-checkblocks", 192);
if (nCheckDepth == 0)
nCheckDepth = 1000000000; // suffices until the year 19000
if (nCheckDepth > nBestHeight)
// Verify blocks in the best chain
int nCheckLevel = GetArgInt("-checklevel", 1);
- int nCheckDepth = GetArgInt( "-checkblocks", 2500);
+ int nCheckDepth = GetArgInt( "-checkblocks", 192);
if (nCheckDepth == 0)
nCheckDepth = 1000000000; // suffices until the year 19000
if (nCheckDepth > nBestHeight)