From 4066de04a1c6356e9874434a95dba46290512ed2 Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 10 May 2022 17:29:42 +0200 Subject: [PATCH 01/19] epee: clean up the mess with namespace misc_utils::parse + string tools --- .../storages/portable_storage_from_json.h | 21 +++++++++---------- contrib/epee/include/string_tools.h | 16 ++------------ 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/contrib/epee/include/storages/portable_storage_from_json.h b/contrib/epee/include/storages/portable_storage_from_json.h index 4e74fb7a..fa76cc9b 100644 --- a/contrib/epee/include/storages/portable_storage_from_json.h +++ b/contrib/epee/include/storages/portable_storage_from_json.h @@ -30,7 +30,6 @@ namespace epee { - using namespace misc_utils::parse; namespace serialization { namespace json @@ -86,7 +85,7 @@ namespace epee switch(*it) { case '"': - match_string2(it, buf_end, name); + misc_utils::parse::match_string2(it, buf_end, name); state = match_state_waiting_separator; break; case '}': @@ -107,7 +106,7 @@ namespace epee if(*it == '"') {//just a named string value started std::string val; - match_string2(it, buf_end, val); + misc_utils::parse::match_string2(it, buf_end, val); //insert text value stg.set_value(name, val, current_section); state = match_state_wonder_after_value; @@ -115,7 +114,7 @@ namespace epee {//just a named number value started std::string val; bool is_v_float = false;bool is_signed = false; - match_number2(it, buf_end, val, is_v_float, is_signed); + misc_utils::parse::match_number2(it, buf_end, val, is_v_float, is_signed); if(!is_v_float) { if(is_signed) @@ -136,7 +135,7 @@ namespace epee }else if(isalpha(*it) ) {// could be null, true or false std::string word; - match_word2(it, buf_end, word); + misc_utils::parse::match_word2(it, buf_end, word); if(boost::iequals(word, "null")) { state = match_state_wonder_after_value; @@ -191,7 +190,7 @@ namespace epee { //mean array of strings std::string val; - match_string2(it, buf_end, val); + misc_utils::parse::match_string2(it, buf_end, val); h_array = stg.insert_first_value(name, val, current_section); CHECK_AND_ASSERT_THROW_MES(h_array, " failed to insert values entry"); state = match_state_array_after_value; @@ -200,7 +199,7 @@ namespace epee {//array of numbers value started std::string val; bool is_v_float = false;bool is_signed_val = false; - match_number2(it, buf_end, val, is_v_float, is_signed_val); + misc_utils::parse::match_number2(it, buf_end, val, is_v_float, is_signed_val); if(!is_v_float) { int64_t nval = boost::lexical_cast(val);//bool res = string_tools::string_to_num_fast(val, nval); @@ -222,7 +221,7 @@ namespace epee }else if(isalpha(*it) ) {// array of booleans std::string word; - match_word2(it, buf_end, word); + misc_utils::parse::match_word2(it, buf_end, word); if(boost::iequals(word, "true")) { h_array = stg.insert_first_value(name, true, current_section); @@ -266,7 +265,7 @@ namespace epee if(*it == '"') { std::string val; - match_string2(it, buf_end, val); + misc_utils::parse::match_string2(it, buf_end, val); bool res = stg.insert_next_value(h_array, val); CHECK_AND_ASSERT_THROW_MES(res, "failed to insert values"); state = match_state_array_after_value; @@ -277,7 +276,7 @@ namespace epee {//array of numbers value started std::string val; bool is_v_float = false;bool is_signed_val = false; - match_number2(it, buf_end, val, is_v_float, is_signed_val); + misc_utils::parse::match_number2(it, buf_end, val, is_v_float, is_signed_val); bool insert_res = false; if(!is_v_float) { @@ -299,7 +298,7 @@ namespace epee if(isalpha(*it) ) {// array of booleans std::string word; - match_word2(it, buf_end, word); + misc_utils::parse::match_word2(it, buf_end, word); if(boost::iequals(word, "true")) { bool r = stg.insert_next_value(h_array, true); diff --git a/contrib/epee/include/string_tools.h b/contrib/epee/include/string_tools.h index 95a5d88e..f1af2c65 100644 --- a/contrib/epee/include/string_tools.h +++ b/contrib/epee/include/string_tools.h @@ -23,16 +23,11 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // - - - #ifndef _STRING_TOOLS_H_ #define _STRING_TOOLS_H_ -//#include #include #include -//#include #include #include #include @@ -322,13 +317,6 @@ POP_GCC_WARNINGS return true; } -/* template - bool get_xparam_from_command_line(const std::map& res, const std::basic_string & key, t_type& val) - { - - } - */ - template bool get_xparam_from_command_line(const std::map& res, const t_string & key, t_type& val) { @@ -803,6 +791,6 @@ POP_GCC_WARNINGS return buff; } #endif -} -} +} // namespace stringtools +} // namwspace epee #endif //_STRING_TOOLS_H_ From 50970e3d544172c0b434e03de0a2f32e27ddf2de Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 10 May 2022 18:48:18 +0200 Subject: [PATCH 02/19] removed that crazy annoying Boost warning (a bug in Boost 1.70, already fixed) "The use of BOOST_*_ENDIAN and BOOST_BYTE_ORDER is deprecated." --- contrib/eos_portable_archive/eos/portable_iarchive.hpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/contrib/eos_portable_archive/eos/portable_iarchive.hpp b/contrib/eos_portable_archive/eos/portable_iarchive.hpp index cd087f34..f46507f4 100644 --- a/contrib/eos_portable_archive/eos/portable_iarchive.hpp +++ b/contrib/eos_portable_archive/eos/portable_iarchive.hpp @@ -88,6 +88,13 @@ // basic headers #include + +// The following four lines disable annoying message in Boost 1.70 (The use of BOOST_*_ENDIAN and BOOST_BYTE_ORDER is deprecated.) +#if BOOST_VERSION == 107000 +# define BOOST_PREDEF_DETAIL_ENDIAN_COMPAT_H +# include +#endif + #include #include #include From b30bc2f781fc3c53400fb587b2b5606aaa465bd6 Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 10 May 2022 19:59:58 +0200 Subject: [PATCH 03/19] eos portable archive fixed (endians defines) --- .../eos/portable_iarchive.hpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/contrib/eos_portable_archive/eos/portable_iarchive.hpp b/contrib/eos_portable_archive/eos/portable_iarchive.hpp index f46507f4..d5a39e08 100644 --- a/contrib/eos_portable_archive/eos/portable_iarchive.hpp +++ b/contrib/eos_portable_archive/eos/portable_iarchive.hpp @@ -89,10 +89,22 @@ // basic headers #include -// The following four lines disable annoying message in Boost 1.70 (The use of BOOST_*_ENDIAN and BOOST_BYTE_ORDER is deprecated.) -#if BOOST_VERSION == 107000 +// The following sixteen lines disable annoying message in Boost 1.70 (The use of BOOST_*_ENDIAN and BOOST_BYTE_ORDER is deprecated.) +#if BOOST_VERSION == 107000 && !defined(BOOST_PREDEF_DETAIL_ENDIAN_COMPAT_H) # define BOOST_PREDEF_DETAIL_ENDIAN_COMPAT_H # include +#if BOOST_ENDIAN_BIG_BYTE +# define BOOST_BIG_ENDIAN +# define BOOST_BYTE_ORDER 4321 +#endif +#if BOOST_ENDIAN_LITTLE_BYTE +# define BOOST_LITTLE_ENDIAN +# define BOOST_BYTE_ORDER 1234 +#endif +#if BOOST_ENDIAN_LITTLE_WORD +# define BOOST_PDP_ENDIAN +# define BOOST_BYTE_ORDER 2134 +#endif #endif #include From aa90e50f421aed49675bfaa82aa037c8bc4c2b6f Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 10 May 2022 20:42:54 +0200 Subject: [PATCH 04/19] fix for Argument-Dependent Lookup issue with parse_tpod_from_hex_string() --- contrib/epee/include/string_tools.h | 2 +- contrib/epee/include/syncobj.h | 2 +- src/crypto/crypto-sugar.h | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/contrib/epee/include/string_tools.h b/contrib/epee/include/string_tools.h index f1af2c65..0d50b4e1 100644 --- a/contrib/epee/include/string_tools.h +++ b/contrib/epee/include/string_tools.h @@ -207,7 +207,7 @@ namespace string_tools t_pod_type parse_tpod_from_hex_string(const std::string& str_hash) { t_pod_type t_pod = AUTO_VAL_INIT(t_pod); - parse_tpod_from_hex_string(str_hash, t_pod); + epee::string_tools::parse_tpod_from_hex_string(str_hash, t_pod); // using fully qualified name to avoid Argument-Dependent Lookup issues return t_pod; } //---------------------------------------------------------------------------- diff --git a/contrib/epee/include/syncobj.h b/contrib/epee/include/syncobj.h index 07c0a484..9971ef12 100644 --- a/contrib/epee/include/syncobj.h +++ b/contrib/epee/include/syncobj.h @@ -711,4 +711,4 @@ namespace epee #define EXCLUSIVE_CRITICAL_REGION_BEGIN(x) { EXCLUSIVE_CRITICAL_REGION_LOCAL(x) #define EXCLUSIVE_CRITICAL_REGION_END() } -} +} // namespace epee diff --git a/src/crypto/crypto-sugar.h b/src/crypto/crypto-sugar.h index a2681642..4363e5ae 100644 --- a/src/crypto/crypto-sugar.h +++ b/src/crypto/crypto-sugar.h @@ -1,5 +1,5 @@ -// Copyright (c) 2020-2021 Zano Project -// Copyright (c) 2020-2021 sowle (val@zano.org, crypto.sowle@gmail.com) +// Copyright (c) 2020-2022 Zano Project +// Copyright (c) 2020-2022 sowle (val@zano.org, crypto.sowle@gmail.com) // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. // @@ -125,7 +125,7 @@ namespace crypto t_pod_type parse_tpod_from_hex_string(const std::string& hex_str) { t_pod_type t_pod = AUTO_VAL_INIT(t_pod); - parse_tpod_from_hex_string(hex_str, t_pod); + crypto::parse_tpod_from_hex_string(hex_str, t_pod); // using fully qualified name to avoid Argument-Dependent Lookup issues return t_pod; } From 10ed5dc433c7d627e727a27d59549ee72c9e6448 Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 10 May 2022 21:05:15 +0200 Subject: [PATCH 05/19] getting rig of "using namespace epee" in headers --- src/currency_core/blockchain_storage.h | 6 +++--- src/currency_core/currency_core.h | 8 ++++---- src/currency_core/miner.h | 10 +++++----- src/currency_core/tx_pool.cpp | 2 ++ src/currency_core/tx_pool.h | 1 - src/stratum/stratum_server.cpp | 2 +- src/wallet/wallets_manager.h | 2 -- 7 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/currency_core/blockchain_storage.h b/src/currency_core/blockchain_storage.h index cad2ca91..2ca28c2e 100644 --- a/src/currency_core/blockchain_storage.h +++ b/src/currency_core/blockchain_storage.h @@ -531,9 +531,9 @@ namespace currency - mutable critical_section m_invalid_blocks_lock; + mutable epee::critical_section m_invalid_blocks_lock; blocks_ext_by_hash m_invalid_blocks; // crypto::hash -> block_extended_info - mutable critical_section m_alternative_chains_lock; + mutable epee::critical_section m_alternative_chains_lock; alt_chain_container m_alternative_chains; // crypto::hash -> alt_block_extended_info std::unordered_map m_alternative_chains_txs; // tx_id -> how many alt blocks it related to (always >= 1) std::unordered_map> m_altblocks_keyimages; // key image -> list of alt blocks hashes where it appears in inputs @@ -557,7 +557,7 @@ namespace currency mutable wide_difficulty_type m_cached_next_pow_difficulty; mutable wide_difficulty_type m_cached_next_pos_difficulty; - mutable critical_section m_targetdata_cache_lock; + mutable epee::critical_section m_targetdata_cache_lock; mutable std::list > m_pos_targetdata_cache; mutable std::list > m_pow_targetdata_cache; //work like a cache to avoid recalculation on read operations diff --git a/src/currency_core/currency_core.h b/src/currency_core/currency_core.h index 354fd772..383ae47e 100644 --- a/src/currency_core/currency_core.h +++ b/src/currency_core/currency_core.h @@ -139,18 +139,18 @@ namespace currency tx_memory_pool m_mempool; i_currency_protocol* m_pprotocol; i_critical_error_handler* m_critical_error_handler; - critical_section m_incoming_tx_lock; + epee::critical_section m_incoming_tx_lock; miner m_miner; account_public_address m_miner_address; std::string m_config_folder; uint64_t m_stop_after_height; currency_protocol_stub m_protocol_stub; - math_helper::once_a_time_seconds<60*60*12, false> m_prune_alt_blocks_interval; - math_helper::once_a_time_seconds<60, true> m_check_free_space_interval; + epee::math_helper::once_a_time_seconds<60*60*12, false> m_prune_alt_blocks_interval; + epee::math_helper::once_a_time_seconds<60, true> m_check_free_space_interval; friend class tx_validate_inputs; std::atomic m_starter_message_showed; - critical_section m_blockchain_update_listeners_lock; + epee::critical_section m_blockchain_update_listeners_lock; std::vector m_blockchain_update_listeners; }; } diff --git a/src/currency_core/miner.h b/src/currency_core/miner.h index 69a4bdc7..ec011801 100644 --- a/src/currency_core/miner.h +++ b/src/currency_core/miner.h @@ -92,7 +92,7 @@ namespace currency volatile uint32_t m_stop; - ::critical_section m_template_lock; + epee::critical_section m_template_lock; block m_template; std::atomic m_template_no; std::atomic m_starter_nonce; @@ -101,15 +101,15 @@ namespace currency volatile uint32_t m_thread_index; volatile uint32_t m_threads_total; std::atomic m_pausers_count; - ::critical_section m_miners_count_lock; + epee::critical_section m_miners_count_lock; std::list m_threads; - ::critical_section m_threads_lock; + epee::critical_section m_threads_lock; i_miner_handler* m_phandler; //blockchain_storage& m_bc; account_public_address m_mine_address; - math_helper::once_a_time_seconds<5> m_update_block_template_interval; - math_helper::once_a_time_seconds<2> m_update_merge_hr_interval; + epee::math_helper::once_a_time_seconds<5> m_update_block_template_interval; + epee::math_helper::once_a_time_seconds<2> m_update_merge_hr_interval; std::vector m_extra_messages; miner_config m_config; std::string m_config_folder; diff --git a/src/currency_core/tx_pool.cpp b/src/currency_core/tx_pool.cpp index 581dfdb8..7f4d4495 100644 --- a/src/currency_core/tx_pool.cpp +++ b/src/currency_core/tx_pool.cpp @@ -40,6 +40,8 @@ DISABLE_VS_WARNINGS(4244 4345 4503) //'boost::foreach_detail_::or_' : decorated #define LOG_DEFAULT_CHANNEL "tx_pool" ENABLE_CHANNEL_BY_DEFAULT("tx_pool"); +using namespace epee; + namespace currency { //--------------------------------------------------------------------------------- diff --git a/src/currency_core/tx_pool.h b/src/currency_core/tx_pool.h index 4e660a68..c9de4748 100644 --- a/src/currency_core/tx_pool.h +++ b/src/currency_core/tx_pool.h @@ -6,7 +6,6 @@ #pragma once #include "include_base_utils.h" -using namespace epee; #include diff --git a/src/stratum/stratum_server.cpp b/src/stratum/stratum_server.cpp index f952cd7a..8ec41088 100644 --- a/src/stratum/stratum_server.cpp +++ b/src/stratum/stratum_server.cpp @@ -368,7 +368,7 @@ namespace void block_template_update_thread() { - log_space::log_singletone::set_thread_log_prefix("[ST]"); + epee::log_space::log_singletone::set_thread_log_prefix("[ST]"); while (!m_stop_flag) { if (is_core_syncronized() && epee::misc_utils::get_tick_count() - m_block_template_update_ts >= m_block_template_update_pediod_ms) diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index 77656785..45dec851 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -15,8 +15,6 @@ DISABLE_VS_WARNINGS(4503) #include "include_base_utils.h" #include "version.h" -using namespace epee; - #include "console_handler.h" #include "p2p/net_node.h" #include "currency_core/checkpoints_create.h" From d692c83d1453c4b97fdbd4cb170cd1ce222a7e14 Mon Sep 17 00:00:00 2001 From: sowle Date: Tue, 10 May 2022 21:10:33 +0200 Subject: [PATCH 06/19] crypto serialization code re-arranged, bpp_signature_serialized introduced --- ...serialization.h => crypto_serialization.h} | 68 +++++++++++++++++-- src/currency_core/bc_offers_serialization.h | 2 +- src/currency_core/currency_basic.h | 3 +- .../currency_boost_serialization.h | 2 +- .../maintainers_info_boost_serialization.h | 2 +- src/serialization/crypto.h | 63 ----------------- 6 files changed, 66 insertions(+), 74 deletions(-) rename src/common/{crypto_boost_serialization.h => crypto_serialization.h} (56%) delete mode 100644 src/serialization/crypto.h diff --git a/src/common/crypto_boost_serialization.h b/src/common/crypto_serialization.h similarity index 56% rename from src/common/crypto_boost_serialization.h rename to src/common/crypto_serialization.h index 310c8e92..23b4c143 100644 --- a/src/common/crypto_boost_serialization.h +++ b/src/common/crypto_serialization.h @@ -1,11 +1,9 @@ -// Copyright (c) 2014-2018 Zano Project +// Copyright (c) 2014-2022 Zano Project // Copyright (c) 2014-2018 The Louisdor Project // Copyright (c) 2012-2013 The Cryptonote developers // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. - #pragma once - #include #include #include @@ -13,7 +11,65 @@ #include #include #include + +#include "serialization/serialization.h" +#include "serialization/debug_archive.h" +#include "crypto/chacha8.h" #include "crypto/crypto.h" +#include "crypto/hash.h" +#include "crypto/range_proofs.h" +#include "boost_serialization_maps.h" + +// +// binary serialization +// + +namespace crypto +{ + struct bpp_signature_serialized : public crypto::bppe_signature + { + BEGIN_SERIALIZE_OBJECT() + FIELD(L) + FIELD(R) + FIELD(A0) + FIELD(A) + FIELD(B) + FIELD(r) + FIELD(s) + FIELD(delta) + END_SERIALIZE() + + BEGIN_BOOST_SERIALIZATION() + BOOST_SERIALIZE(L) + BOOST_SERIALIZE(R) + BOOST_SERIALIZE(A0) + BOOST_SERIALIZE(A) + BOOST_SERIALIZE(B) + BOOST_SERIALIZE(r) + BOOST_SERIALIZE(s) + BOOST_SERIALIZE(delta) + END_BOOST_SERIALIZATION() + }; +} + +BLOB_SERIALIZER(crypto::chacha8_iv); +BLOB_SERIALIZER(crypto::hash); +BLOB_SERIALIZER(crypto::public_key); +BLOB_SERIALIZER(crypto::secret_key); +BLOB_SERIALIZER(crypto::key_derivation); +BLOB_SERIALIZER(crypto::key_image); +BLOB_SERIALIZER(crypto::signature); +VARIANT_TAG(debug_archive, crypto::hash, "hash"); +VARIANT_TAG(debug_archive, crypto::public_key, "public_key"); +VARIANT_TAG(debug_archive, crypto::secret_key, "secret_key"); +VARIANT_TAG(debug_archive, crypto::key_derivation, "key_derivation"); +VARIANT_TAG(debug_archive, crypto::key_image, "key_image"); +VARIANT_TAG(debug_archive, crypto::signature, "signature"); + + +// +// Boost serialization +// namespace boost { @@ -51,7 +107,5 @@ namespace boost { a & reinterpret_cast(x); } - } -} - -//} + } // namespace serialization +} // namespace boost diff --git a/src/currency_core/bc_offers_serialization.h b/src/currency_core/bc_offers_serialization.h index cee1e274..f786133f 100644 --- a/src/currency_core/bc_offers_serialization.h +++ b/src/currency_core/bc_offers_serialization.h @@ -13,7 +13,7 @@ #include #include #include "common/unordered_containers_boost_serialization.h" -#include "common/crypto_boost_serialization.h" +#include "common/crypto_serialization.h" #include "offers_service_basics.h" #include "offers_services_helpers.h" diff --git a/src/currency_core/currency_basic.h b/src/currency_core/currency_basic.h index 676d4f4d..37c97a58 100644 --- a/src/currency_core/currency_basic.h +++ b/src/currency_core/currency_basic.h @@ -26,7 +26,6 @@ #include "include_base_utils.h" #include "serialization/binary_archive.h" -#include "serialization/crypto.h" #include "serialization/stl_containers.h" #include "serialization/serialization.h" #include "serialization/variant.h" @@ -37,9 +36,11 @@ #include "currency_config.h" #include "crypto/crypto.h" #include "crypto/hash.h" +#include "crypto/range_proofs.h" #include "misc_language.h" #include "block_flags.h" #include "etc_custom_serialization.h" +#include "common/crypto_serialization.h" namespace currency { diff --git a/src/currency_core/currency_boost_serialization.h b/src/currency_core/currency_boost_serialization.h index 9b241bec..72d2bd4d 100644 --- a/src/currency_core/currency_boost_serialization.h +++ b/src/currency_core/currency_boost_serialization.h @@ -15,7 +15,7 @@ #include #include "currency_basic.h" #include "common/unordered_containers_boost_serialization.h" -#include "common/crypto_boost_serialization.h" +#include "common/crypto_serialization.h" #include "offers_services_helpers.h" #define CURRENT_BLOCK_ARCHIVE_VER 2 diff --git a/src/p2p/maintainers_info_boost_serialization.h b/src/p2p/maintainers_info_boost_serialization.h index fafc659e..b8b5df48 100644 --- a/src/p2p/maintainers_info_boost_serialization.h +++ b/src/p2p/maintainers_info_boost_serialization.h @@ -6,7 +6,7 @@ #pragma once #include "p2p_protocol_defs.h" -#include "common/crypto_boost_serialization.h" +#include "common/crypto_serialization.h" namespace boost { diff --git a/src/serialization/crypto.h b/src/serialization/crypto.h deleted file mode 100644 index c436b466..00000000 --- a/src/serialization/crypto.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2014-2017 The The Louisdor Project -// Copyright (c) 2012-2013 The Cryptonote developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#include "serialization.h" -#include "debug_archive.h" -#include "crypto/chacha8.h" -#include "crypto/crypto.h" -#include "crypto/hash.h" - -/*// read -template