aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt82
-rw-r--r--README.md14
-rw-r--r--cmake/CheckLinkerFlag.cmake2
-rw-r--r--contrib/depends/packages/hidapi-darwin.mk2
-rw-r--r--contrib/depends/packages/packages.mk2
-rw-r--r--contrib/depends/packages/sodium-darwin.mk3
-rw-r--r--contrib/epee/include/console_handler.h3
-rw-r--r--contrib/epee/include/net/levin_protocol_handler_async.h6
-rw-r--r--contrib/epee/include/net/net_helper.h3
-rw-r--r--contrib/epee/src/CMakeLists.txt2
-rw-r--r--contrib/epee/src/mlog.cpp7
-rw-r--r--external/easylogging++/easylogging++.cc4
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp35
-rw-r--r--src/blockchain_utilities/blockchain_blackball.cpp8
-rw-r--r--src/common/CMakeLists.txt4
-rw-r--r--src/common/exec.cpp88
-rw-r--r--src/common/exec.h36
-rw-r--r--src/common/notify.cpp61
-rw-r--r--src/common/notify.h49
-rw-r--r--src/common/threadpool.cpp3
-rw-r--r--src/crypto/slow-hash.c43
-rw-r--r--src/cryptonote_basic/miner.cpp6
-rw-r--r--src/cryptonote_core/blockchain.cpp5
-rw-r--r--src/cryptonote_core/blockchain.h11
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp17
-rw-r--r--src/gen_multisig/gen_multisig.cpp4
-rw-r--r--src/simplewallet/simplewallet.cpp7
-rw-r--r--src/wallet/api/pending_transaction.cpp6
-rw-r--r--src/wallet/api/wallet.cpp30
-rw-r--r--src/wallet/api/wallet.h12
-rw-r--r--src/wallet/ringdb.cpp15
-rw-r--r--src/wallet/wallet2.cpp71
-rw-r--r--src/wallet/wallet2.h7
-rw-r--r--src/wallet/wallet_rpc_server.cpp5
-rw-r--r--src/wallet/wallet_rpc_server_commands_defs.h2
-rw-r--r--tests/fuzz/fuzzer.cpp4
-rw-r--r--tests/performance_tests/main.cpp8
-rw-r--r--tests/unit_tests/is_hdd.cpp4
-rw-r--r--tests/unit_tests/main.cpp4
-rw-r--r--tests/unit_tests/mlocker.cpp69
-rw-r--r--tests/unit_tests/ringdb.cpp24
-rw-r--r--tests/unit_tests/wipeable_string.cpp8
42 files changed, 624 insertions, 152 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 994d47691..c31c14350 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -529,6 +529,40 @@ else()
endif()
endif()
endif()
+
+ option(NO_AES "Explicitly disable AES support" ${NO_AES})
+
+ if(NO_AES)
+ message(STATUS "AES support explicitly disabled")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNO_AES")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNO_AES")
+ elseif(NOT ARM AND NOT PPC64LE AND NOT PPC64 AND NOT PPC AND NOT S390X)
+ message(STATUS "AES support enabled")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maes")
+ elseif(PPC64LE OR PPC64 OR PPC)
+ message(STATUS "AES support not available on POWER")
+ elseif(S390X)
+ message(STATUS "AES support not available on s390x")
+ elseif(ARM6)
+ message(STATUS "AES support not available on ARMv6")
+ elseif(ARM7)
+ message(STATUS "AES support not available on ARMv7")
+ elseif(ARM8)
+ CHECK_CXX_ACCEPTS_FLAG("-march=${ARCH}+crypto" ARCH_PLUS_CRYPTO)
+ if(ARCH_PLUS_CRYPTO)
+ message(STATUS "Crypto extensions enabled for ARMv8")
+ set(ARCH_FLAG "-march=${ARCH}+crypto")
+ else()
+ message(STATUS "Crypto extensions unavailable on your ARMv8 device")
+ endif()
+ else()
+ message(STATUS "AES support disabled")
+ endif()
+
+ 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")
if(NOT MINGW)
set(WARNINGS_AS_ERRORS_FLAG "-Werror")
@@ -639,38 +673,8 @@ else()
message(STATUS "Using C++ security hardening flags: ${CXX_SECURITY_FLAGS}")
message(STATUS "Using linker security hardening flags: ${LD_SECURITY_FLAGS}")
- option(NO_AES "Explicitly disable AES support" ${NO_AES})
-
- if(NO_AES)
- message(STATUS "AES support explicitly disabled")
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DNO_AES")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNO_AES")
- elseif(NOT ARM AND NOT PPC64LE AND NOT PPC64 AND NOT PPC AND NOT S390X)
- message(STATUS "AES support enabled")
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maes")
- elseif(PPC64LE OR PPC64 OR PPC)
- message(STATUS "AES support not available on POWER")
- elseif(S390X)
- message(STATUS "AES support not available on s390x")
- elseif(ARM6)
- message(STATUS "AES support not available on ARMv6")
- elseif(ARM7)
- message(STATUS "AES support not available on ARMv7")
- elseif(ARM8)
- CHECK_CXX_ACCEPTS_FLAG("-march=${ARCH}+crypto" ARCH_PLUS_CRYPTO)
- if(ARCH_PLUS_CRYPTO)
- message(STATUS "Crypto extensions enabled for ARMv8")
- set(ARCH_FLAG "-march=${ARCH}+crypto")
- else()
- message(STATUS "Crypto extensions unavailable on your ARMv8 device")
- endif()
- else()
- message(STATUS "AES support disabled")
- endif()
-
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_FLAG} ${WARNINGS} ${C_WARNINGS} ${ARCH_FLAG} ${COVERAGE_FLAGS} ${PIC_FLAG} ${C_SECURITY_FLAGS}")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_CPP_FLAG} ${WARNINGS} ${CXX_WARNINGS} ${ARCH_FLAG} ${COVERAGE_FLAGS} ${PIC_FLAG} ${CXX_SECURITY_FLAGS}")
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_FLAG} ${WARNINGS} ${C_WARNINGS} ${COVERAGE_FLAGS} ${PIC_FLAG} ${C_SECURITY_FLAGS}")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_CPP_FLAG} ${WARNINGS} ${CXX_WARNINGS} ${COVERAGE_FLAGS} ${PIC_FLAG} ${CXX_SECURITY_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LD_SECURITY_FLAGS}")
# With GCC 6.1.1 the compiled binary malfunctions due to aliasing. Until that
@@ -769,7 +773,7 @@ else()
endif()
if(APPLE)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -DGTEST_HAS_TR1_TUPLE=0")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default -DGTEST_HAS_TR1_TUPLE=0")
endif()
set(DEBUG_FLAGS "-g3")
@@ -883,10 +887,14 @@ list(APPEND EXTRA_LIBRARIES ${CMAKE_DL_LIBS})
if (HIDAPI_FOUND)
if (APPLE)
- find_library(COREFOUNDATION CoreFoundation)
- find_library(IOKIT IOKit)
- list(APPEND EXTRA_LIBRARIES ${IOKIT})
- list(APPEND EXTRA_LIBRARIES ${COREFOUNDATION})
+ if(DEPENDS)
+ list(APPEND EXTRA_LIBRARIES "-framework Foundation -framework IOKit")
+ else()
+ find_library(COREFOUNDATION CoreFoundation)
+ find_library(IOKIT IOKit)
+ list(APPEND EXTRA_LIBRARIES ${IOKIT})
+ list(APPEND EXTRA_LIBRARIES ${COREFOUNDATION})
+ endif()
endif()
if (WIN32)
list(APPEND EXTRA_LIBRARIES setupapi)
diff --git a/README.md b/README.md
index ac40f08d3..d16b21528 100644
--- a/README.md
+++ b/README.md
@@ -666,9 +666,19 @@ Type `run` to run monerod
### Analysing memory corruption
-We use the tool `valgrind` for this.
+There are two tools available:
-Run with `valgrind /path/to/monerod`. It will be slow.
+* ASAN
+
+Configure Monero with the -D SANITIZE=ON cmake flag, eg:
+
+ cd build/debug && cmake -D SANITIZE=ON -D CMAKE_BUILD_TYPE=Debug ../..
+
+You can then run the monero tools normally. Performance will typically halve.
+
+* valgrind
+
+Install valgrind and run as `valgrind /path/to/monerod`. It will be very slow.
### LMDB
diff --git a/cmake/CheckLinkerFlag.cmake b/cmake/CheckLinkerFlag.cmake
index a3879d0be..2b507ab71 100644
--- a/cmake/CheckLinkerFlag.cmake
+++ b/cmake/CheckLinkerFlag.cmake
@@ -39,7 +39,7 @@ macro(CHECK_LINKER_FLAG flag VARIABLE)
endif()
set(${VARIABLE} "" CACHE INTERNAL "Have linker flag ${flag}")
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
- "Determining if the ${flag} linker flag is suppored "
+ "Determining if the ${flag} linker flag is supported "
"failed with the following output:\n"
"${OUTPUT}\n\n")
endif()
diff --git a/contrib/depends/packages/hidapi-darwin.mk b/contrib/depends/packages/hidapi-darwin.mk
index 1fbbb59e0..014aba578 100644
--- a/contrib/depends/packages/hidapi-darwin.mk
+++ b/contrib/depends/packages/hidapi-darwin.mk
@@ -11,7 +11,7 @@ endef
define $(package)_config_cmds
./bootstrap &&\
- $($(package)_autoconf) $($(package)_config_opts) RANLIB="$(host_prefix)/native/bin/x86_64-apple-darwin11-ranlib" AR="$(host_prefix)/native/bin/x86_64-apple-darwin11-ar"
+ $($(package)_autoconf) $($(package)_config_opts) RANLIB="$(host_prefix)/native/bin/x86_64-apple-darwin11-ranlib" AR="$(host_prefix)/native/bin/x86_64-apple-darwin11-ar" CC="$(host_prefix)/native/bin/$($(package)_cc)"
endef
define $(package)_build_cmds
diff --git a/contrib/depends/packages/packages.mk b/contrib/depends/packages/packages.mk
index 13ba37628..9bfbff7d9 100644
--- a/contrib/depends/packages/packages.mk
+++ b/contrib/depends/packages/packages.mk
@@ -4,7 +4,7 @@ native_packages := native_ccache
wallet_packages=bdb
darwin_native_packages = native_biplist native_ds_store native_mac_alias
-darwin_packages += sodium-darwin hidapi-darwin
+darwin_packages = sodium-darwin hidapi-darwin
linux_packages = eudev libusb hidapi-linux
diff --git a/contrib/depends/packages/sodium-darwin.mk b/contrib/depends/packages/sodium-darwin.mk
index 796bead16..59c6d1ec6 100644
--- a/contrib/depends/packages/sodium-darwin.mk
+++ b/contrib/depends/packages/sodium-darwin.mk
@@ -5,13 +5,14 @@ $(package)_file_name=libsodium-$($(package)_version).tar.gz
$(package)_sha256_hash=fb6a9e879a2f674592e4328c5d9f79f082405ee4bb05cb6e679b90afe9e178f4
define $(package)_set_vars
+$(package)_build_opts_darwin=OS=Darwin LIBTOOL="$($(package)_libtool)"
$(package)_config_opts=--enable-static
$(package)_config_opts+=--prefix=$(host_prefix)
endef
define $(package)_config_cmds
./autogen.sh &&\
- $($(package)_autoconf) $($(package)_config_opts) RANLIB="$(host_prefix)/native/bin/x86_64-apple-darwin11-ranlib" AR="$(host_prefix)/native/bin/x86_64-apple-darwin11-ar"
+ $($(package)_autoconf) $($(package)_config_opts) RANLIB="$(host_prefix)/native/bin/x86_64-apple-darwin11-ranlib" AR="$(host_prefix)/native/bin/x86_64-apple-darwin11-ar" CC="$(host_prefix)/native/bin/$($(package)_cc)"
endef
define $(package)_build_cmds
diff --git a/contrib/epee/include/console_handler.h b/contrib/epee/include/console_handler.h
index 0e22a971c..2ccf5b095 100644
--- a/contrib/epee/include/console_handler.h
+++ b/contrib/epee/include/console_handler.h
@@ -63,7 +63,8 @@ namespace epee
~async_stdin_reader()
{
- stop();
+ try { stop(); }
+ catch (...) { /* ignore */ }
}
#ifdef HAVE_READLINE
diff --git a/contrib/epee/include/net/levin_protocol_handler_async.h b/contrib/epee/include/net/levin_protocol_handler_async.h
index 0b1fe05fa..e9853ee26 100644
--- a/contrib/epee/include/net/levin_protocol_handler_async.h
+++ b/contrib/epee/include/net/levin_protocol_handler_async.h
@@ -275,6 +275,9 @@ public:
}
virtual ~async_protocol_handler()
{
+ try
+ {
+
m_deletion_initiated = true;
if(m_connection_initialized)
{
@@ -288,6 +291,9 @@ public:
CHECK_AND_ASSERT_MES_NO_RET(0 == boost::interprocess::ipcdetail::atomic_read32(&m_wait_count), "Failed to wait for operation completion. m_wait_count = " << m_wait_count);
MTRACE(m_connection_context << "~async_protocol_handler()");
+
+ }
+ catch (...) { /* ignore */ }
}
bool start_outer_call()
diff --git a/contrib/epee/include/net/net_helper.h b/contrib/epee/include/net/net_helper.h
index 2c2efcd82..94744ac21 100644
--- a/contrib/epee/include/net/net_helper.h
+++ b/contrib/epee/include/net/net_helper.h
@@ -106,7 +106,8 @@ namespace net_utils
~blocked_mode_client()
{
//profile_tools::local_coast lc("~blocked_mode_client()", 3);
- shutdown();
+ try { shutdown(); }
+ catch(...) { /* ignore */ }
}
inline
diff --git a/contrib/epee/src/CMakeLists.txt b/contrib/epee/src/CMakeLists.txt
index 0b5e7ae6c..bc437deb9 100644
--- a/contrib/epee/src/CMakeLists.txt
+++ b/contrib/epee/src/CMakeLists.txt
@@ -54,7 +54,9 @@ endif()
target_link_libraries(epee
PUBLIC
easylogging
+ ${Boost_CHRONO_LIBRARY}
${Boost_FILESYSTEM_LIBRARY}
+ ${Boost_THREAD_LIBRARY}
PRIVATE
${OPENSSL_LIBRARIES}
${EXTRA_LIBRARIES})
diff --git a/contrib/epee/src/mlog.cpp b/contrib/epee/src/mlog.cpp
index cd9867ff5..61d853ef4 100644
--- a/contrib/epee/src/mlog.cpp
+++ b/contrib/epee/src/mlog.cpp
@@ -137,7 +137,12 @@ void mlog_configure(const std::string &filename_base, bool console, const std::s
el::Loggers::addFlag(el::LoggingFlag::StrictLogFileSizeCheck);
el::Helpers::installPreRollOutCallback([filename_base, max_log_files](const char *name, size_t){
std::string rname = generate_log_filename(filename_base.c_str());
- rename(name, rname.c_str());
+ int ret = rename(name, rname.c_str());
+ if (ret < 0)
+ {
+ // can't log a failure, but don't do the file removal below
+ return;
+ }
if (max_log_files != 0)
{
std::vector<boost::filesystem::path> found_files;
diff --git a/external/easylogging++/easylogging++.cc b/external/easylogging++/easylogging++.cc
index b438fa543..a4bdad4cf 100644
--- a/external/easylogging++/easylogging++.cc
+++ b/external/easylogging++/easylogging++.cc
@@ -1975,11 +1975,11 @@ void VRegistry::setCategories(const char* categories, bool clear) {
m_cached_allowed_categories.clear();
m_categoriesString.clear();
}
+ if (!categories)
+ return;
if (!m_categoriesString.empty())
m_categoriesString += ",";
m_categoriesString += categories;
- if (!categories)
- return;
bool isCat = true;
bool isLevel = false;
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index b0f3ca5f0..824598f8c 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -1145,7 +1145,10 @@ BlockchainLMDB::~BlockchainLMDB()
// batch transaction shouldn't be active at this point. If it is, consider it aborted.
if (m_batch_active)
- batch_abort();
+ {
+ try { batch_abort(); }
+ catch (...) { /* ignore */ }
+ }
if (m_open)
close();
}
@@ -3490,7 +3493,17 @@ void BlockchainLMDB::fixup()
BlockchainDB::fixup();
}
-#define RENAME_DB(name) \
+#define RENAME_DB(name) do { \
+ char n2[] = name; \
+ MDB_dbi tdbi; \
+ n2[sizeof(n2)-2]--; \
+ /* play some games to put (name) on a writable page */ \
+ result = mdb_dbi_open(txn, n2, MDB_CREATE, &tdbi); \
+ if (result) \
+ throw0(DB_ERROR(lmdb_error("Failed to create " + std::string(n2) + ": ", result).c_str())); \
+ result = mdb_drop(txn, tdbi, 1); \
+ if (result) \
+ throw0(DB_ERROR(lmdb_error("Failed to delete " + std::string(n2) + ": ", result).c_str())); \
k.mv_data = (void *)name; \
k.mv_size = sizeof(name)-1; \
result = mdb_cursor_open(txn, 1, &c_cur); \
@@ -3500,7 +3513,7 @@ void BlockchainLMDB::fixup()
if (result) \
throw0(DB_ERROR(lmdb_error("Failed to get DB record for " name ": ", result).c_str())); \
ptr = (char *)k.mv_data; \
- ptr[sizeof(name)-2]++
+ ptr[sizeof(name)-2]++; } while(0)
#define LOGIF(y) if (ELPP->vRegistry()->allowed(y, "global"))
@@ -3579,7 +3592,9 @@ void BlockchainLMDB::migrate_0_1()
throw0(DB_ERROR(lmdb_error("Failed to open a cursor for block_heights: ", result).c_str()));
if (!i) {
MDB_stat ms;
- mdb_stat(txn, m_block_heights, &ms);
+ result = mdb_stat(txn, m_block_heights, &ms);
+ if (result)
+ throw0(DB_ERROR(lmdb_error("Failed to query block_heights table: ", result).c_str()));
i = ms.ms_entries;
}
}
@@ -3682,7 +3697,9 @@ void BlockchainLMDB::migrate_0_1()
throw0(DB_ERROR(lmdb_error("Failed to open a cursor for block_timestamps: ", result).c_str()));
if (!i) {
MDB_stat ms;
- mdb_stat(txn, m_block_info, &ms);
+ result = mdb_stat(txn, m_block_info, &ms);
+ if (result)
+ throw0(DB_ERROR(lmdb_error("Failed to query block_info table: ", result).c_str()));
i = ms.ms_entries;
}
}
@@ -3802,7 +3819,9 @@ void BlockchainLMDB::migrate_0_1()
throw0(DB_ERROR(lmdb_error("Failed to open a cursor for spent_keys: ", result).c_str()));
if (!i) {
MDB_stat ms;
- mdb_stat(txn, m_hf_versions, &ms);
+ result = mdb_stat(txn, m_hf_versions, &ms);
+ if (result)
+ throw0(DB_ERROR(lmdb_error("Failed to query hf_versions table: ", result).c_str()));
i = ms.ms_entries;
}
}
@@ -3957,7 +3976,9 @@ void BlockchainLMDB::migrate_0_1()
throw0(DB_ERROR(lmdb_error("Failed to open a cursor for txs: ", result).c_str()));
if (!i) {
MDB_stat ms;
- mdb_stat(txn, m_txs, &ms);
+ result = mdb_stat(txn, m_txs, &ms);
+ if (result)
+ throw0(DB_ERROR(lmdb_error("Failed to query txs table: ", result).c_str()));
i = ms.ms_entries;
if (i) {
MDB_val_set(pk, "txblk");
diff --git a/src/blockchain_utilities/blockchain_blackball.cpp b/src/blockchain_utilities/blockchain_blackball.cpp
index 1c6e54d10..5eb2acc79 100644
--- a/src/blockchain_utilities/blockchain_blackball.cpp
+++ b/src/blockchain_utilities/blockchain_blackball.cpp
@@ -401,7 +401,8 @@ static bool for_all_transactions(const std::string &filename, uint64_t &start_id
}
mdb_cursor_close(cur);
- mdb_txn_commit(txn);
+ dbr = mdb_txn_commit(txn);
+ if (dbr) throw std::runtime_error("Failed to commit db transaction: " + std::string(mdb_strerror(dbr)));
tx_active = false;
mdb_dbi_close(env, dbi);
mdb_env_close(env);
@@ -471,7 +472,8 @@ static uint64_t find_first_diverging_transaction(const std::string &first_filena
for (int i = 0; i < 2; ++i)
{
mdb_cursor_close(cur[i]);
- mdb_txn_commit(txn[i]);
+ dbr = mdb_txn_commit(txn[i]);
+ if (dbr) throw std::runtime_error("Failed to query transaction: " + std::string(mdb_strerror(dbr)));
tx_active[i] = false;
mdb_dbi_close(env[i], dbi[i]);
mdb_env_close(env[i]);
@@ -675,7 +677,7 @@ static uint64_t get_ring_subset_instances(MDB_txn *txn, uint64_t amount, const s
uint64_t extra = 0;
std::vector<uint64_t> subset;
subset.reserve(ring.size());
- for (uint64_t mask = 1; mask < (1u << ring.size()) - 1; ++mask)
+ for (uint64_t mask = 1; mask < (((uint64_t)1) << ring.size()) - 1; ++mask)
{
subset.resize(0);
for (size_t i = 0; i < ring.size(); ++i)
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index e89dbbc24..9b83f149f 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -34,9 +34,11 @@ set(common_sources
dns_utils.cpp
download.cpp
error.cpp
+ exec.cpp
expect.cpp
util.cpp
i18n.cpp
+ notify.cpp
password.cpp
perf_timer.cpp
threadpool.cpp
@@ -58,9 +60,11 @@ set(common_private_headers
dns_utils.h
download.h
error.h
+ exec.h
expect.h
http_connection.h
int-util.h
+ notify.h
pod-class.h
rpc_client.h
scoped_message_writer.h
diff --git a/src/common/exec.cpp b/src/common/exec.cpp
new file mode 100644
index 000000000..41b8f1378
--- /dev/null
+++ b/src/common/exec.cpp
@@ -0,0 +1,88 @@
+// Copyright (c) 2018, 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 <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include "misc_log_ex.h"
+#include "exec.h"
+
+namespace tools
+{
+
+int exec(const char *filename, char * const argv[], bool wait)
+{
+ pid_t pid = fork();
+ if (pid < 0)
+ {
+ MERROR("Error forking: " << strerror(errno));
+ return -1;
+ }
+
+ // child
+ if (pid == 0)
+ {
+ char *envp[] = {NULL};
+ execve(filename, argv, envp);
+ MERROR("Failed to execve: " << strerror(errno));
+ return -1;
+ }
+
+ // parent
+ if (pid > 0)
+ {
+ if (!wait)
+ return 0;
+
+ while (1)
+ {
+ int wstatus = 0;
+ pid_t w = waitpid(pid, &wstatus, WUNTRACED | WCONTINUED);
+ if (w < 0) {
+ MERROR("Error waiting for child: " << strerror(errno));
+ return -1;
+ }
+ if (WIFEXITED(wstatus))
+ {
+ MINFO("Child exited with " << WEXITSTATUS(wstatus));
+ return WEXITSTATUS(wstatus);
+ }
+ if (WIFSIGNALED(wstatus))
+ {
+ MINFO("Child killed by " << WEXITSTATUS(wstatus));
+ return WEXITSTATUS(wstatus);
+ }
+ }
+ }
+ MERROR("Secret passage found");
+ return -1;
+}
+
+}
diff --git a/src/common/exec.h b/src/common/exec.h
new file mode 100644
index 000000000..4d2037798
--- /dev/null
+++ b/src/common/exec.h
@@ -0,0 +1,36 @@
+// Copyright (c) 2018, 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
+
+namespace tools
+{
+
+int exec(const char *filename, char * const argv[], bool wait);
+
+}
diff --git a/src/common/notify.cpp b/src/common/notify.cpp
new file mode 100644
index 000000000..b7869ad84
--- /dev/null
+++ b/src/common/notify.cpp
@@ -0,0 +1,61 @@
+// Copyright (c) 2018, 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 <boost/algorithm/string.hpp>
+#include "misc_log_ex.h"
+#include "file_io_utils.h"
+#include "exec.h"
+#include "notify.h"
+
+namespace tools
+{
+
+Notify::Notify(const char *spec)
+{
+ CHECK_AND_ASSERT_THROW_MES(spec, "Null spec");
+
+ boost::split(args, spec, boost::is_any_of(" "));
+ CHECK_AND_ASSERT_THROW_MES(args.size() > 0, "Failed to parse spec");
+ filename = args[0];
+ CHECK_AND_ASSERT_THROW_MES(epee::file_io_utils::is_file_exist(filename), "File not found: " << filename);
+}
+
+int Notify::notify(const char *parameter)
+{
+ std::vector<std::string> margs = args;
+ for (std::string &s: margs)
+ boost::replace_all(s, "%s", parameter);
+
+ char **cargs = (char**)alloca(sizeof(char*) * (margs.size() + 1));
+ for (size_t n = 0; n < margs.size(); ++n)
+ cargs[n] = (char*)margs[n].c_str();
+ cargs[margs.size()] = NULL;
+ return tools::exec(filename.c_str(), cargs, false);
+}
+
+}
diff --git a/src/common/notify.h b/src/common/notify.h
new file mode 100644
index 000000000..81aacebb0
--- /dev/null
+++ b/src/common/notify.h
@@ -0,0 +1,49 @@
+// Copyright (c) 2018, 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 <string>
+#include <vector>
+
+namespace tools
+{
+
+class Notify
+{
+public:
+ Notify(const char *spec);
+
+ int notify(const char *parameter);
+
+private:
+ std::string filename;
+ std::vector<std::string> args;
+};
+
+}
diff --git a/src/common/threadpool.cpp b/src/common/threadpool.cpp
index 6b69e2a12..5ea04a353 100644
--- a/src/common/threadpool.cpp
+++ b/src/common/threadpool.cpp
@@ -57,7 +57,8 @@ threadpool::~threadpool() {
has_work.notify_all();
}
for (size_t i = 0; i<threads.size(); i++) {
- threads[i].join();
+ try { threads[i].join(); }
+ catch (...) { /* ignore */ }
}
}
diff --git a/src/crypto/slow-hash.c b/src/crypto/slow-hash.c
index 80bf4e06f..40cfb0461 100644
--- a/src/crypto/slow-hash.c
+++ b/src/crypto/slow-hash.c
@@ -1040,10 +1040,37 @@ STATIC INLINE void aes_pseudo_round_xor(const uint8_t *in, uint8_t *out, const u
}
}
+#ifdef FORCE_USE_HEAP
+STATIC INLINE void* aligned_malloc(size_t size, size_t align)
+{
+ void *result;
+#ifdef _MSC_VER
+ result = _aligned_malloc(size, align);
+#else
+ if (posix_memalign(&result, align, size)) result = NULL;
+#endif
+ return result;
+}
+
+STATIC INLINE void aligned_free(void *ptr)
+{
+#ifdef _MSC_VER
+ _aligned_free(ptr);
+#else
+ free(ptr);
+#endif
+}
+#endif /* FORCE_USE_HEAP */
+
void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int prehashed)
{
RDATA_ALIGN16 uint8_t expandedKey[240];
+
+#ifndef FORCE_USE_HEAP
RDATA_ALIGN16 uint8_t hp_state[MEMORY];
+#else
+ uint8_t *hp_state = (uint8_t *)aligned_malloc(MEMORY,16);
+#endif
uint8_t text[INIT_SIZE_BYTE];
RDATA_ALIGN16 uint64_t a[2];
@@ -1129,6 +1156,10 @@ void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int
memcpy(state.init, text, INIT_SIZE_BYTE);
hash_permutation(&state.hs);
extra_hashes[state.hs.b[0] & 3](&state, 200, hash);
+
+#ifdef FORCE_USE_HEAP
+ aligned_free(hp_state);
+#endif
}
#else /* aarch64 && crypto */
@@ -1270,8 +1301,7 @@ void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int
#ifndef FORCE_USE_HEAP
uint8_t long_state[MEMORY];
#else
- uint8_t *long_state = NULL;
- long_state = (uint8_t *)malloc(MEMORY);
+ uint8_t *long_state = (uint8_t *)malloc(MEMORY);
#endif
if (prehashed) {
@@ -1449,7 +1479,12 @@ union cn_slow_hash_state {
#pragma pack(pop)
void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int prehashed) {
+#ifndef FORCE_USE_HEAP
uint8_t long_state[MEMORY];
+#else
+ uint8_t *long_state = (uint8_t *)malloc(MEMORY);
+#endif
+
union cn_slow_hash_state state;
uint8_t text[INIT_SIZE_BYTE];
uint8_t a[AES_BLOCK_SIZE];
@@ -1534,6 +1569,10 @@ void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int
/*memcpy(hash, &state, 32);*/
extra_hashes[state.hs.b[0] & 3](&state, 200, hash);
oaes_free((OAES_CTX **) &aes_ctx);
+
+#ifdef FORCE_USE_HEAP
+ free(long_state);
+#endif
}
#endif
diff --git a/src/cryptonote_basic/miner.cpp b/src/cryptonote_basic/miner.cpp
index dfe456ef4..2bd43de94 100644
--- a/src/cryptonote_basic/miner.cpp
+++ b/src/cryptonote_basic/miner.cpp
@@ -121,7 +121,8 @@ namespace cryptonote
//-----------------------------------------------------------------------------------------------------
miner::~miner()
{
- stop();
+ try { stop(); }
+ catch (...) { /* ignore */ }
}
//-----------------------------------------------------------------------------------------------------
bool miner::set_block_template(const block& bl, const difficulty_type& di, uint64_t height)
@@ -198,8 +199,9 @@ namespace cryptonote
{
uint64_t total_hr = std::accumulate(m_last_hash_rates.begin(), m_last_hash_rates.end(), 0);
float hr = static_cast<float>(total_hr)/static_cast<float>(m_last_hash_rates.size());
+ const auto flags = std::cout.flags();
const auto precision = std::cout.precision();
- std::cout << "hashrate: " << std::setprecision(4) << std::fixed << hr << precision << ENDL;
+ std::cout << "hashrate: " << std::setprecision(4) << std::fixed << hr << flags << precision << ENDL;
}
}
m_last_hr_merge_time = misc_utils::get_tick_count();
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 0e175cdbe..fb4dcef7c 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -52,6 +52,7 @@
#include "cryptonote_core.h"
#include "ringct/rctSigs.h"
#include "common/perf_timer.h"
+#include "common/notify.h"
#if defined(PER_BLOCK_CHECKPOINT)
#include "blocks/blocks.h"
#endif
@@ -3552,6 +3553,10 @@ leave:
get_difficulty_for_next_block(); // just to cache it
invalidate_block_template_cache();
+ std::shared_ptr<tools::Notify> block_notify = m_block_notify;
+ if (block_notify)
+ block_notify->notify(epee::string_tools::pod_to_hex(id).c_str());
+
return true;
}
//------------------------------------------------------------------
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index 50ceccd0f..ab66fac8b 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -55,6 +55,8 @@
#include "cryptonote_basic/hardfork.h"
#include "blockchain_db/blockchain_db.h"
+namespace tools { class Notify; }
+
namespace cryptonote
{
class tx_memory_pool;
@@ -706,6 +708,13 @@ namespace cryptonote
blockchain_db_sync_mode sync_mode, bool fast_sync);
/**
+ * @brief sets a block notify object to call for every new block
+ *
+ * @param notify the notify object to cal at every new block
+ */
+ void set_block_notify(const std::shared_ptr<tools::Notify> &notify) { m_block_notify = notify; }
+
+ /**
* @brief Put DB in safe sync mode
*/
void safesyncmode(const bool onoff);
@@ -1032,6 +1041,8 @@ namespace cryptonote
uint64_t m_btc_expected_reward;
bool m_btc_valid;
+ std::shared_ptr<tools::Notify> m_block_notify;
+
/**
* @brief collects the keys for all outputs being "spent" as an input
*
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 3e3d3c19c..69e3c708b 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -53,6 +53,7 @@ using namespace epee;
#include "ringct/rctTypes.h"
#include "blockchain_db/blockchain_db.h"
#include "ringct/rctSigs.h"
+#include "common/notify.h"
#include "version.h"
#undef MONERO_DEFAULT_LOG_CATEGORY
@@ -167,6 +168,11 @@ namespace cryptonote
, "Set maximum txpool weight in bytes."
, DEFAULT_TXPOOL_MAX_WEIGHT
};
+ static const command_line::arg_descriptor<std::string> arg_block_notify = {
+ "block-notify"
+ , "Run a program for each new block, '%s' will be replaced by the block hash"
+ , ""
+ };
//-----------------------------------------------------------------------------------------------
core::core(i_cryptonote_protocol* pprotocol):
@@ -276,6 +282,7 @@ namespace cryptonote
command_line::add_arg(desc, arg_offline);
command_line::add_arg(desc, arg_disable_dns_checkpoints);
command_line::add_arg(desc, arg_max_txpool_weight);
+ command_line::add_arg(desc, arg_block_notify);
miner::init_options(desc);
BlockchainDB::init_options(desc);
@@ -545,6 +552,16 @@ namespace cryptonote
m_blockchain_storage.set_user_options(blocks_threads,
sync_on_blocks, sync_threshold, sync_mode, fast_sync);
+ try
+ {
+ if (!command_line::is_arg_defaulted(vm, arg_block_notify))
+ m_blockchain_storage.set_block_notify(std::shared_ptr<tools::Notify>(new tools::Notify(command_line::get_arg(vm, arg_block_notify).c_str())));
+ }
+ catch (const std::exception &e)
+ {
+ MERROR("Failed to parse block notify spec");
+ }
+
const std::pair<uint8_t, uint64_t> regtest_hard_forks[3] = {std::make_pair(1, 0), std::make_pair(Blockchain::get_hard_fork_heights(MAINNET).back().version, 1), std::make_pair(0, 0)};
const cryptonote::test_options regtest_test_options = {
regtest_hard_forks
diff --git a/src/gen_multisig/gen_multisig.cpp b/src/gen_multisig/gen_multisig.cpp
index f11f442bc..69be70e1b 100644
--- a/src/gen_multisig/gen_multisig.cpp
+++ b/src/gen_multisig/gen_multisig.cpp
@@ -167,6 +167,8 @@ static bool generate_multisig(uint32_t threshold, uint32_t total, const std::str
int main(int argc, char* argv[])
{
+ TRY_ENTRY();
+
po::options_description desc_params(wallet_args::tr("Wallet options"));
command_line::add_arg(desc_params, arg_filename_base);
command_line::add_arg(desc_params, arg_scheme);
@@ -254,5 +256,5 @@ int main(int argc, char* argv[])
return 1;
return 0;
- //CATCH_ENTRY_L0("main", 1);
+ CATCH_ENTRY_L0("main", 1);
}
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 302d2a999..7c68de3f3 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -4157,10 +4157,11 @@ void simple_wallet::on_money_received(uint64_t height, const crypto::hash &txid,
if (find_tx_extra_field_by_type(tx_extra_fields, extra_nonce))
{
crypto::hash8 payment_id8 = crypto::null_hash8;
+ crypto::hash payment_id = crypto::null_hash;
if (get_encrypted_payment_id_from_tx_extra_nonce(extra_nonce.nonce, payment_id8))
message_writer() <<
tr("NOTE: this transaction uses an encrypted payment ID: consider using subaddresses instead");
- else
+ else if (get_payment_id_from_tx_extra_nonce(extra_nonce.nonce, payment_id))
message_writer(console_color_red, false) <<
tr("WARNING: this transaction uses an unencrypted payment ID: consider using subaddresses instead");
}
@@ -8072,6 +8073,8 @@ void simple_wallet::commit_or_save(std::vector<tools::wallet2::pending_tx>& ptx_
//----------------------------------------------------------------------------------------------------
int main(int argc, char* argv[])
{
+ TRY_ENTRY();
+
#ifdef WIN32
// Activate UTF-8 support for Boost filesystem classes on Windows
std::locale::global(boost::locale::generator().generate(""));
@@ -8166,5 +8169,5 @@ int main(int argc, char* argv[])
w.deinit();
}
return 0;
- //CATCH_ENTRY_L0("main", 1);
+ CATCH_ENTRY_L0("main", 1);
}
diff --git a/src/wallet/api/pending_transaction.cpp b/src/wallet/api/pending_transaction.cpp
index 8d200220d..913e3156f 100644
--- a/src/wallet/api/pending_transaction.cpp
+++ b/src/wallet/api/pending_transaction.cpp
@@ -200,7 +200,11 @@ std::string PendingTransactionImpl::multisigSignData() {
throw std::runtime_error("wallet is not multisig");
}
- auto cipher = m_wallet.m_wallet->save_multisig_tx(m_pending_tx);
+ tools::wallet2::multisig_tx_set txSet;
+ txSet.m_ptx = m_pending_tx;
+ txSet.m_signers = m_signers;
+ auto cipher = m_wallet.m_wallet->save_multisig_tx(txSet);
+
return epee::string_tools::buff_to_hex_nodelimer(cipher);
} catch (const std::exception& e) {
m_status = Status_Error;
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp
index 5827e4d1a..3d4e981ea 100644
--- a/src/wallet/api/wallet.cpp
+++ b/src/wallet/api/wallet.cpp
@@ -376,15 +376,15 @@ WalletImpl::WalletImpl(NetworkType nettype, uint64_t kdf_rounds)
, m_rebuildWalletCache(false)
, m_is_connected(false)
{
- m_wallet = new tools::wallet2(static_cast<cryptonote::network_type>(nettype), kdf_rounds, true);
- m_history = new TransactionHistoryImpl(this);
- m_wallet2Callback = new Wallet2CallbackImpl(this);
+ m_wallet = std::make_unique<tools::wallet2>(static_cast<cryptonote::network_type>(nettype), kdf_rounds, true);
+ m_history = std::make_unique<TransactionHistoryImpl>(this);
+ m_wallet2Callback = std::make_unique<Wallet2CallbackImpl>(this);
m_wallet->callback(m_wallet2Callback);
m_refreshThreadDone = false;
m_refreshEnabled = false;
- m_addressBook = new AddressBookImpl(this);
- m_subaddress = new SubaddressImpl(this);
- m_subaddressAccount = new SubaddressAccountImpl(this);
+ m_addressBook = std::make_unique<AddressBookImpl>(this);
+ m_subaddress = std::make_unique<SubaddressImpl>(this);
+ m_subaddressAccount = std::make_unique<SubaddressAccountImpl>(this);
m_refreshIntervalMillis = DEFAULT_REFRESH_INTERVAL_MILLIS;
@@ -405,12 +405,6 @@ WalletImpl::~WalletImpl()
close(false); // do not store wallet as part of the closing activities
// Stop refresh thread
stopRefresh();
- delete m_wallet2Callback;
- delete m_history;
- delete m_addressBook;
- delete m_subaddress;
- delete m_subaddressAccount;
- delete m_wallet;
LOG_PRINT_L1(__FUNCTION__ << " finished");
}
@@ -609,7 +603,7 @@ bool WalletImpl::recoverFromKeysWithPassword(const std::string &path,
LOG_PRINT_L1("Generated new view only wallet from keys");
}
if(has_spendkey && !has_viewkey) {
- m_wallet->generate(path, password, spendkey, true, false, false);
+ m_wallet->generate(path, password, spendkey, true, false);
setSeedLanguage(language);
LOG_PRINT_L1("Generated deterministic wallet from spend key with seed language: " + language);
}
@@ -629,7 +623,7 @@ bool WalletImpl::recoverFromDevice(const std::string &path, const std::string &p
m_recoveringFromDevice = true;
try
{
- m_wallet->restore(path, password, device_name, false);
+ m_wallet->restore(path, password, device_name);
LOG_PRINT_L1("Generated new wallet from device: " + device_name);
}
catch (const std::exception& e) {
@@ -1551,22 +1545,22 @@ void WalletImpl::disposeTransaction(PendingTransaction *t)
TransactionHistory *WalletImpl::history()
{
- return m_history;
+ return m_history.get();
}
AddressBook *WalletImpl::addressBook()
{
- return m_addressBook;
+ return m_addressBook.get();
}
Subaddress *WalletImpl::subaddress()
{
- return m_subaddress;
+ return m_subaddress.get();
}
SubaddressAccount *WalletImpl::subaddressAccount()
{
- return m_subaddressAccount;
+ return m_subaddressAccount.get();
}
void WalletImpl::setListener(WalletListener *l)
diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h
index 64350cee7..5963a7607 100644
--- a/src/wallet/api/wallet.h
+++ b/src/wallet/api/wallet.h
@@ -215,16 +215,16 @@ private:
friend class SubaddressImpl;
friend class SubaddressAccountImpl;
- tools::wallet2 * m_wallet;
+ std::unique_ptr<tools::wallet2> m_wallet;
mutable boost::mutex m_statusMutex;
mutable int m_status;
mutable std::string m_errorString;
std::string m_password;
- TransactionHistoryImpl * m_history;
- Wallet2CallbackImpl * m_wallet2Callback;
- AddressBookImpl * m_addressBook;
- SubaddressImpl * m_subaddress;
- SubaddressAccountImpl * m_subaddressAccount;
+ std::unique_ptr<TransactionHistoryImpl> m_history;
+ std::unique_ptr<Wallet2CallbackImpl> m_wallet2Callback;
+ std::unique_ptr<AddressBookImpl> m_addressBook;
+ std::unique_ptr<SubaddressImpl> m_subaddress;
+ std::unique_ptr<SubaddressAccountImpl> m_subaddressAccount;
// multi-threaded refresh stuff
std::atomic<bool> m_refreshEnabled;
diff --git a/src/wallet/ringdb.cpp b/src/wallet/ringdb.cpp
index e9fc6866d..e5995e7fb 100644
--- a/src/wallet/ringdb.cpp
+++ b/src/wallet/ringdb.cpp
@@ -398,6 +398,8 @@ bool ringdb::blackball_worker(const std::vector<std::pair<uint64_t, uint64_t>> &
epee::misc_utils::auto_scope_leave_caller txn_dtor = epee::misc_utils::create_scope_leave_handler([&](){if (tx_active) mdb_txn_abort(txn);});
tx_active = true;
+ dbr = mdb_cursor_open(txn, dbi_blackballs, &cursor);
+ THROW_WALLET_EXCEPTION_IF(dbr, tools::error::wallet_internal_error, "Failed to create cursor for blackballs table: " + std::string(mdb_strerror(dbr)));
MDB_val key, data;
for (const std::pair<uint64_t, uint64_t> &output: outputs)
@@ -411,25 +413,22 @@ bool ringdb::blackball_worker(const std::vector<std::pair<uint64_t, uint64_t>> &
{
case BLACKBALL_BLACKBALL:
MDEBUG("Blackballing output " << output.first << "/" << output.second);
- dbr = mdb_put(txn, dbi_blackballs, &key, &data, MDB_APPENDDUP);
+ dbr = mdb_cursor_put(cursor, &key, &data, MDB_APPENDDUP);
if (dbr == MDB_KEYEXIST)
dbr = 0;
break;
case BLACKBALL_UNBLACKBALL:
MDEBUG("Unblackballing output " << output.first << "/" << output.second);
- dbr = mdb_del(txn, dbi_blackballs, &key, &data);
- if (dbr == MDB_NOTFOUND)
- dbr = 0;
+ dbr = mdb_cursor_get(cursor, &key, &data, MDB_GET_BOTH);
+ if (dbr == 0)
+ dbr = mdb_cursor_del(cursor, 0);
break;
case BLACKBALL_QUERY:
- dbr = mdb_cursor_open(txn, dbi_blackballs, &cursor);
- THROW_WALLET_EXCEPTION_IF(dbr, tools::error::wallet_internal_error, "Failed to create cursor for blackballs table: " + std::string(mdb_strerror(dbr)));
dbr = mdb_cursor_get(cursor, &key, &data, MDB_GET_BOTH);
THROW_WALLET_EXCEPTION_IF(dbr && dbr != MDB_NOTFOUND, tools::error::wallet_internal_error, "Failed to lookup in blackballs table: " + std::string(mdb_strerror(dbr)));
ret = dbr != MDB_NOTFOUND;
if (dbr == MDB_NOTFOUND)
dbr = 0;
- mdb_cursor_close(cursor);
break;
case BLACKBALL_CLEAR:
break;
@@ -439,6 +438,8 @@ bool ringdb::blackball_worker(const std::vector<std::pair<uint64_t, uint64_t>> &
THROW_WALLET_EXCEPTION_IF(dbr, tools::error::wallet_internal_error, "Failed to query blackballs table: " + std::string(mdb_strerror(dbr)));
}
+ mdb_cursor_close(cursor);
+
if (op == BLACKBALL_CLEAR)
{
dbr = mdb_drop(txn, dbi_blackballs, 0);
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 75178845a..299b4afeb 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -66,6 +66,7 @@ using namespace epee;
#include "memwipe.h"
#include "common/base58.h"
#include "common/dns_utils.h"
+#include "common/notify.h"
#include "ringct/rctSigs.h"
#include "ringdb.h"
@@ -162,6 +163,7 @@ struct options {
};
const command_line::arg_descriptor<uint64_t> kdf_rounds = {"kdf-rounds", tools::wallet2::tr("Number of rounds for the key derivation function"), 1};
const command_line::arg_descriptor<std::string> hw_device = {"hw-device", tools::wallet2::tr("HW device to use"), ""};
+ const command_line::arg_descriptor<std::string> tx_notify = { "tx-notify" , "Run a program for each new incoming transaction, '%s' will be replaced by the transaction hash" , "" };
};
void do_prepare_file_names(const std::string& file_path, std::string& keys_file, std::string& wallet_file)
@@ -268,6 +270,17 @@ std::unique_ptr<tools::wallet2> make_basic(const boost::program_options::variabl
boost::filesystem::path ringdb_path = command_line::get_arg(vm, opts.shared_ringdb_dir);
wallet->set_ring_database(ringdb_path.string());
wallet->device_name(device_name);
+
+ try
+ {
+ if (!command_line::is_arg_defaulted(vm, opts.tx_notify))
+ wallet->set_tx_notify(std::shared_ptr<tools::Notify>(new tools::Notify(command_line::get_arg(vm, opts.tx_notify).c_str())));
+ }
+ catch (const std::exception &e)
+ {
+ MERROR("Failed to parse tx notify spec");
+ }
+
return wallet;
}
@@ -838,6 +851,7 @@ void wallet2::init_options(boost::program_options::options_description& desc_par
command_line::add_arg(desc_params, opts.shared_ringdb_dir);
command_line::add_arg(desc_params, opts.kdf_rounds);
command_line::add_arg(desc_params, opts.hw_device);
+ command_line::add_arg(desc_params, opts.tx_notify);
}
std::unique_ptr<wallet2> wallet2::make_from_json(const boost::program_options::variables_map& vm, bool unattended, const std::string& json_file, const std::function<boost::optional<tools::password_container>(const char *, bool)> &password_prompter)
@@ -1328,6 +1342,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
std::vector<size_t> outs;
std::unordered_map<cryptonote::subaddress_index, uint64_t> tx_money_got_in_outs; // per receiving subaddress index
crypto::public_key tx_pub_key = null_pkey;
+ bool notify = false;
std::vector<tx_extra_field> local_tx_extra_fields;
if (tx_cache_data.tx_extra_fields.empty())
@@ -1567,6 +1582,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
m_callback->on_money_received(height, txid, tx, td.m_amount, td.m_subaddr_index);
}
total_received_1 += amount;
+ notify = true;
}
else if (m_transfers[kit->second].m_spent || m_transfers[kit->second].amount() >= tx_scan_info[o].amount)
{
@@ -1634,6 +1650,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
m_callback->on_money_received(height, txid, tx, td.m_amount, td.m_subaddr_index);
}
total_received_1 += extra_amount;
+ notify = true;
}
}
}
@@ -1707,10 +1724,14 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
}
// remove change sent to the spending subaddress account from the list of received funds
+ uint64_t sub_change = 0;
for (auto i = tx_money_got_in_outs.begin(); i != tx_money_got_in_outs.end();)
{
if (subaddr_account && i->first.major == *subaddr_account)
+ {
+ sub_change += i->second;
i = tx_money_got_in_outs.erase(i);
+ }
else
++i;
}
@@ -1755,7 +1776,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
}
}
- uint64_t total_received_2 = 0;
+ uint64_t total_received_2 = sub_change;
for (const auto& i : tx_money_got_in_outs)
total_received_2 += i.second;
if (total_received_1 != total_received_2)
@@ -1790,6 +1811,13 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
LOG_PRINT_L2("Payment found in " << (pool ? "pool" : "block") << ": " << payment_id << " / " << payment.m_tx_hash << " / " << payment.m_amount);
}
}
+
+ if (notify)
+ {
+ std::shared_ptr<tools::Notify> tx_notify = m_tx_notify;
+ if (tx_notify)
+ tx_notify->notify(epee::string_tools::pod_to_hex(txid).c_str());
+ }
}
//----------------------------------------------------------------------------------------------------
void wallet2::process_unconfirmed(const crypto::hash &txid, const cryptonote::transaction& tx, uint64_t height)
@@ -3282,9 +3310,16 @@ bool wallet2::load_keys(const std::string& keys_file_name, const epee::wipeable_
encrypted_secret_keys = field_encrypted_secret_keys;
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, device_name, std::string, String, false, std::string());
- if (m_device_name.empty() && field_device_name_found)
+ if (m_device_name.empty())
{
- m_device_name = field_device_name;
+ if (field_device_name_found)
+ {
+ m_device_name = field_device_name;
+ }
+ else
+ {
+ m_device_name = m_key_device_type == hw::device::device_type::LEDGER ? "Ledger" : "default";
+ }
}
}
else
@@ -6723,11 +6758,23 @@ void wallet2::get_outs(std::vector<std::vector<tools::wallet2::get_outs_entry>>
}
// while we still need more mixins
+ uint64_t num_usable_outs = num_outs;
+ bool allow_blackballed = false;
while (num_found < requested_outputs_count)
{
// if we've gone through every possible output, we've gotten all we can
- if (seen_indices.size() == num_outs)
- break;
+ if (seen_indices.size() == num_usable_outs)
+ {
+ // there is a first pass which rejects blackballed outputs, then a second pass
+ // which allows them if we don't have enough non blackballed outputs to reach
+ // the required amount of outputs (since consensus does not care about blackballed
+ // outputs, we still need to reach the minimum ring size)
+ if (allow_blackballed)
+ break;
+ MINFO("Not enough non blackballed outputs, we'll allow blackballed ones");
+ allow_blackballed = true;
+ num_usable_outs = num_outs;
+ }
// get a random output index from the DB. If we've already seen it,
// return to the top of the loop and try again, otherwise add it to the
@@ -6801,14 +6848,26 @@ void wallet2::get_outs(std::vector<std::vector<tools::wallet2::get_outs_entry>>
if (seen_indices.count(i))
continue;
- if (is_output_blackballed(std::make_pair(amount, i))) // don't add blackballed outputs
+ if (!allow_blackballed && is_output_blackballed(std::make_pair(amount, i))) // don't add blackballed outputs
+ {
+ --num_usable_outs;
continue;
+ }
seen_indices.emplace(i);
LOG_PRINT_L2("picking " << i << " as " << type);
req.outputs.push_back({amount, i});
++num_found;
}
+
+ // if we had enough unusable outputs, we might fall off here and still
+ // have too few outputs, so we stuff with one to keep counts good, and
+ // we'll error out later
+ while (num_found < requested_outputs_count)
+ {
+ req.outputs.push_back({amount, 0});
+ ++num_found;
+ }
}
// sort the subsection, to ensure the daemon doesn't know which output is ours
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index acbc09c36..497dd486f 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -68,6 +68,7 @@ namespace tools
{
class ringdb;
class wallet2;
+ class Notify;
class wallet_keys_unlocker
{
@@ -554,7 +555,7 @@ namespace tools
* \param device_name name of HW to use
* \param create_address_file Whether to create an address file
*/
- void restore(const std::string& wallet_, const epee::wipeable_string& password, const std::string &device_name, bool create_address_file);
+ void restore(const std::string& wallet_, const epee::wipeable_string& password, const std::string &device_name, bool create_address_file = false);
/*!
* \brief Creates a multisig wallet
@@ -1176,6 +1177,8 @@ namespace tools
void change_password(const std::string &filename, const epee::wipeable_string &original_password, const epee::wipeable_string &new_password);
+ void set_tx_notify(const std::shared_ptr<tools::Notify> &notify) { m_tx_notify = notify; }
+
private:
/*!
* \brief Stores wallet information to wallet file.
@@ -1353,6 +1356,8 @@ namespace tools
boost::optional<epee::wipeable_string> m_encrypt_keys_after_refresh;
bool m_unattended;
+
+ std::shared_ptr<tools::Notify> m_tx_notify;
};
}
BOOST_CLASS_VERSION(tools::wallet2, 25)
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index e6eb64d12..5991e0cc2 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -1554,7 +1554,7 @@ namespace tools
rpc_transfers.global_index = td.m_global_output_index;
rpc_transfers.tx_hash = epee::string_tools::pod_to_hex(td.m_txid);
rpc_transfers.subaddr_index = {td.m_subaddr_index.major, td.m_subaddr_index.minor};
- rpc_transfers.key_image = req.verbose && td.m_key_image_known ? epee::string_tools::pod_to_hex(td.m_key_image) : "";
+ rpc_transfers.key_image = td.m_key_image_known ? epee::string_tools::pod_to_hex(td.m_key_image) : "";
res.transfers.push_back(rpc_transfers);
}
}
@@ -3457,6 +3457,8 @@ public:
std::string const t_executor::NAME = "Wallet RPC Daemon";
int main(int argc, char** argv) {
+ TRY_ENTRY();
+
namespace po = boost::program_options;
const auto arg_wallet_file = wallet_args::arg_wallet_file();
@@ -3500,4 +3502,5 @@ int main(int argc, char** argv) {
}
return daemonizer::daemonize(argc, const_cast<const char**>(argv), t_executor{}, *vm) ? 0 : 1;
+ CATCH_ENTRY_L0("main", 1);
}
diff --git a/src/wallet/wallet_rpc_server_commands_defs.h b/src/wallet/wallet_rpc_server_commands_defs.h
index 2168e0f71..81ea22928 100644
--- a/src/wallet/wallet_rpc_server_commands_defs.h
+++ b/src/wallet/wallet_rpc_server_commands_defs.h
@@ -883,13 +883,11 @@ namespace wallet_rpc
std::string transfer_type;
uint32_t account_index;
std::set<uint32_t> subaddr_indices;
- bool verbose;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(transfer_type)
KV_SERIALIZE(account_index)
KV_SERIALIZE(subaddr_indices)
- KV_SERIALIZE(verbose)
END_KV_SERIALIZE_MAP()
};
diff --git a/tests/fuzz/fuzzer.cpp b/tests/fuzz/fuzzer.cpp
index 032ff049a..ab14e2b79 100644
--- a/tests/fuzz/fuzzer.cpp
+++ b/tests/fuzz/fuzzer.cpp
@@ -46,6 +46,8 @@ static int __AFL_LOOP(int)
int run_fuzzer(int argc, const char **argv, Fuzzer &fuzzer)
{
+ TRY_ENTRY();
+
if (argc < 2)
{
std::cout << "usage: " << argv[0] << " " << "<filename>" << std::endl;
@@ -69,4 +71,6 @@ int run_fuzzer(int argc, const char **argv, Fuzzer &fuzzer)
}
return 0;
+
+ CATCH_ENTRY_L0("run_fuzzer", 1);
}
diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp
index 7c5135c65..87a1573c2 100644
--- a/tests/performance_tests/main.cpp
+++ b/tests/performance_tests/main.cpp
@@ -75,10 +75,10 @@ int main(int argc, char** argv)
const command_line::arg_descriptor<bool> arg_verbose = { "verbose", "Verbose output", false };
const command_line::arg_descriptor<bool> arg_stats = { "stats", "Including statistics (min/median)", false };
const command_line::arg_descriptor<unsigned> arg_loop_multiplier = { "loop-multiplier", "Run for that many times more loops", 1 };
- command_line::add_arg(desc_options, arg_filter, "");
- command_line::add_arg(desc_options, arg_verbose, "");
- command_line::add_arg(desc_options, arg_stats, "");
- command_line::add_arg(desc_options, arg_loop_multiplier, "");
+ command_line::add_arg(desc_options, arg_filter);
+ command_line::add_arg(desc_options, arg_verbose);
+ command_line::add_arg(desc_options, arg_stats);
+ command_line::add_arg(desc_options, arg_loop_multiplier);
po::variables_map vm;
bool r = command_line::handle_error_helper(desc_options, [&]()
diff --git a/tests/unit_tests/is_hdd.cpp b/tests/unit_tests/is_hdd.cpp
index 1be670e5e..040af4f47 100644
--- a/tests/unit_tests/is_hdd.cpp
+++ b/tests/unit_tests/is_hdd.cpp
@@ -6,12 +6,12 @@
TEST(is_hdd, linux_os_root)
{
std::string path = "/";
- EXPECT_TRUE(tools::is_hdd(path.c_str()));
+ EXPECT_TRUE(tools::is_hdd(path.c_str()) != boost::none);
}
#else
TEST(is_hdd, unknown_os)
{
std::string path = "";
- EXPECT_FALSE(tools::is_hdd(path.c_str()));
+ EXPECT_FALSE(tools::is_hdd(path.c_str()) != boost::none);
}
#endif
diff --git a/tests/unit_tests/main.cpp b/tests/unit_tests/main.cpp
index 13b62cbb4..f7251a09e 100644
--- a/tests/unit_tests/main.cpp
+++ b/tests/unit_tests/main.cpp
@@ -53,6 +53,8 @@ namespace cryptonote { template class t_cryptonote_protocol_handler<cryptonote::
int main(int argc, char** argv)
{
+ TRY_ENTRY();
+
tools::on_startup();
epee::string_tools::set_module_name_and_folder(argv[0]);
mlog_configure(mlog_get_default_log_path("unit_tests.log"), true);
@@ -76,5 +78,7 @@ int main(int argc, char** argv)
unit_test::data_dir = command_line::get_arg(vm, arg_data_dir);
+ CATCH_ENTRY_L0("main", 1);
+
return RUN_ALL_TESTS();
}
diff --git a/tests/unit_tests/mlocker.cpp b/tests/unit_tests/mlocker.cpp
index 480940374..c97dc2c1d 100644
--- a/tests/unit_tests/mlocker.cpp
+++ b/tests/unit_tests/mlocker.cpp
@@ -46,14 +46,14 @@ TEST(mlocker, distinct_1)
const size_t base_pages = epee::mlocker::get_num_locked_pages();
const size_t base_objects = epee::mlocker::get_num_locked_objects();
std::unique_ptr<char[]> data{new char[8 * page_size]};
- epee::mlocker *m0 = new epee::mlocker(BASE(data), 1);
- epee::mlocker *m1 = new epee::mlocker(BASE(data) + 2 * page_size, 1);
- epee::mlocker *m2 = new epee::mlocker(BASE(data) + 3 * page_size, 1);
+ std::shared_ptr<epee::mlocker> m0{new epee::mlocker(BASE(data), 1)};
+ std::shared_ptr<epee::mlocker> m1{new epee::mlocker(BASE(data) + 2 * page_size, 1)};
+ std::shared_ptr<epee::mlocker> m2{new epee::mlocker(BASE(data) + 3 * page_size, 1)};
ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 3);
ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 3);
- delete m0;
- delete m1;
- delete m2;
+ m0 = NULL;
+ m1 = NULL;
+ m2 = NULL;
ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 0);
ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 0);
}
@@ -65,14 +65,14 @@ TEST(mlocker, distinct_full_page)
const size_t base_pages = epee::mlocker::get_num_locked_pages();
const size_t base_objects = epee::mlocker::get_num_locked_objects();
std::unique_ptr<char[]> data{new char[8 * page_size]};
- epee::mlocker *m0 = new epee::mlocker(BASE(data), page_size);
- epee::mlocker *m1 = new epee::mlocker(BASE(data) + 2 * page_size, page_size);
- epee::mlocker *m2 = new epee::mlocker(BASE(data) + 3 * page_size, page_size);
+ std::shared_ptr<epee::mlocker> m0{new epee::mlocker(BASE(data), page_size)};
+ std::shared_ptr<epee::mlocker> m1{new epee::mlocker(BASE(data) + 2 * page_size, page_size)};
+ std::shared_ptr<epee::mlocker> m2{new epee::mlocker(BASE(data) + 3 * page_size, page_size)};
ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 3);
ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 3);
- delete m0;
- delete m1;
- delete m2;
+ m0 = NULL;
+ m1 = NULL;
+ m2 = NULL;
ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 0);
ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 0);
}
@@ -84,16 +84,16 @@ TEST(mlocker, identical)
const size_t base_pages = epee::mlocker::get_num_locked_pages();
const size_t base_objects = epee::mlocker::get_num_locked_objects();
std::unique_ptr<char[]> data{new char[8 * page_size]};
- epee::mlocker *m0 = new epee::mlocker(BASE(data) + page_size, 32);
- epee::mlocker *m1 = new epee::mlocker(BASE(data) + page_size, 32);
- epee::mlocker *m2 = new epee::mlocker(BASE(data) + page_size, 32);
+ std::shared_ptr<epee::mlocker> m0{new epee::mlocker(BASE(data) + page_size, 32)};
+ std::shared_ptr<epee::mlocker> m1{new epee::mlocker(BASE(data) + page_size, 32)};
+ std::shared_ptr<epee::mlocker> m2{new epee::mlocker(BASE(data) + page_size, 32)};
ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 1);
ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 3);
- delete m1;
+ m1 = NULL;
ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 1);
ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 2);
- delete m0;
- delete m2;
+ m0 = NULL;
+ m2 = NULL;
ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 0);
ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 0);
}
@@ -105,16 +105,16 @@ TEST(mlocker, overlapping_small)
const size_t base_pages = epee::mlocker::get_num_locked_pages();
const size_t base_objects = epee::mlocker::get_num_locked_objects();
std::unique_ptr<char[]> data{new char[8 * page_size]};
- epee::mlocker *m0 = new epee::mlocker(BASE(data), 32);
- epee::mlocker *m1 = new epee::mlocker(BASE(data) + 16, 32);
- epee::mlocker *m2 = new epee::mlocker(BASE(data) + 8, 32);
+ std::shared_ptr<epee::mlocker> m0{new epee::mlocker(BASE(data), 32)};
+ std::shared_ptr<epee::mlocker> m1{new epee::mlocker(BASE(data) + 16, 32)};
+ std::shared_ptr<epee::mlocker> m2{new epee::mlocker(BASE(data) + 8, 32)};
ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 1);
ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 3);
- delete m1;
+ m1 = NULL;
ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 1);
ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 2);
- delete m2;
- delete m0;
+ m2 = NULL;
+ m0 = NULL;
ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 0);
ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 0);
}
@@ -126,16 +126,16 @@ TEST(mlocker, multi_page)
const size_t base_pages = epee::mlocker::get_num_locked_pages();
const size_t base_objects = epee::mlocker::get_num_locked_objects();
std::unique_ptr<char[]> data{new char[8 * page_size]};
- epee::mlocker *m0 = new epee::mlocker(BASE(data) + page_size, page_size * 3);
+ std::shared_ptr<epee::mlocker> m0{new epee::mlocker(BASE(data) + page_size, page_size * 3)};
ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 3);
ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 1);
- epee::mlocker *m1 = new epee::mlocker(BASE(data) + page_size * 7, page_size);
+ std::shared_ptr<epee::mlocker> m1{new epee::mlocker(BASE(data) + page_size * 7, page_size)};
ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 4);
ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 2);
- delete m0;
+ m0 = NULL;
ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 1);
ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 1);
- delete m1;
+ m1 = NULL;
ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 0);
ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 0);
}
@@ -147,10 +147,10 @@ TEST(mlocker, cross_page)
const size_t base_pages = epee::mlocker::get_num_locked_pages();
const size_t base_objects = epee::mlocker::get_num_locked_objects();
std::unique_ptr<char[]> data{new char[2 * page_size]};
- epee::mlocker *m0 = new epee::mlocker(BASE(data) + page_size - 1, 2);
+ std::shared_ptr<epee::mlocker> m0{new epee::mlocker(BASE(data) + page_size - 1, 2)};
ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 2);
ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 1);
- delete m0;
+ m0 = NULL;
ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 0);
ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 0);
}
@@ -158,21 +158,22 @@ TEST(mlocker, cross_page)
TEST(mlocker, redundant)
{
const size_t page_size = epee::mlocker::get_page_size();
+ ASSERT_TRUE(page_size > 0);
const size_t base_pages = epee::mlocker::get_num_locked_pages();
const size_t base_objects = epee::mlocker::get_num_locked_objects();
std::unique_ptr<char[]> data{new char[2 * page_size]};
ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 0);
ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 0);
- epee::mlocker *m0 = new epee::mlocker(BASE(data), 32);
+ std::shared_ptr<epee::mlocker> m0{new epee::mlocker(BASE(data), 32)};
ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 1);
ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 1);
- epee::mlocker *m1 = new epee::mlocker(BASE(data), 32);
+ std::shared_ptr<epee::mlocker> m1{new epee::mlocker(BASE(data), 32)};
ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 1);
ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 2);
- delete m1;
+ m1 = NULL;
ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 1);
ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 1);
- delete m0;
+ m0 = NULL;
ASSERT_EQ(epee::mlocker::get_num_locked_pages(), base_pages + 0);
ASSERT_EQ(epee::mlocker::get_num_locked_objects(), base_objects + 0);
}
diff --git a/tests/unit_tests/ringdb.cpp b/tests/unit_tests/ringdb.cpp
index 416ae0890..0d92049ac 100644
--- a/tests/unit_tests/ringdb.cpp
+++ b/tests/unit_tests/ringdb.cpp
@@ -150,6 +150,30 @@ TEST(blackball, found)
ASSERT_TRUE(ringdb.blackballed(OUTPUT_1));
}
+TEST(blackball, vector)
+{
+ RingDB ringdb;
+ std::vector<std::pair<uint64_t, uint64_t>> outputs;
+ outputs.push_back(std::make_pair(0, 1));
+ outputs.push_back(std::make_pair(10, 3));
+ outputs.push_back(std::make_pair(10, 4));
+ outputs.push_back(std::make_pair(10, 8));
+ outputs.push_back(std::make_pair(20, 0));
+ outputs.push_back(std::make_pair(20, 1));
+ outputs.push_back(std::make_pair(30, 5));
+ ASSERT_TRUE(ringdb.blackball(outputs));
+ ASSERT_TRUE(ringdb.blackballed(std::make_pair(0, 1)));
+ ASSERT_FALSE(ringdb.blackballed(std::make_pair(10, 2)));
+ ASSERT_TRUE(ringdb.blackballed(std::make_pair(10, 3)));
+ ASSERT_TRUE(ringdb.blackballed(std::make_pair(10, 4)));
+ ASSERT_FALSE(ringdb.blackballed(std::make_pair(10, 5)));
+ ASSERT_TRUE(ringdb.blackballed(std::make_pair(10, 8)));
+ ASSERT_TRUE(ringdb.blackballed(std::make_pair(20, 0)));
+ ASSERT_TRUE(ringdb.blackballed(std::make_pair(20, 1)));
+ ASSERT_FALSE(ringdb.blackballed(std::make_pair(20, 2)));
+ ASSERT_TRUE(ringdb.blackballed(std::make_pair(30, 5)));
+}
+
TEST(blackball, unblackball)
{
RingDB ringdb;
diff --git a/tests/unit_tests/wipeable_string.cpp b/tests/unit_tests/wipeable_string.cpp
index 65718fd45..44e050c5c 100644
--- a/tests/unit_tests/wipeable_string.cpp
+++ b/tests/unit_tests/wipeable_string.cpp
@@ -194,13 +194,13 @@ TEST(wipeable_string, parse_hexstr)
ASSERT_EQ(boost::none, epee::wipeable_string("0").parse_hexstr());
ASSERT_EQ(boost::none, epee::wipeable_string("000").parse_hexstr());
- ASSERT_TRUE((s = epee::wipeable_string("").parse_hexstr()));
+ ASSERT_TRUE((s = epee::wipeable_string("").parse_hexstr()) != boost::none);
ASSERT_EQ(*s, "");
- ASSERT_TRUE((s = epee::wipeable_string("00").parse_hexstr()));
+ ASSERT_TRUE((s = epee::wipeable_string("00").parse_hexstr()) != boost::none);
ASSERT_EQ(*s, epee::wipeable_string("", 1));
- ASSERT_TRUE((s = epee::wipeable_string("41").parse_hexstr()));
+ ASSERT_TRUE((s = epee::wipeable_string("41").parse_hexstr()) != boost::none);
ASSERT_EQ(*s, epee::wipeable_string("A"));
- ASSERT_TRUE((s = epee::wipeable_string("414243").parse_hexstr()));
+ ASSERT_TRUE((s = epee::wipeable_string("414243").parse_hexstr()) != boost::none);
ASSERT_EQ(*s, epee::wipeable_string("ABC"));
}