From 87d57d9c595b451eff6062a1189d07dbadece72e Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 5 Mar 2017 19:24:47 +0000 Subject: [PATCH 1/5] blockchain_export: error out nicely on exceptions --- src/blockchain_utilities/blockchain_export.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/blockchain_utilities/blockchain_export.cpp b/src/blockchain_utilities/blockchain_export.cpp index 269710ee1..b45f36771 100644 --- a/src/blockchain_utilities/blockchain_export.cpp +++ b/src/blockchain_utilities/blockchain_export.cpp @@ -57,6 +57,8 @@ std::string join_set_strings(const std::unordered_set& db_types_all int main(int argc, char* argv[]) { + TRY_ENTRY(); + epee::string_tools::set_module_name_and_folder(argv[0]); std::string default_db_type = "lmdb"; @@ -226,4 +228,7 @@ int main(int argc, char* argv[]) } CHECK_AND_ASSERT_MES(r, false, "Failed to export blockchain raw data"); LOG_PRINT_L0("Blockchain raw data exported OK"); + return 0; + + CATCH_ENTRY("Export error", 1); } From 50ebf661509bddaeecf44a8a61eb835b0f3f6515 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 5 Mar 2017 19:25:01 +0000 Subject: [PATCH 2/5] blockchain_import: error out nicely on exceptions --- src/blockchain_utilities/blockchain_import.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/blockchain_utilities/blockchain_import.cpp b/src/blockchain_utilities/blockchain_import.cpp index 83fd6fb20..66dd0b136 100644 --- a/src/blockchain_utilities/blockchain_import.cpp +++ b/src/blockchain_utilities/blockchain_import.cpp @@ -596,6 +596,8 @@ int import_from_file(FakeCore& simple_core, const std::string& import_file_path, int main(int argc, char* argv[]) { + TRY_ENTRY(); + epee::string_tools::set_module_name_and_folder(argv[0]); std::string default_db_type = "lmdb"; @@ -852,4 +854,6 @@ int main(int argc, char* argv[]) // calls delete on its BlockchainDB derived class' object, which closes its // files. return 0; + + CATCH_ENTRY("Import error", 1); } From 5fee85616d408dd2e30c3aa104c4c24566a6f480 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 5 Mar 2017 19:45:00 +0000 Subject: [PATCH 3/5] blockchain_export: make --log-level understand categories --- src/blockchain_utilities/blockchain_export.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/blockchain_utilities/blockchain_export.cpp b/src/blockchain_utilities/blockchain_export.cpp index b45f36771..f145bc107 100644 --- a/src/blockchain_utilities/blockchain_export.cpp +++ b/src/blockchain_utilities/blockchain_export.cpp @@ -82,7 +82,7 @@ int main(int argc, char* argv[]) po::options_description desc_cmd_only("Command line options"); po::options_description desc_cmd_sett("Command line options and settings options"); const command_line::arg_descriptor arg_output_file = {"output-file", "Specify output file", "", true}; - const command_line::arg_descriptor arg_log_level = {"log-level", "", log_level}; + const command_line::arg_descriptor arg_log_level = {"log-level", "0-4 or categories", ""}; const command_line::arg_descriptor arg_block_stop = {"block-stop", "Stop at block number", block_stop}; const command_line::arg_descriptor arg_testnet_on = { "testnet" @@ -126,11 +126,13 @@ int main(int argc, char* argv[]) return 1; } - log_level = command_line::get_arg(vm, arg_log_level); + mlog_configure(mlog_get_default_log_path("monero-blockchain-export.log"), true); + if (!vm["log-level"].defaulted()) + mlog_set_log(command_line::get_arg(vm, arg_log_level).c_str()); + else + mlog_set_log(std::string(std::to_string(log_level) + ",bcutil:INFO").c_str()); block_stop = command_line::get_arg(vm, arg_block_stop); - mlog_configure(mlog_get_default_log_path("monero-blockchain-export.log"), true); - mlog_set_log(std::string(std::to_string(log_level) + ",bcutil:INFO").c_str()); LOG_PRINT_L0("Starting..."); bool opt_testnet = command_line::get_arg(vm, arg_testnet_on); From 38359036503d7159e7993d9f94c7d1e9afa62d02 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 5 Mar 2017 19:45:22 +0000 Subject: [PATCH 4/5] blockchain_import: make --log-level understand categories --- src/blockchain_utilities/blockchain_import.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/blockchain_utilities/blockchain_import.cpp b/src/blockchain_utilities/blockchain_import.cpp index 66dd0b136..b2c217ca1 100644 --- a/src/blockchain_utilities/blockchain_import.cpp +++ b/src/blockchain_utilities/blockchain_import.cpp @@ -624,7 +624,7 @@ int main(int argc, char* argv[]) po::options_description desc_cmd_only("Command line options"); po::options_description desc_cmd_sett("Command line options and settings options"); const command_line::arg_descriptor arg_input_file = {"input-file", "Specify input file", "", true}; - const command_line::arg_descriptor arg_log_level = {"log-level", "", log_level}; + const command_line::arg_descriptor arg_log_level = {"log-level", "0-4 or categories", ""}; const command_line::arg_descriptor arg_block_stop = {"block-stop", "Stop at block number", block_stop}; const command_line::arg_descriptor arg_batch_size = {"batch-size", "", db_batch_size}; const command_line::arg_descriptor arg_pop_blocks = {"pop-blocks", "Remove blocks from end of blockchain", num_blocks}; @@ -684,7 +684,6 @@ int main(int argc, char* argv[]) if (! r) return 1; - log_level = command_line::get_arg(vm, arg_log_level); opt_verify = command_line::get_arg(vm, arg_verify); opt_batch = command_line::get_arg(vm, arg_batch); opt_resume = command_line::get_arg(vm, arg_resume); @@ -727,7 +726,11 @@ int main(int argc, char* argv[]) db_arg_str = command_line::get_arg(vm, arg_database); mlog_configure(mlog_get_default_log_path("monero-blockchain-import.log"), true); - mlog_set_log(std::string(std::to_string(log_level) + ",bcutil:INFO").c_str()); + if (!vm["log-level"].defaulted()) + mlog_set_log(command_line::get_arg(vm, arg_log_level).c_str()); + else + mlog_set_log(std::string(std::to_string(log_level) + ",bcutil:INFO").c_str()); + MINFO("Starting..."); boost::filesystem::path fs_import_file_path; From cfa2564a40fc3ecee7bae718ef5c68a9f093c15e Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 5 Mar 2017 19:46:01 +0000 Subject: [PATCH 5/5] blockchain: don't try to load an empty block hash set If the blocks aren't being linked against a binary (such as one of the blockchain utilities), the symbol will not be NULL, but the size will be 0. This avoids a apurious warning about the data hash. --- src/cryptonote_core/blockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index f49050918..0713274a6 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -4016,7 +4016,7 @@ void Blockchain::cancel() static const char expected_block_hashes_hash[] = "23d8a8c73de7b2383c72a016d9a6034e69d62dd48077d1c414e064ceab6daa94"; void Blockchain::load_compiled_in_block_hashes() { - if (m_fast_sync && get_blocks_dat_start(m_testnet) != nullptr) + if (m_fast_sync && get_blocks_dat_start(m_testnet) != nullptr && get_blocks_dat_size(m_testnet) > 0) { MINFO("Loading precomputed blocks (" << get_blocks_dat_size(m_testnet) << " bytes)");