447 available_dbs =
"available: " + available_dbs;
453 boost::filesystem::path output_file_path;
455 po::options_description desc_cmd_only(
"Command line options");
456 po::options_description desc_cmd_sett(
"Command line options and settings options");
459 "database", available_dbs.c_str(), default_db_type
463 ,
"Specify sync option, using format [safe|fast|fastest]:[nrecords_per_sync]." 477 po::options_description desc_options(
"Allowed options");
478 desc_options.add(desc_cmd_only).add(desc_cmd_sett);
480 po::variables_map vm;
483 auto parser = po::command_line_parser(argc, argv).options(desc_options);
484 po::store(parser.run(), vm);
494 std::cout << desc_options << std::endl;
504 MINFO(
"Starting...");
517 MERROR(
"Invalid database type: " << db_type);
520 if (db_type !=
"lmdb")
522 MERROR(
"Unsupported database type: " << db_type <<
". Only lmdb is supported");
528 if (!parse_db_sync_mode(db_sync_mode, db_flags))
530 MERROR(
"Invalid db sync mode: " << db_sync_mode);
545 MINFO(
"Initializing source blockchain (BlockchainDB)");
546 std::array<std::unique_ptr<Blockchain>, 2> core_storage;
549 boost::filesystem::path paths[2];
550 bool already_pruned =
false;
551 for (
size_t n = 0; n < core_storage.size(); ++n)
553 core_storage[n].reset(
new Blockchain(m_mempool));
558 MERROR(
"Attempted to use non-existent database type: " << db_type);
559 throw std::runtime_error(
"Attempting to use non-existent database type");
561 MDEBUG(
"database: " << db_type);
566 if (boost::filesystem::exists(paths[1]))
568 if (!boost::filesystem::is_directory(paths[1]))
570 MERROR(
"LMDB needs a directory path, but a file was passed: " << paths[1].
string());
576 if (!boost::filesystem::create_directories(paths[1]))
578 MERROR(
"Failed to create directory: " << paths[1].
string());
582 db_path = paths[1].string();
589 MINFO(
"Loading blockchain from folder " << paths[n] <<
" ...");
595 catch (
const std::exception& e)
597 MERROR(
"Error opening database: " << e.what());
600 r = core_storage[n]->init(db, net_type);
602 std::string source_dest = n == 0 ?
"source" :
"pruned";
604 MINFO(source_dest <<
" blockchain storage initialized OK");
605 if (n == 0 && core_storage[0]->get_blockchain_pruning_seed())
607 if (!opt_copy_pruned_database)
609 MERROR(
"Blockchain is already pruned, use --" << arg_copy_pruned_database.name <<
" to copy it anyway");
612 already_pruned =
true;
615 core_storage[0]->deinit();
616 core_storage[0].reset(NULL);
617 core_storage[1]->deinit();
618 core_storage[1].reset(NULL);
621 MDB_env *env0 = NULL, *env1 = NULL;
622 open(env0, paths[0], db_flags,
true);
623 open(env1, paths[1], db_flags,
false);
636 copy_table(env0, env1,
"txpool_meta", 0,
MDB_NODUPDATA, BlockchainLMDB::compare_hash32);
637 copy_table(env0, env1,
"txpool_blob", 0,
MDB_NODUPDATA, BlockchainLMDB::compare_hash32);
639 copy_table(env0, env1,
"properties", 0, 0, BlockchainLMDB::compare_string);
652 MINFO(
"Swapping databases, pre-pruning blockchain will be left in " << paths[0].
string() +
"-old and can be removed if desired");
653 if (replace_file(paths[0].
string(), paths[0].
string() +
"-old") || replace_file(paths[1].
string(), paths[0].
string()))
655 MERROR(
"Blockchain pruned OK, but renaming failed");
659 MINFO(
"Blockchain pruned OK");
const char *const ELECTRONEUM_RELEASE_NAME
virtual std::string get_db_name() const =0
gets the name of the folder the BlockchainDB's file(s) should be in
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
void mlog_set_log(const char *log)
#define CATCH_ENTRY(location, return_val)
std::string mlog_get_default_log_path(const char *default_filename)
void mlog_configure(const std::string &filename_base, bool console, const std::size_t max_log_file_size=MAX_LOG_FILE_SIZE, const std::size_t max_log_files=MAX_LOG_FILES)
const command_line::arg_descriptor< std::string > arg_db_sync_mode
const command_line::arg_descriptor< bool, false > arg_stagenet_on
const arg_descriptor< bool > arg_help
std::string blockchain_db_types(const std::string &sep)
struct MDB_env MDB_env
Opaque structure for a database environment.
boost::filesystem::path data_dir
virtual void open(const std::string &filename, const int db_flags=0)=0
open a db, or create it if necessary.
const char *const ELECTRONEUM_VERSION_FULL
bool blockchain_valid_db_type(const std::string &db_type)
const command_line::arg_descriptor< bool, false > arg_testnet_on
BlockchainDB * new_db(const std::string &db_type)
bool handle_error_helper(const boost::program_options::options_description &desc, F parser)
const command_line::arg_descriptor< std::string > arg_log_level
unsigned __int64 uint64_t
const command_line::arg_descriptor< std::string, false, true, 2 > arg_data_dir
void add_arg(boost::program_options::options_description &description, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg, bool unique=true)
Transaction pool, handles transactions which are not part of a block.
The BlockchainDB backing store interface declaration/contract.
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
std::string to_string(t_connection_type type)
int compare_uint64(const MDB_val *a, const MDB_val *b)
bool is_arg_defaulted(const boost::program_options::variables_map &vm, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg)