From 74a1a89e27c719811a1fcc0578e4795802555225 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Mon, 27 Oct 2014 23:44:45 -0400 Subject: Integrate BlockchainDB into cryptonote_core Probably needs more looking at -- lot of things were done...in a rushed sort of way. That said, it all builds and *should* be at least testable. update for rebase (warptangent 2015-01-04) fix conflicts with upstream CMakeLists.txt files src/CMakeLists.txt (remove edits from original commit) tests/CMakeLists.txt (remove edits from original commit) src/cryptonote_core/CMakeLists.txt (edit) - use blockchain db .cpp and .h files - add LMDB_LIBRARIES --- src/cryptonote_core/blockchain.cpp | 39 +++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'src/cryptonote_core/blockchain.cpp') diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index a35ce846c..0f5765281 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -32,10 +32,14 @@ #include #include #include +#include #include "include_base_utils.h" #include "cryptonote_basic_impl.h" +#include "tx_pool.h" #include "blockchain.h" +#include "cryptonote_core/blockchain_db.h" +#include "cryptonote_core/BlockchainDB_impl/db_lmdb.h" #include "cryptonote_format_utils.h" #include "cryptonote_boost_serialization.h" #include "cryptonote_config.h" @@ -62,10 +66,6 @@ DISABLE_VS_WARNINGS(4267) // TODO: initialize m_db with a concrete implementation of BlockchainDB Blockchain::Blockchain(tx_memory_pool& tx_pool):m_db(), m_tx_pool(tx_pool), m_current_block_cumul_sz_limit(0), m_is_in_checkpoint_zone(false), m_is_blockchain_storing(false) { - if (m_db == NULL) - { - throw new DB_ERROR("database pointer null in blockchain init"); - } } //------------------------------------------------------------------ //TODO: is this still needed? I don't think so - tewinget @@ -222,11 +222,23 @@ bool Blockchain::init(const std::string& config_folder, bool testnet) { CRITICAL_REGION_LOCAL(m_blockchain_lock); + m_db = new BlockchainLMDB(); + m_config_folder = config_folder; + m_testnet = testnet; + + boost::filesystem::path folder(m_config_folder); + + // append "testnet" directory as needed + if (testnet) + { + folder /= "testnet"; + } + LOG_PRINT_L0("Loading blockchain..."); //FIXME: update filename for BlockchainDB - const std::string filename = m_config_folder + "/" CRYPTONOTE_BLOCKCHAINDATA_FILENAME; + const std::string filename = folder.string(); try { m_db->open(filename); @@ -328,6 +340,8 @@ bool Blockchain::deinit() { LOG_PRINT_L0("There was an issue closing/storing the blockchain, shutting down now to prevent issues!"); } + + delete m_db; return true; } //------------------------------------------------------------------ @@ -1450,7 +1464,7 @@ uint64_t Blockchain::block_difficulty(uint64_t i) } //------------------------------------------------------------------ template -void Blockchain::get_blocks(const t_ids_container& block_ids, t_blocks_container& blocks, t_missed_container& missed_bs) +bool Blockchain::get_blocks(const t_ids_container& block_ids, t_blocks_container& blocks, t_missed_container& missed_bs) { CRITICAL_REGION_LOCAL(m_blockchain_lock); @@ -1464,11 +1478,16 @@ void Blockchain::get_blocks(const t_ids_container& block_ids, t_blocks_container { missed_bs.push_back(block_hash); } + catch (const std::exception& e) + { + return false; + } } + return true; } //------------------------------------------------------------------ template -void Blockchain::get_transactions(const t_ids_container& txs_ids, t_tx_container& txs, t_missed_container& missed_txs) +bool Blockchain::get_transactions(const t_ids_container& txs_ids, t_tx_container& txs, t_missed_container& missed_txs) { CRITICAL_REGION_LOCAL(m_blockchain_lock); @@ -1482,7 +1501,13 @@ void Blockchain::get_transactions(const t_ids_container& txs_ids, t_tx_container { missed_txs.push_back(tx_hash); } + //FIXME: is this the correct way to handle this? + catch (const std::exception& e) + { + return false; + } } + return true; } //------------------------------------------------------------------ void Blockchain::print_blockchain(uint64_t start_index, uint64_t end_index) -- cgit v1.2.3