aboutsummaryrefslogtreecommitdiff
path: root/src/init.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/init.cpp')
-rw-r--r--src/init.cpp56
1 files changed, 27 insertions, 29 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 8a928218b..1724382bf 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -2,7 +2,7 @@
// Copyright (c) 2009-2012 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-#include "db.h"
+#include "txdb.h"
#include "walletdb.h"
#include "bitcoinrpc.h"
#include "net.h"
@@ -50,6 +50,8 @@ void StartShutdown()
#endif
}
+static CCoinsViewDB *pcoinsdbview;
+
void Shutdown(void* parg)
{
static CCriticalSection cs_Shutdown;
@@ -74,6 +76,16 @@ void Shutdown(void* parg)
nTransactionsUpdated++;
bitdb.Flush(false);
StopNode();
+ {
+ LOCK(cs_main);
+ if (pblocktree)
+ pblocktree->Flush();
+ if (pcoinsTip)
+ pcoinsTip->Flush();
+ delete pcoinsTip;
+ delete pcoinsdbview;
+ delete pblocktree;
+ }
bitdb.Flush(true);
boost::filesystem::remove(GetPidFile());
UnregisterWallet(pwalletMain);
@@ -298,6 +310,7 @@ std::string HelpMessage()
return strUsage;
}
+
/** Initialize bitcoin.
* @pre Parameters should be parsed and config file should be read.
*/
@@ -628,7 +641,7 @@ bool AppInit2()
BOOST_FOREACH(string strDest, mapMultiArgs["-seednode"])
AddOneShot(strDest);
- // ********************************************************* Step 7: load blockchain
+ // ********************************************************* Step 7: load block chain
if (!bitdb.Open(GetDataDir()))
{
@@ -638,17 +651,13 @@ bool AppInit2()
return InitError(msg);
}
- if (GetBoolArg("-loadblockindextest"))
- {
- CTxDB txdb("r");
- txdb.LoadBlockIndex();
- PrintBlockTree();
- return false;
- }
-
uiInterface.InitMessage(_("Loading block index..."));
printf("Loading block index...\n");
nStart = GetTimeMillis();
+ pblocktree = new CBlockTreeDB();
+ pcoinsdbview = new CCoinsViewDB();
+ pcoinsTip = new CCoinsViewCache(*pcoinsdbview);
+
if (!LoadBlockIndex())
return InitError(_("Error loading blkindex.dat"));
@@ -776,29 +785,18 @@ bool AppInit2()
// ********************************************************* Step 9: import blocks
+ // scan for better chains in the block chain database, that are not yet connected in the active best chain
+ uiInterface.InitMessage(_("Importing blocks from block database..."));
+ if (!ConnectBestBlock())
+ strErrors << "Failed to connect best block";
+
+ std::vector<boost::filesystem::path> *vPath = new std::vector<boost::filesystem::path>();
if (mapArgs.count("-loadblock"))
{
- uiInterface.InitMessage(_("Importing blockchain data file."));
-
BOOST_FOREACH(string strFile, mapMultiArgs["-loadblock"])
- {
- FILE *file = fopen(strFile.c_str(), "rb");
- if (file)
- LoadExternalBlockFile(file);
- }
- }
-
- filesystem::path pathBootstrap = GetDataDir() / "bootstrap.dat";
- if (filesystem::exists(pathBootstrap)) {
- uiInterface.InitMessage(_("Importing bootstrap blockchain data file."));
-
- FILE *file = fopen(pathBootstrap.string().c_str(), "rb");
- if (file) {
- filesystem::path pathBootstrapOld = GetDataDir() / "bootstrap.dat.old";
- LoadExternalBlockFile(file);
- RenameOver(pathBootstrap, pathBootstrapOld);
- }
+ vPath->push_back(strFile);
}
+ NewThread(ThreadImport, vPath);
// ********************************************************* Step 10: load peers