From dc5b5f72a31bfdc8d89693ad4276e5ddf60d3c6f Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Mon, 24 Mar 2025 03:09:29 +0400 Subject: [PATCH] moved to v3 db --- src/common/db_backend_selector.cpp | 13 ++++++++++++ src/common/db_backend_selector.h | 3 +++ src/currency_core/blockchain_storage.cpp | 27 ++++++++++++++++++------ src/currency_core/blockchain_storage.h | 2 +- src/currency_core/currency_config.h | 6 +++++- 5 files changed, 43 insertions(+), 8 deletions(-) diff --git a/src/common/db_backend_selector.cpp b/src/common/db_backend_selector.cpp index 9c7917ca..33f1382f 100644 --- a/src/common/db_backend_selector.cpp +++ b/src/common/db_backend_selector.cpp @@ -67,6 +67,19 @@ namespace db return m_config_folder + ("/" CURRENCY_BLOCKCHAINDATA_FOLDERNAME_PREFIX) + get_engine_name() + CURRENCY_BLOCKCHAINDATA_FOLDERNAME_SUFFIX; } + std::string db_backend_selector::get_db_folder_path_old_1() const + { + //CHECK_AND_ASSERT_THROW_MES(m_engine_type != db_none, "db_backend_selector was no inited"); + return m_config_folder + ("/" CURRENCY_BLOCKCHAINDATA_FOLDERNAME_PREFIX) + get_engine_name() + CURRENCY_BLOCKCHAINDATA_FOLDERNAME_SUFFIX_OLD_1; + } + + std::string db_backend_selector::get_db_folder_path_old_2() const + { + //CHECK_AND_ASSERT_THROW_MES(m_engine_type != db_none, "db_backend_selector was no inited"); + return m_config_folder + ("/" CURRENCY_BLOCKCHAINDATA_FOLDERNAME_PREFIX) + get_engine_name() + CURRENCY_BLOCKCHAINDATA_FOLDERNAME_SUFFIX_OLD_2; + } + + std::string db_backend_selector::get_temp_db_folder_path() const { //CHECK_AND_ASSERT_THROW_MES(m_engine_type != db_none, "db_backend_selector was no inited"); diff --git a/src/common/db_backend_selector.h b/src/common/db_backend_selector.h index b9d811b8..54c4a10a 100644 --- a/src/common/db_backend_selector.h +++ b/src/common/db_backend_selector.h @@ -34,6 +34,9 @@ namespace tools std::shared_ptr create_backend(); + std::string get_db_folder_path_old_1() const; + std::string get_db_folder_path_old_2() const; + private: db_engine_type m_engine_type; std::string m_config_folder; diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index a033e3de..6c541583 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -220,6 +220,23 @@ void blockchain_storage::set_db_l2_cache_size(uint64_t ceched_elements) const m_db_assets.set_cache_size(ceched_elements); m_db_addr_to_alias.set_cache_size(ceched_elements); } + +void remove_old_db(const std::string old_db_folder_path) +{ + try { + if (boost::filesystem::exists(epee::string_encoding::utf8_to_wstring(old_db_folder_path))) + { + LOG_PRINT_YELLOW("Removing old DB in " << old_db_folder_path << "...", LOG_LEVEL_0); + boost::filesystem::remove_all(epee::string_encoding::utf8_to_wstring(old_db_folder_path)); + } + } + catch (...) + { + + } +} + + bool blockchain_storage::init(const std::string& config_folder, const boost::program_options::variables_map& vm) { // CRITICAL_REGION_LOCAL(m_read_lock); @@ -251,12 +268,10 @@ bool blockchain_storage::init(const std::string& config_folder, const boost::pro m_config_folder = config_folder; // remove old incompatible DB - const std::string old_db_folder_path = m_config_folder + "/" CURRENCY_BLOCKCHAINDATA_FOLDERNAME_OLD; - if (boost::filesystem::exists(epee::string_encoding::utf8_to_wstring(old_db_folder_path))) - { - LOG_PRINT_YELLOW("Removing old DB in " << old_db_folder_path << "...", LOG_LEVEL_0); - boost::filesystem::remove_all(epee::string_encoding::utf8_to_wstring(old_db_folder_path)); - } + std::string old_db_folder_path = m_config_folder + "/" CURRENCY_BLOCKCHAINDATA_FOLDERNAME_OLD; + remove_old_db(old_db_folder_path); + remove_old_db(dbbs.get_db_folder_path_old_1()); + remove_old_db(dbbs.get_db_folder_path_old_2()); const std::string db_folder_path = dbbs.get_db_folder_path(); LOG_PRINT_L0("Loading blockchain from " << db_folder_path); diff --git a/src/currency_core/blockchain_storage.h b/src/currency_core/blockchain_storage.h index 40860074..035fd400 100644 --- a/src/currency_core/blockchain_storage.h +++ b/src/currency_core/blockchain_storage.h @@ -722,7 +722,7 @@ namespace currency bool is_output_allowed_for_input(const txout_to_key& out_v, const txin_v& in_v) const; bool is_output_allowed_for_input(const txout_htlc& out_v, const txin_v& in_v, uint64_t top_minus_source_height) const; bool is_output_allowed_for_input(const tx_out_zarcanum& out, const txin_v& in_v) const; - + void remove_old_dbs(); //POS diff --git a/src/currency_core/currency_config.h b/src/currency_core/currency_config.h index bf0b901b..5ab8c014 100644 --- a/src/currency_core/currency_config.h +++ b/src/currency_core/currency_config.h @@ -232,7 +232,11 @@ #define CURRENCY_POOLDATA_FOLDERNAME_PREFIX "poolstate_" #define CURRENCY_POOLDATA_FOLDERNAME_SUFFIX "_v1" #define CURRENCY_BLOCKCHAINDATA_FOLDERNAME_PREFIX "blockchain_" -#define CURRENCY_BLOCKCHAINDATA_FOLDERNAME_SUFFIX "_v2" +#define CURRENCY_BLOCKCHAINDATA_FOLDERNAME_SUFFIX "_v3" + +#define CURRENCY_BLOCKCHAINDATA_FOLDERNAME_SUFFIX_OLD_1 "_v1" +#define CURRENCY_BLOCKCHAINDATA_FOLDERNAME_SUFFIX_OLD_2 "_v2" + #define P2P_NET_DATA_FILENAME "p2pstate.bin" #define MINER_CONFIG_FILENAME "miner_conf.json"