aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/build.yml17
-rw-r--r--.gitmodules3
-rw-r--r--CMakeLists.txt7
-rw-r--r--Dockerfile4
-rw-r--r--Doxyfile6
-rw-r--r--README.md2
-rw-r--r--contrib/epee/include/byte_slice.h2
-rw-r--r--contrib/epee/include/misc_language.h17
-rw-r--r--contrib/epee/include/net/abstract_tcp_server2.h6
-rw-r--r--contrib/epee/include/net/abstract_tcp_server2.inl11
-rw-r--r--contrib/epee/include/net/http_server_handlers_map2.h16
-rw-r--r--contrib/epee/include/net/levin_protocol_handler_async.h60
-rw-r--r--contrib/epee/include/net/net_ssl.h4
-rw-r--r--contrib/epee/include/storages/portable_storage.h206
-rw-r--r--contrib/epee/include/storages/portable_storage_base.h2
-rw-r--r--contrib/epee/include/storages/portable_storage_from_json.h1
-rw-r--r--contrib/epee/include/storages/portable_storage_template_helper.h1
-rw-r--r--contrib/epee/include/storages/portable_storage_to_bin.h1
-rw-r--r--contrib/epee/include/storages/portable_storage_val_converters.h7
-rw-r--r--contrib/epee/src/CMakeLists.txt7
-rw-r--r--contrib/epee/src/byte_slice.cpp24
-rw-r--r--contrib/epee/src/misc_language.cpp44
-rw-r--r--contrib/epee/src/net_ssl.cpp47
-rw-r--r--contrib/epee/src/portable_storage.cpp215
-rw-r--r--docs/ANONYMITY_NETWORKS.md9
-rw-r--r--external/CMakeLists.txt2
-rw-r--r--external/db_drivers/liblmdb/mdb.c2
m---------external/miniupnp0
-rw-r--r--src/blockchain_db/blockchain_db.cpp2
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp15
-rw-r--r--src/blockchain_utilities/blockchain_ancestry.cpp6
-rw-r--r--src/blockchain_utilities/blockchain_blackball.cpp8
-rw-r--r--src/blockchain_utilities/blockchain_import.cpp2
-rw-r--r--src/blockchain_utilities/blockchain_prune_known_spent_data.cpp1
-rw-r--r--src/blockchain_utilities/blockchain_usage.cpp3
-rw-r--r--src/common/dns_utils.cpp62
-rw-r--r--src/common/updates.cpp5
-rw-r--r--src/crypto/hash-ops.h4
-rw-r--r--src/crypto/tree-hash.c151
-rw-r--r--src/cryptonote_basic/CMakeLists.txt2
-rw-r--r--src/cryptonote_basic/cryptonote_format_utils.cpp20
-rw-r--r--src/cryptonote_basic/cryptonote_format_utils.h1
-rw-r--r--src/cryptonote_basic/merge_mining.cpp95
-rw-r--r--src/cryptonote_basic/merge_mining.h40
-rw-r--r--src/cryptonote_config.h2
-rw-r--r--src/cryptonote_core/blockchain.cpp3
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp2
-rw-r--r--src/cryptonote_core/tx_pool.cpp2
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler.inl7
-rw-r--r--src/daemon/rpc_command_executor.cpp1
-rw-r--r--src/debug_utilities/cn_deserialize.cpp12
-rw-r--r--src/debug_utilities/dns_checks.cpp2
-rw-r--r--src/device/device_io_hid.cpp1
-rw-r--r--src/device_trezor/device_trezor_base.cpp29
-rw-r--r--src/device_trezor/device_trezor_base.hpp2
-rw-r--r--src/gen_multisig/gen_multisig.cpp2
-rw-r--r--src/mnemonics/electrum-words.cpp1
-rw-r--r--src/mnemonics/language_base.h2
-rw-r--r--src/net/socks.cpp1
-rw-r--r--src/p2p/net_node.cpp1
-rw-r--r--src/p2p/net_node.h6
-rw-r--r--src/p2p/net_node.inl59
-rw-r--r--src/p2p/net_peerlist_boost_serialization.h10
-rw-r--r--src/p2p/p2p_protocol_defs.h2
-rw-r--r--src/ringct/multiexp.cc3
-rw-r--r--src/ringct/rctSigs.cpp2
-rw-r--r--src/rpc/core_rpc_server.cpp147
-rw-r--r--src/rpc/core_rpc_server.h2
-rw-r--r--src/rpc/core_rpc_server_commands_defs.h48
-rw-r--r--src/simplewallet/simplewallet.cpp85
-rw-r--r--src/simplewallet/simplewallet.h1
-rw-r--r--src/wallet/api/transaction_history.cpp1
-rw-r--r--src/wallet/api/wallet.cpp4
-rw-r--r--src/wallet/api/wallet.h2
-rw-r--r--src/wallet/api/wallet2_api.h3
-rw-r--r--src/wallet/message_store.cpp5
-rw-r--r--src/wallet/node_rpc_proxy.cpp2
-rw-r--r--src/wallet/node_rpc_proxy.h1
-rw-r--r--src/wallet/ringdb.cpp3
-rw-r--r--src/wallet/wallet2.cpp104
-rw-r--r--src/wallet/wallet2.h2
-rw-r--r--src/wallet/wallet_rpc_server.cpp12
-rw-r--r--tests/core_tests/transaction_tests.cpp2
-rw-r--r--tests/core_tests/tx_pool.cpp7
-rwxr-xr-xtests/functional_tests/mining.py2
-rw-r--r--tests/functional_tests/transactions_flow_test.cpp1
-rw-r--r--tests/net_load_tests/srv.cpp2
-rw-r--r--tests/performance_tests/performance_tests.h1
-rw-r--r--tests/unit_tests/bulletproofs.cpp1
-rw-r--r--tests/unit_tests/crypto.cpp213
-rw-r--r--tests/unit_tests/epee_boosted_tcp_server.cpp221
-rw-r--r--tests/unit_tests/epee_serialization.cpp1
-rw-r--r--tests/unit_tests/epee_utils.cpp4
-rw-r--r--tests/unit_tests/hardfork.cpp1
-rw-r--r--tests/unit_tests/net.cpp16
-rw-r--r--tests/unit_tests/node_server.cpp1
-rw-r--r--tests/unit_tests/output_selection.cpp2
-rw-r--r--tests/unit_tests/wipeable_string.cpp18
-rw-r--r--tests/unit_tests/zmq_rpc.cpp1
-rwxr-xr-xutils/python-rpc/console.py4
-rw-r--r--utils/python-rpc/framework/daemon.py13
101 files changed, 1681 insertions, 544 deletions
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index c6ed13e62..4c358e93e 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -14,7 +14,7 @@ jobs:
submodules: recursive
- uses: actions/cache@v2
with:
- path: ~/.ccache
+ path: /Users/runner/Library/Caches/ccache
key: ccache-macos-build-${{ github.sha }}
restore-keys: ccache-macos-build-
- name: install dependencies
@@ -26,6 +26,10 @@ jobs:
build-windows:
runs-on: windows-latest
+ env:
+ CCACHE_COMPRESS: 1
+ CCACHE_TEMPDIR: C:\Users\runneradmin\.ccache-temp
+ CCACHE_DIR: C:\Users\runneradmin\.ccache
defaults:
run:
shell: msys2 {0}
@@ -33,12 +37,19 @@ jobs:
- uses: actions/checkout@v1
with:
submodules: recursive
+ - uses: actions/cache@v2
+ with:
+ path: C:\Users\runneradmin\.ccache
+ key: ccache-windows-build-${{ github.sha }}
+ restore-keys: ccache-windows-build-
- uses: eine/setup-msys2@v2
with:
update: true
- install: mingw-w64-x86_64-toolchain make mingw-w64-x86_64-cmake mingw-w64-x86_64-boost mingw-w64-x86_64-openssl mingw-w64-x86_64-zeromq mingw-w64-x86_64-libsodium mingw-w64-x86_64-hidapi mingw-w64-x86_64-protobuf-c mingw-w64-x86_64-libusb git
+ install: mingw-w64-x86_64-toolchain make mingw-w64-x86_64-cmake mingw-w64-x86_64-ccache mingw-w64-x86_64-boost mingw-w64-x86_64-openssl mingw-w64-x86_64-zeromq mingw-w64-x86_64-libsodium mingw-w64-x86_64-hidapi mingw-w64-x86_64-protobuf-c mingw-w64-x86_64-libusb git
- name: build
- run: make release-static-win64 -j2
+ run: |
+ ccache --max-size=150M
+ make release-static-win64 -j2
build-ubuntu:
runs-on: ubuntu-latest
diff --git a/.gitmodules b/.gitmodules
index 9dacf534f..3cf831bcd 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -4,8 +4,7 @@
branch = monero
[submodule "external/miniupnp"]
path = external/miniupnp
- url = https://github.com/monero-project/miniupnp
- branch = monero
+ url = https://github.com/miniupnp/miniupnp
[submodule "external/rapidjson"]
path = external/rapidjson
url = https://github.com/Tencent/rapidjson
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c6d102ba7..49ac18c66 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -522,7 +522,7 @@ ExternalProject_Add(generate_translations_header
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/translations"
STAMP_DIR ${LRELEASE_PATH}
CMAKE_ARGS -DLRELEASE_PATH=${LRELEASE_PATH}
- INSTALL_COMMAND cmake -E echo "")
+ INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "")
include_directories("${CMAKE_CURRENT_BINARY_DIR}/translations")
add_subdirectory(external)
@@ -629,7 +629,7 @@ else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARCH_FLAG}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARCH_FLAG}")
- set(WARNINGS "-Wall -Wextra -Wpointer-arith -Wundef -Wvla -Wwrite-strings -Wno-error=extra -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-unused-variable -Wno-error=unused-variable -Wno-error=undef -Wno-error=uninitialized")
+ set(WARNINGS "-Wall -Wextra -Wpointer-arith -Wundef -Wvla -Wwrite-strings -Wno-error=extra -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-error=unused-variable -Wno-error=undef -Wno-error=uninitialized")
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
if(ARM)
set(WARNINGS "${WARNINGS} -Wno-error=inline-asm")
@@ -714,9 +714,10 @@ else()
endif()
# linker
- if (NOT SANITIZE AND NOT OSSFUZZ AND NOT (WIN32 AND (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 9.1)))
+ if (NOT SANITIZE AND NOT OSSFUZZ AND NOT (WIN32 AND (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND (CMAKE_C_COMPILER_VERSION VERSION_LESS 9.1 OR NOT STATIC))))
# PIE executables randomly crash at startup with ASAN
# Windows binaries die on startup with PIE when compiled with GCC <9.x
+ # Windows dynamically-linked binaries die on startup with PIE regardless of GCC version
add_linker_flag_if_supported(-pie LD_SECURITY_FLAGS)
endif()
add_linker_flag_if_supported(-Wl,-z,relro LD_SECURITY_FLAGS)
diff --git a/Dockerfile b/Dockerfile
index 61bbd76f2..51fd51e1c 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -55,8 +55,8 @@ RUN set -ex \
ENV BOOST_ROOT /usr/local/boost_${BOOST_VERSION}
# OpenSSL
-ARG OPENSSL_VERSION=1.1.1g
-ARG OPENSSL_HASH=ddb04774f1e32f0c49751e21b67216ac87852ceb056b75209af2443400636d46
+ARG OPENSSL_VERSION=1.1.1i
+ARG OPENSSL_HASH=e8be6a35fe41d10603c3cc635e93289ed00bf34b79671a3a4de64fcee00d5242
RUN set -ex \
&& curl -s -O https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz \
&& echo "${OPENSSL_HASH} openssl-${OPENSSL_VERSION}.tar.gz" | sha256sum -c \
diff --git a/Doxyfile b/Doxyfile
index 8e08ad3ec..5f9ddb7b6 100644
--- a/Doxyfile
+++ b/Doxyfile
@@ -68,7 +68,7 @@ OUTPUT_DIRECTORY = doc
# performance problems for the file system.
# The default value is: NO.
-CREATE_SUBDIRS = NO
+CREATE_SUBDIRS = YES
# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII
# characters to appear in the names of generated files. If set to NO, non-ASCII
@@ -754,7 +754,7 @@ WARN_LOGFILE =
# spaces.
# Note: If this tag is empty the current directory is searched.
-INPUT = src
+INPUT = .
# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
@@ -1552,7 +1552,7 @@ EXTRA_SEARCH_MAPPINGS =
# If the GENERATE_LATEX tag is set to YES doxygen will generate LaTeX output.
# The default value is: YES.
-GENERATE_LATEX = YES
+GENERATE_LATEX = NO
# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a
# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
diff --git a/README.md b/README.md
index d0c92a550..a3cecb3b5 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# Monero
-Copyright (c) 2014-2020 The Monero Project.
+Copyright (c) 2014-2021 The Monero Project.
Portions Copyright (c) 2012-2013 The Cryptonote developers.
## Table of Contents
diff --git a/contrib/epee/include/byte_slice.h b/contrib/epee/include/byte_slice.h
index 6b79f6d92..18d60e088 100644
--- a/contrib/epee/include/byte_slice.h
+++ b/contrib/epee/include/byte_slice.h
@@ -112,7 +112,7 @@ namespace epee
explicit byte_slice(std::string&& buffer);
//! Convert `stream` into a slice with zero allocations.
- explicit byte_slice(byte_stream&& stream) noexcept;
+ explicit byte_slice(byte_stream&& stream, bool shrink = true);
byte_slice(byte_slice&& source) noexcept;
~byte_slice() noexcept = default;
diff --git a/contrib/epee/include/misc_language.h b/contrib/epee/include/misc_language.h
index a04c63231..5ccfe6fcc 100644
--- a/contrib/epee/include/misc_language.h
+++ b/contrib/epee/include/misc_language.h
@@ -28,9 +28,11 @@
#pragma once
-#include <limits>
-#include <boost/thread.hpp>
#include <boost/utility/value_init.hpp>
+#include <boost/shared_ptr.hpp>
+#include <limits>
+#include <functional>
+#include <vector>
namespace epee
{
#define STD_TRY_BEGIN() try {
@@ -95,16 +97,7 @@ namespace misc_utils
return memcmp(&_Left, &_Right, sizeof(_Left)) < 0;
}
-
- inline
- bool sleep_no_w(long ms )
- {
- boost::this_thread::sleep(
- boost::get_system_time() +
- boost::posix_time::milliseconds( std::max<long>(ms,0) ) );
-
- return true;
- }
+ bool sleep_no_w(long ms );
template <typename T>
T get_mid(const T &a, const T &b)
diff --git a/contrib/epee/include/net/abstract_tcp_server2.h b/contrib/epee/include/net/abstract_tcp_server2.h
index 3c31cf22b..f40cd108a 100644
--- a/contrib/epee/include/net/abstract_tcp_server2.h
+++ b/contrib/epee/include/net/abstract_tcp_server2.h
@@ -265,6 +265,12 @@ namespace net_utils
template<class t_callback>
bool connect_async(const std::string& adr, const std::string& port, uint32_t conn_timeot, const t_callback &cb, const std::string& bind_ip = "0.0.0.0", epee::net_utils::ssl_support_t ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_autodetect);
+ boost::asio::ssl::context& get_ssl_context() noexcept
+ {
+ assert(m_state != nullptr);
+ return m_state->ssl_context;
+ }
+
typename t_protocol_handler::config_type& get_config_object()
{
assert(m_state != nullptr); // always set in constructor
diff --git a/contrib/epee/include/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl
index cb1388f3b..61e2b30fe 100644
--- a/contrib/epee/include/net/abstract_tcp_server2.inl
+++ b/contrib/epee/include/net/abstract_tcp_server2.inl
@@ -40,6 +40,7 @@
#include <boost/date_time/posix_time/posix_time.hpp> // TODO
#include <boost/thread/condition_variable.hpp> // TODO
#include <boost/make_shared.hpp>
+#include <boost/thread.hpp>
#include "warnings.h"
#include "string_tools.h"
#include "misc_language.h"
@@ -269,8 +270,6 @@ PRAGMA_WARNING_DISABLE_VS(4355)
//_dbg3("[sock " << socket().native_handle() << "] add_ref, m_peer_number=" << mI->m_peer_number);
CRITICAL_REGION_LOCAL(self->m_self_refs_lock);
//_dbg3("[sock " << socket().native_handle() << "] add_ref 2, m_peer_number=" << mI->m_peer_number);
- if(m_was_shutdown)
- return false;
++m_reference_count;
m_self_ref = std::move(self);
return true;
@@ -562,7 +561,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
{ // LOCK: chunking
epee::critical_region_t<decltype(m_chunking_lock)> send_guard(m_chunking_lock); // *** critical ***
- MDEBUG("do_send() will SPLIT into small chunks, from packet="<<message_size<<" B for ptr="<<message_data);
+ MDEBUG("do_send() will SPLIT into small chunks, from packet="<<message_size<<" B for ptr="<<(const void*)message_data);
// 01234567890
// ^^^^ (pos=0, len=4) ; pos:=pos+len, pos=4
// ^^^^ (pos=4, len=4) ; pos:=pos+len, pos=8
@@ -575,14 +574,14 @@ PRAGMA_WARNING_DISABLE_VS(4355)
while (!message.empty()) {
byte_slice chunk = message.take_slice(chunksize_good);
- MDEBUG("chunk_start="<<(void*)chunk.data()<<" ptr="<<message_data<<" pos="<<(chunk.data() - message_data));
+ MDEBUG("chunk_start="<<(void*)chunk.data()<<" ptr="<<(const void*)message_data<<" pos="<<(chunk.data() - message_data));
MDEBUG("part of " << message.size() << ": pos="<<(chunk.data() - message_data) << " len="<<chunk.size());
bool ok = do_send_chunk(std::move(chunk)); // <====== ***
all_ok = all_ok && ok;
if (!all_ok) {
- MDEBUG("do_send() DONE ***FAILED*** from packet="<<message_size<<" B for ptr="<<message_data);
+ MDEBUG("do_send() DONE ***FAILED*** from packet="<<message_size<<" B for ptr="<<(const void*)message_data);
MDEBUG("do_send() SEND was aborted in middle of big package - this is mostly harmless "
<< " (e.g. peer closed connection) but if it causes trouble tell us at #monero-dev. " << message_size);
return false; // partial failure in sending
@@ -590,7 +589,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
// (in catch block, or uniq pointer) delete buf;
} // each chunk
- MDEBUG("do_send() DONE SPLIT from packet="<<message_size<<" B for ptr="<<message_data);
+ MDEBUG("do_send() DONE SPLIT from packet="<<message_size<<" B for ptr="<<(const void*)message_data);
MDEBUG("do_send() m_connection_type = " << m_connection_type);
diff --git a/contrib/epee/include/net/http_server_handlers_map2.h b/contrib/epee/include/net/http_server_handlers_map2.h
index 1665fdac7..ffb3f3b7e 100644
--- a/contrib/epee/include/net/http_server_handlers_map2.h
+++ b/contrib/epee/include/net/http_server_handlers_map2.h
@@ -74,7 +74,13 @@
uint64_t ticks = misc_utils::get_tick_count(); \
boost::value_initialized<command_type::request> req; \
bool parse_res = epee::serialization::load_t_from_json(static_cast<command_type::request&>(req), query_info.m_body); \
- CHECK_AND_ASSERT_MES(parse_res, false, "Failed to parse json: \r\n" << query_info.m_body); \
+ if (!parse_res) \
+ { \
+ MERROR("Failed to parse json: \r\n" << query_info.m_body); \
+ response_info.m_response_code = 400; \
+ response_info.m_response_comment = "Bad request"; \
+ return true; \
+ } \
uint64_t ticks1 = epee::misc_utils::get_tick_count(); \
boost::value_initialized<command_type::response> resp;\
MINFO(m_conn_context << "calling " << s_pattern); \
@@ -104,7 +110,13 @@
uint64_t ticks = misc_utils::get_tick_count(); \
boost::value_initialized<command_type::request> req; \
bool parse_res = epee::serialization::load_t_from_binary(static_cast<command_type::request&>(req), epee::strspan<uint8_t>(query_info.m_body)); \
- CHECK_AND_ASSERT_MES(parse_res, false, "Failed to parse bin body data, body size=" << query_info.m_body.size()); \
+ if (!parse_res) \
+ { \
+ MERROR("Failed to parse bin body data, body size=" << query_info.m_body.size()); \
+ response_info.m_response_code = 400; \
+ response_info.m_response_comment = "Bad request"; \
+ return true; \
+ } \
uint64_t ticks1 = misc_utils::get_tick_count(); \
boost::value_initialized<command_type::response> resp;\
MINFO(m_conn_context << "calling " << s_pattern); \
diff --git a/contrib/epee/include/net/levin_protocol_handler_async.h b/contrib/epee/include/net/levin_protocol_handler_async.h
index ddde701ee..f6b73a2d5 100644
--- a/contrib/epee/include/net/levin_protocol_handler_async.h
+++ b/contrib/epee/include/net/levin_protocol_handler_async.h
@@ -146,7 +146,6 @@ public:
stream_state_body
};
- std::atomic<bool> m_deletion_initiated;
std::atomic<bool> m_protocol_released;
volatile uint32_t m_invoke_buf_ready;
@@ -297,7 +296,6 @@ public:
m_state(stream_state_head)
{
m_close_called = 0;
- m_deletion_initiated = false;
m_protocol_released = false;
m_wait_count = 0;
m_oponent_protocol_ver = 0;
@@ -310,7 +308,6 @@ public:
try
{
- m_deletion_initiated = true;
if(m_connection_initialized)
{
m_config.del_connection(this);
@@ -633,20 +630,8 @@ public:
int err_code = LEVIN_OK;
do
{
- if(m_deletion_initiated)
- {
- err_code = LEVIN_ERROR_CONNECTION_DESTROYED;
- break;
- }
-
CRITICAL_REGION_LOCAL(m_call_lock);
- if(m_deletion_initiated)
- {
- err_code = LEVIN_ERROR_CONNECTION_DESTROYED;
- break;
- }
-
boost::interprocess::ipcdetail::atomic_write32(&m_invoke_buf_ready, 0);
CRITICAL_REGION_BEGIN(m_invoke_response_handlers_lock);
@@ -684,14 +669,8 @@ public:
misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler(
boost::bind(&async_protocol_handler::finish_outer_call, this));
- if(m_deletion_initiated)
- return LEVIN_ERROR_CONNECTION_DESTROYED;
-
CRITICAL_REGION_LOCAL(m_call_lock);
- if(m_deletion_initiated)
- return LEVIN_ERROR_CONNECTION_DESTROYED;
-
boost::interprocess::ipcdetail::atomic_write32(&m_invoke_buf_ready, 0);
if (command == m_connection_context.handshake_command())
@@ -706,7 +685,7 @@ public:
uint64_t ticks_start = misc_utils::get_tick_count();
size_t prev_size = 0;
- while(!boost::interprocess::ipcdetail::atomic_read32(&m_invoke_buf_ready) && !m_deletion_initiated && !m_protocol_released)
+ while(!boost::interprocess::ipcdetail::atomic_read32(&m_invoke_buf_ready) && !m_protocol_released)
{
if(m_cache_in_buffer.size() - prev_size >= MIN_BYTES_WANTED)
{
@@ -723,7 +702,7 @@ public:
return LEVIN_ERROR_CONNECTION_DESTROYED;
}
- if(m_deletion_initiated || m_protocol_released)
+ if(m_protocol_released)
return LEVIN_ERROR_CONNECTION_DESTROYED;
CRITICAL_REGION_BEGIN(m_local_inv_buff_lock);
@@ -739,14 +718,8 @@ public:
misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler(
boost::bind(&async_protocol_handler::finish_outer_call, this));
- if(m_deletion_initiated)
- return LEVIN_ERROR_CONNECTION_DESTROYED;
-
CRITICAL_REGION_LOCAL(m_call_lock);
- if(m_deletion_initiated)
- return LEVIN_ERROR_CONNECTION_DESTROYED;
-
if (!send_message(command, in_buff, LEVIN_PACKET_REQUEST, false))
{
LOG_ERROR_CC(m_connection_context, "Failed to send notify message");
@@ -768,9 +741,6 @@ public:
boost::bind(&async_protocol_handler::finish_outer_call, this)
);
- if(m_deletion_initiated)
- return LEVIN_ERROR_CONNECTION_DESTROYED;
-
const std::size_t length = message.size();
if (!m_pservice_endpoint->do_send(std::move(message)))
{
@@ -817,7 +787,7 @@ void async_protocol_handler_config<t_connection_context>::delete_connections(siz
{
auto i = connections.end() - 1;
async_protocol_handler<t_connection_context> *conn = m_connects.at(*i);
- del_connection(conn);
+ m_connects.erase(*i);
conn->close();
connections.erase(i);
}
@@ -891,12 +861,22 @@ template<class t_connection_context> template<class callback_t>
bool async_protocol_handler_config<t_connection_context>::foreach_connection(const callback_t &cb)
{
CRITICAL_REGION_LOCAL(m_connects_lock);
- for(auto& c: m_connects)
- {
- async_protocol_handler<t_connection_context>* aph = c.second;
- if(!cb(aph->get_context_ref()))
+ std::vector<typename connections_map::mapped_type> conn;
+ conn.reserve(m_connects.size());
+
+ auto scope_exit_handler = misc_utils::create_scope_leave_handler([&conn]{
+ for (auto &aph: conn)
+ aph->finish_outer_call();
+ });
+
+ for (auto &e: m_connects)
+ if (e.second->start_outer_call())
+ conn.push_back(e.second);
+
+ for (auto &aph: conn)
+ if (!cb(aph->get_context_ref()))
return false;
- }
+
return true;
}
//------------------------------------------------------------------------------------------
@@ -907,6 +887,10 @@ bool async_protocol_handler_config<t_connection_context>::for_connection(const b
async_protocol_handler<t_connection_context>* aph = find_connection(connection_id);
if (!aph)
return false;
+ if (!aph->start_outer_call())
+ return false;
+ auto scope_exit_handler = misc_utils::create_scope_leave_handler(
+ boost::bind(&async_protocol_handler<t_connection_context>::finish_outer_call, aph));
if(!cb(aph->get_context_ref()))
return false;
return true;
diff --git a/contrib/epee/include/net/net_ssl.h b/contrib/epee/include/net/net_ssl.h
index 1b1577e77..58cd7e45f 100644
--- a/contrib/epee/include/net/net_ssl.h
+++ b/contrib/epee/include/net/net_ssl.h
@@ -36,6 +36,7 @@
#include <boost/utility/string_ref.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/ssl.hpp>
+#include <boost/filesystem/path.hpp>
#include <boost/system/error_code.hpp>
#define SSL_FINGERPRINT_SIZE 32
@@ -144,6 +145,9 @@ namespace net_utils
bool create_ec_ssl_certificate(EVP_PKEY *&pkey, X509 *&cert);
bool create_rsa_ssl_certificate(EVP_PKEY *&pkey, X509 *&cert);
+
+ //! Store private key for `ssl` at `base + ".key"` unencrypted and certificate for `ssl` at `base + ".crt"`.
+ boost::system::error_code store_ssl_keys(boost::asio::ssl::context& ssl, const boost::filesystem::path& base);
}
}
diff --git a/contrib/epee/include/storages/portable_storage.h b/contrib/epee/include/storages/portable_storage.h
index f77e89cb6..c5d0c48ee 100644
--- a/contrib/epee/include/storages/portable_storage.h
+++ b/contrib/epee/include/storages/portable_storage.h
@@ -24,20 +24,12 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
-
-
#pragma once
-#include <type_traits>
-
-#include "misc_language.h"
#include "portable_storage_base.h"
-#include "portable_storage_from_bin.h"
-#include "portable_storage_to_json.h"
-#include "portable_storage_from_json.h"
#include "portable_storage_val_converters.h"
+#include "misc_log_ex.h"
#include "span.h"
-#include "int-util.h"
namespace epee
{
@@ -92,7 +84,7 @@ namespace epee
//-------------------------------------------------------------------------------
bool store_to_binary(byte_slice& target, std::size_t initial_buffer_size = 8192);
bool load_from_binary(const epee::span<const uint8_t> target, const limits_t *limits = NULL);
- bool load_from_binary(const std::string& target, const limits_t *limits = NULL) { return load_from_binary(epee::strspan<uint8_t>(target), limits); }
+ bool load_from_binary(const std::string& target, const limits_t *limits = NULL);
template<class trace_policy>
bool dump_as_xml(std::string& targetObj, const std::string& root_name = "");
bool dump_as_json(std::string& targetObj, size_t indent = 0, bool insert_newlines = true);
@@ -117,85 +109,13 @@ namespace epee
};
#pragma pack(pop)
};
- inline
- bool portable_storage::dump_as_json(std::string& buff, size_t indent, bool insert_newlines)
- {
- TRY_ENTRY();
- std::stringstream ss;
- epee::serialization::dump_as_json(ss, m_root, indent, insert_newlines);
- buff = ss.str();
- return true;
- CATCH_ENTRY("portable_storage::dump_as_json", false)
- }
- inline
- bool portable_storage::load_from_json(const std::string& source)
- {
- TRY_ENTRY();
- return json::load_from_json(source, *this);
- CATCH_ENTRY("portable_storage::load_from_json", false)
- }
-
+
template<class trace_policy>
bool portable_storage::dump_as_xml(std::string& targetObj, const std::string& root_name)
{
return false;//TODO: don't think i ever again will use xml - ambiguous and "overtagged" format
- }
- inline
- bool portable_storage::load_from_binary(const epee::span<const uint8_t> source, const limits_t *limits)
- {
- m_root.m_entries.clear();
- if(source.size() < sizeof(storage_block_header))
- {
- LOG_ERROR("portable_storage: wrong binary format, packet size = " << source.size() << " less than expected sizeof(storage_block_header)=" << sizeof(storage_block_header));
- return false;
- }
- storage_block_header* pbuff = (storage_block_header*)source.data();
- if(pbuff->m_signature_a != SWAP32LE(PORTABLE_STORAGE_SIGNATUREA) ||
- pbuff->m_signature_b != SWAP32LE(PORTABLE_STORAGE_SIGNATUREB)
- )
- {
- LOG_ERROR("portable_storage: wrong binary format - signature mismatch");
- return false;
- }
- if(pbuff->m_ver != PORTABLE_STORAGE_FORMAT_VER)
- {
- LOG_ERROR("portable_storage: wrong binary format - unknown format ver = " << pbuff->m_ver);
- return false;
- }
- TRY_ENTRY();
- throwable_buffer_reader buf_reader(source.data()+sizeof(storage_block_header), source.size()-sizeof(storage_block_header));
- if (limits)
- buf_reader.set_limits(limits->n_objects, limits->n_fields, limits->n_strings);
- buf_reader.read(m_root);
- return true;//TODO:
- CATCH_ENTRY("portable_storage::load_from_binary", false);
- }
- //---------------------------------------------------------------------------------------------------------------
- inline
- hsection portable_storage::open_section(const std::string& section_name, hsection hparent_section, bool create_if_notexist)
- {
- TRY_ENTRY();
- hparent_section = hparent_section ? hparent_section:&m_root;
- storage_entry* pentry = find_storage_entry(section_name, hparent_section);
- if(!pentry)
- {
- if(!create_if_notexist)
- return nullptr;
- return insert_new_section(section_name, hparent_section);
- }
- CHECK_AND_ASSERT(pentry , nullptr);
- //check that section_entry we find is real "CSSection"
- if(pentry->type() != typeid(section))
- {
- if(create_if_notexist)
- *pentry = storage_entry(section());//replace
- else
- return nullptr;
- }
- return &boost::get<section>(*pentry);
- CATCH_ENTRY("portable_storage::open_section", nullptr);
- }
- //---------------------------------------------------------------------------------------------------------------
+ }
+
template<class to_type>
struct get_value_visitor: boost::static_visitor<void>
{
@@ -221,20 +141,6 @@ namespace epee
//CATCH_ENTRY("portable_storage::template<>get_value", false);
}
//---------------------------------------------------------------------------------------------------------------
- inline
- bool portable_storage::get_value(const std::string& value_name, storage_entry& val, hsection hparent_section)
- {
- //TRY_ENTRY();
- if(!hparent_section) hparent_section = &m_root;
- storage_entry* pentry = find_storage_entry(value_name, hparent_section);
- if(!pentry)
- return false;
-
- val = *pentry;
- return true;
- //CATCH_ENTRY("portable_storage::template<>get_value", false);
- }
- //---------------------------------------------------------------------------------------------------------------
template<class t_value>
bool portable_storage::set_value(const std::string& value_name, t_value&& v, hsection hparent_section)
{
@@ -256,19 +162,6 @@ namespace epee
CATCH_ENTRY("portable_storage::template<>set_value", false);
}
//---------------------------------------------------------------------------------------------------------------
- inline
- storage_entry* portable_storage::find_storage_entry(const std::string& pentry_name, hsection psection)
- {
- TRY_ENTRY();
- CHECK_AND_ASSERT(psection, nullptr);
- auto it = psection->m_entries.find(pentry_name);
- if(it == psection->m_entries.end())
- return nullptr;
-
- return &it->second;
- CATCH_ENTRY("portable_storage::find_storage_entry", nullptr);
- }
- //---------------------------------------------------------------------------------------------------------------
template<class entry_type>
storage_entry* portable_storage::insert_new_entry_get_storage_entry(const std::string& pentry_name, hsection psection, entry_type&& entry)
{
@@ -281,16 +174,6 @@ namespace epee
CATCH_ENTRY("portable_storage::insert_new_entry_get_storage_entry", nullptr);
}
//---------------------------------------------------------------------------------------------------------------
- inline
- hsection portable_storage::insert_new_section(const std::string& pentry_name, hsection psection)
- {
- TRY_ENTRY();
- storage_entry* pse = insert_new_entry_get_storage_entry(pentry_name, psection, section());
- if(!pse) return nullptr;
- return &boost::get<section>(*pse);
- CATCH_ENTRY("portable_storage::insert_new_section", nullptr);
- }
- //---------------------------------------------------------------------------------------------------------------
template<class to_type>
struct get_first_value_visitor: boost::static_visitor<bool>
{
@@ -344,7 +227,6 @@ namespace epee
}
};
-
template<class t_value>
bool portable_storage::get_next_value(harray hval_array, t_value& target)
{
@@ -402,83 +284,5 @@ namespace epee
return true;
CATCH_ENTRY("portable_storage::insert_next_value", false);
}
- //---------------------------------------------------------------------------------------------------------------
- //sections
- inline
- harray portable_storage::get_first_section(const std::string& sec_name, hsection& h_child_section, hsection hparent_section)
- {
- TRY_ENTRY();
- if(!hparent_section) hparent_section = &m_root;
- storage_entry* pentry = find_storage_entry(sec_name, hparent_section);
- if(!pentry)
- return nullptr;
- if(pentry->type() != typeid(array_entry))
- return nullptr;
- array_entry& ar_entry = boost::get<array_entry>(*pentry);
- if(ar_entry.type() != typeid(array_entry_t<section>))
- return nullptr;
- array_entry_t<section>& sec_array = boost::get<array_entry_t<section>>(ar_entry);
- section* psec = sec_array.get_first_val();
- if(!psec)
- return nullptr;
- h_child_section = psec;
- return &ar_entry;
- CATCH_ENTRY("portable_storage::get_first_section", nullptr);
- }
- //---------------------------------------------------------------------------------------------------------------
- inline
- bool portable_storage::get_next_section(harray hsec_array, hsection& h_child_section)
- {
- TRY_ENTRY();
- CHECK_AND_ASSERT(hsec_array, false);
- if(hsec_array->type() != typeid(array_entry_t<section>))
- return false;
- array_entry_t<section>& sec_array = boost::get<array_entry_t<section>>(*hsec_array);
- h_child_section = sec_array.get_next_val();
- if(!h_child_section)
- return false;
- return true;
- CATCH_ENTRY("portable_storage::get_next_section", false);
- }
- //---------------------------------------------------------------------------------------------------------------
- inline
- harray portable_storage::insert_first_section(const std::string& sec_name, hsection& hinserted_childsection, hsection hparent_section)
- {
- TRY_ENTRY();
- if(!hparent_section) hparent_section = &m_root;
- storage_entry* pentry = find_storage_entry(sec_name, hparent_section);
- if(!pentry)
- {
- pentry = insert_new_entry_get_storage_entry(sec_name, hparent_section, array_entry(array_entry_t<section>()));
- if(!pentry)
- return nullptr;
- }
- if(pentry->type() != typeid(array_entry))
- *pentry = storage_entry(array_entry(array_entry_t<section>()));
-
- array_entry& ar_entry = boost::get<array_entry>(*pentry);
- if(ar_entry.type() != typeid(array_entry_t<section>))
- ar_entry = array_entry(array_entry_t<section>());
-
- array_entry_t<section>& sec_array = boost::get<array_entry_t<section>>(ar_entry);
- hinserted_childsection = &sec_array.insert_first_val(section());
- return &ar_entry;
- CATCH_ENTRY("portable_storage::insert_first_section", nullptr);
- }
- //---------------------------------------------------------------------------------------------------------------
- inline
- bool portable_storage::insert_next_section(harray hsec_array, hsection& hinserted_childsection)
- {
- TRY_ENTRY();
- CHECK_AND_ASSERT(hsec_array, false);
- CHECK_AND_ASSERT_MES(hsec_array->type() == typeid(array_entry_t<section>),
- false, "unexpected type(not 'section') in insert_next_section, type: " << hsec_array->type().name());
-
- array_entry_t<section>& sec_array = boost::get<array_entry_t<section>>(*hsec_array);
- hinserted_childsection = &sec_array.insert_next_value(section());
- return true;
- CATCH_ENTRY("portable_storage::insert_next_section", false);
- }
- //---------------------------------------------------------------------------------------------------------------
}
}
diff --git a/contrib/epee/include/storages/portable_storage_base.h b/contrib/epee/include/storages/portable_storage_base.h
index 1676f41fb..ae0be6a34 100644
--- a/contrib/epee/include/storages/portable_storage_base.h
+++ b/contrib/epee/include/storages/portable_storage_base.h
@@ -29,10 +29,10 @@
#pragma once
#include <boost/variant.hpp>
-#include <boost/any.hpp>
#include <string>
#include <vector>
#include <deque>
+#include <map>
#define PORTABLE_STORAGE_SIGNATUREA 0x01011101
#define PORTABLE_STORAGE_SIGNATUREB 0x01020101 // bender's nightmare
diff --git a/contrib/epee/include/storages/portable_storage_from_json.h b/contrib/epee/include/storages/portable_storage_from_json.h
index 2b2dc7ff9..3021598f5 100644
--- a/contrib/epee/include/storages/portable_storage_from_json.h
+++ b/contrib/epee/include/storages/portable_storage_from_json.h
@@ -26,6 +26,7 @@
#pragma once
#include <boost/lexical_cast.hpp>
+#include <boost/utility/string_ref.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include "parserse_base_utils.h"
#include "file_io_utils.h"
diff --git a/contrib/epee/include/storages/portable_storage_template_helper.h b/contrib/epee/include/storages/portable_storage_template_helper.h
index 16dd565ec..e7250e895 100644
--- a/contrib/epee/include/storages/portable_storage_template_helper.h
+++ b/contrib/epee/include/storages/portable_storage_template_helper.h
@@ -32,6 +32,7 @@
#include "parserse_base_utils.h"
#include "portable_storage.h"
#include "file_io_utils.h"
+#include "span.h"
namespace epee
{
diff --git a/contrib/epee/include/storages/portable_storage_to_bin.h b/contrib/epee/include/storages/portable_storage_to_bin.h
index 49a7be185..b82cf532b 100644
--- a/contrib/epee/include/storages/portable_storage_to_bin.h
+++ b/contrib/epee/include/storages/portable_storage_to_bin.h
@@ -32,6 +32,7 @@
#include "misc_language.h"
#include "portable_storage_base.h"
#include "portable_storage_bin_utils.h"
+#include "misc_log_ex.h"
namespace epee
{
diff --git a/contrib/epee/include/storages/portable_storage_val_converters.h b/contrib/epee/include/storages/portable_storage_val_converters.h
index e54cda828..96b0c024c 100644
--- a/contrib/epee/include/storages/portable_storage_val_converters.h
+++ b/contrib/epee/include/storages/portable_storage_val_converters.h
@@ -28,12 +28,17 @@
#pragma once
-#include <time.h>
#include <boost/regex.hpp>
#include "misc_language.h"
#include "portable_storage_base.h"
+#include "parserse_base_utils.h"
#include "warnings.h"
+#include "misc_log_ex.h"
+
+#include <boost/lexical_cast.hpp>
+#include <typeinfo>
+#include <iomanip>
namespace epee
{
diff --git a/contrib/epee/src/CMakeLists.txt b/contrib/epee/src/CMakeLists.txt
index 5e101a86a..641d4718e 100644
--- a/contrib/epee/src/CMakeLists.txt
+++ b/contrib/epee/src/CMakeLists.txt
@@ -29,7 +29,9 @@
add_library(epee STATIC byte_slice.cpp byte_stream.cpp hex.cpp abstract_http_client.cpp http_auth.cpp mlog.cpp net_helper.cpp net_utils_base.cpp string_tools.cpp
wipeable_string.cpp levin_base.cpp memwipe.c connection_basic.cpp network_throttle.cpp network_throttle-detail.cpp mlocker.cpp buffer.cpp net_ssl.cpp
- int-util.cpp portable_storage.cpp)
+ int-util.cpp portable_storage.cpp
+ misc_language.cpp
+ )
if (USE_READLINE AND (GNU_READLINE_FOUND OR (DEPENDS AND NOT MINGW)))
add_library(epee_readline STATIC readline_buffer.cpp)
@@ -71,3 +73,6 @@ if (USE_READLINE AND (GNU_READLINE_FOUND OR (DEPENDS AND NOT MINGW)))
PRIVATE
${GNU_READLINE_LIBRARY})
endif()
+
+target_include_directories(epee PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../include")
+
diff --git a/contrib/epee/src/byte_slice.cpp b/contrib/epee/src/byte_slice.cpp
index faf7689be..453b63a4c 100644
--- a/contrib/epee/src/byte_slice.cpp
+++ b/contrib/epee/src/byte_slice.cpp
@@ -36,6 +36,11 @@
#include "byte_slice.h"
#include "byte_stream.h"
+namespace
+{
+ const std::size_t page_size = 4096;
+}
+
namespace epee
{
struct byte_slice_data
@@ -173,16 +178,27 @@ namespace epee
: byte_slice(adapt_buffer{}, std::move(buffer))
{}
- byte_slice::byte_slice(byte_stream&& stream) noexcept
+ byte_slice::byte_slice(byte_stream&& stream, const bool shrink)
: storage_(nullptr), portion_(stream.data(), stream.size())
{
- if (stream.size())
+ if (portion_.size())
{
- std::uint8_t* const data = stream.take_buffer().release() - sizeof(raw_byte_slice);
+ byte_buffer buf;
+ if (shrink && page_size <= stream.available())
+ {
+ buf = byte_buffer_resize(stream.take_buffer(), portion_.size());
+ if (!buf)
+ throw std::bad_alloc{};
+ portion_ = {buf.get(), portion_.size()};
+ }
+ else // no need to shrink buffer
+ buf = stream.take_buffer();
+
+ std::uint8_t* const data = buf.release() - sizeof(raw_byte_slice);
new (data) raw_byte_slice{};
storage_.reset(reinterpret_cast<raw_byte_slice*>(data));
}
- else
+ else // empty stream
portion_ = nullptr;
}
diff --git a/contrib/epee/src/misc_language.cpp b/contrib/epee/src/misc_language.cpp
new file mode 100644
index 000000000..6e8f2daef
--- /dev/null
+++ b/contrib/epee/src/misc_language.cpp
@@ -0,0 +1,44 @@
+// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// * Neither the name of the Andrey N. Sabelnikov nor the
+// names of its contributors may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
+// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+
+#include "misc_language.h"
+
+#include <boost/thread.hpp>
+
+namespace epee
+{
+namespace misc_utils
+{
+ bool sleep_no_w(long ms )
+ {
+ boost::this_thread::sleep(
+ boost::get_system_time() +
+ boost::posix_time::milliseconds( std::max<long>(ms,0) ) );
+
+ return true;
+ }
+}
+}
diff --git a/contrib/epee/src/net_ssl.cpp b/contrib/epee/src/net_ssl.cpp
index 6ed27efa9..765dadce3 100644
--- a/contrib/epee/src/net_ssl.cpp
+++ b/contrib/epee/src/net_ssl.cpp
@@ -29,6 +29,8 @@
#include <string.h>
#include <thread>
#include <boost/asio/ssl.hpp>
+#include <boost/cerrno.hpp>
+#include <boost/filesystem/operations.hpp>
#include <boost/lambda/lambda.hpp>
#include <openssl/ssl.h>
#include <openssl/pem.h>
@@ -567,6 +569,51 @@ bool ssl_support_from_string(ssl_support_t &ssl, boost::string_ref s)
return true;
}
+boost::system::error_code store_ssl_keys(boost::asio::ssl::context& ssl, const boost::filesystem::path& base)
+{
+ EVP_PKEY* ssl_key = nullptr;
+ X509* ssl_cert = nullptr;
+ const auto ctx = ssl.native_handle();
+ CHECK_AND_ASSERT_MES(ctx, boost::system::error_code(EINVAL, boost::system::system_category()), "Context is null");
+ CHECK_AND_ASSERT_MES(base.has_filename(), boost::system::error_code(EINVAL, boost::system::system_category()), "Need filename");
+ if (!(ssl_key = SSL_CTX_get0_privatekey(ctx)) || !(ssl_cert = SSL_CTX_get0_certificate(ctx)))
+ return {EINVAL, boost::system::system_category()};
+
+ using file_closer = int(std::FILE*);
+ boost::system::error_code error{};
+ std::unique_ptr<std::FILE, file_closer*> file{nullptr, std::fclose};
+
+ // write key file unencrypted
+ {
+ const boost::filesystem::path key_file{base.string() + ".key"};
+ file.reset(std::fopen(key_file.string().c_str(), "wb"));
+ if (!file)
+ return {errno, boost::system::system_category()};
+ boost::filesystem::permissions(key_file, boost::filesystem::owner_read, error);
+ if (error)
+ return error;
+ if (!PEM_write_PrivateKey(file.get(), ssl_key, nullptr, nullptr, 0, nullptr, nullptr))
+ return boost::asio::error::ssl_errors(ERR_get_error());
+ if (std::fclose(file.release()) != 0)
+ return {errno, boost::system::system_category()};
+ }
+
+ // write certificate file in standard SSL X.509 unencrypted
+ const boost::filesystem::path cert_file{base.string() + ".crt"};
+ file.reset(std::fopen(cert_file.string().c_str(), "wb"));
+ if (!file)
+ return {errno, boost::system::system_category()};
+ const auto cert_perms = (boost::filesystem::owner_read | boost::filesystem::group_read | boost::filesystem::others_read);
+ boost::filesystem::permissions(cert_file, cert_perms, error);
+ if (error)
+ return error;
+ if (!PEM_write_X509(file.get(), ssl_cert))
+ return boost::asio::error::ssl_errors(ERR_get_error());
+ if (std::fclose(file.release()) != 0)
+ return {errno, boost::system::system_category()};
+ return error;
+}
+
} // namespace
} // namespace
diff --git a/contrib/epee/src/portable_storage.cpp b/contrib/epee/src/portable_storage.cpp
index 4534deff3..c3c9ccc02 100644
--- a/contrib/epee/src/portable_storage.cpp
+++ b/contrib/epee/src/portable_storage.cpp
@@ -1,10 +1,43 @@
+// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// * Neither the name of the Andrey N. Sabelnikov nor the
+// names of its contributors may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
+// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
#include "byte_slice.h"
#include "byte_stream.h"
#include "misc_log_ex.h"
#include "span.h"
#include "storages/portable_storage.h"
+#include "storages/portable_storage_to_json.h"
+#include "storages/portable_storage_from_json.h"
#include "storages/portable_storage_to_bin.h"
+#include "storages/portable_storage_from_bin.h"
+
+#include <boost/utility/string_ref.hpp>
+
+#include <string>
+#include <sstream>
namespace epee
{
@@ -25,5 +58,187 @@ namespace serialization
return true;
CATCH_ENTRY("portable_storage::store_to_binary", false)
}
+
+ bool portable_storage::dump_as_json(std::string& buff, size_t indent, bool insert_newlines)
+ {
+ TRY_ENTRY();
+ std::stringstream ss;
+ epee::serialization::dump_as_json(ss, m_root, indent, insert_newlines);
+ buff = ss.str();
+ return true;
+ CATCH_ENTRY("portable_storage::dump_as_json", false)
+ }
+
+ bool portable_storage::load_from_json(const std::string& source)
+ {
+ TRY_ENTRY();
+ return json::load_from_json(source, *this);
+ CATCH_ENTRY("portable_storage::load_from_json", false)
+ }
+
+ bool portable_storage::load_from_binary(const std::string& target, const limits_t *limits)
+ {
+ return load_from_binary(epee::strspan<uint8_t>(target), limits);
+ }
+
+ bool portable_storage::load_from_binary(const epee::span<const uint8_t> source, const limits_t *limits)
+ {
+ m_root.m_entries.clear();
+ if(source.size() < sizeof(storage_block_header))
+ {
+ LOG_ERROR("portable_storage: wrong binary format, packet size = " << source.size() << " less than expected sizeof(storage_block_header)=" << sizeof(storage_block_header));
+ return false;
+ }
+ storage_block_header* pbuff = (storage_block_header*)source.data();
+ if(pbuff->m_signature_a != SWAP32LE(PORTABLE_STORAGE_SIGNATUREA) ||
+ pbuff->m_signature_b != SWAP32LE(PORTABLE_STORAGE_SIGNATUREB)
+ )
+ {
+ LOG_ERROR("portable_storage: wrong binary format - signature mismatch");
+ return false;
+ }
+ if(pbuff->m_ver != PORTABLE_STORAGE_FORMAT_VER)
+ {
+ LOG_ERROR("portable_storage: wrong binary format - unknown format ver = " << pbuff->m_ver);
+ return false;
+ }
+ TRY_ENTRY();
+ throwable_buffer_reader buf_reader(source.data()+sizeof(storage_block_header), source.size()-sizeof(storage_block_header));
+ if (limits)
+ buf_reader.set_limits(limits->n_objects, limits->n_fields, limits->n_strings);
+ buf_reader.read(m_root);
+ return true;//TODO:
+ CATCH_ENTRY("portable_storage::load_from_binary", false);
+ }
+
+ hsection portable_storage::open_section(const std::string& section_name, hsection hparent_section, bool create_if_notexist)
+ {
+ TRY_ENTRY();
+ hparent_section = hparent_section ? hparent_section:&m_root;
+ storage_entry* pentry = find_storage_entry(section_name, hparent_section);
+ if(!pentry)
+ {
+ if(!create_if_notexist)
+ return nullptr;
+ return insert_new_section(section_name, hparent_section);
+ }
+ CHECK_AND_ASSERT(pentry , nullptr);
+ //check that section_entry we find is real "CSSection"
+ if(pentry->type() != typeid(section))
+ {
+ if(create_if_notexist)
+ *pentry = storage_entry(section());//replace
+ else
+ return nullptr;
+ }
+ return &boost::get<section>(*pentry);
+ CATCH_ENTRY("portable_storage::open_section", nullptr);
+ }
+
+ bool portable_storage::get_value(const std::string& value_name, storage_entry& val, hsection hparent_section)
+ {
+ //TRY_ENTRY();
+ if(!hparent_section) hparent_section = &m_root;
+ storage_entry* pentry = find_storage_entry(value_name, hparent_section);
+ if(!pentry)
+ return false;
+
+ val = *pentry;
+ return true;
+ //CATCH_ENTRY("portable_storage::template<>get_value", false);
+ }
+
+ storage_entry* portable_storage::find_storage_entry(const std::string& pentry_name, hsection psection)
+ {
+ TRY_ENTRY();
+ CHECK_AND_ASSERT(psection, nullptr);
+ auto it = psection->m_entries.find(pentry_name);
+ if(it == psection->m_entries.end())
+ return nullptr;
+
+ return &it->second;
+ CATCH_ENTRY("portable_storage::find_storage_entry", nullptr);
+ }
+
+ hsection portable_storage::insert_new_section(const std::string& pentry_name, hsection psection)
+ {
+ TRY_ENTRY();
+ storage_entry* pse = insert_new_entry_get_storage_entry(pentry_name, psection, section());
+ if(!pse) return nullptr;
+ return &boost::get<section>(*pse);
+ CATCH_ENTRY("portable_storage::insert_new_section", nullptr);
+ }
+
+ harray portable_storage::get_first_section(const std::string& sec_name, hsection& h_child_section, hsection hparent_section)
+ {
+ TRY_ENTRY();
+ if(!hparent_section) hparent_section = &m_root;
+ storage_entry* pentry = find_storage_entry(sec_name, hparent_section);
+ if(!pentry)
+ return nullptr;
+ if(pentry->type() != typeid(array_entry))
+ return nullptr;
+ array_entry& ar_entry = boost::get<array_entry>(*pentry);
+ if(ar_entry.type() != typeid(array_entry_t<section>))
+ return nullptr;
+ array_entry_t<section>& sec_array = boost::get<array_entry_t<section>>(ar_entry);
+ section* psec = sec_array.get_first_val();
+ if(!psec)
+ return nullptr;
+ h_child_section = psec;
+ return &ar_entry;
+ CATCH_ENTRY("portable_storage::get_first_section", nullptr);
+ }
+
+ bool portable_storage::get_next_section(harray hsec_array, hsection& h_child_section)
+ {
+ TRY_ENTRY();
+ CHECK_AND_ASSERT(hsec_array, false);
+ if(hsec_array->type() != typeid(array_entry_t<section>))
+ return false;
+ array_entry_t<section>& sec_array = boost::get<array_entry_t<section>>(*hsec_array);
+ h_child_section = sec_array.get_next_val();
+ if(!h_child_section)
+ return false;
+ return true;
+ CATCH_ENTRY("portable_storage::get_next_section", false);
+ }
+
+ harray portable_storage::insert_first_section(const std::string& sec_name, hsection& hinserted_childsection, hsection hparent_section)
+ {
+ TRY_ENTRY();
+ if(!hparent_section) hparent_section = &m_root;
+ storage_entry* pentry = find_storage_entry(sec_name, hparent_section);
+ if(!pentry)
+ {
+ pentry = insert_new_entry_get_storage_entry(sec_name, hparent_section, array_entry(array_entry_t<section>()));
+ if(!pentry)
+ return nullptr;
+ }
+ if(pentry->type() != typeid(array_entry))
+ *pentry = storage_entry(array_entry(array_entry_t<section>()));
+
+ array_entry& ar_entry = boost::get<array_entry>(*pentry);
+ if(ar_entry.type() != typeid(array_entry_t<section>))
+ ar_entry = array_entry(array_entry_t<section>());
+
+ array_entry_t<section>& sec_array = boost::get<array_entry_t<section>>(ar_entry);
+ hinserted_childsection = &sec_array.insert_first_val(section());
+ return &ar_entry;
+ CATCH_ENTRY("portable_storage::insert_first_section", nullptr);
+ }
+
+ bool portable_storage::insert_next_section(harray hsec_array, hsection& hinserted_childsection)
+ {
+ TRY_ENTRY();
+ CHECK_AND_ASSERT(hsec_array, false);
+ CHECK_AND_ASSERT_MES(hsec_array->type() == typeid(array_entry_t<section>),
+ false, "unexpected type(not 'section') in insert_next_section, type: " << hsec_array->type().name());
+
+ array_entry_t<section>& sec_array = boost::get<array_entry_t<section>>(*hsec_array);
+ hinserted_childsection = &sec_array.insert_next_value(section());
+ return true;
+ CATCH_ENTRY("portable_storage::insert_next_section", false);
+ }
}
}
diff --git a/docs/ANONYMITY_NETWORKS.md b/docs/ANONYMITY_NETWORKS.md
index 3337b5fc3..f8d08b05f 100644
--- a/docs/ANONYMITY_NETWORKS.md
+++ b/docs/ANONYMITY_NETWORKS.md
@@ -36,10 +36,6 @@ with additional exclusive IPv4 address(es).
## Usage
-Anonymity networks have no seed nodes (the feature is still considered
-experimental), so a user must specify an address. If configured properly,
-additional peers can be found through typical p2p peerlist sharing.
-
### Outbound Connections
Connecting to an anonymous address requires the command line option
@@ -54,8 +50,9 @@ separate process. On most systems the configuration will look like:
which tells `monerod` that ".onion" p2p addresses can be forwarded to a socks
proxy at IP 127.0.0.1 port 9050 with a max of 10 outgoing connections and
".b32.i2p" p2p addresses can be forwarded to a socks proxy at IP 127.0.0.1 port
-9000 with the default max outgoing connections. Since there are no seed nodes
-for anonymity connections, peers must be manually specified:
+9000 with the default max outgoing connections.
+
+If desired, peers can be manually specified:
```
--add-exclusive-node rveahdfho7wo4b2m.onion:28083
diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt
index a8916a7d0..7ae4ba750 100644
--- a/external/CMakeLists.txt
+++ b/external/CMakeLists.txt
@@ -38,8 +38,10 @@
find_package(Miniupnpc REQUIRED)
message(STATUS "Using in-tree miniupnpc")
+set(UPNPC_NO_INSTALL TRUE CACHE BOOL "Disable miniupnp installation" FORCE)
add_subdirectory(miniupnp/miniupnpc)
set_property(TARGET libminiupnpc-static PROPERTY FOLDER "external")
+set_property(TARGET libminiupnpc-static PROPERTY POSITION_INDEPENDENT_CODE ON)
if(MSVC)
set_property(TARGET libminiupnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -wd4244 -wd4267")
elseif(NOT MSVC)
diff --git a/external/db_drivers/liblmdb/mdb.c b/external/db_drivers/liblmdb/mdb.c
index ba1315401..8699b445e 100644
--- a/external/db_drivers/liblmdb/mdb.c
+++ b/external/db_drivers/liblmdb/mdb.c
@@ -3461,9 +3461,9 @@ mdb_freelist_save(MDB_txn *txn)
} else {
x = mdb_mid2l_search(dl, mp->mp_pgno);
mdb_tassert(txn, dl[x].mid == mp->mp_pgno);
+ mdb_dpage_free(env, mp);
}
dl[x].mptr = NULL;
- mdb_dpage_free(env, mp);
}
{
/* squash freed slots out of the dirty list */
diff --git a/external/miniupnp b/external/miniupnp
-Subproject 4c700e09526a7d546394e85628c57e9490feefa
+Subproject 544e6fcc73c5ad9af48a8985c94f0f1d742ef2e
diff --git a/src/blockchain_db/blockchain_db.cpp b/src/blockchain_db/blockchain_db.cpp
index a9a7d035f..5e12fa8ec 100644
--- a/src/blockchain_db/blockchain_db.cpp
+++ b/src/blockchain_db/blockchain_db.cpp
@@ -287,7 +287,7 @@ uint64_t BlockchainDB::add_block( const std::pair<block, blobdata>& blck
num_rct_outs += blk.miner_tx.vout.size();
int tx_i = 0;
crypto::hash tx_hash = crypto::null_hash;
- for (const std::pair<transaction, blobdata_ref>& tx : txs)
+ for (const std::pair<transaction, blobdata>& tx : txs)
{
tx_hash = blk.tx_hashes[tx_i];
add_transaction(blk_hash, tx, &tx_hash);
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index 0aa2aee6f..5f3b495b0 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -897,7 +897,6 @@ uint64_t BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, cons
throw0(DB_ERROR(lmdb_error("Failed to add tx data to db transaction: ", result).c_str()));
const cryptonote::blobdata_ref &blob = txp.second;
- MDB_val_sized(blobval, blob);
unsigned int unprunable_size = tx.unprunable_size;
if (unprunable_size == 0)
@@ -3190,9 +3189,8 @@ bool BlockchainLMDB::get_blocks_from(uint64_t start_height, size_t min_block_cou
uint64_t size = 0;
size_t num_txes = 0;
MDB_val_copy<uint64_t> key(start_height);
- MDB_val k, v, val_tx_id;
+ MDB_val v, val_tx_id;
uint64_t tx_id = ~0;
- MDB_cursor_op op = MDB_SET;
for (uint64_t h = start_height; h < blockchain_height && blocks.size() < max_block_count && (size < max_size || blocks.size() < min_block_count); ++h)
{
MDB_cursor_op op = h == start_height ? MDB_SET : MDB_NEXT;
@@ -3314,7 +3312,7 @@ bool BlockchainLMDB::get_prunable_tx_hash(const crypto::hash& tx_hash, crypto::h
RCURSOR(txs_prunable_hash);
MDB_val_set(v, tx_hash);
- MDB_val result, val_tx_prunable_hash;
+ MDB_val result;
auto get_result = mdb_cursor_get(m_cur_tx_indices, (MDB_val *)&zerokval, &v, MDB_GET_BOTH);
if (get_result == 0)
{
@@ -4311,7 +4309,6 @@ bool BlockchainLMDB::get_output_distribution(uint64_t amount, uint64_t from_heig
return false;
distribution.resize(db_height - from_height, 0);
- bool fret = true;
MDB_val_set(k, amount);
MDB_val v;
MDB_cursor_op op = MDB_SET;
@@ -5106,11 +5103,10 @@ void BlockchainLMDB::migrate_0_1()
void BlockchainLMDB::migrate_1_2()
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
- uint64_t i, z;
+ uint64_t i;
int result;
mdb_txn_safe txn(false);
- MDB_val k, v;
- char *ptr;
+ MDB_val v;
MGINFO_YELLOW("Migrating blockchain from DB version 1 to 2 - this may take a while:");
MINFO("updating txs_pruned and txs_prunable tables...");
@@ -5311,7 +5307,6 @@ void BlockchainLMDB::migrate_2_3()
if (result)
throw0(DB_ERROR(lmdb_error("Failed to open a cursor for block_info: ", result).c_str()));
if (!i) {
- MDB_stat db_stat;
result = mdb_stat(txn, m_block_info, &db_stats);
if (result)
throw0(DB_ERROR(lmdb_error("Failed to query m_block_info: ", result).c_str()));
@@ -5443,7 +5438,6 @@ void BlockchainLMDB::migrate_3_4()
if (result)
throw0(DB_ERROR(lmdb_error("Failed to open a cursor for blocks: ", result).c_str()));
if (!i) {
- MDB_stat db_stat;
result = mdb_stat(txn, m_block_info, &db_stats);
if (result)
throw0(DB_ERROR(lmdb_error("Failed to query m_block_info: ", result).c_str()));
@@ -5597,7 +5591,6 @@ void BlockchainLMDB::migrate_4_5()
if (result)
throw0(DB_ERROR(lmdb_error("Failed to open a cursor for block_info: ", result).c_str()));
if (!i) {
- MDB_stat db_stat;
result = mdb_stat(txn, m_block_info, &db_stats);
if (result)
throw0(DB_ERROR(lmdb_error("Failed to query m_block_info: ", result).c_str()));
diff --git a/src/blockchain_utilities/blockchain_ancestry.cpp b/src/blockchain_utilities/blockchain_ancestry.cpp
index 89b932e4f..b1b238427 100644
--- a/src/blockchain_utilities/blockchain_ancestry.cpp
+++ b/src/blockchain_utilities/blockchain_ancestry.cpp
@@ -149,7 +149,7 @@ struct ancestry_state_t
{
std::unordered_map<crypto::hash, cryptonote::transaction> old_tx_cache;
a & old_tx_cache;
- for (const auto i: old_tx_cache)
+ for (const auto& i: old_tx_cache)
tx_cache.insert(std::make_pair(i.first, ::tx_data_t(i.second)));
}
else
@@ -161,7 +161,7 @@ struct ancestry_state_t
std::unordered_map<uint64_t, cryptonote::block> old_block_cache;
a & old_block_cache;
block_cache.resize(old_block_cache.size());
- for (const auto i: old_block_cache)
+ for (const auto& i: old_block_cache)
block_cache[i.first] = i.second;
}
else
@@ -575,7 +575,6 @@ int main(int argc, char* argv[])
{
add_ancestry(state.ancestry, txid, ancestor{amount, offset});
// find the tx which created this output
- bool found = false;
crypto::hash output_txid;
if (!get_output_txid(state, db, amount, offset, output_txid))
{
@@ -693,7 +692,6 @@ int main(int argc, char* argv[])
add_ancestor(ancestry, amount, offset);
// find the tx which created this output
- bool found = false;
crypto::hash output_txid;
if (!get_output_txid(state, db, amount, offset, output_txid))
{
diff --git a/src/blockchain_utilities/blockchain_blackball.cpp b/src/blockchain_utilities/blockchain_blackball.cpp
index a8197483f..e439895bf 100644
--- a/src/blockchain_utilities/blockchain_blackball.cpp
+++ b/src/blockchain_utilities/blockchain_blackball.cpp
@@ -47,9 +47,6 @@ namespace po = boost::program_options;
using namespace epee;
using namespace cryptonote;
-static const char zerokey[8] = {0};
-static const MDB_val zerokval = { sizeof(zerokey), (void *)zerokey };
-
static uint64_t records_per_sync = 200;
static uint64_t db_flags = 0;
static MDB_dbi dbi_relative_rings;
@@ -703,7 +700,6 @@ static void get_per_amount_outputs(MDB_txn *txn, uint64_t amount, uint64_t &tota
int dbr = mdb_cursor_open(txn, dbi_per_amount, &cur);
CHECK_AND_ASSERT_THROW_MES(!dbr, "Failed to open cursor for per amount outputs: " + std::string(mdb_strerror(dbr)));
MDB_val k, v;
- mdb_size_t count = 0;
k.mv_size = sizeof(uint64_t);
k.mv_data = (void*)&amount;
dbr = mdb_cursor_get(cur, &k, &v, MDB_SET);
@@ -726,7 +722,6 @@ static void inc_per_amount_outputs(MDB_txn *txn, uint64_t amount, uint64_t total
int dbr = mdb_cursor_open(txn, dbi_per_amount, &cur);
CHECK_AND_ASSERT_THROW_MES(!dbr, "Failed to open cursor for per amount outputs: " + std::string(mdb_strerror(dbr)));
MDB_val k, v;
- mdb_size_t count = 0;
k.mv_size = sizeof(uint64_t);
k.mv_data = (void*)&amount;
dbr = mdb_cursor_get(cur, &k, &v, MDB_SET);
@@ -1077,7 +1072,6 @@ static std::vector<std::pair<uint64_t, uint64_t>> load_outputs(const std::string
s[len - 1] = 0;
if (!s[0])
continue;
- std::pair<uint64_t, uint64_t> output;
uint64_t offset, num_offsets;
if (sscanf(s, "@%" PRIu64, &amount) == 1)
{
@@ -1269,8 +1263,6 @@ int main(int argc, char* argv[])
LOG_PRINT_L0("Scanning for spent outputs...");
- size_t done = 0;
-
const uint64_t start_blackballed_outputs = get_num_spent_outputs();
tools::ringdb ringdb(output_file_path.string(), epee::string_tools::pod_to_hex(get_genesis_block_hash(inputs[0])));
diff --git a/src/blockchain_utilities/blockchain_import.cpp b/src/blockchain_utilities/blockchain_import.cpp
index 60c069c3b..df2662444 100644
--- a/src/blockchain_utilities/blockchain_import.cpp
+++ b/src/blockchain_utilities/blockchain_import.cpp
@@ -227,7 +227,7 @@ int import_from_file(cryptonote::core& core, const std::string& import_file_path
return false;
}
- uint64_t block_first, block_last;
+ uint64_t block_first;
uint64_t start_height = 1, seek_height;
if (opt_resume)
start_height = core.get_blockchain_storage().get_current_blockchain_height();
diff --git a/src/blockchain_utilities/blockchain_prune_known_spent_data.cpp b/src/blockchain_utilities/blockchain_prune_known_spent_data.cpp
index f8763710e..1a54778a7 100644
--- a/src/blockchain_utilities/blockchain_prune_known_spent_data.cpp
+++ b/src/blockchain_utilities/blockchain_prune_known_spent_data.cpp
@@ -66,7 +66,6 @@ static std::map<uint64_t, uint64_t> load_outputs(const std::string &filename)
s[len - 1] = 0;
if (!s[0])
continue;
- std::pair<uint64_t, uint64_t> output;
uint64_t offset, num_offsets;
if (sscanf(s, "@%" PRIu64, &amount) == 1)
{
diff --git a/src/blockchain_utilities/blockchain_usage.cpp b/src/blockchain_utilities/blockchain_usage.cpp
index 6e87a0974..095e6c503 100644
--- a/src/blockchain_utilities/blockchain_usage.cpp
+++ b/src/blockchain_utilities/blockchain_usage.cpp
@@ -180,7 +180,6 @@ int main(int argc, char* argv[])
LOG_PRINT_L0("Building usage patterns...");
- size_t done = 0;
std::unordered_map<output_data, std::list<reference>> outputs;
std::unordered_map<uint64_t,uint64_t> indices;
@@ -195,7 +194,7 @@ int main(int argc, char* argv[])
{
if (opt_rct_only && out.amount)
continue;
- uint64_t index = indices[out.amount]++;
+ indices[out.amount]++;
output_data od(out.amount, indices[out.amount], coinbase, height);
auto itb = outputs.emplace(od, std::list<reference>());
itb.first->first.info(coinbase, height);
diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp
index 4f4efcd81..c31d1dd96 100644
--- a/src/common/dns_utils.cpp
+++ b/src/common/dns_utils.cpp
@@ -484,36 +484,12 @@ std::string get_account_address_as_str_from_url(const std::string& url, bool& dn
return dns_confirm(url, addresses, dnssec_valid);
}
-namespace
-{
- bool dns_records_match(const std::vector<std::string>& a, const std::vector<std::string>& b)
- {
- if (a.size() != b.size()) return false;
-
- for (const auto& record_in_a : a)
- {
- bool ok = false;
- for (const auto& record_in_b : b)
- {
- if (record_in_a == record_in_b)
- {
- ok = true;
- break;
- }
- }
- if (!ok) return false;
- }
-
- return true;
- }
-}
-
bool load_txt_records_from_dns(std::vector<std::string> &good_records, const std::vector<std::string> &dns_urls)
{
// Prevent infinite recursion when distributing
if (dns_urls.empty()) return false;
- std::vector<std::vector<std::string> > records;
+ std::vector<std::set<std::string> > records;
records.resize(dns_urls.size());
size_t first_index = crypto::rand_idx(dns_urls.size());
@@ -525,7 +501,9 @@ bool load_txt_records_from_dns(std::vector<std::string> &good_records, const std
for (size_t n = 0; n < dns_urls.size(); ++n)
{
tpool.submit(&waiter,[n, dns_urls, &records, &avail, &valid](){
- records[n] = tools::DNSResolver::instance().get_txt_record(dns_urls[n], avail[n], valid[n]);
+ const auto res = tools::DNSResolver::instance().get_txt_record(dns_urls[n], avail[n], valid[n]);
+ for (const auto &s: res)
+ records[n].insert(s);
});
}
waiter.wait();
@@ -568,29 +546,31 @@ bool load_txt_records_from_dns(std::vector<std::string> &good_records, const std
return false;
}
- int good_records_index = -1;
- for (size_t i = 0; i < records.size() - 1; ++i)
+ typedef std::map<std::set<std::string>, uint32_t> map_t;
+ map_t record_count;
+ for (const auto &e: records)
{
- if (records[i].size() == 0) continue;
+ if (!e.empty())
+ ++record_count[e];
+ }
- for (size_t j = i + 1; j < records.size(); ++j)
- {
- if (dns_records_match(records[i], records[j]))
- {
- good_records_index = i;
- break;
- }
- }
- if (good_records_index >= 0) break;
+ map_t::const_iterator good_record = record_count.end();
+ for (map_t::const_iterator i = record_count.begin(); i != record_count.end(); ++i)
+ {
+ if (good_record == record_count.end() || i->second > good_record->second)
+ good_record = i;
}
- if (good_records_index < 0)
+ MDEBUG("Found " << (good_record == record_count.end() ? 0 : good_record->second) << "/" << dns_urls.size() << " matching records from " << num_valid_records << " valid records");
+ if (good_record == record_count.end() || good_record->second < dns_urls.size() / 2 + 1)
{
- LOG_PRINT_L0("WARNING: no two DNS TXT records matched");
+ LOG_PRINT_L0("WARNING: no majority of DNS TXT records matched (only " << good_record->second << "/" << dns_urls.size() << ")");
return false;
}
- good_records = records[good_records_index];
+ good_records = {};
+ for (const auto &s: good_record->first)
+ good_records.push_back(s);
return true;
}
diff --git a/src/common/updates.cpp b/src/common/updates.cpp
index 61a76f5da..af38d7a54 100644
--- a/src/common/updates.cpp
+++ b/src/common/updates.cpp
@@ -48,7 +48,10 @@ namespace tools
static const std::vector<std::string> dns_urls = {
"updates.moneropulse.org",
"updates.moneropulse.net",
- "updates.moneropulse.co",
+ "updates.moneropulse.fr",
+ "updates.moneropulse.de",
+ "updates.moneropulse.no",
+ "updates.moneropulse.ch",
"updates.moneropulse.se"
};
diff --git a/src/crypto/hash-ops.h b/src/crypto/hash-ops.h
index 7dfc5151d..1cd502994 100644
--- a/src/crypto/hash-ops.h
+++ b/src/crypto/hash-ops.h
@@ -87,6 +87,10 @@ void hash_extra_jh(const void *data, size_t length, char *hash);
void hash_extra_skein(const void *data, size_t length, char *hash);
void tree_hash(const char (*hashes)[HASH_SIZE], size_t count, char *root_hash);
+bool tree_path(size_t count, size_t idx, uint32_t *path);
+bool tree_branch(const char (*hashes)[HASH_SIZE], size_t count, const char *hash, char (*branch)[HASH_SIZE], size_t *depth, uint32_t *path);
+bool tree_branch_hash(const char hash[HASH_SIZE], const char (*branch)[HASH_SIZE], size_t depth, uint32_t path, char root[HASH_SIZE]);
+bool is_branch_in_tree(const char hash[HASH_SIZE], const char root[HASH_SIZE], const char (*branch)[HASH_SIZE], size_t depth, uint32_t path);
#define RX_BLOCK_VERSION 12
void rx_slow_hash_allocate_state(void);
diff --git a/src/crypto/tree-hash.c b/src/crypto/tree-hash.c
index 643e95121..8f3ea3339 100644
--- a/src/crypto/tree-hash.c
+++ b/src/crypto/tree-hash.c
@@ -104,3 +104,154 @@ void tree_hash(const char (*hashes)[HASH_SIZE], size_t count, char *root_hash) {
free(ints);
}
}
+
+bool tree_path(size_t count, size_t idx, uint32_t *path)
+{
+ if (count == 0)
+ return false;
+
+ if (count == 1) {
+ *path = 0;
+ } else if (count == 2) {
+ *path = idx == 0 ? 0 : 1;
+ } else {
+ size_t i, j;
+
+ *path = 0;
+ size_t cnt = tree_hash_cnt( count );
+
+ for (i = 2 * cnt - count, j = 2 * cnt - count; j < cnt; i += 2, ++j) {
+ if (idx == i || idx == i+1)
+ {
+ *path = (*path << 1) | (idx == i ? 0 : 1);
+ idx = j;
+ }
+ }
+ assert(i == count);
+
+ while (cnt > 2) {
+ cnt >>= 1;
+ for (i = 0, j = 0; j < cnt; i += 2, ++j) {
+ if (idx == i || idx == i + 1)
+ {
+ *path = (*path << 1) | (idx == i ? 0 : 1);
+ idx = j;
+ }
+ }
+ }
+
+ if (idx == 0 || idx == 1)
+ {
+ *path = (*path << 1) | (idx == 0 ? 0 : 1);
+ idx = 0;
+ }
+ }
+ return true;
+}
+
+bool tree_branch(const char (*hashes)[HASH_SIZE], size_t count, const char *hash, char (*branch)[HASH_SIZE], size_t *depth, uint32_t *path)
+{
+ size_t idx;
+
+ if (count == 0)
+ return false;
+
+ for (idx = 0; idx < count; ++idx)
+ if (!memcmp(hash, hashes[idx], HASH_SIZE))
+ break;
+ if (idx == count)
+ return false;
+
+ assert(count > 0);
+ if (count == 1) {
+ *depth = 0;
+ *path = 0;
+ } else if (count == 2) {
+ *depth = 1;
+ *path = idx == 0 ? 0 : 1;
+ memcpy(branch[0], hashes[idx ^ 1], HASH_SIZE);
+ } else {
+ size_t i, j;
+
+ *depth = 0;
+ *path = 0;
+ size_t cnt = tree_hash_cnt( count );
+
+ char *ints = calloc(cnt, HASH_SIZE); // zero out as extra protection for using uninitialized mem
+ assert(ints);
+
+ memcpy(ints, hashes, (2 * cnt - count) * HASH_SIZE);
+
+ for (i = 2 * cnt - count, j = 2 * cnt - count; j < cnt; i += 2, ++j) {
+ if (idx == i || idx == i+1)
+ {
+ memcpy(branch[*depth], hashes[idx == i ? i + 1 : i], HASH_SIZE);
+ ++*depth;
+ *path = (*path << 1) | (idx == i ? 0 : 1);
+ idx = j;
+ }
+ cn_fast_hash(hashes[i], 64, ints + j * HASH_SIZE);
+ }
+ assert(i == count);
+
+ while (cnt > 2) {
+ cnt >>= 1;
+ for (i = 0, j = 0; j < cnt; i += 2, ++j) {
+ if (idx == i || idx == i + 1)
+ {
+ memcpy(branch[*depth], ints + (idx == i ? i + 1 : i) * HASH_SIZE, HASH_SIZE);
+ ++*depth;
+ *path = (*path << 1) | (idx == i ? 0 : 1);
+ idx = j;
+ }
+ cn_fast_hash(ints + i * HASH_SIZE, 64, ints + j * HASH_SIZE);
+ }
+ }
+
+ if (idx == 0 || idx == 1)
+ {
+ memcpy(branch[*depth], ints + (idx == 0 ? 1 : 0) * HASH_SIZE, HASH_SIZE);
+ ++*depth;
+ *path = (*path << 1) | (idx == 0 ? 0 : 1);
+ idx = 0;
+ }
+
+ free(ints);
+ }
+ return true;
+}
+
+bool tree_branch_hash(const char hash[HASH_SIZE], const char (*branch)[HASH_SIZE], size_t depth, uint32_t path, char root[HASH_SIZE])
+{
+ size_t d;
+ char partial[HASH_SIZE];
+
+ memcpy(partial, hash, HASH_SIZE);
+
+ for (d = 0; d < depth; ++d)
+ {
+ char buffer[2 * HASH_SIZE];
+ if ((path >> (depth - d - 1)) & 1)
+ {
+ memcpy(buffer, branch[d], HASH_SIZE);
+ memcpy(buffer + HASH_SIZE, partial, HASH_SIZE);
+ }
+ else
+ {
+ memcpy(buffer, partial, HASH_SIZE);
+ memcpy(buffer + HASH_SIZE, branch[d], HASH_SIZE);
+ }
+ cn_fast_hash(buffer, 2 * HASH_SIZE, partial);
+ }
+
+ memcpy(root, partial, HASH_SIZE);
+ return true;
+}
+
+bool is_branch_in_tree(const char hash[HASH_SIZE], const char root[HASH_SIZE], const char (*branch)[HASH_SIZE], size_t depth, uint32_t path)
+{
+ char res[HASH_SIZE];
+ if (!tree_branch_hash(hash, branch, depth, path, res))
+ return false;
+ return memcmp(res, root, HASH_SIZE) == 0;
+}
diff --git a/src/cryptonote_basic/CMakeLists.txt b/src/cryptonote_basic/CMakeLists.txt
index 5286256c7..c9fb1433c 100644
--- a/src/cryptonote_basic/CMakeLists.txt
+++ b/src/cryptonote_basic/CMakeLists.txt
@@ -43,6 +43,7 @@ set(cryptonote_basic_sources
cryptonote_format_utils.cpp
difficulty.cpp
hardfork.cpp
+ merge_mining.cpp
miner.cpp)
set(cryptonote_basic_headers)
@@ -57,6 +58,7 @@ set(cryptonote_basic_private_headers
cryptonote_format_utils.h
difficulty.h
hardfork.h
+ merge_mining.h
miner.h
tx_extra.h
verification_context.h)
diff --git a/src/cryptonote_basic/cryptonote_format_utils.cpp b/src/cryptonote_basic/cryptonote_format_utils.cpp
index fcc96883b..3e4532d4e 100644
--- a/src/cryptonote_basic/cryptonote_format_utils.cpp
+++ b/src/cryptonote_basic/cryptonote_format_utils.cpp
@@ -104,7 +104,6 @@ namespace cryptonote
uint64_t get_transaction_weight_clawback(const transaction &tx, size_t n_padded_outputs)
{
- const rct::rctSig &rv = tx.rct_signatures;
const uint64_t bp_base = 368;
const size_t n_outputs = tx.vout.size();
if (n_padded_outputs <= 2)
@@ -728,6 +727,25 @@ namespace cryptonote
return true;
}
//---------------------------------------------------------------
+ bool add_mm_merkle_root_to_tx_extra(std::vector<uint8_t>& tx_extra, const crypto::hash& mm_merkle_root, size_t mm_merkle_tree_depth)
+ {
+ CHECK_AND_ASSERT_MES(mm_merkle_tree_depth < 32, false, "merge mining merkle tree depth should be less than 32");
+ size_t start_pos = tx_extra.size();
+ tx_extra.resize(tx_extra.size() + 3 + 32);
+ //write tag
+ tx_extra[start_pos] = TX_EXTRA_MERGE_MINING_TAG;
+ //write data size
+ ++start_pos;
+ tx_extra[start_pos] = 33;
+ //write depth varint (always one byte here)
+ ++start_pos;
+ tx_extra[start_pos] = mm_merkle_tree_depth;
+ //write data
+ ++start_pos;
+ memcpy(&tx_extra[start_pos], &mm_merkle_root, 32);
+ return true;
+ }
+ //---------------------------------------------------------------
bool remove_field_from_tx_extra(std::vector<uint8_t>& tx_extra, const std::type_info &type)
{
if (tx_extra.empty())
diff --git a/src/cryptonote_basic/cryptonote_format_utils.h b/src/cryptonote_basic/cryptonote_format_utils.h
index 636a88b9a..b311bd2b2 100644
--- a/src/cryptonote_basic/cryptonote_format_utils.h
+++ b/src/cryptonote_basic/cryptonote_format_utils.h
@@ -83,6 +83,7 @@ namespace cryptonote
std::vector<crypto::public_key> get_additional_tx_pub_keys_from_extra(const transaction_prefix& tx);
bool add_additional_tx_pub_keys_to_extra(std::vector<uint8_t>& tx_extra, const std::vector<crypto::public_key>& additional_pub_keys);
bool add_extra_nonce_to_tx_extra(std::vector<uint8_t>& tx_extra, const blobdata& extra_nonce);
+ bool add_mm_merkle_root_to_tx_extra(std::vector<uint8_t>& tx_extra, const crypto::hash& mm_merkle_root, size_t mm_merkle_tree_depth);
bool remove_field_from_tx_extra(std::vector<uint8_t>& tx_extra, const std::type_info &type);
void set_payment_id_to_tx_extra_nonce(blobdata& extra_nonce, const crypto::hash& payment_id);
void set_encrypted_payment_id_to_tx_extra_nonce(blobdata& extra_nonce, const crypto::hash8& payment_id);
diff --git a/src/cryptonote_basic/merge_mining.cpp b/src/cryptonote_basic/merge_mining.cpp
new file mode 100644
index 000000000..fcc74859f
--- /dev/null
+++ b/src/cryptonote_basic/merge_mining.cpp
@@ -0,0 +1,95 @@
+// Copyright (c) 2020, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include <string.h>
+#include "misc_log_ex.h"
+#include "int-util.h"
+#include "crypto/crypto.h"
+#include "common/util.h"
+#include "merge_mining.h"
+
+using namespace epee;
+
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "cn.mm"
+
+using namespace crypto;
+
+namespace cryptonote
+{
+
+//---------------------------------------------------------------
+uint32_t get_aux_slot(const crypto::hash &id, uint32_t nonce, uint32_t n_aux_chains)
+{
+ CHECK_AND_ASSERT_THROW_MES(n_aux_chains > 0, "n_aux_chains is 0");
+
+ uint8_t buf[HASH_SIZE + sizeof(uint32_t) + 1];
+ memcpy(buf, &id, HASH_SIZE);
+ uint32_t v = SWAP32LE(nonce);
+ memcpy(buf + HASH_SIZE, &v, sizeof(uint32_t));
+ buf[HASH_SIZE + sizeof(uint32_t)] = config::HASH_KEY_MM_SLOT;
+
+ crypto::hash res;
+ tools::sha256sum(buf, sizeof(buf), res);
+ v = *((const uint32_t*)&res);
+ return SWAP32LE(v) % n_aux_chains;
+}
+//---------------------------------------------------------------
+uint32_t get_path_from_aux_slot(uint32_t slot, uint32_t n_aux_chains)
+{
+ CHECK_AND_ASSERT_THROW_MES(n_aux_chains > 0, "n_aux_chains is 0");
+ CHECK_AND_ASSERT_THROW_MES(slot < n_aux_chains, "slot >= n_aux_chains");
+
+ uint32_t path = 0;
+ CHECK_AND_ASSERT_THROW_MES(tree_path(n_aux_chains, slot, &path), "Failed to get path from aux slot");
+ return path;
+}
+//---------------------------------------------------------------
+uint32_t encode_mm_depth(uint32_t n_aux_chains, uint32_t nonce)
+{
+ CHECK_AND_ASSERT_THROW_MES(n_aux_chains > 0, "n_aux_chains is 0");
+
+ // how many bits to we need to representing n_aux_chains - 1
+ uint32_t n_bits = 1;
+ while ((1u << n_bits) < n_aux_chains && n_bits < 16)
+ ++n_bits;
+ CHECK_AND_ASSERT_THROW_MES(n_bits <= 16, "Way too many bits required");
+
+ const uint32_t depth = (n_bits - 1) | ((n_aux_chains - 1) << 3) | (nonce << (3 + n_bits));
+ return depth;
+}
+//---------------------------------------------------------------
+bool decode_mm_depth(uint32_t depth, uint32_t &n_aux_chains, uint32_t &nonce)
+{
+ const uint32_t n_bits = 1 + (depth & 7);
+ n_aux_chains = 1 + (depth >> 3 & ((1 << n_bits) - 1));
+ nonce = depth >> (3 + n_bits);
+ return true;
+}
+//---------------------------------------------------------------
+}
diff --git a/src/cryptonote_basic/merge_mining.h b/src/cryptonote_basic/merge_mining.h
new file mode 100644
index 000000000..378438f7c
--- /dev/null
+++ b/src/cryptonote_basic/merge_mining.h
@@ -0,0 +1,40 @@
+// Copyright (c) 2020, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#pragma once
+
+#include <stdint.h>
+#include "crypto/crypto.h"
+
+namespace cryptonote
+{
+ uint32_t get_aux_slot(const crypto::hash &id, uint32_t nonce, uint32_t n_aux_chains);
+ uint32_t get_path_from_aux_slot(uint32_t slot, uint32_t n_aux_chains);
+ uint32_t encode_mm_depth(uint32_t n_aux_chains, uint32_t nonce);
+ bool decode_mm_depth(uint32_t depth, uint32_t &n_aux_chains, uint32_t &nonce);
+}
diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h
index 2cb28b2b1..915835d1b 100644
--- a/src/cryptonote_config.h
+++ b/src/cryptonote_config.h
@@ -194,7 +194,6 @@
#define CRYPTONOTE_PRUNING_STRIPE_SIZE 4096 // the smaller, the smoother the increase
#define CRYPTONOTE_PRUNING_LOG_STRIPES 3 // the higher, the more space saved
#define CRYPTONOTE_PRUNING_TIP_BLOCKS 5500 // the smaller, the more space saved
-//#define CRYPTONOTE_PRUNING_DEBUG_SPOOF_SEED
#define RPC_CREDITS_PER_HASH_SCALE ((float)(1<<24))
@@ -235,6 +234,7 @@ namespace config
const unsigned char HASH_KEY_CLSAG_AGG_0[] = "CLSAG_agg_0";
const unsigned char HASH_KEY_CLSAG_AGG_1[] = "CLSAG_agg_1";
const char HASH_KEY_MESSAGE_SIGNING[] = "MoneroMessageSignature";
+ const unsigned char HASH_KEY_MM_SLOT = 'm';
namespace testnet
{
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 8ec624254..cdad39a2c 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -973,7 +973,7 @@ start:
std::pair<bool, uint64_t> Blockchain::check_difficulty_checkpoints() const
{
uint64_t res = 0;
- for (const std::pair<uint64_t, difficulty_type>& i : m_checkpoints.get_difficulty_points())
+ for (const std::pair<const uint64_t, difficulty_type>& i : m_checkpoints.get_difficulty_points())
{
if (i.first >= m_db->height())
break;
@@ -3438,7 +3438,6 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
bool failed = false;
for (size_t i = 0; i < tx.vin.size(); i++)
{
- const txin_to_key& in_to_key = boost::get<txin_to_key>(tx.vin[i]);
if(!failed && !results[i])
failed = true;
}
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 12125fb9d..57104fd59 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -630,7 +630,7 @@ namespace cryptonote
void operator()(std::uint64_t, epee::span<const block> blocks) const
{
- for (const block bl : blocks)
+ for (const block& bl : blocks)
cmdline.notify("%s", epee::string_tools::pod_to_hex(get_block_hash(bl)).c_str(), NULL);
}
};
diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp
index d059ab78f..a7e96e23a 100644
--- a/src/cryptonote_core/tx_pool.cpp
+++ b/src/cryptonote_core/tx_pool.cpp
@@ -383,7 +383,6 @@ namespace cryptonote
bool tx_memory_pool::add_tx(transaction &tx, tx_verification_context& tvc, relay_method tx_relay, bool relayed, uint8_t version)
{
crypto::hash h = null_hash;
- size_t blob_size = 0;
cryptonote::blobdata bl;
t_serializable_object_to_blob(tx, bl);
if (bl.size() == 0 || !get_transaction_hash(tx, h))
@@ -1041,7 +1040,6 @@ namespace cryptonote
return true;
}, true, category);
- txpool_tx_meta_t meta;
for (const key_images_container::value_type& kee : m_spent_key_images) {
const crypto::key_image& k_image = kee.first;
const std::unordered_set<crypto::hash>& kei_image_set = kee.second;
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
index b57fc0f0f..c798dbcdb 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
@@ -338,10 +338,6 @@ namespace cryptonote
}
context.m_remote_blockchain_height = hshd.current_height;
context.m_pruning_seed = hshd.pruning_seed;
-#ifdef CRYPTONOTE_PRUNING_DEBUG_SPOOF_SEED
- context.m_pruning_seed = tools::make_pruning_seed(1 + (context.m_remote_address.as<epee::net_utils::ipv4_network_address>().ip()) % (1 << CRYPTONOTE_PRUNING_LOG_STRIPES), CRYPTONOTE_PRUNING_LOG_STRIPES);
- LOG_INFO_CC(context, "New connection posing as pruning seed " << epee::string_tools::to_string_hex(context.m_pruning_seed) << ", seed address " << &context.m_pruning_seed);
-#endif
uint64_t target = m_core.get_target_blockchain_height();
if (target == 0)
@@ -1849,10 +1845,8 @@ skip:
bool t_cryptonote_protocol_handler<t_core>::should_download_next_span(cryptonote_connection_context& context, bool standby)
{
std::vector<crypto::hash> hashes;
- boost::uuids::uuid span_connection_id;
boost::posix_time::ptime request_time;
boost::uuids::uuid connection_id;
- std::pair<uint64_t, uint64_t> span;
bool filled;
const uint64_t blockchain_height = m_core.get_current_blockchain_height();
@@ -1878,7 +1872,6 @@ skip:
// in standby, be ready to double download early since we're idling anyway
// let the fastest peer trigger first
- long threshold;
const double dl_speed = context.m_max_speed_down;
if (standby && dt >= REQUEST_NEXT_SCHEDULED_SPAN_THRESHOLD_STANDBY && dl_speed > 0)
{
diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp
index 5a7d4dd4e..8194fe642 100644
--- a/src/daemon/rpc_command_executor.cpp
+++ b/src/daemon/rpc_command_executor.cpp
@@ -1059,7 +1059,6 @@ bool t_rpc_command_executor::print_transaction(crypto::hash transaction_hash,
// Print json if requested
if (include_json)
{
- crypto::hash tx_hash, tx_prefix_hash;
cryptonote::transaction tx;
cryptonote::blobdata blob;
std::string source = as_hex.empty() ? pruned_as_hex + prunable_as_hex : as_hex;
diff --git a/src/debug_utilities/cn_deserialize.cpp b/src/debug_utilities/cn_deserialize.cpp
index dd4701e4f..c039b93c5 100644
--- a/src/debug_utilities/cn_deserialize.cpp
+++ b/src/debug_utilities/cn_deserialize.cpp
@@ -133,6 +133,18 @@ int main(int argc, char* argv[])
{
std::cout << "Parsed block:" << std::endl;
std::cout << cryptonote::obj_to_json_str(block) << std::endl;
+ bool parsed = cryptonote::parse_tx_extra(block.miner_tx.extra, fields);
+ if (!parsed)
+ std::cout << "Failed to parse tx_extra" << std::endl;
+
+ if (!fields.empty())
+ {
+ print_extra_fields(fields);
+ }
+ else
+ {
+ std::cout << "No fields were found in tx_extra" << std::endl;
+ }
}
else if (cryptonote::parse_and_validate_tx_from_blob(blob, tx) || cryptonote::parse_and_validate_tx_base_from_blob(blob, tx))
{
diff --git a/src/debug_utilities/dns_checks.cpp b/src/debug_utilities/dns_checks.cpp
index 76b66c6cb..138cd4fc1 100644
--- a/src/debug_utilities/dns_checks.cpp
+++ b/src/debug_utilities/dns_checks.cpp
@@ -131,7 +131,7 @@ int main(int argc, char* argv[])
lookup(LOOKUP_A, {"seeds.moneroseeds.se", "seeds.moneroseeds.ae.org", "seeds.moneroseeds.ch", "seeds.moneroseeds.li"});
- lookup(LOOKUP_TXT, {"updates.moneropulse.org", "updates.moneropulse.net", "updates.moneropulse.co", "updates.moneropulse.se"});
+ lookup(LOOKUP_TXT, {"updates.moneropulse.org", "updates.moneropulse.net", "updates.moneropulse.co", "updates.moneropulse.se", "updates.moneropulse.fr", "updates.moneropulse.de", "updates.moneropulse.no", "updates.moneropulse.ch"});
lookup(LOOKUP_TXT, {"checkpoints.moneropulse.org", "checkpoints.moneropulse.net", "checkpoints.moneropulse.co", "checkpoints.moneropulse.se"});
diff --git a/src/device/device_io_hid.cpp b/src/device/device_io_hid.cpp
index 7c61c3b1a..7aa5b39bf 100644
--- a/src/device/device_io_hid.cpp
+++ b/src/device/device_io_hid.cpp
@@ -181,7 +181,6 @@ namespace hw {
unsigned char padding_buffer[MAX_BLOCK+1];
unsigned int result;
int hid_ret;
- unsigned int sw_offset;
unsigned int remaining;
unsigned int offset = 0;
diff --git a/src/device_trezor/device_trezor_base.cpp b/src/device_trezor/device_trezor_base.cpp
index f59be1573..70dc7f539 100644
--- a/src/device_trezor/device_trezor_base.cpp
+++ b/src/device_trezor/device_trezor_base.cpp
@@ -365,15 +365,14 @@ namespace trezor {
void device_trezor_base::device_state_initialize_unsafe()
{
require_connected();
- std::string tmp_session_id;
auto initMsg = std::make_shared<messages::management::Initialize>();
const auto data_cleaner = epee::misc_utils::create_scope_leave_handler([&]() {
- memwipe(&tmp_session_id[0], tmp_session_id.size());
+ if (initMsg->has_session_id())
+ memwipe(&(*initMsg->mutable_session_id())[0], initMsg->mutable_session_id()->size());
});
if(!m_device_session_id.empty()) {
- tmp_session_id.assign(m_device_session_id.data(), m_device_session_id.size());
- initMsg->set_allocated_session_id(&tmp_session_id);
+ initMsg->set_allocated_session_id(new std::string(m_device_session_id.data(), m_device_session_id.size()));
}
m_features = this->client_exchange<messages::management::Features>(initMsg);
@@ -382,8 +381,6 @@ namespace trezor {
} else {
m_device_session_id.clear();
}
-
- initMsg->release_session_id();
}
void device_trezor_base::device_state_reset()
@@ -453,18 +450,14 @@ namespace trezor {
pin = m_pin;
}
- std::string pin_field;
messages::common::PinMatrixAck m;
if (pin) {
- pin_field.assign(pin->data(), pin->size());
- m.set_allocated_pin(&pin_field);
+ m.set_allocated_pin(new std::string(pin->data(), pin->size()));
}
const auto data_cleaner = epee::misc_utils::create_scope_leave_handler([&]() {
- m.release_pin();
- if (!pin_field.empty()){
- memwipe(&pin_field[0], pin_field.size());
- }
+ if (m.has_pin())
+ memwipe(&(*m.mutable_pin())[0], m.mutable_pin()->size());
});
resp = call_raw(&m);
@@ -499,7 +492,6 @@ namespace trezor {
boost::optional<epee::wipeable_string> passphrase;
TREZOR_CALLBACK_GET(passphrase, on_passphrase_request, on_device);
- std::string passphrase_field;
messages::common::PassphraseAck m;
m.set_on_device(on_device);
if (!on_device) {
@@ -512,16 +504,13 @@ namespace trezor {
}
if (passphrase) {
- passphrase_field.assign(passphrase->data(), passphrase->size());
- m.set_allocated_passphrase(&passphrase_field);
+ m.set_allocated_passphrase(new std::string(passphrase->data(), passphrase->size()));
}
}
const auto data_cleaner = epee::misc_utils::create_scope_leave_handler([&]() {
- m.release_passphrase();
- if (!passphrase_field.empty()){
- memwipe(&passphrase_field[0], passphrase_field.size());
- }
+ if (m.has_passphrase())
+ memwipe(&(m.mutable_passphrase())[0], m.mutable_passphrase()->size());
});
resp = call_raw(&m);
diff --git a/src/device_trezor/device_trezor_base.hpp b/src/device_trezor/device_trezor_base.hpp
index 4db8f0c8e..0162b23df 100644
--- a/src/device_trezor/device_trezor_base.hpp
+++ b/src/device_trezor/device_trezor_base.hpp
@@ -165,7 +165,7 @@ namespace trezor {
// Scoped session closer
BOOST_SCOPE_EXIT_ALL(&, this) {
- if (open_session){
+ if (open_session && this->get_transport()){
this->get_transport()->close();
}
};
diff --git a/src/gen_multisig/gen_multisig.cpp b/src/gen_multisig/gen_multisig.cpp
index 15f7e5c0a..4aa21b149 100644
--- a/src/gen_multisig/gen_multisig.cpp
+++ b/src/gen_multisig/gen_multisig.cpp
@@ -74,8 +74,6 @@ namespace
const command_line::arg_descriptor<bool, false> arg_testnet = {"testnet", genms::tr("Create testnet multisig wallets"), false};
const command_line::arg_descriptor<bool, false> arg_stagenet = {"stagenet", genms::tr("Create stagenet multisig wallets"), false};
const command_line::arg_descriptor<bool, false> arg_create_address_file = {"create-address-file", genms::tr("Create an address file for new wallets"), false};
-
- const command_line::arg_descriptor< std::vector<std::string> > arg_command = {"command", ""};
}
static bool generate_multisig(uint32_t threshold, uint32_t total, const std::string &basename, network_type nettype, bool create_address_file)
diff --git a/src/mnemonics/electrum-words.cpp b/src/mnemonics/electrum-words.cpp
index bda18d950..b6bc22a3d 100644
--- a/src/mnemonics/electrum-words.cpp
+++ b/src/mnemonics/electrum-words.cpp
@@ -194,7 +194,6 @@ namespace
{
epee::wipeable_string trimmed_words = "", word;
- const auto &word_map = language->get_word_map();
const auto &trimmed_word_map = language->get_trimmed_word_map();
const uint32_t unique_prefix_length = language->get_unique_prefix_length();
for (std::vector<epee::wipeable_string>::const_iterator it = word_list.begin(); it != word_list.end(); it++)
diff --git a/src/mnemonics/language_base.h b/src/mnemonics/language_base.h
index bf8793aa2..1aa869e45 100644
--- a/src/mnemonics/language_base.h
+++ b/src/mnemonics/language_base.h
@@ -129,7 +129,7 @@ namespace Language
if ((*it).size() < unique_prefix_length)
{
if (flags & ALLOW_SHORT_WORDS)
- MWARNING(language_name << " word '" << *it << "' is shorter than its prefix length, " << unique_prefix_length);
+ MINFO(language_name << " word '" << *it << "' is shorter than its prefix length, " << unique_prefix_length);
else
throw std::runtime_error("Too short word in " + language_name + " word list: " + *it);
}
diff --git a/src/net/socks.cpp b/src/net/socks.cpp
index 3463f452c..c2330bd41 100644
--- a/src/net/socks.cpp
+++ b/src/net/socks.cpp
@@ -48,7 +48,6 @@ namespace socks
{
namespace
{
- constexpr const unsigned v4_reply_size = 8;
constexpr const std::uint8_t v4_connect_command = 1;
constexpr const std::uint8_t v4tor_resolve_command = 0xf0;
constexpr const std::uint8_t v4_request_granted = 90;
diff --git a/src/p2p/net_node.cpp b/src/p2p/net_node.cpp
index 8dd551d1e..84cc1581e 100644
--- a/src/p2p/net_node.cpp
+++ b/src/p2p/net_node.cpp
@@ -166,6 +166,7 @@ namespace nodetool
const command_line::arg_descriptor<bool> arg_pad_transactions = {
"pad-transactions", "Pad relayed transactions to help defend against traffic volume analysis", false
};
+ const command_line::arg_descriptor<uint32_t> arg_max_connections_per_ip = {"max-connections-per-ip", "Maximum number of connections allowed from the same IP address", 1};
boost::optional<std::vector<proxy>> get_proxies(boost::program_options::variables_map const& vm)
{
diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h
index 59a6e5091..db931122e 100644
--- a/src/p2p/net_node.h
+++ b/src/p2p/net_node.h
@@ -258,7 +258,8 @@ namespace nodetool
m_igd(no_igd),
m_offline(false),
is_closing(false),
- m_network_id()
+ m_network_id(),
+ max_connections(1)
{}
virtual ~node_server();
@@ -517,6 +518,8 @@ namespace nodetool
epee::net_utils::ssl_support_t m_ssl_support;
bool m_enable_dns_blocklist;
+
+ uint32_t max_connections;
};
const int64_t default_limit_up = P2P_DEFAULT_LIMIT_RATE_UP; // kB/s
@@ -551,6 +554,7 @@ namespace nodetool
extern const command_line::arg_descriptor<int64_t> arg_limit_rate_down;
extern const command_line::arg_descriptor<int64_t> arg_limit_rate;
extern const command_line::arg_descriptor<bool> arg_pad_transactions;
+ extern const command_line::arg_descriptor<uint32_t> arg_max_connections_per_ip;
}
POP_WARNINGS
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index 05af22a7f..07b45b9bd 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -131,6 +131,7 @@ namespace nodetool
command_line::add_arg(desc, arg_limit_rate_down);
command_line::add_arg(desc, arg_limit_rate);
command_line::add_arg(desc, arg_pad_transactions);
+ command_line::add_arg(desc, arg_max_connections_per_ip);
}
//-----------------------------------------------------------------------------------
template<class t_payload_net_handler>
@@ -615,6 +616,8 @@ namespace nodetool
return false;
}
+ max_connections = command_line::get_arg(vm, arg_max_connections_per_ip);
+
return true;
}
//-----------------------------------------------------------------------------------
@@ -894,32 +897,6 @@ namespace nodetool
for(const auto& p: m_command_line_peers)
m_network_zones.at(p.adr.get_zone()).m_peerlist.append_with_peer_white(p);
-// all peers are now setup
-#ifdef CRYPTONOTE_PRUNING_DEBUG_SPOOF_SEED
- for (auto& zone : m_network_zones)
- {
- std::list<peerlist_entry> plw;
- while (zone.second.m_peerlist.get_white_peers_count())
- {
- plw.push_back(peerlist_entry());
- zone.second.m_peerlist.get_white_peer_by_index(plw.back(), 0);
- zone.second.m_peerlist.remove_from_peer_white(plw.back());
- }
- for (auto &e:plw)
- zone.second.m_peerlist.append_with_peer_white(e);
-
- std::list<peerlist_entry> plg;
- while (zone.second.m_peerlist.get_gray_peers_count())
- {
- plg.push_back(peerlist_entry());
- zone.second.m_peerlist.get_gray_peer_by_index(plg.back(), 0);
- zone.second.m_peerlist.remove_from_peer_gray(plg.back());
- }
- for (auto &e:plg)
- zone.second.m_peerlist.append_with_peer_gray(e);
- }
-#endif
-
//only in case if we really sure that we have external visible ip
m_have_address = true;
@@ -1162,6 +1139,7 @@ namespace nodetool
pi = context.peer_id = rsp.node_data.peer_id;
context.m_rpc_port = rsp.node_data.rpc_port;
context.m_rpc_credits_per_hash = rsp.node_data.rpc_credits_per_hash;
+ context.support_flags = rsp.node_data.support_flags;
const auto azone = context.m_remote_address.get_zone();
network_zone& zone = m_network_zones.at(azone);
zone.m_peerlist.set_peer_just_seen(rsp.node_data.peer_id, context.m_remote_address, context.m_pruning_seed, context.m_rpc_port, context.m_rpc_credits_per_hash);
@@ -1195,10 +1173,11 @@ namespace nodetool
}
else if (!just_take_peerlist)
{
- try_get_support_flags(context_, [](p2p_connection_context& flags_context, const uint32_t& support_flags)
- {
- flags_context.support_flags = support_flags;
- });
+ if (context_.support_flags == 0)
+ try_get_support_flags(context_, [](p2p_connection_context& flags_context, const uint32_t& support_flags)
+ {
+ flags_context.support_flags = support_flags;
+ });
}
return hsh_result;
@@ -2022,6 +2001,8 @@ namespace nodetool
boost::split(ips, record, boost::is_any_of(";"));
for (const auto &ip: ips)
{
+ if (ip.empty())
+ continue;
const expect<epee::net_utils::network_address> parsed_addr = net::get_network_address(ip, 0);
if (!parsed_addr)
{
@@ -2125,10 +2106,6 @@ namespace nodetool
continue;
}
local_peerlist[i].last_seen = 0;
-
-#ifdef CRYPTONOTE_PRUNING_DEBUG_SPOOF_SEED
- be.pruning_seed = tools::make_pruning_seed(1 + (be.adr.as<epee::net_utils::ipv4_network_address>().ip()) % (1ul << CRYPTONOTE_PRUNING_LOG_STRIPES), CRYPTONOTE_PRUNING_LOG_STRIPES);
-#endif
}
return true;
}
@@ -2174,6 +2151,7 @@ namespace nodetool
node_data.rpc_port = zone.m_can_pingback ? m_rpc_port : 0;
node_data.rpc_credits_per_hash = zone.m_can_pingback ? m_rpc_credits_per_hash : 0;
node_data.network_id = m_network_id;
+ node_data.support_flags = zone.m_config.m_support_flags;
return true;
}
//-----------------------------------------------------------------------------------
@@ -2544,6 +2522,7 @@ namespace nodetool
context.m_in_timedsync = false;
context.m_rpc_port = arg.node_data.rpc_port;
context.m_rpc_credits_per_hash = arg.node_data.rpc_credits_per_hash;
+ context.support_flags = arg.node_data.support_flags;
if(arg.node_data.my_port && zone.m_can_pingback)
{
@@ -2577,10 +2556,11 @@ namespace nodetool
});
}
- try_get_support_flags(context, [](p2p_connection_context& flags_context, const uint32_t& support_flags)
- {
- flags_context.support_flags = support_flags;
- });
+ if (context.support_flags == 0)
+ try_get_support_flags(context, [](p2p_connection_context& flags_context, const uint32_t& support_flags)
+ {
+ flags_context.support_flags = support_flags;
+ });
//fill response
zone.m_peerlist.get_peerlist_head(rsp.local_peerlist_new, true);
@@ -2846,8 +2826,7 @@ namespace nodetool
if (address.get_zone() != epee::net_utils::zone::public_)
return false; // Unable to determine how many connections from host
- const size_t max_connections = 1;
- size_t count = 0;
+ uint32_t count = 0;
m_network_zones.at(epee::net_utils::zone::public_).m_net_server.get_config_object().foreach_connection([&](const p2p_connection_context& cntxt)
{
diff --git a/src/p2p/net_peerlist_boost_serialization.h b/src/p2p/net_peerlist_boost_serialization.h
index 37a85d526..1cf4cb026 100644
--- a/src/p2p/net_peerlist_boost_serialization.h
+++ b/src/p2p/net_peerlist_boost_serialization.h
@@ -38,10 +38,6 @@
#include "net/i2p_address.h"
#include "p2p/p2p_protocol_defs.h"
-#ifdef CRYPTONOTE_PRUNING_DEBUG_SPOOF_SEED
-#include "common/pruning.h"
-#endif
-
BOOST_CLASS_VERSION(nodetool::peerlist_entry, 3)
namespace boost
@@ -228,12 +224,6 @@ namespace boost
return;
}
a & pl.pruning_seed;
-#ifdef CRYPTONOTE_PRUNING_DEBUG_SPOOF_SEED
- if (!typename Archive::is_saving())
- {
- pl.pruning_seed = tools::make_pruning_seed(1+pl.adr.as<epee::net_utils::ipv4_network_address>().ip() % (1<<CRYPTONOTE_PRUNING_LOG_STRIPES), CRYPTONOTE_PRUNING_LOG_STRIPES);
- }
-#endif
if (ver < 2)
{
if (!typename Archive::is_saving())
diff --git a/src/p2p/p2p_protocol_defs.h b/src/p2p/p2p_protocol_defs.h
index b439dc47e..12763d4ee 100644
--- a/src/p2p/p2p_protocol_defs.h
+++ b/src/p2p/p2p_protocol_defs.h
@@ -188,6 +188,7 @@ namespace nodetool
uint16_t rpc_port;
uint32_t rpc_credits_per_hash;
peerid_type peer_id;
+ uint32_t support_flags;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_VAL_POD_AS_BLOB(network_id)
@@ -195,6 +196,7 @@ namespace nodetool
KV_SERIALIZE(my_port)
KV_SERIALIZE_OPT(rpc_port, (uint16_t)(0))
KV_SERIALIZE_OPT(rpc_credits_per_hash, (uint32_t)0)
+ KV_SERIALIZE_OPT(support_flags, (uint32_t)0)
END_KV_SERIALIZE_MAP()
};
diff --git a/src/ringct/multiexp.cc b/src/ringct/multiexp.cc
index f69b4a12c..620f7d0dd 100644
--- a/src/ringct/multiexp.cc
+++ b/src/ringct/multiexp.cc
@@ -372,7 +372,6 @@ std::shared_ptr<straus_cached_data> straus_init_cache(const std::vector<Multiexp
if (N == 0)
N = data.size();
CHECK_AND_ASSERT_THROW_MES(N <= data.size(), "Bad cache base data");
- ge_cached cached;
ge_p1p1 p1;
ge_p3 p3;
std::shared_ptr<straus_cached_data> cache(new straus_cached_data());
@@ -454,7 +453,6 @@ rct::key straus(const std::vector<MultiexpData> &data, const std::shared_ptr<str
std::shared_ptr<straus_cached_data> local_cache = cache == NULL ? straus_init_cache(data) : cache;
ge_cached cached;
ge_p1p1 p1;
- ge_p3 p3;
#ifdef TRACK_STRAUS_ZERO_IDENTITY
MULTIEXP_PERF(PERF_TIMER_START_UNIT(skip, 1000000));
@@ -587,7 +585,6 @@ std::shared_ptr<pippenger_cached_data> pippenger_init_cache(const std::vector<Mu
if (N == 0)
N = data.size() - start_offset;
CHECK_AND_ASSERT_THROW_MES(N <= data.size() - start_offset, "Bad cache base data");
- ge_cached cached;
std::shared_ptr<pippenger_cached_data> cache(new pippenger_cached_data());
cache->size = N;
diff --git a/src/ringct/rctSigs.cpp b/src/ringct/rctSigs.cpp
index 93eb52d4e..f5950c53c 100644
--- a/src/ringct/rctSigs.cpp
+++ b/src/ringct/rctSigs.cpp
@@ -725,7 +725,6 @@ namespace rct {
CHECK_AND_ASSERT_THROW_MES((kLRki && mscout) || (!kLRki && !mscout), "Only one of kLRki/mscout is present");
keyV tmp(rows + 1);
keyV sk(rows + 1);
- size_t i;
keyM M(cols, tmp);
keyV P, C, C_nonzero;
@@ -899,7 +898,6 @@ namespace rct {
key R;
geDsmp P_precomp;
geDsmp C_precomp;
- geDsmp H_precomp;
size_t i = 0;
ge_p3 hash8_p3;
geDsmp hash_precomp;
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index db228dd94..15b2a9bfd 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -44,6 +44,7 @@ using namespace epee;
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "cryptonote_basic/account.h"
#include "cryptonote_basic/cryptonote_basic_impl.h"
+#include "cryptonote_basic/merge_mining.h"
#include "cryptonote_core/tx_sanity_check.h"
#include "misc_language.h"
#include "net/parse.h"
@@ -278,6 +279,7 @@ namespace cryptonote
}
}
disable_rpc_ban = rpc_config->disable_rpc_ban;
+ const std::string data_dir{command_line::get_arg(vm, cryptonote::arg_data_dir)};
std::string address = command_line::get_arg(vm, arg_rpc_payment_address);
if (!address.empty() && allow_rpc_payment)
{
@@ -306,7 +308,7 @@ namespace cryptonote
}
m_rpc_payment_allow_free_loopback = command_line::get_arg(vm, arg_rpc_payment_allow_free_loopback);
m_rpc_payment.reset(new rpc_payment(info.address, diff, credits));
- m_rpc_payment->load(command_line::get_arg(vm, cryptonote::arg_data_dir));
+ m_rpc_payment->load(data_dir);
m_p2p.set_rpc_credits_per_hash(RPC_CREDITS_PER_HASH_SCALE * (credits / (float)diff));
}
@@ -333,12 +335,32 @@ namespace cryptonote
if (m_rpc_payment)
m_net_server.add_idle_handler([this](){ return m_rpc_payment->on_idle(); }, 60 * 1000);
+ bool store_ssl_key = !restricted && rpc_config->ssl_options.auth.certificate_path.empty();
+ const auto ssl_base_path = (boost::filesystem::path{data_dir} / "rpc_ssl").string();
+ if (store_ssl_key && boost::filesystem::exists(ssl_base_path + ".crt"))
+ {
+ // load key from previous run, password prompted by OpenSSL
+ store_ssl_key = false;
+ rpc_config->ssl_options.auth =
+ epee::net_utils::ssl_authentication_t{ssl_base_path + ".key", ssl_base_path + ".crt"};
+ }
+
auto rng = [](size_t len, uint8_t *ptr){ return crypto::rand(len, ptr); };
- return epee::http_server_impl_base<core_rpc_server, connection_context>::init(
+ const bool inited = epee::http_server_impl_base<core_rpc_server, connection_context>::init(
rng, std::move(port), std::move(bind_ip_str),
std::move(bind_ipv6_str), std::move(rpc_config->use_ipv6), std::move(rpc_config->require_ipv4),
std::move(rpc_config->access_control_origins), std::move(http_login), std::move(rpc_config->ssl_options)
);
+
+ if (store_ssl_key && inited)
+ {
+ // new keys were generated, store for next run
+ const auto error = epee::net_utils::store_ssl_keys(m_net_server.get_ssl_context(), ssl_base_path);
+ if (error)
+ MFATAL("Failed to store HTTP SSL cert/key for " << (restricted ? "restricted " : "") << "RPC server: " << error.message());
+ return !bool(error);
+ }
+ return inited;
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::check_payment(const std::string &client_message, uint64_t payment, const std::string &rpc, bool same_ts, std::string &message, uint64_t &credits, std::string &top_hash)
@@ -367,7 +389,6 @@ namespace cryptonote
message = "Client signature does not verify for " + rpc;
return false;
}
- crypto::public_key local_client;
if (!m_rpc_payment->pay(client, ts, payment, rpc, same_ts, credits))
{
message = CORE_RPC_STATUS_PAYMENT_REQUIRED;
@@ -1806,7 +1827,6 @@ namespace cryptonote
return false;
}
}
- uint64_t seed_height;
crypto::hash seed_hash, next_seed_hash;
if (!get_block_template(info.address, req.prev_block.empty() ? NULL : &prev_block, blob_reserve, reserved_offset, wdiff, res.height, res.expected_reward, b, res.seed_height, seed_hash, next_seed_hash, error_resp))
return false;
@@ -1828,6 +1848,125 @@ namespace cryptonote
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
+ bool core_rpc_server::on_add_aux_pow(const COMMAND_RPC_ADD_AUX_POW::request& req, COMMAND_RPC_ADD_AUX_POW::response& res, epee::json_rpc::error& error_resp, const connection_context *ctx)
+ {
+ RPC_TRACKER(add_aux_pow);
+ bool r;
+ if (use_bootstrap_daemon_if_necessary<COMMAND_RPC_ADD_AUX_POW>(invoke_http_mode::JON_RPC, "add_aux_pow", req, res, r))
+ return r;
+
+ if (req.aux_pow.empty())
+ {
+ error_resp.code = CORE_RPC_ERROR_CODE_WRONG_PARAM;
+ error_resp.message = "Empty aux pow hash vector";
+ return false;
+ }
+
+ crypto::hash merkle_root;
+ size_t merkle_tree_depth = 0;
+ std::vector<std::pair<crypto::hash, crypto::hash>> aux_pow;
+ std::vector<crypto::hash> aux_pow_raw;
+ aux_pow.reserve(req.aux_pow.size());
+ aux_pow_raw.reserve(req.aux_pow.size());
+ for (const auto &s: req.aux_pow)
+ {
+ aux_pow.push_back({});
+ if (!epee::string_tools::hex_to_pod(s.id, aux_pow.back().first))
+ {
+ error_resp.code = CORE_RPC_ERROR_CODE_WRONG_PARAM;
+ error_resp.message = "Invalid aux pow id";
+ return false;
+ }
+ if (!epee::string_tools::hex_to_pod(s.hash, aux_pow.back().second))
+ {
+ error_resp.code = CORE_RPC_ERROR_CODE_WRONG_PARAM;
+ error_resp.message = "Invalid aux pow hash";
+ return false;
+ }
+ aux_pow_raw.push_back(aux_pow.back().second);
+ }
+
+ size_t path_domain = 1;
+ while ((1u << path_domain) < aux_pow.size())
+ ++path_domain;
+ uint32_t nonce;
+ const uint32_t max_nonce = 65535;
+ bool collision = true;
+ for (nonce = 0; nonce <= max_nonce; ++nonce)
+ {
+ std::vector<bool> slots(aux_pow.size(), false);
+ collision = false;
+ for (size_t idx = 0; idx < aux_pow.size(); ++idx)
+ {
+ const uint32_t slot = cryptonote::get_aux_slot(aux_pow[idx].first, nonce, aux_pow.size());
+ if (slot >= aux_pow.size())
+ {
+ error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
+ error_resp.message = "Computed slot is out of range";
+ return false;
+ }
+ if (slots[slot])
+ {
+ collision = true;
+ break;
+ }
+ slots[slot] = true;
+ }
+ if (!collision)
+ break;
+ }
+ if (collision)
+ {
+ error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
+ error_resp.message = "Failed to find a suitable nonce";
+ return false;
+ }
+
+ crypto::tree_hash((const char(*)[crypto::HASH_SIZE])aux_pow_raw.data(), aux_pow_raw.size(), merkle_root.data);
+ res.merkle_root = epee::string_tools::pod_to_hex(merkle_root);
+ res.merkle_tree_depth = cryptonote::encode_mm_depth(aux_pow.size(), nonce);
+
+ blobdata blocktemplate_blob;
+ if (!epee::string_tools::parse_hexstr_to_binbuff(req.blocktemplate_blob, blocktemplate_blob))
+ {
+ error_resp.code = CORE_RPC_ERROR_CODE_WRONG_PARAM;
+ error_resp.message = "Invalid blocktemplate_blob";
+ return false;
+ }
+
+ block b;
+ if (!parse_and_validate_block_from_blob(blocktemplate_blob, b))
+ {
+ error_resp.code = CORE_RPC_ERROR_CODE_WRONG_BLOCKBLOB;
+ error_resp.message = "Wrong blocktemplate_blob";
+ return false;
+ }
+
+ if (!remove_field_from_tx_extra(b.miner_tx.extra, typeid(cryptonote::tx_extra_merge_mining_tag)))
+ {
+ error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
+ error_resp.message = "Error removing existing merkle root";
+ return false;
+ }
+ if (!add_mm_merkle_root_to_tx_extra(b.miner_tx.extra, merkle_root, merkle_tree_depth))
+ {
+ error_resp.code = CORE_RPC_ERROR_CODE_INTERNAL_ERROR;
+ error_resp.message = "Error adding merkle root";
+ return false;
+ }
+ b.invalidate_hashes();
+ b.miner_tx.invalidate_hashes();
+
+ const blobdata block_blob = t_serializable_object_to_blob(b);
+ const blobdata hashing_blob = get_block_hashing_blob(b);
+
+ res.blocktemplate_blob = string_tools::buff_to_hex_nodelimer(block_blob);
+ res.blockhashing_blob = string_tools::buff_to_hex_nodelimer(hashing_blob);
+ res.aux_pow = req.aux_pow;
+ res.status = CORE_RPC_STATUS_OK;
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_submitblock(const COMMAND_RPC_SUBMITBLOCK::request& req, COMMAND_RPC_SUBMITBLOCK::response& res, epee::json_rpc::error& error_resp, const connection_context *ctx)
{
RPC_TRACKER(submitblock);
diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h
index dcf6b4e4b..6736a6b7f 100644
--- a/src/rpc/core_rpc_server.h
+++ b/src/rpc/core_rpc_server.h
@@ -146,6 +146,7 @@ namespace cryptonote
MAP_JON_RPC_WE("on_getblockhash", on_getblockhash, COMMAND_RPC_GETBLOCKHASH)
MAP_JON_RPC_WE("get_block_template", on_getblocktemplate, COMMAND_RPC_GETBLOCKTEMPLATE)
MAP_JON_RPC_WE("getblocktemplate", on_getblocktemplate, COMMAND_RPC_GETBLOCKTEMPLATE)
+ MAP_JON_RPC_WE("add_aux_pow", on_add_aux_pow, COMMAND_RPC_ADD_AUX_POW)
MAP_JON_RPC_WE("submit_block", on_submitblock, COMMAND_RPC_SUBMITBLOCK)
MAP_JON_RPC_WE("submitblock", on_submitblock, COMMAND_RPC_SUBMITBLOCK)
MAP_JON_RPC_WE_IF("generateblocks", on_generateblocks, COMMAND_RPC_GENERATEBLOCKS, !m_restricted)
@@ -226,6 +227,7 @@ namespace cryptonote
bool on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request& req, COMMAND_RPC_GETBLOCKCOUNT::response& res, const connection_context *ctx = NULL);
bool on_getblockhash(const COMMAND_RPC_GETBLOCKHASH::request& req, COMMAND_RPC_GETBLOCKHASH::response& res, epee::json_rpc::error& error_resp, const connection_context *ctx = NULL);
bool on_getblocktemplate(const COMMAND_RPC_GETBLOCKTEMPLATE::request& req, COMMAND_RPC_GETBLOCKTEMPLATE::response& res, epee::json_rpc::error& error_resp, const connection_context *ctx = NULL);
+ bool on_add_aux_pow(const COMMAND_RPC_ADD_AUX_POW::request& req, COMMAND_RPC_ADD_AUX_POW::response& res, epee::json_rpc::error& error_resp, const connection_context *ctx = NULL);
bool on_submitblock(const COMMAND_RPC_SUBMITBLOCK::request& req, COMMAND_RPC_SUBMITBLOCK::response& res, epee::json_rpc::error& error_resp, const connection_context *ctx = NULL);
bool on_generateblocks(const COMMAND_RPC_GENERATEBLOCKS::request& req, COMMAND_RPC_GENERATEBLOCKS::response& res, epee::json_rpc::error& error_resp, const connection_context *ctx = NULL);
bool on_get_last_block_header(const COMMAND_RPC_GET_LAST_BLOCK_HEADER::request& req, COMMAND_RPC_GET_LAST_BLOCK_HEADER::response& res, epee::json_rpc::error& error_resp, const connection_context *ctx = NULL);
diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h
index bbcb27f1c..e7bcb5570 100644
--- a/src/rpc/core_rpc_server_commands_defs.h
+++ b/src/rpc/core_rpc_server_commands_defs.h
@@ -88,7 +88,7 @@ namespace cryptonote
// advance which version they will stop working with
// Don't go over 32767 for any of these
#define CORE_RPC_VERSION_MAJOR 3
-#define CORE_RPC_VERSION_MINOR 5
+#define CORE_RPC_VERSION_MINOR 6
#define MAKE_CORE_RPC_VERSION(major,minor) (((major)<<16)|(minor))
#define CORE_RPC_VERSION MAKE_CORE_RPC_VERSION(CORE_RPC_VERSION_MAJOR, CORE_RPC_VERSION_MINOR)
@@ -938,6 +938,52 @@ namespace cryptonote
typedef epee::misc_utils::struct_init<response_t> response;
};
+ struct COMMAND_RPC_ADD_AUX_POW
+ {
+ struct aux_pow_t
+ {
+ std::string id;
+ std::string hash;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(id)
+ KV_SERIALIZE(hash)
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct request_t: public rpc_request_base
+ {
+ blobdata blocktemplate_blob;
+ std::vector<aux_pow_t> aux_pow;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE_PARENT(rpc_request_base)
+ KV_SERIALIZE(blocktemplate_blob)
+ KV_SERIALIZE(aux_pow)
+ END_KV_SERIALIZE_MAP()
+ };
+ typedef epee::misc_utils::struct_init<request_t> request;
+
+ struct response_t: public rpc_response_base
+ {
+ blobdata blocktemplate_blob;
+ blobdata blockhashing_blob;
+ std::string merkle_root;
+ uint32_t merkle_tree_depth;
+ std::vector<aux_pow_t> aux_pow;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE_PARENT(rpc_response_base)
+ KV_SERIALIZE(blocktemplate_blob)
+ KV_SERIALIZE(blockhashing_blob)
+ KV_SERIALIZE(merkle_root)
+ KV_SERIALIZE(merkle_tree_depth)
+ KV_SERIALIZE(aux_pow)
+ END_KV_SERIALIZE_MAP()
+ };
+ typedef epee::misc_utils::struct_init<response_t> response;
+ };
+
struct COMMAND_RPC_SUBMITBLOCK
{
typedef std::vector<std::string> request;
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index dfd6adf3a..2a3c33f48 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -195,7 +195,7 @@ namespace
const char* USAGE_SWEEP_BELOW("sweep_below <amount_threshold> [index=<N1>[,<N2>,...]] [<priority>] [<ring_size>] <address> [<payment_id (obsolete)>]");
const char* USAGE_SWEEP_SINGLE("sweep_single [<priority>] [<ring_size>] [outputs=<N>] <key_image> <address> [<payment_id (obsolete)>]");
const char* USAGE_DONATE("donate [index=<N1>[,<N2>,...]] [<priority>] [<ring_size>] <amount> [<payment_id (obsolete)>]");
- const char* USAGE_SIGN_TRANSFER("sign_transfer [export_raw]");
+ const char* USAGE_SIGN_TRANSFER("sign_transfer [export_raw] [<filename>]");
const char* USAGE_SET_LOG("set_log <level>|{+,-,}<categories>");
const char* USAGE_ACCOUNT("account\n"
" account new <label text with white spaces allowed>\n"
@@ -282,6 +282,7 @@ namespace
const char* USAGE_VERSION("version");
const char* USAGE_HELP("help [<command> | all]");
const char* USAGE_APROPOS("apropos <keyword> [<keyword> ...]");
+ const char* USAGE_SCAN_TX("scan_tx <txid> [<txid> ...]");
std::string input_line(const std::string& prompt, bool yesno = false)
{
@@ -1360,7 +1361,7 @@ bool simple_wallet::import_multisig_main(const std::vector<std::string> &args, b
size_t n_outputs = m_wallet->import_multisig(info);
// Clear line "Height xxx of xxx"
std::cout << "\r \r";
- success_msg_writer() << tr("Multisig info imported");
+ success_msg_writer() << tr("Multisig info imported. Number of outputs updated: ") << n_outputs;
}
catch (const std::exception &e)
{
@@ -3214,6 +3215,45 @@ bool simple_wallet::apropos(const std::vector<std::string> &args)
return true;
}
+bool simple_wallet::scan_tx(const std::vector<std::string> &args)
+{
+ if (args.empty())
+ {
+ PRINT_USAGE(USAGE_SCAN_TX);
+ return true;
+ }
+
+ // Parse and dedup args
+ std::unordered_set<crypto::hash> txids;
+ for (const auto &s : args) {
+ crypto::hash txid;
+ if (!epee::string_tools::hex_to_pod(s, txid)) {
+ fail_msg_writer() << tr("Invalid txid specified: ") << s;
+ return true;
+ }
+ txids.insert(txid);
+ }
+ std::vector<crypto::hash> txids_v(txids.begin(), txids.end());
+
+ if (!m_wallet->is_trusted_daemon()) {
+ message_writer(console_color_red, true) << tr("WARNING: this operation may reveal the txids to the remote node and affect your privacy");
+ if (!command_line::is_yes(input_line("Do you want to continue?", true))) {
+ message_writer() << tr("You have canceled the operation");
+ return true;
+ }
+ }
+
+ LOCK_IDLE_SCOPE();
+ m_in_manual_refresh.store(true);
+ try {
+ m_wallet->scan_tx(txids_v);
+ } catch (const std::exception &e) {
+ fail_msg_writer() << e.what();
+ }
+ m_in_manual_refresh.store(false);
+ return true;
+}
+
simple_wallet::simple_wallet()
: m_allow_mismatched_daemon_version(false)
, m_refresh_progress_reporter(*this)
@@ -3301,7 +3341,8 @@ simple_wallet::simple_wallet()
m_cmd_binder.set_handler("sign_transfer",
boost::bind(&simple_wallet::on_command, this, &simple_wallet::sign_transfer, _1),
tr(USAGE_SIGN_TRANSFER),
- tr("Sign a transaction from a file. If the parameter \"export_raw\" is specified, transaction raw hex data suitable for the daemon RPC /sendrawtransaction is exported."));
+ tr("Sign a transaction from a file. If the parameter \"export_raw\" is specified, transaction raw hex data suitable for the daemon RPC /sendrawtransaction is exported.\n"
+ "Use the parameter <filename> to specify the file to read from. If not specified, the default \"unsigned_monero_tx\" will be used."));
m_cmd_binder.set_handler("submit_transfer",
boost::bind(&simple_wallet::on_command, this, &simple_wallet::submit_transfer, _1),
tr("Submit a signed transaction from a file."));
@@ -3763,6 +3804,10 @@ simple_wallet::simple_wallet()
boost::bind(&simple_wallet::on_command, this, &simple_wallet::apropos, _1),
tr(USAGE_APROPOS),
tr("Search all command descriptions for keyword(s)"));
+ m_cmd_binder.set_handler("scan_tx",
+ boost::bind(&simple_wallet::on_command, this, &simple_wallet::scan_tx, _1),
+ tr(USAGE_SCAN_TX),
+ tr("Scan the transactions given by <txid>(s), processing them and looking for outputs"));
m_cmd_binder.set_unknown_command_handler(boost::bind(&simple_wallet::on_command, this, &simple_wallet::on_unknown_command, _1));
m_cmd_binder.set_empty_command_handler(boost::bind(&simple_wallet::on_empty_command, this));
m_cmd_binder.set_cancel_handler(boost::bind(&simple_wallet::on_cancelled_command, this));
@@ -4519,7 +4564,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm)
password = *r;
welcome = true;
// if no block_height is specified, assume its a new account and start it "now"
- if(m_wallet->get_refresh_from_block_height() == 0) {
+ if (command_line::is_arg_defaulted(vm, arg_restore_height)) {
{
tools::scoped_message_writer wrt = tools::msg_writer();
wrt << tr("No restore height is specified.") << " ";
@@ -5937,7 +5982,7 @@ bool simple_wallet::show_balance_unlocked(bool detailed)
if (m_wallet->has_multisig_partial_key_images())
extra = tr(" (Some owned outputs have partial key images - import_multisig_info needed)");
else if (m_wallet->has_unknown_key_images())
- extra += tr(" (Some owned outputs have missing key images - import_key_images needed)");
+ extra += tr(" (Some owned outputs have missing key images - export_outputs, import_outputs, export_key_images, and import_key_images needed)");
success_msg_writer() << tr("Currently selected account: [") << m_current_subaddress_account << tr("] ") << m_wallet->get_subaddress_label({m_current_subaddress_account, 0});
const std::string tag = m_wallet->get_account_tags().second[m_current_subaddress_account];
success_msg_writer() << tr("Tag: ") << (tag.empty() ? std::string{tr("(No tag assigned)")} : tag);
@@ -6468,8 +6513,6 @@ void simple_wallet::check_for_inactivity_lock(bool user)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::on_command(bool (simple_wallet::*cmd)(const std::vector<std::string>&), const std::vector<std::string> &args)
{
- const time_t now = time(NULL);
- time_t dt = now - m_last_activity_time;
m_last_activity_time = time(NULL);
m_in_command = true;
@@ -7435,7 +7478,6 @@ bool simple_wallet::sweep_single(const std::vector<std::string> &args_)
if (local_args.size() == 3)
{
crypto::hash payment_id;
- crypto::hash8 payment_id8;
std::string extra_nonce;
if (tools::wallet2::parse_long_payment_id(local_args.back(), payment_id))
{
@@ -7891,19 +7933,33 @@ bool simple_wallet::sign_transfer(const std::vector<std::string> &args_)
fail_msg_writer() << tr("This is a watch only wallet");
return true;
}
- if (args_.size() > 1 || (args_.size() == 1 && args_[0] != "export_raw"))
+
+ bool export_raw = false;
+ std::string unsigned_filename = "unsigned_monero_tx";
+ if (args_.size() > 2 || (args_.size() == 2 && args_[0] != "export_raw"))
{
PRINT_USAGE(USAGE_SIGN_TRANSFER);
return true;
}
+ else if (args_.size() == 2)
+ {
+ export_raw = true;
+ unsigned_filename = args_[1];
+ }
+ else if (args_.size() == 1)
+ {
+ if (args_[0] == "export_raw")
+ export_raw = true;
+ else
+ unsigned_filename = args_[0];
+ }
SCOPED_WALLET_UNLOCK();
- const bool export_raw = args_.size() == 1;
std::vector<tools::wallet2::pending_tx> ptx;
try
{
- bool r = m_wallet->sign_tx("unsigned_monero_tx", "signed_monero_tx", ptx, [&](const tools::wallet2::unsigned_tx_set &tx){ return accept_loaded_tx(tx); }, export_raw);
+ bool r = m_wallet->sign_tx(unsigned_filename, "signed_monero_tx", ptx, [&](const tools::wallet2::unsigned_tx_set &tx){ return accept_loaded_tx(tx); }, export_raw);
if (!r)
{
fail_msg_writer() << tr("Failed to sign transaction");
@@ -8601,7 +8657,6 @@ bool simple_wallet::get_transfers(std::vector<std::string>& local_args, std::vec
if (!unlocked)
{
locked_msg = "locked";
- const uint64_t unlock_time = pd.m_unlock_time;
if (pd.m_unlock_time < CRYPTONOTE_MAX_BLOCK_NUMBER)
{
uint64_t bh = std::max(pd.m_unlock_time, pd.m_block_height + CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE);
@@ -9466,7 +9521,7 @@ void simple_wallet::print_accounts()
{
const std::pair<std::map<std::string, std::string>, std::vector<std::string>>& account_tags = m_wallet->get_account_tags();
size_t num_untagged_accounts = m_wallet->get_num_subaddress_accounts();
- for (const std::pair<std::string, std::string>& p : account_tags.first)
+ for (const std::pair<const std::string, std::string>& p : account_tags.first)
{
const std::string& tag = p.first;
print_accounts(tag);
@@ -11180,7 +11235,6 @@ void simple_wallet::mms_next(const std::vector<std::string> &args)
void simple_wallet::mms_sync(const std::vector<std::string> &args)
{
- mms::message_store& ms = m_wallet->get_message_store();
if (args.size() != 0)
{
fail_msg_writer() << tr("Usage: mms sync");
@@ -11278,7 +11332,6 @@ void simple_wallet::mms_export(const std::vector<std::string> &args)
return;
}
LOCK_IDLE_SCOPE();
- mms::message_store& ms = m_wallet->get_message_store();
mms::message m;
bool valid_id = get_message_from_arg(args[0], m);
if (valid_id)
@@ -11347,7 +11400,6 @@ void simple_wallet::mms_show(const std::vector<std::string> &args)
return;
}
LOCK_IDLE_SCOPE();
- mms::message_store& ms = m_wallet->get_message_store();
mms::message m;
bool valid_id = get_message_from_arg(args[0], m);
if (valid_id)
@@ -11653,4 +11705,3 @@ bool simple_wallet::mms(const std::vector<std::string> &args)
return true;
}
// End MMS ------------------------------------------------------------------------------------------------
-
diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h
index 61104c87f..af654e0dd 100644
--- a/src/simplewallet/simplewallet.h
+++ b/src/simplewallet/simplewallet.h
@@ -158,6 +158,7 @@ namespace cryptonote
bool set_credits_target(const std::vector<std::string> &args = std::vector<std::string>());
bool help(const std::vector<std::string> &args = std::vector<std::string>());
bool apropos(const std::vector<std::string> &args);
+ bool scan_tx(const std::vector<std::string> &args);
bool start_mining(const std::vector<std::string> &args);
bool stop_mining(const std::vector<std::string> &args);
bool set_daemon(const std::vector<std::string> &args);
diff --git a/src/wallet/api/transaction_history.cpp b/src/wallet/api/transaction_history.cpp
index b6d52c58d..d8e4aab65 100644
--- a/src/wallet/api/transaction_history.cpp
+++ b/src/wallet/api/transaction_history.cpp
@@ -139,6 +139,7 @@ void TransactionHistoryImpl::refresh()
ti->m_paymentid = payment_id;
ti->m_coinbase = pd.m_coinbase;
ti->m_amount = pd.m_amount;
+ ti->m_fee = pd.m_fee;
ti->m_direction = TransactionInfo::Direction_In;
ti->m_hash = string_tools::pod_to_hex(pd.m_tx_hash);
ti->m_blockheight = pd.m_block_height;
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp
index 9acc8484c..4f923ce54 100644
--- a/src/wallet/api/wallet.cpp
+++ b/src/wallet/api/wallet.cpp
@@ -1168,7 +1168,7 @@ bool WalletImpl::submitTransaction(const string &fileName) {
return true;
}
-bool WalletImpl::exportKeyImages(const string &filename)
+bool WalletImpl::exportKeyImages(const string &filename, bool all)
{
if (m_wallet->watch_only())
{
@@ -1178,7 +1178,7 @@ bool WalletImpl::exportKeyImages(const string &filename)
try
{
- if (!m_wallet->export_key_images(filename))
+ if (!m_wallet->export_key_images(filename), all)
{
setStatusError(tr("failed to save file ") + filename);
return false;
diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h
index 3bf3e759b..e501d3943 100644
--- a/src/wallet/api/wallet.h
+++ b/src/wallet/api/wallet.h
@@ -164,7 +164,7 @@ public:
virtual PendingTransaction * createSweepUnmixableTransaction() override;
bool submitTransaction(const std::string &fileName) override;
virtual UnsignedTransaction * loadUnsignedTx(const std::string &unsigned_filename) override;
- bool exportKeyImages(const std::string &filename) override;
+ bool exportKeyImages(const std::string &filename, bool all = false) override;
bool importKeyImages(const std::string &filename) override;
virtual void disposeTransaction(PendingTransaction * t) override;
diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h
index 44928a422..b40b6763f 100644
--- a/src/wallet/api/wallet2_api.h
+++ b/src/wallet/api/wallet2_api.h
@@ -901,9 +901,10 @@ struct Wallet
/*!
* \brief exportKeyImages - exports key images to file
* \param filename
+ * \param all - export all key images or only those that have not yet been exported
* \return - true on success
*/
- virtual bool exportKeyImages(const std::string &filename) = 0;
+ virtual bool exportKeyImages(const std::string &filename, bool all = false) = 0;
/*!
* \brief importKeyImages - imports key images from file
diff --git a/src/wallet/message_store.cpp b/src/wallet/message_store.cpp
index 303b576c7..87cb75fbf 100644
--- a/src/wallet/message_store.cpp
+++ b/src/wallet/message_store.cpp
@@ -1340,7 +1340,10 @@ bool message_store::check_for_messages(const multisig_wallet_state &state, std::
}
}
std::vector<transport_message> transport_messages;
- bool r = m_transporter.receive_messages(destinations, transport_messages);
+ if (!m_transporter.receive_messages(destinations, transport_messages))
+ {
+ return false;
+ }
if (!m_run.load(std::memory_order_relaxed))
{
// Stop was called, don't waste time processing the messages
diff --git a/src/wallet/node_rpc_proxy.cpp b/src/wallet/node_rpc_proxy.cpp
index 48a602bf3..a576c267c 100644
--- a/src/wallet/node_rpc_proxy.cpp
+++ b/src/wallet/node_rpc_proxy.cpp
@@ -32,6 +32,8 @@
#include "rpc/rpc_payment_costs.h"
#include "storages/http_abstract_invoke.h"
+#include <boost/thread.hpp>
+
#define RETURN_ON_RPC_RESPONSE_ERROR(r, error, res, method) \
do { \
CHECK_AND_ASSERT_MES(error.code == 0, error.message, error.message); \
diff --git a/src/wallet/node_rpc_proxy.h b/src/wallet/node_rpc_proxy.h
index 51b7f01dd..f5e3fca5f 100644
--- a/src/wallet/node_rpc_proxy.h
+++ b/src/wallet/node_rpc_proxy.h
@@ -30,6 +30,7 @@
#include <string>
#include <boost/thread/mutex.hpp>
+#include <boost/thread/recursive_mutex.hpp>
#include "include_base_utils.h"
#include "net/abstract_http_client.h"
#include "rpc/core_rpc_server_commands_defs.h"
diff --git a/src/wallet/ringdb.cpp b/src/wallet/ringdb.cpp
index dfeb987ca..025a2037f 100644
--- a/src/wallet/ringdb.cpp
+++ b/src/wallet/ringdb.cpp
@@ -42,9 +42,6 @@
#define V1TAG ((uint64_t)798237759845202)
-static const char zerokey[8] = {0};
-static const MDB_val zerokeyval = { sizeof(zerokey), (void *)zerokey };
-
static int compare_hash32(const MDB_val *a, const MDB_val *b)
{
uint32_t *va = (uint32_t*) a->mv_data;
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index d80335db8..e298eca53 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -30,6 +30,7 @@
#include <numeric>
#include <tuple>
+#include <queue>
#include <boost/format.hpp>
#include <boost/optional/optional.hpp>
#include <boost/algorithm/string/classification.hpp>
@@ -344,8 +345,6 @@ std::string get_weight_string(const cryptonote::transaction &tx, size_t blob_siz
std::unique_ptr<tools::wallet2> make_basic(const boost::program_options::variables_map& vm, bool unattended, const options& opts, const std::function<boost::optional<tools::password_container>(const char *, bool)> &password_prompter)
{
- namespace ip = boost::asio::ip;
-
const bool testnet = command_line::get_arg(vm, opts.testnet);
const bool stagenet = command_line::get_arg(vm, opts.stagenet);
const network_type nettype = testnet ? TESTNET : stagenet ? STAGENET : MAINNET;
@@ -367,7 +366,7 @@ std::unique_ptr<tools::wallet2> make_basic(const boost::program_options::variabl
// user specified CA file or fingeprints implies enabled SSL by default
epee::net_utils::ssl_options_t ssl_options = epee::net_utils::ssl_support_t::e_ssl_support_enabled;
- if (command_line::get_arg(vm, opts.daemon_ssl_allow_any_cert))
+ if (daemon_ssl_allow_any_cert)
ssl_options.verification = epee::net_utils::ssl_verification_t::none;
else if (!daemon_ssl_ca_file.empty() || !daemon_ssl_allowed_fingerprints.empty())
{
@@ -1004,9 +1003,6 @@ bool get_pruned_tx(const cryptonote::COMMAND_RPC_GET_TRANSACTIONS::entry &entry,
namespace tools
{
-// for now, limit to 30 attempts. TODO: discuss a good number to limit to.
-const size_t MAX_SPLIT_ATTEMPTS = 30;
-
constexpr const std::chrono::seconds wallet2::rpc_timeout;
const char* wallet2::tr(const char* str) { return i18n_translate(str, "tools::wallet2"); }
@@ -1602,6 +1598,47 @@ std::string wallet2::get_subaddress_label(const cryptonote::subaddress_index& in
return m_subaddress_labels[index.major][index.minor];
}
//----------------------------------------------------------------------------------------------------
+void wallet2::scan_tx(const std::vector<crypto::hash> &txids)
+{
+ // Get the transactions from daemon in batches and add them to a priority queue ordered in chronological order
+ auto cmp_tx_entry = [](const cryptonote::COMMAND_RPC_GET_TRANSACTIONS::entry& l, const cryptonote::COMMAND_RPC_GET_TRANSACTIONS::entry& r)
+ { return l.block_height > r.block_height; };
+
+ std::priority_queue<cryptonote::COMMAND_RPC_GET_TRANSACTIONS::entry, std::vector<COMMAND_RPC_GET_TRANSACTIONS::entry>, decltype(cmp_tx_entry)> txq(cmp_tx_entry);
+ const size_t SLICE_SIZE = 100; // RESTRICTED_TRANSACTIONS_COUNT as defined in rpc/core_rpc_server.cpp, hardcoded in daemon code
+ for(size_t slice = 0; slice < txids.size(); slice += SLICE_SIZE) {
+ cryptonote::COMMAND_RPC_GET_TRANSACTIONS::request req = AUTO_VAL_INIT(req);
+ cryptonote::COMMAND_RPC_GET_TRANSACTIONS::response res = AUTO_VAL_INIT(res);
+ req.decode_as_json = false;
+ req.prune = true;
+
+ size_t ntxes = slice + SLICE_SIZE > txids.size() ? txids.size() - slice : SLICE_SIZE;
+ for (size_t i = slice; i < slice + ntxes; ++i)
+ req.txs_hashes.push_back(epee::string_tools::pod_to_hex(txids[i]));
+
+ {
+ const boost::lock_guard<boost::recursive_mutex> lock{m_daemon_rpc_mutex};
+ req.client = get_client_signature();
+ bool r = epee::net_utils::invoke_http_json("/gettransactions", req, res, *m_http_client, rpc_timeout);
+ THROW_WALLET_EXCEPTION_IF(!r, error::wallet_internal_error, "Failed to get transaction from daemon");
+ THROW_WALLET_EXCEPTION_IF(res.txs.size() != req.txs_hashes.size(), error::wallet_internal_error, "Failed to get transaction from daemon");
+ }
+
+ for (auto& tx_info : res.txs)
+ txq.push(tx_info);
+ }
+
+ // Process the transactions in chronologically ascending order
+ while(!txq.empty()) {
+ auto& tx_info = txq.top();
+ cryptonote::transaction tx;
+ crypto::hash tx_hash;
+ THROW_WALLET_EXCEPTION_IF(!get_pruned_tx(tx_info, tx, tx_hash), error::wallet_internal_error, "Failed to get transaction from daemon (2)");
+ process_new_transaction(tx_hash, tx, tx_info.output_indices, tx_info.block_height, 0, tx_info.block_timestamp, false, tx_info.in_pool, tx_info.double_spend_seen, {}, {});
+ txq.pop();
+ }
+}
+//----------------------------------------------------------------------------------------------------
void wallet2::set_subaddress_label(const cryptonote::subaddress_index& index, const std::string &label)
{
THROW_WALLET_EXCEPTION_IF(index.major >= m_subaddress_labels.size(), error::account_index_outofbound);
@@ -6042,6 +6079,14 @@ std::map<uint32_t, uint64_t> wallet2::balance_per_subaddress(uint32_t index_majo
found->second += utx.second.m_change;
}
}
+
+ for (const auto& utx: m_unconfirmed_payments)
+ {
+ if (utx.second.m_pd.m_subaddr_index.major == index_major)
+ {
+ amount_per_subaddr[utx.second.m_pd.m_subaddr_index.minor] += utx.second.m_pd.m_amount;
+ }
+ }
}
return amount_per_subaddr;
}
@@ -7984,7 +8029,6 @@ void wallet2::light_wallet_get_outs(std::vector<std::vector<tools::wallet2::get_
// Check if we got enough outputs for each amount
for(auto& out: ores.amount_outs) {
- const uint64_t out_amount = boost::lexical_cast<uint64_t>(out.amount);
THROW_WALLET_EXCEPTION_IF(out.outputs.size() < light_wallet_requested_outputs_count , error::wallet_internal_error, "Not enough outputs for amount: " + boost::lexical_cast<std::string>(out.amount));
MDEBUG(out.outputs.size() << " outputs for amount "+ boost::lexical_cast<std::string>(out.amount) + " received from light wallet node");
}
@@ -9778,13 +9822,18 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
TX() : weight(0), needed_fee(0) {}
- void add(const cryptonote::tx_destination_entry &de, uint64_t amount, unsigned int original_output_index, bool merge_destinations) {
+ /* Add an output to the transaction.
+ * Returns True if the output was added, False if there are no more available output slots.
+ */
+ bool add(const cryptonote::tx_destination_entry &de, uint64_t amount, unsigned int original_output_index, bool merge_destinations, size_t max_dsts) {
if (merge_destinations)
{
std::vector<cryptonote::tx_destination_entry>::iterator i;
i = std::find_if(dsts.begin(), dsts.end(), [&](const cryptonote::tx_destination_entry &d) { return !memcmp (&d.addr, &de.addr, sizeof(de.addr)); });
if (i == dsts.end())
{
+ if (dsts.size() >= max_dsts)
+ return false;
dsts.push_back(de);
i = dsts.end() - 1;
i->amount = 0;
@@ -9797,12 +9846,15 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
std::string("original_output_index too large: ") + std::to_string(original_output_index) + " > " + std::to_string(dsts.size()));
if (original_output_index == dsts.size())
{
+ if (dsts.size() >= max_dsts)
+ return false;
dsts.push_back(de);
dsts.back().amount = 0;
}
THROW_WALLET_EXCEPTION_IF(memcmp(&dsts[original_output_index].addr, &de.addr, sizeof(de.addr)), error::wallet_internal_error, "Mismatched destination address");
dsts[original_output_index].amount += amount;
}
+ return true;
}
};
std::vector<TX> txes;
@@ -10072,6 +10124,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
// clear any fake outs we'd already gathered, since we'll need a new set
outs.clear();
+ bool out_slots_exhausted = false;
if (adding_fee)
{
LOG_PRINT_L2("We need more fee, adding it to fee");
@@ -10084,20 +10137,32 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
// we can fully pay that destination
LOG_PRINT_L2("We can fully pay " << get_account_address_as_str(m_nettype, dsts[0].is_subaddress, dsts[0].addr) <<
" for " << print_money(dsts[0].amount));
- tx.add(dsts[0], dsts[0].amount, original_output_index, m_merge_destinations);
+ if (!tx.add(dsts[0], dsts[0].amount, original_output_index, m_merge_destinations, BULLETPROOF_MAX_OUTPUTS-1))
+ {
+ LOG_PRINT_L2("Didn't pay: ran out of output slots");
+ out_slots_exhausted = true;
+ break;
+ }
available_amount -= dsts[0].amount;
dsts[0].amount = 0;
pop_index(dsts, 0);
++original_output_index;
}
- if (available_amount > 0 && !dsts.empty() && estimate_tx_weight(use_rct, tx.selected_transfers.size(), fake_outs_count, tx.dsts.size()+1, extra.size(), bulletproof, clsag) < TX_WEIGHT_TARGET(upper_transaction_weight_limit)) {
+ if (!out_slots_exhausted && available_amount > 0 && !dsts.empty() && estimate_tx_weight(use_rct, tx.selected_transfers.size(), fake_outs_count, tx.dsts.size()+1, extra.size(), bulletproof, clsag) < TX_WEIGHT_TARGET(upper_transaction_weight_limit)) {
// we can partially fill that destination
LOG_PRINT_L2("We can partially pay " << get_account_address_as_str(m_nettype, dsts[0].is_subaddress, dsts[0].addr) <<
" for " << print_money(available_amount) << "/" << print_money(dsts[0].amount));
- tx.add(dsts[0], available_amount, original_output_index, m_merge_destinations);
- dsts[0].amount -= available_amount;
- available_amount = 0;
+ if (tx.add(dsts[0], available_amount, original_output_index, m_merge_destinations, BULLETPROOF_MAX_OUTPUTS-1))
+ {
+ dsts[0].amount -= available_amount;
+ available_amount = 0;
+ }
+ else
+ {
+ LOG_PRINT_L2("Didn't pay: ran out of output slots");
+ out_slots_exhausted = true;
+ }
}
}
@@ -10105,8 +10170,15 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
LOG_PRINT_L2("Considering whether to create a tx now, " << tx.selected_transfers.size() << " inputs, tx limit "
<< upper_transaction_weight_limit);
bool try_tx = false;
+
+ // If the new transaction is full, create it and start a new one
+ if (out_slots_exhausted)
+ {
+ LOG_PRINT_L2("Transaction is full, will create it and start a new tx");
+ try_tx = true;
+ }
// if we have preferred picks, but haven't yet used all of them, continue
- if (preferred_inputs.empty())
+ else if (preferred_inputs.empty())
{
if (adding_fee)
{
@@ -10303,8 +10375,6 @@ bool wallet2::sanity_check(const std::vector<wallet2::pending_tx> &ptx_vector, s
{
MDEBUG("sanity_check: " << ptx_vector.size() << " txes, " << dsts.size() << " destinations");
- hw::device &hwdev = m_account.get_device();
-
THROW_WALLET_EXCEPTION_IF(ptx_vector.empty(), error::wallet_internal_error, "No transactions");
// check every party in there does receive at least the required amount
@@ -10341,7 +10411,6 @@ bool wallet2::sanity_check(const std::vector<wallet2::pending_tx> &ptx_vector, s
for (const auto &r: required)
{
const account_public_address &address = r.first;
- const crypto::public_key &view_pkey = address.m_view_public_key;
uint64_t total_received = 0;
for (const auto &ptx: ptx_vector)
@@ -13229,7 +13298,6 @@ rct::multisig_kLRki wallet2::get_multisig_composite_kLRki(size_t n, const std::u
{
CHECK_AND_ASSERT_THROW_MES(n < m_transfers.size(), "Bad transfer index");
- const transfer_details &td = m_transfers[n];
rct::multisig_kLRki kLRki = get_multisig_kLRki(n, rct::skGen());
// pick a L/R pair from every other participant but one
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index 2e455c40c..e5a5136a4 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -1264,6 +1264,8 @@ private:
std::string get_spend_proof(const crypto::hash &txid, const std::string &message);
bool check_spend_proof(const crypto::hash &txid, const std::string &message, const std::string &sig_str);
+ void scan_tx(const std::vector<crypto::hash> &txids);
+
/*!
* \brief Generates a proof that proves the reserve of unspent funds
* \param account_minreserve When specified, collect outputs only belonging to the given account and prove the smallest reserve above the given amount
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index 03db8b70f..327a189ca 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -687,7 +687,7 @@ namespace tools
{
if (!m_wallet) return not_open(er);
const std::pair<std::map<std::string, std::string>, std::vector<std::string>> account_tags = m_wallet->get_account_tags();
- for (const std::pair<std::string, std::string>& p : account_tags.first)
+ for (const std::pair<const std::string, std::string>& p : account_tags.first)
{
res.account_tags.resize(res.account_tags.size() + 1);
auto& info = res.account_tags.back();
@@ -1282,7 +1282,6 @@ namespace tools
dests.erase(cd.change_dts.addr);
}
- size_t n_dummy_outputs = 0;
for (auto i = dests.begin(); i != dests.end(); )
{
if (i->second.second > 0)
@@ -4438,7 +4437,14 @@ public:
wal->stop();
});
- wal->refresh(wal->is_trusted_daemon());
+ try
+ {
+ wal->refresh(wal->is_trusted_daemon());
+ }
+ catch (const std::exception& e)
+ {
+ LOG_ERROR(tools::wallet_rpc_server::tr("Initial refresh failed: ") << e.what());
+ }
// if we ^C during potentially length load/refresh, there's no server loop yet
if (quit)
{
diff --git a/tests/core_tests/transaction_tests.cpp b/tests/core_tests/transaction_tests.cpp
index d0b55dcf4..d19bdd1f9 100644
--- a/tests/core_tests/transaction_tests.cpp
+++ b/tests/core_tests/transaction_tests.cpp
@@ -78,8 +78,6 @@ bool test_transaction_generation_and_ring_signature()
tx_source_entry& src = sources.back();
src.amount = 70368744177663;
{
- tx_output_entry oe;
-
src.push_output(0, boost::get<txout_to_key>(tx_mine_1.vout[0].target).key, src.amount);
src.push_output(1, boost::get<txout_to_key>(tx_mine_2.vout[0].target).key, src.amount);
diff --git a/tests/core_tests/tx_pool.cpp b/tests/core_tests/tx_pool.cpp
index 1e496f3da..166eb6075 100644
--- a/tests/core_tests/tx_pool.cpp
+++ b/tests/core_tests/tx_pool.cpp
@@ -165,9 +165,6 @@ bool txpool_double_spend_base::timestamp_change_pause(cryptonote::core& /*c*/, s
bool txpool_double_spend_base::check_changed(cryptonote::core& c, const size_t ev_index, relay_test condition)
{
- const std::size_t public_hash_count = m_broadcasted_hashes.size();
- const std::size_t all_hash_count = m_all_hashes.size();
-
const std::size_t new_broadcasted_hash_count = m_broadcasted_hashes.size() + unsigned(condition == relay_test::broadcasted);
const std::size_t new_all_hash_count = m_all_hashes.size() + unsigned(condition == relay_test::hidden) + unsigned(condition == relay_test::no_relay);
@@ -393,7 +390,7 @@ bool txpool_double_spend_base::check_changed(cryptonote::core& c, const size_t e
}
}
- for (const std::pair<crypto::hash, uint64_t>& hash : m_all_hashes)
+ for (const std::pair<const crypto::hash, uint64_t>& hash : m_all_hashes)
{
cryptonote::blobdata tx_blob{};
if (!c.get_pool_transaction(hash.first, tx_blob, cryptonote::relay_category::all))
@@ -411,7 +408,7 @@ bool txpool_double_spend_base::check_changed(cryptonote::core& c, const size_t e
for (const crypto::hash& hash : m_no_relay_hashes)
difference.erase(hash);
- for (const std::pair<crypto::hash, uint64_t>& hash : difference)
+ for (const std::pair<const crypto::hash, uint64_t>& hash : difference)
{
if (c.pool_has_tx(hash.first))
{
diff --git a/tests/functional_tests/mining.py b/tests/functional_tests/mining.py
index 1eb6b0ba7..50bfd32a2 100755
--- a/tests/functional_tests/mining.py
+++ b/tests/functional_tests/mining.py
@@ -97,7 +97,7 @@ class MiningTest():
# wait till we mined a few of them
target_height = prev_height + 5
height = prev_height
- timeout = 60 # randomx is slow to init
+ timeout = 240 # randomx is slow to init
while height < target_height:
seen_height = height
for _ in range(timeout):
diff --git a/tests/functional_tests/transactions_flow_test.cpp b/tests/functional_tests/transactions_flow_test.cpp
index cec6825f5..3f5f90d3b 100644
--- a/tests/functional_tests/transactions_flow_test.cpp
+++ b/tests/functional_tests/transactions_flow_test.cpp
@@ -41,7 +41,6 @@ using namespace cryptonote;
namespace
{
uint64_t const TEST_FEE = 5000000000; // 5 * 10^9
- uint64_t const TEST_DUST_THRESHOLD = 5000000000; // 5 * 10^9
}
std::string generate_random_wallet_name()
diff --git a/tests/net_load_tests/srv.cpp b/tests/net_load_tests/srv.cpp
index 84d97ebd4..fabe14f49 100644
--- a/tests/net_load_tests/srv.cpp
+++ b/tests/net_load_tests/srv.cpp
@@ -169,7 +169,7 @@ namespace
LOG_PRINT_L0("Closing connections. Number of opened connections: " << m_tcp_server.get_config_object().get_connections_count());
size_t count = 0;
- bool r = m_tcp_server.get_config_object().foreach_connection([&](test_connection_context& ctx) {
+ m_tcp_server.get_config_object().foreach_connection([&](test_connection_context& ctx) {
if (ctx.m_connection_id != cmd_conn_id)
{
++count;
diff --git a/tests/performance_tests/performance_tests.h b/tests/performance_tests/performance_tests.h
index ae7aabe08..7bedfdd4e 100644
--- a/tests/performance_tests/performance_tests.h
+++ b/tests/performance_tests/performance_tests.h
@@ -215,7 +215,6 @@ void run_test(const std::string &filter, Params &params, const char* test_name)
if (params.stats)
{
uint64_t mins = min / scale;
- uint64_t maxs = max / scale;
uint64_t meds = med / scale;
uint64_t p95s = quantiles[9] / scale;
uint64_t stddevs = stddev / scale;
diff --git a/tests/unit_tests/bulletproofs.cpp b/tests/unit_tests/bulletproofs.cpp
index 7c6e459f5..ee617938c 100644
--- a/tests/unit_tests/bulletproofs.cpp
+++ b/tests/unit_tests/bulletproofs.cpp
@@ -296,7 +296,6 @@ TEST(bulletproof, weight_pruned)
ASSERT_TRUE(tx.version == 2);
ASSERT_FALSE(tx.pruned);
ASSERT_TRUE(rct::is_rct_bulletproof(tx.rct_signatures.type));
- const uint64_t tx_size = bd.size();
const uint64_t tx_weight = cryptonote::get_transaction_weight(tx);
ASSERT_TRUE(parse_and_validate_tx_base_from_blob(bd, pruned_tx));
ASSERT_TRUE(pruned_tx.version == 2);
diff --git a/tests/unit_tests/crypto.cpp b/tests/unit_tests/crypto.cpp
index 7ac87ca7c..b550b35b0 100644
--- a/tests/unit_tests/crypto.cpp
+++ b/tests/unit_tests/crypto.cpp
@@ -33,6 +33,7 @@
#include <string>
#include "cryptonote_basic/cryptonote_basic_impl.h"
+#include "cryptonote_basic/merge_mining.h"
namespace
{
@@ -99,3 +100,215 @@ TEST(Crypto, verify_32)
}
}
}
+
+TEST(Crypto, tree_branch)
+{
+ crypto::hash inputs[6];
+ crypto::hash branch[8];
+ crypto::hash root, root2;
+ size_t depth;
+ uint32_t path, path2;
+
+ auto hasher = [](const crypto::hash &h0, const crypto::hash &h1) -> crypto::hash
+ {
+ char buffer[64];
+ memcpy(buffer, &h0, 32);
+ memcpy(buffer + 32, &h1, 32);
+ crypto::hash res;
+ cn_fast_hash(buffer, 64, res);
+ return res;
+ };
+
+ for (int n = 0; n < 6; ++n)
+ {
+ memset(&inputs[n], 0, 32);
+ inputs[n].data[0] = n + 1;
+ }
+
+ // empty
+ ASSERT_FALSE(crypto::tree_branch((const char(*)[32])inputs, 0, crypto::null_hash.data, (char(*)[32])branch, &depth, &path));
+
+ // one, matching
+ ASSERT_TRUE(crypto::tree_branch((const char(*)[32])inputs, 1, inputs[0].data, (char(*)[32])branch, &depth, &path));
+ ASSERT_EQ(depth, 0);
+ ASSERT_EQ(path, 0);
+ ASSERT_TRUE(crypto::tree_path(1, 0, &path2));
+ ASSERT_EQ(path, path2);
+ crypto::tree_hash((const char(*)[32])inputs, 1, root.data);
+ ASSERT_EQ(root, inputs[0]);
+ ASSERT_TRUE(crypto::is_branch_in_tree(inputs[0].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[1].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(crypto::null_hash.data, root.data, (const char(*)[32])branch, depth, path));
+
+ // one, not found
+ ASSERT_FALSE(crypto::tree_branch((const char(*)[32])inputs, 1, inputs[1].data, (char(*)[32])branch, &depth, &path));
+
+ // two, index 0
+ ASSERT_TRUE(crypto::tree_branch((const char(*)[32])inputs, 2, inputs[0].data, (char(*)[32])branch, &depth, &path));
+ ASSERT_EQ(depth, 1);
+ ASSERT_EQ(path, 0);
+ ASSERT_TRUE(crypto::tree_path(2, 0, &path2));
+ ASSERT_EQ(path, path2);
+ ASSERT_EQ(branch[0], inputs[1]);
+ crypto::tree_hash((const char(*)[32])inputs, 2, root.data);
+ ASSERT_EQ(root, hasher(inputs[0], inputs[1]));
+ ASSERT_TRUE(crypto::is_branch_in_tree(inputs[0].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[1].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[2].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(crypto::null_hash.data, root.data, (const char(*)[32])branch, depth, path));
+
+ // two, index 1
+ ASSERT_TRUE(crypto::tree_branch((const char(*)[32])inputs, 2, inputs[1].data, (char(*)[32])branch, &depth, &path));
+ ASSERT_EQ(depth, 1);
+ ASSERT_EQ(path, 1);
+ ASSERT_TRUE(crypto::tree_path(2, 1, &path2));
+ ASSERT_EQ(path, path2);
+ ASSERT_EQ(branch[0], inputs[0]);
+ crypto::tree_hash((const char(*)[32])inputs, 2, root.data);
+ ASSERT_EQ(root, hasher(inputs[0], inputs[1]));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[0].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_TRUE(crypto::is_branch_in_tree(inputs[1].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[2].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(crypto::null_hash.data, root.data, (const char(*)[32])branch, depth, path));
+
+ // two, not found
+ ASSERT_FALSE(crypto::tree_branch((const char(*)[32])inputs, 2, inputs[2].data, (char(*)[32])branch, &depth, &path));
+
+ // a b c 0
+ // x y
+ // z
+
+ // three, index 0
+ ASSERT_TRUE(crypto::tree_branch((const char(*)[32])inputs, 3, inputs[0].data, (char(*)[32])branch, &depth, &path));
+ ASSERT_GE(depth, 1);
+ ASSERT_LE(depth, 2);
+ ASSERT_TRUE(crypto::tree_path(3, 0, &path2));
+ ASSERT_EQ(path, path2);
+ crypto::tree_hash((const char(*)[32])inputs, 3, root.data);
+ ASSERT_EQ(root, hasher(inputs[0], hasher(inputs[1], inputs[2])));
+ ASSERT_TRUE(crypto::is_branch_in_tree(inputs[0].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[1].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[2].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[3].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(crypto::null_hash.data, root.data, (const char(*)[32])branch, depth, path));
+
+ // three, index 1
+ ASSERT_TRUE(crypto::tree_branch((const char(*)[32])inputs, 3, inputs[1].data, (char(*)[32])branch, &depth, &path));
+ ASSERT_GE(depth, 1);
+ ASSERT_LE(depth, 2);
+ ASSERT_TRUE(crypto::tree_path(3, 1, &path2));
+ ASSERT_EQ(path, path2);
+ crypto::tree_hash((const char(*)[32])inputs, 3, root.data);
+ ASSERT_EQ(root, hasher(inputs[0], hasher(inputs[1], inputs[2])));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[0].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_TRUE(crypto::is_branch_in_tree(inputs[1].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[2].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[3].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(crypto::null_hash.data, root.data, (const char(*)[32])branch, depth, path));
+
+ // three, index 2
+ ASSERT_TRUE(crypto::tree_branch((const char(*)[32])inputs, 3, inputs[2].data, (char(*)[32])branch, &depth, &path));
+ ASSERT_GE(depth, 1);
+ ASSERT_LE(depth, 2);
+ ASSERT_TRUE(crypto::tree_path(3, 2, &path2));
+ ASSERT_EQ(path, path2);
+ crypto::tree_hash((const char(*)[32])inputs, 3, root.data);
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[0].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[1].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_TRUE(crypto::is_branch_in_tree(inputs[2].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[3].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(crypto::null_hash.data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_TRUE(crypto::tree_branch_hash(inputs[2].data, (const char(*)[32])branch, depth, path, root2.data));
+ ASSERT_EQ(root, root2);
+
+ // three, not found
+ ASSERT_FALSE(crypto::tree_branch((const char(*)[32])inputs, 3, inputs[3].data, (char(*)[32])branch, &depth, &path));
+
+ // a b c d e 0 0 0
+ // x y
+ // z
+ // w
+
+ // five, index 0
+ ASSERT_TRUE(crypto::tree_branch((const char(*)[32])inputs, 5, inputs[0].data, (char(*)[32])branch, &depth, &path));
+ ASSERT_GE(depth, 2);
+ ASSERT_LE(depth, 3);
+ ASSERT_TRUE(crypto::tree_path(5, 0, &path2));
+ ASSERT_EQ(path, path2);
+ crypto::tree_hash((const char(*)[32])inputs, 5, root.data);
+ ASSERT_TRUE(crypto::is_branch_in_tree(inputs[0].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[1].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[2].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[3].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[4].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[5].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(crypto::null_hash.data, root.data, (const char(*)[32])branch, depth, path));
+
+ // five, index 1
+ ASSERT_TRUE(crypto::tree_branch((const char(*)[32])inputs, 5, inputs[1].data, (char(*)[32])branch, &depth, &path));
+ ASSERT_GE(depth, 2);
+ ASSERT_LE(depth, 3);
+ ASSERT_TRUE(crypto::tree_path(5, 1, &path2));
+ ASSERT_EQ(path, path2);
+ crypto::tree_hash((const char(*)[32])inputs, 5, root.data);
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[0].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_TRUE(crypto::is_branch_in_tree(inputs[1].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[2].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[3].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[4].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[5].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(crypto::null_hash.data, root.data, (const char(*)[32])branch, depth, path));
+
+ // five, index 2
+ ASSERT_TRUE(crypto::tree_branch((const char(*)[32])inputs, 5, inputs[2].data, (char(*)[32])branch, &depth, &path));
+ ASSERT_GE(depth, 2);
+ ASSERT_LE(depth, 3);
+ ASSERT_TRUE(crypto::tree_path(5, 2, &path2));
+ ASSERT_EQ(path, path2);
+ crypto::tree_hash((const char(*)[32])inputs, 5, root.data);
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[0].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[1].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_TRUE(crypto::is_branch_in_tree(inputs[2].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[3].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[4].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[5].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(crypto::null_hash.data, root.data, (const char(*)[32])branch, depth, path));
+
+ // five, index 4
+ ASSERT_TRUE(crypto::tree_branch((const char(*)[32])inputs, 5, inputs[4].data, (char(*)[32])branch, &depth, &path));
+ ASSERT_GE(depth, 2);
+ ASSERT_LE(depth, 3);
+ ASSERT_TRUE(crypto::tree_path(5, 4, &path2));
+ ASSERT_EQ(path, path2);
+ crypto::tree_hash((const char(*)[32])inputs, 5, root.data);
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[0].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[1].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[2].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[3].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_TRUE(crypto::is_branch_in_tree(inputs[4].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[5].data, root.data, (const char(*)[32])branch, depth, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(crypto::null_hash.data, root.data, (const char(*)[32])branch, depth, path));
+
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[4].data, root.data, (const char(*)[32])branch, depth - 1, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[4].data, root.data, (const char(*)[32])branch, depth + 1, path));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[4].data, root.data, (const char(*)[32])branch, depth, path ^ 1));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[4].data, root.data, (const char(*)[32])branch, depth, path ^ 2));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[4].data, root.data, (const char(*)[32])branch, depth, path ^ 3));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[4].data, root.data, (const char(*)[32])(branch + 1), depth, path));
+
+ // five, not found
+ ASSERT_FALSE(crypto::tree_branch((const char(*)[32])inputs, 5, crypto::null_hash.data, (char(*)[32])branch, &depth, &path));
+
+ // depth encoding roundtrip
+ for (uint32_t n_chains = 1; n_chains <= 65; ++n_chains)
+ {
+ for (uint32_t nonce = 0; nonce < 1024; ++nonce)
+ {
+ const uint32_t depth = cryptonote::encode_mm_depth(n_chains, nonce);
+ uint32_t n_chains_2, nonce_2;
+ ASSERT_TRUE(cryptonote::decode_mm_depth(depth, n_chains_2, nonce_2));
+ ASSERT_EQ(n_chains, n_chains_2);
+ ASSERT_EQ(nonce, nonce_2);
+ }
+ }
+}
diff --git a/tests/unit_tests/epee_boosted_tcp_server.cpp b/tests/unit_tests/epee_boosted_tcp_server.cpp
index 71098f612..06e076a3a 100644
--- a/tests/unit_tests/epee_boosted_tcp_server.cpp
+++ b/tests/unit_tests/epee_boosted_tcp_server.cpp
@@ -37,6 +37,7 @@
#include "include_base_utils.h"
#include "string_tools.h"
#include "net/abstract_tcp_server2.h"
+#include "net/levin_protocol_handler_async.h"
namespace
{
@@ -132,3 +133,223 @@ TEST(boosted_tcp_server, worker_threads_are_exception_resistant)
ASSERT_TRUE(srv.timed_wait_server_stop(5 * 1000));
ASSERT_TRUE(srv.deinit_server());
}
+
+
+TEST(test_epee_connection, test_lifetime)
+{
+ struct context_t: epee::net_utils::connection_context_base {
+ static constexpr size_t get_max_bytes(int) noexcept { return -1; }
+ static constexpr int handshake_command() noexcept { return 1001; }
+ static constexpr bool handshake_complete() noexcept { return true; }
+ };
+
+ using functional_obj_t = std::function<void ()>;
+ struct command_handler_t: epee::levin::levin_commands_handler<context_t> {
+ size_t delay;
+ functional_obj_t on_connection_close_f;
+ command_handler_t(size_t delay = 0,
+ functional_obj_t on_connection_close_f = nullptr
+ ):
+ delay(delay),
+ on_connection_close_f(on_connection_close_f)
+ {}
+ virtual int invoke(int, const epee::span<const uint8_t>, epee::byte_slice&, context_t&) override { epee::misc_utils::sleep_no_w(delay); return {}; }
+ virtual int notify(int, const epee::span<const uint8_t>, context_t&) override { return {}; }
+ virtual void callback(context_t&) override {}
+ virtual void on_connection_new(context_t&) override {}
+ virtual void on_connection_close(context_t&) override {
+ if (on_connection_close_f)
+ on_connection_close_f();
+ }
+ virtual ~command_handler_t() override {}
+ static void destroy(epee::levin::levin_commands_handler<context_t>* ptr) { delete ptr; }
+ };
+
+ using handler_t = epee::levin::async_protocol_handler<context_t>;
+ using connection_t = epee::net_utils::connection<handler_t>;
+ using connection_ptr = boost::shared_ptr<connection_t>;
+ using shared_state_t = typename connection_t::shared_state;
+ using shared_state_ptr = std::shared_ptr<shared_state_t>;
+ using tag_t = boost::uuids::uuid;
+ using tags_t = std::vector<tag_t>;
+ using io_context_t = boost::asio::io_service;
+ using endpoint_t = boost::asio::ip::tcp::endpoint;
+ using work_t = boost::asio::io_service::work;
+ using work_ptr = std::shared_ptr<work_t>;
+ using workers_t = std::vector<std::thread>;
+ using server_t = epee::net_utils::boosted_tcp_server<handler_t>;
+ using lock_t = std::mutex;
+ using lock_guard_t = std::lock_guard<lock_t>;
+ using connection_weak_ptr = boost::weak_ptr<connection_t>;
+ struct shared_conn_t {
+ lock_t lock;
+ connection_weak_ptr conn;
+ };
+ using shared_conn_ptr = std::shared_ptr<shared_conn_t>;
+
+ io_context_t io_context;
+ work_ptr work(std::make_shared<work_t>(io_context));
+
+ workers_t workers;
+ while (workers.size() < 4) {
+ workers.emplace_back([&io_context]{
+ io_context.run();
+ });
+ }
+
+ endpoint_t endpoint(boost::asio::ip::address::from_string("127.0.0.1"), 5262);
+ server_t server(epee::net_utils::e_connection_type_P2P);
+ server.init_server(endpoint.port(),
+ endpoint.address().to_string(),
+ 0,
+ "",
+ false,
+ true,
+ epee::net_utils::ssl_support_t::e_ssl_support_disabled
+ );
+ server.run_server(2, false);
+ server.get_config_shared()->set_handler(new command_handler_t, &command_handler_t::destroy);
+
+ io_context.post([&io_context, &work, &endpoint, &server]{
+ auto scope_exit_handler = epee::misc_utils::create_scope_leave_handler([&work]{
+ work.reset();
+ });
+
+ shared_state_ptr shared_state(std::make_shared<shared_state_t>());
+ shared_state->set_handler(new command_handler_t, &command_handler_t::destroy);
+
+ auto create_connection = [&io_context, &endpoint, &shared_state] {
+ connection_ptr conn(new connection_t(io_context, shared_state, {}, {}));
+ conn->socket().connect(endpoint);
+ conn->start({}, {});
+ context_t context;
+ conn->get_context(context);
+ auto tag = context.m_connection_id;
+ return tag;
+ };
+
+ ASSERT_TRUE(shared_state->get_connections_count() == 0);
+ auto tag = create_connection();
+ ASSERT_TRUE(shared_state->get_connections_count() == 1);
+ bool success = shared_state->for_connection(tag, [shared_state](context_t& context){
+ shared_state->close(context.m_connection_id);
+ context.m_remote_address.get_zone();
+ return true;
+ });
+ ASSERT_TRUE(success);
+
+ ASSERT_TRUE(shared_state->get_connections_count() == 0);
+ constexpr auto N = 8;
+ tags_t tags(N);
+ for(auto &t: tags)
+ t = create_connection();
+ ASSERT_TRUE(shared_state->get_connections_count() == N);
+ size_t index = 0;
+ success = shared_state->foreach_connection([&index, shared_state, &tags, &create_connection](context_t& context){
+ if (!index)
+ for (const auto &t: tags)
+ shared_state->close(t);
+
+ shared_state->close(context.m_connection_id);
+ context.m_remote_address.get_zone();
+ ++index;
+
+ for(auto i = 0; i < N; ++i)
+ create_connection();
+ return true;
+ });
+ ASSERT_TRUE(success);
+ ASSERT_TRUE(index == N);
+ ASSERT_TRUE(shared_state->get_connections_count() == N * N);
+
+ index = 0;
+ success = shared_state->foreach_connection([&index, shared_state](context_t& context){
+ shared_state->close(context.m_connection_id);
+ context.m_remote_address.get_zone();
+ ++index;
+ return true;
+ });
+ ASSERT_TRUE(success);
+ ASSERT_TRUE(index == N * N);
+ ASSERT_TRUE(shared_state->get_connections_count() == 0);
+
+ while (shared_state->sock_count);
+ ASSERT_TRUE(shared_state->get_connections_count() == 0);
+ constexpr auto DELAY = 30;
+ constexpr auto TIMEOUT = 1;
+ server.get_config_shared()->set_handler(new command_handler_t(DELAY), &command_handler_t::destroy);
+ for (auto i = 0; i < N; ++i) {
+ tag = create_connection();
+ ASSERT_TRUE(shared_state->get_connections_count() == 1);
+ success = shared_state->invoke_async(1, {}, tag, [](int, const epee::span<const uint8_t>, context_t&){}, TIMEOUT);
+ ASSERT_TRUE(success);
+ while (shared_state->sock_count == 1) {
+ success = shared_state->foreach_connection([&shared_state, &tag](context_t&){
+ return shared_state->request_callback(tag);
+ });
+ ASSERT_TRUE(success);
+ }
+ shared_state->close(tag);
+ ASSERT_TRUE(shared_state->get_connections_count() == 0);
+ }
+
+ while (shared_state->sock_count);
+ constexpr auto ZERO_DELAY = 0;
+ size_t counter = 0;
+ shared_state->set_handler(new command_handler_t(ZERO_DELAY,
+ [&counter]{
+ ASSERT_TRUE(counter++ == 0);
+ }
+ ),
+ &command_handler_t::destroy
+ );
+ connection_ptr conn(new connection_t(io_context, shared_state, {}, {}));
+ conn->socket().connect(endpoint);
+ conn->start({}, {});
+ ASSERT_TRUE(shared_state->get_connections_count() == 1);
+ shared_state->del_out_connections(1);
+ ASSERT_TRUE(shared_state->get_connections_count() == 0);
+ conn.reset();
+
+ while (shared_state->sock_count);
+ shared_conn_ptr shared_conn(std::make_shared<shared_conn_t>());
+ shared_state->set_handler(new command_handler_t(ZERO_DELAY,
+ [shared_state, shared_conn]{
+ {
+ connection_ptr conn;
+ {
+ lock_guard_t guard(shared_conn->lock);
+ conn = std::move(shared_conn->conn.lock());
+ }
+ if (conn)
+ conn->cancel();
+ }
+ const auto success = shared_state->foreach_connection([](context_t&){
+ return true;
+ });
+ ASSERT_TRUE(success);
+ }
+ ),
+ &command_handler_t::destroy
+ );
+ for (auto i = 0; i < N; ++i) {
+ {
+ connection_ptr conn(new connection_t(io_context, shared_state, {}, {}));
+ conn->socket().connect(endpoint);
+ conn->start({}, {});
+ lock_guard_t guard(shared_conn->lock);
+ shared_conn->conn = conn;
+ }
+ ASSERT_TRUE(shared_state->get_connections_count() == 1);
+ shared_state->del_out_connections(1);
+ ASSERT_TRUE(shared_state->get_connections_count() == 0);
+ }
+ });
+
+ for (auto& w: workers) {
+ w.join();
+ }
+ server.send_stop_signal();
+ server.timed_wait_server_stop(5 * 1000);
+ server.deinit_server();
+}
diff --git a/tests/unit_tests/epee_serialization.cpp b/tests/unit_tests/epee_serialization.cpp
index cade16f0d..95a2b6ecd 100644
--- a/tests/unit_tests/epee_serialization.cpp
+++ b/tests/unit_tests/epee_serialization.cpp
@@ -30,6 +30,7 @@
#include <gtest/gtest.h>
#include "storages/portable_storage.h"
+#include "span.h"
TEST(epee_binary, two_keys)
{
diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp
index 256f8c3c2..cbe3c61b1 100644
--- a/tests/unit_tests/epee_utils.cpp
+++ b/tests/unit_tests/epee_utils.cpp
@@ -1115,11 +1115,13 @@ TEST(ByteStream, ToByteSlice)
epee::byte_stream stream;
+ stream.reserve(128*1024);
stream.write(source);
EXPECT_EQ(sizeof(source), stream.size());
+ EXPECT_EQ(128*1024, stream.capacity());
EXPECT_TRUE(equal(source, byte_span{stream.data(), stream.size()}));
- const epee::byte_slice slice{std::move(stream)};
+ const epee::byte_slice slice{std::move(stream), true};
EXPECT_EQ(0u, stream.size());
EXPECT_EQ(0u, stream.available());
EXPECT_EQ(0u, stream.capacity());
diff --git a/tests/unit_tests/hardfork.cpp b/tests/unit_tests/hardfork.cpp
index 6d7e9a8aa..912651de4 100644
--- a/tests/unit_tests/hardfork.cpp
+++ b/tests/unit_tests/hardfork.cpp
@@ -432,7 +432,6 @@ TEST(voting, info)
// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
static const uint8_t block_versions[] = { 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4 };
- static const uint8_t expected_versions[] = { 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4 };
static const uint8_t expected_thresholds[] = { 0, 1, 1, 2, 2, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 2, 2, 2, 2 };
for (uint64_t h = 0; h < sizeof(block_versions) / sizeof(block_versions[0]); ++h) {
diff --git a/tests/unit_tests/net.cpp b/tests/unit_tests/net.cpp
index dffda5e4e..2836fd948 100644
--- a/tests/unit_tests/net.cpp
+++ b/tests/unit_tests/net.cpp
@@ -1351,7 +1351,7 @@ TEST(dandelionpp_map, dropped_connection)
}
EXPECT_EQ(3u, used.size());
- for (const std::pair<boost::uuids::uuid, std::size_t>& entry : used)
+ for (const std::pair<const boost::uuids::uuid, std::size_t>& entry : used)
EXPECT_EQ(3u, entry.second);
for (const boost::uuids::uuid& connection : in_connections)
@@ -1409,7 +1409,7 @@ TEST(dandelionpp_map, dropped_connection)
}
EXPECT_EQ(3u, used.size());
- for (const std::pair<boost::uuids::uuid, std::size_t>& entry : used)
+ for (const std::pair<const boost::uuids::uuid, std::size_t>& entry : used)
EXPECT_EQ(3u, entry.second);
}
{
@@ -1472,7 +1472,7 @@ TEST(dandelionpp_map, dropped_connection_remapped)
}
EXPECT_EQ(3u, used.size());
- for (const std::pair<boost::uuids::uuid, std::size_t>& entry : used)
+ for (const std::pair<const boost::uuids::uuid, std::size_t>& entry : used)
EXPECT_EQ(3u, entry.second);
for (const boost::uuids::uuid& connection : in_connections)
@@ -1511,7 +1511,7 @@ TEST(dandelionpp_map, dropped_connection_remapped)
}
EXPECT_EQ(2u, used.size());
- for (const std::pair<boost::uuids::uuid, std::size_t>& entry : used)
+ for (const std::pair<const boost::uuids::uuid, std::size_t>& entry : used)
EXPECT_EQ(5u, entry.second);
}
// select 3 of 3 connections but do not remap existing links
@@ -1532,7 +1532,7 @@ TEST(dandelionpp_map, dropped_connection_remapped)
}
EXPECT_EQ(2u, used.size());
- for (const std::pair<boost::uuids::uuid, std::size_t>& entry : used)
+ for (const std::pair<const boost::uuids::uuid, std::size_t>& entry : used)
EXPECT_EQ(5u, entry.second);
}
// map 8 new incoming connections across 3 outgoing links
@@ -1555,7 +1555,7 @@ TEST(dandelionpp_map, dropped_connection_remapped)
}
EXPECT_EQ(3u, used.size());
- for (const std::pair<boost::uuids::uuid, std::size_t>& entry : used)
+ for (const std::pair<const boost::uuids::uuid, std::size_t>& entry : used)
EXPECT_EQ(6u, entry.second);
}
}
@@ -1609,7 +1609,7 @@ TEST(dandelionpp_map, dropped_all_connections)
}
EXPECT_EQ(3u, used.size());
- for (const std::pair<boost::uuids::uuid, std::size_t>& entry : used)
+ for (const std::pair<const boost::uuids::uuid, std::size_t>& entry : used)
EXPECT_EQ(3u, entry.second);
for (const boost::uuids::uuid& connection : in_connections)
@@ -1641,7 +1641,7 @@ TEST(dandelionpp_map, dropped_all_connections)
}
EXPECT_EQ(3u, used.size());
- for (const std::pair<boost::uuids::uuid, std::size_t>& entry : used)
+ for (const std::pair<const boost::uuids::uuid, std::size_t>& entry : used)
EXPECT_EQ(3u, entry.second);
}
}
diff --git a/tests/unit_tests/node_server.cpp b/tests/unit_tests/node_server.cpp
index 4d6f09e69..af297d01a 100644
--- a/tests/unit_tests/node_server.cpp
+++ b/tests/unit_tests/node_server.cpp
@@ -250,7 +250,6 @@ TEST(ban, subnet)
TEST(ban, ignores_port)
{
- time_t seconds;
test_core pr_core;
cryptonote::t_cryptonote_protocol_handler<test_core> cprotocol(pr_core, NULL);
Server server(cprotocol);
diff --git a/tests/unit_tests/output_selection.cpp b/tests/unit_tests/output_selection.cpp
index cff509451..20dc58e03 100644
--- a/tests/unit_tests/output_selection.cpp
+++ b/tests/unit_tests/output_selection.cpp
@@ -206,7 +206,7 @@ TEST(select_outputs, same_distribution)
for (size_t i = 0; i < chain_picks.size(); ++i)
chain_norm[i * 100 / chain_picks.size()] += chain_picks[i];
- double max_dev = 0.0, avg_dev = 0.0;
+ double avg_dev = 0.0;
for (size_t i = 0; i < 100; ++i)
{
const double diff = (double)output_norm[i] - (double)chain_norm[i];
diff --git a/tests/unit_tests/wipeable_string.cpp b/tests/unit_tests/wipeable_string.cpp
index 9911bd6f4..0e0bf8906 100644
--- a/tests/unit_tests/wipeable_string.cpp
+++ b/tests/unit_tests/wipeable_string.cpp
@@ -189,20 +189,20 @@ TEST(wipeable_string, parse_hexstr)
{
boost::optional<epee::wipeable_string> s;
- ASSERT_EQ(boost::none, epee::wipeable_string("x").parse_hexstr());
- ASSERT_EQ(boost::none, epee::wipeable_string("x0000000000000000").parse_hexstr());
- ASSERT_EQ(boost::none, epee::wipeable_string("0000000000000000x").parse_hexstr());
- ASSERT_EQ(boost::none, epee::wipeable_string("0").parse_hexstr());
- ASSERT_EQ(boost::none, epee::wipeable_string("000").parse_hexstr());
+ ASSERT_TRUE(boost::none == epee::wipeable_string("x").parse_hexstr());
+ ASSERT_TRUE(boost::none == epee::wipeable_string("x0000000000000000").parse_hexstr());
+ ASSERT_TRUE(boost::none == epee::wipeable_string("0000000000000000x").parse_hexstr());
+ ASSERT_TRUE(boost::none == epee::wipeable_string("0").parse_hexstr());
+ ASSERT_TRUE(boost::none == epee::wipeable_string("000").parse_hexstr());
ASSERT_TRUE((s = epee::wipeable_string("").parse_hexstr()) != boost::none);
- ASSERT_EQ(*s, "");
+ ASSERT_TRUE(*s == "");
ASSERT_TRUE((s = epee::wipeable_string("00").parse_hexstr()) != boost::none);
- ASSERT_EQ(*s, epee::wipeable_string("", 1));
+ ASSERT_TRUE(*s == epee::wipeable_string("", 1));
ASSERT_TRUE((s = epee::wipeable_string("41").parse_hexstr()) != boost::none);
- ASSERT_EQ(*s, epee::wipeable_string("A"));
+ ASSERT_TRUE(*s == epee::wipeable_string("A"));
ASSERT_TRUE((s = epee::wipeable_string("414243").parse_hexstr()) != boost::none);
- ASSERT_EQ(*s, epee::wipeable_string("ABC"));
+ ASSERT_TRUE(*s == epee::wipeable_string("ABC"));
}
TEST(wipeable_string, to_hex)
diff --git a/tests/unit_tests/zmq_rpc.cpp b/tests/unit_tests/zmq_rpc.cpp
index 59759bed8..66a7f3ac1 100644
--- a/tests/unit_tests/zmq_rpc.cpp
+++ b/tests/unit_tests/zmq_rpc.cpp
@@ -202,7 +202,6 @@ namespace
MASSERT(!expected.empty());
std::size_t actual_height = 0;
- crypto::hash actual_id{};
crypto::hash actual_prev_id{};
std::vector<crypto::hash> actual_ids{};
GET_FROM_JSON_OBJECT(pub.second, actual_height, first_height);
diff --git a/utils/python-rpc/console.py b/utils/python-rpc/console.py
index 57a04528b..c94e07eab 100755
--- a/utils/python-rpc/console.py
+++ b/utils/python-rpc/console.py
@@ -29,7 +29,7 @@ for n in range(1, len(sys.argv)):
raise Exception(USAGE)
if port <= 0 or port > 65535:
raise Exception(USAGE)
- except Exception, e:
+ except Exception as e:
print('Error: ' + str(e))
raise Exception(USAGE)
@@ -49,7 +49,7 @@ for n in range(1, len(sys.argv)):
}
try:
res = rpc.send_json_rpc_request(get_version)
- except Exception, e:
+ except Exception as e:
raise Exception('Failed to call version RPC: ' + str(e))
if 'version' not in res:
diff --git a/utils/python-rpc/framework/daemon.py b/utils/python-rpc/framework/daemon.py
index 435bc93f8..207565e6f 100644
--- a/utils/python-rpc/framework/daemon.py
+++ b/utils/python-rpc/framework/daemon.py
@@ -53,6 +53,19 @@ class Daemon(object):
return self.rpc.send_json_rpc_request(getblocktemplate)
get_block_template = getblocktemplate
+ def add_aux_pow(self, blocktemplate_blob, aux_pow, client = ""):
+ add_aux_pow = {
+ 'method': 'add_aux_pow',
+ 'params': {
+ 'blocktemplate_blob': blocktemplate_blob,
+ 'aux_pow' : aux_pow,
+ 'client' : client,
+ },
+ 'jsonrpc': '2.0',
+ 'id': '0'
+ }
+ return self.rpc.send_json_rpc_request(add_aux_pow)
+
def send_raw_transaction(self, tx_as_hex, do_not_relay = False, do_sanity_checks = True, client = ""):
send_raw_transaction = {
'client': client,