forked from lthn/blockchain
db_backend_selector is used only locally to make things simplier
This commit is contained in:
parent
0b6b30b01c
commit
6bd9a73448
9 changed files with 40 additions and 37 deletions
|
|
@ -28,8 +28,12 @@ namespace tools
|
|||
#endif
|
||||
|
||||
template<class callback_t>
|
||||
bool process_predownload(const boost::program_options::variables_map& vm, callback_t cb_should_stop, db::db_backend_selector& dbbs)
|
||||
bool process_predownload(const boost::program_options::variables_map& vm, callback_t cb_should_stop)
|
||||
{
|
||||
tools::db::db_backend_selector dbbs;
|
||||
bool r = dbbs.init(vm);
|
||||
CHECK_AND_ASSERT_MES(r, false, "db_backend_selector failed to initialize");
|
||||
|
||||
std::string config_folder = dbbs.get_config_folder();
|
||||
std::string working_folder = dbbs.get_db_folder_path();
|
||||
std::string db_main_file_path = working_folder + "/" + dbbs.get_db_main_file_name();
|
||||
|
|
@ -80,7 +84,7 @@ namespace tools
|
|||
};
|
||||
|
||||
tools::create_directories_if_necessary(working_folder);
|
||||
bool r = cl.download_and_unzip(cb, downloading_file_path, url, 1000 /* timout */, "GET", std::string(), 3 /* fails count */);
|
||||
r = cl.download_and_unzip(cb, downloading_file_path, url, 1000 /* timout */, "GET", std::string(), 3 /* fails count */);
|
||||
if (!r)
|
||||
{
|
||||
LOG_PRINT_RED("Download failed", LOG_LEVEL_0);
|
||||
|
|
@ -157,11 +161,7 @@ namespace tools
|
|||
source_core_vm.insert(std::make_pair("db-engine", boost::program_options::variable_value(dbbs.get_engine_name(), false)));
|
||||
//source_core_vm.insert(std::make_pair("db-sync-mode", boost::program_options::variable_value(std::string("fast"), false)));
|
||||
|
||||
db::db_backend_selector source_core_dbbs;
|
||||
r = source_core_dbbs.init(source_core_vm);
|
||||
CHECK_AND_ASSERT_MES(r, false, "failed to init source_core_dbbs");
|
||||
|
||||
r = source_core.init(source_core_vm, source_core_dbbs);
|
||||
r = source_core.init(source_core_vm);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to init source core");
|
||||
|
||||
// target core
|
||||
|
|
@ -170,11 +170,7 @@ namespace tools
|
|||
target_core_vm.insert(std::make_pair("db-engine", boost::program_options::variable_value(dbbs.get_engine_name(), false)));
|
||||
//vm_with_fast_sync.insert(std::make_pair("db-sync-mode", boost::program_options::variable_value(std::string("fast"), false)));
|
||||
|
||||
db::db_backend_selector target_core_dbbs;
|
||||
r = target_core_dbbs.init(target_core_vm);
|
||||
CHECK_AND_ASSERT_MES(r, false, "failed to init target_core_dbbs");
|
||||
|
||||
r = target_core.init(target_core_vm, target_core_dbbs);
|
||||
r = target_core.init(target_core_vm);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to init target core");
|
||||
|
||||
CHECK_AND_ASSERT_MES(target_core.get_top_block_height() == 0, false, "Target blockchain initialized not empty");
|
||||
|
|
|
|||
|
|
@ -202,9 +202,12 @@ bool blockchain_storage::validate_instance(const std::string& path)
|
|||
}
|
||||
}
|
||||
//------------------------------------------------------------------
|
||||
bool blockchain_storage::init(const std::string& config_folder, const boost::program_options::variables_map& vm, tools::db::db_backend_selector& dbbs)
|
||||
bool blockchain_storage::init(const std::string& config_folder, const boost::program_options::variables_map& vm)
|
||||
{
|
||||
// CRITICAL_REGION_LOCAL(m_read_lock);
|
||||
|
||||
tools::db::db_backend_selector dbbs;
|
||||
dbbs.init(vm);
|
||||
auto p_backend = dbbs.create_backend();
|
||||
if (!p_backend)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -177,8 +177,8 @@ namespace currency
|
|||
~blockchain_storage();
|
||||
|
||||
|
||||
bool init(const boost::program_options::variables_map& vm, tools::db::db_backend_selector& dbbs) { return init(tools::get_default_data_dir(), vm, dbbs); }
|
||||
bool init(const std::string& config_folder, const boost::program_options::variables_map& vm, tools::db::db_backend_selector& dbbs);
|
||||
bool init(const boost::program_options::variables_map& vm) { return init(tools::get_default_data_dir(), vm); }
|
||||
bool init(const std::string& config_folder, const boost::program_options::variables_map& vm);
|
||||
bool deinit();
|
||||
static void init_options(boost::program_options::options_description& desc);
|
||||
|
||||
|
|
|
|||
|
|
@ -136,17 +136,17 @@ namespace currency
|
|||
return m_blockchain_storage.get_alternative_blocks_count();
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
bool core::init(const boost::program_options::variables_map& vm, tools::db::db_backend_selector& dbbs)
|
||||
bool core::init(const boost::program_options::variables_map& vm)
|
||||
{
|
||||
bool r = handle_command_line(vm);
|
||||
|
||||
uint64_t available_space = 0;
|
||||
CHECK_AND_ASSERT_MES(!check_if_free_space_critically_low(&available_space), false, "free space in data folder is critically low: " << std::fixed << available_space / (1024 * 1024) << " MB");
|
||||
|
||||
r = m_mempool.init(m_config_folder, vm, dbbs);
|
||||
r = m_mempool.init(m_config_folder, vm);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to initialize memory pool");
|
||||
|
||||
r = m_blockchain_storage.init(m_config_folder, vm, dbbs);
|
||||
r = m_blockchain_storage.init(m_config_folder, vm);
|
||||
CHECK_AND_ASSERT_MES(r, false, "Failed to initialize blockchain storage");
|
||||
|
||||
r = m_miner.init(vm);
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@
|
|||
#include "currency_core/currency_stat_info.h"
|
||||
#include "warnings.h"
|
||||
#include "crypto/hash.h"
|
||||
#include "common/db_backend_selector.h"
|
||||
|
||||
PUSH_VS_WARNINGS
|
||||
DISABLE_VS_WARNINGS(4355)
|
||||
|
|
@ -60,7 +59,7 @@ namespace currency
|
|||
|
||||
miner& get_miner(){ return m_miner; }
|
||||
static void init_options(boost::program_options::options_description& desc);
|
||||
bool init(const boost::program_options::variables_map& vm, tools::db::db_backend_selector& dbbs);
|
||||
bool init(const boost::program_options::variables_map& vm);
|
||||
bool set_genesis_block(const block& b);
|
||||
bool deinit();
|
||||
uint64_t get_current_blockchain_size() const;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
#include "warnings.h"
|
||||
#include "crypto/hash.h"
|
||||
#include "profile_tools.h"
|
||||
#include "common/db_backend_selector.h"
|
||||
|
||||
DISABLE_VS_WARNINGS(4244 4345 4503) //'boost::foreach_detail_::or_' : decorated name length exceeded, name was truncated
|
||||
|
||||
|
|
@ -1161,8 +1162,10 @@ namespace currency
|
|||
m_db.commit_transaction();
|
||||
}
|
||||
//---------------------------------------------------------------------------------
|
||||
bool tx_memory_pool::init(const std::string& config_folder, const boost::program_options::variables_map& vm, tools::db::db_backend_selector& dbbs)
|
||||
bool tx_memory_pool::init(const std::string& config_folder, const boost::program_options::variables_map& vm)
|
||||
{
|
||||
tools::db::db_backend_selector dbbs;
|
||||
dbbs.init(vm);
|
||||
auto p_backend = dbbs.create_backend();
|
||||
if (!p_backend)
|
||||
{
|
||||
|
|
@ -1185,7 +1188,7 @@ namespace currency
|
|||
boost::filesystem::remove_all(epee::string_encoding::utf8_to_wstring(old_db_folder_path));
|
||||
}
|
||||
|
||||
const std::string db_folder_path = m_config_folder + ("/" CURRENCY_POOLDATA_FOLDERNAME_PREFIX) + m_db.get_backend()->name() + CURRENCY_POOLDATA_FOLDERNAME_SUFFIX;
|
||||
const std::string db_folder_path = dbbs.get_pool_db_folder_path();
|
||||
|
||||
LOG_PRINT_L0("Loading blockchain from " << db_folder_path << "...");
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ using namespace epee;
|
|||
#include "crypto/hash.h"
|
||||
#include "common/boost_serialization_helper.h"
|
||||
#include "currency_protocol/currency_protocol_handler_common.h"
|
||||
#include "common/db_backend_selector.h"
|
||||
|
||||
namespace currency
|
||||
{
|
||||
|
|
@ -117,7 +116,7 @@ namespace currency
|
|||
void clear();
|
||||
|
||||
// load/store operations
|
||||
bool init(const std::string& config_folder, const boost::program_options::variables_map& vm, tools::db::db_backend_selector& dbbs);
|
||||
bool init(const std::string& config_folder, const boost::program_options::variables_map& vm);
|
||||
bool deinit();
|
||||
bool fill_block_template(block &bl, bool pos, size_t median_size, const boost::multiprecision::uint128_t& already_generated_coins, size_t &total_size, uint64_t &fee, uint64_t height, const std::list<transaction>& explicit_txs);
|
||||
bool get_transactions(std::list<transaction>& txs) const;
|
||||
|
|
|
|||
|
|
@ -246,8 +246,6 @@ int main(int argc, char* argv[])
|
|||
command_line::get_arg(vm, command_line::arg_disable_stop_on_low_free_space));
|
||||
ccore.set_critical_error_handler(&cceh);
|
||||
|
||||
tools::db::db_backend_selector dbbs;
|
||||
|
||||
|
||||
if (command_line::get_arg(vm, command_line::arg_enable_offers_service))
|
||||
{
|
||||
|
|
@ -279,16 +277,20 @@ int main(int argc, char* argv[])
|
|||
}
|
||||
|
||||
bool res = false;
|
||||
res = dbbs.init(vm);
|
||||
CHECK_AND_ASSERT_MES(res, EXIT_FAILURE, "db_backend_selector failed to initialize");
|
||||
|
||||
//do pre_download if needed
|
||||
if (!command_line::has_arg(vm, command_line::arg_no_predownload) || command_line::has_arg(vm, command_line::arg_explicit_predownload))
|
||||
{
|
||||
tools::process_predownload(vm, [&](uint64_t total_bytes, uint64_t received_bytes){
|
||||
return static_cast<nodetool::i_p2p_endpoint<currency::t_currency_protocol_handler<currency::core>::connection_context> *>(&p2psrv)->is_stop_signal_sent();
|
||||
}, dbbs);
|
||||
if (static_cast<nodetool::i_p2p_endpoint<currency::t_currency_protocol_handler<currency::core>::connection_context>*>(&p2psrv)->is_stop_signal_sent())
|
||||
auto is_stop_signal_sent = [&p2psrv]() -> bool {
|
||||
return static_cast<nodetool::i_p2p_endpoint<currency::t_currency_protocol_handler<currency::core>::connection_context>*>(&p2psrv)->is_stop_signal_sent();
|
||||
};
|
||||
|
||||
if (!tools::process_predownload(vm, [&](uint64_t total_bytes, uint64_t received_bytes) { return is_stop_signal_sent(); }))
|
||||
{
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (is_stop_signal_sent())
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -319,7 +321,7 @@ int main(int argc, char* argv[])
|
|||
|
||||
//initialize core here
|
||||
LOG_PRINT_L0("Initializing core...");
|
||||
res = ccore.init(vm, dbbs);
|
||||
res = ccore.init(vm);
|
||||
CHECK_AND_ASSERT_MES(res, 1, "Failed to initialize core");
|
||||
LOG_PRINT_L0("Core initialized OK");
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
#include "string_coding.h"
|
||||
#include "wallet_helpers.h"
|
||||
#include "core_default_rpc_proxy.h"
|
||||
#include "common/db_backend_selector.h"
|
||||
|
||||
#define GET_WALLET_OPT_BY_ID(wallet_id, name) \
|
||||
CRITICAL_REGION_LOCAL(m_wallets_lock); \
|
||||
|
|
@ -317,15 +318,15 @@ bool wallets_manager::init_local_daemon()
|
|||
dsi.daemon_network_state = currency::COMMAND_RPC_GET_INFO::daemon_network_state_loading_core;
|
||||
m_pview->update_daemon_status(dsi);
|
||||
|
||||
tools::db::db_backend_selector dbbs;
|
||||
bool res = dbbs.init(m_vm);
|
||||
CHECK_AND_ASSERT_AND_SET_GUI(res, "Failed to initialize db_backend_selector");
|
||||
//tools::db::db_backend_selector dbbs;
|
||||
//bool res = dbbs.init(m_vm);
|
||||
//CHECK_AND_ASSERT_AND_SET_GUI(res, "Failed to initialize db_backend_selector");
|
||||
|
||||
//initialize core here
|
||||
LOG_PRINT_L0("Initializing core...");
|
||||
//dsi.text_state = "Initializing core";
|
||||
m_pview->update_daemon_status(dsi);
|
||||
res = m_ccore.init(m_vm, dbbs);
|
||||
bool res = m_ccore.init(m_vm);
|
||||
CHECK_AND_ASSERT_AND_SET_GUI(res, "Failed to initialize core");
|
||||
LOG_PRINT_L0("Core initialized OK");
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue