aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core/cryptonote_core.cpp
diff options
context:
space:
mode:
authorThomas Winget <tewinget@gmail.com>2015-03-25 11:41:30 -0400
committerThomas Winget <tewinget@gmail.com>2015-03-25 12:09:44 -0400
commit7b14d4a17f739c383322312f1a597f264c074c6e (patch)
tree3934f69a876d5f10637c93fc868d5a8f139aa164 /src/cryptonote_core/cryptonote_core.cpp
parentupdate berkeleydb branch to blockchain branch (diff)
downloadmonero-7b14d4a17f739c383322312f1a597f264c074c6e.tar.xz
Steps toward multiple dbs available -- working
There will need to be some more refactoring for these changes to be considered complete/correct, but for now it's working. new daemon cli argument "--db-type", works for LMDB and BerkeleyDB. A good deal of refactoring is also present in this commit, namely Blockchain no longer instantiates BlockchainDB, but rather is passed a pointer to an already-instantiated BlockchainDB on init().
Diffstat (limited to 'src/cryptonote_core/cryptonote_core.cpp')
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index f9b2b19ff..7864b55c8 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -44,6 +44,9 @@ using namespace epee;
#include <csignal>
#include "daemon/command_line_args.h"
#include "cryptonote_core/checkpoints_create.h"
+#include "blockchain_db/blockchain_db.h"
+#include "blockchain_db/lmdb/db_lmdb.h"
+#include "blockchain_db/berkeleydb/db_bdb.h"
DISABLE_VS_WARNINGS(4355)
@@ -194,7 +197,45 @@ namespace cryptonote
r = m_mempool.init(m_config_folder);
CHECK_AND_ASSERT_MES(r, false, "Failed to initialize memory pool");
+#if BLOCKCHAIN_DB == DB_LMDB
+ std::string db_type = command_line::get_arg(vm, daemon_args::arg_db_type);
+
+ BlockchainDB* db = nullptr;
+ if (db_type == "lmdb")
+ {
+ db = new BlockchainLMDB();
+ }
+ else if (db_type == "berkeley")
+ {
+ db = new BlockchainBDB();
+ }
+ else
+ {
+ LOG_ERROR("Attempted to use non-existant database type");
+ return false;
+ }
+
+ boost::filesystem::path folder(m_config_folder);
+
+ folder /= db->get_db_name();
+
+ LOG_PRINT_L0("Loading blockchain from folder " << folder.c_str() << " ...");
+
+ const std::string filename = folder.string();
+ try
+ {
+ db->open(filename);
+ }
+ catch (const DB_ERROR& e)
+ {
+ LOG_PRINT_L0("Error opening database: " << e.what());
+ return false;
+ }
+
+ r = m_blockchain_storage.init(db, m_testnet);
+#else
r = m_blockchain_storage.init(m_config_folder, m_testnet);
+#endif
CHECK_AND_ASSERT_MES(r, false, "Failed to initialize blockchain storage");
// load json & DNS checkpoints, and verify them