diff --git a/CMakeLists.txt b/CMakeLists.txt index b57c164ab..0bc5b72a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,10 @@ statusinfo("CMake version ${CMAKE_VERSION}") project(arqma LANGUAGES CXX C) +if(POLICY CMP0167) + cmake_policy(SET CMP0167 NEW) +endif() + cmake_host_system_information(RESULT freememsys QUERY AVAILABLE_PHYSICAL_MEMORY) cmake_host_system_information(RESULT freememvirt QUERY AVAILABLE_VIRTUAL_MEMORY) statusinfo("${Green}Total available physical memory:${ColourReset}${BoldBlue} ${freememsys} Mib ${ColourReset}") @@ -1011,10 +1015,10 @@ else() endif() if(APPLE) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mmacosx-version-min=10.15 -fvisibility=hidden -DGTEST_HAS_TR1_TUPLE=0") - if(NOT DEPENDS) - set(CMAKE_OSX_DEPLOYMENT_TARGET 13.0) - endif() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -DGTEST_HAS_TR1_TUPLE=0") +# if(NOT DEPENDS) +# set(CMAKE_OSX_DEPLOYMENT_TARGET 14.0) +# endif() endif() set(DEBUG_FLAGS "-g3") @@ -1081,8 +1085,10 @@ if(STATIC) set(CMAKE_FIND_LIBRARY_SUFFIXES .a) endif() - set(Boost_USE_STATIC_LIBS ON) - set(Boost_USE_STATIC_RUNTIME ON) + if(NOT APPLE) + set(Boost_USE_STATIC_LIBS ON) + set(Boost_USE_STATIC_RUNTIME ON) + endif() endif() if(DEPENDS) @@ -1093,15 +1099,15 @@ if(DEPENDS) endif() endif() +set(BOOST_LIBRARIES system filesystem thread date_time chrono regex serialization program_options) if(WIN32) - set(BOOST_LIBRARIES system filesystem thread date_time chrono regex serialization program_options locale) -else() - set(BOOST_LIBRARIES system filesystem thread date_time chrono regex serialization program_options) + list(APPEND BOOST_LIBRARIES locale) endif() find_package(Boost 1.62.0 QUIET REQUIRED COMPONENTS ${BOOST_LIBRARIES}) include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) add_definitions(-DBOOST_ASIO_ENABLE_SEQUENTIAL_STRAND_ALLOCATION) +add_definitions(-DBOOST_UUID_DISABLE_ALIGNMENT) set(CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_LIB_SUFFIXES}) if(NOT Boost_FOUND) diff --git a/contrib/epee/include/file_io_utils.h b/contrib/epee/include/file_io_utils.h index 1c1d1d2f4..f9c76a687 100644 --- a/contrib/epee/include/file_io_utils.h +++ b/contrib/epee/include/file_io_utils.h @@ -103,29 +103,6 @@ namespace file_io_utils #endif } - inline - bool get_file_time(const std::string& path_to_file, time_t& ft) - { - boost::system::error_code ec; - ft = boost::filesystem::last_write_time(boost::filesystem::path(path_to_file), ec); - if(!ec) - return true; - else - return false; - } - - inline - bool set_file_time(const std::string& path_to_file, const time_t& ft) - { - boost::system::error_code ec; - boost::filesystem::last_write_time(boost::filesystem::path(path_to_file), ft, ec); - if(!ec) - return true; - else - return false; - } - - inline bool load_file_to_string(const std::string& path_to_file, std::string& target_str, size_t max_size = 1000000000) { @@ -175,26 +152,6 @@ namespace file_io_utils #endif } - inline - bool append_string_to_file(const std::string& path_to_file, const std::string& str) - { - // No special Windows implementation because so far not used in Monero code - try - { - std::ofstream fstream; - fstream.exceptions(std::ifstream::failbit | std::ifstream::badbit); - fstream.open(path_to_file.c_str(), std::ios_base::binary | std::ios_base::out | std::ios_base::app); - fstream << str; - fstream.close(); - return true; - } - - catch(...) - { - return false; - } - } - inline bool get_file_size(const std::string& path_to_file, uint64_t &size) { diff --git a/contrib/epee/include/misc_language.h b/contrib/epee/include/misc_language.h index 13e2dcfb2..a5849ab4b 100644 --- a/contrib/epee/include/misc_language.h +++ b/contrib/epee/include/misc_language.h @@ -28,44 +28,12 @@ #pragma once -#include +#include #include namespace epee { -#define STD_TRY_BEGIN() try { - -#define STD_TRY_CATCH(where_, ret_val) \ - } \ - catch (const std::exception &e) \ - { \ - LOG_ERROR("EXCEPTION: " << where_ << ", mes: "<< e.what()); \ - return ret_val; \ - } \ - catch (...) \ - { \ - LOG_ERROR("EXCEPTION: " << where_ ); \ - return ret_val; \ - } - - - namespace misc_utils { - template - t_type get_max_t_val(t_type t) - { - return (std::numeric_limits::max)(); - } - - - template - t_iterator move_it_forward(t_iterator it, size_t count) - { - while(count--) - it++; - return it; - } - template t_iterator move_it_backward(t_iterator it, size_t count) { @@ -74,25 +42,6 @@ namespace misc_utils return it; } - - // TEMPLATE STRUCT less - template - struct less_as_pod - : public std::binary_function<_Ty, _Ty, bool> - { // functor for operator< - bool operator()(const _Ty& _Left, const _Ty& _Right) const - { // apply operator< to operands - return memcmp(&_Left, &_Right, sizeof(_Left)) < 0; - } - }; - - template - bool is_less_as_pod(const _Ty& _Left, const _Ty& _Right) - { // apply operator< to operands - return memcmp(&_Left, &_Right, sizeof(_Left)) < 0; - } - - inline bool sleep_no_w(long ms ) { diff --git a/contrib/epee/include/serialization/keyvalue_serialization.h b/contrib/epee/include/serialization/keyvalue_serialization.h index 9bd1e3ba9..a93f19925 100644 --- a/contrib/epee/include/serialization/keyvalue_serialization.h +++ b/contrib/epee/include/serialization/keyvalue_serialization.h @@ -95,12 +95,14 @@ do { \ epee::serialization::selector::serialize_t_val_as_blob(this_ref.variable, stg, hparent_section, val_name); #define KV_SERIALIZE_VAL_POD_AS_BLOB_N(variable, val_name) \ - static_assert(std::is_pod::value, "t_type must be a POD type."); \ + static_assert(std::is_trivially_copyable_v, "t_type must be a trivially copyable type."); \ + static_assert(std::is_standard_layout_v, "t_type must be a standard layout type."); \ KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(variable, val_name) #define KV_SERIALIZE_VAL_POD_AS_BLOB_OPT_N(variable, val_name, default_value) \ do { \ - static_assert(std::is_pod::value, "t_type must be a POD type."); \ + static_assert(std::is_trivially_copyable_v, "t_type must be a trivially copyable type."); \ + static_assert(std::is_standard_layout_v, "t_type must be a standard layout type."); \ bool ret = KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(variable, val_name); \ if (!ret) \ epee::serialize_default(this_ref.variable, default_value); \ @@ -114,7 +116,7 @@ do { \ #define KV_SERIALIZE(variable) KV_SERIALIZE_N(variable, #variable) #define KV_SERIALIZE_VAL_POD_AS_BLOB(variable) KV_SERIALIZE_VAL_POD_AS_BLOB_N(variable, #variable) #define KV_SERIALIZE_VAL_POD_AS_BLOB_OPT(variable, def) KV_SERIALIZE_VAL_POD_AS_BLOB_OPT_N(variable, #variable, def) -#define KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(variable) KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(variable, #variable) //skip is_pod compile time check +#define KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE(variable) KV_SERIALIZE_VAL_POD_AS_BLOB_FORCE_N(variable, #variable) //skip is_trivially_copyable and is_standard_layout compile time check #define KV_SERIALIZE_CONTAINER_POD_AS_BLOB(variable) KV_SERIALIZE_CONTAINER_POD_AS_BLOB_N(variable, #variable) #define KV_SERIALIZE_OPT(variable,default_value) KV_SERIALIZE_OPT_N(variable, #variable, default_value) #define KV_SERIALIZE_OPT2(variable,default_value) KV_SERIALIZE_OPT_N2(variable, #variable, default_value) diff --git a/contrib/epee/include/span.h b/contrib/epee/include/span.h index a31732d22..410393f5f 100644 --- a/contrib/epee/include/span.h +++ b/contrib/epee/include/span.h @@ -132,17 +132,13 @@ namespace epee return {src.data(), src.size()}; } - template - constexpr bool has_padding() noexcept - { - return !std::is_standard_layout() || alignof(T) != 1; - } - //! \return Cast data from `src` as `span`. template span to_byte_span(const span src) noexcept { - static_assert(!has_padding(), "source type may have padding"); + static_assert(!std::is_empty(), "empty value types will not work -> sizeof == 1"); + static_assert(std::is_standard_layout_v, "type must have standard layout"); + static_assert(std::has_unique_object_representations_v, "type must be trivially copyable with no padding"); return {reinterpret_cast(src.data()), src.size_bytes()}; } @@ -151,7 +147,8 @@ namespace epee span as_byte_span(const T& src) noexcept { static_assert(!std::is_empty(), "empty types will not work -> sizeof == 1"); - static_assert(!has_padding(), "source type may have padding"); + static_assert(std::is_standard_layout_v, "type must have standard layout"); + static_assert(std::has_unique_object_representations_v, "type must be trivially copyable with no padding"); return {reinterpret_cast(std::addressof(src)), sizeof(T)}; } @@ -160,7 +157,8 @@ namespace epee span as_mut_byte_span(T& src) noexcept { static_assert(!std::is_empty(), "empty types will not work -> sizeof == 1"); - static_assert(!has_padding(), "source type may have padding"); + static_assert(std::is_standard_layout_v, "type must have standard layout"); + static_assert(std::has_unique_object_representations_v, "type must be trivially copyable with no padding"); return {reinterpret_cast(std::addressof(src)), sizeof(T)}; } diff --git a/contrib/epee/include/string_tools.h b/contrib/epee/include/string_tools.h index 453e64928..6d7db0909 100644 --- a/contrib/epee/include/string_tools.h +++ b/contrib/epee/include/string_tools.h @@ -297,6 +297,7 @@ POP_WARNINGS std::string pod_to_hex(const t_pod_type& s) { static_assert(std::is_standard_layout(), "expected standard layout type"); + static_assert(std::has_unique_object_representations_v, "type may have padding"); return to_hex::string(as_byte_span(s)); } //---------------------------------------------------------------------------- @@ -309,6 +310,7 @@ POP_WARNINGS epee::span rspan((char*)&s, sizeof(s)); return parse_hexstr_to_binbuff(epee::to_span(hex_str), rspan);*/ static_assert(std::is_standard_layout(), "expected standard layout type"); + static_assert(std::has_unique_object_representations_v, "type may have padding"); return from_hex::to_buffer(as_mut_byte_span(s), hex_str); } //---------------------------------------------------------------------------- diff --git a/src/checkpoints/checkpoints.h b/src/checkpoints/checkpoints.h index 71cc72afd..5225d90ff 100644 --- a/src/checkpoints/checkpoints.h +++ b/src/checkpoints/checkpoints.h @@ -45,7 +45,7 @@ namespace cryptonote { - struct Blockchain; + class Blockchain; enum struct checkpoint_type { hardcoded, diff --git a/src/common/boost_serialization_helper.h b/src/common/boost_serialization_helper.h index d81616216..1964d797f 100644 --- a/src/common/boost_serialization_helper.h +++ b/src/common/boost_serialization_helper.h @@ -35,6 +35,7 @@ #include #include #include +#include "common/util.h" namespace tools @@ -111,7 +112,7 @@ namespace tools catch(...) { // if failed, try reading in unportable mode - boost::filesystem::copy_file(file_path, file_path + ".unportable", boost::filesystem::copy_option::overwrite_if_exists); + tools::copy_file(file_path, file_path + ".unportable"); data_file.close(); data_file.open( file_path, std::ios_base::binary | std::ios_base::in); if(data_file.fail()) diff --git a/src/common/threadpool.h b/src/common/threadpool.h index 2b54c9afe..5a2b5f843 100644 --- a/src/common/threadpool.h +++ b/src/common/threadpool.h @@ -34,6 +34,7 @@ #include #include #include +#include #include #include diff --git a/src/common/util.cpp b/src/common/util.cpp index 4af45af56..c7415020d 100644 --- a/src/common/util.cpp +++ b/src/common/util.cpp @@ -117,6 +117,22 @@ static int flock_exnb(int fd) namespace tools { + void copy_file(const std::string& from, const std::string& to) + { + using boost::filesystem::path; + #if BOOST_VERSION < 107400 + boost::filesystem::copy_file( + path(from), + path(to), + boost::filesystem::copy_option::overwrite_if_exists); + #else + boost::filesystem::copy_file( + path(from), + path(to), + boost::filesystem::copy_options::overwrite_existing); + #endif + } + std::function signal_handler::m_handler; private_file::private_file() noexcept : m_handle(), m_filename() {} diff --git a/src/common/util.h b/src/common/util.h index 7203741c2..428fe14e0 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -70,6 +70,8 @@ namespace tools } }; + void copy_file(const std::string& from, const std::string& to); + //! A file restricted to process owner AND process. Deletes file on destruction. class private_file { std::unique_ptr m_handle; diff --git a/src/crypto/crypto.h b/src/crypto/crypto.h index f1a79a197..db9128042 100644 --- a/src/crypto/crypto.h +++ b/src/crypto/crypto.h @@ -134,7 +134,9 @@ namespace crypto { /* Generate a value filled with random bytes. */ template - typename std::enable_if::value, T>::type rand() { + T rand() { + static_assert(std::is_standard_layout_v, "cannot write random bytes into non-standard layout type"); + static_assert(std::is_trivially_copyable_v, "cannot write random bytes into non-trivially copyable type"); typename std::remove_cv::type res; generate_random_bytes_thread_safe(sizeof(T), (uint8_t*)&res); return res; @@ -229,8 +231,9 @@ namespace crypto { inline std::ostream &operator <<(std::ostream &o, const crypto::public_key &v) { epee::to_hex::formatted(o, epee::as_byte_span(v)); return o; } - inline std::ostream &operator <<(std::ostream &o, const crypto::secret_key &v) { - epee::to_hex::formatted(o, epee::as_byte_span(v)); return o; + struct secret_key_explicit_print_ref { const crypto::secret_key &sk; }; + inline std::ostream &operator <<(std::ostream &o, const secret_key_explicit_print_ref v) { + epee::to_hex::formatted(o, epee::as_byte_span(unwrap(unwrap(v.sk)))); return o; } inline std::ostream &operator <<(std::ostream &o, const crypto::key_derivation &v) { epee::to_hex::formatted(o, epee::as_byte_span(v)); return o; diff --git a/src/cryptonote_basic/cryptonote_basic_impl.h b/src/cryptonote_basic/cryptonote_basic_impl.h index 6a96d9ce2..8adf539ab 100644 --- a/src/cryptonote_basic/cryptonote_basic_impl.h +++ b/src/cryptonote_basic/cryptonote_basic_impl.h @@ -70,16 +70,6 @@ namespace cryptonote { /************************************************************************/ /* */ /************************************************************************/ - template - struct array_hasher: std::unary_function - { - std::size_t operator()(const t_array& val) const - { - return boost::hash_range(&val.data[0], &val.data[sizeof(val.data)]); - } - }; - - #pragma pack(push, 1) struct public_address_outer_blob { diff --git a/src/cryptonote_basic/cryptonote_format_utils.cpp b/src/cryptonote_basic/cryptonote_format_utils.cpp index 18359efb3..130429b12 100644 --- a/src/cryptonote_basic/cryptonote_format_utils.cpp +++ b/src/cryptonote_basic/cryptonote_format_utils.cpp @@ -302,7 +302,7 @@ namespace cryptonote bool r = hwdev.generate_key_derivation(tx_public_key, ack.m_view_secret_key, recv_derivation); if (!r) { - MWARNING("key image helper: failed to generate_key_derivation(" << tx_public_key << ", " << ack.m_view_secret_key << ")"); + MWARNING("key image helper: failed to generate_key_derivation(" << tx_public_key << ", )"); memcpy(&recv_derivation, rct::identity().bytes, sizeof(recv_derivation)); } @@ -313,7 +313,7 @@ namespace cryptonote r = hwdev.generate_key_derivation(additional_tx_public_keys[i], ack.m_view_secret_key, additional_recv_derivation); if (!r) { - MWARNING("key image helper: failed to generate_key_derivation(" << additional_tx_public_keys[i] << ", " << ack.m_view_secret_key << ")"); + MWARNING("key image helper: failed to generate_key_derivation(" << additional_tx_public_keys[i] << ", )"); } else { diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 2b4c6adc0..e228817da 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -1327,7 +1327,7 @@ difficulty_type Blockchain::get_next_difficulty_for_alternative_chain(const std: size_t count = 0; size_t max_i = timestamps.size()-1; // get difficulties and timestamps from most recent blocks in alt chain - for (const auto bei: boost::adaptors::reverse(alt_chain)) + for (const auto& bei: boost::adaptors::reverse(alt_chain)) { timestamps[max_i - count] = bei.bl.timestamp; cumulative_difficulties[max_i - count] = bei.cumulative_difficulty; diff --git a/src/cryptonote_core/cryptonote_tx_utils.cpp b/src/cryptonote_core/cryptonote_tx_utils.cpp index 586c6a273..ce5357a12 100644 --- a/src/cryptonote_core/cryptonote_tx_utils.cpp +++ b/src/cryptonote_core/cryptonote_tx_utils.cpp @@ -113,7 +113,7 @@ namespace cryptonote { crypto::key_derivation derivation{}; bool r = crypto::generate_key_derivation(address.m_view_public_key, tx_key.sec, derivation); - CHECK_AND_ASSERT_MES(r, false, "failed to generate_key_derivation(" << address.m_view_public_key << ", " << tx_key.sec << ")"); + CHECK_AND_ASSERT_MES(r, false, "failed to generate_key_derivation(" << address.m_view_public_key << ", " << crypto::secret_key_explicit_print_ref{tx_key.sec} << ")"); r = crypto::derive_public_key(derivation, output_index, address.m_spend_public_key, output_key); CHECK_AND_ASSERT_MES(r, false, "failed to derive_public_key(" << derivation << ", " << output_index << ", " << address.m_spend_public_key << ")"); @@ -253,7 +253,7 @@ namespace cryptonote crypto::key_derivation derivation{}; crypto::public_key out_eph_public_key{}; bool r = crypto::generate_key_derivation(miner_address.m_view_public_key, txkey.sec, derivation); - CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to generate_key_derivation(" << miner_address.m_view_public_key << ", " << txkey.sec << ")"); + CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to generate_key_derivation(" << miner_address.m_view_public_key << ", " << crypto::secret_key_explicit_print_ref{txkey.sec} << ")"); r = crypto::derive_public_key(derivation, 0, miner_address.m_spend_public_key, out_eph_public_key); CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to derive_public_key(" << derivation << ", " << 0 << ", " << miner_address.m_spend_public_key << ")"); @@ -284,7 +284,7 @@ namespace cryptonote crypto::key_derivation derivation{}; crypto::public_key out_eph_public_key{}; bool r = crypto::generate_key_derivation(service_node_info[i].first.m_view_public_key, gov_key.sec, derivation); - CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to generate_key_derivation(" << service_node_info[i].first.m_view_public_key << ", " << gov_key.sec << ")"); + CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to generate_key_derivation(" << service_node_info[i].first.m_view_public_key << ", " << crypto::secret_key_explicit_print_ref{gov_key.sec} << ")"); r = crypto::derive_public_key(derivation, 1+i, service_node_info[i].first.m_spend_public_key, out_eph_public_key); CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to derive_public_key(" << derivation << ", " << (1+i) << ", "<< service_node_info[i].first.m_spend_public_key << ")"); @@ -758,7 +758,7 @@ namespace cryptonote crypto::generate_ring_signature(tx_prefix_hash, boost::get(tx.vin[i]).k_image, keys_ptrs, in_contexts[i].in_ephemeral.sec, src_entr.real_output, sigs.data()); ss_ring_s << "signatures:" << ENDL; std::for_each(sigs.begin(), sigs.end(), [&](const crypto::signature& s){ss_ring_s << s << ENDL;}); - ss_ring_s << "prefix_hash:" << tx_prefix_hash << ENDL << "in_ephemeral_key: " << in_contexts[i].in_ephemeral.sec << ENDL << "real_output: " << src_entr.real_output << ENDL; + ss_ring_s << "prefix_hash:" << tx_prefix_hash << ENDL << "in_ephemeral_key: " << crypto::secret_key_explicit_print_ref{in_contexts[i].in_ephemeral.sec} << ENDL << "real_output: " << src_entr.real_output << ENDL; i++; } diff --git a/src/cryptonote_core/service_node_list.cpp b/src/cryptonote_core/service_node_list.cpp index ff15996a4..9668d5a12 100644 --- a/src/cryptonote_core/service_node_list.cpp +++ b/src/cryptonote_core/service_node_list.cpp @@ -1489,7 +1489,7 @@ namespace service_nodes cryptonote::keypair gov_key = cryptonote::get_deterministic_keypair_from_height(height); bool r = crypto::generate_key_derivation(addresses_and_portions[i].first.m_view_public_key, gov_key.sec, derivation); - CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to generate_key_derivation(" << addresses_and_portions[i].first.m_view_public_key << ", " << gov_key.sec << ")"); + CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to generate_key_derivation(" << addresses_and_portions[i].first.m_view_public_key << ", " << crypto::secret_key_explicit_print_ref{gov_key.sec} << ")"); r = crypto::derive_public_key(derivation, vout_index, addresses_and_portions[i].first.m_spend_public_key, out_eph_public_key); CHECK_AND_ASSERT_MES(r, false, "while creating outs: failed to derive_public_key(" << derivation << ", " << vout_index << ", "<< addresses_and_portions[i].first.m_spend_public_key << ")"); diff --git a/src/cryptonote_protocol/block_queue.cpp b/src/cryptonote_protocol/block_queue.cpp index 067727f27..228e85e78 100644 --- a/src/cryptonote_protocol/block_queue.cpp +++ b/src/cryptonote_protocol/block_queue.cpp @@ -41,15 +41,6 @@ #undef ARQMA_DEFAULT_LOG_CATEGORY #define ARQMA_DEFAULT_LOG_CATEGORY "cn.block_queue" -namespace std { - static_assert(sizeof(size_t) <= sizeof(boost::uuids::uuid), "boost::uuids::uuid too small"); - template<> struct hash { - std::size_t operator()(const boost::uuids::uuid &_v) const { - return reinterpret_cast(_v); - } - }; -} - namespace cryptonote { @@ -461,7 +452,7 @@ bool block_queue::has_spans(const boost::uuids::uuid &connection_id) const float block_queue::get_speed(const boost::uuids::uuid &connection_id) const { boost::unique_lock lock(mutex); - std::unordered_map speeds; + std::unordered_map> speeds; for (const auto &span: blocks) { if (span.blocks.empty()) @@ -469,7 +460,7 @@ float block_queue::get_speed(const boost::uuids::uuid &connection_id) const // note that the average below does not average over the whole set, but over the // previous pseudo average and the latest rate: this gives much more importance // to the latest measurements, which is fine here - std::unordered_map::iterator i = speeds.find(span.connection_id); + const auto i = speeds.find(span.connection_id); if (i == speeds.end()) speeds.insert(std::make_pair(span.connection_id, span.rate)); else diff --git a/src/device/device_default.cpp b/src/device/device_default.cpp index 039d7e312..bc6db5dde 100644 --- a/src/device/device_default.cpp +++ b/src/device/device_default.cpp @@ -310,13 +310,14 @@ namespace hw { found_change = true; // sending change to yourself; derivation = a*R r = generate_key_derivation(txkey_pub, sender_account_keys.m_view_secret_key, derivation); - CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to generate_key_derivation(" << txkey_pub << ", " << sender_account_keys.m_view_secret_key << ")"); + CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to generate_key_derivation(" << txkey_pub << ", )"); } else { // sending to the recipient; derivation = r*A (or s*C in the subaddress scheme) - r = generate_key_derivation(dst_entr.addr.m_view_public_key, dst_entr.is_subaddress && need_additional_txkeys ? additional_txkey.sec : tx_key, derivation); - CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to generate_key_derivation(" << dst_entr.addr.m_view_public_key << ", " << (dst_entr.is_subaddress && need_additional_txkeys ? additional_txkey.sec : tx_key) << ")"); + const crypto::secret_key &tx_privkey{dst_entr.is_subaddress && need_additional_txkeys ? additional_txkey.sec : tx_key}; + r = generate_key_derivation(dst_entr.addr.m_view_public_key, tx_privkey, derivation); + CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to generate_key_derivation(" << dst_entr.addr.m_view_public_key << ", " << crypto::secret_key_explicit_print_ref{tx_privkey} << ")"); } if(need_additional_txkeys) diff --git a/src/lmdb/util.h b/src/lmdb/util.h index f35a83015..44433524f 100644 --- a/src/lmdb/util.h +++ b/src/lmdb/util.h @@ -127,7 +127,7 @@ namespace lmdb /*! A LMDB comparison function that uses `std::memcmp`. - \toaram T is `!epee::has_padding` + \toaram T has standard layout and an alignment of 1 \tparam offset to `T` within the value. \return The result of `std::memcmp` over the value. @@ -135,7 +135,7 @@ namespace lmdb template inline int compare(MDB_val const* left, MDB_val const* right) noexcept { - static_assert(!epee::has_padding(), "memcmp will not work"); + static_assert(std::is_standard_layout_v && alignof(T) == 1, "memcmp will not work"); if (!left || !right || left->mv_size < sizeof(T) + offset || right->mv_size < sizeof(T) + offset) { assert("invalid use of custom comparison" == 0); diff --git a/src/p2p/net_peerlist.cpp b/src/p2p/net_peerlist.cpp index 866bb2fca..49bb630ed 100644 --- a/src/p2p/net_peerlist.cpp +++ b/src/p2p/net_peerlist.cpp @@ -42,6 +42,7 @@ #include #include "net_peerlist_boost_serialization.h" +#include "common/util.h" namespace nodetool @@ -200,7 +201,7 @@ namespace nodetool if (!out) { // if failed, try reading in unportable mode - boost::filesystem::copy_file(path, path + ".unportable", boost::filesystem::copy_option::overwrite_if_exists); + tools::copy_file(path, path + ".unportable"); src_file.close(); src_file.open( path , std::ios_base::binary | std::ios_base::in); if(src_file.fail()) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 76c5ca6d8..d72d05890 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -6634,9 +6634,9 @@ bool simple_wallet::get_tx_key(const std::vector &args_) if (m_wallet->get_tx_key(txid, tx_key, additional_tx_keys)) { ostringstream oss; - oss << epee::string_tools::pod_to_hex(tx_key); + oss << epee::string_tools::pod_to_hex(unwrap(unwrap(tx_key))); for (size_t i = 0; i < additional_tx_keys.size(); ++i) - oss << epee::string_tools::pod_to_hex(additional_tx_keys[i]); + oss << epee::string_tools::pod_to_hex(unwrap(unwrap(additional_tx_keys[i]))); success_msg_writer() << tr("Tx key: ") << oss.str(); return true; } diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index 404f0e6de..30da0dd82 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -823,7 +823,7 @@ std::string WalletImpl::integratedAddress(const std::string &payment_id) const std::string WalletImpl::secretViewKey() const { - return epee::string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_view_secret_key); + return epee::string_tools::pod_to_hex(unwrap(unwrap(m_wallet->get_account().get_keys().m_view_secret_key))); } std::string WalletImpl::publicViewKey() const @@ -833,7 +833,7 @@ std::string WalletImpl::publicViewKey() const std::string WalletImpl::secretSpendKey() const { - return epee::string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_spend_secret_key); + return epee::string_tools::pod_to_hex(unwrap(unwrap(m_wallet->get_account().get_keys().m_spend_secret_key))); } std::string WalletImpl::publicSpendKey() const @@ -1683,9 +1683,9 @@ std::string WalletImpl::getTxKey(const std::string &txid_str) const { clearStatus(); std::ostringstream oss; - oss << epee::string_tools::pod_to_hex(tx_key); + oss << epee::string_tools::pod_to_hex(unwrap(unwrap(tx_key))); for (size_t i = 0; i < additional_tx_keys.size(); ++i) - oss << epee::string_tools::pod_to_hex(additional_tx_keys[i]); + oss << epee::string_tools::pod_to_hex(unwrap(unwrap(additional_tx_keys[i]))); return oss.str(); } else diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 5d70529bd..908d44473 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -5080,7 +5080,7 @@ void wallet2::load(const std::string& wallet_, const epee::wipeable_string& pass catch (...) { LOG_PRINT_L0("Failed to open portable binary, trying unportable"); - boost::filesystem::copy_file(m_wallet_file, m_wallet_file + ".unportable", boost::filesystem::copy_option::overwrite_if_exists); + tools::copy_file(m_wallet_file, m_wallet_file + ".unportable"); std::stringstream iss; iss.str(""); iss << cache_data; @@ -5102,7 +5102,7 @@ void wallet2::load(const std::string& wallet_, const epee::wipeable_string& pass catch (...) { LOG_PRINT_L0("Failed to open portable binary, trying unportable"); - boost::filesystem::copy_file(m_wallet_file, m_wallet_file + ".unportable", boost::filesystem::copy_option::overwrite_if_exists); + tools::copy_file(m_wallet_file, m_wallet_file + ".unportable"); std::stringstream iss; iss.str(""); iss << buf; @@ -5867,7 +5867,7 @@ void wallet2::commit_tx(pending_tx& ptx) cryptonote::COMMAND_RPC_SUBMIT_RAW_TX::request oreq; cryptonote::COMMAND_RPC_SUBMIT_RAW_TX::response ores; oreq.address = get_account().get_public_address_str(m_nettype); - oreq.view_key = string_tools::pod_to_hex(get_account().get_keys().m_view_secret_key); + oreq.view_key = string_tools::pod_to_hex(unwrap(unwrap(get_account().get_keys().m_view_secret_key))); oreq.tx = epee::string_tools::buff_to_hex_nodelimer(tx_to_blob(ptx.tx)); m_daemon_rpc_mutex.lock(); bool r = epee::net_utils::invoke_http_json("/submit_raw_tx", oreq, ores, m_http_client, rpc_timeout, "POST"); @@ -8853,7 +8853,7 @@ bool wallet2::light_wallet_login(bool &new_address) tools::COMMAND_RPC_LOGIN::request request; tools::COMMAND_RPC_LOGIN::response response; request.address = get_account().get_public_address_str(m_nettype); - request.view_key = string_tools::pod_to_hex(get_account().get_keys().m_view_secret_key); + request.view_key = string_tools::pod_to_hex(unwrap(unwrap(get_account().get_keys().m_view_secret_key))); // Always create account if it doesn't exist. request.create_account = true; m_daemon_rpc_mutex.lock(); @@ -8880,7 +8880,7 @@ bool wallet2::light_wallet_import_wallet_request(tools::COMMAND_RPC_IMPORT_WALLE MDEBUG("Light wallet import wallet request"); tools::COMMAND_RPC_IMPORT_WALLET_REQUEST::request oreq; oreq.address = get_account().get_public_address_str(m_nettype); - oreq.view_key = string_tools::pod_to_hex(get_account().get_keys().m_view_secret_key); + oreq.view_key = string_tools::pod_to_hex(unwrap(unwrap(get_account().get_keys().m_view_secret_key))); m_daemon_rpc_mutex.lock(); bool r = epee::net_utils::invoke_http_json("/import_wallet_request", oreq, response, m_http_client, rpc_timeout, "POST"); m_daemon_rpc_mutex.unlock(); @@ -8899,7 +8899,7 @@ void wallet2::light_wallet_get_unspent_outs() oreq.amount = "0"; oreq.address = get_account().get_public_address_str(m_nettype); - oreq.view_key = string_tools::pod_to_hex(get_account().get_keys().m_view_secret_key); + oreq.view_key = string_tools::pod_to_hex(unwrap(unwrap(get_account().get_keys().m_view_secret_key))); // openMonero specific oreq.dust_threshold = boost::lexical_cast(::config::DEFAULT_DUST_THRESHOLD); // below are required by openMonero api - but are not used. @@ -9054,7 +9054,7 @@ bool wallet2::light_wallet_get_address_info(tools::COMMAND_RPC_GET_ADDRESS_INFO: tools::COMMAND_RPC_GET_ADDRESS_INFO::request request; request.address = get_account().get_public_address_str(m_nettype); - request.view_key = string_tools::pod_to_hex(get_account().get_keys().m_view_secret_key); + request.view_key = string_tools::pod_to_hex(unwrap(unwrap(get_account().get_keys().m_view_secret_key))); m_daemon_rpc_mutex.lock(); bool r = epee::net_utils::invoke_http_json("/get_address_info", request, response, m_http_client, rpc_timeout, "POST"); m_daemon_rpc_mutex.unlock(); @@ -9071,7 +9071,7 @@ void wallet2::light_wallet_get_address_txs() tools::COMMAND_RPC_GET_ADDRESS_TXS::response ires; ireq.address = get_account().get_public_address_str(m_nettype); - ireq.view_key = string_tools::pod_to_hex(get_account().get_keys().m_view_secret_key); + ireq.view_key = string_tools::pod_to_hex(unwrap(unwrap(get_account().get_keys().m_view_secret_key))); m_daemon_rpc_mutex.lock(); bool r = epee::net_utils::invoke_http_json("/get_address_txs", ireq, ires, m_http_client, rpc_timeout, "POST"); m_daemon_rpc_mutex.unlock(); @@ -9302,7 +9302,7 @@ bool wallet2::light_wallet_key_image_is_ours(const crypto::key_image& key_image, const account_keys& ack = get_account().get_keys(); crypto::key_derivation derivation; bool r = crypto::generate_key_derivation(tx_public_key, ack.m_view_secret_key, derivation); - CHECK_AND_ASSERT_MES(r, false, "failed to generate_key_derivation(" << tx_public_key << ", " << ack.m_view_secret_key << ")"); + CHECK_AND_ASSERT_MES(r, false, "failed to generate_key_derivation(" << tx_public_key << ", " << crypto::secret_key_explicit_print_ref{ack.m_view_secret_key} << ")"); r = crypto::derive_public_key(derivation, out_index, ack.m_account_address.m_spend_public_key, in_ephemeral.pub); CHECK_AND_ASSERT_MES(r, false, "failed to derive_public_key (" << derivation << ", " << out_index << ", " << ack.m_account_address.m_spend_public_key << ")"); @@ -9310,7 +9310,7 @@ bool wallet2::light_wallet_key_image_is_ours(const crypto::key_image& key_image, crypto::derive_secret_key(derivation, out_index, ack.m_spend_secret_key, in_ephemeral.sec); crypto::public_key out_pkey_test; r = crypto::secret_key_to_public_key(in_ephemeral.sec, out_pkey_test); - CHECK_AND_ASSERT_MES(r, false, "failed to secret_key_to_public_key(" << in_ephemeral.sec << ")"); + CHECK_AND_ASSERT_MES(r, false, "failed to secret_key_to_public_key(" << crypto::secret_key_explicit_print_ref{in_ephemeral.sec} << ")"); CHECK_AND_ASSERT_MES(in_ephemeral.pub == out_pkey_test, false, "derived secret key doesn't match derived public key"); crypto::generate_key_image(in_ephemeral.pub, in_ephemeral.sec, calculated_key_image); diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index c28ea8dc3..7439fe7a0 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -1892,7 +1892,7 @@ namespace boost if(ver < 5) { x.tx_type = cryptonote::txtype::standard; - x.hard_fork_version = cryptonote::network_version_16; + x.hard_fork_version = cryptonote::network_version_15; } } if(ver < 2) diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 7acd60470..ccdd941c5 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -1028,7 +1028,7 @@ namespace tools { res.tx_hash_list.push_back(epee::string_tools::pod_to_hex(cryptonote::get_transaction_hash(ptx.tx))); if (req.get_tx_keys) - res.tx_key_list.push_back(epee::string_tools::pod_to_hex(ptx.tx_key)); + res.tx_key_list.push_back(epee::string_tools::pod_to_hex(unwrap(unwrap(ptx.tx_key)))); } if (req.export_raw)