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
This commit is contained in:
Thomas Winget 2014-10-27 23:44:45 -04:00 committed by warptangent
parent d8c570b588
commit 74a1a89e27
No known key found for this signature in database
GPG key ID: 0E490BEBFBE4E92D
8 changed files with 58 additions and 24 deletions

View file

@ -672,6 +672,7 @@ void BlockchainLMDB::open(const std::string& filename)
// unused for now, create will happen on open if doesn't exist
void BlockchainLMDB::create(const std::string& filename)
{
throw DB_CREATE_FAILURE("create() is not implemented for this BlockchainDB, open() will create files if needed.");
}
void BlockchainLMDB::close()

View file

@ -29,6 +29,9 @@
set(cryptonote_core_sources
account.cpp
blockchain_storage.cpp
blockchain.cpp
blockchain_db.cpp
BlockchainDB_impl/db_lmdb.cpp
checkpoints.cpp
checkpoints_create.cpp
cryptonote_basic_impl.cpp
@ -45,6 +48,9 @@ set(cryptonote_core_private_headers
account_boost_serialization.h
blockchain_storage.h
blockchain_storage_boost_serialization.h
blockchain.h
blockchain_db.h
BlockchainDB_impl/db_lmdb.h
checkpoints.h
checkpoints_create.h
connection_context.h
@ -77,4 +83,5 @@ target_link_libraries(cryptonote_core
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY}
${Boost_THREAD_LIBRARY}
${LMDB_LIBRARIES}
${EXTRA_LIBRARIES})

View file

@ -32,10 +32,14 @@
#include <cstdio>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/filesystem.hpp>
#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<class t_ids_container, class t_blocks_container, class t_missed_container>
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<class t_ids_container, class t_tx_container, class t_missed_container>
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,8 +1501,14 @@ 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)
{

View file

@ -41,7 +41,6 @@
#include "syncobj.h"
#include "string_tools.h"
#include "tx_pool.h"
#include "cryptonote_basic.h"
#include "common/util.h"
#include "cryptonote_protocol/cryptonote_protocol_defs.h"
@ -55,6 +54,7 @@
namespace cryptonote
{
class tx_memory_pool;
/************************************************************************/
/* */
@ -131,16 +131,19 @@ namespace cryptonote
uint64_t block_difficulty(uint64_t i);
template<class t_ids_container, class t_blocks_container, class t_missed_container>
void get_blocks(const t_ids_container& block_ids, t_blocks_container& blocks, t_missed_container& missed_bs);
bool get_blocks(const t_ids_container& block_ids, t_blocks_container& blocks, t_missed_container& missed_bs);
template<class t_ids_container, class t_tx_container, class t_missed_container>
void get_transactions(const t_ids_container& txs_ids, t_tx_container& txs, t_missed_container& missed_txs);
bool get_transactions(const t_ids_container& txs_ids, t_tx_container& txs, t_missed_container& missed_txs);
//debug functions
void print_blockchain(uint64_t start_index, uint64_t end_index);
void print_blockchain_index();
void print_blockchain_outs(const std::string& file);
void set_enforce_dns_checkpoints(bool enforce) { }
bool update_checkpoints(const std::string& path, bool dns) { return true; }
private:
typedef std::unordered_map<crypto::hash, size_t> blocks_by_id_index;
typedef std::unordered_map<crypto::hash, transaction_chain_entry> transactions_container;
@ -175,6 +178,7 @@ namespace cryptonote
checkpoints m_checkpoints;
std::atomic<bool> m_is_in_checkpoint_zone;
std::atomic<bool> m_is_blockchain_storing;
bool m_testnet;
bool switch_to_alternative_blockchain(std::list<blocks_ext_by_hash::iterator>& alt_chain, bool discard_disconnected_chain);
block pop_block_from_blockchain();

View file

@ -290,9 +290,9 @@ namespace cryptonote
return false;
}
if(!keeped_by_block && get_object_blobsize(tx) >= m_blockchain_storage.get_current_comulative_blocksize_limit() - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE)
if(!keeped_by_block && get_object_blobsize(tx) >= m_blockchain_storage.get_current_cumulative_blocksize_limit() - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE)
{
LOG_PRINT_RED_L1("tx is too large " << get_object_blobsize(tx) << ", expected not bigger than " << m_blockchain_storage.get_current_comulative_blocksize_limit() - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE);
LOG_PRINT_RED_L1("tx is too large " << get_object_blobsize(tx) << ", expected not bigger than " << m_blockchain_storage.get_current_cumulative_blocksize_limit() - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE);
return false;
}
@ -577,7 +577,7 @@ namespace cryptonote
m_starter_message_showed = true;
}
m_store_blockchain_interval.do_call(boost::bind(&blockchain_storage::store_blockchain, &m_blockchain_storage));
m_store_blockchain_interval.do_call(boost::bind(&Blockchain::store_blockchain, &m_blockchain_storage));
m_miner.on_idle();
m_mempool.on_idle();
return true;

View file

@ -39,7 +39,7 @@
#include "cryptonote_protocol/cryptonote_protocol_handler_common.h"
#include "storages/portable_storage_template_helper.h"
#include "tx_pool.h"
#include "blockchain_storage.h"
#include "blockchain.h"
#include "miner.h"
#include "connection_context.h"
#include "cryptonote_core/cryptonote_stat_info.h"
@ -112,7 +112,7 @@ namespace cryptonote
bool get_random_outs_for_amounts(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& res);
void pause_mine();
void resume_mine();
blockchain_storage& get_blockchain_storage(){return m_blockchain_storage;}
Blockchain& get_blockchain_storage(){return m_blockchain_storage;}
//debug functions
void print_blockchain(uint64_t start_index, uint64_t end_index);
void print_blockchain_index();
@ -149,7 +149,7 @@ namespace cryptonote
tx_memory_pool m_mempool;
blockchain_storage m_blockchain_storage;
Blockchain m_blockchain_storage;
i_cryptonote_protocol* m_pprotocol;
epee::critical_section m_incoming_tx_lock;
//m_miner and m_miner_addres are probably temporary here

View file

@ -37,7 +37,7 @@
#include "cryptonote_format_utils.h"
#include "cryptonote_boost_serialization.h"
#include "cryptonote_config.h"
#include "blockchain_storage.h"
#include "blockchain.h"
#include "common/boost_serialization_helper.h"
#include "common/int-util.h"
#include "misc_language.h"
@ -54,7 +54,7 @@ namespace cryptonote
}
//---------------------------------------------------------------------------------
tx_memory_pool::tx_memory_pool(blockchain_storage& bchs): m_blockchain(bchs)
tx_memory_pool::tx_memory_pool(Blockchain& bchs): m_blockchain(bchs)
{
}

View file

@ -47,7 +47,7 @@
namespace cryptonote
{
class blockchain_storage;
class Blockchain;
/************************************************************************/
/* */
/************************************************************************/
@ -55,7 +55,7 @@ namespace cryptonote
class tx_memory_pool: boost::noncopyable
{
public:
tx_memory_pool(blockchain_storage& bchs);
tx_memory_pool(Blockchain& bchs);
bool add_tx(const transaction &tx, const crypto::hash &id, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block);
bool add_tx(const transaction &tx, tx_verification_context& tvc, bool keeped_by_block);
//gets tx and remove it from pool
@ -127,7 +127,7 @@ namespace cryptonote
//transactions_container m_alternative_transactions;
std::string m_config_folder;
blockchain_storage& m_blockchain;
Blockchain& m_blockchain;
/************************************************************************/
/* */
/************************************************************************/
@ -170,9 +170,6 @@ namespace cryptonote
uint64_t operator()(const txin_to_scripthash& tx) const {return 0;}
};
#if defined(DEBUG_CREATE_BLOCK_TEMPLATE)
friend class blockchain_storage;
#endif
};
}