Add compile-time support for both db implementations: in-memory and LMDB
Usage: default is lmdb for blockchain branch: $ make release same as: $ DATABASE=lmdb make release for original in-memory implementation: $ DATABASE=memory make release
This commit is contained in:
parent
a4f5344024
commit
84fe5fbd65
9 changed files with 77 additions and 4 deletions
|
@ -116,6 +116,27 @@ if(STATIC)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# default database:
|
||||||
|
# should be lmdb for testing, memory for production still
|
||||||
|
# set(DATABASE memory)
|
||||||
|
set(DATABASE lmdb)
|
||||||
|
|
||||||
|
if (DEFINED ENV{DATABASE})
|
||||||
|
set(DATABASE $ENV{DATABASE})
|
||||||
|
message(STATUS "DATABASE set: ${DATABASE}")
|
||||||
|
else()
|
||||||
|
message(STATUS "Could not find DATABASE in env (not required unless you want to change database type from default: ${DATABASE})")
|
||||||
|
endif()
|
||||||
|
if (DATABASE STREQUAL "lmdb")
|
||||||
|
set(BLOCKCHAIN_DB DB_LMDB)
|
||||||
|
elseif (DATABASE STREQUAL "memory")
|
||||||
|
set(BLOCKCHAIN_DB DB_MEMORY)
|
||||||
|
else()
|
||||||
|
die("Invalid database type: ${DATABASE}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_definitions("-DBLOCKCHAIN_DB=${BLOCKCHAIN_DB}")
|
||||||
|
|
||||||
if (UNIX AND NOT APPLE)
|
if (UNIX AND NOT APPLE)
|
||||||
# Note that at the time of this writing the -Wstrict-prototypes flag added below will make this fail
|
# Note that at the time of this writing the -Wstrict-prototypes flag added below will make this fail
|
||||||
find_package(Threads)
|
find_package(Threads)
|
||||||
|
|
|
@ -35,6 +35,7 @@ set(blockchain_converter_private_headers)
|
||||||
bitmonero_private_headers(blockchain_converter
|
bitmonero_private_headers(blockchain_converter
|
||||||
${blockchain_converter_private_headers})
|
${blockchain_converter_private_headers})
|
||||||
|
|
||||||
|
if (BLOCKCHAIN_DB STREQUAL DB_LMDB)
|
||||||
bitmonero_add_executable(blockchain_converter
|
bitmonero_add_executable(blockchain_converter
|
||||||
${blockchain_converter_sources}
|
${blockchain_converter_sources}
|
||||||
${blockchain_converter_private_headers})
|
${blockchain_converter_private_headers})
|
||||||
|
@ -49,3 +50,4 @@ add_dependencies(blockchain_converter
|
||||||
set_property(TARGET blockchain_converter
|
set_property(TARGET blockchain_converter
|
||||||
PROPERTY
|
PROPERTY
|
||||||
OUTPUT_NAME "blockchain_converter")
|
OUTPUT_NAME "blockchain_converter")
|
||||||
|
endif ()
|
||||||
|
|
|
@ -640,7 +640,7 @@ bool blockchain_storage::get_last_n_blocks_sizes(std::vector<size_t>& sz, size_t
|
||||||
return get_backward_blocks_sizes(m_blocks.size() -1, sz, count);
|
return get_backward_blocks_sizes(m_blocks.size() -1, sz, count);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------
|
//------------------------------------------------------------------
|
||||||
uint64_t blockchain_storage::get_current_comulative_blocksize_limit() const
|
uint64_t blockchain_storage::get_current_cumulative_blocksize_limit() const
|
||||||
{
|
{
|
||||||
return m_current_block_cumul_sz_limit;
|
return m_current_block_cumul_sz_limit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,7 @@ namespace cryptonote
|
||||||
bool check_tx_inputs(const transaction& tx, const crypto::hash& tx_prefix_hash, uint64_t* pmax_used_block_height = NULL) const;
|
bool check_tx_inputs(const transaction& tx, const crypto::hash& tx_prefix_hash, uint64_t* pmax_used_block_height = NULL) const;
|
||||||
bool check_tx_inputs(const transaction& tx, uint64_t* pmax_used_block_height = NULL) const;
|
bool check_tx_inputs(const transaction& tx, uint64_t* pmax_used_block_height = NULL) const;
|
||||||
bool check_tx_inputs(const transaction& tx, uint64_t& pmax_used_block_height, crypto::hash& max_used_block_id) const;
|
bool check_tx_inputs(const transaction& tx, uint64_t& pmax_used_block_height, crypto::hash& max_used_block_id) const;
|
||||||
uint64_t get_current_comulative_blocksize_limit() const;
|
uint64_t get_current_cumulative_blocksize_limit() const;
|
||||||
bool is_storing_blockchain()const{return m_is_blockchain_storing;}
|
bool is_storing_blockchain()const{return m_is_blockchain_storing;}
|
||||||
uint64_t block_difficulty(size_t i) const;
|
uint64_t block_difficulty(size_t i) const;
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,8 @@
|
||||||
#include "misc_language.h"
|
#include "misc_language.h"
|
||||||
#include "tx_extra.h"
|
#include "tx_extra.h"
|
||||||
|
|
||||||
|
#define DB_MEMORY 1
|
||||||
|
#define DB_LMDB 2
|
||||||
|
|
||||||
namespace cryptonote
|
namespace cryptonote
|
||||||
{
|
{
|
||||||
|
|
|
@ -51,7 +51,11 @@ namespace cryptonote
|
||||||
//-----------------------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------------------
|
||||||
core::core(i_cryptonote_protocol* pprotocol):
|
core::core(i_cryptonote_protocol* pprotocol):
|
||||||
m_mempool(m_blockchain_storage),
|
m_mempool(m_blockchain_storage),
|
||||||
|
#if BLOCKCHAIN_DB == DB_LMDB
|
||||||
m_blockchain_storage(m_mempool),
|
m_blockchain_storage(m_mempool),
|
||||||
|
#else
|
||||||
|
m_blockchain_storage(&m_mempool),
|
||||||
|
#endif
|
||||||
m_miner(this),
|
m_miner(this),
|
||||||
m_miner_address(boost::value_initialized<account_public_address>()),
|
m_miner_address(boost::value_initialized<account_public_address>()),
|
||||||
m_starter_message_showed(false),
|
m_starter_message_showed(false),
|
||||||
|
@ -577,7 +581,11 @@ namespace cryptonote
|
||||||
m_starter_message_showed = true;
|
m_starter_message_showed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if BLOCKCHAIN_DB == DB_LMDB
|
||||||
m_store_blockchain_interval.do_call(boost::bind(&Blockchain::store_blockchain, &m_blockchain_storage));
|
m_store_blockchain_interval.do_call(boost::bind(&Blockchain::store_blockchain, &m_blockchain_storage));
|
||||||
|
#else
|
||||||
|
m_store_blockchain_interval.do_call(boost::bind(&blockchain_storage::store_blockchain, &m_blockchain_storage));
|
||||||
|
#endif
|
||||||
m_miner.on_idle();
|
m_miner.on_idle();
|
||||||
m_mempool.on_idle();
|
m_mempool.on_idle();
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -39,7 +39,11 @@
|
||||||
#include "cryptonote_protocol/cryptonote_protocol_handler_common.h"
|
#include "cryptonote_protocol/cryptonote_protocol_handler_common.h"
|
||||||
#include "storages/portable_storage_template_helper.h"
|
#include "storages/portable_storage_template_helper.h"
|
||||||
#include "tx_pool.h"
|
#include "tx_pool.h"
|
||||||
|
#if BLOCKCHAIN_DB == DB_LMDB
|
||||||
#include "blockchain.h"
|
#include "blockchain.h"
|
||||||
|
#else
|
||||||
|
#include "blockchain_storage.h"
|
||||||
|
#endif
|
||||||
#include "miner.h"
|
#include "miner.h"
|
||||||
#include "connection_context.h"
|
#include "connection_context.h"
|
||||||
#include "cryptonote_core/cryptonote_stat_info.h"
|
#include "cryptonote_core/cryptonote_stat_info.h"
|
||||||
|
@ -112,7 +116,11 @@ 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);
|
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 pause_mine();
|
||||||
void resume_mine();
|
void resume_mine();
|
||||||
|
#if BLOCKCHAIN_DB == DB_LMDB
|
||||||
Blockchain& get_blockchain_storage(){return m_blockchain_storage;}
|
Blockchain& get_blockchain_storage(){return m_blockchain_storage;}
|
||||||
|
#else
|
||||||
|
blockchain_storage& get_blockchain_storage(){return m_blockchain_storage;}
|
||||||
|
#endif
|
||||||
//debug functions
|
//debug functions
|
||||||
void print_blockchain(uint64_t start_index, uint64_t end_index);
|
void print_blockchain(uint64_t start_index, uint64_t end_index);
|
||||||
void print_blockchain_index();
|
void print_blockchain_index();
|
||||||
|
@ -149,7 +157,11 @@ namespace cryptonote
|
||||||
|
|
||||||
|
|
||||||
tx_memory_pool m_mempool;
|
tx_memory_pool m_mempool;
|
||||||
|
#if BLOCKCHAIN_DB == DB_LMDB
|
||||||
Blockchain m_blockchain_storage;
|
Blockchain m_blockchain_storage;
|
||||||
|
#else
|
||||||
|
blockchain_storage m_blockchain_storage;
|
||||||
|
#endif
|
||||||
i_cryptonote_protocol* m_pprotocol;
|
i_cryptonote_protocol* m_pprotocol;
|
||||||
epee::critical_section m_incoming_tx_lock;
|
epee::critical_section m_incoming_tx_lock;
|
||||||
//m_miner and m_miner_addres are probably temporary here
|
//m_miner and m_miner_addres are probably temporary here
|
||||||
|
|
|
@ -37,7 +37,11 @@
|
||||||
#include "cryptonote_format_utils.h"
|
#include "cryptonote_format_utils.h"
|
||||||
#include "cryptonote_boost_serialization.h"
|
#include "cryptonote_boost_serialization.h"
|
||||||
#include "cryptonote_config.h"
|
#include "cryptonote_config.h"
|
||||||
|
#if BLOCKCHAIN_DB == DB_LMDB
|
||||||
#include "blockchain.h"
|
#include "blockchain.h"
|
||||||
|
#else
|
||||||
|
#include "blockchain_storage.h"
|
||||||
|
#endif
|
||||||
#include "common/boost_serialization_helper.h"
|
#include "common/boost_serialization_helper.h"
|
||||||
#include "common/int-util.h"
|
#include "common/int-util.h"
|
||||||
#include "misc_language.h"
|
#include "misc_language.h"
|
||||||
|
@ -52,12 +56,19 @@ namespace cryptonote
|
||||||
{
|
{
|
||||||
size_t const TRANSACTION_SIZE_LIMIT = (((CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE * 125) / 100) - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE);
|
size_t const TRANSACTION_SIZE_LIMIT = (((CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE * 125) / 100) - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE);
|
||||||
}
|
}
|
||||||
|
//---------------------------------------------------------------------------------
|
||||||
|
#if BLOCKCHAIN_DB == DB_LMDB
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
tx_memory_pool::tx_memory_pool(Blockchain& bchs): m_blockchain(bchs)
|
tx_memory_pool::tx_memory_pool(Blockchain& bchs): m_blockchain(bchs)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
tx_memory_pool::tx_memory_pool(blockchain_storage& bchs): m_blockchain(bchs)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
//---------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------
|
||||||
bool tx_memory_pool::add_tx(const transaction &tx, /*const crypto::hash& tx_prefix_hash,*/ const crypto::hash &id, size_t blob_size, tx_verification_context& tvc, bool kept_by_block)
|
bool tx_memory_pool::add_tx(const transaction &tx, /*const crypto::hash& tx_prefix_hash,*/ const crypto::hash &id, size_t blob_size, tx_verification_context& tvc, bool kept_by_block)
|
||||||
{
|
{
|
||||||
|
|
|
@ -44,10 +44,13 @@
|
||||||
#include "verification_context.h"
|
#include "verification_context.h"
|
||||||
#include "crypto/hash.h"
|
#include "crypto/hash.h"
|
||||||
|
|
||||||
|
|
||||||
namespace cryptonote
|
namespace cryptonote
|
||||||
{
|
{
|
||||||
|
#if BLOCKCHAIN_DB == DB_LMDB
|
||||||
class Blockchain;
|
class Blockchain;
|
||||||
|
#else
|
||||||
|
class blockchain_storage;
|
||||||
|
#endif
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
/* */
|
/* */
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
@ -55,7 +58,11 @@ namespace cryptonote
|
||||||
class tx_memory_pool: boost::noncopyable
|
class tx_memory_pool: boost::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
#if BLOCKCHAIN_DB == DB_LMDB
|
||||||
tx_memory_pool(Blockchain& bchs);
|
tx_memory_pool(Blockchain& bchs);
|
||||||
|
#else
|
||||||
|
tx_memory_pool(blockchain_storage& bchs);
|
||||||
|
#endif
|
||||||
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, 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);
|
bool add_tx(const transaction &tx, tx_verification_context& tvc, bool keeped_by_block);
|
||||||
//gets tx and remove it from pool
|
//gets tx and remove it from pool
|
||||||
|
@ -127,7 +134,11 @@ namespace cryptonote
|
||||||
//transactions_container m_alternative_transactions;
|
//transactions_container m_alternative_transactions;
|
||||||
|
|
||||||
std::string m_config_folder;
|
std::string m_config_folder;
|
||||||
|
#if BLOCKCHAIN_DB == DB_LMDB
|
||||||
Blockchain& m_blockchain;
|
Blockchain& m_blockchain;
|
||||||
|
#else
|
||||||
|
blockchain_storage& m_blockchain;
|
||||||
|
#endif
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
/* */
|
/* */
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
@ -170,6 +181,12 @@ namespace cryptonote
|
||||||
uint64_t operator()(const txin_to_scripthash& tx) const {return 0;}
|
uint64_t operator()(const txin_to_scripthash& tx) const {return 0;}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if BLOCKCHAIN_DB == DB_LMDB
|
||||||
|
#else
|
||||||
|
#if defined(DEBUG_CREATE_BLOCK_TEMPLATE)
|
||||||
|
friend class blockchain_storage;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue