aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt9
-rw-r--r--Makefile2
-rw-r--r--cmake/CheckTrezor.cmake25
-rw-r--r--cmake/FindLibUSB.cmake10
-rw-r--r--contrib/depends/Makefile5
-rw-r--r--contrib/depends/packages/native_cctools.mk5
-rw-r--r--contrib/depends/packages/native_libtapi.mk5
-rw-r--r--contrib/depends/packages/native_protobuf.mk8
-rw-r--r--contrib/depends/packages/openssl.mk10
-rw-r--r--contrib/depends/packages/protobuf.mk11
-rw-r--r--contrib/depends/packages/unbound.mk2
-rw-r--r--contrib/depends/patches/native_cctools/no-build-date.patch12
-rw-r--r--contrib/depends/patches/native_libtapi/no_embed_git_rev.patch31
-rw-r--r--contrib/depends/toolchain.cmake.in4
-rw-r--r--contrib/epee/README.md2
-rw-r--r--contrib/epee/include/storages/portable_storage_val_converters.h1
-rw-r--r--contrib/epee/include/string_tools.h17
-rw-r--r--contrib/epee/src/readline_buffer.cpp3
-rw-r--r--contrib/epee/src/string_tools.cpp83
-rw-r--r--contrib/valgrind/monero.supp31
-rw-r--r--src/blocks/checkpoints.datbin332676 -> 387844 bytes
-rw-r--r--src/checkpoints/checkpoints.cpp10
-rw-r--r--src/common/timings.cc96
-rw-r--r--src/common/timings.h10
-rw-r--r--src/common/util.cpp41
-rw-r--r--src/common/util.h8
-rw-r--r--src/crypto/CMakeLists.txt1
-rw-r--r--src/crypto/blake2b.c563
-rw-r--r--src/crypto/blake2b.h116
-rw-r--r--src/cryptonote_basic/account.cpp11
-rw-r--r--src/cryptonote_basic/account.h1
-rw-r--r--src/cryptonote_basic/verification_context.h1
-rw-r--r--src/cryptonote_config.h2
-rw-r--r--src/cryptonote_core/blockchain.cpp105
-rw-r--r--src/cryptonote_core/blockchain.h24
-rw-r--r--src/cryptonote_core/cryptonote_tx_utils.cpp12
-rw-r--r--src/cryptonote_core/cryptonote_tx_utils.h6
-rw-r--r--src/cryptonote_core/tx_pool.cpp9
-rw-r--r--src/cryptonote_protocol/levin_notify.cpp11
-rw-r--r--src/cryptonote_protocol/levin_notify.h3
-rw-r--r--src/device/log.hpp2
-rw-r--r--src/device_trezor/README.md22
-rw-r--r--src/gen_multisig/gen_multisig.cpp7
-rw-r--r--src/multisig/multisig_account.h58
-rw-r--r--src/multisig/multisig_account_kex_impl.cpp175
-rw-r--r--src/multisig/multisig_tx_builder_ringct.cpp3
-rw-r--r--src/multisig/multisig_tx_builder_ringct.h1
-rw-r--r--src/p2p/net_node.inl22
-rw-r--r--src/p2p/net_peerlist.cpp3
-rw-r--r--src/ringct/rctTypes.h2
-rw-r--r--src/rpc/core_rpc_server.cpp8
-rw-r--r--src/rpc/core_rpc_server_commands_defs.h4
-rw-r--r--src/rpc/daemon_handler.cpp21
-rw-r--r--src/serialization/crypto.h2
-rw-r--r--src/serialization/serialization.h26
-rw-r--r--src/serialization/tuple.h162
-rw-r--r--src/simplewallet/simplewallet.cpp487
-rw-r--r--src/simplewallet/simplewallet.h7
-rw-r--r--src/wallet/api/wallet.cpp262
-rw-r--r--src/wallet/api/wallet.h13
-rw-r--r--src/wallet/api/wallet2_api.h54
-rw-r--r--src/wallet/message_store.h7
-rw-r--r--src/wallet/wallet2.cpp1365
-rw-r--r--src/wallet/wallet2.h200
-rw-r--r--src/wallet/wallet_errors.h54
-rw-r--r--src/wallet/wallet_rpc_server.cpp310
-rw-r--r--src/wallet/wallet_rpc_server.h8
-rw-r--r--src/wallet/wallet_rpc_server_commands_defs.h95
-rw-r--r--src/wallet/wallet_rpc_server_error_codes.h3
-rw-r--r--tests/block_weight/block_weight.cpp6
-rwxr-xr-xtests/block_weight/block_weight.py16
-rw-r--r--tests/core_tests/block_validation.cpp4
-rw-r--r--tests/core_tests/bulletproof_plus.cpp2
-rw-r--r--tests/core_tests/bulletproofs.cpp2
-rw-r--r--tests/core_tests/chaingen.cpp12
-rw-r--r--tests/core_tests/chaingen.h2
-rw-r--r--tests/core_tests/chaingen_serialization.h3
-rw-r--r--tests/core_tests/double_spend.inl2
-rw-r--r--tests/core_tests/integer_overflow.cpp4
-rw-r--r--tests/core_tests/multisig.cpp4
-rw-r--r--tests/core_tests/rct.cpp4
-rw-r--r--tests/core_tests/rct2.cpp2
-rw-r--r--tests/core_tests/transaction_tests.cpp2
-rw-r--r--tests/core_tests/tx_validation.cpp29
-rw-r--r--tests/core_tests/v2_tests.cpp2
-rw-r--r--tests/core_tests/wallet_tools.cpp8
-rw-r--r--tests/core_tests/wallet_tools.h3
-rwxr-xr-xtests/functional_tests/functional_tests_rpc.py24
-rw-r--r--tests/functional_tests/http_digest_auth.py110
-rw-r--r--tests/functional_tests/transactions_flow_test.cpp2
-rwxr-xr-xtests/functional_tests/transfer.py400
-rwxr-xr-xtests/functional_tests/util_resources.py25
-rwxr-xr-xtests/functional_tests/wallet.py43
-rw-r--r--tests/hash/main.cpp2
-rw-r--r--tests/performance_tests/check_tx_signature.h6
-rw-r--r--tests/performance_tests/construct_tx.h2
-rw-r--r--tests/performance_tests/ge_frombytes_vartime.h2
-rw-r--r--tests/performance_tests/ge_tobytes.h2
-rw-r--r--tests/performance_tests/performance_tests.h13
-rw-r--r--tests/trezor/trezor_tests.cpp1
-rw-r--r--tests/unit_tests/CMakeLists.txt1
-rw-r--r--tests/unit_tests/crypto.cpp9
-rw-r--r--tests/unit_tests/fee.cpp136
-rw-r--r--tests/unit_tests/json_serialization.cpp2
-rw-r--r--tests/unit_tests/levin.cpp33
-rw-r--r--tests/unit_tests/multisig.cpp182
-rw-r--r--tests/unit_tests/scaling_2021.cpp66
-rw-r--r--tests/unit_tests/serialization.cpp97
-rw-r--r--tests/unit_tests/wallet_storage.cpp13
-rw-r--r--tests/unit_tests/wipeable_string.cpp12
-rw-r--r--utils/python-rpc/framework/daemon.py5
-rw-r--r--utils/python-rpc/framework/rpc.py8
-rw-r--r--utils/python-rpc/framework/wallet.py61
113 files changed, 4757 insertions, 1296 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6ffdaeb55..f9d43aa55 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -338,6 +338,11 @@ set(RISCV 1)
set(RISCV32 1)
endif()
+if(ARCH_ID STREQUAL "loongarch64")
+set(LOONGARCH 1)
+set(LOONGARCH64 1)
+endif()
+
if(WIN32 OR ARM OR PPC64LE OR PPC64 OR PPC)
set(OPT_FLAGS_RELEASE "-O2")
else()
@@ -747,7 +752,7 @@ else()
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 AND NOT RISCV)
+ elseif(NOT ARM AND NOT PPC64LE AND NOT PPC64 AND NOT PPC AND NOT S390X AND NOT RISCV AND NOT LOONGARCH)
message(STATUS "AES support enabled")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -maes")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maes")
@@ -757,6 +762,8 @@ else()
message(STATUS "AES support not available on s390x")
elseif(RISCV)
message(STATUS "AES support not available on RISC-V")
+ elseif(LOONGARCH)
+ message(STATUS "AES support not available on LOONGARCH")
elseif(ARM6)
message(STATUS "AES support not available on ARMv6")
elseif(ARM7)
diff --git a/Makefile b/Makefile
index 99c8ed31d..c0476f0d6 100644
--- a/Makefile
+++ b/Makefile
@@ -48,7 +48,7 @@ all: release-all
depends:
cd contrib/depends && $(MAKE) HOST=$(target) && cd ../.. && mkdir -p build/$(target)/release
- cd build/$(target)/release && cmake -DCMAKE_TOOLCHAIN_FILE=$(CURDIR)/contrib/depends/$(target)/share/toolchain.cmake ../../.. && $(MAKE)
+ cd build/$(target)/release && USE_DEVICE_TREZOR_MANDATORY=1 cmake -DCMAKE_TOOLCHAIN_FILE=$(CURDIR)/contrib/depends/$(target)/share/toolchain.cmake ../../.. && $(MAKE)
cmake-debug:
mkdir -p $(builddir)/debug
diff --git a/cmake/CheckTrezor.cmake b/cmake/CheckTrezor.cmake
index 05b8ebd93..87582a713 100644
--- a/cmake/CheckTrezor.cmake
+++ b/cmake/CheckTrezor.cmake
@@ -75,7 +75,13 @@ if (USE_DEVICE_TREZOR)
# Protobuf is required to build protobuf messages for Trezor
include(FindProtobuf OPTIONAL)
- FIND_PACKAGE(Protobuf CONFIG)
+ # PkgConfig works better with new Protobuf
+ find_package(PkgConfig QUIET)
+ pkg_check_modules(PROTOBUF protobuf)
+
+ if (NOT Protobuf_FOUND)
+ FIND_PACKAGE(Protobuf CONFIG)
+ endif()
if (NOT Protobuf_FOUND)
FIND_PACKAGE(Protobuf)
endif()
@@ -83,11 +89,11 @@ if (USE_DEVICE_TREZOR)
_trezor_protobuf_fix_vars()
# Early fail for optional Trezor support
- if(${Protobuf_VERSION} GREATER 21)
- trezor_fatal_msg("Trezor: Unsupported Protobuf version ${Protobuf_VERSION}. Please, use Protobuf v21.")
- elseif(NOT Protobuf_FOUND AND NOT Protobuf_LIBRARY AND NOT Protobuf_PROTOC_EXECUTABLE AND NOT Protobuf_INCLUDE_DIR)
+ if(NOT Protobuf_FOUND AND NOT Protobuf_LIBRARY AND NOT Protobuf_PROTOC_EXECUTABLE AND NOT Protobuf_INCLUDE_DIR)
trezor_fatal_msg("Trezor: Could not find Protobuf")
- elseif(NOT Protobuf_LIBRARY OR NOT EXISTS "${Protobuf_LIBRARY}")
+ elseif(${CMAKE_CXX_STANDARD} LESS 17 AND ${Protobuf_VERSION} GREATER 21)
+ trezor_fatal_msg("Trezor: Unsupported Protobuf version ${Protobuf_VERSION} with C++ ${CMAKE_CXX_STANDARD}. Please, use Protobuf v21.")
+ elseif(NOT Protobuf_LIBRARY)
trezor_fatal_msg("Trezor: Protobuf library not found: ${Protobuf_LIBRARY}")
unset(Protobuf_FOUND)
elseif(NOT Protobuf_PROTOC_EXECUTABLE OR NOT EXISTS "${Protobuf_PROTOC_EXECUTABLE}")
@@ -150,9 +156,10 @@ if(Protobuf_FOUND AND USE_DEVICE_TREZOR AND TREZOR_PYTHON)
endif()
if(USE_DEVICE_TREZOR_PROTOBUF_TEST)
- # For now, Protobuf v21 is the maximum supported version as v23 requires C++17. TODO: Remove once we move to C++17
- if(${Protobuf_VERSION} GREATER 21)
- trezor_fatal_msg("Trezor: Unsupported Protobuf version ${Protobuf_VERSION}. Please, use Protobuf v21.")
+ if(PROTOBUF_LDFLAGS)
+ set(PROTOBUF_TRYCOMPILE_LINKER "${PROTOBUF_LDFLAGS}")
+ else()
+ set(PROTOBUF_TRYCOMPILE_LINKER "${Protobuf_LIBRARY}")
endif()
try_compile(Protobuf_COMPILE_TEST_PASSED
@@ -164,7 +171,7 @@ if(Protobuf_FOUND AND USE_DEVICE_TREZOR AND TREZOR_PYTHON)
CMAKE_EXE_LINKER_FLAGS ${CMAKE_TRY_COMPILE_LINKER_FLAGS}
"-DINCLUDE_DIRECTORIES=${Protobuf_INCLUDE_DIR};${CMAKE_BINARY_DIR}"
"-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
- LINK_LIBRARIES ${Protobuf_LIBRARY} ${CMAKE_TRY_COMPILE_LINK_LIBRARIES}
+ LINK_LIBRARIES "${PROTOBUF_TRYCOMPILE_LINKER}" ${CMAKE_TRY_COMPILE_LINK_LIBRARIES}
OUTPUT_VARIABLE OUTPUT
)
if(NOT Protobuf_COMPILE_TEST_PASSED)
diff --git a/cmake/FindLibUSB.cmake b/cmake/FindLibUSB.cmake
index f701b6398..647f3c656 100644
--- a/cmake/FindLibUSB.cmake
+++ b/cmake/FindLibUSB.cmake
@@ -119,10 +119,6 @@ if ( LibUSB_FOUND )
list(APPEND TEST_COMPILE_EXTRA_LIBRARIES ${LibUSB_LIBRARIES})
set(CMAKE_REQUIRED_LIBRARIES ${TEST_COMPILE_EXTRA_LIBRARIES})
- check_library_exists ( "${LibUSB_LIBRARIES}" usb_open "" LibUSB_FOUND )
- check_library_exists ( "${LibUSB_LIBRARIES}" libusb_get_device_list "" LibUSB_VERSION_1.0 )
- check_library_exists ( "${LibUSB_LIBRARIES}" libusb_get_port_numbers "" LibUSB_VERSION_1.0.16 )
-
if((STATIC AND UNIX AND NOT APPLE AND NOT FREEBSD) OR (DEPENDS AND CMAKE_SYSTEM_NAME STREQUAL "Linux") OR ANDROID)
find_library(LIBUDEV_LIBRARY udev)
if(LIBUDEV_LIBRARY)
@@ -132,6 +128,10 @@ if ( LibUSB_FOUND )
endif()
endif()
+ check_library_exists ( "${LibUSB_LIBRARIES}" usb_open "" LibUSB_FOUND )
+ check_library_exists ( "${LibUSB_LIBRARIES}" libusb_get_device_list "" LibUSB_VERSION_1.0 )
+ check_library_exists ( "${LibUSB_LIBRARIES}" libusb_get_port_numbers "" LibUSB_VERSION_1.0.16 )
+
# Library 1.0.16+ compilation test.
# The check_library_exists does not work well on Apple with shared libs.
if (APPLE OR LibUSB_VERSION_1.0.16 OR STATIC)
@@ -141,7 +141,7 @@ if ( LibUSB_FOUND )
CMAKE_FLAGS
"-DINCLUDE_DIRECTORIES=${LibUSB_INCLUDE_DIRS}"
"-DLINK_DIRECTORIES=${LibUSB_LIBRARIES}"
- LINK_LIBRARIES ${TEST_COMPILE_EXTRA_LIBRARIES}
+ LINK_LIBRARIES ${LibUSB_LIBRARIES} ${TEST_COMPILE_EXTRA_LIBRARIES}
OUTPUT_VARIABLE OUTPUT)
unset(TEST_COMPILE_EXTRA_LIBRARIES)
message(STATUS "LibUSB Compilation test: ${LibUSB_COMPILE_TEST_PASSED}")
diff --git a/contrib/depends/Makefile b/contrib/depends/Makefile
index a1c93ae00..f612dbffb 100644
--- a/contrib/depends/Makefile
+++ b/contrib/depends/Makefile
@@ -1,5 +1,9 @@
.NOTPARALLEL :
+# Pattern rule to print variables, e.g. make print-all_packages
+print-%: FORCE
+ @echo '$($*)'
+
SOURCES_PATH ?= $(BASEDIR)/sources
BASE_CACHE ?= $(BASEDIR)/built
FALLBACK_DOWNLOAD_PATH ?= https://downloads.getmonero.org/depends-sources
@@ -184,3 +188,4 @@ download: download-osx download-linux download-win download-freebsd download-and
$(foreach package,$(all_packages),$(eval $(call ext_add_stages,$(package))))
.PHONY: install cached download-one download-osx download-linux download-win download-freebsd download-android download check-packages check-sources
+.PHONY: FORCE
diff --git a/contrib/depends/packages/native_cctools.mk b/contrib/depends/packages/native_cctools.mk
index 0324f7acd..8c1ea4c62 100644
--- a/contrib/depends/packages/native_cctools.mk
+++ b/contrib/depends/packages/native_cctools.mk
@@ -6,6 +6,7 @@ $(package)_file_name=$(package)-$($(package)_version).tar.gz
$(package)_sha256_hash=70a7189418c2086d20c299c5d59250cf5940782c778892ccc899c66516ed240e
$(package)_build_subdir=cctools
$(package)_dependencies=native_clang native_libtapi
+$(package)_patches=no-build-date.patch
define $(package)_set_vars
$(package)_config_opts=--target=$(host) --disable-lto-support --with-libtapi=$(host_prefix)
@@ -14,6 +15,10 @@ $(package)_cc=$(host_prefix)/native/bin/clang
$(package)_cxx=$(host_prefix)/native/bin/clang++
endef
+define $(package)_preprocess_cmds
+ patch -p1 < $($(package)_patch_dir)/no-build-date.patch
+endef
+
define $(package)_config_cmds
$($(package)_autoconf)
endef
diff --git a/contrib/depends/packages/native_libtapi.mk b/contrib/depends/packages/native_libtapi.mk
index 56ee087cb..c5625501a 100644
--- a/contrib/depends/packages/native_libtapi.mk
+++ b/contrib/depends/packages/native_libtapi.mk
@@ -6,6 +6,11 @@ $(package)_file_name=$(package)-$($(package)_version).tar.gz
$(package)_sha256_hash=62e419c12d1c9fad67cc1cd523132bc00db050998337c734c15bc8d73cc02b61
$(package)_build_subdir=build
$(package)_dependencies=native_clang
+$(package)_patches=no_embed_git_rev.patch
+
+define $(package)_preprocess_cmds
+ patch -p1 -i $($(package)_patch_dir)/no_embed_git_rev.patch
+endef
define $(package)_config_cmds
echo -n $(build_prefix) > INSTALLPREFIX; \
diff --git a/contrib/depends/packages/native_protobuf.mk b/contrib/depends/packages/native_protobuf.mk
index 2dc11b23c..8d7649b67 100644
--- a/contrib/depends/packages/native_protobuf.mk
+++ b/contrib/depends/packages/native_protobuf.mk
@@ -1,4 +1,4 @@
-package=protobuf3
+package=native_protobuf
$(package)_version=21.12
$(package)_version_protobuf_cpp=3.21.12
$(package)_download_path=https://github.com/protocolbuffers/protobuf/releases/download/v$($(package)_version)/
@@ -16,13 +16,13 @@ define $(package)_config_cmds
endef
define $(package)_build_cmds
- $(MAKE) -C src
+ $(MAKE) -C src protoc
endef
define $(package)_stage_cmds
- $(MAKE) DESTDIR=$($(package)_staging_dir) -C src install
+ $(MAKE) DESTDIR=$($(package)_staging_dir) -C src install-binPROGRAMS install-nobase_dist_protoDATA
endef
define $(package)_postprocess_cmds
- rm lib/libprotoc.a
+ rm -rf lib/
endef
diff --git a/contrib/depends/packages/openssl.mk b/contrib/depends/packages/openssl.mk
index a157762c7..8c9727fa7 100644
--- a/contrib/depends/packages/openssl.mk
+++ b/contrib/depends/packages/openssl.mk
@@ -4,9 +4,12 @@ $(package)_download_path=https://www.openssl.org/source
$(package)_file_name=$(package)-$($(package)_version).tar.gz
$(package)_sha256_hash=88525753f79d3bec27d2fa7c66aa0b92b3aa9498dafd93d7cfa4b3780cdae313
+# The bundled ranlib in Android NDK 18b inserts timestamps by default.
+# To prevent reproducibility issues, we must enable [D]eterministic mode.
+
define $(package)_set_vars
-$(package)_config_env=AR="$($(package)_ar)" ARFLAGS=$($(package)_arflags) RANLIB="$($(package)_ranlib)" CC="$($(package)_cc)"
-$(package)_config_env_android=ANDROID_NDK_ROOT="$(host_prefix)/native" PATH="$(host_prefix)/native/bin" CC=clang AR=ar RANLIB=ranlib
+$(package)_config_env=AR="$($(package)_ar)" RANLIB="$($(package)_ranlib)" CC="$($(package)_cc)"
+$(package)_config_env_android=ANDROID_NDK_ROOT="$(host_prefix)/native" PATH="$(host_prefix)/native/bin" CC=clang AR=ar RANLIB="ranlib -D"
$(package)_build_env_android=ANDROID_NDK_ROOT="$(host_prefix)/native"
$(package)_config_opts=--prefix=$(host_prefix) --openssldir=$(host_prefix)/etc/openssl --libdir=$(host_prefix)/lib
$(package)_config_opts+=no-capieng
@@ -38,6 +41,7 @@ $(package)_config_opts_arm_android=--static android-arm
$(package)_config_opts_aarch64_android=--static android-arm64
$(package)_config_opts_aarch64_darwin=darwin64-arm64-cc
$(package)_config_opts_riscv64_linux=linux-generic64
+$(package)_config_opts_loongarch64_linux=linux-generic64
$(package)_config_opts_mipsel_linux=linux-generic32
$(package)_config_opts_mips_linux=linux-generic32
$(package)_config_opts_powerpc_linux=linux-generic32
@@ -52,7 +56,7 @@ define $(package)_preprocess_cmds
endef
define $(package)_config_cmds
- ./Configure $($(package)_config_opts)
+ ./Configure $($(package)_config_opts) ARFLAGS=$($(package)_arflags)
endef
define $(package)_build_cmds
diff --git a/contrib/depends/packages/protobuf.mk b/contrib/depends/packages/protobuf.mk
index 780357c90..9702506d0 100644
--- a/contrib/depends/packages/protobuf.mk
+++ b/contrib/depends/packages/protobuf.mk
@@ -21,12 +21,7 @@ define $(package)_build_cmds
endef
define $(package)_stage_cmds
- $(MAKE) DESTDIR=$($(package)_staging_dir) -C src install-libLTLIBRARIES install-nobase_includeHEADERS &&\
- $(MAKE) DESTDIR=$($(package)_staging_dir) install-pkgconfigDATA
+ $(MAKE) DESTDIR=$($(package)_staging_dir) -C src install-nobase_includeHEADERS &&\
+ $(MAKE) DESTDIR=$($(package)_staging_dir) install-pkgconfigDATA &&\
+ cp src/.libs/libprotobuf.a $($(package)_staging_prefix_dir)/lib/
endef
-
-define $(package)_postprocess_cmds
- rm lib/libprotoc.a &&\
- rm lib/*.la
-endef
-
diff --git a/contrib/depends/packages/unbound.mk b/contrib/depends/packages/unbound.mk
index d9ef0076a..254636bca 100644
--- a/contrib/depends/packages/unbound.mk
+++ b/contrib/depends/packages/unbound.mk
@@ -24,7 +24,7 @@ define $(package)_preprocess_cmds
endef
define $(package)_config_cmds
- $($(package)_autoconf) ac_cv_func_getentropy=no
+ $($(package)_autoconf) ac_cv_func_getentropy=no AR_FLAGS=$($(package)_arflags)
endef
define $(package)_build_cmds
diff --git a/contrib/depends/patches/native_cctools/no-build-date.patch b/contrib/depends/patches/native_cctools/no-build-date.patch
new file mode 100644
index 000000000..8b7d1e1f7
--- /dev/null
+++ b/contrib/depends/patches/native_cctools/no-build-date.patch
@@ -0,0 +1,12 @@
+diff --git a/cctools/ld64/src/ld/Options.cpp b/cctools/ld64/src/ld/Options.cpp
+index 3bb8324..033760d 100644
+--- a/cctools/ld64/src/ld/Options.cpp
++++ b/cctools/ld64/src/ld/Options.cpp
+@@ -4279,7 +4279,6 @@ void Options::buildSearchPaths(int argc, const char* argv[])
+ fVerbose = true;
+ extern const char ldVersionString[];
+ fprintf(stderr, "%s", ldVersionString);
+- fprintf(stderr, "BUILD " __TIME__ " " __DATE__"\n");
+ fprintf(stderr, "configured to support archs: %s\n", ALL_SUPPORTED_ARCHS);
+ // if only -v specified, exit cleanly
+ if ( argc == 2 ) {
diff --git a/contrib/depends/patches/native_libtapi/no_embed_git_rev.patch b/contrib/depends/patches/native_libtapi/no_embed_git_rev.patch
new file mode 100644
index 000000000..b898ccb43
--- /dev/null
+++ b/contrib/depends/patches/native_libtapi/no_embed_git_rev.patch
@@ -0,0 +1,31 @@
+diff --git a/src/llvm/CMakeLists.txt b/src/llvm/CMakeLists.txt
+index ab92717c8..4ad621ea3 100644
+--- a/src/llvm/CMakeLists.txt
++++ b/src/llvm/CMakeLists.txt
+@@ -752,9 +752,10 @@ set(LLVM_SRPM_USER_BINARY_SPECFILE ${CMAKE_CURRENT_SOURCE_DIR}/llvm.spec.in
+ set(LLVM_SRPM_BINARY_SPECFILE ${CMAKE_CURRENT_BINARY_DIR}/llvm.spec)
+ set(LLVM_SRPM_DIR "${CMAKE_CURRENT_BINARY_DIR}/srpm")
+
+-# SVN_REVISION and GIT_COMMIT get set by the call to add_version_info_from_vcs.
+-# DUMMY_VAR contains a version string which we don't care about.
+-add_version_info_from_vcs(DUMMY_VAR)
++# A call to add_version_info_from_vcs() was removed, leaving SVN_REVISION
++# and GIT_COMMIT unset. Accordingly, LLVM_RPM_SPEC_REVISION is left empty.
++# This variable appears to be unused. Since it may be used in a future
++# update of native_libtapi this change serves as a precautionairy measure.
+ if ( SVN_REVISION )
+ set(LLVM_RPM_SPEC_REVISION "r${SVN_REVISION}")
+ elseif ( GIT_COMMIT )
+diff --git a/src/llvm/cmake/modules/GenerateVersionFromCVS.cmake b/src/llvm/cmake/modules/GenerateVersionFromCVS.cmake
+index 6b1c71983..e16326ed6 100644
+--- a/src/llvm/cmake/modules/GenerateVersionFromCVS.cmake
++++ b/src/llvm/cmake/modules/GenerateVersionFromCVS.cmake
+@@ -24,7 +24,7 @@ include(VersionFromVCS)
+ set(ENV{TERM} "dumb")
+
+ function(append_info name path)
+- add_version_info_from_vcs(REVISION ${path})
++ set(REVISION "git-0000000")
+ string(STRIP "${REVISION}" REVISION)
+ file(APPEND "${HEADER_FILE}.txt"
+ "#define ${name} \"${REVISION}\"\n")
diff --git a/contrib/depends/toolchain.cmake.in b/contrib/depends/toolchain.cmake.in
index fc502c596..50eaaa593 100644
--- a/contrib/depends/toolchain.cmake.in
+++ b/contrib/depends/toolchain.cmake.in
@@ -147,6 +147,10 @@ if(ARCHITECTURE STREQUAL "riscv64")
set(ARCH_ID "riscv64")
set(ARCH "rv64gc")
endif()
+if(ARCHITECTURE STREQUAL "loongarch64")
+ set(ARCH_ID "loongarch64")
+ set(ARCH "loongarch")
+endif()
if(ARCHITECTURE STREQUAL "i686")
SET(ARCH_ID "i386")
diff --git a/contrib/epee/README.md b/contrib/epee/README.md
index 8157d3e56..2937c1264 100644
--- a/contrib/epee/README.md
+++ b/contrib/epee/README.md
@@ -1 +1 @@
-epee - is a small library of helpers, wrappers, tools and and so on, used to make my life easier.
+epee - is a small library of helpers, wrappers, tools and so on, used to make my life easier.
diff --git a/contrib/epee/include/storages/portable_storage_val_converters.h b/contrib/epee/include/storages/portable_storage_val_converters.h
index 96b0c024c..5eb9acffd 100644
--- a/contrib/epee/include/storages/portable_storage_val_converters.h
+++ b/contrib/epee/include/storages/portable_storage_val_converters.h
@@ -37,6 +37,7 @@
#include "misc_log_ex.h"
#include <boost/lexical_cast.hpp>
+#include <boost/numeric/conversion/bounds.hpp>
#include <typeinfo>
#include <iomanip>
diff --git a/contrib/epee/include/string_tools.h b/contrib/epee/include/string_tools.h
index 7fcd02726..887f4aa40 100644
--- a/contrib/epee/include/string_tools.h
+++ b/contrib/epee/include/string_tools.h
@@ -31,6 +31,7 @@
#include "mlocker.h"
#include <boost/utility/string_ref.hpp>
+#include <boost/algorithm/string.hpp>
#include <sstream>
#include <string>
#include <cstdint>
@@ -69,23 +70,19 @@ namespace string_tools
#ifdef _WIN32
std::string get_current_module_path();
#endif
- bool set_module_name_and_folder(const std::string& path_to_process_);
- bool trim_left(std::string& str);
- bool trim_right(std::string& str);
+ void set_module_name_and_folder(const std::string& path_to_process_);
+ void trim_left(std::string& str);
+ void trim_right(std::string& str);
//----------------------------------------------------------------------------
inline std::string& trim(std::string& str)
{
- trim_left(str);
- trim_right(str);
+ boost::trim(str);
return str;
}
//----------------------------------------------------------------------------
- inline std::string trim(const std::string& str_)
+ inline std::string trim(const std::string& str)
{
- std::string str = str_;
- trim_left(str);
- trim_right(str);
- return str;
+ return boost::trim_copy(str);
}
std::string pad_string(std::string s, size_t n, char c = ' ', bool prepend = false);
diff --git a/contrib/epee/src/readline_buffer.cpp b/contrib/epee/src/readline_buffer.cpp
index ac68d1fdb..cefde158c 100644
--- a/contrib/epee/src/readline_buffer.cpp
+++ b/contrib/epee/src/readline_buffer.cpp
@@ -1,4 +1,5 @@
#include "readline_buffer.h"
+#include "string_tools.h"
#include <readline/readline.h>
#include <readline/history.h>
#include <iostream>
@@ -173,7 +174,7 @@ static void handle_line(char* line)
line_stat = rdln::full;
the_line = line;
std::string test_line = line;
- boost::trim_right(test_line);
+ epee::string_tools::trim_right(test_line);
if(!test_line.empty())
{
if (!same_as_last_line(test_line))
diff --git a/contrib/epee/src/string_tools.cpp b/contrib/epee/src/string_tools.cpp
index 3abb83c74..d8580c216 100644
--- a/contrib/epee/src/string_tools.cpp
+++ b/contrib/epee/src/string_tools.cpp
@@ -38,9 +38,12 @@
#include <cstdlib>
#include <string>
#include <type_traits>
+#include <system_error>
#include <boost/lexical_cast.hpp>
+#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/utility/string_ref.hpp>
+#include <boost/filesystem.hpp>
#include "misc_log_ex.h"
#include "storages/parserse_base_utils.h"
#include "hex.h"
@@ -147,46 +150,33 @@ namespace string_tools
return pname;
}
#endif
-
- bool set_module_name_and_folder(const std::string& path_to_process_)
- {
- std::string path_to_process = path_to_process_;
+
+ void set_module_name_and_folder(const std::string& path_to_process_)
+ {
+ boost::filesystem::path path_to_process = path_to_process_;
+
#ifdef _WIN32
path_to_process = get_current_module_path();
#endif
- std::string::size_type a = path_to_process.rfind( '\\' );
- if(a == std::string::npos )
- {
- a = path_to_process.rfind( '/' );
- }
- if ( a != std::string::npos )
- {
- get_current_module_name() = path_to_process.substr(a+1, path_to_process.size());
- get_current_module_folder() = path_to_process.substr(0, a);
- return true;
- }else
- return false;
- }
+ get_current_module_name() = path_to_process.filename().string();
+ get_current_module_folder() = path_to_process.parent_path().string();
+ }
//----------------------------------------------------------------------------
- bool trim_left(std::string& str)
- {
- for(std::string::iterator it = str.begin(); it!= str.end() && isspace(static_cast<unsigned char>(*it));)
- str.erase(str.begin());
-
- return true;
- }
- //----------------------------------------------------------------------------
- bool trim_right(std::string& str)
- {
+ void trim_left(std::string& str)
+ {
+ boost::trim_left(str);
+ return;
+ }
- for(std::string::reverse_iterator it = str.rbegin(); it!= str.rend() && isspace(static_cast<unsigned char>(*it));)
- str.erase( --((it++).base()));
+ //----------------------------------------------------------------------------
+ void trim_right(std::string& str)
+ {
+ boost::trim_right(str);
+ return;
+ }
- return true;
- }
- //----------------------------------------------------------------------------
std::string pad_string(std::string s, size_t n, char c, bool prepend)
{
if (s.size() < n)
@@ -199,28 +189,17 @@ namespace string_tools
return s;
}
- std::string get_extension(const std::string& str)
- {
- std::string res;
- std::string::size_type pos = str.rfind('.');
- if(std::string::npos == pos)
- return res;
-
- res = str.substr(pos+1, str.size()-pos);
- return res;
- }
+ std::string get_extension(const std::string& str)
+ {
+ return boost::filesystem::path(str).extension().string();
+ }
+
//----------------------------------------------------------------------------
- std::string cut_off_extension(const std::string& str)
- {
- std::string res;
- std::string::size_type pos = str.rfind('.');
- if(std::string::npos == pos)
- return str;
+ std::string cut_off_extension(const std::string& str)
+ {
+ return boost::filesystem::path(str).stem().string();
+ }
- res = str.substr(0, pos);
- return res;
- }
- //----------------------------------------------------------------------------
#ifdef _WIN32
std::wstring utf8_to_utf16(const std::string& str)
{
diff --git a/contrib/valgrind/monero.supp b/contrib/valgrind/monero.supp
index 015b05a1c..8df2cc120 100644
--- a/contrib/valgrind/monero.supp
+++ b/contrib/valgrind/monero.supp
@@ -26,3 +26,34 @@
fun:_ZN2el4base7Storage7getELPPEv
...
}
+
+{
+ in boost multiprecision, we don't get a pointer to the actual code causing it but if so it's only in the test itself anyway
+ Memcheck:Overlap
+ fun:__memcpy_chk
+ fun:_ZL6MKHASHmm
+ fun:_ZN26difficulty_check_hash_Test8TestBodyEv
+ fun:_ZN7testing8internal38HandleSehExceptionsInMethodIfSupportedINS_4TestEvEET0_PT_MS4_FS3_vEPKc
+ fun:_ZN7testing8internal35HandleExceptionsInMethodIfSupportedINS_4TestEvEET0_PT_MS4_FS3_vEPKc
+ fun:_ZN7testing4Test3RunEv
+ fun:_ZN7testing8TestInfo3RunEv
+ fun:_ZN7testing8TestCase3RunEv
+ fun:_ZN7testing8internal12UnitTestImpl11RunAllTestsEv
+ fun:_ZN7testing8internal38HandleSehExceptionsInMethodIfSupportedINS0_12UnitTestImplEbEET0_PT_MS4_FS3_vEPKc
+ fun:_ZN7testing8internal35HandleExceptionsInMethodIfSupportedINS0_12UnitTestImplEbEET0_PT_MS4_FS3_vEPKc
+ fun:_ZN7testing8UnitTest3RunEv
+}
+
+{
+ valgrind seems to be confusing memmove with memcpy
+ Memcheck:Overlap
+ fun:__memcpy_chk
+ fun:memmove
+ fun:left_shift_byte<boost::multiprecision::backends::cpp_int_backend<512, 512, (boost::multiprecision::cpp_integer_type)0, (boost::multiprecision::cpp_int_check_type)0, void> >
+ fun:eval_left_shift<512, 512, (boost::multiprecision::cpp_integer_type)0, (boost::multiprecision::cpp_int_check_type)0, void>
+ fun:eval_left_shift<512, 512, (boost::multiprecision::cpp_integer_type)0, (boost::multiprecision::cpp_int_check_type)0, void>
+ fun:operator<<=<int>
+ fun:_ZN10cryptonote14check_hash_128ERKN6crypto4hashEN5boost14multiprecision6numberINS5_8backends15cpp_int_backendILj128ELj128ELNS5_16cpp_integer_typeE0ELNS5_18cpp_int_check_typeE0EvEELNS5_26expression_template_optionE0EEE
+ fun:_ZN10cryptonote10check_hashERKN6crypto4hashEN5boost14multiprecision6numberINS5_8backends15cpp_int_backendILj128ELj128ELNS5_16cpp_integer_typeE0ELNS5_18cpp_int_check_typeE0EvEELNS5_26expression_template_optionE0EEE
+ fun:_ZN26difficulty_check_hash_Test8TestBodyEv
+}
diff --git a/src/blocks/checkpoints.dat b/src/blocks/checkpoints.dat
index 2ed1d630f..2dc9ce3b3 100644
--- a/src/blocks/checkpoints.dat
+++ b/src/blocks/checkpoints.dat
Binary files differ
diff --git a/src/checkpoints/checkpoints.cpp b/src/checkpoints/checkpoints.cpp
index 70ae58cf0..63ec6ede9 100644
--- a/src/checkpoints/checkpoints.cpp
+++ b/src/checkpoints/checkpoints.cpp
@@ -240,6 +240,16 @@ namespace cryptonote
ADD_CHECKPOINT2(2092500, "c4e00820c9c7989b49153d5e90ae095a18a11d990e82fcc3be54e6ed785472b5", "0xb4e585a31369cb");
ADD_CHECKPOINT2(2182500, "0d22b5f81982eff21d094af9e821dc2007e6342069e3b1a37b15d97646353124", "0xead4a874083492");
ADD_CHECKPOINT2(2661600, "41c9060e8426012238e8a26da26fcb90797436896cc70886a894c2c560bcccf2", "0x2e0d87526ff161f");
+ ADD_CHECKPOINT2(2677000, "1b9fee6246eeb176bd17d637bf252e9af54a4218675f01b4449cc0901867f9eb", "0x2f165bc1a5163ba");
+ ADD_CHECKPOINT2(2706000, "d8eb144c5e1fe6b329ecc900ec95e7792fccff84175fb23a25ed59d7299a511c", "0x310f7d89372f705");
+ ADD_CHECKPOINT2(2720000, "b19fb41dff15bd1016afbee9f8469f05aab715c9e5d1b974466a11fd58ecbb86", "0x3216b5851ddbb61");
+ ADD_CHECKPOINT2(2817000, "39726d19ccaac01d150bec827b877ffae710b516bd633503662036ef4422e577", "0x3900669561954c1");
+ ADD_CHECKPOINT2(2844000, "28fc7b446dfef5b469f5778eb72ddf32a307a5f5a9823d1c394e772349e05d40", "0x3af384ec0e97d12");
+ ADD_CHECKPOINT2(2851000, "5bf0e47fc782263191a33f63a67db6c711781dc2a3c442e17ed901ec401be5c9", "0x3b6cd8a8ed610e8");
+ ADD_CHECKPOINT2(2971000, "3d4cac5ac515eeabd18769ab943af85f36db51d28720def0d0e6effc2c8f5ce3", "0x436e532738b8b5b");
+ ADD_CHECKPOINT2(2985000, "08f5e6b7301c1b6ed88268a28f8677a06e8ff943b3f9e48d3080f71f9c134bfb", "0x444b7b42a633c96");
+ ADD_CHECKPOINT2(3088000, "bddf8ca09110d33d6d497f13a113630c2b6af1c84d4f3a6f35cb1446f2604ade", "0x4aed3615c2f8c3e");
+ ADD_CHECKPOINT2(3102800, "083f4a34f9490403b564286e7f13fd1ed45c52c86fa47195f151594e5bc87504", "0x4bbed52d4da5dfb");
return true;
}
diff --git a/src/common/timings.cc b/src/common/timings.cc
index 612ac2cc6..aa719fa5e 100644
--- a/src/common/timings.cc
+++ b/src/common/timings.cc
@@ -12,10 +12,11 @@ TimingsDatabase::TimingsDatabase()
{
}
-TimingsDatabase::TimingsDatabase(const std::string &filename):
+TimingsDatabase::TimingsDatabase(const std::string &filename, const bool load_previous /*=false*/):
filename(filename)
{
- load();
+ if (load_previous)
+ load();
}
TimingsDatabase::~TimingsDatabase()
@@ -73,53 +74,96 @@ bool TimingsDatabase::load()
{
i.deciles.push_back(atoi(fields[idx++].c_str()));
}
- instances.insert(std::make_pair(name, i));
+ instances.emplace_back(name, i);
}
fclose(f);
return true;
}
-bool TimingsDatabase::save()
+bool TimingsDatabase::save(const bool save_current_time /*=true*/)
{
- if (filename.empty())
+ if (filename.empty() || instances.empty())
return true;
- FILE *f = fopen(filename.c_str(), "w");
+ FILE *f = fopen(filename.c_str(), "a"); // append
if (!f)
{
MERROR("Failed to write to file " << filename << ": " << strerror(errno));
return false;
}
- for (const auto &i: instances)
+
+ if (save_current_time)
{
- fprintf(f, "%s", i.first.c_str());
- fprintf(f, "\t%lu", (unsigned long)i.second.t);
- fprintf(f, " %zu", i.second.npoints);
- fprintf(f, " %f", i.second.min);
- fprintf(f, " %f", i.second.max);
- fprintf(f, " %f", i.second.mean);
- fprintf(f, " %f", i.second.median);
- fprintf(f, " %f", i.second.stddev);
- fprintf(f, " %f", i.second.npskew);
- for (uint64_t v: i.second.deciles)
- fprintf(f, " %lu", (unsigned long)v);
+ // save current time in readable format (UTC)
+ std::time_t sys_time{std::time(nullptr)};
+ std::tm *utc_time = std::gmtime(&sys_time); //GMT is equivalent to UTC
+
+ // format: year-month-day : hour:minute:second
+ std::string current_time{};
+ if (utc_time && sys_time != (std::time_t)(-1))
+ {
+ char timeString[22]; //length = std::size("yyyy-mm-dd : hh:mm:ss") (constexpr std::size is C++17)
+ std::strftime(timeString, 22, "%F : %T", utc_time);
+ current_time += timeString;
+ }
+ else
+ {
+ current_time += "TIME_ERROR_";
+ }
+ fputc('\n', f); // add an extra line before each 'print time'
+ fprintf(f, "%s", current_time.c_str());
fputc('\n', f);
}
+
+ for (const auto &i: instances)
+ {
+ fprintf(f, "%s,", i.first.c_str());
+
+ if (i.second.npoints > 0)
+ {
+ fprintf(f, "%lu,", (unsigned long)i.second.t);
+ fprintf(f, "%zu,", i.second.npoints);
+ fprintf(f, "%f,", i.second.min);
+ fprintf(f, "%f,", i.second.max);
+ fprintf(f, "%f,", i.second.mean);
+ fprintf(f, "%f,", i.second.median);
+ fprintf(f, "%f,", i.second.stddev);
+ fprintf(f, "%f,", i.second.npskew);
+ for (uint64_t v: i.second.deciles)
+ fprintf(f, "%lu,", (unsigned long)v);
+
+ // note: only add a new line if there are points; assume that 'no points' means i.first is a message meant to be
+ // prepended to the next save operation
+ fputc('\n', f);
+ }
+ }
fclose(f);
+
+ // after saving, clear so next save does not append the same stuff over again
+ instances.clear();
+
return true;
}
-std::vector<TimingsDatabase::instance> TimingsDatabase::get(const char *name) const
+const TimingsDatabase::instance* TimingsDatabase::get_most_recent(const char *name) const
{
- std::vector<instance> ret;
- auto range = instances.equal_range(name);
- for (auto i = range.first; i != range.second; ++i)
- ret.push_back(i->second);
- std::sort(ret.begin(), ret.end(), [](const instance &e0, const instance &e1){ return e0.t < e1.t; });
- return ret;
+ time_t latest_time = 0;
+ const TimingsDatabase::instance *instance_ptr = nullptr;
+
+ for (const auto &i: instances)
+ {
+ if (i.first != name)
+ continue;
+ if (i.second.t < latest_time)
+ continue;
+
+ latest_time = i.second.t;
+ instance_ptr = &i.second;
+ }
+ return instance_ptr;
}
void TimingsDatabase::add(const char *name, const instance &i)
{
- instances.insert(std::make_pair(name, i));
+ instances.emplace_back(name, i);
}
diff --git a/src/common/timings.h b/src/common/timings.h
index fb905611f..6e7ff5659 100644
--- a/src/common/timings.h
+++ b/src/common/timings.h
@@ -2,8 +2,8 @@
#include <stdint.h>
#include <string>
+#include <utility>
#include <vector>
-#include <map>
class TimingsDatabase
{
@@ -18,17 +18,17 @@ public:
public:
TimingsDatabase();
- TimingsDatabase(const std::string &filename);
+ TimingsDatabase(const std::string &filename, const bool load_previous = false);
~TimingsDatabase();
- std::vector<instance> get(const char *name) const;
+ const instance* get_most_recent(const char *name) const;
void add(const char *name, const instance &data);
+ bool save(const bool print_current_time = true);
private:
bool load();
- bool save();
private:
std::string filename;
- std::multimap<std::string, instance> instances;
+ std::vector<std::pair<std::string, instance>> instances;
};
diff --git a/src/common/util.cpp b/src/common/util.cpp
index b4f3360ef..05ddfc359 100644
--- a/src/common/util.cpp
+++ b/src/common/util.cpp
@@ -114,6 +114,24 @@ static int flock_exnb(int fd)
namespace tools
{
+
+ void copy_file(const std::string& from, const std::string& to)
+ {
+ using boost::filesystem::path;
+ #if BOOST_VERSION < 107400
+ // Remove this preprocessor if/else when we are bumping the boost version.
+ boost::filesystem::copy_file(
+ path(from),
+ path(to),
+ boost::filesystem::copy_option::overwrite_if_exists);
+ #else
+ boost::filesystem::copy_file(
+ path(from),
+ path(to),
+ boost::filesystem::copy_options::overwrite_existing);
+ #endif
+ }
+
std::function<void(int)> signal_handler::m_handler;
private_file::private_file() noexcept : m_handle(), m_filename() {}
@@ -121,7 +139,7 @@ namespace tools
private_file::private_file(std::FILE* handle, std::string&& filename) noexcept
: m_handle(handle), m_filename(std::move(filename)) {}
- private_file private_file::create(std::string name)
+ private_file private_file::create(std::string name, uint32_t extra_flags)
{
#ifdef WIN32
struct close_handle
@@ -174,7 +192,7 @@ namespace tools
name.c_str(),
GENERIC_WRITE, FILE_SHARE_READ,
std::addressof(attributes),
- CREATE_NEW, (FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE),
+ CREATE_NEW, (FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE | extra_flags),
nullptr
)
};
@@ -193,7 +211,7 @@ namespace tools
}
}
#else
- const int fdr = open(name.c_str(), (O_RDONLY | O_CREAT), S_IRUSR);
+ const int fdr = open(name.c_str(), (O_RDONLY | O_CREAT | extra_flags), S_IRUSR);
if (0 <= fdr)
{
struct stat rstats = {};
@@ -224,6 +242,23 @@ namespace tools
return {};
}
+ private_file private_file::drop_and_recreate(std::string filename)
+ {
+ if (epee::file_io_utils::is_file_exist(filename)) {
+ boost::system::error_code ec{};
+ boost::filesystem::remove(filename, ec);
+ if (ec) {
+ MERROR("Failed to remove " << filename << ": " << ec.message());
+ return {};
+ }
+ }
+#ifdef WIN32
+ return create(filename);
+#else
+ return create(filename, O_EXCL);
+#endif
+ }
+
private_file::~private_file() noexcept
{
try
diff --git a/src/common/util.h b/src/common/util.h
index 05748e020..ef591fc12 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -67,6 +67,8 @@ namespace tools
}
};
+ void copy_file(const std::string& from, const std::string& to);
+
//! A file restricted to process owner AND process. Deletes file on destruction.
class private_file {
std::unique_ptr<std::FILE, close_file> m_handle;
@@ -80,7 +82,11 @@ namespace tools
/*! \return File only readable by owner and only used by this process
OR `private_file{}` on error. */
- static private_file create(std::string filename);
+ static private_file create(std::string filename, uint32_t extra_flags = 0);
+
+ /*! \return Drop and create file only readable by owner and only used
+ by this process OR `private_file{}` on error. */
+ static private_file drop_and_recreate(std::string filename);
private_file(private_file&&) = default;
private_file& operator=(private_file&&) = default;
diff --git a/src/crypto/CMakeLists.txt b/src/crypto/CMakeLists.txt
index 9ac376780..2559c754e 100644
--- a/src/crypto/CMakeLists.txt
+++ b/src/crypto/CMakeLists.txt
@@ -29,6 +29,7 @@
set(crypto_sources
aesb.c
blake256.c
+ blake2b.c
chacha.c
crypto-ops-data.c
crypto-ops.c
diff --git a/src/crypto/blake2b.c b/src/crypto/blake2b.c
new file mode 100644
index 000000000..7e8be7890
--- /dev/null
+++ b/src/crypto/blake2b.c
@@ -0,0 +1,563 @@
+/*
+Copyright (c) 2018-2019, tevador <tevador@gmail.com>
+
+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 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.
+*/
+
+/* Original code from Argon2 reference source code package used under CC0 Licence
+ * https://github.com/P-H-C/phc-winner-argon2
+ * Copyright 2015
+ * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves
+*/
+
+#include "blake2b.h"
+
+#include "memwipe.h"
+
+#include <stdint.h>
+#include <string.h>
+#include <stdio.h>
+
+/// BEGIN: endian.h
+
+#if defined(_MSC_VER)
+#define FORCE_INLINE __inline
+#elif defined(__GNUC__) || defined(__clang__)
+#define FORCE_INLINE __inline__
+#else
+#define FORCE_INLINE
+#endif
+
+ /* Argon2 Team - Begin Code */
+ /*
+ Not an exhaustive list, but should cover the majority of modern platforms
+ Additionally, the code will always be correct---this is only a performance
+ tweak.
+ */
+#if (defined(__BYTE_ORDER__) && \
+ (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) || \
+ defined(__LITTLE_ENDIAN__) || defined(__ARMEL__) || defined(__MIPSEL__) || \
+ defined(__AARCH64EL__) || defined(__amd64__) || defined(__i386__) || \
+ defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || \
+ defined(_M_ARM)
+#define NATIVE_LITTLE_ENDIAN
+#endif
+ /* Argon2 Team - End Code */
+
+static FORCE_INLINE uint32_t load32(const void *src) {
+#if defined(NATIVE_LITTLE_ENDIAN)
+ uint32_t w;
+ memcpy(&w, src, sizeof w);
+ return w;
+#else
+ const uint8_t *p = (const uint8_t *)src;
+ uint32_t w = *p++;
+ w |= (uint32_t)(*p++) << 8;
+ w |= (uint32_t)(*p++) << 16;
+ w |= (uint32_t)(*p++) << 24;
+ return w;
+#endif
+}
+
+static FORCE_INLINE uint64_t load64_native(const void *src) {
+ uint64_t w;
+ memcpy(&w, src, sizeof w);
+ return w;
+}
+
+static FORCE_INLINE uint64_t load64(const void *src) {
+#if defined(NATIVE_LITTLE_ENDIAN)
+ return load64_native(src);
+#else
+ const uint8_t *p = (const uint8_t *)src;
+ uint64_t w = *p++;
+ w |= (uint64_t)(*p++) << 8;
+ w |= (uint64_t)(*p++) << 16;
+ w |= (uint64_t)(*p++) << 24;
+ w |= (uint64_t)(*p++) << 32;
+ w |= (uint64_t)(*p++) << 40;
+ w |= (uint64_t)(*p++) << 48;
+ w |= (uint64_t)(*p++) << 56;
+ return w;
+#endif
+}
+
+static FORCE_INLINE void store32(void *dst, uint32_t w) {
+#if defined(NATIVE_LITTLE_ENDIAN)
+ memcpy(dst, &w, sizeof w);
+#else
+ uint8_t *p = (uint8_t *)dst;
+ *p++ = (uint8_t)w;
+ w >>= 8;
+ *p++ = (uint8_t)w;
+ w >>= 8;
+ *p++ = (uint8_t)w;
+ w >>= 8;
+ *p++ = (uint8_t)w;
+#endif
+}
+
+static FORCE_INLINE void store64_native(void *dst, uint64_t w) {
+ memcpy(dst, &w, sizeof w);
+}
+
+static FORCE_INLINE void store64(void *dst, uint64_t w) {
+#if defined(NATIVE_LITTLE_ENDIAN)
+ store64_native(dst, w);
+#else
+ uint8_t *p = (uint8_t *)dst;
+ *p++ = (uint8_t)w;
+ w >>= 8;
+ *p++ = (uint8_t)w;
+ w >>= 8;
+ *p++ = (uint8_t)w;
+ w >>= 8;
+ *p++ = (uint8_t)w;
+ w >>= 8;
+ *p++ = (uint8_t)w;
+ w >>= 8;
+ *p++ = (uint8_t)w;
+ w >>= 8;
+ *p++ = (uint8_t)w;
+ w >>= 8;
+ *p++ = (uint8_t)w;
+#endif
+}
+
+/// END: endian.h
+
+/// BEGIN: blake2-impl.h
+
+static FORCE_INLINE uint64_t load48(const void *src) {
+ const uint8_t *p = (const uint8_t *)src;
+ uint64_t w = *p++;
+ w |= (uint64_t)(*p++) << 8;
+ w |= (uint64_t)(*p++) << 16;
+ w |= (uint64_t)(*p++) << 24;
+ w |= (uint64_t)(*p++) << 32;
+ w |= (uint64_t)(*p++) << 40;
+ return w;
+}
+
+static FORCE_INLINE void store48(void *dst, uint64_t w) {
+ uint8_t *p = (uint8_t *)dst;
+ *p++ = (uint8_t)w;
+ w >>= 8;
+ *p++ = (uint8_t)w;
+ w >>= 8;
+ *p++ = (uint8_t)w;
+ w >>= 8;
+ *p++ = (uint8_t)w;
+ w >>= 8;
+ *p++ = (uint8_t)w;
+ w >>= 8;
+ *p++ = (uint8_t)w;
+}
+
+static FORCE_INLINE uint32_t rotr32(const uint32_t w, const unsigned c) {
+ return (w >> c) | (w << (32 - c));
+}
+
+static FORCE_INLINE uint64_t rotr64(const uint64_t w, const unsigned c) {
+ return (w >> c) | (w << (64 - c));
+}
+
+/// END: blake2-impl.h
+
+void clear_internal_memory(void *mem, const size_t length) {
+ memwipe(mem, length);
+}
+
+/// BEGIN: blake2b.c
+
+static const uint64_t blake2b_IV[8] = {
+ UINT64_C(0x6a09e667f3bcc908), UINT64_C(0xbb67ae8584caa73b),
+ UINT64_C(0x3c6ef372fe94f82b), UINT64_C(0xa54ff53a5f1d36f1),
+ UINT64_C(0x510e527fade682d1), UINT64_C(0x9b05688c2b3e6c1f),
+ UINT64_C(0x1f83d9abfb41bd6b), UINT64_C(0x5be0cd19137e2179) };
+
+static const unsigned int blake2b_sigma[12][16] = {
+ {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
+ {14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3},
+ {11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4},
+ {7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8},
+ {9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13},
+ {2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9},
+ {12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11},
+ {13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10},
+ {6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5},
+ {10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0},
+ {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15},
+ {14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3},
+};
+
+static FORCE_INLINE void blake2b_set_lastnode(blake2b_state *S) {
+ S->f[1] = (uint64_t)-1;
+}
+
+static FORCE_INLINE void blake2b_set_lastblock(blake2b_state *S) {
+ if (S->last_node) {
+ blake2b_set_lastnode(S);
+ }
+ S->f[0] = (uint64_t)-1;
+}
+
+static FORCE_INLINE void blake2b_increment_counter(blake2b_state *S,
+ uint64_t inc) {
+ S->t[0] += inc;
+ S->t[1] += (S->t[0] < inc);
+}
+
+static FORCE_INLINE void blake2b_invalidate_state(blake2b_state *S) {
+ clear_internal_memory(S, sizeof(*S)); /* wipe */
+ blake2b_set_lastblock(S); /* invalidate for further use */
+}
+
+static FORCE_INLINE void blake2b_init0(blake2b_state *S) {
+ memset(S, 0, sizeof(*S));
+ memcpy(S->h, blake2b_IV, sizeof(S->h));
+}
+
+int blake2b_init_param(blake2b_state *S, const blake2b_param *P) {
+ const unsigned char *p = (const unsigned char *)P;
+ unsigned int i;
+
+ if (NULL == P || NULL == S) {
+ return -1;
+ }
+
+ blake2b_init0(S);
+ /* IV XOR Parameter Block */
+ for (i = 0; i < 8; ++i) {
+ S->h[i] ^= load64(&p[i * sizeof(S->h[i])]);
+ }
+ S->outlen = P->digest_length;
+ return 0;
+}
+
+/* Sequential blake2b initialization */
+int blake2b_init(blake2b_state *S, size_t outlen) {
+ blake2b_param P;
+
+ if (S == NULL) {
+ return -1;
+ }
+
+ if ((outlen == 0) || (outlen > BLAKE2B_OUTBYTES)) {
+ blake2b_invalidate_state(S);
+ return -1;
+ }
+
+ /* Setup Parameter Block for unkeyed BLAKE2 */
+ P.digest_length = (uint8_t)outlen;
+ P.key_length = 0;
+ P.fanout = 1;
+ P.depth = 1;
+ P.leaf_length = 0;
+ P.node_offset = 0;
+ P.node_depth = 0;
+ P.inner_length = 0;
+ memset(P.reserved, 0, sizeof(P.reserved));
+ memset(P.salt, 0, sizeof(P.salt));
+ memset(P.personal, 0, sizeof(P.personal));
+
+ return blake2b_init_param(S, &P);
+}
+
+int blake2b_init_key(blake2b_state *S, size_t outlen, const void *key, size_t keylen) {
+ blake2b_param P;
+
+ if (S == NULL) {
+ return -1;
+ }
+
+ if ((outlen == 0) || (outlen > BLAKE2B_OUTBYTES)) {
+ blake2b_invalidate_state(S);
+ return -1;
+ }
+
+ if ((key == 0) || (keylen == 0) || (keylen > BLAKE2B_KEYBYTES)) {
+ blake2b_invalidate_state(S);
+ return -1;
+ }
+
+ /* Setup Parameter Block for keyed BLAKE2 */
+ P.digest_length = (uint8_t)outlen;
+ P.key_length = (uint8_t)keylen;
+ P.fanout = 1;
+ P.depth = 1;
+ P.leaf_length = 0;
+ P.node_offset = 0;
+ P.node_depth = 0;
+ P.inner_length = 0;
+ memset(P.reserved, 0, sizeof(P.reserved));
+ memset(P.salt, 0, sizeof(P.salt));
+ memset(P.personal, 0, sizeof(P.personal));
+
+ if (blake2b_init_param(S, &P) < 0) {
+ blake2b_invalidate_state(S);
+ return -1;
+ }
+
+ {
+ uint8_t block[BLAKE2B_BLOCKBYTES];
+ memset(block, 0, BLAKE2B_BLOCKBYTES);
+ memcpy(block, key, keylen);
+ blake2b_update(S, block, BLAKE2B_BLOCKBYTES);
+ /* Burn the key from stack */
+ clear_internal_memory(block, BLAKE2B_BLOCKBYTES);
+ }
+ return 0;
+}
+
+static void blake2b_compress(blake2b_state *S, const uint8_t *block) {
+ uint64_t m[16];
+ uint64_t v[16];
+ unsigned int i, r;
+
+ for (i = 0; i < 16; ++i) {
+ m[i] = load64(block + i * sizeof(m[i]));
+ }
+
+ for (i = 0; i < 8; ++i) {
+ v[i] = S->h[i];
+ }
+
+ v[8] = blake2b_IV[0];
+ v[9] = blake2b_IV[1];
+ v[10] = blake2b_IV[2];
+ v[11] = blake2b_IV[3];
+ v[12] = blake2b_IV[4] ^ S->t[0];
+ v[13] = blake2b_IV[5] ^ S->t[1];
+ v[14] = blake2b_IV[6] ^ S->f[0];
+ v[15] = blake2b_IV[7] ^ S->f[1];
+
+#define G(r, i, a, b, c, d) \
+ do { \
+ a = a + b + m[blake2b_sigma[r][2 * i + 0]]; \
+ d = rotr64(d ^ a, 32); \
+ c = c + d; \
+ b = rotr64(b ^ c, 24); \
+ a = a + b + m[blake2b_sigma[r][2 * i + 1]]; \
+ d = rotr64(d ^ a, 16); \
+ c = c + d; \
+ b = rotr64(b ^ c, 63); \
+ } while ((void)0, 0)
+
+#define ROUND(r) \
+ do { \
+ G(r, 0, v[0], v[4], v[8], v[12]); \
+ G(r, 1, v[1], v[5], v[9], v[13]); \
+ G(r, 2, v[2], v[6], v[10], v[14]); \
+ G(r, 3, v[3], v[7], v[11], v[15]); \
+ G(r, 4, v[0], v[5], v[10], v[15]); \
+ G(r, 5, v[1], v[6], v[11], v[12]); \
+ G(r, 6, v[2], v[7], v[8], v[13]); \
+ G(r, 7, v[3], v[4], v[9], v[14]); \
+ } while ((void)0, 0)
+
+ for (r = 0; r < 12; ++r) {
+ ROUND(r);
+ }
+
+ for (i = 0; i < 8; ++i) {
+ S->h[i] = S->h[i] ^ v[i] ^ v[i + 8];
+ }
+
+#undef G
+#undef ROUND
+}
+
+int blake2b_update(blake2b_state *S, const void *in, size_t inlen) {
+ const uint8_t *pin = (const uint8_t *)in;
+
+ if (inlen == 0) {
+ return 0;
+ }
+
+ /* Sanity check */
+ if (S == NULL || in == NULL) {
+ return -1;
+ }
+
+ /* Is this a reused state? */
+ if (S->f[0] != 0) {
+ return -1;
+ }
+
+ if (S->buflen + inlen > BLAKE2B_BLOCKBYTES) {
+ /* Complete current block */
+ size_t left = S->buflen;
+ size_t fill = BLAKE2B_BLOCKBYTES - left;
+ memcpy(&S->buf[left], pin, fill);
+ blake2b_increment_counter(S, BLAKE2B_BLOCKBYTES);
+ blake2b_compress(S, S->buf);
+ S->buflen = 0;
+ inlen -= fill;
+ pin += fill;
+ /* Avoid buffer copies when possible */
+ while (inlen > BLAKE2B_BLOCKBYTES) {
+ blake2b_increment_counter(S, BLAKE2B_BLOCKBYTES);
+ blake2b_compress(S, pin);
+ inlen -= BLAKE2B_BLOCKBYTES;
+ pin += BLAKE2B_BLOCKBYTES;
+ }
+ }
+ memcpy(&S->buf[S->buflen], pin, inlen);
+ S->buflen += (unsigned int)inlen;
+ return 0;
+}
+
+int blake2b_final(blake2b_state *S, void *out, size_t outlen) {
+ uint8_t buffer[BLAKE2B_OUTBYTES] = { 0 };
+ unsigned int i;
+
+ /* Sanity checks */
+ if (S == NULL || out == NULL || outlen < S->outlen) {
+ return -1;
+ }
+
+ /* Is this a reused state? */
+ if (S->f[0] != 0) {
+ return -1;
+ }
+
+ blake2b_increment_counter(S, S->buflen);
+ blake2b_set_lastblock(S);
+ memset(&S->buf[S->buflen], 0, BLAKE2B_BLOCKBYTES - S->buflen); /* Padding */
+ blake2b_compress(S, S->buf);
+
+ for (i = 0; i < 8; ++i) { /* Output full hash to temp buffer */
+ store64(buffer + sizeof(S->h[i]) * i, S->h[i]);
+ }
+
+ memcpy(out, buffer, S->outlen);
+ clear_internal_memory(buffer, sizeof(buffer));
+ clear_internal_memory(S->buf, sizeof(S->buf));
+ clear_internal_memory(S->h, sizeof(S->h));
+ return 0;
+}
+
+int blake2b(void *out, size_t outlen, const void *in, size_t inlen,
+ const void *key, size_t keylen) {
+ blake2b_state S;
+ int ret = -1;
+
+ /* Verify parameters */
+ if (NULL == in && inlen > 0) {
+ goto fail;
+ }
+
+ if (NULL == out || outlen == 0 || outlen > BLAKE2B_OUTBYTES) {
+ goto fail;
+ }
+
+ if ((NULL == key && keylen > 0) || keylen > BLAKE2B_KEYBYTES) {
+ goto fail;
+ }
+
+ if (keylen > 0) {
+ if (blake2b_init_key(&S, outlen, key, keylen) < 0) {
+ goto fail;
+ }
+ }
+ else {
+ if (blake2b_init(&S, outlen) < 0) {
+ goto fail;
+ }
+ }
+
+ if (blake2b_update(&S, in, inlen) < 0) {
+ goto fail;
+ }
+ ret = blake2b_final(&S, out, outlen);
+
+fail:
+ clear_internal_memory(&S, sizeof(S));
+ return ret;
+}
+
+/* Argon2 Team - Begin Code */
+int blake2b_long(void *pout, size_t outlen, const void *in, size_t inlen) {
+ uint8_t *out = (uint8_t *)pout;
+ blake2b_state blake_state;
+ uint8_t outlen_bytes[sizeof(uint32_t)] = { 0 };
+ int ret = -1;
+
+ if (outlen > UINT32_MAX) {
+ goto fail;
+ }
+
+ /* Ensure little-endian byte order! */
+ store32(outlen_bytes, (uint32_t)outlen);
+
+#define TRY(statement) \
+ do { \
+ ret = statement; \
+ if (ret < 0) { \
+ goto fail; \
+ } \
+ } while ((void)0, 0)
+
+ if (outlen <= BLAKE2B_OUTBYTES) {
+ TRY(blake2b_init(&blake_state, outlen));
+ TRY(blake2b_update(&blake_state, outlen_bytes, sizeof(outlen_bytes)));
+ TRY(blake2b_update(&blake_state, in, inlen));
+ TRY(blake2b_final(&blake_state, out, outlen));
+ }
+ else {
+ uint32_t toproduce;
+ uint8_t out_buffer[BLAKE2B_OUTBYTES];
+ uint8_t in_buffer[BLAKE2B_OUTBYTES];
+ TRY(blake2b_init(&blake_state, BLAKE2B_OUTBYTES));
+ TRY(blake2b_update(&blake_state, outlen_bytes, sizeof(outlen_bytes)));
+ TRY(blake2b_update(&blake_state, in, inlen));
+ TRY(blake2b_final(&blake_state, out_buffer, BLAKE2B_OUTBYTES));
+ memcpy(out, out_buffer, BLAKE2B_OUTBYTES / 2);
+ out += BLAKE2B_OUTBYTES / 2;
+ toproduce = (uint32_t)outlen - BLAKE2B_OUTBYTES / 2;
+
+ while (toproduce > BLAKE2B_OUTBYTES) {
+ memcpy(in_buffer, out_buffer, BLAKE2B_OUTBYTES);
+ TRY(blake2b(out_buffer, BLAKE2B_OUTBYTES, in_buffer,
+ BLAKE2B_OUTBYTES, NULL, 0));
+ memcpy(out, out_buffer, BLAKE2B_OUTBYTES / 2);
+ out += BLAKE2B_OUTBYTES / 2;
+ toproduce -= BLAKE2B_OUTBYTES / 2;
+ }
+
+ memcpy(in_buffer, out_buffer, BLAKE2B_OUTBYTES);
+ TRY(blake2b(out_buffer, toproduce, in_buffer, BLAKE2B_OUTBYTES, NULL,
+ 0));
+ memcpy(out, out_buffer, toproduce);
+ }
+fail:
+ clear_internal_memory(&blake_state, sizeof(blake_state));
+ return ret;
+#undef TRY
+}
+/* Argon2 Team - End Code */
+
+/// END: blake2b.c
diff --git a/src/crypto/blake2b.h b/src/crypto/blake2b.h
new file mode 100644
index 000000000..ea00f381b
--- /dev/null
+++ b/src/crypto/blake2b.h
@@ -0,0 +1,116 @@
+/*
+Copyright (c) 2018-2019, tevador <tevador@gmail.com>
+
+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 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.
+*/
+
+/* Original code from Argon2 reference source code package used under CC0 Licence
+ * https://github.com/P-H-C/phc-winner-argon2
+ * Copyright 2015
+ * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves
+*/
+
+/// NOTE: implementation lifted out of randomx package
+
+#pragma once
+
+#include <stddef.h>
+#include <stdint.h>
+#include <limits.h>
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+ enum blake2b_constant {
+ BLAKE2B_BLOCKBYTES = 128,
+ BLAKE2B_OUTBYTES = 64,
+ BLAKE2B_KEYBYTES = 64,
+ BLAKE2B_SALTBYTES = 16,
+ BLAKE2B_PERSONALBYTES = 16
+ };
+
+#pragma pack(push, 1)
+ typedef struct __blake2b_param {
+ uint8_t digest_length; /* 1 */
+ uint8_t key_length; /* 2 */
+ uint8_t fanout; /* 3 */
+ uint8_t depth; /* 4 */
+ uint32_t leaf_length; /* 8 */
+ uint64_t node_offset; /* 16 */
+ uint8_t node_depth; /* 17 */
+ uint8_t inner_length; /* 18 */
+ uint8_t reserved[14]; /* 32 */
+ uint8_t salt[BLAKE2B_SALTBYTES]; /* 48 */
+ uint8_t personal[BLAKE2B_PERSONALBYTES]; /* 64 */
+ } blake2b_param;
+#pragma pack(pop)
+
+ typedef struct __blake2b_state {
+ uint64_t h[8];
+ uint64_t t[2];
+ uint64_t f[2];
+ uint8_t buf[BLAKE2B_BLOCKBYTES];
+ unsigned buflen;
+ unsigned outlen;
+ uint8_t last_node;
+ } blake2b_state;
+
+ /* Ensure param structs have not been wrongly padded */
+ /* Poor man's static_assert */
+ enum {
+ blake2_size_check_0 = 1 / !!(CHAR_BIT == 8),
+ blake2_size_check_2 =
+ 1 / !!(sizeof(blake2b_param) == sizeof(uint64_t) * CHAR_BIT)
+ };
+
+ // crypto namespace (fixes naming collisions with libsodium)
+#define blake2b_init crypto_blake2b_init
+#define blake2b_init_key crypto_blake2b_init_key
+#define blake2b_init_param crypto_blake2b_init_param
+#define blake2b_update crypto_blake2b_update
+#define blake2b_final crypto_blake2b_final
+#define blake2b crypto_blake2b
+#define blake2b_long crypto_blake2b_long
+
+ /* Streaming API */
+ int blake2b_init(blake2b_state *S, size_t outlen);
+ int blake2b_init_key(blake2b_state *S, size_t outlen, const void *key,
+ size_t keylen);
+ int blake2b_init_param(blake2b_state *S, const blake2b_param *P);
+ int blake2b_update(blake2b_state *S, const void *in, size_t inlen);
+ int blake2b_final(blake2b_state *S, void *out, size_t outlen);
+
+ /* Simple API */
+ int blake2b(void *out, size_t outlen, const void *in, size_t inlen,
+ const void *key, size_t keylen);
+
+ /* Argon2 Team - Begin Code */
+ int blake2b_long(void *out, size_t outlen, const void *in, size_t inlen);
+ /* Argon2 Team - End Code */
+
+#if defined(__cplusplus)
+}
+#endif
diff --git a/src/cryptonote_basic/account.cpp b/src/cryptonote_basic/account.cpp
index 9dc6e387d..c157c1fe1 100644
--- a/src/cryptonote_basic/account.cpp
+++ b/src/cryptonote_basic/account.cpp
@@ -152,6 +152,17 @@ DISABLE_VS_WARNINGS(4244 4345)
m_keys.m_multisig_keys.clear();
}
//-----------------------------------------------------------------
+ void account_base::set_spend_key(const crypto::secret_key& spend_secret_key)
+ {
+ // make sure derived spend public key matches saved public spend key
+ crypto::public_key spend_public_key;
+ crypto::secret_key_to_public_key(spend_secret_key, spend_public_key);
+ CHECK_AND_ASSERT_THROW_MES(m_keys.m_account_address.m_spend_public_key == spend_public_key,
+ "Unexpected derived public spend key");
+
+ m_keys.m_spend_secret_key = spend_secret_key;
+ }
+ //-----------------------------------------------------------------
crypto::secret_key account_base::generate(const crypto::secret_key& recovery_key, bool recover, bool two_random)
{
crypto::secret_key first = generate_keys(m_keys.m_account_address.m_spend_public_key, m_keys.m_spend_secret_key, recovery_key, recover);
diff --git a/src/cryptonote_basic/account.h b/src/cryptonote_basic/account.h
index 7578aaf2a..8f484166a 100644
--- a/src/cryptonote_basic/account.h
+++ b/src/cryptonote_basic/account.h
@@ -95,6 +95,7 @@ namespace cryptonote
bool store(const std::string& file_path);
void forget_spend_key();
+ void set_spend_key(const crypto::secret_key& spend_secret_key);
const std::vector<crypto::secret_key> &get_multisig_keys() const { return m_keys.m_multisig_keys; }
void encrypt_keys(const crypto::chacha_key &key) { m_keys.encrypt(key); }
diff --git a/src/cryptonote_basic/verification_context.h b/src/cryptonote_basic/verification_context.h
index 11d54ae9f..8dcd55187 100644
--- a/src/cryptonote_basic/verification_context.h
+++ b/src/cryptonote_basic/verification_context.h
@@ -59,6 +59,7 @@ namespace cryptonote
bool m_fee_too_low;
bool m_too_few_outputs;
bool m_tx_extra_too_big;
+ bool m_nonzero_unlock_time;
};
struct block_verification_context
diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h
index fec905928..578f2aa02 100644
--- a/src/cryptonote_config.h
+++ b/src/cryptonote_config.h
@@ -241,6 +241,8 @@ namespace config
const unsigned char HASH_KEY_ENCRYPTED_PAYMENT_ID = 0x8d;
const unsigned char HASH_KEY_WALLET = 0x8c;
const unsigned char HASH_KEY_WALLET_CACHE = 0x8d;
+ const unsigned char HASH_KEY_BACKGROUND_CACHE = 0x8e;
+ const unsigned char HASH_KEY_BACKGROUND_KEYS_FILE = 0x8f;
const unsigned char HASH_KEY_RPC_PAYMENT_NONCE = 0x58;
const unsigned char HASH_KEY_MEMORY = 'k';
const unsigned char HASH_KEY_MULTISIG[] = {'M', 'u', 'l', 't' , 'i', 's', 'i', 'g', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 3e1704048..3a7575119 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -3691,18 +3691,16 @@ void Blockchain::check_ring_signature(const crypto::hash &tx_prefix_hash, const
}
//------------------------------------------------------------------
-uint64_t Blockchain::get_dynamic_base_fee(uint64_t block_reward, size_t median_block_weight, uint8_t version)
+uint64_t Blockchain::get_dynamic_base_fee(uint64_t block_reward, size_t median_block_weight)
{
- const uint64_t min_block_weight = get_min_block_weight(version);
+ constexpr uint64_t min_block_weight = CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5;
if (median_block_weight < min_block_weight)
median_block_weight = min_block_weight;
uint64_t hi, lo;
- if (version >= HF_VERSION_PER_BYTE_FEE)
{
lo = mul128(block_reward, DYNAMIC_FEE_REFERENCE_TRANSACTION_WEIGHT, &hi);
div128_64(hi, lo, median_block_weight, &hi, &lo, NULL, NULL);
- if (version >= HF_VERSION_2021_SCALING)
{
// min_fee_per_byte = round_up( 0.95 * block_reward * ref_weight / (fee_median^2) )
// note: since hardfork HF_VERSION_2021_SCALING, fee_median (a.k.a. median_block_weight) equals effective long term median
@@ -3711,29 +3709,7 @@ uint64_t Blockchain::get_dynamic_base_fee(uint64_t block_reward, size_t median_b
lo -= lo / 20;
return lo == 0 ? 1 : lo;
}
- else
- {
- // min_fee_per_byte = 0.2 * block_reward * ref_weight / (min_penalty_free_zone * fee_median)
- div128_64(hi, lo, min_block_weight, &hi, &lo, NULL, NULL);
- assert(hi == 0);
- lo /= 5;
- return lo;
- }
}
-
- const uint64_t fee_base = version >= 5 ? DYNAMIC_FEE_PER_KB_BASE_FEE_V5 : DYNAMIC_FEE_PER_KB_BASE_FEE;
-
- uint64_t unscaled_fee_base = (fee_base * min_block_weight / median_block_weight);
- lo = mul128(unscaled_fee_base, block_reward, &hi);
- div128_64(hi, lo, DYNAMIC_FEE_PER_KB_BASE_BLOCK_REWARD, &hi, &lo, NULL, NULL);
- assert(hi == 0);
-
- // quantize fee up to 8 decimals
- uint64_t mask = get_fee_quantization_mask();
- uint64_t qlo = (lo + mask - 1) / mask * mask;
- MDEBUG("lo " << print_money(lo) << ", qlo " << print_money(qlo) << ", mask " << mask);
-
- return qlo;
}
//------------------------------------------------------------------
@@ -3744,7 +3720,6 @@ bool Blockchain::check_fee(size_t tx_weight, uint64_t fee) const
uint64_t median = 0;
uint64_t already_generated_coins = 0;
uint64_t base_reward = 0;
- if (version >= HF_VERSION_DYNAMIC_FEE)
{
median = m_current_block_cumul_weight_limit / 2;
const uint64_t blockchain_height = m_db->height();
@@ -3754,33 +3729,15 @@ bool Blockchain::check_fee(size_t tx_weight, uint64_t fee) const
}
uint64_t needed_fee;
- if (version >= HF_VERSION_PER_BYTE_FEE)
{
- const bool use_long_term_median_in_fee = version >= HF_VERSION_LONG_TERM_BLOCK_WEIGHT;
- uint64_t fee_per_byte = get_dynamic_base_fee(base_reward, use_long_term_median_in_fee ? std::min<uint64_t>(median, m_long_term_effective_median_block_weight) : median, version);
+ const uint64_t fee_per_byte = get_dynamic_base_fee(base_reward,
+ std::min<uint64_t>(median, m_long_term_effective_median_block_weight));
MDEBUG("Using " << print_money(fee_per_byte) << "/byte fee");
needed_fee = tx_weight * fee_per_byte;
// quantize fee up to 8 decimals
const uint64_t mask = get_fee_quantization_mask();
needed_fee = (needed_fee + mask - 1) / mask * mask;
}
- else
- {
- uint64_t fee_per_kb;
- if (version < HF_VERSION_DYNAMIC_FEE)
- {
- fee_per_kb = FEE_PER_KB;
- }
- else
- {
- fee_per_kb = get_dynamic_base_fee(base_reward, median, version);
- }
- MDEBUG("Using " << print_money(fee_per_kb) << "/kB fee");
-
- needed_fee = tx_weight / 1024;
- needed_fee += (tx_weight % 1024) ? 1 : 0;
- needed_fee *= fee_per_kb;
- }
if (fee < needed_fee - needed_fee / 50) // keep a little 2% buffer on acceptance - no integer overflow
{
@@ -3791,7 +3748,8 @@ bool Blockchain::check_fee(size_t tx_weight, uint64_t fee) const
}
//------------------------------------------------------------------
-void Blockchain::get_dynamic_base_fee_estimate_2021_scaling(uint64_t grace_blocks, uint64_t base_reward, uint64_t Mnw, uint64_t Mlw, std::vector<uint64_t> &fees) const
+void Blockchain::get_dynamic_base_fee_estimate_2021_scaling(uint64_t base_reward, uint64_t Mnw,
+ uint64_t Mlw, std::vector<uint64_t> &fees)
{
// variable names and calculations as per https://github.com/ArticMine/Monero-Documents/blob/master/MoneroScaling2021-02.pdf
// from (earlier than) this fork, the base fee is per byte
@@ -3863,55 +3821,8 @@ void Blockchain::get_dynamic_base_fee_estimate_2021_scaling(uint64_t grace_block
base_reward = BLOCK_REWARD_OVERESTIMATE;
}
- get_dynamic_base_fee_estimate_2021_scaling(grace_blocks, base_reward, Mnw, Mlw_penalty_free_zone_for_wallet, fees);
-}
-
-//------------------------------------------------------------------
-uint64_t Blockchain::get_dynamic_base_fee_estimate(uint64_t grace_blocks) const
-{
- const uint8_t version = get_current_hard_fork_version();
- const uint64_t db_height = m_db->height();
-
- if (version < HF_VERSION_DYNAMIC_FEE)
- return FEE_PER_KB;
-
- if (grace_blocks >= CRYPTONOTE_REWARD_BLOCKS_WINDOW)
- grace_blocks = CRYPTONOTE_REWARD_BLOCKS_WINDOW - 1;
-
- if (version >= HF_VERSION_2021_SCALING)
- {
- std::vector<uint64_t> fees;
- get_dynamic_base_fee_estimate_2021_scaling(grace_blocks, fees);
- return fees[0];
- }
-
- const uint64_t min_block_weight = get_min_block_weight(version);
- std::vector<uint64_t> weights;
- get_last_n_blocks_weights(weights, CRYPTONOTE_REWARD_BLOCKS_WINDOW - grace_blocks);
- weights.reserve(grace_blocks);
- for (size_t i = 0; i < grace_blocks; ++i)
- weights.push_back(min_block_weight);
-
- uint64_t median = epee::misc_utils::median(weights);
- if(median <= min_block_weight)
- median = min_block_weight;
-
- uint64_t already_generated_coins = db_height ? m_db->get_block_already_generated_coins(db_height - 1) : 0;
- uint64_t base_reward;
- if (!get_block_reward(m_current_block_cumul_weight_limit / 2, 1, already_generated_coins, base_reward, version))
- {
- MERROR("Failed to determine block reward, using placeholder " << print_money(BLOCK_REWARD_OVERESTIMATE) << " as a high bound");
- base_reward = BLOCK_REWARD_OVERESTIMATE;
- }
-
- const bool use_long_term_median_in_fee = version >= HF_VERSION_LONG_TERM_BLOCK_WEIGHT;
- const uint64_t use_median_value = use_long_term_median_in_fee ? std::min<uint64_t>(median, m_long_term_effective_median_block_weight) : median;
- const uint64_t fee = get_dynamic_base_fee(base_reward, use_median_value, version);
- const bool per_byte = version < HF_VERSION_PER_BYTE_FEE;
- MDEBUG("Estimating " << grace_blocks << "-block fee at " << print_money(fee) << "/" << (per_byte ? "byte" : "kB"));
- return fee;
+ get_dynamic_base_fee_estimate_2021_scaling(base_reward, Mnw, Mlw_penalty_free_zone_for_wallet, fees);
}
-
//------------------------------------------------------------------
// This function checks to see if a tx is unlocked. unlock_time is either
// a block index or a unix time.
@@ -5551,7 +5462,7 @@ void Blockchain::cancel()
}
#if defined(PER_BLOCK_CHECKPOINT)
-static const char expected_block_hashes_hash[] = "e9371004b9f6be59921b27bc81e28b4715845ade1c6d16891d5c455f72e21365";
+static const char expected_block_hashes_hash[] = "0046a0019beb6e697e27d834d6127851425f7ee09bfb8e9f8df7b1420131aca8";
void Blockchain::load_compiled_in_block_hashes(const GetCheckpointsCallback& get_checkpoints)
{
if (get_checkpoints == nullptr || !m_fast_sync)
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index be2848d09..2249d8cb2 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -638,27 +638,24 @@ namespace cryptonote
*
* @param block_reward the current block reward
* @param median_block_weight the median block weight in the past window
- * @param version hard fork version for rules and constants to use
*
* @return the fee
*/
- static uint64_t get_dynamic_base_fee(uint64_t block_reward, size_t median_block_weight, uint8_t version);
+ static uint64_t get_dynamic_base_fee(uint64_t block_reward, size_t median_block_weight);
/**
- * @brief get dynamic per kB or byte fee estimate for the next few blocks
+ * @brief get four levels of dynamic per byte fee estimate for the next few blocks
*
* The dynamic fee is based on the block weight in a past window, and
- * the current block reward. It is expressed by kB before v8, and
- * per byte from v8.
- * This function calculates an estimate for a dynamic fee which will be
- * valid for the next grace_blocks
- *
- * @param grace_blocks number of blocks we want the fee to be valid for
+ * the current block reward. It is expressed per byte, and is based on
+ * https://github.com/ArticMine/Monero-Documents/blob/master/MoneroScaling2021-02.pdf
*
- * @return the fee estimate
+ * @param Mnw min(Msw, 50*Mlw)
+ * @param Mlw The median over the last 99990 and future 10 blocks of max(min(Mbw, 2*Ml), Zm, Ml/2)
+ * @param[out] fees fee estimate levels [Fl, Fn, Fm, Fh]
*/
- uint64_t get_dynamic_base_fee_estimate(uint64_t grace_blocks) const;
- void get_dynamic_base_fee_estimate_2021_scaling(uint64_t grace_blocks, uint64_t base_reward, uint64_t Mnw, uint64_t Mlw, std::vector<uint64_t> &fees) const;
+ static void get_dynamic_base_fee_estimate_2021_scaling(uint64_t base_reward, uint64_t Mnw,
+ uint64_t Mlw, std::vector<uint64_t> &fees);
/**
* @brief get four levels of dynamic per byte fee estimate for the next few blocks
@@ -670,8 +667,7 @@ namespace cryptonote
* valid for the next grace_blocks
*
* @param grace_blocks number of blocks we want the fee to be valid for
- *
- * @return the fee estimates (4 of them)
+ * @param[out] fees fee estimate levels [Fl, Fn, Fm, Fh]
*/
void get_dynamic_base_fee_estimate_2021_scaling(uint64_t grace_blocks, std::vector<uint64_t> &fees) const;
diff --git a/src/cryptonote_core/cryptonote_tx_utils.cpp b/src/cryptonote_core/cryptonote_tx_utils.cpp
index 60b399bb5..d5bb8fee7 100644
--- a/src/cryptonote_core/cryptonote_tx_utils.cpp
+++ b/src/cryptonote_core/cryptonote_tx_utils.cpp
@@ -203,7 +203,7 @@ namespace cryptonote
return addr.m_view_public_key;
}
//---------------------------------------------------------------
- bool construct_tx_with_tx_key(const account_keys& sender_account_keys, const std::unordered_map<crypto::public_key, subaddress_index>& subaddresses, std::vector<tx_source_entry>& sources, std::vector<tx_destination_entry>& destinations, const boost::optional<cryptonote::account_public_address>& change_addr, const std::vector<uint8_t> &extra, transaction& tx, uint64_t unlock_time, const crypto::secret_key &tx_key, const std::vector<crypto::secret_key> &additional_tx_keys, bool rct, const rct::RCTConfig &rct_config, bool shuffle_outs, bool use_view_tags)
+ bool construct_tx_with_tx_key(const account_keys& sender_account_keys, const std::unordered_map<crypto::public_key, subaddress_index>& subaddresses, std::vector<tx_source_entry>& sources, std::vector<tx_destination_entry>& destinations, const boost::optional<cryptonote::account_public_address>& change_addr, const std::vector<uint8_t> &extra, transaction& tx, const crypto::secret_key &tx_key, const std::vector<crypto::secret_key> &additional_tx_keys, bool rct, const rct::RCTConfig &rct_config, bool shuffle_outs, bool use_view_tags)
{
hw::device &hwdev = sender_account_keys.get_device();
@@ -218,7 +218,7 @@ namespace cryptonote
amount_keys.clear();
tx.version = rct ? 2 : 1;
- tx.unlock_time = unlock_time;
+ tx.unlock_time = 0;
tx.extra = extra;
crypto::public_key txkey_pub;
@@ -606,7 +606,7 @@ namespace cryptonote
return true;
}
//---------------------------------------------------------------
- bool construct_tx_and_get_tx_key(const account_keys& sender_account_keys, const std::unordered_map<crypto::public_key, subaddress_index>& subaddresses, std::vector<tx_source_entry>& sources, std::vector<tx_destination_entry>& destinations, const boost::optional<cryptonote::account_public_address>& change_addr, const std::vector<uint8_t> &extra, transaction& tx, uint64_t unlock_time, crypto::secret_key &tx_key, std::vector<crypto::secret_key> &additional_tx_keys, bool rct, const rct::RCTConfig &rct_config, bool use_view_tags)
+ bool construct_tx_and_get_tx_key(const account_keys& sender_account_keys, const std::unordered_map<crypto::public_key, subaddress_index>& subaddresses, std::vector<tx_source_entry>& sources, std::vector<tx_destination_entry>& destinations, const boost::optional<cryptonote::account_public_address>& change_addr, const std::vector<uint8_t> &extra, transaction& tx, crypto::secret_key &tx_key, std::vector<crypto::secret_key> &additional_tx_keys, bool rct, const rct::RCTConfig &rct_config, bool use_view_tags)
{
hw::device &hwdev = sender_account_keys.get_device();
hwdev.open_tx(tx_key);
@@ -627,7 +627,7 @@ namespace cryptonote
}
bool shuffle_outs = true;
- bool r = construct_tx_with_tx_key(sender_account_keys, subaddresses, sources, destinations, change_addr, extra, tx, unlock_time, tx_key, additional_tx_keys, rct, rct_config, shuffle_outs, use_view_tags);
+ bool r = construct_tx_with_tx_key(sender_account_keys, subaddresses, sources, destinations, change_addr, extra, tx, tx_key, additional_tx_keys, rct, rct_config, shuffle_outs, use_view_tags);
hwdev.close_tx();
return r;
} catch(...) {
@@ -636,14 +636,14 @@ namespace cryptonote
}
}
//---------------------------------------------------------------
- bool construct_tx(const account_keys& sender_account_keys, std::vector<tx_source_entry>& sources, const std::vector<tx_destination_entry>& destinations, const boost::optional<cryptonote::account_public_address>& change_addr, const std::vector<uint8_t> &extra, transaction& tx, uint64_t unlock_time)
+ bool construct_tx(const account_keys& sender_account_keys, std::vector<tx_source_entry>& sources, const std::vector<tx_destination_entry>& destinations, const boost::optional<cryptonote::account_public_address>& change_addr, const std::vector<uint8_t> &extra, transaction& tx)
{
std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
subaddresses[sender_account_keys.m_account_address.m_spend_public_key] = {0,0};
crypto::secret_key tx_key;
std::vector<crypto::secret_key> additional_tx_keys;
std::vector<tx_destination_entry> destinations_copy = destinations;
- return construct_tx_and_get_tx_key(sender_account_keys, subaddresses, sources, destinations_copy, change_addr, extra, tx, unlock_time, tx_key, additional_tx_keys, false, { rct::RangeProofBorromean, 0});
+ return construct_tx_and_get_tx_key(sender_account_keys, subaddresses, sources, destinations_copy, change_addr, extra, tx, tx_key, additional_tx_keys, false, { rct::RangeProofBorromean, 0});
}
//---------------------------------------------------------------
bool generate_genesis_block(
diff --git a/src/cryptonote_core/cryptonote_tx_utils.h b/src/cryptonote_core/cryptonote_tx_utils.h
index 2ee93fd8f..8f1073766 100644
--- a/src/cryptonote_core/cryptonote_tx_utils.h
+++ b/src/cryptonote_core/cryptonote_tx_utils.h
@@ -118,9 +118,9 @@ namespace cryptonote
//---------------------------------------------------------------
crypto::public_key get_destination_view_key_pub(const std::vector<tx_destination_entry> &destinations, const boost::optional<cryptonote::account_public_address>& change_addr);
- bool construct_tx(const account_keys& sender_account_keys, std::vector<tx_source_entry> &sources, const std::vector<tx_destination_entry>& destinations, const boost::optional<cryptonote::account_public_address>& change_addr, const std::vector<uint8_t> &extra, transaction& tx, uint64_t unlock_time);
- bool construct_tx_with_tx_key(const account_keys& sender_account_keys, const std::unordered_map<crypto::public_key, subaddress_index>& subaddresses, std::vector<tx_source_entry>& sources, std::vector<tx_destination_entry>& destinations, const boost::optional<cryptonote::account_public_address>& change_addr, const std::vector<uint8_t> &extra, transaction& tx, uint64_t unlock_time, const crypto::secret_key &tx_key, const std::vector<crypto::secret_key> &additional_tx_keys, bool rct = false, const rct::RCTConfig &rct_config = { rct::RangeProofBorromean, 0 }, bool shuffle_outs = true, bool use_view_tags = false);
- bool construct_tx_and_get_tx_key(const account_keys& sender_account_keys, const std::unordered_map<crypto::public_key, subaddress_index>& subaddresses, std::vector<tx_source_entry>& sources, std::vector<tx_destination_entry>& destinations, const boost::optional<cryptonote::account_public_address>& change_addr, const std::vector<uint8_t> &extra, transaction& tx, uint64_t unlock_time, crypto::secret_key &tx_key, std::vector<crypto::secret_key> &additional_tx_keys, bool rct = false, const rct::RCTConfig &rct_config = { rct::RangeProofBorromean, 0 }, bool use_view_tags = false);
+ bool construct_tx(const account_keys& sender_account_keys, std::vector<tx_source_entry> &sources, const std::vector<tx_destination_entry>& destinations, const boost::optional<cryptonote::account_public_address>& change_addr, const std::vector<uint8_t> &extra, transaction& tx);
+ bool construct_tx_with_tx_key(const account_keys& sender_account_keys, const std::unordered_map<crypto::public_key, subaddress_index>& subaddresses, std::vector<tx_source_entry>& sources, std::vector<tx_destination_entry>& destinations, const boost::optional<cryptonote::account_public_address>& change_addr, const std::vector<uint8_t> &extra, transaction& tx, const crypto::secret_key &tx_key, const std::vector<crypto::secret_key> &additional_tx_keys, bool rct = false, const rct::RCTConfig &rct_config = { rct::RangeProofBorromean, 0 }, bool shuffle_outs = true, bool use_view_tags = false);
+ bool construct_tx_and_get_tx_key(const account_keys& sender_account_keys, const std::unordered_map<crypto::public_key, subaddress_index>& subaddresses, std::vector<tx_source_entry>& sources, std::vector<tx_destination_entry>& destinations, const boost::optional<cryptonote::account_public_address>& change_addr, const std::vector<uint8_t> &extra, transaction& tx, crypto::secret_key &tx_key, std::vector<crypto::secret_key> &additional_tx_keys, bool rct = false, const rct::RCTConfig &rct_config = { rct::RangeProofBorromean, 0 }, bool use_view_tags = false);
bool generate_output_ephemeral_keys(const size_t tx_version, const cryptonote::account_keys &sender_account_keys, const crypto::public_key &txkey_pub, const crypto::secret_key &tx_key,
const cryptonote::tx_destination_entry &dst_entr, const boost::optional<cryptonote::account_public_address> &change_addr, const size_t output_index,
const bool &need_additional_txkeys, const std::vector<crypto::secret_key> &additional_tx_keys,
diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp
index 4f0501c1d..96b229177 100644
--- a/src/cryptonote_core/tx_pool.cpp
+++ b/src/cryptonote_core/tx_pool.cpp
@@ -235,6 +235,15 @@ namespace cryptonote
return false;
}
+ if (!kept_by_block && tx.unlock_time)
+ {
+ LOG_PRINT_L1("transaction unlock time is not zero: " << tx.unlock_time);
+ tvc.m_verifivation_failed = true;
+ tvc.m_nonzero_unlock_time = true;
+ tvc.m_no_drop_offense = true;
+ return false;
+ }
+
// if the transaction came from a block popped from the chain,
// don't check if we have its key images as spent.
// TODO: Investigate why not?
diff --git a/src/cryptonote_protocol/levin_notify.cpp b/src/cryptonote_protocol/levin_notify.cpp
index 5b420ec3f..1c3a2901c 100644
--- a/src/cryptonote_protocol/levin_notify.cpp
+++ b/src/cryptonote_protocol/levin_notify.cpp
@@ -741,9 +741,14 @@ namespace levin
notify::status notify::get_status() const noexcept
{
if (!zone_)
- return {false, false};
-
- return {!zone_->noise.empty(), CRYPTONOTE_NOISE_CHANNELS <= zone_->connection_count};
+ return {false, false, false};
+
+ // `connection_count` is only set when `!noise.empty()`.
+ const std::size_t connection_count = zone_->connection_count;
+ bool has_outgoing = connection_count;
+ if (zone_->noise.empty())
+ has_outgoing = zone_->p2p->get_out_connections_count();
+ return {!zone_->noise.empty(), CRYPTONOTE_NOISE_CHANNELS <= connection_count, has_outgoing};
}
void notify::new_out_connection()
diff --git a/src/cryptonote_protocol/levin_notify.h b/src/cryptonote_protocol/levin_notify.h
index 52d36efb0..816170841 100644
--- a/src/cryptonote_protocol/levin_notify.h
+++ b/src/cryptonote_protocol/levin_notify.h
@@ -75,7 +75,8 @@ namespace levin
struct status
{
bool has_noise;
- bool connections_filled;
+ bool connections_filled; //!< True when has zone has `CRYPTONOTE_NOISE_CHANNELS` outgoing noise channels
+ bool has_outgoing; //!< True when zone has outgoing connections
};
//! Construct an instance that cannot notify.
diff --git a/src/device/log.hpp b/src/device/log.hpp
index 92d174da1..21bd70149 100644
--- a/src/device/log.hpp
+++ b/src/device/log.hpp
@@ -48,7 +48,7 @@ namespace hw {
* - All computation done by device are checked by default device.
* Required IODUMMYCRYPT_HWDEVICE or IONOCRYPT_HWDEVICE for fully working
* #define IODUMMYCRYPT_HWDEVICE 1
- * - It assumes sensitive data encryption is is off on device side. a XOR with 0x55. This allow Ledger Class to make check on clear value
+ * - It assumes sensitive data encryption is off on device side. a XOR with 0x55. This allow Ledger Class to make check on clear value
* #define IONOCRYPT_HWDEVICE 1
* - It assumes sensitive data encryption is off on device side.
*/
diff --git a/src/device_trezor/README.md b/src/device_trezor/README.md
index ce08c0009..dede853ae 100644
--- a/src/device_trezor/README.md
+++ b/src/device_trezor/README.md
@@ -15,19 +15,29 @@ Please, refer to [monero readme](https://github.com/trezor/trezor-firmware/blob/
## Dependencies
-Trezor uses [Protobuf](https://protobuf.dev/) library. As Monero is compiled with C++14, the newest Protobuf library version cannot be compiled because it requires C++17 (through its dependency Abseil library).
-This can result in a compilation failure.
+Trezor uses [Protobuf](https://protobuf.dev/) library. Monero is now compiled with C++ 17 by default.
+Protobuf v21 is tested, older versions are not guaranteed to work. Note that Protobuf v23+ requires C++ 17.
-Protobuf v21 is the latest compatible protobuf version.
+If you are getting Trezor compilation errors, it may be caused by abseil (protobuf dependency) not being compiled with C++17.
+To fix this try installing protobuf from sources:
-If you want to compile Monero with Trezor support, please make sure the Protobuf v21 is installed.
+```shell
+git clone --recursive git@github.com:protocolbuffers/protobuf.git
+cd protobuf
+cmake -DABSL_PROPAGATE_CXX_STD=TRUE -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_SHARED_LIBS=ON -Dprotobuf_BUILD_TESTS=OFF .
+cmake --build .
+sudo make install
+```
+
+If Monero is compiled with C++14, Protobuf v21 is the latest compatible protobuf version for C++ 14.
+If you want to compile Monero with Trezor support with C++14, please make sure the Protobuf v21 is installed.
More about this limitation: [PR #8752](https://github.com/monero-project/monero/pull/8752),
[1](https://github.com/monero-project/monero/pull/8752#discussion_r1246174755), [2](https://github.com/monero-project/monero/pull/8752#discussion_r1246480393)
### OSX
-To build with installed, but not linked protobuf:
+To build with installed, but not linked Protobuf v21:
```bash
CMAKE_PREFIX_PATH=$(find /opt/homebrew/Cellar/protobuf@21 -maxdepth 1 -type d -name "21.*" -print -quit) \
@@ -53,7 +63,7 @@ pacman --noconfirm -U mingw-w64-x86_64-protobuf-c-1.4.1-1-any.pkg.tar.zst mingw-
### Other systems
-- install protobufv21
+- install Protobuf v21
- point `CMAKE_PREFIX_PATH` environment variable to Protobuf v21 installation.
## Troubleshooting
diff --git a/src/gen_multisig/gen_multisig.cpp b/src/gen_multisig/gen_multisig.cpp
index 48cf818ef..fd82c66af 100644
--- a/src/gen_multisig/gen_multisig.cpp
+++ b/src/gen_multisig/gen_multisig.cpp
@@ -121,16 +121,15 @@ static bool generate_multisig(uint32_t threshold, uint32_t total, const std::str
}
// exchange keys until the wallets are done
- bool ready{false};
- wallets[0]->multisig(&ready);
- while (!ready)
+ multisig::multisig_account_status ms_status{wallets[0]->get_multisig_status()};
+ while (!ms_status.is_ready)
{
for (size_t n = 0; n < total; ++n)
{
kex_msgs_intermediate[n] = wallets[n]->exchange_multisig_keys(pwd_container->password(), kex_msgs_intermediate);
}
- wallets[0]->multisig(&ready);
+ ms_status = wallets[0]->get_multisig_status();
}
std::string address = wallets[0]->get_account().get_public_address_str(wallets[0]->nettype());
diff --git a/src/multisig/multisig_account.h b/src/multisig/multisig_account.h
index 0d832f243..dc2fbabd8 100644
--- a/src/multisig/multisig_account.h
+++ b/src/multisig/multisig_account.h
@@ -40,6 +40,19 @@
namespace multisig
{
+ struct multisig_account_status
+ {
+ // is the multisig account active/initialized?
+ bool multisig_is_active{false};
+ // has the multisig account completed the main key exchange rounds?
+ bool kex_is_done{false};
+ // is the multisig account ready to use?
+ bool is_ready{false};
+ // multisig is: M-of-N
+ std::uint32_t threshold{0}; // M
+ std::uint32_t total{0}; // N
+ };
+
/**
* multisig account:
*
@@ -90,7 +103,8 @@ namespace multisig
*
* - prepares a kex msg for the first round of multisig key construction.
* - the local account's kex msgs are signed with the base_privkey
- * - the first kex msg transmits the local base_common_privkey to other participants, for creating the group's common_privkey
+ * - the first kex msg transmits the local base_common_privkey to other participants, for creating the group's
+ * common_privkey
*/
multisig_account(const crypto::secret_key &base_privkey,
const crypto::secret_key &base_common_privkey);
@@ -177,24 +191,48 @@ namespace multisig
* - If force updating with maliciously-crafted messages, the resulting account will be invalid (either unable
* to complete signatures, or a 'hostage' to the malicious signer [i.e. can't sign without his participation]).
*/
- void kex_update(const std::vector<multisig_kex_msg> &expanded_msgs,
- const bool force_update_use_with_caution = false);
+ void kex_update(const std::vector<multisig_kex_msg> &expanded_msgs, const bool force_update_use_with_caution = false);
+ /**
+ * brief: get_multisig_kex_round_booster - Create a multisig kex msg for the kex round that follows the kex round this
+ * account is currently working on, in order to 'boost' another participant's kex setup.
+ * - A booster message is for the round after the in-progress round because get_next_kex_round_msg() provides access
+ * to the in-progress round's message.
+ * - Useful for 'jumpstarting' the following kex round when you don't have messages from all other signers to complete
+ * the current round.
+ * - Sanitizes input messages and produces a new kex msg for round 'num_completed_rounds + 2'.
+ *
+ * - For example, in 2-of-3 escrowed purchasing, the [vendor, arbitrator] pair can boost the second round
+ * of key exchange by calling this function with the 'round 1' messages of each other.
+ * Then the [buyer] can use the resulting boost messages, in combination with [vender, arbitrator] round 1 messages,
+ * to complete the address in one step. In other words, call initialize_kex() on the round 1 messages,
+ * then call kex_update() on the round 2 booster messages to finish the multisig key.
+ *
+ * - Note: The 'threshold' and 'num_signers' are inputs here in case kex has not been initialized yet.
+ * param: threshold - threshold for multisig (M in M-of-N)
+ * param: num_signers - number of participants in multisig (N)
+ * param: expanded_msgs - set of multisig kex messages to process
+ * return: multisig kex message for next round
+ */
+ multisig_kex_msg get_multisig_kex_round_booster(const std::uint32_t threshold,
+ const std::uint32_t num_signers,
+ const std::vector<multisig_kex_msg> &expanded_msgs) const;
private:
// implementation of kex_update() (non-transactional)
void kex_update_impl(const std::vector<multisig_kex_msg> &expanded_msgs, const bool incomplete_signer_set);
/**
- * brief: initialize_kex_update - Helper for kex_update_impl()
- * - Collect the local signer's shared keys to ignore in incoming messages, build the aggregate ancillary key
- * if appropriate.
+ * brief: get_kex_exclude_pubkeys - collect the local signer's shared keys to ignore in incoming messages
+ * return: keys held by the local account corresponding to the 'in-progress round'
+ * - If 'in-progress round' is the final round, these are the local account's shares of the final aggregate key.
+ */
+ std::vector<crypto::public_key> get_kex_exclude_pubkeys() const;
+ /**
+ * brief: initialize_kex_update - initialize the multisig account for the first kex round
* param: expanded_msgs - set of multisig kex messages to process
* param: kex_rounds_required - number of rounds required for kex (not including post-kex verification round)
- * outparam: exclude_pubkeys_out - keys held by the local account corresponding to round 'current_round'
- * - If 'current_round' is the final round, these are the local account's shares of the final aggregate key.
*/
void initialize_kex_update(const std::vector<multisig_kex_msg> &expanded_msgs,
- const std::uint32_t kex_rounds_required,
- std::vector<crypto::public_key> &exclude_pubkeys_out);
+ const std::uint32_t kex_rounds_required);
/**
* brief: finalize_kex_update - Helper for kex_update_impl()
* param: kex_rounds_required - number of rounds required for kex (not including post-kex verification round)
diff --git a/src/multisig/multisig_account_kex_impl.cpp b/src/multisig/multisig_account_kex_impl.cpp
index ef0acf307..5c68dd5dc 100644
--- a/src/multisig/multisig_account_kex_impl.cpp
+++ b/src/multisig/multisig_account_kex_impl.cpp
@@ -395,7 +395,7 @@ namespace multisig
* - Sanitizes input msgs.
* - Require uniqueness in: 'exclude_pubkeys'.
* - Requires each input pubkey be recommended by 'num_recommendations = expected_round' msg signers.
- * - For a final multisig key to be truly 'M-of-N', each of the the private key's components must be
+ * - For a final multisig key to be truly 'M-of-N', each of the private key's components must be
* shared by (N - M + 1) signers.
* - Requires that msgs are signed by only keys in 'signers'.
* - Requires that each key in 'signers' recommends [num_signers - 2 CHOOSE (expected_round - 1)] pubkeys.
@@ -567,7 +567,7 @@ namespace multisig
// note: do NOT remove the local signer from the pubkey origins map, since the post-kex round can be force-updated with
// just the local signer's post-kex message (if the local signer were removed, then the post-kex message's pubkeys
- // would be completely lost)
+ // would be completely deleted)
// evaluate pubkeys collected
@@ -608,7 +608,7 @@ namespace multisig
* INTERNAL
*
* brief: multisig_kex_process_round_msgs - Process kex messages for the active kex round.
- * - A wrapper around evaluate_multisig_kex_round_msgs() -> multisig_kex_make_next_msg().
+ * - A wrapper around evaluate_multisig_kex_round_msgs() -> multisig_kex_make_round_keys().
* - In other words, evaluate the input messages and try to make a message for the next round.
* - Note: Must be called on the final round's msgs to evaluate the final key components
* recommended by other participants.
@@ -623,7 +623,7 @@ namespace multisig
* outparam: keys_to_origins_map_out - map between round keys and identity keys
* - If in the final round, these are key shares recommended by other signers for the final aggregate key.
* - Otherwise, these are the local account's DH derivations for the next round.
- * - See multisig_kex_make_next_msg() for an explanation.
+ * - See multisig_kex_make_round_keys() for an explanation.
* return: multisig kex message for next round, or empty message if 'current_round' is the final round
*/
//----------------------------------------------------------------------------------------------------------------------
@@ -684,59 +684,67 @@ namespace multisig
//----------------------------------------------------------------------------------------------------------------------
// multisig_account: INTERNAL
//----------------------------------------------------------------------------------------------------------------------
- void multisig_account::initialize_kex_update(const std::vector<multisig_kex_msg> &expanded_msgs,
- const std::uint32_t kex_rounds_required,
- std::vector<crypto::public_key> &exclude_pubkeys_out)
+ std::vector<crypto::public_key> multisig_account::get_kex_exclude_pubkeys() const
{
+ // exclude all keys the local account recommends
+ std::vector<crypto::public_key> exclude_pubkeys;
+
if (m_kex_rounds_complete == 0)
{
- // the first round of kex msgs will contain each participant's base pubkeys and ancillary privkeys
+ // in the first round, only the local pubkey is recommended by the local signer
+ exclude_pubkeys.emplace_back(m_base_pubkey);
+ }
+ else
+ {
+ // in other rounds, kex msgs will contain participants' shared keys, so ignore shared keys the account helped
+ // create for this round
+ for (const auto &shared_key_with_origins : m_kex_keys_to_origins_map)
+ exclude_pubkeys.emplace_back(shared_key_with_origins.first);
+ }
- // collect participants' base common privkey shares
- // note: duplicate privkeys are acceptable, and duplicates due to duplicate signers
- // will be blocked by duplicate-signer errors after this function is called
- std::vector<crypto::secret_key> participant_base_common_privkeys;
- participant_base_common_privkeys.reserve(expanded_msgs.size() + 1);
+ return exclude_pubkeys;
+ }
+ //----------------------------------------------------------------------------------------------------------------------
+ // multisig_account: INTERNAL
+ //----------------------------------------------------------------------------------------------------------------------
+ void multisig_account::initialize_kex_update(const std::vector<multisig_kex_msg> &expanded_msgs,
+ const std::uint32_t kex_rounds_required)
+ {
+ // initialization is only needed during the first round
+ if (m_kex_rounds_complete > 0)
+ return;
- // add local ancillary base privkey
- participant_base_common_privkeys.emplace_back(m_base_common_privkey);
+ // the first round of kex msgs will contain each participant's base pubkeys and ancillary privkeys, so we prepare
+ // them here
- // add other signers' base common privkeys
- for (const auto &expanded_msg : expanded_msgs)
- {
- if (expanded_msg.get_signing_pubkey() != m_base_pubkey)
- {
- participant_base_common_privkeys.emplace_back(expanded_msg.get_msg_privkey());
- }
- }
+ // collect participants' base common privkey shares
+ // note: duplicate privkeys are acceptable, and duplicates due to duplicate signers
+ // will be blocked by duplicate-signer errors after this function is called
+ std::vector<crypto::secret_key> participant_base_common_privkeys;
+ participant_base_common_privkeys.reserve(expanded_msgs.size() + 1);
- // make common privkey
- make_multisig_common_privkey(std::move(participant_base_common_privkeys), m_common_privkey);
+ // add local ancillary base privkey
+ participant_base_common_privkeys.emplace_back(m_base_common_privkey);
- // set common pubkey
- CHECK_AND_ASSERT_THROW_MES(crypto::secret_key_to_public_key(m_common_privkey, m_common_pubkey),
- "Failed to derive public key");
+ // add other signers' base common privkeys
+ for (const multisig_kex_msg &expanded_msg : expanded_msgs)
+ {
+ if (expanded_msg.get_signing_pubkey() != m_base_pubkey)
+ participant_base_common_privkeys.emplace_back(expanded_msg.get_msg_privkey());
+ }
- // if N-of-N, then the base privkey will be used directly to make the account's share of the final key
- if (kex_rounds_required == 1)
- {
- m_multisig_privkeys.clear();
- m_multisig_privkeys.emplace_back(m_base_privkey);
- }
+ // make common privkey
+ make_multisig_common_privkey(std::move(participant_base_common_privkeys), m_common_privkey);
- // exclude all keys the local account recommends
- // - in the first round, only the local pubkey is recommended by the local signer
- exclude_pubkeys_out.emplace_back(m_base_pubkey);
- }
- else
- {
- // in other rounds, kex msgs will contain participants' shared keys
+ // set common pubkey
+ CHECK_AND_ASSERT_THROW_MES(crypto::secret_key_to_public_key(m_common_privkey, m_common_pubkey),
+ "Failed to derive public key");
- // ignore shared keys the account helped create for this round
- for (const auto &shared_key_with_origins : m_kex_keys_to_origins_map)
- {
- exclude_pubkeys_out.emplace_back(shared_key_with_origins.first);
- }
+ // if N-of-N, then the base privkey will be used directly to make the account's share of the final key
+ if (kex_rounds_required == 1)
+ {
+ m_multisig_privkeys.clear();
+ m_multisig_privkeys.emplace_back(m_base_privkey);
}
}
//----------------------------------------------------------------------------------------------------------------------
@@ -771,9 +779,7 @@ namespace multisig
result_keys.reserve(result_keys_to_origins_map.size());
for (const auto &result_key_and_origins : result_keys_to_origins_map)
- {
result_keys.emplace_back(result_key_and_origins.first);
- }
// compute final aggregate key, update local multisig privkeys with aggregation coefficients applied
m_multisig_pubkey = generate_multisig_aggregate_key(std::move(result_keys), m_multisig_privkeys);
@@ -811,7 +817,8 @@ namespace multisig
// derived pubkey = multisig_key * G
crypto::public_key_memsafe derived_pubkey;
m_multisig_privkeys.push_back(
- calculate_multisig_keypair_from_derivation(derivation_and_origins.first, derived_pubkey));
+ calculate_multisig_keypair_from_derivation(derivation_and_origins.first, derived_pubkey)
+ );
// save the account's kex key mappings for this round [derived pubkey : other signers who will have the same key]
m_kex_keys_to_origins_map[derived_pubkey] = std::move(derivation_and_origins.second);
@@ -863,8 +870,7 @@ namespace multisig
"Multisig kex has already completed all required rounds (including post-kex verification).");
// initialize account update
- std::vector<crypto::public_key> exclude_pubkeys;
- initialize_kex_update(expanded_msgs, kex_rounds_required, exclude_pubkeys);
+ this->initialize_kex_update(expanded_msgs, kex_rounds_required);
// process messages into a [pubkey : {origins}] map
multisig_keyset_map_memsafe_t result_keys_to_origins_map;
@@ -875,12 +881,75 @@ namespace multisig
m_threshold,
m_signers,
expanded_msgs,
- exclude_pubkeys,
+ this->get_kex_exclude_pubkeys(),
incomplete_signer_set,
result_keys_to_origins_map);
// finish account update
- finalize_kex_update(kex_rounds_required, std::move(result_keys_to_origins_map));
+ this->finalize_kex_update(kex_rounds_required, std::move(result_keys_to_origins_map));
+ }
+ //-----------------------------------------------------------------
+ // multisig_account: EXTERNAL
+ //-----------------------------------------------------------------
+ multisig_kex_msg multisig_account::get_multisig_kex_round_booster(const std::uint32_t threshold,
+ const std::uint32_t num_signers,
+ const std::vector<multisig_kex_msg> &expanded_msgs) const
+ {
+ // the messages passed in should be required for the next kex round of this account (the round it is currently
+ // working on)
+ const std::uint32_t expected_msgs_round{m_kex_rounds_complete + 1};
+ const std::uint32_t kex_rounds_required{multisig_kex_rounds_required(num_signers, threshold)};
+
+ CHECK_AND_ASSERT_THROW_MES(num_signers > 1, "Must be at least one other multisig signer.");
+ CHECK_AND_ASSERT_THROW_MES(num_signers <= config::MULTISIG_MAX_SIGNERS, "Too many multisig signers specified.");
+ CHECK_AND_ASSERT_THROW_MES(expected_msgs_round < kex_rounds_required,
+ "Multisig kex booster: this account has already completed all intermediate kex rounds so it can't make a kex "
+ "booster (there is no round available to boost).");
+ CHECK_AND_ASSERT_THROW_MES(expanded_msgs.size() > 0, "At least one input kex message expected.");
+
+ // sanitize pubkeys from input msgs
+ multisig_keyset_map_memsafe_t pubkey_origins_map;
+ const std::uint32_t msgs_round{
+ multisig_kex_msgs_sanitize_pubkeys(expanded_msgs, this->get_kex_exclude_pubkeys(), pubkey_origins_map)
+ };
+ CHECK_AND_ASSERT_THROW_MES(msgs_round == expected_msgs_round, "Kex messages were not for expected round.");
+
+ // remove the local signer from sanitized messages
+ remove_key_from_mapped_sets(m_base_pubkey, pubkey_origins_map);
+
+ // make DH derivations for booster message
+ multisig_keyset_map_memsafe_t derivation_to_origins_map;
+ multisig_kex_make_round_keys(m_base_privkey, std::move(pubkey_origins_map), derivation_to_origins_map);
+
+ // collect keys for booster message
+ std::vector<crypto::public_key> next_msg_keys;
+ next_msg_keys.reserve(derivation_to_origins_map.size());
+
+ if (msgs_round + 1 == kex_rounds_required)
+ {
+ // final kex round: send DH derivation pubkeys in the message
+ for (const auto &derivation_and_origins : derivation_to_origins_map)
+ {
+ // multisig_privkey = H(derivation)
+ // derived pubkey = multisig_key * G
+ crypto::public_key_memsafe derived_pubkey;
+ calculate_multisig_keypair_from_derivation(derivation_and_origins.first, derived_pubkey);
+
+ // save keys that should be recommended to other signers
+ // - The keys multisig_key*G are sent to other participants in the message, so they can be used to produce the final
+ // multisig key via generate_multisig_spend_public_key().
+ next_msg_keys.push_back(derived_pubkey);
+ }
+ }
+ else //(msgs_round + 1 < kex_rounds_required)
+ {
+ // intermediate kex round: send DH derivations directly in the message
+ for (const auto &derivation_and_origins : derivation_to_origins_map)
+ next_msg_keys.push_back(derivation_and_origins.first);
+ }
+
+ // produce a kex message for the round after the round this account is currently working on
+ return multisig_kex_msg{msgs_round + 1, m_base_privkey, std::move(next_msg_keys)}.get_msg();
}
//----------------------------------------------------------------------------------------------------------------------
} //namespace multisig
diff --git a/src/multisig/multisig_tx_builder_ringct.cpp b/src/multisig/multisig_tx_builder_ringct.cpp
index 8643a8af4..2653a70dd 100644
--- a/src/multisig/multisig_tx_builder_ringct.cpp
+++ b/src/multisig/multisig_tx_builder_ringct.cpp
@@ -820,7 +820,6 @@ tx_builder_ringct_t::~tx_builder_ringct_t()
bool tx_builder_ringct_t::init(
const cryptonote::account_keys& account_keys,
const std::vector<std::uint8_t>& extra,
- const std::uint64_t unlock_time,
const std::uint32_t subaddr_account,
const std::set<std::uint32_t>& subaddr_minor_indices,
std::vector<cryptonote::tx_source_entry>& sources,
@@ -854,7 +853,7 @@ bool tx_builder_ringct_t::init(
// misc. fields
unsigned_tx.version = 2; //rct = 2
- unsigned_tx.unlock_time = unlock_time;
+ unsigned_tx.unlock_time = 0;
// sort inputs
sort_sources(sources);
diff --git a/src/multisig/multisig_tx_builder_ringct.h b/src/multisig/multisig_tx_builder_ringct.h
index f1bd24e73..a1b72b177 100644
--- a/src/multisig/multisig_tx_builder_ringct.h
+++ b/src/multisig/multisig_tx_builder_ringct.h
@@ -71,7 +71,6 @@ public:
bool init(
const cryptonote::account_keys& account_keys,
const std::vector<std::uint8_t>& extra,
- const std::uint64_t unlock_time,
const std::uint32_t subaddr_account,
const std::set<std::uint32_t>& subaddr_minor_indices,
std::vector<cryptonote::tx_source_entry>& sources,
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index 815c1b354..505ba026e 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -702,18 +702,18 @@ namespace nodetool
if (m_nettype == cryptonote::TESTNET)
{
full_addrs.insert("176.9.0.187:28080");
- full_addrs.insert("88.99.173.38:28080");
full_addrs.insert("51.79.173.165:28080");
full_addrs.insert("192.99.8.110:28080");
full_addrs.insert("37.187.74.171:28080");
+ full_addrs.insert("77.172.183.193:28080");
}
else if (m_nettype == cryptonote::STAGENET)
{
full_addrs.insert("176.9.0.187:38080");
- full_addrs.insert("88.99.173.38:38080");
full_addrs.insert("51.79.173.165:38080");
full_addrs.insert("192.99.8.110:38080");
full_addrs.insert("37.187.74.171:38080");
+ full_addrs.insert("77.172.183.193:38080");
}
else if (m_nettype == cryptonote::FAKECHAIN)
{
@@ -723,10 +723,10 @@ namespace nodetool
full_addrs.insert("176.9.0.187:18080");
full_addrs.insert("88.198.163.90:18080");
full_addrs.insert("66.85.74.134:18080");
- full_addrs.insert("88.99.173.38:18080");
full_addrs.insert("51.79.173.165:18080");
full_addrs.insert("192.99.8.110:18080");
full_addrs.insert("37.187.74.171:18080");
+ full_addrs.insert("77.172.183.193:18080");
}
return full_addrs;
}
@@ -857,12 +857,12 @@ namespace nodetool
if (m_nettype == cryptonote::MAINNET)
{
return {
- "xwvz3ekocr3dkyxfkmgm2hvbpzx2ysqmaxgter7znnqrhoicygkfswid.onion:18083",
- "4pixvbejrvihnkxmduo2agsnmc3rrulrqc7s3cbwwrep6h6hrzsibeqd.onion:18083",
"zbjkbsxc5munw3qusl7j2hpcmikhqocdf4pqhnhtpzw5nt5jrmofptid.onion:18083",
"qz43zul2x56jexzoqgkx2trzwcfnr6l3hbtfcfx54g4r3eahy3bssjyd.onion:18083",
"plowsof3t5hogddwabaeiyrno25efmzfxyro2vligremt7sxpsclfaid.onion:18083",
"plowsoffjexmxalw73tkjmf422gq6575fc7vicuu4javzn2ynnte6tyd.onion:18083",
+ "plowsofe6cleftfmk2raiw5h2x66atrik3nja4bfd3zrfa2hdlgworad.onion:18083",
+ "aclc4e2jhhtr44guufbnwk5bzwhaecinax4yip4wr4tjn27sjsfg6zqd.onion:18083",
};
}
return {};
@@ -870,10 +870,9 @@ namespace nodetool
if (m_nettype == cryptonote::MAINNET)
{
return {
- "s3l6ke4ed3df466khuebb4poienoingwof7oxtbo6j4n56sghe3a.b32.i2p:18080",
- "sel36x6fibfzujwvt4hf5gxolz6kd3jpvbjqg6o3ud2xtionyl2q.b32.i2p:18080",
- "uqj3aphckqtjsitz7kxx5flqpwjlq5ppr3chazfued7xucv3nheq.b32.i2p:18080",
- "vdmnehdjkpkg57nthgnjfuaqgku673r5bpbqg56ix6fyqoywgqrq.b32.i2p:18080",
+ "uqj3aphckqtjsitz7kxx5flqpwjlq5ppr3chazfued7xucv3nheq.b32.i2p",
+ "vdmnehdjkpkg57nthgnjfuaqgku673r5bpbqg56ix6fyqoywgqrq.b32.i2p",
+ "ugnlcdciyhghh2zert7c3kl4biwkirc43ke33jiy5slnd3mv2trq.b32.i2p",
};
}
return {};
@@ -2296,11 +2295,12 @@ namespace nodetool
if (enet::zone::tor < network->first)
break; // unknown network
- if (network->second.m_connect)
+ const auto status = network->second.m_notifier.get_status();
+ if (network->second.m_connect && status.has_outgoing)
return send(*network);
}
- // configuration should not allow this scenario
+ MWARNING("Unable to send " << txs.size() << " transaction(s): anonymity networks had no outgoing connections");
return enet::zone::invalid;
}
//-----------------------------------------------------------------------------------
diff --git a/src/p2p/net_peerlist.cpp b/src/p2p/net_peerlist.cpp
index 11cf235a5..78cf13785 100644
--- a/src/p2p/net_peerlist.cpp
+++ b/src/p2p/net_peerlist.cpp
@@ -42,6 +42,7 @@
#include <boost/serialization/version.hpp>
#include "net_peerlist_boost_serialization.h"
+#include "common/util.h"
namespace nodetool
@@ -200,7 +201,7 @@ namespace nodetool
if (!out)
{
// if failed, try reading in unportable mode
- boost::filesystem::copy_file(path, path + ".unportable", boost::filesystem::copy_option::overwrite_if_exists);
+ tools::copy_file(path, path + ".unportable");
src_file.close();
src_file.open( path , std::ios_base::binary | std::ios_base::in);
if(src_file.fail())
diff --git a/src/ringct/rctTypes.h b/src/ringct/rctTypes.h
index 299798e17..dea95ace0 100644
--- a/src/ringct/rctTypes.h
+++ b/src/ringct/rctTypes.h
@@ -771,7 +771,7 @@ namespace std
BLOB_SERIALIZER(rct::key);
BLOB_SERIALIZER(rct::key64);
BLOB_SERIALIZER(rct::ctkey);
-BLOB_SERIALIZER(rct::multisig_kLRki);
+BLOB_SERIALIZER_FORCED(rct::multisig_kLRki);
BLOB_SERIALIZER(rct::boroSig);
VARIANT_TAG(debug_archive, rct::key, "rct::key");
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index 9a0b02f70..16d66e79d 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -1378,6 +1378,8 @@ namespace cryptonote
add_reason(reason, "too few outputs");
if ((res.tx_extra_too_big = tvc.m_tx_extra_too_big))
add_reason(reason, "tx-extra too big");
+ if ((res.nonzero_unlock_time = tvc.m_nonzero_unlock_time))
+ add_reason(reason, "tx unlock time is not zero");
const std::string punctuation = reason.empty() ? "" : ": ";
if (tvc.m_verifivation_failed)
{
@@ -3019,16 +3021,10 @@ namespace cryptonote
CHECK_PAYMENT(req, res, COST_PER_FEE_ESTIMATE);
- const uint8_t version = m_core.get_blockchain_storage().get_current_hard_fork_version();
- if (version >= HF_VERSION_2021_SCALING)
{
m_core.get_blockchain_storage().get_dynamic_base_fee_estimate_2021_scaling(req.grace_blocks, res.fees);
res.fee = res.fees[0];
}
- else
- {
- res.fee = m_core.get_blockchain_storage().get_dynamic_base_fee_estimate(req.grace_blocks);
- }
res.quantization_mask = Blockchain::get_fee_quantization_mask();
res.status = CORE_RPC_STATUS_OK;
return true;
diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h
index 2a0a6201d..c634b8957 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 13
+#define CORE_RPC_VERSION_MINOR 14
#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)
@@ -640,6 +640,7 @@ namespace cryptonote
bool too_few_outputs;
bool sanity_check_failed;
bool tx_extra_too_big;
+ bool nonzero_unlock_time;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_PARENT(rpc_access_response_base)
@@ -655,6 +656,7 @@ namespace cryptonote
KV_SERIALIZE(too_few_outputs)
KV_SERIALIZE(sanity_check_failed)
KV_SERIALIZE(tx_extra_too_big)
+ KV_SERIALIZE(nonzero_unlock_time)
END_KV_SERIALIZE_MAP()
};
typedef epee::misc_utils::struct_init<response_t> response;
diff --git a/src/rpc/daemon_handler.cpp b/src/rpc/daemon_handler.cpp
index 52067bd4d..4712de134 100644
--- a/src/rpc/daemon_handler.cpp
+++ b/src/rpc/daemon_handler.cpp
@@ -422,6 +422,16 @@ namespace rpc
if (!res.error_details.empty()) res.error_details += " and ";
res.error_details += "too few outputs";
}
+ if (tvc.m_tx_extra_too_big)
+ {
+ if (!res.error_details.empty()) res.error_details += " and ";
+ res.error_details += "tx_extra too long";
+ }
+ if (tvc.m_nonzero_unlock_time)
+ {
+ if (!res.error_details.empty()) res.error_details += " and ";
+ res.error_details += "non-zero unlock time";
+ }
if (res.error_details.empty())
{
res.error_details = "an unknown issue was found with the transaction";
@@ -831,14 +841,11 @@ namespace rpc
void DaemonHandler::handle(const GetFeeEstimate::Request& req, GetFeeEstimate::Response& res)
{
res.hard_fork_version = m_core.get_blockchain_storage().get_current_hard_fork_version();
- res.estimated_base_fee = m_core.get_blockchain_storage().get_dynamic_base_fee_estimate(req.num_grace_blocks);
- if (res.hard_fork_version < HF_VERSION_PER_BYTE_FEE)
- {
- res.size_scale = 1024; // per KiB fee
- res.fee_mask = 1;
- }
- else
+ std::vector<uint64_t> fees;
+ m_core.get_blockchain_storage().get_dynamic_base_fee_estimate_2021_scaling(req.num_grace_blocks, fees);
+ res.estimated_base_fee = fees[0];
+
{
res.size_scale = 1; // per byte fee
res.fee_mask = Blockchain::get_fee_quantization_mask();
diff --git a/src/serialization/crypto.h b/src/serialization/crypto.h
index 896d00583..2da26abe7 100644
--- a/src/serialization/crypto.h
+++ b/src/serialization/crypto.h
@@ -81,7 +81,7 @@ BLOB_SERIALIZER(crypto::chacha_iv);
BLOB_SERIALIZER(crypto::hash);
BLOB_SERIALIZER(crypto::hash8);
BLOB_SERIALIZER(crypto::public_key);
-BLOB_SERIALIZER(crypto::secret_key);
+BLOB_SERIALIZER_FORCED(crypto::secret_key);
BLOB_SERIALIZER(crypto::key_derivation);
BLOB_SERIALIZER(crypto::key_image);
BLOB_SERIALIZER(crypto::signature);
diff --git a/src/serialization/serialization.h b/src/serialization/serialization.h
index d1f97e324..33edf3f62 100644
--- a/src/serialization/serialization.h
+++ b/src/serialization/serialization.h
@@ -50,13 +50,16 @@
#include <boost/type_traits/integral_constant.hpp>
#include <boost/mpl/bool.hpp>
-/*! \struct is_blob_type
+/*! \struct is_blob_type / is_blob_forced
*
- * \brief a descriptor for dispatching serialize
+ * \brief descriptors for dispatching serialize: whether to take byte-wise copy/store to type
*/
template <class T>
struct is_blob_type { typedef boost::false_type type; };
+template <class T>
+struct is_blob_forced: std::false_type {};
+
/*! \fn do_serialize(Archive &ar, T &v)
*
* \brief main function for dispatching serialization for a given pair of archive and value types
@@ -68,6 +71,8 @@ struct is_blob_type { typedef boost::false_type type; };
template <class Archive, class T>
inline std::enable_if_t<is_blob_type<T>::type::value, bool> do_serialize(Archive &ar, T &v)
{
+ static_assert(std::is_trivially_copyable<T>() || is_blob_forced<T>(),
+ "sanity check: types that can't be trivially copied shouldn't be using the blob serializer");
ar.serialize_blob(&v, sizeof(v));
return true;
}
@@ -94,6 +99,9 @@ inline bool do_serialize(Archive &ar, bool &v)
/*! \macro BLOB_SERIALIZER
*
* \brief makes the type have a blob serializer trait defined
+ *
+ * In case your type is not a good candidate to be blob serialized, a static assertion may be thrown
+ * at compile-time.
*/
#define BLOB_SERIALIZER(T) \
template<> \
@@ -101,6 +109,20 @@ inline bool do_serialize(Archive &ar, bool &v)
typedef boost::true_type type; \
}
+/*! \macro BLOB_SERIALIZER_FORCED
+ *
+ * \brief makes the type have a blob serializer trait defined, even if it isn't trivially copyable
+ *
+ * Caution: do NOT use this macro for your type <T>, unless you are absolutely sure that moving raw
+ * bytes in/out of this type will not cause undefined behavior. Any types with managed memory
+ * (e.g. vector, string, etc) will segfault and/or cause memory errors if you use this macro with
+ * that type.
+ */
+#define BLOB_SERIALIZER_FORCED(T) \
+ BLOB_SERIALIZER(T); \
+ template<> \
+ struct is_blob_forced<T>: std::true_type {};
+
/*! \macro VARIANT_TAG
*
* \brief Adds the tag \tag to the \a Archive of \a Type
diff --git a/src/serialization/tuple.h b/src/serialization/tuple.h
index d9592bc96..b1ef94097 100644
--- a/src/serialization/tuple.h
+++ b/src/serialization/tuple.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2023, The Monero Project
+// Copyright (c) 2014-2024, The Monero Project
//
// All rights reserved.
//
@@ -29,7 +29,7 @@
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
#pragma once
-#include <memory>
+#include <tuple>
#include "serialization.h"
namespace serialization
@@ -51,119 +51,71 @@ namespace serialization
}
}
-template <template <bool> class Archive, class E0, class E1, class E2>
-inline bool do_serialize(Archive<false>& ar, std::tuple<E0,E1,E2>& p)
+template <size_t I, bool BackwardsCompat, bool W, template <bool> class Archive, typename... Ts>
+bool do_serialize_tuple_nth(Archive<W>& ar, std::tuple<Ts...>& v)
{
- size_t cnt;
- ar.begin_array(cnt);
- if (!ar.good())
- return false;
- if (cnt != 3)
- return false;
+ static constexpr const size_t tuple_size = std::tuple_size<std::tuple<Ts...>>();
+ static_assert(I <= tuple_size, "bad call");
- if (!::serialization::detail::serialize_tuple_element(ar, std::get<0>(p)))
- return false;
- if (!ar.good())
- return false;
- ar.delimit_array();
- if (!::serialization::detail::serialize_tuple_element(ar, std::get<1>(p)))
- return false;
- if (!ar.good())
- return false;
- ar.delimit_array();
- if (!::serialization::detail::serialize_tuple_element(ar, std::get<2>(p)))
- return false;
- if (!ar.good())
- return false;
+ if constexpr (I == 0)
+ {
+ // If BackwardsCompat is true, we serialize the size of 3-tuples and 4-tuples
+ if constexpr (BackwardsCompat && (tuple_size == 3 || tuple_size == 4))
+ {
+ size_t cnt = tuple_size;
+ ar.begin_array(cnt);
+ if (cnt != tuple_size)
+ return false;
+ }
+ else
+ {
+ ar.begin_array();
+ }
+ }
+ else if constexpr (I < tuple_size)
+ {
+ ar.delimit_array();
+ }
- ar.end_array();
- return true;
+ if constexpr (I == tuple_size)
+ {
+ ar.end_array();
+ return ar.good();
+ }
+ else
+ {
+ if (!::serialization::detail::serialize_tuple_element(ar, std::get<I>(v))
+ || !ar.good())
+ return false;
+
+ return do_serialize_tuple_nth<I + 1, BackwardsCompat>(ar, v);
+ }
}
-template <template <bool> class Archive, class E0, class E1, class E2>
-inline bool do_serialize(Archive<true>& ar, std::tuple<E0,E1,E2>& p)
+template <bool BackwardsCompat, bool W, template <bool> class Archive, typename... Ts>
+bool do_serialize_tuple(Archive<W>& ar, std::tuple<Ts...>& v)
{
- ar.begin_array(3);
- if (!ar.good())
- return false;
- if(!::serialization::detail::serialize_tuple_element(ar, std::get<0>(p)))
- return false;
- if (!ar.good())
- return false;
- ar.delimit_array();
- if(!::serialization::detail::serialize_tuple_element(ar, std::get<1>(p)))
- return false;
- if (!ar.good())
- return false;
- ar.delimit_array();
- if(!::serialization::detail::serialize_tuple_element(ar, std::get<2>(p)))
- return false;
- if (!ar.good())
- return false;
- ar.end_array();
- return true;
+ return do_serialize_tuple_nth<0, BackwardsCompat>(ar, v);
}
-template <template <bool> class Archive, class E0, class E1, class E2, class E3>
-inline bool do_serialize(Archive<false>& ar, std::tuple<E0,E1,E2,E3>& p)
+template <bool W, template <bool> class Archive, typename... Ts>
+bool do_serialize(Archive<W>& ar, std::tuple<Ts...>& v)
{
- size_t cnt;
- ar.begin_array(cnt);
- if (!ar.good())
- return false;
- if (cnt != 4)
- return false;
+ return do_serialize_tuple<true>(ar, v);
+}
- if (!::serialization::detail::serialize_tuple_element(ar, std::get<0>(p)))
- return false;
- if (!ar.good())
- return false;
- ar.delimit_array();
- if (!::serialization::detail::serialize_tuple_element(ar, std::get<1>(p)))
- return false;
- if (!ar.good())
- return false;
- ar.delimit_array();
- if (!::serialization::detail::serialize_tuple_element(ar, std::get<2>(p)))
- return false;
- if (!ar.good())
- return false;
- ar.delimit_array();
- if (!::serialization::detail::serialize_tuple_element(ar, std::get<3>(p)))
- return false;
- if (!ar.good())
- return false;
+#define TUPLE_COMPACT_FIELDS(v) \
+ do { \
+ if (!do_serialize_tuple<false>(ar, v) || !ar.good()) \
+ return false; \
+ } while (0);
- ar.end_array();
- return true;
-}
+#define TUPLE_COMPACT_FIELD_N(t, v) \
+ do { \
+ ar.tag(t); \
+ TUPLE_COMPACT_FIELDS(v); \
+ } while (0);
-template <template <bool> class Archive, class E0, class E1, class E2, class E3>
-inline bool do_serialize(Archive<true>& ar, std::tuple<E0,E1,E2,E3>& p)
-{
- ar.begin_array(4);
- if (!ar.good())
- return false;
- if(!::serialization::detail::serialize_tuple_element(ar, std::get<0>(p)))
- return false;
- if (!ar.good())
- return false;
- ar.delimit_array();
- if(!::serialization::detail::serialize_tuple_element(ar, std::get<1>(p)))
- return false;
- if (!ar.good())
- return false;
- ar.delimit_array();
- if(!::serialization::detail::serialize_tuple_element(ar, std::get<2>(p)))
- return false;
- if (!ar.good())
- return false;
- ar.delimit_array();
- if(!::serialization::detail::serialize_tuple_element(ar, std::get<3>(p)))
- return false;
- if (!ar.good())
- return false;
- ar.end_array();
- return true;
-}
+#define TUPLE_COMPACT_FIELD(f) TUPLE_COMPACT_FIELD_N(#f, f)
+#define TUPLE_COMPACT_FIELD_F(f) TUPLE_COMPACT_FIELD_N(#f, v.f)
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 5a9d790cb..4f76834e3 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -148,10 +148,16 @@ typedef cryptonote::simple_wallet sw;
} \
} while(0)
-enum TransferType {
- Transfer,
- TransferLocked,
-};
+#define CHECK_IF_BACKGROUND_SYNCING(msg) \
+ do \
+ { \
+ if (m_wallet->is_background_wallet() || m_wallet->is_background_syncing()) \
+ { \
+ std::string type = m_wallet->is_background_wallet() ? "background wallet" : "background syncing wallet"; \
+ fail_msg_writer() << boost::format(tr("%s %s")) % type % msg; \
+ return false; \
+ } \
+ } while (0)
static std::string get_human_readable_timespan(std::chrono::seconds seconds);
static std::string get_human_readable_timespan(uint64_t seconds);
@@ -189,8 +195,6 @@ namespace
const char* USAGE_PAYMENTS("payments <PID_1> [<PID_2> ... <PID_N>]");
const char* USAGE_PAYMENT_ID("payment_id");
const char* USAGE_TRANSFER("transfer [index=<N1>[,<N2>,...]] [<priority>] [<ring_size>] (<URI> | <address> <amount>) [subtractfeefrom=<D0>[,<D1>,all,...]] [<payment_id>]");
- const char* USAGE_LOCKED_TRANSFER("locked_transfer [index=<N1>[,<N2>,...]] [<priority>] [<ring_size>] (<URI> | <addr> <amount>) <lockblocks> [<payment_id (obsolete)>]");
- const char* USAGE_LOCKED_SWEEP_ALL("locked_sweep_all [index=<N1>[,<N2>,...] | index=all] [<priority>] [<ring_size>] <address> <lockblocks> [<payment_id (obsolete)>]");
const char* USAGE_SWEEP_ALL("sweep_all [index=<N1>[,<N2>,...] | index=all] [<priority>] [<ring_size>] [outputs=<N>] <address> [<payment_id (obsolete)>]");
const char* USAGE_SWEEP_ACCOUNT("sweep_account <account> [index=<N1>[,<N2>,...] | index=all] [<priority>] [<ring_size>] [outputs=<N>] <address> [<payment_id (obsolete)>]");
const char* USAGE_SWEEP_BELOW("sweep_below <amount_threshold> [index=<N1>[,<N2>,...]] [<priority>] [<ring_size>] <address> [<payment_id (obsolete)>]");
@@ -321,7 +325,7 @@ namespace
auto pwd_container = tools::password_container::prompt(verify, prompt);
if (!pwd_container)
{
- tools::fail_msg_writer() << sw::tr("failed to read wallet password");
+ tools::fail_msg_writer() << sw::tr("failed to read password");
}
return pwd_container;
}
@@ -331,6 +335,11 @@ namespace
return password_prompter(verify ? sw::tr("Enter a new password for the wallet") : sw::tr("Wallet password"), verify);
}
+ boost::optional<tools::password_container> background_sync_cache_password_prompter(bool verify)
+ {
+ return password_prompter(verify ? sw::tr("Enter a custom password for the background sync cache") : sw::tr("Background sync cache password"), verify);
+ }
+
inline std::string interpret_rpc_response(bool ok, const std::string& status)
{
std::string err;
@@ -448,6 +457,41 @@ namespace
return "invalid";
}
+ const struct
+ {
+ const char *name;
+ tools::wallet2::BackgroundSyncType background_sync_type;
+ } background_sync_type_names[] =
+ {
+ { "off", tools::wallet2::BackgroundSyncOff },
+ { "reuse-wallet-password", tools::wallet2::BackgroundSyncReusePassword },
+ { "custom-background-password", tools::wallet2::BackgroundSyncCustomPassword },
+ };
+
+ bool parse_background_sync_type(const std::string &s, tools::wallet2::BackgroundSyncType &background_sync_type)
+ {
+ for (size_t n = 0; n < sizeof(background_sync_type_names) / sizeof(background_sync_type_names[0]); ++n)
+ {
+ if (s == background_sync_type_names[n].name)
+ {
+ background_sync_type = background_sync_type_names[n].background_sync_type;
+ return true;
+ }
+ }
+ fail_msg_writer() << cryptonote::simple_wallet::tr("failed to parse background sync type");
+ return false;
+ }
+
+ std::string get_background_sync_type_name(tools::wallet2::BackgroundSyncType type)
+ {
+ for (size_t n = 0; n < sizeof(background_sync_type_names) / sizeof(background_sync_type_names[0]); ++n)
+ {
+ if (type == background_sync_type_names[n].background_sync_type)
+ return background_sync_type_names[n].name;
+ }
+ return "invalid";
+ }
+
std::string get_version_string(uint32_t version)
{
return boost::lexical_cast<std::string>(version >> 16) + "." + boost::lexical_cast<std::string>(version & 0xffff);
@@ -800,6 +844,7 @@ bool simple_wallet::spendkey(const std::vector<std::string> &args/* = std::vecto
fail_msg_writer() << tr("wallet is watch-only and has no spend key");
return true;
}
+ CHECK_IF_BACKGROUND_SYNCING("has no spend key");
// don't log
PAUSE_READLINE();
if (m_wallet->key_on_device()) {
@@ -819,7 +864,6 @@ bool simple_wallet::print_seed(bool encrypted)
{
bool success = false;
epee::wipeable_string seed;
- bool ready, multisig;
if (m_wallet->key_on_device())
{
@@ -831,11 +875,12 @@ bool simple_wallet::print_seed(bool encrypted)
fail_msg_writer() << tr("wallet is watch-only and has no seed");
return true;
}
+ CHECK_IF_BACKGROUND_SYNCING("has no seed");
- multisig = m_wallet->multisig(&ready);
- if (multisig)
+ const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
+ if (ms_status.multisig_is_active)
{
- if (!ready)
+ if (!ms_status.is_ready)
{
fail_msg_writer() << tr("wallet is multisig but not yet finalized");
return true;
@@ -844,7 +889,7 @@ bool simple_wallet::print_seed(bool encrypted)
SCOPED_WALLET_UNLOCK();
- if (!multisig && !m_wallet->is_deterministic())
+ if (!ms_status.multisig_is_active && !m_wallet->is_deterministic())
{
fail_msg_writer() << tr("wallet is non-deterministic and has no seed");
return true;
@@ -859,7 +904,7 @@ bool simple_wallet::print_seed(bool encrypted)
seed_pass = pwd_container->password();
}
- if (multisig)
+ if (ms_status.multisig_is_active)
success = m_wallet->get_multisig_seed(seed, seed_pass);
else if (m_wallet->is_deterministic())
success = m_wallet->get_seed(seed, seed_pass);
@@ -898,7 +943,7 @@ bool simple_wallet::seed_set_language(const std::vector<std::string> &args/* = s
fail_msg_writer() << tr("command not supported by HW wallet");
return true;
}
- if (m_wallet->multisig())
+ if (m_wallet->get_multisig_status().multisig_is_active)
{
fail_msg_writer() << tr("wallet is multisig and has no seed");
return true;
@@ -908,6 +953,7 @@ bool simple_wallet::seed_set_language(const std::vector<std::string> &args/* = s
fail_msg_writer() << tr("wallet is watch-only and has no seed");
return true;
}
+ CHECK_IF_BACKGROUND_SYNCING("has no seed");
epee::wipeable_string password;
{
@@ -1044,7 +1090,7 @@ bool simple_wallet::prepare_multisig_main(const std::vector<std::string> &args,
fail_msg_writer() << tr("command not supported by HW wallet");
return false;
}
- if (m_wallet->multisig())
+ if (m_wallet->get_multisig_status().multisig_is_active)
{
fail_msg_writer() << tr("This wallet is already multisig");
return false;
@@ -1054,6 +1100,7 @@ bool simple_wallet::prepare_multisig_main(const std::vector<std::string> &args,
fail_msg_writer() << tr("wallet is watch-only and cannot be made multisig");
return false;
}
+ CHECK_IF_BACKGROUND_SYNCING("cannot be made multisig");
if(m_wallet->get_num_transfer_details())
{
@@ -1091,7 +1138,7 @@ bool simple_wallet::make_multisig_main(const std::vector<std::string> &args, boo
fail_msg_writer() << tr("command not supported by HW wallet");
return false;
}
- if (m_wallet->multisig())
+ if (m_wallet->get_multisig_status().multisig_is_active)
{
fail_msg_writer() << tr("This wallet is already multisig");
return false;
@@ -1136,9 +1183,7 @@ bool simple_wallet::make_multisig_main(const std::vector<std::string> &args, boo
auto local_args = args;
local_args.erase(local_args.begin());
std::string multisig_extra_info = m_wallet->make_multisig(orig_pwd_container->password(), local_args, threshold);
- bool ready;
- m_wallet->multisig(&ready);
- if (!ready)
+ if (!m_wallet->get_multisig_status().is_ready)
{
success_msg_writer() << tr("Another step is needed");
success_msg_writer() << multisig_extra_info;
@@ -1156,13 +1201,13 @@ bool simple_wallet::make_multisig_main(const std::vector<std::string> &args, boo
return false;
}
- uint32_t total;
- if (!m_wallet->multisig(NULL, &threshold, &total))
+ const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
+ if (!ms_status.multisig_is_active)
{
fail_msg_writer() << tr("Error creating multisig: new wallet is not multisig");
return false;
}
- success_msg_writer() << std::to_string(threshold) << "/" << total << tr(" multisig address: ")
+ success_msg_writer() << std::to_string(ms_status.threshold) << "/" << ms_status.total << tr(" multisig address: ")
<< m_wallet->get_account().get_public_address_str(m_wallet->nettype());
return true;
@@ -1188,18 +1233,18 @@ bool simple_wallet::exchange_multisig_keys_main(const std::vector<std::string> &
const bool force_update_use_with_caution,
const bool called_by_mms) {
CHECK_MULTISIG_ENABLED();
- bool ready;
+ const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
if (m_wallet->key_on_device())
{
fail_msg_writer() << tr("command not supported by HW wallet");
return false;
}
- if (!m_wallet->multisig(&ready))
+ if (!ms_status.multisig_is_active)
{
fail_msg_writer() << tr("This wallet is not multisig");
return false;
}
- if (ready)
+ if (ms_status.is_ready)
{
fail_msg_writer() << tr("This wallet is already finalized");
return false;
@@ -1215,9 +1260,7 @@ bool simple_wallet::exchange_multisig_keys_main(const std::vector<std::string> &
try
{
std::string multisig_extra_info = m_wallet->exchange_multisig_keys(orig_pwd_container->password(), args, force_update_use_with_caution);
- bool ready;
- m_wallet->multisig(&ready);
- if (!ready)
+ if (!m_wallet->get_multisig_status().is_ready)
{
message_writer() << tr("Another step is needed");
message_writer() << multisig_extra_info;
@@ -1228,9 +1271,8 @@ bool simple_wallet::exchange_multisig_keys_main(const std::vector<std::string> &
}
return true;
} else {
- uint32_t threshold, total;
- m_wallet->multisig(NULL, &threshold, &total);
- success_msg_writer() << tr("Multisig wallet has been successfully created. Current wallet type: ") << threshold << "/" << total;
+ const multisig::multisig_account_status ms_status_new{m_wallet->get_multisig_status()};
+ success_msg_writer() << tr("Multisig wallet has been successfully created. Current wallet type: ") << ms_status_new.threshold << "/" << ms_status_new.total;
success_msg_writer() << tr("Multisig address: ") << m_wallet->get_account().get_public_address_str(m_wallet->nettype());
}
}
@@ -1253,18 +1295,18 @@ bool simple_wallet::export_multisig(const std::vector<std::string> &args)
bool simple_wallet::export_multisig_main(const std::vector<std::string> &args, bool called_by_mms)
{
CHECK_MULTISIG_ENABLED();
- bool ready;
+ const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
if (m_wallet->key_on_device())
{
fail_msg_writer() << tr("command not supported by HW wallet");
return false;
}
- if (!m_wallet->multisig(&ready))
+ if (!ms_status.multisig_is_active)
{
fail_msg_writer() << tr("This wallet is not multisig");
return false;
}
- if (!ready)
+ if (!ms_status.is_ready)
{
fail_msg_writer() << tr("This multisig wallet is not yet finalized");
return false;
@@ -1320,24 +1362,24 @@ bool simple_wallet::import_multisig(const std::vector<std::string> &args)
bool simple_wallet::import_multisig_main(const std::vector<std::string> &args, bool called_by_mms)
{
CHECK_MULTISIG_ENABLED();
- bool ready;
- uint32_t threshold, total;
+ const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
+
if (m_wallet->key_on_device())
{
fail_msg_writer() << tr("command not supported by HW wallet");
return false;
}
- if (!m_wallet->multisig(&ready, &threshold, &total))
+ if (!ms_status.multisig_is_active)
{
fail_msg_writer() << tr("This wallet is not multisig");
return false;
}
- if (!ready)
+ if (!ms_status.is_ready)
{
fail_msg_writer() << tr("This multisig wallet is not yet finalized");
return false;
}
- if (args.size() < threshold - 1)
+ if (args.size() + 1 < ms_status.threshold)
{
PRINT_USAGE(USAGE_IMPORT_MULTISIG_INFO);
return false;
@@ -1417,18 +1459,19 @@ bool simple_wallet::sign_multisig(const std::vector<std::string> &args)
bool simple_wallet::sign_multisig_main(const std::vector<std::string> &args, bool called_by_mms)
{
CHECK_MULTISIG_ENABLED();
- bool ready;
+ const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};\
+
if (m_wallet->key_on_device())
{
fail_msg_writer() << tr("command not supported by HW wallet");
return false;
}
- if(!m_wallet->multisig(&ready))
+ if (!ms_status.multisig_is_active)
{
fail_msg_writer() << tr("This is not a multisig wallet");
return false;
}
- if (!ready)
+ if (!ms_status.is_ready)
{
fail_msg_writer() << tr("This multisig wallet is not yet finalized");
return false;
@@ -1502,9 +1545,7 @@ bool simple_wallet::sign_multisig_main(const std::vector<std::string> &args, boo
if (txids.empty())
{
- uint32_t threshold;
- m_wallet->multisig(NULL, &threshold);
- uint32_t signers_needed = threshold - signers - 1;
+ uint32_t signers_needed = ms_status.threshold - signers - 1;
success_msg_writer(true) << tr("Transaction successfully signed to file ") << filename << ", "
<< signers_needed << " more signer(s) needed";
return true;
@@ -1534,19 +1575,19 @@ bool simple_wallet::submit_multisig(const std::vector<std::string> &args)
bool simple_wallet::submit_multisig_main(const std::vector<std::string> &args, bool called_by_mms)
{
CHECK_MULTISIG_ENABLED();
- bool ready;
- uint32_t threshold;
+ const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
+
if (m_wallet->key_on_device())
{
fail_msg_writer() << tr("command not supported by HW wallet");
return false;
}
- if (!m_wallet->multisig(&ready, &threshold))
+ if (!ms_status.multisig_is_active)
{
fail_msg_writer() << tr("This is not a multisig wallet");
return false;
}
- if (!ready)
+ if (!ms_status.is_ready)
{
fail_msg_writer() << tr("This multisig wallet is not yet finalized");
return false;
@@ -1584,10 +1625,10 @@ bool simple_wallet::submit_multisig_main(const std::vector<std::string> &args, b
return false;
}
}
- if (txs.m_signers.size() < threshold)
+ if (txs.m_signers.size() < ms_status.threshold)
{
fail_msg_writer() << (boost::format(tr("Multisig transaction signed by only %u signers, needs %u more signatures"))
- % txs.m_signers.size() % (threshold - txs.m_signers.size())).str();
+ % txs.m_signers.size() % (ms_status.threshold - txs.m_signers.size())).str();
return false;
}
@@ -1616,19 +1657,19 @@ bool simple_wallet::submit_multisig_main(const std::vector<std::string> &args, b
bool simple_wallet::export_raw_multisig(const std::vector<std::string> &args)
{
CHECK_MULTISIG_ENABLED();
- bool ready;
- uint32_t threshold;
+ const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
+
if (m_wallet->key_on_device())
{
fail_msg_writer() << tr("command not supported by HW wallet");
return true;
}
- if (!m_wallet->multisig(&ready, &threshold))
+ if (!ms_status.multisig_is_active)
{
fail_msg_writer() << tr("This is not a multisig wallet");
return true;
}
- if (!ready)
+ if (!ms_status.is_ready)
{
fail_msg_writer() << tr("This multisig wallet is not yet finalized");
return true;
@@ -1654,10 +1695,10 @@ bool simple_wallet::export_raw_multisig(const std::vector<std::string> &args)
fail_msg_writer() << tr("Failed to load multisig transaction from file");
return true;
}
- if (txs.m_signers.size() < threshold)
+ if (txs.m_signers.size() < ms_status.threshold)
{
fail_msg_writer() << (boost::format(tr("Multisig transaction signed by only %u signers, needs %u more signatures"))
- % txs.m_signers.size() % (threshold - txs.m_signers.size())).str();
+ % txs.m_signers.size() % (ms_status.threshold - txs.m_signers.size())).str();
return true;
}
@@ -2119,6 +2160,7 @@ bool simple_wallet::save_known_rings(const std::vector<std::string> &args)
bool simple_wallet::freeze_thaw(const std::vector<std::string> &args, bool freeze)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot freeze/thaw");
if (args.empty())
{
fail_msg_writer() << boost::format(tr("usage: %s <key_image>|<pubkey>")) % (freeze ? "freeze" : "thaw");
@@ -2158,6 +2200,7 @@ bool simple_wallet::thaw(const std::vector<std::string> &args)
bool simple_wallet::frozen(const std::vector<std::string> &args)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot see frozen key images");
if (args.empty())
{
size_t ntd = m_wallet->get_num_transfer_details();
@@ -2808,6 +2851,57 @@ bool simple_wallet::set_track_uses(const std::vector<std::string> &args/* = std:
return true;
}
+bool simple_wallet::setup_background_sync(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
+{
+ if (m_wallet->get_multisig_status().multisig_is_active)
+ {
+ fail_msg_writer() << tr("background sync not implemented for multisig wallet");
+ return true;
+ }
+ if (m_wallet->watch_only())
+ {
+ fail_msg_writer() << tr("background sync not implemented for watch only wallet");
+ return true;
+ }
+ if (m_wallet->key_on_device())
+ {
+ fail_msg_writer() << tr("command not supported by HW wallet");
+ return true;
+ }
+
+ tools::wallet2::BackgroundSyncType background_sync_type;
+ if (!parse_background_sync_type(args[1], background_sync_type))
+ {
+ fail_msg_writer() << tr("invalid option");
+ return true;
+ }
+
+ const auto pwd_container = get_and_verify_password();
+ if (!pwd_container)
+ return true;
+
+ try
+ {
+ boost::optional<epee::wipeable_string> background_cache_password = boost::none;
+ if (background_sync_type == tools::wallet2::BackgroundSyncCustomPassword)
+ {
+ const auto background_pwd_container = background_sync_cache_password_prompter(true);
+ if (!background_pwd_container)
+ return true;
+ background_cache_password = background_pwd_container->password();
+ }
+
+ LOCK_IDLE_SCOPE();
+ m_wallet->setup_background_sync(background_sync_type, pwd_container->password(), background_cache_password);
+ }
+ catch (const std::exception &e)
+ {
+ fail_msg_writer() << tr("Error setting background sync type: ") << e.what();
+ }
+
+ return true;
+}
+
bool simple_wallet::set_show_wallet_name_when_locked(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
{
const auto pwd_container = get_and_verify_password();
@@ -3040,6 +3134,7 @@ bool simple_wallet::apropos(const std::vector<std::string> &args)
bool simple_wallet::scan_tx(const std::vector<std::string> &args)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot scan tx");
if (args.empty())
{
PRINT_USAGE(USAGE_SCAN_TX);
@@ -3126,14 +3221,6 @@ simple_wallet::simple_wallet()
m_cmd_binder.set_handler("transfer", boost::bind(&simple_wallet::on_command, this, &simple_wallet::transfer, _1),
tr(USAGE_TRANSFER),
tr("Transfer <amount> to <address>. If the parameter \"index=<N1>[,<N2>,...]\" is specified, the wallet uses outputs received by addresses of those indices. If omitted, the wallet randomly chooses address indices to be used. In any case, it tries its best not to combine outputs across multiple addresses. <priority> is the priority of the transaction. The higher the priority, the higher the transaction fee. Valid values in priority order (from lowest to highest) are: unimportant, normal, elevated, priority. If omitted, the default value (see the command \"set priority\") is used. <ring_size> is the number of inputs to include for untraceability. Multiple payments can be made at once by adding URI_2 or <address_2> <amount_2> etcetera (before the payment ID, if it's included). The \"subtractfeefrom=\" list allows you to choose which destinations to fund the tx fee from instead of the change output. The fee will be split across the chosen destinations proportionally equally. For example, to make 3 transfers where the fee is taken from the first and third destinations, one could do: \"transfer <addr1> 3 <addr2> 0.5 <addr3> 1 subtractfeefrom=0,2\". Let's say the tx fee is 0.1. The balance would drop by exactly 4.5 XMR including fees, and addr1 & addr3 would receive 2.925 & 0.975 XMR, respectively. Use \"subtractfeefrom=all\" to spread the fee across all destinations."));
- m_cmd_binder.set_handler("locked_transfer",
- boost::bind(&simple_wallet::on_command, this, &simple_wallet::locked_transfer,_1),
- tr(USAGE_LOCKED_TRANSFER),
- tr("Transfer <amount> to <address> and lock it for <lockblocks> (max. 1000000). If the parameter \"index=<N1>[,<N2>,...]\" is specified, the wallet uses outputs received by addresses of those indices. If omitted, the wallet randomly chooses address indices to be used. In any case, it tries its best not to combine outputs across multiple addresses. <priority> is the priority of the transaction. The higher the priority, the higher the transaction fee. Valid values in priority order (from lowest to highest) are: unimportant, normal, elevated, priority. If omitted, the default value (see the command \"set priority\") is used. <ring_size> is the number of inputs to include for untraceability. Multiple payments can be made at once by adding URI_2 or <address_2> <amount_2> etcetera (before the payment ID, if it's included)"));
- m_cmd_binder.set_handler("locked_sweep_all",
- boost::bind(&simple_wallet::on_command, this, &simple_wallet::locked_sweep_all,_1),
- tr(USAGE_LOCKED_SWEEP_ALL),
- tr("Send all unlocked balance to an address and lock it for <lockblocks> (max. 1000000). If the parameter \"index=<N1>[,<N2>,...]\" or \"index=all\" is specified, the wallet sweeps outputs received by those or all address indices, respectively. If omitted, the wallet randomly chooses an address index to be used. <priority> is the priority of the sweep. The higher the priority, the higher the transaction fee. Valid values in priority order (from lowest to highest) are: unimportant, normal, elevated, priority. If omitted, the default value (see the command \"set priority\") is used. <ring_size> is the number of inputs to include for untraceability."));
m_cmd_binder.set_handler("sweep_unmixable",
boost::bind(&simple_wallet::on_command, this, &simple_wallet::sweep_unmixable, _1),
tr("Send all unmixable outputs to yourself with ring_size 1"));
@@ -3265,6 +3352,8 @@ simple_wallet::simple_wallet()
" Ignore outputs of amount below this threshold when spending.\n "
"track-uses <1|0>\n "
" Whether to keep track of owned outputs uses.\n "
+ "background-sync <off|reuse-wallet-password|custom-background-password>\n "
+ " Set this to enable scanning in the background with just the view key while the wallet is locked.\n "
"setup-background-mining <1|0>\n "
" Whether to enable background mining. Set this to support the network and to get a chance to receive new monero.\n "
"device-name <device_name[:device_spec]>\n "
@@ -3667,6 +3756,7 @@ bool simple_wallet::set_variable(const std::vector<std::string> &args)
success_msg_writer() << "ignore-outputs-above = " << cryptonote::print_money(m_wallet->ignore_outputs_above());
success_msg_writer() << "ignore-outputs-below = " << cryptonote::print_money(m_wallet->ignore_outputs_below());
success_msg_writer() << "track-uses = " << m_wallet->track_uses();
+ success_msg_writer() << "background-sync = " << get_background_sync_type_name(m_wallet->background_sync_type());
success_msg_writer() << "setup-background-mining = " << setup_background_mining_string;
success_msg_writer() << "device-name = " << m_wallet->device_name();
success_msg_writer() << "export-format = " << (m_wallet->export_format() == tools::wallet2::ExportFormat::Ascii ? "ascii" : "binary");
@@ -3682,6 +3772,7 @@ bool simple_wallet::set_variable(const std::vector<std::string> &args)
}
else
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot change wallet settings");
#define CHECK_SIMPLE_VARIABLE(name, f, help) do \
if (args[0] == name) { \
@@ -3735,6 +3826,7 @@ bool simple_wallet::set_variable(const std::vector<std::string> &args)
CHECK_SIMPLE_VARIABLE("ignore-outputs-above", set_ignore_outputs_above, tr("amount"));
CHECK_SIMPLE_VARIABLE("ignore-outputs-below", set_ignore_outputs_below, tr("amount"));
CHECK_SIMPLE_VARIABLE("track-uses", set_track_uses, tr("0 or 1"));
+ CHECK_SIMPLE_VARIABLE("background-sync", setup_background_sync, tr("off (default); reuse-wallet-password (reuse the wallet password to encrypt the background cache); custom-background-password (use a custom background password to encrypt the background cache)"));
CHECK_SIMPLE_VARIABLE("show-wallet-name-when-locked", set_show_wallet_name_when_locked, tr("1 or 0"));
CHECK_SIMPLE_VARIABLE("inactivity-lock-timeout", set_inactivity_lock_timeout, tr("unsigned integer (seconds, 0 to disable)"));
CHECK_SIMPLE_VARIABLE("setup-background-mining", set_setup_background_mining, tr("1/yes or 0/no"));
@@ -3838,7 +3930,7 @@ bool simple_wallet::ask_wallet_create_if_needed()
bool ok = true;
if (!m_restoring)
{
- message_writer() << tr("Looking for filename: ") << boost::filesystem::complete(wallet_path);
+ message_writer() << tr("Looking for filename: ") << boost::filesystem::absolute(wallet_path);
message_writer() << tr("No wallet found with that name. Confirm creation of new wallet named: ") << wallet_path;
confirm_creation = input_line("", true);
if(std::cin.eof())
@@ -3870,7 +3962,7 @@ void simple_wallet::print_seed(const epee::wipeable_string &seed)
{
success_msg_writer(true) << "\n" << boost::format(tr("NOTE: the following %s can be used to recover access to your wallet. "
"Write them down and store them somewhere safe and secure. Please do not store them in "
- "your email or on file storage services outside of your immediate control.\n")) % (m_wallet->multisig() ? tr("string") : tr("25 words"));
+ "your email or on file storage services outside of your immediate control.\n")) % (m_wallet->get_multisig_status().multisig_is_active ? tr("string") : tr("25 words"));
// don't log
int space_index = 0;
size_t len = seed.size();
@@ -4675,7 +4767,10 @@ std::string simple_wallet::get_mnemonic_language()
//----------------------------------------------------------------------------------------------------
boost::optional<tools::password_container> simple_wallet::get_and_verify_password() const
{
- auto pwd_container = default_password_prompter(m_wallet_file.empty());
+ const bool verify = m_wallet_file.empty();
+ auto pwd_container = (m_wallet->is_background_wallet() && m_wallet->background_sync_type() == tools::wallet2::BackgroundSyncCustomPassword)
+ ? background_sync_cache_password_prompter(verify)
+ : default_password_prompter(verify);
if (!pwd_container)
return boost::none;
@@ -4774,7 +4869,7 @@ boost::optional<epee::wipeable_string> simple_wallet::new_wallet(const boost::pr
"your current session's state. Otherwise, you might need to synchronize \n"
"your wallet again (your wallet keys are NOT at risk in any case).\n")
;
- success_msg_writer() << tr("Filename: ") << boost::filesystem::complete(m_wallet->get_keys_file());
+ success_msg_writer() << tr("Filename: ") << boost::filesystem::absolute(m_wallet->get_keys_file());
if (!two_random)
{
@@ -4922,14 +5017,14 @@ boost::optional<epee::wipeable_string> simple_wallet::new_wallet(const boost::pr
const epee::wipeable_string &msig_keys = m_wallet->decrypt<epee::wipeable_string>(std::string(multisig_keys.data(), multisig_keys.size()), key, true);
m_wallet->generate(m_wallet_file, std::move(rc.second).password(), msig_keys, create_address_file);
}
- bool ready;
- uint32_t threshold, total;
- if (!m_wallet->multisig(&ready, &threshold, &total) || !ready)
+ const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
+
+ if (!ms_status.multisig_is_active || !ms_status.is_ready)
{
fail_msg_writer() << tr("failed to generate new mutlisig wallet");
return {};
}
- message_writer(console_color_white, true) << boost::format(tr("Generated new %u/%u multisig wallet: ")) % threshold % total
+ message_writer(console_color_white, true) << boost::format(tr("Generated new %u/%u multisig wallet: ")) % ms_status.threshold % ms_status.total
<< m_wallet->get_account().get_public_address_str(m_wallet->nettype());
}
catch (const std::exception& e)
@@ -4973,12 +5068,13 @@ boost::optional<epee::wipeable_string> simple_wallet::open_wallet(const boost::p
m_wallet->callback(this);
m_wallet->load(m_wallet_file, password);
std::string prefix;
- bool ready;
- uint32_t threshold, total;
+ const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
if (m_wallet->watch_only())
prefix = tr("Opened watch-only wallet");
- else if (m_wallet->multisig(&ready, &threshold, &total))
- prefix = (boost::format(tr("Opened %u/%u multisig wallet%s")) % threshold % total % (ready ? "" : " (not yet finalized)")).str();
+ else if (ms_status.multisig_is_active)
+ prefix = (boost::format(tr("Opened %u/%u multisig wallet%s")) % ms_status.threshold % ms_status.total % (ms_status.is_ready ? "" : " (not yet finalized)")).str();
+ else if (m_wallet->is_background_wallet())
+ prefix = tr("Opened background wallet");
else
prefix = tr("Opened wallet");
message_writer(console_color_white, true) <<
@@ -5096,7 +5192,7 @@ bool simple_wallet::save(const std::vector<std::string> &args)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::save_watch_only(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
{
- if (m_wallet->multisig())
+ if (m_wallet->get_multisig_status().multisig_is_active)
{
fail_msg_writer() << tr("wallet is multisig and cannot save a watch-only version");
return true;
@@ -5186,6 +5282,10 @@ void simple_wallet::stop_background_mining()
//----------------------------------------------------------------------------------------------------
void simple_wallet::check_background_mining(const epee::wipeable_string &password)
{
+ // Background mining can be toggled from the main wallet
+ if (m_wallet->is_background_wallet() || m_wallet->is_background_syncing())
+ return;
+
tools::wallet2::BackgroundMiningSetupType setup = m_wallet->setup_background_mining();
if (setup == tools::wallet2::BackgroundMiningNo)
{
@@ -6001,6 +6101,7 @@ bool simple_wallet::show_blockchain_height(const std::vector<std::string>& args)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::rescan_spent(const std::vector<std::string> &args)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot rescan spent");
if (!m_wallet->is_trusted_daemon())
{
fail_msg_writer() << tr("this command requires a trusted daemon. Enable with --trusted-daemon");
@@ -6256,10 +6357,27 @@ void simple_wallet::check_for_inactivity_lock(bool user)
" || ||" << std::endl <<
"" << std::endl;
}
+
+ bool started_background_sync = false;
+ if (!m_wallet->is_background_wallet() &&
+ m_wallet->background_sync_type() != tools::wallet2::BackgroundSyncOff)
+ {
+ LOCK_IDLE_SCOPE();
+ m_wallet->start_background_sync();
+ started_background_sync = true;
+ }
+
while (1)
{
const char *inactivity_msg = user ? "" : tr("Locked due to inactivity.");
- tools::msg_writer() << inactivity_msg << (inactivity_msg[0] ? " " : "") << tr("The wallet password is required to unlock the console.");
+ tools::msg_writer() << inactivity_msg << (inactivity_msg[0] ? " " : "") << (
+ (m_wallet->is_background_wallet() && m_wallet->background_sync_type() == tools::wallet2::BackgroundSyncCustomPassword)
+ ? tr("The background password is required to unlock the console.")
+ : tr("The wallet password is required to unlock the console.")
+ );
+
+ if (m_wallet->is_background_syncing())
+ tools::msg_writer() << tr("\nSyncing in the background while locked...") << std::endl;
const bool show_wallet_name = m_wallet->show_wallet_name_when_locked();
if (show_wallet_name)
@@ -6272,8 +6390,16 @@ void simple_wallet::check_for_inactivity_lock(bool user)
}
try
{
- if (get_and_verify_password())
+ const auto pwd_container = get_and_verify_password();
+ if (pwd_container)
+ {
+ if (started_background_sync)
+ {
+ LOCK_IDLE_SCOPE();
+ m_wallet->stop_background_sync(pwd_container->password());
+ }
break;
+ }
}
catch (...) { /* do nothing, just let the loop loop */ }
}
@@ -6297,9 +6423,10 @@ bool simple_wallet::on_command(bool (simple_wallet::*cmd)(const std::vector<std:
return (this->*cmd)(args);
}
//----------------------------------------------------------------------------------------------------
-bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::string> &args_, bool called_by_mms)
+bool simple_wallet::transfer_main(const std::vector<std::string> &args_, bool called_by_mms)
{
// "transfer [index=<N1>[,<N2>,...]] [<priority>] [<ring_size>] <address> <amount> [<payment_id>]"
+ CHECK_IF_BACKGROUND_SYNCING("cannot transfer");
if (!try_connect_to_daemon())
return false;
@@ -6349,7 +6476,7 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
return false;
}
- const size_t min_args = (transfer_type == TransferLocked) ? 2 : 1;
+ const size_t min_args = 1;
if(local_args.size() < min_args)
{
fail_msg_writer() << tr("wrong number of arguments");
@@ -6374,26 +6501,6 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
}
}
- uint64_t locked_blocks = 0;
- if (transfer_type == TransferLocked)
- {
- try
- {
- locked_blocks = boost::lexical_cast<uint64_t>(local_args.back());
- }
- catch (const std::exception &e)
- {
- fail_msg_writer() << tr("bad locked_blocks parameter:") << " " << local_args.back();
- return false;
- }
- if (locked_blocks > 1000000)
- {
- fail_msg_writer() << tr("Locked blocks too high, max 1000000 (˜4 yrs)");
- return false;
- }
- local_args.pop_back();
- }
-
// Parse subtractfeefrom destination list
tools::wallet2::unique_index_container subtract_fee_from_outputs;
bool subtract_fee_from_all = false;
@@ -6523,28 +6630,8 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
try
{
// figure out what tx will be necessary
- std::vector<tools::wallet2::pending_tx> ptx_vector;
- uint64_t bc_height, unlock_block = 0;
- std::string err;
- switch (transfer_type)
- {
- case TransferLocked:
- bc_height = get_daemon_blockchain_height(err);
- if (!err.empty())
- {
- fail_msg_writer() << tr("failed to get blockchain height: ") << err;
- return false;
- }
- unlock_block = bc_height + locked_blocks;
- ptx_vector = m_wallet->create_transactions_2(dsts, fake_outs_count, unlock_block /* unlock_time */, priority, extra, m_current_subaddress_account, subaddr_indices, subtract_fee_from_outputs);
- break;
- default:
- LOG_ERROR("Unknown transfer method, using default");
- /* FALLTHRU */
- case Transfer:
- ptx_vector = m_wallet->create_transactions_2(dsts, fake_outs_count, 0 /* unlock_time */, priority, extra, m_current_subaddress_account, subaddr_indices, subtract_fee_from_outputs);
- break;
- }
+ auto ptx_vector = m_wallet->create_transactions_2(dsts, fake_outs_count, priority, extra,
+ m_current_subaddress_account, subaddr_indices, subtract_fee_from_outputs);
if (ptx_vector.empty())
{
@@ -6654,11 +6741,6 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
if (dust_in_fee != 0) prompt << boost::format(tr(", of which %s is dust from change")) % print_money(dust_in_fee);
if (dust_not_in_fee != 0) prompt << tr(".") << ENDL << boost::format(tr("A total of %s from dust change will be sent to dust address"))
% print_money(dust_not_in_fee);
- if (transfer_type == TransferLocked)
- {
- float days = locked_blocks / 720.0f;
- prompt << boost::format(tr(".\nThis transaction (including %s change) will unlock on block %llu, in approximately %s days (assuming 2 minutes per block)")) % cryptonote::print_money(change) % ((unsigned long long)unlock_block) % days;
- }
if (!process_ring_members(ptx_vector, prompt, m_wallet->print_ring_members()))
return false;
@@ -6676,7 +6758,8 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
}
// actually commit the transactions
- if (m_wallet->multisig() && called_by_mms)
+ const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
+ if (ms_status.multisig_is_active && called_by_mms)
{
std::string ciphertext = m_wallet->save_multisig_tx(ptx_vector);
if (!ciphertext.empty())
@@ -6685,7 +6768,7 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
success_msg_writer(true) << tr("Unsigned transaction(s) successfully written to MMS");
}
}
- else if (m_wallet->multisig())
+ else if (ms_status.multisig_is_active)
{
bool r = m_wallet->save_multisig_tx(ptx_vector, "multisig_monero_tx");
if (!r)
@@ -6757,40 +6840,20 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
//----------------------------------------------------------------------------------------------------
bool simple_wallet::transfer(const std::vector<std::string> &args_)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot transfer");
if (args_.size() < 1)
{
PRINT_USAGE(USAGE_TRANSFER);
return true;
}
- transfer_main(Transfer, args_, false);
- return true;
-}
-//----------------------------------------------------------------------------------------------------
-bool simple_wallet::locked_transfer(const std::vector<std::string> &args_)
-{
- if (args_.size() < 1)
- {
- PRINT_USAGE(USAGE_LOCKED_TRANSFER);
- return true;
- }
- transfer_main(TransferLocked, args_, false);
- return true;
-}
-//----------------------------------------------------------------------------------------------------
-bool simple_wallet::locked_sweep_all(const std::vector<std::string> &args_)
-{
- if (args_.size() < 1)
- {
- PRINT_USAGE(USAGE_LOCKED_SWEEP_ALL);
- return true;
- }
- sweep_main(m_current_subaddress_account, 0, true, args_);
+ transfer_main(args_, false);
return true;
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot sweep");
if (!try_connect_to_daemon())
return true;
@@ -6839,7 +6902,7 @@ bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_)
}
// actually commit the transactions
- if (m_wallet->multisig())
+ if (m_wallet->get_multisig_status().multisig_is_active)
{
CHECK_MULTISIG_ENABLED();
bool r = m_wallet->save_multisig_tx(ptx_vector, "multisig_monero_tx");
@@ -6896,8 +6959,9 @@ bool simple_wallet::sweep_unmixable(const std::vector<std::string> &args_)
return true;
}
//----------------------------------------------------------------------------------------------------
-bool simple_wallet::sweep_main(uint32_t account, uint64_t below, bool locked, const std::vector<std::string> &args_)
+bool simple_wallet::sweep_main(uint32_t account, uint64_t below, const std::vector<std::string> &args_)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot sweep");
auto print_usage = [this, account, below]()
{
if (below)
@@ -6976,41 +7040,6 @@ bool simple_wallet::sweep_main(uint32_t account, uint64_t below, bool locked, co
return true;
}
- uint64_t unlock_block = 0;
- if (locked) {
- uint64_t locked_blocks = 0;
-
- if (local_args.size() < 2) {
- fail_msg_writer() << tr("missing lockedblocks parameter");
- return true;
- }
-
- try
- {
- locked_blocks = boost::lexical_cast<uint64_t>(local_args[1]);
- }
- catch (const std::exception &e)
- {
- fail_msg_writer() << tr("bad locked_blocks parameter");
- return true;
- }
- if (locked_blocks > 1000000)
- {
- fail_msg_writer() << tr("Locked blocks too high, max 1000000 (˜4 yrs)");
- return true;
- }
- std::string err;
- uint64_t bc_height = get_daemon_blockchain_height(err);
- if (!err.empty())
- {
- fail_msg_writer() << tr("failed to get blockchain height: ") << err;
- return true;
- }
- unlock_block = bc_height + locked_blocks;
-
- local_args.erase(local_args.begin() + 1);
- }
-
size_t outputs = 1;
if (local_args.size() > 0 && local_args[0].substr(0, 8) == "outputs=")
{
@@ -7085,7 +7114,7 @@ bool simple_wallet::sweep_main(uint32_t account, uint64_t below, bool locked, co
try
{
// figure out what tx will be necessary
- auto ptx_vector = m_wallet->create_transactions_all(below, info.address, info.is_subaddress, outputs, fake_outs_count, unlock_block /* unlock_time */, priority, extra, account, subaddr_indices);
+ auto ptx_vector = m_wallet->create_transactions_all(below, info.address, info.is_subaddress, outputs, fake_outs_count, priority, extra, account, subaddr_indices);
if (ptx_vector.empty())
{
@@ -7144,7 +7173,7 @@ bool simple_wallet::sweep_main(uint32_t account, uint64_t below, bool locked, co
}
// actually commit the transactions
- if (m_wallet->multisig())
+ if (m_wallet->get_multisig_status().multisig_is_active)
{
CHECK_MULTISIG_ENABLED();
bool r = m_wallet->save_multisig_tx(ptx_vector, "multisig_monero_tx");
@@ -7214,6 +7243,7 @@ bool simple_wallet::sweep_main(uint32_t account, uint64_t below, bool locked, co
//----------------------------------------------------------------------------------------------------
bool simple_wallet::sweep_single(const std::vector<std::string> &args_)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot sweep");
if (!try_connect_to_daemon())
return true;
@@ -7342,7 +7372,7 @@ bool simple_wallet::sweep_single(const std::vector<std::string> &args_)
try
{
// figure out what tx will be necessary
- auto ptx_vector = m_wallet->create_transactions_single(ki, info.address, info.is_subaddress, outputs, fake_outs_count, 0 /* unlock_time */, priority, extra);
+ auto ptx_vector = m_wallet->create_transactions_single(ki, info.address, info.is_subaddress, outputs, fake_outs_count, priority, extra);
if (ptx_vector.empty())
{
@@ -7379,7 +7409,7 @@ bool simple_wallet::sweep_single(const std::vector<std::string> &args_)
}
// actually commit the transactions
- if (m_wallet->multisig())
+ if (m_wallet->get_multisig_status().multisig_is_active)
{
CHECK_MULTISIG_ENABLED();
bool r = m_wallet->save_multisig_tx(ptx_vector, "multisig_monero_tx");
@@ -7452,12 +7482,14 @@ bool simple_wallet::sweep_single(const std::vector<std::string> &args_)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::sweep_all(const std::vector<std::string> &args_)
{
- sweep_main(m_current_subaddress_account, 0, false, args_);
+ CHECK_IF_BACKGROUND_SYNCING("cannot sweep");
+ sweep_main(m_current_subaddress_account, 0, args_);
return true;
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet::sweep_account(const std::vector<std::string> &args_)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot sweep");
auto local_args = args_;
if (local_args.empty())
{
@@ -7472,12 +7504,13 @@ bool simple_wallet::sweep_account(const std::vector<std::string> &args_)
}
local_args.erase(local_args.begin());
- sweep_main(account, 0, false, local_args);
+ sweep_main(account, 0, local_args);
return true;
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet::sweep_below(const std::vector<std::string> &args_)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot sweep");
uint64_t below = 0;
if (args_.size() < 1)
{
@@ -7490,12 +7523,13 @@ bool simple_wallet::sweep_below(const std::vector<std::string> &args_)
fail_msg_writer() << tr("invalid amount threshold");
return true;
}
- sweep_main(m_current_subaddress_account, below, false, std::vector<std::string>(++args_.begin(), args_.end()));
+ sweep_main(m_current_subaddress_account, below, std::vector<std::string>(++args_.begin(), args_.end()));
return true;
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet::donate(const std::vector<std::string> &args_)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot donate");
std::vector<std::string> local_args = args_;
if(local_args.empty() || local_args.size() > 5)
{
@@ -7557,6 +7591,7 @@ bool simple_wallet::donate(const std::vector<std::string> &args_)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::accept_loaded_tx(const std::function<size_t()> get_num_txes, const std::function<const tools::wallet2::tx_construction_data&(size_t)> &get_tx, const std::string &extra_message)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot load tx");
// gather info to ask the user
uint64_t amount = 0, amount_to_dests = 0, change = 0;
size_t min_ring_size = ~0;
@@ -7727,7 +7762,7 @@ bool simple_wallet::sign_transfer(const std::vector<std::string> &args_)
fail_msg_writer() << tr("command not supported by HW wallet");
return true;
}
- if(m_wallet->multisig())
+ if(m_wallet->get_multisig_status().multisig_is_active)
{
fail_msg_writer() << tr("This is a multisig wallet, it can only sign with sign_multisig");
return true;
@@ -7737,6 +7772,7 @@ bool simple_wallet::sign_transfer(const std::vector<std::string> &args_)
fail_msg_writer() << tr("This is a watch only wallet");
return true;
}
+ CHECK_IF_BACKGROUND_SYNCING("cannot sign transfer");
bool export_raw = false;
std::string unsigned_filename = "unsigned_monero_tx";
@@ -7844,6 +7880,8 @@ std::string get_tx_key_stream(crypto::secret_key tx_key, std::vector<crypto::sec
bool simple_wallet::get_tx_key(const std::vector<std::string> &args_)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot get tx key");
+
std::vector<std::string> local_args = args_;
if (m_wallet->key_on_device() && m_wallet->get_account().get_device().get_type() != hw::device::TREZOR)
@@ -7884,6 +7922,8 @@ bool simple_wallet::get_tx_key(const std::vector<std::string> &args_)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::set_tx_key(const std::vector<std::string> &args_)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot set tx key");
+
std::vector<std::string> local_args = args_;
if(local_args.size() != 2 && local_args.size() != 3) {
@@ -7960,6 +8000,8 @@ bool simple_wallet::set_tx_key(const std::vector<std::string> &args_)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::get_tx_proof(const std::vector<std::string> &args)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot get tx proof");
+
if (args.size() != 2 && args.size() != 3)
{
PRINT_USAGE(USAGE_GET_TX_PROOF);
@@ -8166,6 +8208,7 @@ bool simple_wallet::check_tx_proof(const std::vector<std::string> &args)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::get_spend_proof(const std::vector<std::string> &args)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot get spend proof");
if (m_wallet->key_on_device())
{
fail_msg_writer() << tr("command not supported by HW wallet");
@@ -8250,6 +8293,7 @@ bool simple_wallet::check_spend_proof(const std::vector<std::string> &args)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::get_reserve_proof(const std::vector<std::string> &args)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot get reserve proof");
if (m_wallet->key_on_device())
{
fail_msg_writer() << tr("command not supported by HW wallet");
@@ -8260,7 +8304,7 @@ bool simple_wallet::get_reserve_proof(const std::vector<std::string> &args)
return true;
}
- if (m_wallet->watch_only() || m_wallet->multisig())
+ if (m_wallet->watch_only() || m_wallet->get_multisig_status().multisig_is_active)
{
fail_msg_writer() << tr("The reserve proof can be generated only by a full wallet");
return true;
@@ -8845,6 +8889,7 @@ bool simple_wallet::unspent_outputs(const std::vector<std::string> &args_)
uint64_t max_height = 0;
uint64_t found_min_amount = std::numeric_limits<uint64_t>::max();
uint64_t found_max_amount = 0;
+ uint64_t found_sum_amount = 0;
uint64_t count = 0;
for (const auto& td : transfers)
{
@@ -8856,6 +8901,7 @@ bool simple_wallet::unspent_outputs(const std::vector<std::string> &args_)
if (max_height < td.m_block_height) max_height = td.m_block_height;
if (found_min_amount > amount) found_min_amount = amount;
if (found_max_amount < amount) found_max_amount = amount;
+ found_sum_amount += amount;
++count;
}
if (amount_to_tds.empty())
@@ -8880,6 +8926,7 @@ bool simple_wallet::unspent_outputs(const std::vector<std::string> &args_)
<< tr("\nMax block height: ") << max_height
<< tr("\nMin amount found: ") << print_money(found_min_amount)
<< tr("\nMax amount found: ") << print_money(found_max_amount)
+ << tr("\nSum amount found: ") << print_money(found_sum_amount)
<< tr("\nTotal count: ") << count;
const size_t histogram_height = 10;
const size_t histogram_width = 50;
@@ -8936,6 +8983,8 @@ bool simple_wallet::unspent_outputs(const std::vector<std::string> &args_)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::rescan_blockchain(const std::vector<std::string> &args_)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot rescan");
+
uint64_t start_height = 0;
ResetType reset_type = ResetSoft;
@@ -9160,6 +9209,7 @@ bool simple_wallet::account(const std::vector<std::string> &args/* = std::vector
if (command == "new")
{
// create a new account and switch to it
+ CHECK_IF_BACKGROUND_SYNCING("cannot create new account");
std::string label = boost::join(local_args, " ");
if (label.empty())
label = tr("(Untitled account)");
@@ -9190,6 +9240,7 @@ bool simple_wallet::account(const std::vector<std::string> &args/* = std::vector
else if (command == "label" && local_args.size() >= 1)
{
// set label of the specified account
+ CHECK_IF_BACKGROUND_SYNCING("cannot modify account");
uint32_t index_major;
if (!epee::string_tools::get_xtype_from_string(index_major, local_args[0]))
{
@@ -9211,6 +9262,7 @@ bool simple_wallet::account(const std::vector<std::string> &args/* = std::vector
}
else if (command == "tag" && local_args.size() >= 2)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot modify account");
const std::string tag = local_args[0];
std::set<uint32_t> account_indices;
for (size_t i = 1; i < local_args.size(); ++i)
@@ -9235,6 +9287,7 @@ bool simple_wallet::account(const std::vector<std::string> &args/* = std::vector
}
else if (command == "untag" && local_args.size() >= 1)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot modify account");
std::set<uint32_t> account_indices;
for (size_t i = 0; i < local_args.size(); ++i)
{
@@ -9258,6 +9311,7 @@ bool simple_wallet::account(const std::vector<std::string> &args/* = std::vector
}
else if (command == "tag_description" && local_args.size() >= 1)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot modify account");
const std::string tag = local_args[0];
std::string description;
if (local_args.size() > 1)
@@ -9375,6 +9429,7 @@ bool simple_wallet::print_address(const std::vector<std::string> &args/* = std::
}
else if (local_args[0] == "new")
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot add address");
local_args.erase(local_args.begin());
std::string label;
if (local_args.size() > 0)
@@ -9387,6 +9442,7 @@ bool simple_wallet::print_address(const std::vector<std::string> &args/* = std::
}
else if (local_args[0] == "mnew")
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot add addresses");
local_args.erase(local_args.begin());
if (local_args.size() != 1)
{
@@ -9412,6 +9468,7 @@ bool simple_wallet::print_address(const std::vector<std::string> &args/* = std::
}
else if (local_args[0] == "one-off")
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot add address");
local_args.erase(local_args.begin());
std::string label;
if (local_args.size() != 2)
@@ -9430,6 +9487,7 @@ bool simple_wallet::print_address(const std::vector<std::string> &args/* = std::
}
else if (local_args.size() >= 2 && local_args[0] == "label")
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot modify address");
if (!epee::string_tools::get_xtype_from_string(index, local_args[1]))
{
fail_msg_writer() << tr("failed to parse index: ") << local_args[1];
@@ -9576,6 +9634,8 @@ bool simple_wallet::print_integrated_address(const std::vector<std::string> &arg
//----------------------------------------------------------------------------------------------------
bool simple_wallet::address_book(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot get address book");
+
if (args.size() == 0)
{
}
@@ -9636,6 +9696,8 @@ bool simple_wallet::address_book(const std::vector<std::string> &args/* = std::v
//----------------------------------------------------------------------------------------------------
bool simple_wallet::set_tx_note(const std::vector<std::string> &args)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot set tx note");
+
if (args.size() == 0)
{
PRINT_USAGE(USAGE_SET_TX_NOTE);
@@ -9664,6 +9726,8 @@ bool simple_wallet::set_tx_note(const std::vector<std::string> &args)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::get_tx_note(const std::vector<std::string> &args)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot get tx note");
+
if (args.size() != 1)
{
PRINT_USAGE(USAGE_GET_TX_NOTE);
@@ -9689,6 +9753,8 @@ bool simple_wallet::get_tx_note(const std::vector<std::string> &args)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::set_description(const std::vector<std::string> &args)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot set description");
+
// 0 arguments allowed, for setting the description to empty string
std::string description = "";
@@ -9705,6 +9771,8 @@ bool simple_wallet::set_description(const std::vector<std::string> &args)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::get_description(const std::vector<std::string> &args)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot get description");
+
if (args.size() != 0)
{
PRINT_USAGE(USAGE_GET_DESCRIPTION);
@@ -9748,8 +9816,8 @@ bool simple_wallet::status(const std::vector<std::string> &args)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::wallet_info(const std::vector<std::string> &args)
{
- bool ready;
- uint32_t threshold, total;
+ const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
+
std::string description = m_wallet->get_description();
if (description.empty())
{
@@ -9761,8 +9829,10 @@ bool simple_wallet::wallet_info(const std::vector<std::string> &args)
std::string type;
if (m_wallet->watch_only())
type = tr("Watch only");
- else if (m_wallet->multisig(&ready, &threshold, &total))
- type = (boost::format(tr("%u/%u multisig%s")) % threshold % total % (ready ? "" : " (not yet finalized)")).str();
+ else if (ms_status.multisig_is_active)
+ type = (boost::format(tr("%u/%u multisig%s")) % ms_status.threshold % ms_status.total % (ms_status.is_ready ? "" : " (not yet finalized)")).str();
+ else if (m_wallet->is_background_wallet())
+ type = tr("Background wallet");
else
type = tr("Normal");
message_writer() << tr("Type: ") << type;
@@ -9774,6 +9844,7 @@ bool simple_wallet::wallet_info(const std::vector<std::string> &args)
//----------------------------------------------------------------------------------------------------
bool simple_wallet::sign(const std::vector<std::string> &args)
{
+ CHECK_IF_BACKGROUND_SYNCING("cannot sign");
if (m_wallet->key_on_device())
{
fail_msg_writer() << tr("command not supported by HW wallet");
@@ -9789,7 +9860,7 @@ bool simple_wallet::sign(const std::vector<std::string> &args)
fail_msg_writer() << tr("wallet is watch-only and cannot sign");
return true;
}
- if (m_wallet->multisig())
+ if (m_wallet->get_multisig_status().multisig_is_active)
{
fail_msg_writer() << tr("This wallet is multisig and cannot sign");
return true;
@@ -9881,6 +9952,7 @@ bool simple_wallet::export_key_images(const std::vector<std::string> &args_)
fail_msg_writer() << tr("command not supported by HW wallet");
return true;
}
+ CHECK_IF_BACKGROUND_SYNCING("cannot export key images");
auto args = args_;
if (m_wallet->watch_only())
@@ -9934,6 +10006,7 @@ bool simple_wallet::import_key_images(const std::vector<std::string> &args)
fail_msg_writer() << tr("command not supported by HW wallet");
return true;
}
+ CHECK_IF_BACKGROUND_SYNCING("cannot import key images");
if (!m_wallet->is_trusted_daemon())
{
fail_msg_writer() << tr("this command requires a trusted daemon. Enable with --trusted-daemon");
@@ -10042,6 +10115,7 @@ bool simple_wallet::export_outputs(const std::vector<std::string> &args_)
fail_msg_writer() << tr("command not supported by HW wallet");
return true;
}
+ CHECK_IF_BACKGROUND_SYNCING("cannot export outputs");
auto args = args_;
bool all = false;
@@ -10091,6 +10165,7 @@ bool simple_wallet::import_outputs(const std::vector<std::string> &args)
fail_msg_writer() << tr("command not supported by HW wallet");
return true;
}
+ CHECK_IF_BACKGROUND_SYNCING("cannot import outputs");
if (args.size() != 1)
{
PRINT_USAGE(USAGE_IMPORT_OUTPUTS);
@@ -11018,7 +11093,7 @@ void simple_wallet::mms_sync(const std::vector<std::string> &args)
void simple_wallet::mms_transfer(const std::vector<std::string> &args)
{
// It's too complicated to check any arguments here, just let 'transfer_main' do the whole job
- transfer_main(Transfer, args, true);
+ transfer_main(args, true);
}
void simple_wallet::mms_delete(const std::vector<std::string> &args)
diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h
index 2a5d7f2b6..0e00c3490 100644
--- a/src/simplewallet/simplewallet.h
+++ b/src/simplewallet/simplewallet.h
@@ -147,6 +147,7 @@ namespace cryptonote
bool set_ignore_outputs_above(const std::vector<std::string> &args = std::vector<std::string>());
bool set_ignore_outputs_below(const std::vector<std::string> &args = std::vector<std::string>());
bool set_track_uses(const std::vector<std::string> &args = std::vector<std::string>());
+ bool setup_background_sync(const std::vector<std::string> &args = std::vector<std::string>());
bool set_show_wallet_name_when_locked(const std::vector<std::string> &args = std::vector<std::string>());
bool set_inactivity_lock_timeout(const std::vector<std::string> &args = std::vector<std::string>());
bool set_setup_background_mining(const std::vector<std::string> &args = std::vector<std::string>());
@@ -167,11 +168,9 @@ namespace cryptonote
bool show_incoming_transfers(const std::vector<std::string> &args);
bool show_payments(const std::vector<std::string> &args);
bool show_blockchain_height(const std::vector<std::string> &args);
- bool transfer_main(int transfer_type, const std::vector<std::string> &args, bool called_by_mms);
+ bool transfer_main(const std::vector<std::string> &args, bool called_by_mms);
bool transfer(const std::vector<std::string> &args);
- bool locked_transfer(const std::vector<std::string> &args);
- bool locked_sweep_all(const std::vector<std::string> &args);
- bool sweep_main(uint32_t account, uint64_t below, bool locked, const std::vector<std::string> &args);
+ bool sweep_main(uint32_t account, uint64_t below, const std::vector<std::string> &args);
bool sweep_all(const std::vector<std::string> &args);
bool sweep_account(const std::vector<std::string> &args);
bool sweep_below(const std::vector<std::string> &args);
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp
index 7f4dbbc79..40481fc4b 100644
--- a/src/wallet/api/wallet.cpp
+++ b/src/wallet/api/wallet.cpp
@@ -38,6 +38,7 @@
#include "subaddress_account.h"
#include "common_defines.h"
#include "common/util.h"
+#include "multisig/multisig_account.h"
#include "mnemonics/electrum-words.h"
#include "mnemonics/english.h"
@@ -57,6 +58,40 @@ using namespace cryptonote;
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "WalletAPI"
+#define LOCK_REFRESH() \
+ bool refresh_enabled = m_refreshEnabled; \
+ m_refreshEnabled = false; \
+ m_wallet->stop(); \
+ m_refreshCV.notify_one(); \
+ boost::mutex::scoped_lock lock(m_refreshMutex); \
+ boost::mutex::scoped_lock lock2(m_refreshMutex2); \
+ epee::misc_utils::auto_scope_leave_caller scope_exit_handler = epee::misc_utils::create_scope_leave_handler([&](){ \
+ /* m_refreshMutex's still locked here */ \
+ if (refresh_enabled) \
+ startRefresh(); \
+ })
+
+#define PRE_VALIDATE_BACKGROUND_SYNC() \
+ do \
+ { \
+ clearStatus(); \
+ if (m_wallet->key_on_device()) \
+ { \
+ setStatusError(tr("HW wallet cannot use background sync")); \
+ return false; \
+ } \
+ if (m_wallet->watch_only()) \
+ { \
+ setStatusError(tr("View only wallet cannot use background sync")); \
+ return false; \
+ } \
+ if (m_wallet->get_multisig_status().multisig_is_active) \
+ { \
+ setStatusError(tr("Multisig wallet cannot use background sync")); \
+ return false; \
+ } \
+ } while (0)
+
namespace Monero {
namespace {
@@ -87,12 +122,13 @@ namespace {
throw runtime_error("Wallet is not initialized yet");
}
- bool ready;
- if (!wallet->multisig(&ready)) {
+ const multisig::multisig_account_status ms_status{wallet->get_multisig_status()};
+
+ if (!ms_status.multisig_is_active) {
throw runtime_error("Wallet is not multisig");
}
- if (!ready) {
+ if (!ms_status.is_ready) {
throw runtime_error("Multisig wallet is not finalized yet");
}
}
@@ -105,12 +141,13 @@ namespace {
throw runtime_error("Wallet is not initialized yet");
}
- bool ready;
- if (!wallet->multisig(&ready)) {
+ const multisig::multisig_account_status ms_status{wallet->get_multisig_status()};
+
+ if (!ms_status.multisig_is_active) {
throw runtime_error("Wallet is not multisig");
}
- if (ready) {
+ if (ms_status.is_ready) {
throw runtime_error("Multisig wallet is already finalized");
}
}
@@ -763,6 +800,8 @@ bool WalletImpl::close(bool store)
std::string WalletImpl::seed(const std::string& seed_offset) const
{
+ if (checkBackgroundSync("cannot get seed"))
+ return std::string();
epee::wipeable_string seed;
if (m_wallet)
m_wallet->get_seed(seed, seed_offset);
@@ -776,6 +815,8 @@ std::string WalletImpl::getSeedLanguage() const
void WalletImpl::setSeedLanguage(const std::string &arg)
{
+ if (checkBackgroundSync("cannot set seed language"))
+ return;
m_wallet->set_seed_language(arg);
}
@@ -799,6 +840,8 @@ void WalletImpl::statusWithErrorString(int& status, std::string& errorString) co
bool WalletImpl::setPassword(const std::string &password)
{
+ if (checkBackgroundSync("cannot change password"))
+ return false;
clearStatus();
try {
m_wallet->change_password(m_wallet->get_wallet_file(), m_password, password);
@@ -928,6 +971,8 @@ bool WalletImpl::init(const std::string &daemon_address, uint64_t upper_transact
void WalletImpl::setRefreshFromBlockHeight(uint64_t refresh_from_block_height)
{
+ if (checkBackgroundSync("cannot change refresh height"))
+ return;
m_wallet->set_refresh_from_block_height(refresh_from_block_height);
}
@@ -1036,6 +1081,8 @@ void WalletImpl::refreshAsync()
bool WalletImpl::rescanBlockchain()
{
+ if (checkBackgroundSync("cannot rescan blockchain"))
+ return false;
clearStatus();
m_refreshShouldRescan = true;
doRefresh();
@@ -1044,6 +1091,8 @@ bool WalletImpl::rescanBlockchain()
void WalletImpl::rescanBlockchainAsync()
{
+ if (checkBackgroundSync("cannot rescan blockchain"))
+ return;
m_refreshShouldRescan = true;
refreshAsync();
}
@@ -1067,7 +1116,7 @@ int WalletImpl::autoRefreshInterval() const
UnsignedTransaction *WalletImpl::loadUnsignedTx(const std::string &unsigned_filename) {
clearStatus();
UnsignedTransactionImpl * transaction = new UnsignedTransactionImpl(*this);
- if (!m_wallet->load_unsigned_tx(unsigned_filename, transaction->m_unsigned_tx_set)){
+ if (checkBackgroundSync("cannot load tx") || !m_wallet->load_unsigned_tx(unsigned_filename, transaction->m_unsigned_tx_set)){
setStatusError(tr("Failed to load unsigned transactions"));
transaction->m_status = UnsignedTransaction::Status::Status_Error;
transaction->m_errorString = errorString();
@@ -1087,6 +1136,8 @@ UnsignedTransaction *WalletImpl::loadUnsignedTx(const std::string &unsigned_file
bool WalletImpl::submitTransaction(const string &fileName) {
clearStatus();
+ if (checkBackgroundSync("cannot submit tx"))
+ return false;
std::unique_ptr<PendingTransactionImpl> transaction(new PendingTransactionImpl(*this));
bool r = m_wallet->load_tx(fileName, transaction->m_pending_tx);
@@ -1110,6 +1161,8 @@ bool WalletImpl::exportKeyImages(const string &filename, bool all)
setStatusError(tr("Wallet is view only"));
return false;
}
+ if (checkBackgroundSync("cannot export key images"))
+ return false;
try
{
@@ -1130,6 +1183,8 @@ bool WalletImpl::exportKeyImages(const string &filename, bool all)
bool WalletImpl::importKeyImages(const string &filename)
{
+ if (checkBackgroundSync("cannot import key images"))
+ return false;
if (!trustedDaemon()) {
setStatusError(tr("Key images can only be imported with a trusted daemon"));
return false;
@@ -1153,6 +1208,8 @@ bool WalletImpl::importKeyImages(const string &filename)
bool WalletImpl::exportOutputs(const string &filename, bool all)
{
+ if (checkBackgroundSync("cannot export outputs"))
+ return false;
if (m_wallet->key_on_device())
{
setStatusError(string(tr("Not supported on HW wallets.")) + filename);
@@ -1183,6 +1240,8 @@ bool WalletImpl::exportOutputs(const string &filename, bool all)
bool WalletImpl::importOutputs(const string &filename)
{
+ if (checkBackgroundSync("cannot import outputs"))
+ return false;
if (m_wallet->key_on_device())
{
setStatusError(string(tr("Not supported on HW wallets.")) + filename);
@@ -1215,6 +1274,8 @@ bool WalletImpl::importOutputs(const string &filename)
bool WalletImpl::scanTransactions(const std::vector<std::string> &txids)
{
+ if (checkBackgroundSync("cannot scan transactions"))
+ return false;
if (txids.empty())
{
setStatusError(string(tr("Failed to scan transactions: no transaction ids provided.")));
@@ -1253,8 +1314,86 @@ bool WalletImpl::scanTransactions(const std::vector<std::string> &txids)
return true;
}
+bool WalletImpl::setupBackgroundSync(const Wallet::BackgroundSyncType background_sync_type, const std::string &wallet_password, const optional<std::string> &background_cache_password)
+{
+ try
+ {
+ PRE_VALIDATE_BACKGROUND_SYNC();
+
+ tools::wallet2::BackgroundSyncType bgs_type;
+ switch (background_sync_type)
+ {
+ case Wallet::BackgroundSync_Off: bgs_type = tools::wallet2::BackgroundSyncOff; break;
+ case Wallet::BackgroundSync_ReusePassword: bgs_type = tools::wallet2::BackgroundSyncReusePassword; break;
+ case Wallet::BackgroundSync_CustomPassword: bgs_type = tools::wallet2::BackgroundSyncCustomPassword; break;
+ default: setStatusError(tr("Unknown background sync type")); return false;
+ }
+
+ boost::optional<epee::wipeable_string> bgc_password = background_cache_password
+ ? boost::optional<epee::wipeable_string>(*background_cache_password)
+ : boost::none;
+
+ LOCK_REFRESH();
+ m_wallet->setup_background_sync(bgs_type, wallet_password, bgc_password);
+ }
+ catch (const std::exception &e)
+ {
+ LOG_ERROR("Failed to setup background sync: " << e.what());
+ setStatusError(string(tr("Failed to setup background sync: ")) + e.what());
+ return false;
+ }
+ return true;
+}
+
+Wallet::BackgroundSyncType WalletImpl::getBackgroundSyncType() const
+{
+ switch (m_wallet->background_sync_type())
+ {
+ case tools::wallet2::BackgroundSyncOff: return Wallet::BackgroundSync_Off;
+ case tools::wallet2::BackgroundSyncReusePassword: return Wallet::BackgroundSync_ReusePassword;
+ case tools::wallet2::BackgroundSyncCustomPassword: return Wallet::BackgroundSync_CustomPassword;
+ default: setStatusError(tr("Unknown background sync type")); return Wallet::BackgroundSync_Off;
+ }
+}
+
+bool WalletImpl::startBackgroundSync()
+{
+ try
+ {
+ PRE_VALIDATE_BACKGROUND_SYNC();
+ LOCK_REFRESH();
+ m_wallet->start_background_sync();
+ }
+ catch (const std::exception &e)
+ {
+ LOG_ERROR("Failed to start background sync: " << e.what());
+ setStatusError(string(tr("Failed to start background sync: ")) + e.what());
+ return false;
+ }
+ return true;
+}
+
+bool WalletImpl::stopBackgroundSync(const std::string &wallet_password)
+{
+ try
+ {
+ PRE_VALIDATE_BACKGROUND_SYNC();
+ LOCK_REFRESH();
+ m_wallet->stop_background_sync(epee::wipeable_string(wallet_password));
+ }
+ catch (const std::exception &e)
+ {
+ LOG_ERROR("Failed to stop background sync: " << e.what());
+ setStatusError(string(tr("Failed to stop background sync: ")) + e.what());
+ return false;
+ }
+ return true;
+}
+
void WalletImpl::addSubaddressAccount(const std::string& label)
{
+ if (checkBackgroundSync("cannot add account"))
+ return;
m_wallet->add_subaddress_account(label);
}
size_t WalletImpl::numSubaddressAccounts() const
@@ -1267,10 +1406,14 @@ size_t WalletImpl::numSubaddresses(uint32_t accountIndex) const
}
void WalletImpl::addSubaddress(uint32_t accountIndex, const std::string& label)
{
+ if (checkBackgroundSync("cannot add subbaddress"))
+ return;
m_wallet->add_subaddress(accountIndex, label);
}
std::string WalletImpl::getSubaddressLabel(uint32_t accountIndex, uint32_t addressIndex) const
{
+ if (checkBackgroundSync("cannot get subbaddress label"))
+ return "";
try
{
return m_wallet->get_subaddress_label({accountIndex, addressIndex});
@@ -1284,6 +1427,8 @@ std::string WalletImpl::getSubaddressLabel(uint32_t accountIndex, uint32_t addre
}
void WalletImpl::setSubaddressLabel(uint32_t accountIndex, uint32_t addressIndex, const std::string &label)
{
+ if (checkBackgroundSync("cannot set subbaddress label"))
+ return;
try
{
return m_wallet->set_subaddress_label({accountIndex, addressIndex}, label);
@@ -1297,12 +1442,23 @@ void WalletImpl::setSubaddressLabel(uint32_t accountIndex, uint32_t addressIndex
MultisigState WalletImpl::multisig() const {
MultisigState state;
- state.isMultisig = m_wallet->multisig(&state.isReady, &state.threshold, &state.total);
+ if (checkBackgroundSync("cannot use multisig"))
+ return state;
+
+ const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
+
+ state.isMultisig = ms_status.multisig_is_active;
+ state.kexIsDone = ms_status.kex_is_done;
+ state.isReady = ms_status.is_ready;
+ state.threshold = ms_status.threshold;
+ state.total = ms_status.total;
return state;
}
string WalletImpl::getMultisigInfo() const {
+ if (checkBackgroundSync("cannot use multisig"))
+ return string();
try {
clearStatus();
return m_wallet->get_multisig_first_kex_msg();
@@ -1315,10 +1471,12 @@ string WalletImpl::getMultisigInfo() const {
}
string WalletImpl::makeMultisig(const vector<string>& info, const uint32_t threshold) {
+ if (checkBackgroundSync("cannot make multisig"))
+ return string();
try {
clearStatus();
- if (m_wallet->multisig()) {
+ if (m_wallet->get_multisig_status().multisig_is_active) {
throw runtime_error("Wallet is already multisig");
}
@@ -1345,6 +1503,21 @@ std::string WalletImpl::exchangeMultisigKeys(const std::vector<std::string> &inf
return string();
}
+std::string WalletImpl::getMultisigKeyExchangeBooster(const std::vector<std::string> &info,
+ const std::uint32_t threshold,
+ const std::uint32_t num_signers) {
+ try {
+ clearStatus();
+
+ return m_wallet->get_multisig_key_exchange_booster(epee::wipeable_string(m_password), info, threshold, num_signers);
+ } catch (const exception& e) {
+ LOG_ERROR("Error on boosting multisig key exchange: " << e.what());
+ setStatusError(string(tr("Failed to boost multisig key exchange: ")) + e.what());
+ }
+
+ return string();
+}
+
bool WalletImpl::exportMultisigImages(string& images) {
try {
clearStatus();
@@ -1455,6 +1628,9 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vector<stri
PendingTransactionImpl * transaction = new PendingTransactionImpl(*this);
do {
+ if (checkBackgroundSync("cannot create transactions"))
+ break;
+
std::vector<uint8_t> extra;
std::string extra_nonce;
vector<cryptonote::tx_destination_entry> dsts;
@@ -1519,11 +1695,11 @@ PendingTransaction *WalletImpl::createTransactionMultDest(const std::vector<stri
fake_outs_count = m_wallet->adjust_mixin(mixin_count);
if (amount) {
- transaction->m_pending_tx = m_wallet->create_transactions_2(dsts, fake_outs_count, 0 /* unlock_time */,
+ transaction->m_pending_tx = m_wallet->create_transactions_2(dsts, fake_outs_count,
adjusted_priority,
extra, subaddr_account, subaddr_indices);
} else {
- transaction->m_pending_tx = m_wallet->create_transactions_all(0, info.address, info.is_subaddress, 1, fake_outs_count, 0 /* unlock_time */,
+ transaction->m_pending_tx = m_wallet->create_transactions_all(0, info.address, info.is_subaddress, 1, fake_outs_count,
adjusted_priority,
extra, subaddr_account, subaddr_indices);
}
@@ -1621,6 +1797,9 @@ PendingTransaction *WalletImpl::createSweepUnmixableTransaction()
PendingTransactionImpl * transaction = new PendingTransactionImpl(*this);
do {
+ if (checkBackgroundSync("cannot sweep"))
+ break;
+
try {
transaction->m_pending_tx = m_wallet->create_unmixable_sweep_transactions();
pendingTxPostProcess(transaction);
@@ -1754,11 +1933,15 @@ uint32_t WalletImpl::defaultMixin() const
void WalletImpl::setDefaultMixin(uint32_t arg)
{
+ if (checkBackgroundSync("cannot set default mixin"))
+ return;
m_wallet->default_mixin(arg);
}
bool WalletImpl::setCacheAttribute(const std::string &key, const std::string &val)
{
+ if (checkBackgroundSync("cannot set cache attribute"))
+ return false;
m_wallet->set_attribute(key, val);
return true;
}
@@ -1772,6 +1955,8 @@ std::string WalletImpl::getCacheAttribute(const std::string &key) const
bool WalletImpl::setUserNote(const std::string &txid, const std::string &note)
{
+ if (checkBackgroundSync("cannot set user note"))
+ return false;
cryptonote::blobdata txid_data;
if(!epee::string_tools::parse_hexstr_to_binbuff(txid, txid_data) || txid_data.size() != sizeof(crypto::hash))
return false;
@@ -1783,6 +1968,8 @@ bool WalletImpl::setUserNote(const std::string &txid, const std::string &note)
std::string WalletImpl::getUserNote(const std::string &txid) const
{
+ if (checkBackgroundSync("cannot get user note"))
+ return "";
cryptonote::blobdata txid_data;
if(!epee::string_tools::parse_hexstr_to_binbuff(txid, txid_data) || txid_data.size() != sizeof(crypto::hash))
return "";
@@ -1793,6 +1980,9 @@ std::string WalletImpl::getUserNote(const std::string &txid) const
std::string WalletImpl::getTxKey(const std::string &txid_str) const
{
+ if (checkBackgroundSync("cannot get tx key"))
+ return "";
+
crypto::hash txid;
if(!epee::string_tools::hex_to_pod(txid_str, txid))
{
@@ -1877,6 +2067,9 @@ bool WalletImpl::checkTxKey(const std::string &txid_str, std::string tx_key_str,
std::string WalletImpl::getTxProof(const std::string &txid_str, const std::string &address_str, const std::string &message) const
{
+ if (checkBackgroundSync("cannot get tx proof"))
+ return "";
+
crypto::hash txid;
if (!epee::string_tools::hex_to_pod(txid_str, txid))
{
@@ -1933,6 +2126,9 @@ bool WalletImpl::checkTxProof(const std::string &txid_str, const std::string &ad
}
std::string WalletImpl::getSpendProof(const std::string &txid_str, const std::string &message) const {
+ if (checkBackgroundSync("cannot get spend proof"))
+ return "";
+
crypto::hash txid;
if(!epee::string_tools::hex_to_pod(txid_str, txid))
{
@@ -1975,6 +2171,9 @@ bool WalletImpl::checkSpendProof(const std::string &txid_str, const std::string
}
std::string WalletImpl::getReserveProof(bool all, uint32_t account_index, uint64_t amount, const std::string &message) const {
+ if (checkBackgroundSync("cannot get reserve proof"))
+ return "";
+
try
{
clearStatus();
@@ -2021,6 +2220,9 @@ bool WalletImpl::checkReserveProof(const std::string &address, const std::string
std::string WalletImpl::signMessage(const std::string &message, const std::string &address)
{
+ if (checkBackgroundSync("cannot sign message"))
+ return "";
+
if (address.empty()) {
return m_wallet->sign(message, tools::wallet2::sign_with_spend_key);
}
@@ -2053,8 +2255,8 @@ std::string WalletImpl::signMultisigParticipant(const std::string &message) cons
{
clearStatus();
- bool ready = false;
- if (!m_wallet->multisig(&ready) || !ready) {
+ const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
+ if (!ms_status.multisig_is_active || !ms_status.is_ready) {
m_status = Status_Error;
m_errorString = tr("The wallet must be in multisig ready state");
return {};
@@ -2147,6 +2349,16 @@ bool WalletImpl::isDeterministic() const
return m_wallet->is_deterministic();
}
+bool WalletImpl::isBackgroundSyncing() const
+{
+ return m_wallet->is_background_syncing();
+}
+
+bool WalletImpl::isBackgroundWallet() const
+{
+ return m_wallet->is_background_wallet();
+}
+
void WalletImpl::clearStatus() const
{
boost::lock_guard<boost::mutex> l(m_statusMutex);
@@ -2215,9 +2427,7 @@ void WalletImpl::doRefresh()
if(rescan)
m_wallet->rescan_blockchain(false);
m_wallet->refresh(trustedDaemon());
- if (!m_synchronized) {
- m_synchronized = true;
- }
+ m_synchronized = m_wallet->is_synced();
// assuming if we have empty history, it wasn't initialized yet
// for further history changes client need to update history in
// "on_money_received" and "on_money_sent" callbacks
@@ -2320,6 +2530,24 @@ bool WalletImpl::doInit(const string &daemon_address, const std::string &proxy_a
return true;
}
+bool WalletImpl::checkBackgroundSync(const std::string &message) const
+{
+ clearStatus();
+ if (m_wallet->is_background_wallet())
+ {
+ LOG_ERROR("Background wallets " + message);
+ setStatusError(tr("Background wallets ") + message);
+ return true;
+ }
+ if (m_wallet->is_background_syncing())
+ {
+ LOG_ERROR(message + " while background syncing");
+ setStatusError(message + tr(" while background syncing. Stop background syncing first."));
+ return true;
+ }
+ return false;
+}
+
bool WalletImpl::parse_uri(const std::string &uri, std::string &address, std::string &payment_id, uint64_t &amount, std::string &tx_description, std::string &recipient_name, std::vector<std::string> &unknown_parameters, std::string &error)
{
return m_wallet->parse_uri(uri, address, payment_id, amount, tx_description, recipient_name, unknown_parameters, error);
@@ -2338,6 +2566,8 @@ std::string WalletImpl::getDefaultDataDir() const
bool WalletImpl::rescanSpent()
{
clearStatus();
+ if (checkBackgroundSync("cannot rescan spent"))
+ return false;
if (!trustedDaemon()) {
setStatusError(tr("Rescan spent can only be used with a trusted daemon"));
return false;
diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h
index d1bf4f759..1901efbca 100644
--- a/src/wallet/api/wallet.h
+++ b/src/wallet/api/wallet.h
@@ -148,6 +148,7 @@ public:
std::string getMultisigInfo() const override;
std::string makeMultisig(const std::vector<std::string>& info, uint32_t threshold) override;
std::string exchangeMultisigKeys(const std::vector<std::string> &info, const bool force_update_use_with_caution = false) override;
+ std::string getMultisigKeyExchangeBooster(const std::vector<std::string> &info, const uint32_t threshold, const uint32_t num_signers) override;
bool exportMultisigImages(std::string& images) override;
size_t importMultisigImages(const std::vector<std::string>& images) override;
bool hasMultisigPartialKeyImages() const override;
@@ -172,6 +173,13 @@ public:
bool importOutputs(const std::string &filename) override;
bool scanTransactions(const std::vector<std::string> &txids) override;
+ bool setupBackgroundSync(const BackgroundSyncType background_sync_type, const std::string &wallet_password, const optional<std::string> &background_cache_password = optional<std::string>()) override;
+ BackgroundSyncType getBackgroundSyncType() const override;
+ bool startBackgroundSync() override;
+ bool stopBackgroundSync(const std::string &wallet_password) override;
+ bool isBackgroundSyncing() const override;
+ bool isBackgroundWallet() const override;
+
virtual void disposeTransaction(PendingTransaction * t) override;
virtual uint64_t estimateTransactionFee(const std::vector<std::pair<std::string, uint64_t>> &destinations,
PendingTransaction::Priority priority) const override;
@@ -238,6 +246,7 @@ private:
bool isNewWallet() const;
void pendingTxPostProcess(PendingTransactionImpl * pending);
bool doInit(const std::string &daemon_address, const std::string &proxy_address, uint64_t upper_transaction_size_limit = 0, bool ssl = false);
+ bool checkBackgroundSync(const std::string &message) const;
private:
friend class PendingTransactionImpl;
@@ -253,6 +262,10 @@ private:
mutable boost::mutex m_statusMutex;
mutable int m_status;
mutable std::string m_errorString;
+ // TODO: harden password handling in the wallet API, see relevant discussion
+ // https://github.com/monero-project/monero-gui/issues/1537
+ // https://github.com/feather-wallet/feather/issues/72#issuecomment-1405602142
+ // https://github.com/monero-project/monero/pull/8619#issuecomment-1632951461
std::string m_password;
std::unique_ptr<TransactionHistoryImpl> m_history;
std::unique_ptr<Wallet2CallbackImpl> m_wallet2Callback;
diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h
index df86da847..4eaf80e70 100644
--- a/src/wallet/api/wallet2_api.h
+++ b/src/wallet/api/wallet2_api.h
@@ -322,9 +322,10 @@ struct SubaddressAccount
};
struct MultisigState {
- MultisigState() : isMultisig(false), isReady(false), threshold(0), total(0) {}
+ MultisigState() : isMultisig(false), kexIsDone(false), isReady(false), threshold(0), total(0) {}
bool isMultisig;
+ bool kexIsDone;
bool isReady;
uint32_t threshold;
uint32_t total;
@@ -445,6 +446,12 @@ struct Wallet
ConnectionStatus_WrongVersion
};
+ enum BackgroundSyncType {
+ BackgroundSync_Off = 0,
+ BackgroundSync_ReusePassword = 1,
+ BackgroundSync_CustomPassword = 2
+ };
+
virtual ~Wallet() = 0;
virtual std::string seed(const std::string& seed_offset = "") const = 0;
virtual std::string getSeedLanguage() const = 0;
@@ -802,6 +809,15 @@ struct Wallet
*/
virtual std::string exchangeMultisigKeys(const std::vector<std::string> &info, const bool force_update_use_with_caution) = 0;
/**
+ * @brief getMultisigKeyExchangeBooster - obtain partial information for the key exchange round after the in-progress round,
+ * to speed up another signer's key exchange process
+ * @param info - base58 encoded key derivations returned by makeMultisig or exchangeMultisigKeys function call
+ * @param threshold - number of required signers to make valid transaction. Must be <= number of participants.
+ * @param num_signers - total number of multisig participants.
+ * @return new info string if more rounds required or exception if no more rounds (i.e. no rounds to boost)
+ */
+ virtual std::string getMultisigKeyExchangeBooster(const std::vector<std::string> &info, const uint32_t threshold, const uint32_t num_signers) = 0;
+ /**
* @brief exportMultisigImages - exports transfers' key images
* @param images - output paramter for hex encoded array of images
* @return true if success
@@ -936,6 +952,42 @@ struct Wallet
*/
virtual bool scanTransactions(const std::vector<std::string> &txids) = 0;
+ /*!
+ * \brief setupBackgroundSync - setup background sync mode with just a view key
+ * \param background_sync_type - the mode the wallet background syncs in
+ * \param wallet_password
+ * \param background_cache_password - custom password to encrypt background cache, only needed for custom password background sync type
+ * \return - true on success
+ */
+ virtual bool setupBackgroundSync(const BackgroundSyncType background_sync_type, const std::string &wallet_password, const optional<std::string> &background_cache_password) = 0;
+
+ /*!
+ * \brief getBackgroundSyncType - get mode the wallet background syncs in
+ * \return - the type, or off if type is unknown
+ */
+ virtual BackgroundSyncType getBackgroundSyncType() const = 0;
+
+ /**
+ * @brief startBackgroundSync - sync the chain in the background with just view key
+ */
+ virtual bool startBackgroundSync() = 0;
+
+ /**
+ * @brief stopBackgroundSync - bring back spend key and process background synced txs
+ * \param wallet_password
+ */
+ virtual bool stopBackgroundSync(const std::string &wallet_password) = 0;
+
+ /**
+ * @brief isBackgroundSyncing - returns true if the wallet is background syncing
+ */
+ virtual bool isBackgroundSyncing() const = 0;
+
+ /**
+ * @brief isBackgroundWallet - returns true if the wallet is a background wallet
+ */
+ virtual bool isBackgroundWallet() const = 0;
+
virtual TransactionHistory * history() = 0;
virtual AddressBook * addressBook() = 0;
virtual Subaddress * subaddress() = 0;
diff --git a/src/wallet/message_store.h b/src/wallet/message_store.h
index 202d77be6..c0afa2afa 100644
--- a/src/wallet/message_store.h
+++ b/src/wallet/message_store.h
@@ -245,18 +245,23 @@ namespace mms
crypto::secret_key view_secret_key;
bool multisig;
bool multisig_is_ready;
+ bool multisig_kex_is_done;
bool has_multisig_partial_key_images;
uint32_t multisig_rounds_passed;
size_t num_transfer_details;
std::string mms_file;
BEGIN_SERIALIZE_OBJECT()
- VERSION_FIELD(0)
+ VERSION_FIELD(1)
FIELD(address)
VARINT_FIELD(nettype)
FIELD(view_secret_key)
FIELD(multisig)
FIELD(multisig_is_ready)
+ if (version > 0)
+ FIELD(multisig_kex_is_done)
+ else
+ multisig_kex_is_done = multisig_is_ready;
FIELD(has_multisig_partial_key_images)
VARINT_FIELD(multisig_rounds_passed)
VARINT_FIELD(num_transfer_details)
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index a9ad67f04..f5d4583c3 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -30,6 +30,7 @@
#include <algorithm>
#include <numeric>
+#include <string>
#include <tuple>
#include <queue>
#include <boost/format.hpp>
@@ -155,6 +156,8 @@ static const std::string MULTISIG_SIGNATURE_MAGIC = "SigMultisigPkV1";
static const std::string ASCII_OUTPUT_MAGIC = "MoneroAsciiDataV1";
+static const std::string BACKGROUND_WALLET_SUFFIX = ".background";
+
boost::mutex tools::wallet2::default_daemon_address_lock;
std::string tools::wallet2::default_daemon_address = "";
@@ -1007,14 +1010,14 @@ uint64_t num_priv_multisig_keys_post_setup(uint64_t threshold, uint64_t total)
* @param keys_data_key the chacha key that encrypts wallet keys files
* @return crypto::chacha_key the chacha key that encrypts the wallet cache files
*/
-crypto::chacha_key derive_cache_key(const crypto::chacha_key& keys_data_key)
+crypto::chacha_key derive_cache_key(const crypto::chacha_key& keys_data_key, const unsigned char domain_separator)
{
static_assert(HASH_SIZE == sizeof(crypto::chacha_key), "Mismatched sizes of hash and chacha key");
crypto::chacha_key cache_key;
epee::mlocked<tools::scrubbed_arr<char, HASH_SIZE+1>> cache_key_data;
memcpy(cache_key_data.data(), &keys_data_key, HASH_SIZE);
- cache_key_data[HASH_SIZE] = config::HASH_KEY_WALLET_CACHE;
+ cache_key_data[HASH_SIZE] = domain_separator;
cn_fast_hash(cache_key_data.data(), HASH_SIZE+1, (crypto::hash&) cache_key);
return cache_key;
@@ -1102,7 +1105,7 @@ wallet_keys_unlocker::wallet_keys_unlocker(wallet2 &w, const boost::optional<too
boost::lock_guard<boost::mutex> lock(lockers_lock);
if (lockers++ > 0)
locked = false;
- if (!locked || w.is_unattended() || w.ask_password() != tools::wallet2::AskPasswordToDecrypt || w.watch_only())
+ if (!locked || w.is_unattended() || w.ask_password() != tools::wallet2::AskPasswordToDecrypt || w.watch_only() || w.is_background_syncing())
{
locked = false;
return;
@@ -1218,6 +1221,11 @@ wallet2::wallet2(network_type nettype, uint64_t kdf_rounds, bool unattended, std
m_ignore_outputs_above(MONEY_SUPPLY),
m_ignore_outputs_below(0),
m_track_uses(false),
+ m_is_background_wallet(false),
+ m_background_sync_type(BackgroundSyncOff),
+ m_background_syncing(false),
+ m_processing_background_cache(false),
+ m_custom_background_key(boost::none),
m_show_wallet_name_when_locked(false),
m_inactivity_lock_timeout(DEFAULT_INACTIVITY_LOCK_TIMEOUT),
m_setup_background_mining(BackgroundMiningMaybe),
@@ -1360,6 +1368,10 @@ bool wallet2::set_daemon(std::string daemon_address, boost::optional<epee::net_u
{
boost::lock_guard<boost::recursive_mutex> lock(m_daemon_rpc_mutex);
+ if(daemon_address.empty()) {
+ daemon_address.append("http://localhost:" + std::to_string(get_config(m_nettype).RPC_DEFAULT_PORT));
+ }
+
if(m_http_client->is_connected())
m_http_client->disconnect();
CHECK_AND_ASSERT_MES2(m_proxy.empty() || proxy.empty() , "It is not possible to set global proxy (--proxy) and daemon specific proxy together.");
@@ -1438,20 +1450,20 @@ bool wallet2::get_seed(epee::wipeable_string& electrum_words, const epee::wipeab
//----------------------------------------------------------------------------------------------------
bool wallet2::get_multisig_seed(epee::wipeable_string& seed, const epee::wipeable_string &passphrase) const
{
- bool ready;
- uint32_t threshold, total;
- if (!multisig(&ready, &threshold, &total))
+ const multisig::multisig_account_status ms_status{get_multisig_status()};
+
+ if (!ms_status.multisig_is_active)
{
std::cout << "This is not a multisig wallet" << std::endl;
return false;
}
- if (!ready)
+ if (!ms_status.is_ready)
{
std::cout << "This multisig wallet is not yet finalized" << std::endl;
return false;
}
- const uint64_t num_expected_ms_keys = num_priv_multisig_keys_post_setup(threshold, total);
+ const uint64_t num_expected_ms_keys = num_priv_multisig_keys_post_setup(ms_status.threshold, ms_status.total);
crypto::secret_key skey;
crypto::public_key pkey;
@@ -1459,8 +1471,8 @@ bool wallet2::get_multisig_seed(epee::wipeable_string& seed, const epee::wipeabl
THROW_WALLET_EXCEPTION_IF(num_expected_ms_keys != keys.m_multisig_keys.size(),
error::wallet_internal_error, "Unexpected number of private multisig keys")
epee::wipeable_string data;
- data.append((const char*)&threshold, sizeof(uint32_t));
- data.append((const char*)&total, sizeof(uint32_t));
+ data.append((const char*)&ms_status.threshold, sizeof(uint32_t));
+ data.append((const char*)&ms_status.total, sizeof(uint32_t));
skey = keys.m_spend_secret_key;
data.append((const char*)&skey, sizeof(skey));
pkey = keys.m_account_address.m_spend_public_key;
@@ -1849,6 +1861,9 @@ bool has_nonrequested_tx_at_height_or_above_requested(uint64_t height, const std
//----------------------------------------------------------------------------------------------------
void wallet2::scan_tx(const std::unordered_set<crypto::hash> &txids)
{
+ THROW_WALLET_EXCEPTION_IF(m_background_syncing || m_is_background_wallet, error::wallet_internal_error,
+ "cannot scan tx from background wallet");
+
// Get the transactions from daemon in batches sorted lowest height to highest
tx_entry_data txs_to_scan = get_tx_entries(txids);
if (txs_to_scan.tx_entries.empty())
@@ -2156,11 +2171,11 @@ void wallet2::scan_output(const cryptonote::transaction &tx, bool miner_tx, cons
THROW_WALLET_EXCEPTION_IF(i >= tx.vout.size(), error::wallet_internal_error, "Invalid vout index");
// if keys are encrypted, ask for password
- if (m_ask_password == AskPasswordToDecrypt && !m_unattended && !m_watch_only && !m_multisig_rescan_k)
+ if (m_ask_password == AskPasswordToDecrypt && !m_unattended && !m_watch_only && !m_multisig_rescan_k && !m_background_syncing)
{
static critical_section password_lock;
CRITICAL_REGION_LOCAL(password_lock);
- if (!m_encrypt_keys_after_refresh)
+ if (!m_encrypt_keys_after_refresh && !m_processing_background_cache)
{
boost::optional<epee::wipeable_string> pwd = m_callback->on_get_password(pool ? "output found in pool" : "output received");
THROW_WALLET_EXCEPTION_IF(!pwd, error::password_needed, tr("Password is needed to compute key image for incoming monero"));
@@ -2172,7 +2187,7 @@ void wallet2::scan_output(const cryptonote::transaction &tx, bool miner_tx, cons
crypto::public_key output_public_key;
THROW_WALLET_EXCEPTION_IF(!get_output_public_key(tx.vout[i], output_public_key), error::wallet_internal_error, "Failed to get output public key");
- if (m_multisig)
+ if (m_multisig || m_background_syncing/*no spend key*/)
{
tx_scan_info.in_ephemeral.pub = output_public_key;
tx_scan_info.in_ephemeral.sec = crypto::null_skey;
@@ -2429,6 +2444,22 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
THROW_WALLET_EXCEPTION_IF(tx.vout.size() != o_indices.size(), error::wallet_internal_error,
"transactions outputs size=" + std::to_string(tx.vout.size()) +
" not match with daemon response size=" + std::to_string(o_indices.size()));
+
+ // we're going to re-process this receive when background sync is disabled
+ if (m_background_syncing && m_background_sync_data.txs.find(txid) == m_background_sync_data.txs.end())
+ {
+ size_t bgs_idx = m_background_sync_data.txs.size();
+ background_synced_tx_t bgs_tx = {
+ .index_in_background_sync_data = bgs_idx,
+ .tx = tx,
+ .output_indices = o_indices,
+ .height = height,
+ .block_timestamp = ts,
+ .double_spend_seen = double_spend_seen
+ };
+ LOG_PRINT_L2("Adding received tx " << txid << " to background sync data (idx=" << bgs_idx << ")");
+ m_background_sync_data.txs.insert({txid, std::move(bgs_tx)});
+ }
}
for(size_t o: outs)
@@ -2454,7 +2485,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
td.m_tx = (const cryptonote::transaction_prefix&)tx;
td.m_txid = txid;
td.m_key_image = tx_scan_info[o].ki;
- td.m_key_image_known = !m_watch_only && !m_multisig;
+ td.m_key_image_known = !m_watch_only && !m_multisig && !m_background_syncing;
if (!td.m_key_image_known)
{
// we might have cold signed, and have a mapping to key images
@@ -2644,10 +2675,25 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
set_spent(it->second, height);
if (!ignore_callbacks && 0 != m_callback)
m_callback->on_money_spent(height, txid, tx, amount, tx, td.m_subaddr_index);
+
+ if (m_background_syncing && m_background_sync_data.txs.find(txid) == m_background_sync_data.txs.end())
+ {
+ size_t bgs_idx = m_background_sync_data.txs.size();
+ background_synced_tx_t bgs_tx = {
+ .index_in_background_sync_data = bgs_idx,
+ .tx = tx,
+ .output_indices = o_indices,
+ .height = height,
+ .block_timestamp = ts,
+ .double_spend_seen = double_spend_seen
+ };
+ LOG_PRINT_L2("Adding spent tx " << txid << " to background sync data (idx=" << bgs_idx << ")");
+ m_background_sync_data.txs.insert({txid, std::move(bgs_tx)});
+ }
}
}
- if (!pool && m_track_uses)
+ if (!pool && (m_track_uses || (m_background_syncing && it == m_key_images.end())))
{
PERF_TIMER(track_uses);
const uint64_t amount = in_to_key.amount;
@@ -2661,7 +2707,27 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
{
size_t idx = i->second;
THROW_WALLET_EXCEPTION_IF(idx >= m_transfers.size(), error::wallet_internal_error, "Output tracker cache index out of range");
- m_transfers[idx].m_uses.push_back(std::make_pair(height, txid));
+
+ if (m_track_uses)
+ m_transfers[idx].m_uses.push_back(std::make_pair(height, txid));
+
+ // We'll re-process all txs which *might* be spends when we disable
+ // background sync and retrieve the spend key. We don't know if an
+ // output is a spend in this tx if we don't know its key image.
+ if (m_background_syncing && !m_transfers[idx].m_key_image_known && m_background_sync_data.txs.find(txid) == m_background_sync_data.txs.end())
+ {
+ size_t bgs_idx = m_background_sync_data.txs.size();
+ background_synced_tx_t bgs_tx = {
+ .index_in_background_sync_data = bgs_idx,
+ .tx = tx,
+ .output_indices = o_indices,
+ .height = height,
+ .block_timestamp = ts,
+ .double_spend_seen = double_spend_seen
+ };
+ LOG_PRINT_L2("Adding plausible spent tx " << txid << " to background sync data (idx=" << bgs_idx << ")");
+ m_background_sync_data.txs.insert({txid, std::move(bgs_tx)});
+ }
}
}
}
@@ -2671,7 +2737,24 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
continue;
for (uint64_t offset: offsets)
if (offset == td.m_global_output_index)
- td.m_uses.push_back(std::make_pair(height, txid));
+ {
+ if (m_track_uses)
+ td.m_uses.push_back(std::make_pair(height, txid));
+ if (m_background_syncing && !td.m_key_image_known && m_background_sync_data.txs.find(txid) == m_background_sync_data.txs.end())
+ {
+ size_t bgs_idx = m_background_sync_data.txs.size();
+ background_synced_tx_t bgs_tx = {
+ .index_in_background_sync_data = bgs_idx,
+ .tx = tx,
+ .output_indices = o_indices,
+ .height = height,
+ .block_timestamp = ts,
+ .double_spend_seen = double_spend_seen
+ };
+ LOG_PRINT_L2("Adding plausible spent tx " << txid << " to background sync data (idx=" << bgs_idx << ")");
+ m_background_sync_data.txs.insert({txid, std::move(bgs_tx)});
+ }
+ }
}
}
}
@@ -3044,8 +3127,8 @@ void wallet2::pull_blocks(bool first, bool try_incremental, uint64_t start_heigh
req.start_height = start_height;
req.no_miner_tx = m_refresh_type == RefreshNoCoinbase;
- req.requested_info = first ? COMMAND_RPC_GET_BLOCKS_FAST::BLOCKS_AND_POOL : COMMAND_RPC_GET_BLOCKS_FAST::BLOCKS_ONLY;
- if (try_incremental)
+ req.requested_info = (first && !m_background_syncing) ? COMMAND_RPC_GET_BLOCKS_FAST::BLOCKS_AND_POOL : COMMAND_RPC_GET_BLOCKS_FAST::BLOCKS_ONLY;
+ if (try_incremental && !m_background_syncing)
req.pool_info_since = m_pool_info_query_time;
{
@@ -3068,7 +3151,7 @@ void wallet2::pull_blocks(bool first, bool try_incremental, uint64_t start_heigh
<< ", height " << blocks_start_height + blocks.size() << ", node height " << res.current_height
<< ", pool info " << static_cast<unsigned int>(res.pool_info_extent));
- if (first)
+ if (first && !m_background_syncing)
{
if (res.pool_info_extent != COMMAND_RPC_GET_BLOCKS_FAST::NONE)
{
@@ -3582,6 +3665,9 @@ void wallet2::process_unconfirmed_transfer(bool incremental, const crypto::hash
// incremental update anymore, because with that we might miss some txs altogether.
void wallet2::update_pool_state(std::vector<std::tuple<cryptonote::transaction, crypto::hash, bool>> &process_txs, bool refreshed, bool try_incremental)
{
+ process_txs.clear();
+ if (m_background_syncing)
+ return;
bool updated = false;
if (m_pool_info_query_time != 0 && try_incremental)
{
@@ -4116,6 +4202,8 @@ void wallet2::refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blo
}
m_first_refresh_done = true;
+ if (m_background_syncing || m_is_background_wallet)
+ m_background_sync_data.first_refresh_done = true;
LOG_PRINT_L1("Refresh done, blocks received: " << blocks_fetched << ", balance (all accounts): " << print_money(balance_all(false)) << ", unlocked: " << print_money(unlocked_balance_all(false)));
}
@@ -4198,6 +4286,14 @@ wallet2::detached_blockchain_data wallet2::detach_blockchain(uint64_t height, st
td.m_uses.pop_back();
}
+ for (auto it = m_background_sync_data.txs.begin(); it != m_background_sync_data.txs.end(); )
+ {
+ if(height <= it->second.height)
+ it = m_background_sync_data.txs.erase(it);
+ else
+ ++it;
+ }
+
if (output_tracker_cache)
output_tracker_cache->clear();
@@ -4272,8 +4368,12 @@ void wallet2::handle_reorg(uint64_t height, std::map<std::pair<uint64_t, uint64_
// C
THROW_WALLET_EXCEPTION_IF(height < m_blockchain.offset() && m_blockchain.size() > m_blockchain.offset(),
error::wallet_internal_error, "Daemon claims reorg below last checkpoint");
+
detached_blockchain_data dbd = detach_blockchain(height, output_tracker_cache);
+ if (m_background_syncing && height < m_background_sync_data.start_height)
+ m_background_sync_data.start_height = height;
+
if (m_callback)
m_callback->on_reorg(height, dbd.detached_blockchain.size(), dbd.detached_tx_hashes.size());
}
@@ -4283,6 +4383,7 @@ bool wallet2::deinit()
if(m_is_initialized) {
m_is_initialized = false;
unlock_keys_file();
+ unlock_background_keys_file();
m_account.deinit();
}
return true;
@@ -4309,6 +4410,7 @@ bool wallet2::clear()
m_device_last_key_image_sync = 0;
m_pool_info_query_time = 0;
m_skip_to_height = 0;
+ m_background_sync_data = background_sync_data_t{};
return true;
}
//----------------------------------------------------------------------------------------------------
@@ -4327,13 +4429,30 @@ void wallet2::clear_soft(bool keep_key_images)
m_scanned_pool_txs[1].clear();
m_pool_info_query_time = 0;
m_skip_to_height = 0;
+ m_background_sync_data = background_sync_data_t{};
cryptonote::block b;
generate_genesis(b);
m_blockchain.push_back(get_block_hash(b));
m_last_block_reward = cryptonote::get_outs_money_amount(b.miner_tx);
}
-
+//----------------------------------------------------------------------------------------------------
+void wallet2::clear_user_data()
+{
+ for (auto i = m_confirmed_txs.begin(); i != m_confirmed_txs.end(); ++i)
+ i->second.m_dests.clear();
+ for (auto i = m_unconfirmed_txs.begin(); i != m_unconfirmed_txs.end(); ++i)
+ i->second.m_dests.clear();
+ for (auto i = m_transfers.begin(); i != m_transfers.end(); ++i)
+ i->m_frozen = false;
+ m_tx_keys.clear();
+ m_tx_notes.clear();
+ m_address_book.clear();
+ m_subaddress_labels.clear();
+ m_attributes.clear();
+ m_account_tags = std::pair<std::map<std::string, std::string>, std::vector<std::string>>();
+}
+//----------------------------------------------------------------------------------------------------
/*!
* \brief Stores wallet information to wallet file.
* \param keys_file_name Name of wallet file
@@ -4345,16 +4464,35 @@ bool wallet2::store_keys(const std::string& keys_file_name, const epee::wipeable
{
boost::optional<wallet2::keys_file_data> keys_file_data = get_keys_file_data(password, watch_only);
CHECK_AND_ASSERT_MES(keys_file_data != boost::none, false, "failed to generate wallet keys data");
-
+ return store_keys_file_data(keys_file_name, keys_file_data.get());
+}
+//----------------------------------------------------------------------------------------------------
+bool wallet2::store_keys(const std::string& keys_file_name, const crypto::chacha_key& key, bool watch_only, bool background_keys_file)
+{
+ boost::optional<wallet2::keys_file_data> keys_file_data = get_keys_file_data(key, watch_only, background_keys_file);
+ CHECK_AND_ASSERT_MES(keys_file_data != boost::none, false, "failed to generate wallet keys data");
+ return store_keys_file_data(keys_file_name, keys_file_data.get(), background_keys_file);
+}
+//----------------------------------------------------------------------------------------------------
+bool wallet2::store_keys_file_data(const std::string& keys_file_name, wallet2::keys_file_data &keys_file_data, bool background_keys_file)
+{
std::string tmp_file_name = keys_file_name + ".new";
std::string buf;
- bool r = ::serialization::dump_binary(keys_file_data.get(), buf);
+ bool r = ::serialization::dump_binary(keys_file_data, buf);
r = r && save_to_file(tmp_file_name, buf);
CHECK_AND_ASSERT_MES(r, false, "failed to generate wallet keys file " << tmp_file_name);
- unlock_keys_file();
+ if (!background_keys_file)
+ unlock_keys_file();
+ else
+ unlock_background_keys_file();
+
std::error_code e = tools::replace_file(tmp_file_name, keys_file_name);
- lock_keys_file();
+
+ if (!background_keys_file)
+ lock_keys_file();
+ else
+ lock_background_keys_file(keys_file_name);
if (e) {
boost::filesystem::remove(tmp_file_name);
@@ -4367,25 +4505,26 @@ bool wallet2::store_keys(const std::string& keys_file_name, const epee::wipeable
//----------------------------------------------------------------------------------------------------
boost::optional<wallet2::keys_file_data> wallet2::get_keys_file_data(const epee::wipeable_string& password, bool watch_only)
{
+ crypto::chacha_key key;
+ crypto::generate_chacha_key(password.data(), password.size(), key, m_kdf_rounds);
+ verify_password_with_cached_key(key);
+ return get_keys_file_data(key, watch_only);
+}
+//----------------------------------------------------------------------------------------------------
+boost::optional<wallet2::keys_file_data> wallet2::get_keys_file_data(const crypto::chacha_key& key, bool watch_only, bool background_keys_file)
+{
epee::byte_slice account_data;
std::string multisig_signers;
std::string multisig_derivations;
cryptonote::account_base account = m_account;
- crypto::chacha_key key;
- crypto::generate_chacha_key(password.data(), password.size(), key, m_kdf_rounds);
-
- // We use m_cache_key as a deterministic test to see if given key corresponds to original password
- const crypto::chacha_key cache_key = derive_cache_key(key);
- THROW_WALLET_EXCEPTION_IF(cache_key != m_cache_key, error::invalid_password);
-
if (m_ask_password == AskPasswordToDecrypt && !m_unattended && !m_watch_only)
{
account.encrypt_viewkey(key);
account.decrypt_keys(key);
}
- if (watch_only)
+ if (watch_only || background_keys_file)
account.forget_spend_key();
account.encrypt_keys(key);
@@ -4520,6 +4659,9 @@ boost::optional<wallet2::keys_file_data> wallet2::get_keys_file_data(const epee:
value2.SetInt(m_track_uses ? 1 : 0);
json.AddMember("track_uses", value2, json.GetAllocator());
+ value2.SetInt(m_background_sync_type);
+ json.AddMember("background_sync_type", value2, json.GetAllocator());
+
value2.SetInt(m_show_wallet_name_when_locked ? 1 : 0);
json.AddMember("show_wallet_name_when_locked", value2, json.GetAllocator());
@@ -4580,6 +4722,12 @@ boost::optional<wallet2::keys_file_data> wallet2::get_keys_file_data(const epee:
value2.SetInt(m_enable_multisig ? 1 : 0);
json.AddMember("enable_multisig", value2, json.GetAllocator());
+ if (m_background_sync_type == BackgroundSyncCustomPassword && !background_keys_file && m_custom_background_key)
+ {
+ value.SetString(reinterpret_cast<const char*>(m_custom_background_key.get().data()), m_custom_background_key.get().size());
+ json.AddMember("custom_background_key", value, json.GetAllocator());
+ }
+
// Serialize the JSON object
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
@@ -4606,13 +4754,81 @@ void wallet2::setup_keys(const epee::wipeable_string &password)
m_account.decrypt_viewkey(key);
}
- m_cache_key = derive_cache_key(key);
+ m_cache_key = derive_cache_key(key, config::HASH_KEY_WALLET_CACHE);
get_ringdb_key();
}
//----------------------------------------------------------------------------------------------------
+void validate_background_cache_password_usage(const tools::wallet2::BackgroundSyncType background_sync_type, const boost::optional<epee::wipeable_string> &background_cache_password, const bool multisig, const bool watch_only, const bool key_on_device)
+{
+ THROW_WALLET_EXCEPTION_IF(multisig || watch_only || key_on_device, error::wallet_internal_error, multisig
+ ? "Background sync not implemented for multisig wallets" : watch_only
+ ? "Background sync not implemented for view only wallets"
+ : "Background sync not implemented for HW wallets");
+
+ switch (background_sync_type)
+ {
+ case tools::wallet2::BackgroundSyncOff:
+ {
+ THROW_WALLET_EXCEPTION(error::wallet_internal_error, "background sync is not enabled");
+ break;
+ }
+ case tools::wallet2::BackgroundSyncReusePassword:
+ {
+ THROW_WALLET_EXCEPTION_IF(background_cache_password, error::wallet_internal_error,
+ "unexpected custom background cache password");
+ break;
+ }
+ case tools::wallet2::BackgroundSyncCustomPassword:
+ {
+ THROW_WALLET_EXCEPTION_IF(!background_cache_password, error::wallet_internal_error,
+ "expected custom background cache password");
+ break;
+ }
+ default: THROW_WALLET_EXCEPTION(error::wallet_internal_error, "unknown background sync type");
+ }
+}
+//----------------------------------------------------------------------------------------------------
+void get_custom_background_key(const epee::wipeable_string &password, crypto::chacha_key &custom_background_key, const uint64_t kdf_rounds)
+{
+ crypto::chacha_key key;
+ crypto::generate_chacha_key(password.data(), password.size(), key, kdf_rounds);
+ custom_background_key = derive_cache_key(key, config::HASH_KEY_BACKGROUND_KEYS_FILE);
+}
+//----------------------------------------------------------------------------------------------------
+const crypto::chacha_key wallet2::get_cache_key()
+{
+ if (m_background_sync_type == BackgroundSyncCustomPassword && m_background_syncing)
+ {
+ THROW_WALLET_EXCEPTION_IF(!m_custom_background_key, error::wallet_internal_error, "Custom background key not set");
+ // Domain separate keys used to encrypt background keys file and cache
+ return derive_cache_key(m_custom_background_key.get(), config::HASH_KEY_BACKGROUND_CACHE);
+ }
+ else
+ {
+ return m_cache_key;
+ }
+}
+//----------------------------------------------------------------------------------------------------
+void wallet2::verify_password_with_cached_key(const epee::wipeable_string &password)
+{
+ crypto::chacha_key key;
+ crypto::generate_chacha_key(password.data(), password.size(), key, m_kdf_rounds);
+ verify_password_with_cached_key(key);
+}
+//----------------------------------------------------------------------------------------------------
+void wallet2::verify_password_with_cached_key(const crypto::chacha_key &key)
+{
+ // We use m_cache_key as a deterministic test to see if given key corresponds to original password
+ const crypto::chacha_key cache_key = derive_cache_key(key, config::HASH_KEY_WALLET_CACHE);
+ THROW_WALLET_EXCEPTION_IF(cache_key != m_cache_key, error::invalid_password);
+}
+//----------------------------------------------------------------------------------------------------
void wallet2::change_password(const std::string &filename, const epee::wipeable_string &original_password, const epee::wipeable_string &new_password)
{
+ THROW_WALLET_EXCEPTION_IF(m_background_syncing || m_is_background_wallet, error::wallet_internal_error,
+ "cannot change password from background wallet");
+
if (m_ask_password == AskPasswordToDecrypt && !m_unattended && !m_watch_only)
decrypt_keys(original_password);
setup_keys(new_password);
@@ -4671,8 +4887,24 @@ bool wallet2::load_keys_buf(const std::string& keys_buf, const epee::wipeable_st
std::string account_data;
account_data.resize(keys_file_data.account_data.size());
crypto::chacha20(keys_file_data.account_data.data(), keys_file_data.account_data.size(), key, keys_file_data.iv, &account_data[0]);
- if (json.Parse(account_data.c_str()).HasParseError() || !json.IsObject())
+ const bool try_v0_format = json.Parse(account_data.c_str()).HasParseError() || !json.IsObject();
+ if (try_v0_format)
crypto::chacha8(keys_file_data.account_data.data(), keys_file_data.account_data.size(), key, keys_file_data.iv, &account_data[0]);
+
+ // Check if it's a background keys file if both of the above formats fail
+ {
+ m_is_background_wallet = false;
+ m_background_syncing = false;
+ cryptonote::account_base account_data_check;
+ if (try_v0_format && !epee::serialization::load_t_from_binary(account_data_check, account_data))
+ {
+ get_custom_background_key(password, key, m_kdf_rounds);
+ crypto::chacha20(keys_file_data.account_data.data(), keys_file_data.account_data.size(), key, keys_file_data.iv, &account_data[0]);
+ m_is_background_wallet = !json.Parse(account_data.c_str()).HasParseError() && json.IsObject();
+ m_background_syncing = m_is_background_wallet; // start a background wallet background syncing
+ }
+ }
+
// The contents should be JSON if the wallet follows the new format.
if (json.Parse(account_data.c_str()).HasParseError())
{
@@ -4709,6 +4941,7 @@ bool wallet2::load_keys_buf(const std::string& keys_buf, const epee::wipeable_st
m_ignore_outputs_above = MONEY_SUPPLY;
m_ignore_outputs_below = 0;
m_track_uses = false;
+ m_background_sync_type = BackgroundSyncOff;
m_show_wallet_name_when_locked = false;
m_inactivity_lock_timeout = DEFAULT_INACTIVITY_LOCK_TIMEOUT;
m_setup_background_mining = BackgroundMiningMaybe;
@@ -4723,6 +4956,7 @@ bool wallet2::load_keys_buf(const std::string& keys_buf, const epee::wipeable_st
encrypted_secret_keys = false;
m_enable_multisig = false;
m_allow_mismatched_daemon_version = false;
+ m_custom_background_key = boost::none;
}
else if(json.IsObject())
{
@@ -4950,6 +5184,39 @@ bool wallet2::load_keys_buf(const std::string& keys_buf, const epee::wipeable_st
GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, enable_multisig, int, Int, false, false);
m_enable_multisig = field_enable_multisig;
+
+ GET_FIELD_FROM_JSON_RETURN_ON_ERROR(json, background_sync_type, BackgroundSyncType, Int, false, BackgroundSyncOff);
+ m_background_sync_type = field_background_sync_type;
+
+ // Load encryption key used to encrypt background cache
+ crypto::chacha_key custom_background_key;
+ m_custom_background_key = boost::none;
+ if (m_background_sync_type == BackgroundSyncCustomPassword && !m_is_background_wallet)
+ {
+ if (!json.HasMember("custom_background_key"))
+ {
+ LOG_ERROR("Field custom_background_key not found in JSON");
+ return false;
+ }
+ else if (!json["custom_background_key"].IsString())
+ {
+ LOG_ERROR("Field custom_background_key found in JSON, but not String");
+ return false;
+ }
+ else if (json["custom_background_key"].GetStringLength() != sizeof(crypto::chacha_key))
+ {
+ LOG_ERROR("Field custom_background_key found in JSON, but not correct length");
+ return false;
+ }
+ const char *field_custom_background_key = json["custom_background_key"].GetString();
+ memcpy(custom_background_key.data(), field_custom_background_key, sizeof(crypto::chacha_key));
+ m_custom_background_key = boost::optional<crypto::chacha_key>(custom_background_key);
+ LOG_PRINT_L1("Loaded custom background key derived from custom password");
+ }
+ else if (json.HasMember("custom_background_key"))
+ {
+ LOG_ERROR("Unexpected field custom_background_key found in JSON");
+ }
}
else
{
@@ -5013,12 +5280,17 @@ bool wallet2::load_keys_buf(const std::string& keys_buf, const epee::wipeable_st
const cryptonote::account_keys& keys = m_account.get_keys();
hw::device &hwdev = m_account.get_device();
r = r && hwdev.verify_keys(keys.m_view_secret_key, keys.m_account_address.m_view_public_key);
- if (!m_watch_only && !m_multisig && hwdev.device_protocol() != hw::device::PROTOCOL_COLD)
+ if (!m_watch_only && !m_multisig && hwdev.device_protocol() != hw::device::PROTOCOL_COLD && !m_is_background_wallet)
r = r && hwdev.verify_keys(keys.m_spend_secret_key, keys.m_account_address.m_spend_public_key);
THROW_WALLET_EXCEPTION_IF(!r, error::wallet_files_doesnt_correspond, m_keys_file, m_wallet_file);
if (r)
- setup_keys(password);
+ {
+ if (!m_is_background_wallet)
+ setup_keys(password);
+ else
+ m_custom_background_key = boost::optional<crypto::chacha_key>(key);
+ }
return true;
}
@@ -5033,11 +5305,12 @@ bool wallet2::load_keys_buf(const std::string& keys_buf, const epee::wipeable_st
* can be used prior to rewriting wallet keys file, to ensure user has entered the correct password
*
*/
-bool wallet2::verify_password(const epee::wipeable_string& password)
+bool wallet2::verify_password(const epee::wipeable_string& password, crypto::secret_key &spend_key_out)
{
// this temporary unlocking is necessary for Windows (otherwise the file couldn't be loaded).
unlock_keys_file();
- bool r = verify_password(m_keys_file, password, m_account.get_device().device_protocol() == hw::device::PROTOCOL_COLD || m_watch_only || m_multisig, m_account.get_device(), m_kdf_rounds);
+ const bool no_spend_key = m_account.get_device().device_protocol() == hw::device::PROTOCOL_COLD || m_watch_only || m_multisig || m_is_background_wallet;
+ bool r = verify_password(m_keys_file, password, no_spend_key, m_account.get_device(), m_kdf_rounds, spend_key_out);
lock_keys_file();
return r;
}
@@ -5055,7 +5328,7 @@ bool wallet2::verify_password(const epee::wipeable_string& password)
* can be used prior to rewriting wallet keys file, to ensure user has entered the correct password
*
*/
-bool wallet2::verify_password(const std::string& keys_file_name, const epee::wipeable_string& password, bool no_spend_key, hw::device &hwdev, uint64_t kdf_rounds)
+bool wallet2::verify_password(const std::string& keys_file_name, const epee::wipeable_string& password, bool no_spend_key, hw::device &hwdev, uint64_t kdf_rounds, crypto::secret_key &spend_key_out)
{
rapidjson::Document json;
wallet2::keys_file_data keys_file_data;
@@ -5072,9 +5345,22 @@ bool wallet2::verify_password(const std::string& keys_file_name, const epee::wip
std::string account_data;
account_data.resize(keys_file_data.account_data.size());
crypto::chacha20(keys_file_data.account_data.data(), keys_file_data.account_data.size(), key, keys_file_data.iv, &account_data[0]);
- if (json.Parse(account_data.c_str()).HasParseError() || !json.IsObject())
+ const bool try_v0_format = json.Parse(account_data.c_str()).HasParseError() || !json.IsObject();
+ if (try_v0_format)
crypto::chacha8(keys_file_data.account_data.data(), keys_file_data.account_data.size(), key, keys_file_data.iv, &account_data[0]);
+ // Check if it's a background keys file if both of the above formats fail
+ {
+ cryptonote::account_base account_data_check;
+ if (try_v0_format && !epee::serialization::load_t_from_binary(account_data_check, account_data))
+ {
+ get_custom_background_key(password, key, kdf_rounds);
+ crypto::chacha20(keys_file_data.account_data.data(), keys_file_data.account_data.size(), key, keys_file_data.iv, &account_data[0]);
+ const bool is_background_wallet = json.Parse(account_data.c_str()).HasParseError() && json.IsObject();
+ no_spend_key = no_spend_key || is_background_wallet;
+ }
+ }
+
// The contents should be JSON if the wallet follows the new format.
if (json.Parse(account_data.c_str()).HasParseError())
{
@@ -5099,6 +5385,7 @@ bool wallet2::verify_password(const std::string& keys_file_name, const epee::wip
r = r && hwdev.verify_keys(keys.m_view_secret_key, keys.m_account_address.m_view_public_key);
if(!no_spend_key)
r = r && hwdev.verify_keys(keys.m_spend_secret_key, keys.m_account_address.m_spend_public_key);
+ spend_key_out = (!no_spend_key && r) ? keys.m_spend_secret_key : crypto::null_skey;
return r;
}
@@ -5110,9 +5397,7 @@ void wallet2::encrypt_keys(const crypto::chacha_key &key)
void wallet2::decrypt_keys(const crypto::chacha_key &key)
{
- // We use m_cache_key as a deterministic test to see if given key corresponds to original password
- const crypto::chacha_key cache_key = derive_cache_key(key);
- THROW_WALLET_EXCEPTION_IF(cache_key != m_cache_key, error::invalid_password);
+ verify_password_with_cached_key(key);
m_account.encrypt_viewkey(key);
m_account.decrypt_keys(key);
@@ -5504,32 +5789,77 @@ void wallet2::restore(const std::string& wallet_, const epee::wipeable_string& p
}
}
//----------------------------------------------------------------------------------------------------
-std::string wallet2::make_multisig(const epee::wipeable_string &password,
- const std::vector<std::string> &initial_kex_msgs,
- const std::uint32_t threshold)
+epee::misc_utils::auto_scope_leave_caller wallet2::decrypt_account_for_multisig(const epee::wipeable_string &password)
{
// decrypt account keys
+ // note: this conditional's clauses are old and undocumented
epee::misc_utils::auto_scope_leave_caller keys_reencryptor;
if (m_ask_password == AskPasswordToDecrypt && !m_unattended && !m_watch_only)
{
crypto::chacha_key chacha_key;
crypto::generate_chacha_key(password.data(), password.size(), chacha_key, m_kdf_rounds);
- m_account.encrypt_viewkey(chacha_key);
- m_account.decrypt_keys(chacha_key);
+ this->decrypt_keys(chacha_key);
keys_reencryptor = epee::misc_utils::create_scope_leave_handler(
- [&, this, chacha_key]()
+ [this, chacha_key]()
{
- m_account.encrypt_keys(chacha_key);
- m_account.decrypt_viewkey(chacha_key);
+ this->encrypt_keys(chacha_key);
}
);
}
- // create multisig account
- multisig::multisig_account multisig_account{
- multisig::get_multisig_blinded_secret_key(get_account().get_keys().m_spend_secret_key),
- multisig::get_multisig_blinded_secret_key(get_account().get_keys().m_view_secret_key)
+ return keys_reencryptor;
+}
+//----------------------------------------------------------------------------------------------------
+void wallet2::get_uninitialized_multisig_account(multisig::multisig_account &account_out) const
+{
+ // create uninitialized multisig account
+ account_out = multisig::multisig_account{
+ // k_base = H(normal private spend key)
+ multisig::get_multisig_blinded_secret_key(this->get_account().get_keys().m_spend_secret_key),
+ // k_view = H(normal private view key)
+ multisig::get_multisig_blinded_secret_key(this->get_account().get_keys().m_view_secret_key)
};
+}
+//----------------------------------------------------------------------------------------------------
+void wallet2::get_reconstructed_multisig_account(multisig::multisig_account &account_out) const
+{
+ const multisig::multisig_account_status ms_status{this->get_multisig_status()};
+ CHECK_AND_ASSERT_THROW_MES(ms_status.multisig_is_active,
+ "The wallet is not multisig, so the multisig account couldn't be reconstructed");
+
+ // reconstruct multisig account
+ crypto::public_key common_pubkey;
+ crypto::secret_key_to_public_key(this->get_account().get_keys().m_view_secret_key, common_pubkey);
+
+ multisig::multisig_keyset_map_memsafe_t kex_origins_map;
+ for (const auto &derivation : m_multisig_derivations)
+ kex_origins_map[derivation];
+
+ account_out = multisig::multisig_account{
+ m_multisig_threshold,
+ m_multisig_signers,
+ this->get_account().get_keys().m_spend_secret_key,
+ this->get_account().get_keys().m_view_secret_key,
+ this->get_account().get_keys().m_multisig_keys,
+ this->get_account().get_keys().m_view_secret_key,
+ m_account_public_address.m_spend_public_key,
+ common_pubkey,
+ m_multisig_rounds_passed,
+ std::move(kex_origins_map),
+ ""
+ };
+}
+//----------------------------------------------------------------------------------------------------
+std::string wallet2::make_multisig(const epee::wipeable_string &password,
+ const std::vector<std::string> &initial_kex_msgs,
+ const std::uint32_t threshold)
+{
+ // decrypt account keys
+ epee::misc_utils::auto_scope_leave_caller keys_reencryptor{this->decrypt_account_for_multisig(password)};
+
+ // create multisig account
+ multisig::multisig_account multisig_account;
+ this->get_uninitialized_multisig_account(multisig_account);
// open initial kex messages, validate them, extract signers
std::vector<multisig::multisig_kex_msg> expanded_msgs;
@@ -5537,7 +5867,7 @@ std::string wallet2::make_multisig(const epee::wipeable_string &password,
expanded_msgs.reserve(initial_kex_msgs.size());
signers.reserve(initial_kex_msgs.size() + 1);
- for (const auto &msg : initial_kex_msgs)
+ for (const std::string &msg : initial_kex_msgs)
{
expanded_msgs.emplace_back(msg);
@@ -5546,17 +5876,19 @@ std::string wallet2::make_multisig(const epee::wipeable_string &password,
CHECK_AND_ASSERT_THROW_MES(expanded_msgs.back().get_round() == 1,
"Trying to make multisig with message that has invalid multisig kex round (should be '1').");
- // 2. duplicate signers not allowed
+ // 2. duplicate signers not allowed (the number of signers is implied by the number of initial kex messages passed
+ // in, so we can't just ignore duplicates here)
CHECK_AND_ASSERT_THROW_MES(std::find(signers.begin(), signers.end(), expanded_msgs.back().get_signing_pubkey()) == signers.end(),
"Duplicate signers not allowed when converting a wallet to multisig.");
- // add signer (skip self for now)
- if (expanded_msgs.back().get_signing_pubkey() != multisig_account.get_base_pubkey())
- signers.push_back(expanded_msgs.back().get_signing_pubkey());
+ // add signer
+ signers.push_back(expanded_msgs.back().get_signing_pubkey());
}
- // add self to signers
- signers.push_back(multisig_account.get_base_pubkey());
+ // expect that self is in the input list (this guarantees that the input list size always equals the number of intended
+ // signers for the account [when combined with duplicate checking])
+ CHECK_AND_ASSERT_THROW_MES(std::find(signers.begin(), signers.end(), multisig_account.get_base_pubkey()) != signers.end(),
+ "The local account's signer key was not found in initial multisig kex messages when converting a wallet to multisig.");
// intialize key exchange
multisig_account.initialize_kex(threshold, signers, expanded_msgs);
@@ -5567,12 +5899,13 @@ std::string wallet2::make_multisig(const epee::wipeable_string &password,
{
// Save the original i.e. non-multisig keys so the MMS can continue to use them to encrypt and decrypt messages
// (making a wallet multisig overwrites those keys, see account_base::make_multisig)
- m_original_address = get_account().get_keys().m_account_address;
- m_original_view_secret_key = get_account().get_keys().m_view_secret_key;
+ m_original_address = this->get_account().get_keys().m_account_address;
+ m_original_view_secret_key = this->get_account().get_keys().m_view_secret_key;
m_original_keys_available = true;
}
- clear();
+ // clear wallet caches
+ this->clear();
// account base
MINFO("Creating multisig address...");
@@ -5582,14 +5915,14 @@ std::string wallet2::make_multisig(const epee::wipeable_string &password,
multisig_account.get_multisig_privkeys()),
"Failed to create multisig wallet account due to bad keys");
- init_type(hw::device::device_type::SOFTWARE);
+ this->init_type(hw::device::device_type::SOFTWARE);
m_original_keys_available = true;
m_multisig = true;
m_multisig_threshold = threshold;
m_multisig_signers = signers;
m_multisig_rounds_passed = 1;
- // derivations stored (should be empty in last round)
+ // derivations stored (note: should be empty in last kex round)
m_multisig_derivations.clear();
m_multisig_derivations.reserve(multisig_account.get_kex_keys_to_origins_map().size());
@@ -5603,12 +5936,12 @@ std::string wallet2::make_multisig(const epee::wipeable_string &password,
keys_reencryptor = epee::misc_utils::auto_scope_leave_caller();
if (!m_wallet_file.empty())
- create_keys_file(m_wallet_file, false, password, boost::filesystem::exists(m_wallet_file + ".address.txt"));
+ this->create_keys_file(m_wallet_file, false, password, boost::filesystem::exists(m_wallet_file + ".address.txt"));
- setup_new_blockchain();
+ this->setup_new_blockchain();
if (!m_wallet_file.empty())
- store();
+ this->store();
return multisig_account.get_next_kex_round_msg();
}
@@ -5617,45 +5950,15 @@ std::string wallet2::exchange_multisig_keys(const epee::wipeable_string &passwor
const std::vector<std::string> &kex_messages,
const bool force_update_use_with_caution /*= false*/)
{
- bool ready{false};
- CHECK_AND_ASSERT_THROW_MES(multisig(&ready), "The wallet is not multisig");
+ const multisig::multisig_account_status ms_status{this->get_multisig_status()};
+ CHECK_AND_ASSERT_THROW_MES(ms_status.multisig_is_active, "The wallet is not multisig");
// decrypt account keys
- epee::misc_utils::auto_scope_leave_caller keys_reencryptor;
- if (m_ask_password == AskPasswordToDecrypt && !m_unattended && !m_watch_only)
- {
- crypto::chacha_key chacha_key;
- crypto::generate_chacha_key(password.data(), password.size(), chacha_key, m_kdf_rounds);
- m_account.encrypt_viewkey(chacha_key);
- m_account.decrypt_keys(chacha_key);
- keys_reencryptor = epee::misc_utils::create_scope_leave_handler(
- [&, this, chacha_key]()
- {
- m_account.encrypt_keys(chacha_key);
- m_account.decrypt_viewkey(chacha_key);
- }
- );
- }
+ epee::misc_utils::auto_scope_leave_caller keys_reencryptor{this->decrypt_account_for_multisig(password)};
// reconstruct multisig account
- multisig::multisig_keyset_map_memsafe_t kex_origins_map;
-
- for (const auto &derivation : m_multisig_derivations)
- kex_origins_map[derivation];
-
- multisig::multisig_account multisig_account{
- m_multisig_threshold,
- m_multisig_signers,
- get_account().get_keys().m_spend_secret_key,
- crypto::null_skey, //base common privkey: not used
- get_account().get_keys().m_multisig_keys,
- get_account().get_keys().m_view_secret_key,
- m_account_public_address.m_spend_public_key,
- m_account_public_address.m_view_public_key,
- m_multisig_rounds_passed,
- std::move(kex_origins_map),
- ""
- };
+ multisig::multisig_account multisig_account;
+ this->get_reconstructed_multisig_account(multisig_account);
// KLUDGE: early return if there are no kex messages and main kex is complete (will return the post-kex verification round
// message) (it's a kludge because this behavior would be more appropriate for a standalone wallet method)
@@ -5671,7 +5974,7 @@ std::string wallet2::exchange_multisig_keys(const epee::wipeable_string &passwor
std::vector<multisig::multisig_kex_msg> expanded_msgs;
expanded_msgs.reserve(kex_messages.size());
- for (const auto &msg : kex_messages)
+ for (const std::string &msg : kex_messages)
expanded_msgs.emplace_back(msg);
// update multisig kex
@@ -5707,27 +6010,27 @@ std::string wallet2::exchange_multisig_keys(const epee::wipeable_string &passwor
if (!m_wallet_file.empty())
{
- bool r = store_keys(m_keys_file, password, false);
+ bool r = this->store_keys(m_keys_file, password, false);
THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
if (boost::filesystem::exists(m_wallet_file + ".address.txt"))
{
- r = save_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_nettype), true);
+ r = this->save_to_file(m_wallet_file + ".address.txt", m_account.get_public_address_str(m_nettype), true);
if(!r) MERROR("String with address text not saved");
}
}
m_subaddresses.clear();
m_subaddress_labels.clear();
- add_subaddress_account(tr("Primary account"));
+ this->add_subaddress_account(tr("Primary account"));
if (!m_wallet_file.empty())
- store();
+ this->store();
}
// wallet/file relationship
if (!m_wallet_file.empty())
- create_keys_file(m_wallet_file, false, password, boost::filesystem::exists(m_wallet_file + ".address.txt"));
+ this->create_keys_file(m_wallet_file, false, password, boost::filesystem::exists(m_wallet_file + ".address.txt"));
return multisig_account.get_next_kex_round_msg();
}
@@ -5735,30 +6038,87 @@ std::string wallet2::exchange_multisig_keys(const epee::wipeable_string &passwor
std::string wallet2::get_multisig_first_kex_msg() const
{
// create multisig account
- multisig::multisig_account multisig_account{
- // k_base = H(normal private spend key)
- multisig::get_multisig_blinded_secret_key(get_account().get_keys().m_spend_secret_key),
- // k_view = H(normal private view key)
- multisig::get_multisig_blinded_secret_key(get_account().get_keys().m_view_secret_key)
- };
+ multisig::multisig_account multisig_account;
+ this->get_uninitialized_multisig_account(multisig_account);
return multisig_account.get_next_kex_round_msg();
}
//----------------------------------------------------------------------------------------------------
-bool wallet2::multisig(bool *ready, uint32_t *threshold, uint32_t *total) const
+std::string wallet2::get_multisig_key_exchange_booster(const epee::wipeable_string &password,
+ const std::vector<std::string> &kex_messages,
+ const std::uint32_t threshold,
+ const std::uint32_t num_signers)
{
- if (!m_multisig)
- return false;
- if (threshold)
- *threshold = m_multisig_threshold;
- if (total)
- *total = m_multisig_signers.size();
- if (ready)
+ CHECK_AND_ASSERT_THROW_MES(kex_messages.size() > 0, "No key exchange messages passed in.");
+
+ // decrypt account keys
+ epee::misc_utils::auto_scope_leave_caller keys_reencryptor{this->decrypt_account_for_multisig(password)};
+
+ // prepare multisig account
+ multisig::multisig_account multisig_account;
+
+ const multisig::multisig_account_status ms_status{this->get_multisig_status()};
+ CHECK_AND_ASSERT_THROW_MES(!ms_status.is_ready, "Multisig wallet creation process has already been finished.");
+
+ if (ms_status.multisig_is_active)
+ {
+ // case: this wallet is in the middle of multisig key exchange
+ // - boost the round that comes after the in-progress round
+
+ CHECK_AND_ASSERT_THROW_MES(threshold == m_multisig_threshold,
+ "Expected threshold does not match multisig wallet setting.");
+ CHECK_AND_ASSERT_THROW_MES(num_signers == m_multisig_signers.size(),
+ "Expected number of signers does not match multisig wallet setting.");
+
+ // reconstruct multisig account
+ this->get_reconstructed_multisig_account(multisig_account);
+ }
+ else
+ {
+ // case: make_multisig() has not been called
+ // DANGER: If 'num_signers - threshold > 1', but this wallet's future multisig settings
+ // will be 'num_signers - threshold == 1', then the booster message WILL leak the
+ // future multisig wallet's private keys in this case where the wallet2 multisig wallet is uninitialized.
+
+ this->get_uninitialized_multisig_account(multisig_account);
+ }
+
+ // open kex messages
+ std::vector<multisig::multisig_kex_msg> expanded_msgs;
+ expanded_msgs.reserve(kex_messages.size());
+
+ for (const std::string &msg : kex_messages)
+ expanded_msgs.emplace_back(msg);
+
+ // get kex booster message
+ // note: booster does not change wallet state other than decrypting/reencrypting account keys
+ return multisig_account.get_multisig_kex_round_booster(threshold, num_signers, expanded_msgs).get_msg();
+}
+//----------------------------------------------------------------------------------------------------
+multisig::multisig_account_status wallet2::get_multisig_status() const
+{
+ multisig::multisig_account_status ret;
+
+ if (m_multisig)
{
- *ready = !(get_account().get_keys().m_account_address.m_spend_public_key == rct::rct2pk(rct::identity())) &&
+ ret.multisig_is_active = true;
+ ret.threshold = m_multisig_threshold;
+ ret.total = m_multisig_signers.size();
+ ret.kex_is_done = !(get_account().get_keys().m_account_address.m_spend_public_key == rct::rct2pk(rct::identity())) &&
+ (m_multisig_rounds_passed >= multisig::multisig_kex_rounds_required(m_multisig_signers.size(), m_multisig_threshold));
+ ret.is_ready = ret.kex_is_done &&
(m_multisig_rounds_passed == multisig::multisig_setup_rounds_required(m_multisig_signers.size(), m_multisig_threshold));
}
- return true;
+ else
+ {
+ ret.multisig_is_active = false;
+ ret.threshold = 0;
+ ret.total = 0;
+ ret.kex_is_done = false;
+ ret.is_ready = false;
+ }
+
+ return ret;
}
//----------------------------------------------------------------------------------------------------
bool wallet2::has_multisig_partial_key_images() const
@@ -5788,11 +6148,30 @@ void wallet2::rewrite(const std::string& wallet_name, const epee::wipeable_strin
{
if (wallet_name.empty())
return;
+ THROW_WALLET_EXCEPTION_IF(m_background_syncing || m_is_background_wallet, error::wallet_internal_error,
+ "cannot change wallet settings from background wallet");
prepare_file_names(wallet_name);
boost::system::error_code ignored_ec;
THROW_WALLET_EXCEPTION_IF(!boost::filesystem::exists(m_keys_file, ignored_ec), error::file_not_found, m_keys_file);
bool r = store_keys(m_keys_file, password, m_watch_only);
THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
+
+ // Update the background keys file when we rewrite the main wallet keys file
+ if (m_background_sync_type == BackgroundSyncCustomPassword && m_custom_background_key)
+ {
+ const std::string background_keys_filename = make_background_keys_file_name(wallet_name);
+ if (!lock_background_keys_file(background_keys_filename))
+ {
+ LOG_ERROR("Background keys file " << background_keys_filename << " is opened by another wallet program and cannot be rewritten");
+ return; // not fatal, background keys file will just have different wallet settings
+ }
+ store_background_keys(m_custom_background_key.get());
+ store_background_cache(m_custom_background_key.get(), true/*do_reset_background_sync_data*/);
+ }
+ else if (m_background_sync_type == BackgroundSyncReusePassword)
+ {
+ reset_background_sync_data(m_background_sync_data);
+ }
}
/*!
* \brief Writes to a file named based on the normal wallet (doesn't generate key, assumes it's already there)
@@ -5826,6 +6205,16 @@ bool wallet2::wallet_valid_path_format(const std::string& file_path)
return !file_path.empty();
}
//----------------------------------------------------------------------------------------------------
+std::string wallet2::make_background_wallet_file_name(const std::string &wallet_file)
+{
+ return wallet_file + BACKGROUND_WALLET_SUFFIX;
+}
+//----------------------------------------------------------------------------------------------------
+std::string wallet2::make_background_keys_file_name(const std::string &wallet_file)
+{
+ return make_background_wallet_file_name(wallet_file) + ".keys";
+}
+//----------------------------------------------------------------------------------------------------
bool wallet2::parse_long_payment_id(const std::string& payment_id_str, crypto::hash& payment_id)
{
cryptonote::blobdata payment_id_data;
@@ -6051,10 +6440,78 @@ void wallet2::load(const std::string& wallet_, const epee::wipeable_string& pass
THROW_WALLET_EXCEPTION_IF(true, error::file_read_error, "failed to load keys from buffer");
}
- wallet_keys_unlocker unlocker(*this, m_ask_password == AskPasswordToDecrypt && !m_unattended && !m_watch_only, password);
+ wallet_keys_unlocker unlocker(*this, m_ask_password == AskPasswordToDecrypt && !m_unattended && !m_watch_only && !m_is_background_wallet, password);
//keys loaded ok!
//try to load wallet cache. but even if we failed, it is not big problem
+ load_wallet_cache(use_fs, cache_buf);
+
+ // Wallets used to wipe, but not erase, old unused multisig key info, which lead to huge memory leaks.
+ // Here we erase these multisig keys if they're zero'd out to free up space.
+ for (auto &td : m_transfers)
+ {
+ auto mk_it = td.m_multisig_k.begin();
+ while (mk_it != td.m_multisig_k.end())
+ {
+ if (*mk_it == rct::zero())
+ mk_it = td.m_multisig_k.erase(mk_it);
+ else
+ ++mk_it;
+ }
+ }
+
+ cryptonote::block genesis;
+ generate_genesis(genesis);
+ crypto::hash genesis_hash = get_block_hash(genesis);
+
+ if (m_blockchain.empty())
+ {
+ m_blockchain.push_back(genesis_hash);
+ m_last_block_reward = cryptonote::get_outs_money_amount(genesis.miner_tx);
+ }
+ else
+ {
+ check_genesis(genesis_hash);
+ }
+
+ trim_hashchain();
+
+ if (get_num_subaddress_accounts() == 0)
+ add_subaddress_account(tr("Primary account"));
+
+ try
+ {
+ find_and_save_rings(false);
+ }
+ catch (const std::exception &e)
+ {
+ MERROR("Failed to save rings, will try again next time");
+ }
+
+ try
+ {
+ if (use_fs)
+ m_message_store.read_from_file(get_multisig_wallet_state(), m_mms_file, m_load_deprecated_formats);
+ }
+ catch (const std::exception &e)
+ {
+ MERROR("Failed to initialize MMS, it will be unusable");
+ }
+
+ try
+ {
+ if (use_fs)
+ process_background_cache_on_open();
+ }
+ catch (const std::exception &e)
+ {
+ MERROR("Failed to process background cache on open: " << e.what());
+ }
+}
+//----------------------------------------------------------------------------------------------------
+void wallet2::load_wallet_cache(const bool use_fs, const std::string& cache_buf)
+{
+ boost::system::error_code e;
bool cache_missing = use_fs ? (!boost::filesystem::exists(m_wallet_file, e) || e) : cache_buf.empty();
if (cache_missing)
{
@@ -6068,7 +6525,7 @@ void wallet2::load(const std::string& wallet_, const epee::wipeable_string& pass
bool r = true;
if (use_fs)
{
- load_from_file(m_wallet_file, cache_file_buf, std::numeric_limits<size_t>::max());
+ r = load_from_file(m_wallet_file, cache_file_buf, std::numeric_limits<size_t>::max());
THROW_WALLET_EXCEPTION_IF(!r, error::file_read_error, m_wallet_file);
}
@@ -6081,7 +6538,7 @@ void wallet2::load(const std::string& wallet_, const epee::wipeable_string& pass
THROW_WALLET_EXCEPTION_IF(!r, error::wallet_internal_error, "internal error: failed to deserialize \"" + m_wallet_file + '\"');
std::string cache_data;
cache_data.resize(cache_file_data.cache_data.size());
- crypto::chacha20(cache_file_data.cache_data.data(), cache_file_data.cache_data.size(), m_cache_key, cache_file_data.iv, &cache_data[0]);
+ crypto::chacha20(cache_file_data.cache_data.data(), cache_file_data.cache_data.size(), get_cache_key(), cache_file_data.iv, &cache_data[0]);
try {
bool loaded = false;
@@ -6136,7 +6593,7 @@ void wallet2::load(const std::string& wallet_, const epee::wipeable_string& pass
catch (...)
{
LOG_PRINT_L0("Failed to open portable binary, trying unportable");
- if (use_fs) boost::filesystem::copy_file(m_wallet_file, m_wallet_file + ".unportable", boost::filesystem::copy_option::overwrite_if_exists);
+ if (use_fs) tools::copy_file(m_wallet_file, m_wallet_file + ".unportable");
std::stringstream iss;
iss.str("");
iss << cache_data;
@@ -6158,7 +6615,7 @@ void wallet2::load(const std::string& wallet_, const epee::wipeable_string& pass
catch (...)
{
LOG_PRINT_L0("Failed to open portable binary, trying unportable");
- if (use_fs) boost::filesystem::copy_file(m_wallet_file, m_wallet_file + ".unportable", boost::filesystem::copy_option::overwrite_if_exists);
+ if (use_fs) tools::copy_file(m_wallet_file, m_wallet_file + ".unportable");
std::stringstream iss;
iss.str("");
iss << cache_file_buf;
@@ -6171,57 +6628,76 @@ void wallet2::load(const std::string& wallet_, const epee::wipeable_string& pass
m_account_public_address.m_view_public_key != m_account.get_keys().m_account_address.m_view_public_key,
error::wallet_files_doesnt_correspond, m_keys_file, m_wallet_file);
}
+}
+//----------------------------------------------------------------------------------------------------
+void wallet2::process_background_cache_on_open()
+{
+ if (m_wallet_file.empty())
+ return;
+ if (m_background_syncing || m_is_background_wallet)
+ return;
+ if (m_background_sync_type == BackgroundSyncOff)
+ return;
- // Wallets used to wipe, but not erase, old unused multisig key info, which lead to huge memory leaks.
- // Here we erase these multisig keys if they're zero'd out to free up space.
- for (auto &td : m_transfers)
+ if (m_background_sync_type == BackgroundSyncReusePassword)
{
- auto mk_it = td.m_multisig_k.begin();
- while (mk_it != td.m_multisig_k.end())
+ const background_sync_data_t background_sync_data = m_background_sync_data;
+ const hashchain blockchain = m_blockchain;
+ process_background_cache(background_sync_data, blockchain, m_last_block_reward);
+
+ // Reset the background cache after processing
+ reset_background_sync_data(m_background_sync_data);
+ }
+ else if (m_background_sync_type == BackgroundSyncCustomPassword)
+ {
+ // If the background wallet files don't exist, recreate them
+ const std::string background_keys_file = make_background_keys_file_name(m_wallet_file);
+ const std::string background_wallet_file = make_background_wallet_file_name(m_wallet_file);
+ const bool background_keys_file_exists = boost::filesystem::exists(background_keys_file);
+ const bool background_wallet_exists = boost::filesystem::exists(background_wallet_file);
+
+ THROW_WALLET_EXCEPTION_IF(!lock_background_keys_file(background_keys_file), error::background_wallet_already_open, background_wallet_file);
+ THROW_WALLET_EXCEPTION_IF(!m_custom_background_key, error::wallet_internal_error, "Custom background key not set");
+
+ if (!background_keys_file_exists)
{
- if (*mk_it == rct::zero())
- mk_it = td.m_multisig_k.erase(mk_it);
- else
- ++mk_it;
+ MDEBUG("Background keys file not found, restoring");
+ store_background_keys(m_custom_background_key.get());
}
- }
- cryptonote::block genesis;
- generate_genesis(genesis);
- crypto::hash genesis_hash = get_block_hash(genesis);
+ if (!background_wallet_exists)
+ {
+ MDEBUG("Background cache not found, restoring");
+ store_background_cache(m_custom_background_key.get(), true/*do_reset_background_sync_data*/);
+ return;
+ }
- if (m_blockchain.empty())
- {
- m_blockchain.push_back(genesis_hash);
- m_last_block_reward = cryptonote::get_outs_money_amount(genesis.miner_tx);
- }
- else
- {
- check_genesis(genesis_hash);
- }
+ MDEBUG("Loading background cache");
- trim_hashchain();
+ // Set up a minimal background wallet2 instance
+ std::unique_ptr<wallet2> background_w2(new wallet2(m_nettype));
+ background_w2->m_is_background_wallet = true;
+ background_w2->m_background_syncing = true;
+ background_w2->m_background_sync_type = m_background_sync_type;
+ background_w2->m_custom_background_key = m_custom_background_key;
- if (get_num_subaddress_accounts() == 0)
- add_subaddress_account(tr("Primary account"));
+ cryptonote::account_base account = m_account;
+ account.forget_spend_key();
+ background_w2->m_account = account;
- try
- {
- find_and_save_rings(false);
- }
- catch (const std::exception &e)
- {
- MERROR("Failed to save rings, will try again next time");
- }
-
- try
- {
- if (use_fs)
- m_message_store.read_from_file(get_multisig_wallet_state(), m_mms_file, m_load_deprecated_formats);
+ // Load background cache from file
+ background_w2->clear();
+ background_w2->prepare_file_names(background_wallet_file);
+ background_w2->load_wallet_cache(true/*use_fs*/);
+
+ process_background_cache(background_w2->m_background_sync_data, background_w2->m_blockchain, background_w2->m_last_block_reward);
+
+ // Reset the background cache after processing
+ store_background_cache(m_custom_background_key.get(), true/*do_reset_background_sync_data*/);
}
- catch (const std::exception &e)
+ else
{
- MERROR("Failed to initialize MMS, it will be unusable");
+ THROW_WALLET_EXCEPTION(error::wallet_internal_error, "unknown background sync type");
}
}
//----------------------------------------------------------------------------------------------------
@@ -6303,6 +6779,8 @@ void wallet2::store_to(const std::string &path, const epee::wipeable_string &pas
same_file = canonical_old_path == canonical_new_path;
}
+ THROW_WALLET_EXCEPTION_IF(m_is_background_wallet && !same_file, error::wallet_internal_error,
+ "Cannot save background wallet files to a different location");
if (!same_file)
{
@@ -6319,6 +6797,21 @@ void wallet2::store_to(const std::string &path, const epee::wipeable_string &pas
}
}
}
+ else if (m_background_sync_type == BackgroundSyncCustomPassword && m_background_syncing && !m_is_background_wallet)
+ {
+ // We're background syncing, so store the wallet cache as a background cache
+ // keeping the background sync data
+ try
+ {
+ THROW_WALLET_EXCEPTION_IF(!m_custom_background_key, error::wallet_internal_error, "Custom background key not set");
+ store_background_cache(m_custom_background_key.get(), false/*do_reset_background_sync_data*/);
+ }
+ catch (const std::exception &e)
+ {
+ MERROR("Failed to store background cache while background syncing: " << e.what());
+ }
+ return;
+ }
// get wallet cache data
boost::optional<wallet2::cache_file_data> cache_file_data = get_cache_file_data();
@@ -6412,6 +6905,22 @@ void wallet2::store_to(const std::string &path, const epee::wipeable_string &pas
// store should only exist if the MMS is really active
m_message_store.write_to_file(get_multisig_wallet_state(), m_mms_file);
}
+
+ if (m_background_sync_type == BackgroundSyncCustomPassword && !m_background_syncing && !m_is_background_wallet)
+ {
+ // Update the background wallet cache when we store the main wallet cache
+ // Note: if background syncing when this is called, it means the background
+ // wallet is open and was already stored above
+ try
+ {
+ THROW_WALLET_EXCEPTION_IF(!m_custom_background_key, error::wallet_internal_error, "Custom background key not set");
+ store_background_cache(m_custom_background_key.get(), true/*do_reset_background_sync_data*/);
+ }
+ catch (const std::exception &e)
+ {
+ MERROR("Failed to update background cache: " << e.what());
+ }
+ }
}
//----------------------------------------------------------------------------------------------------
boost::optional<wallet2::cache_file_data> wallet2::get_cache_file_data()
@@ -6429,7 +6938,7 @@ boost::optional<wallet2::cache_file_data> wallet2::get_cache_file_data()
std::string cipher;
cipher.resize(cache_file_data.get().cache_data.size());
cache_file_data.get().iv = crypto::rand<crypto::chacha_iv>();
- crypto::chacha20(cache_file_data.get().cache_data.data(), cache_file_data.get().cache_data.size(), m_cache_key, cache_file_data.get().iv, &cipher[0]);
+ crypto::chacha20(cache_file_data.get().cache_data.data(), cache_file_data.get().cache_data.size(), get_cache_key(), cache_file_data.get().iv, &cipher[0]);
cache_file_data.get().cache_data = cipher;
return cache_file_data;
}
@@ -7252,14 +7761,15 @@ bool wallet2::sign_tx(unsigned_tx_set &exported_txs, std::vector<wallet2::pendin
{
tools::wallet2::tx_construction_data &sd = exported_txs.txes[n];
THROW_WALLET_EXCEPTION_IF(sd.sources.empty(), error::wallet_internal_error, "Empty sources");
+ THROW_WALLET_EXCEPTION_IF(sd.unlock_time, error::nonzero_unlock_time);
LOG_PRINT_L1(" " << (n+1) << ": " << sd.sources.size() << " inputs, ring size " << sd.sources[0].outputs.size());
signed_txes.ptx.push_back(pending_tx());
tools::wallet2::pending_tx &ptx = signed_txes.ptx.back();
rct::RCTConfig rct_config = sd.rct_config;
crypto::secret_key tx_key;
std::vector<crypto::secret_key> additional_tx_keys;
- bool r = cryptonote::construct_tx_and_get_tx_key(m_account.get_keys(), m_subaddresses, sd.sources, sd.splitted_dsts, sd.change_dts.addr, sd.extra, ptx.tx, sd.unlock_time, tx_key, additional_tx_keys, sd.use_rct, rct_config, sd.use_view_tags);
- THROW_WALLET_EXCEPTION_IF(!r, error::tx_not_constructed, sd.sources, sd.splitted_dsts, sd.unlock_time, m_nettype);
+ bool r = cryptonote::construct_tx_and_get_tx_key(m_account.get_keys(), m_subaddresses, sd.sources, sd.splitted_dsts, sd.change_dts.addr, sd.extra, ptx.tx, tx_key, additional_tx_keys, sd.use_rct, rct_config, sd.use_view_tags);
+ THROW_WALLET_EXCEPTION_IF(!r, error::tx_not_constructed, sd.sources, sd.splitted_dsts, m_nettype);
// we don't test tx size, because we don't know the current limit, due to not having a blockchain,
// and it's a bit pointless to fail there anyway, since it'd be a (good) guess only. We sign anyway,
// and if we really go over limit, the daemon will reject when it gets submitted. Chances are it's
@@ -7787,7 +8297,6 @@ bool wallet2::sign_multisig_tx(multisig_tx_set &exported_txs, std::vector<crypto
not multisig_tx_builder.init(
m_account.get_keys(),
ptx.construction_data.extra,
- ptx.construction_data.unlock_time,
ptx.construction_data.subaddr_account,
ptx.construction_data.subaddr_indices,
ptx.construction_data.sources,
@@ -8480,6 +8989,34 @@ bool wallet2::is_keys_file_locked() const
return m_keys_file_locker->locked();
}
+bool wallet2::lock_background_keys_file(const std::string &background_keys_file)
+{
+ if (background_keys_file.empty() || !boost::filesystem::exists(background_keys_file))
+ return true;
+ if (m_background_keys_file_locker && m_background_keys_file_locker->locked())
+ return true;
+ m_background_keys_file_locker.reset(new tools::file_locker(background_keys_file));
+ return m_background_keys_file_locker->locked();
+}
+
+bool wallet2::unlock_background_keys_file()
+{
+ if (!m_background_keys_file_locker)
+ {
+ MDEBUG("background keys file locker is not set");
+ return false;
+ }
+ m_background_keys_file_locker.reset();
+ return true;
+}
+
+bool wallet2::is_background_keys_file_locked() const
+{
+ if (!m_background_keys_file_locker)
+ return false;
+ return m_background_keys_file_locker->locked();
+}
+
bool wallet2::tx_add_fake_output(std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs, uint64_t global_index, const crypto::public_key& output_public_key, const rct::key& mask, uint64_t real_index, bool unlocked, std::unordered_set<crypto::public_key> &valid_public_keys_cache) const
{
if (!unlocked) // don't add locked outs
@@ -9199,7 +9736,7 @@ void wallet2::get_outs(std::vector<std::vector<tools::wallet2::get_outs_entry>>
template<typename T>
void wallet2::transfer_selected(const std::vector<cryptonote::tx_destination_entry>& dsts, const std::vector<size_t>& selected_transfers, size_t fake_outputs_count,
std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs, std::unordered_set<crypto::public_key> &valid_public_keys_cache,
- uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, T destination_split_strategy, const tx_dust_policy& dust_policy, cryptonote::transaction& tx, pending_tx &ptx,
+ uint64_t fee, const std::vector<uint8_t>& extra, T destination_split_strategy, const tx_dust_policy& dust_policy, cryptonote::transaction& tx, pending_tx &ptx,
bool use_view_tags)
{
using namespace cryptonote;
@@ -9310,9 +9847,9 @@ void wallet2::transfer_selected(const std::vector<cryptonote::tx_destination_ent
crypto::secret_key tx_key;
std::vector<crypto::secret_key> additional_tx_keys;
LOG_PRINT_L2("constructing tx");
- bool r = cryptonote::construct_tx_and_get_tx_key(m_account.get_keys(), m_subaddresses, sources, splitted_dsts, change_dts.addr, extra, tx, unlock_time, tx_key, additional_tx_keys, false, {}, use_view_tags);
+ bool r = cryptonote::construct_tx_and_get_tx_key(m_account.get_keys(), m_subaddresses, sources, splitted_dsts, change_dts.addr, extra, tx, tx_key, additional_tx_keys, false, {}, use_view_tags);
LOG_PRINT_L2("constructed tx, r="<<r);
- THROW_WALLET_EXCEPTION_IF(!r, error::tx_not_constructed, sources, splitted_dsts, unlock_time, m_nettype);
+ THROW_WALLET_EXCEPTION_IF(!r, error::tx_not_constructed, sources, splitted_dsts, m_nettype);
THROW_WALLET_EXCEPTION_IF(upper_transaction_weight_limit <= get_transaction_weight(tx), error::tx_too_big, tx, upper_transaction_weight_limit);
std::string key_images;
@@ -9345,7 +9882,7 @@ void wallet2::transfer_selected(const std::vector<cryptonote::tx_destination_ent
ptx.construction_data.splitted_dsts = splitted_dsts;
ptx.construction_data.selected_transfers = selected_transfers;
ptx.construction_data.extra = tx.extra;
- ptx.construction_data.unlock_time = unlock_time;
+ ptx.construction_data.unlock_time = 0;
ptx.construction_data.use_rct = false;
ptx.construction_data.rct_config = { rct::RangeProofBorromean, 0 };
ptx.construction_data.use_view_tags = use_view_tags;
@@ -9360,7 +9897,7 @@ void wallet2::transfer_selected(const std::vector<cryptonote::tx_destination_ent
void wallet2::transfer_selected_rct(std::vector<cryptonote::tx_destination_entry> dsts, const std::vector<size_t>& selected_transfers, size_t fake_outputs_count,
std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs, std::unordered_set<crypto::public_key> &valid_public_keys_cache,
- uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, cryptonote::transaction& tx, pending_tx &ptx, const rct::RCTConfig &rct_config, bool use_view_tags)
+ uint64_t fee, const std::vector<uint8_t>& extra, cryptonote::transaction& tx, pending_tx &ptx, const rct::RCTConfig &rct_config, bool use_view_tags)
{
using namespace cryptonote;
// throw if attempting a transaction with no destinations
@@ -9556,7 +10093,6 @@ void wallet2::transfer_selected_rct(std::vector<cryptonote::tx_destination_entry
THROW_WALLET_EXCEPTION_IF(
not multisig_tx_builder.init(m_account.get_keys(),
extra,
- unlock_time,
subaddr_account,
subaddr_minor_indices,
sources,
@@ -9576,9 +10112,9 @@ void wallet2::transfer_selected_rct(std::vector<cryptonote::tx_destination_entry
}
else {
// make a normal tx
- bool r = cryptonote::construct_tx_and_get_tx_key(m_account.get_keys(), m_subaddresses, sources, splitted_dsts, change_dts.addr, extra, tx, unlock_time, tx_key, additional_tx_keys, true, rct_config, use_view_tags);
+ bool r = cryptonote::construct_tx_and_get_tx_key(m_account.get_keys(), m_subaddresses, sources, splitted_dsts, change_dts.addr, extra, tx, tx_key, additional_tx_keys, true, rct_config, use_view_tags);
LOG_PRINT_L2("constructed tx, r="<<r);
- THROW_WALLET_EXCEPTION_IF(!r, error::tx_not_constructed, sources, dsts, unlock_time, m_nettype);
+ THROW_WALLET_EXCEPTION_IF(!r, error::tx_not_constructed, sources, dsts, m_nettype);
}
THROW_WALLET_EXCEPTION_IF(upper_transaction_weight_limit <= get_transaction_weight(tx), error::tx_too_big, tx, upper_transaction_weight_limit);
@@ -9700,7 +10236,7 @@ void wallet2::transfer_selected_rct(std::vector<cryptonote::tx_destination_entry
ptx.construction_data.splitted_dsts = splitted_dsts;
ptx.construction_data.selected_transfers = ptx.selected_transfers;
ptx.construction_data.extra = tx.extra;
- ptx.construction_data.unlock_time = unlock_time;
+ ptx.construction_data.unlock_time = 0;
ptx.construction_data.use_rct = true;
ptx.construction_data.rct_config = {
rct::RangeProofPaddedBulletproof,
@@ -9860,7 +10396,7 @@ static uint32_t get_count_above(const std::vector<wallet2::transfer_details> &tr
// This system allows for sending (almost) the entire balance, since it does
// not generate spurious change in all txes, thus decreasing the instantaneous
// usable balance.
-std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryptonote::tx_destination_entry> dsts, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t>& extra, uint32_t subaddr_account, std::set<uint32_t> subaddr_indices, const unique_index_container& subtract_fee_from_outputs)
+std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryptonote::tx_destination_entry> dsts, const size_t fake_outs_count, uint32_t priority, const std::vector<uint8_t>& extra, uint32_t subaddr_account, std::set<uint32_t> subaddr_indices, const unique_index_container& subtract_fee_from_outputs)
{
//ensure device is let in NONE mode in any case
hw::device &hwdev = m_account.get_device();
@@ -10383,10 +10919,10 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
tx.selected_transfers.size() << " inputs");
auto tx_dsts = tx.get_adjusted_dsts(needed_fee);
if (use_rct)
- transfer_selected_rct(tx_dsts, tx.selected_transfers, fake_outs_count, outs, valid_public_keys_cache, unlock_time, needed_fee, extra,
+ transfer_selected_rct(tx_dsts, tx.selected_transfers, fake_outs_count, outs, valid_public_keys_cache, needed_fee, extra,
test_tx, test_ptx, rct_config, use_view_tags);
else
- transfer_selected(tx_dsts, tx.selected_transfers, fake_outs_count, outs, valid_public_keys_cache, unlock_time, needed_fee, extra,
+ transfer_selected(tx_dsts, tx.selected_transfers, fake_outs_count, outs, valid_public_keys_cache, needed_fee, extra,
detail::digit_split_strategy, tx_dust_policy(::config::DEFAULT_DUST_THRESHOLD), test_tx, test_ptx, use_view_tags);
auto txBlob = t_serializable_object_to_blob(test_ptx.tx);
needed_fee = calculate_fee(use_per_byte_fee, test_ptx.tx, txBlob.size(), base_fee, fee_quantization_mask);
@@ -10422,21 +10958,21 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
else
{
LOG_PRINT_L2("We made a tx, adjusting fee and saving it, we need " << print_money(needed_fee) << " and we have " << print_money(test_ptx.fee));
- size_t fee_tries;
- for (fee_tries = 0; fee_tries < 10 && needed_fee > test_ptx.fee; ++fee_tries) {
+ size_t fee_tries = 0;
+ do {
tx_dsts = tx.get_adjusted_dsts(needed_fee);
if (use_rct)
- transfer_selected_rct(tx_dsts, tx.selected_transfers, fake_outs_count, outs, valid_public_keys_cache, unlock_time, needed_fee, extra,
+ transfer_selected_rct(tx_dsts, tx.selected_transfers, fake_outs_count, outs, valid_public_keys_cache, needed_fee, extra,
test_tx, test_ptx, rct_config, use_view_tags);
else
- transfer_selected(tx_dsts, tx.selected_transfers, fake_outs_count, outs, valid_public_keys_cache, unlock_time, needed_fee, extra,
+ transfer_selected(tx_dsts, tx.selected_transfers, fake_outs_count, outs, valid_public_keys_cache, needed_fee, extra,
detail::digit_split_strategy, tx_dust_policy(::config::DEFAULT_DUST_THRESHOLD), test_tx, test_ptx, use_view_tags);
txBlob = t_serializable_object_to_blob(test_ptx.tx);
needed_fee = calculate_fee(use_per_byte_fee, test_ptx.tx, txBlob.size(), base_fee, fee_quantization_mask);
LOG_PRINT_L2("Made an attempt at a final " << get_weight_string(test_ptx.tx, txBlob.size()) << " tx, with " << print_money(test_ptx.fee) <<
" fee and " << print_money(test_ptx.change_dts.amount) << " change");
- };
+ } while (needed_fee > test_ptx.fee && ++fee_tries < 10);
THROW_WALLET_EXCEPTION_IF(fee_tries == 10, error::wallet_internal_error,
"Too many attempts to raise pending tx fee to level of needed fee");
@@ -10503,7 +11039,6 @@ skip_tx:
fake_outs_count, /* CONST size_t fake_outputs_count, */
tx.outs, /* MOD std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs, */
valid_public_keys_cache,
- unlock_time, /* CONST uint64_t unlock_time, */
tx.needed_fee, /* CONST uint64_t fee, */
extra, /* const std::vector<uint8_t>& extra, */
test_tx, /* OUT cryptonote::transaction& tx, */
@@ -10516,7 +11051,6 @@ skip_tx:
fake_outs_count,
tx.outs,
valid_public_keys_cache,
- unlock_time,
tx.needed_fee,
extra,
detail::digit_split_strategy,
@@ -10630,7 +11164,7 @@ bool wallet2::sanity_check(const std::vector<wallet2::pending_tx> &ptx_vector, c
return true;
}
-std::vector<wallet2::pending_tx> wallet2::create_transactions_all(uint64_t below, const cryptonote::account_public_address &address, bool is_subaddress, const size_t outputs, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t>& extra, uint32_t subaddr_account, std::set<uint32_t> subaddr_indices)
+std::vector<wallet2::pending_tx> wallet2::create_transactions_all(uint64_t below, const cryptonote::account_public_address &address, bool is_subaddress, const size_t outputs, const size_t fake_outs_count, uint32_t priority, const std::vector<uint8_t>& extra, uint32_t subaddr_account, std::set<uint32_t> subaddr_indices)
{
std::vector<size_t> unused_transfers_indices;
std::vector<size_t> unused_dust_indices;
@@ -10700,10 +11234,10 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_all(uint64_t below
}
}
- return create_transactions_from(address, is_subaddress, outputs, unused_transfers_indices, unused_dust_indices, fake_outs_count, unlock_time, priority, extra);
+ return create_transactions_from(address, is_subaddress, outputs, unused_transfers_indices, unused_dust_indices, fake_outs_count, priority, extra);
}
-std::vector<wallet2::pending_tx> wallet2::create_transactions_single(const crypto::key_image &ki, const cryptonote::account_public_address &address, bool is_subaddress, const size_t outputs, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t>& extra)
+std::vector<wallet2::pending_tx> wallet2::create_transactions_single(const crypto::key_image &ki, const cryptonote::account_public_address &address, bool is_subaddress, const size_t outputs, const size_t fake_outs_count, uint32_t priority, const std::vector<uint8_t>& extra)
{
std::vector<size_t> unused_transfers_indices;
std::vector<size_t> unused_dust_indices;
@@ -10721,10 +11255,10 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_single(const crypt
break;
}
}
- return create_transactions_from(address, is_subaddress, outputs, unused_transfers_indices, unused_dust_indices, fake_outs_count, unlock_time, priority, extra);
+ return create_transactions_from(address, is_subaddress, outputs, unused_transfers_indices, unused_dust_indices, fake_outs_count, priority, extra);
}
-std::vector<wallet2::pending_tx> wallet2::create_transactions_from(const cryptonote::account_public_address &address, bool is_subaddress, const size_t outputs, std::vector<size_t> unused_transfers_indices, std::vector<size_t> unused_dust_indices, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t>& extra)
+std::vector<wallet2::pending_tx> wallet2::create_transactions_from(const cryptonote::account_public_address &address, bool is_subaddress, const size_t outputs, std::vector<size_t> unused_transfers_indices, std::vector<size_t> unused_dust_indices, const size_t fake_outs_count, uint32_t priority, const std::vector<uint8_t>& extra)
{
//ensure device is let in NONE mode in any case
hw::device &hwdev = m_account.get_device();
@@ -10833,10 +11367,10 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_from(const crypton
LOG_PRINT_L2("Trying to create a tx now, with " << tx.dsts.size() << " destinations and " <<
tx.selected_transfers.size() << " outputs");
if (use_rct)
- transfer_selected_rct(tx.dsts, tx.selected_transfers, fake_outs_count, outs, valid_public_keys_cache, unlock_time, needed_fee, extra,
+ transfer_selected_rct(tx.dsts, tx.selected_transfers, fake_outs_count, outs, valid_public_keys_cache, needed_fee, extra,
test_tx, test_ptx, rct_config, use_view_tags);
else
- transfer_selected(tx.dsts, tx.selected_transfers, fake_outs_count, outs, valid_public_keys_cache, unlock_time, needed_fee, extra,
+ transfer_selected(tx.dsts, tx.selected_transfers, fake_outs_count, outs, valid_public_keys_cache, needed_fee, extra,
detail::digit_split_strategy, tx_dust_policy(::config::DEFAULT_DUST_THRESHOLD), test_tx, test_ptx, use_view_tags);
auto txBlob = t_serializable_object_to_blob(test_ptx.tx);
needed_fee = calculate_fee(use_per_byte_fee, test_ptx.tx, txBlob.size(), base_fee, fee_quantization_mask);
@@ -10870,10 +11404,10 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_from(const crypton
dt.amount = dt_amount + dt_residue;
}
if (use_rct)
- transfer_selected_rct(tx.dsts, tx.selected_transfers, fake_outs_count, outs, valid_public_keys_cache, unlock_time, needed_fee, extra,
+ transfer_selected_rct(tx.dsts, tx.selected_transfers, fake_outs_count, outs, valid_public_keys_cache, needed_fee, extra,
test_tx, test_ptx, rct_config, use_view_tags);
else
- transfer_selected(tx.dsts, tx.selected_transfers, fake_outs_count, outs, valid_public_keys_cache, unlock_time, needed_fee, extra,
+ transfer_selected(tx.dsts, tx.selected_transfers, fake_outs_count, outs, valid_public_keys_cache, needed_fee, extra,
detail::digit_split_strategy, tx_dust_policy(::config::DEFAULT_DUST_THRESHOLD), test_tx, test_ptx, use_view_tags);
txBlob = t_serializable_object_to_blob(test_ptx.tx);
needed_fee = calculate_fee(use_per_byte_fee, test_ptx.tx, txBlob.size(), base_fee, fee_quantization_mask);
@@ -10909,10 +11443,10 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_from(const crypton
cryptonote::transaction test_tx;
pending_tx test_ptx;
if (use_rct) {
- transfer_selected_rct(tx.dsts, tx.selected_transfers, fake_outs_count, tx.outs, valid_public_keys_cache, unlock_time, tx.needed_fee, extra,
+ transfer_selected_rct(tx.dsts, tx.selected_transfers, fake_outs_count, tx.outs, valid_public_keys_cache, tx.needed_fee, extra,
test_tx, test_ptx, rct_config, use_view_tags);
} else {
- transfer_selected(tx.dsts, tx.selected_transfers, fake_outs_count, tx.outs, valid_public_keys_cache, unlock_time, tx.needed_fee, extra,
+ transfer_selected(tx.dsts, tx.selected_transfers, fake_outs_count, tx.outs, valid_public_keys_cache, tx.needed_fee, extra,
detail::digit_split_strategy, tx_dust_policy(::config::DEFAULT_DUST_THRESHOLD), test_tx, test_ptx, use_view_tags);
}
auto txBlob = t_serializable_object_to_blob(test_ptx.tx);
@@ -11214,7 +11748,7 @@ std::vector<wallet2::pending_tx> wallet2::create_unmixable_sweep_transactions()
unmixable_transfer_outputs.push_back(n);
}
- return create_transactions_from(m_account_public_address, false, 1, unmixable_transfer_outputs, unmixable_dust_outputs, 0 /*fake_outs_count */, 0 /* unlock_time */, 1 /*priority */, std::vector<uint8_t>());
+ return create_transactions_from(m_account_public_address, false, 1, unmixable_transfer_outputs, unmixable_dust_outputs, 0 /*fake_outs_count */, 1 /*priority */, std::vector<uint8_t>());
}
//----------------------------------------------------------------------------------------------------
void wallet2::discard_unmixable_outputs()
@@ -12401,7 +12935,7 @@ uint64_t wallet2::get_approximate_blockchain_height() const
// Calculated blockchain height
uint64_t approx_blockchain_height = fork_block + (time(NULL) - fork_time)/seconds_per_block;
// testnet and stagenet got some huge rollbacks, so the estimation is way off
- static const uint64_t approximate_rolled_back_blocks = m_nettype == TESTNET ? 342100 : 30000;
+ static const uint64_t approximate_rolled_back_blocks = m_nettype == TESTNET ? 342100 : m_nettype == STAGENET ? 60000 : 30000;
if ((m_nettype == TESTNET || m_nettype == STAGENET) && approx_blockchain_height > approximate_rolled_back_blocks)
approx_blockchain_height -= approximate_rolled_back_blocks;
LOG_PRINT_L2("Calculated blockchain height: " << approx_blockchain_height);
@@ -13164,6 +13698,413 @@ bool wallet2::import_key_images(signed_tx_set & signed_tx, size_t offset, bool o
return import_key_images(signed_tx.key_images, offset, only_selected_transfers ? boost::make_optional(selected_transfers) : boost::none);
}
+/*
+ In background sync mode, we use just the view key when the wallet is scanning
+ to identify all txs where:
+
+ 1. We received an output.
+ 2. We spent an output.
+ 3. We *may* have spent a received output but we didn't know for sure because
+ the spend key was not loaded while background sync was enabled.
+
+ When the user is ready to use the spend key again, we call this function to
+ process all those background synced transactions with the spend key loaded,
+ so that we can properly generate key images for the transactions which we
+ we were not able to do so for while background sync was enabled. This allows
+ us to determine *all* receives and spends the user completed while the wallet
+ had background sync enabled. Once this function completes, we can continue
+ scanning from where the background sync left off.
+
+ Txs of type 3 (txs which we *may* have spent received output(s)) are txs where
+ 1+ rings contain an output that the user received and the wallet does not know
+ the associated key image for that output. We don't know if the user spent in
+ this type of tx or not. This function will generate key images for all outputs
+ we don't know key images for, and then check if those outputs were spent in
+ the txs of type 3.
+
+ By storing this type of "plausible spend tx" when scanning in background sync
+ mode, we avoid the need to query the daemon with key images when background
+ sync mode is disabled to see if those key images were spent. This would
+ reveal key images to 3rd party nodes for users who don't run their own.
+ Although this is not a perfect solution to avoid revealing key images to a 3rd
+ party node (since tx submission trivially reveals key images to a node), it's
+ probably better than revealing *unused* key images to a 3rd party node, which
+ would enable the 3rd party to deduce that a tx is spending an output at least
+ X old when the key image is included in the chain.
+*/
+void wallet2::process_background_cache(const background_sync_data_t &background_sync_data, const hashchain &background_synced_chain, uint64_t last_block_reward)
+{
+ // We expect the spend key to be in a decrypted state while
+ // m_processing_background_cache is true
+ m_processing_background_cache = true;
+ auto done_processing = epee::misc_utils::create_scope_leave_handler([&, this]() {
+ m_processing_background_cache = false;
+ });
+
+ if (m_background_syncing || m_multisig || m_watch_only || key_on_device())
+ return;
+
+ if (!background_sync_data.first_refresh_done)
+ {
+ MDEBUG("Skipping processing background cache, background cache has not synced yet");
+ return;
+ }
+
+ // Skip processing if wallet cache is synced higher than background cache
+ const uint64_t current_height = m_blockchain.size();
+ const uint64_t background_height = background_synced_chain.size();
+ MDEBUG("Background cache height " << background_height << " , wallet height " << current_height);
+ if (current_height > background_height)
+ {
+ MWARNING("Skipping processing background cache, synced height is higher than background cache");
+ return;
+ }
+
+ if (m_refresh_from_block_height < background_sync_data.wallet_refresh_from_block_height ||
+ m_subaddress_lookahead_major > background_sync_data.subaddress_lookahead_major ||
+ m_subaddress_lookahead_minor > background_sync_data.subaddress_lookahead_minor ||
+ m_refresh_type < background_sync_data.wallet_refresh_type)
+ {
+ MWARNING("Skipping processing background cache, background wallet sync settings did not match main wallet's");
+ MDEBUG("Wallet settings: " <<
+ ", m_refresh_from_block_height: " << m_refresh_from_block_height << " vs " << background_sync_data.wallet_refresh_from_block_height <<
+ ", m_subaddress_lookahead_major: " << m_subaddress_lookahead_major << " vs " << background_sync_data.subaddress_lookahead_major <<
+ ", m_subaddress_lookahead_minor: " << m_subaddress_lookahead_minor << " vs " << background_sync_data.subaddress_lookahead_minor <<
+ ", m_refresh_type: " << m_refresh_type << " vs " << background_sync_data.wallet_refresh_type);
+ return;
+ }
+
+ // Sort background synced txs in the order they appeared in the cache so that
+ // we process them in the order they appeared in the chain. Thus if tx2 spends
+ // from tx1, we will know because tx1 is processed before tx2.
+ std::vector<std::pair<crypto::hash, background_synced_tx_t>> sorted_bgs_cache(background_sync_data.txs.begin(), background_sync_data.txs.end());
+ std::sort(sorted_bgs_cache.begin(), sorted_bgs_cache.end(),
+ [](const std::pair<crypto::hash, background_synced_tx_t>& l, const std::pair<crypto::hash, background_synced_tx_t>& r)
+ {
+ uint64_t left_index = l.second.index_in_background_sync_data;
+ uint64_t right_index = r.second.index_in_background_sync_data;
+ THROW_WALLET_EXCEPTION_IF(
+ (left_index < right_index && l.second.height > r.second.height) ||
+ (left_index > right_index && l.second.height < r.second.height),
+ error::wallet_internal_error, "Unexpected background sync data order");
+ return left_index < right_index;
+ });
+
+ // All txs in the background cache should have height >= sync start height,
+ // but not fatal if not
+ if (!sorted_bgs_cache.empty() && sorted_bgs_cache[0].second.height < background_sync_data.start_height)
+ MWARNING("First tx in background cache has height (" << sorted_bgs_cache[0].second.height << ") lower than sync start height (" << background_sync_data.start_height << ")");
+
+ // We want to process all background synced txs in order to make sure
+ // the wallet state updates correctly. First we remove all txs from the wallet
+ // from before the background sync start height, then re-process them in
+ // chronological order. The background cache should contain a superset of
+ // *all* the wallet's txs from after the background sync start height.
+ MDEBUG("Processing " << background_sync_data.txs.size() << " background synced txs starting from height " << background_sync_data.start_height);
+ detached_blockchain_data dbd = detach_blockchain(background_sync_data.start_height);
+
+ for (const auto &bgs_tx : sorted_bgs_cache)
+ {
+ MDEBUG("Processing background synced tx " << bgs_tx.first);
+
+ process_new_transaction(bgs_tx.first, bgs_tx.second.tx, bgs_tx.second.output_indices, bgs_tx.second.height, 0, bgs_tx.second.block_timestamp,
+ cryptonote::is_coinbase(bgs_tx.second.tx), false/*pool*/, bgs_tx.second.double_spend_seen, {}, {}, true/*ignore_callbacks*/);
+
+ // Re-set destination addresses if they were previously set
+ if (m_confirmed_txs.find(bgs_tx.first) != m_confirmed_txs.end() &&
+ dbd.detached_confirmed_txs_dests.find(bgs_tx.first) != dbd.detached_confirmed_txs_dests.end())
+ {
+ m_confirmed_txs[bgs_tx.first].m_dests = std::move(dbd.detached_confirmed_txs_dests[bgs_tx.first]);
+ }
+ }
+
+ m_blockchain = background_synced_chain;
+ m_last_block_reward = last_block_reward;
+
+ MDEBUG("Finished processing background sync data");
+}
+//----------------------------------------------------------------------------------------------------
+void wallet2::reset_background_sync_data(background_sync_data_t &background_sync_data)
+{
+ background_sync_data.first_refresh_done = false;
+ background_sync_data.start_height = get_blockchain_current_height();
+ background_sync_data.txs.clear();
+
+ background_sync_data.wallet_refresh_from_block_height = m_refresh_from_block_height;
+ background_sync_data.subaddress_lookahead_major = m_subaddress_lookahead_major;
+ background_sync_data.subaddress_lookahead_minor = m_subaddress_lookahead_minor;
+ background_sync_data.wallet_refresh_type = m_refresh_type;
+}
+//----------------------------------------------------------------------------------------------------
+void wallet2::store_background_cache(const crypto::chacha_key &custom_background_key, const bool do_reset_background_sync_data)
+{
+ MDEBUG("Storing background cache (do_reset_background_sync_data=" << do_reset_background_sync_data << ")");
+
+ THROW_WALLET_EXCEPTION_IF(m_background_sync_type != BackgroundSyncCustomPassword, error::wallet_internal_error,
+ "Can only write a background cache when using a custom background password");
+ THROW_WALLET_EXCEPTION_IF(m_wallet_file.empty(), error::wallet_internal_error,
+ "No wallet file known, can't store background cache");
+
+ std::unique_ptr<wallet2> background_w2(new wallet2(m_nettype));
+ background_w2->prepare_file_names(make_background_wallet_file_name(m_wallet_file));
+
+ // Make sure background wallet is opened by this wallet
+ THROW_WALLET_EXCEPTION_IF(!lock_background_keys_file(background_w2->m_keys_file),
+ error::background_wallet_already_open, background_w2->m_wallet_file);
+
+ // Load a background wallet2 instance using this wallet2 instance
+ std::string this_wallet2;
+ bool r = ::serialization::dump_binary(*this, this_wallet2);
+ THROW_WALLET_EXCEPTION_IF(!r, error::wallet_internal_error, "Failed to serialize wallet cache");
+
+ background_w2->clear();
+ r = ::serialization::parse_binary(this_wallet2, *background_w2);
+ THROW_WALLET_EXCEPTION_IF(!r, error::wallet_internal_error, "Failed to deserialize wallet cache");
+
+ // Clear sensitive data from background cache not needed to sync
+ background_w2->clear_user_data();
+
+ background_w2->m_is_background_wallet = true;
+ if (do_reset_background_sync_data)
+ reset_background_sync_data(background_w2->m_background_sync_data);
+ else
+ background_w2->m_background_sync_data = m_background_sync_data;
+ background_w2->m_background_syncing = true;
+
+ background_w2->m_custom_background_key = boost::optional<crypto::chacha_key>(custom_background_key);
+ background_w2->m_background_sync_type = m_background_sync_type;
+ background_w2->store();
+
+ MDEBUG("Background cache stored (" << background_w2->m_transfers.size() << " transfers, " << background_w2->m_background_sync_data.txs.size() << " background synced txs)");
+}
+//----------------------------------------------------------------------------------------------------
+void wallet2::store_background_keys(const crypto::chacha_key &custom_background_key)
+{
+ MDEBUG("Storing background keys");
+
+ THROW_WALLET_EXCEPTION_IF(m_wallet_file.empty(), error::wallet_internal_error,
+ "No wallet file known, can't store background keys");
+
+ const std::string background_keys_file = make_background_keys_file_name(m_wallet_file);
+ bool r = store_keys(background_keys_file, custom_background_key, false/*watch_only*/, true/*background_keys_file*/);
+ THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, background_keys_file);
+ THROW_WALLET_EXCEPTION_IF(!is_background_keys_file_locked(), error::wallet_internal_error, background_keys_file + "\" should be locked");
+
+ // GUI uses the address file to differentiate non-mainnet wallets in the UI
+ const std::string background_address_file = make_background_wallet_file_name(m_wallet_file) + ".address.txt";
+ if (m_nettype != MAINNET && !boost::filesystem::exists(background_address_file))
+ {
+ r = save_to_file(background_address_file, m_account.get_public_address_str(m_nettype), true);
+ if (!r) MERROR("String with address text not saved");
+ }
+
+ MDEBUG("Background keys stored");
+}
+//----------------------------------------------------------------------------------------------------
+void wallet2::write_background_sync_wallet(const epee::wipeable_string &wallet_password, const epee::wipeable_string &background_cache_password)
+{
+ MDEBUG("Storing background sync wallet");
+ THROW_WALLET_EXCEPTION_IF(m_background_sync_type != BackgroundSyncCustomPassword, error::wallet_internal_error,
+ "Can only write a background sync wallet when using a custom background password");
+ THROW_WALLET_EXCEPTION_IF(m_background_syncing || m_is_background_wallet, error::wallet_internal_error,
+ "Can't write background sync wallet from an existing background cache");
+ THROW_WALLET_EXCEPTION_IF(wallet_password == background_cache_password,
+ error::background_custom_password_same_as_wallet_password);
+
+ // Set the background encryption key
+ crypto::chacha_key custom_background_key;
+ get_custom_background_key(background_cache_password, custom_background_key, m_kdf_rounds);
+
+ // Keep the background encryption key in memory so the main wallet can update
+ // the background cache when it stores the main wallet cache
+ m_custom_background_key = boost::optional<crypto::chacha_key>(custom_background_key);
+
+ if (m_wallet_file.empty() || m_keys_file.empty())
+ return;
+
+ // Save background keys file, then background cache, then update main wallet settings
+ store_background_keys(custom_background_key);
+ store_background_cache(custom_background_key, true/*do_reset_background_sync_data*/);
+ bool r = store_keys(m_keys_file, wallet_password, false/*watch_only*/);
+ THROW_WALLET_EXCEPTION_IF(!r, error::file_save_error, m_keys_file);
+
+ MDEBUG("Background sync wallet saved successfully");
+}
+//----------------------------------------------------------------------------------------------------
+void wallet2::setup_background_sync(BackgroundSyncType background_sync_type, const epee::wipeable_string &wallet_password, const boost::optional<epee::wipeable_string> &background_cache_password)
+{
+ MDEBUG("Setting background sync to type " << background_sync_type);
+ THROW_WALLET_EXCEPTION_IF(m_background_syncing || m_is_background_wallet, error::wallet_internal_error,
+ "Can't set background sync type from an existing background cache");
+ verify_password_with_cached_key(wallet_password);
+
+ if (background_sync_type != BackgroundSyncOff)
+ validate_background_cache_password_usage(background_sync_type, background_cache_password, m_multisig, m_watch_only, key_on_device());
+
+ THROW_WALLET_EXCEPTION_IF(background_sync_type == BackgroundSyncCustomPassword && wallet_password == background_cache_password,
+ error::background_custom_password_same_as_wallet_password);
+
+ if (m_background_sync_type == background_sync_type && background_sync_type != BackgroundSyncCustomPassword)
+ return; // No need to make any changes
+
+ if (!m_wallet_file.empty())
+ {
+ // Delete existing background files if they already exist
+ const std::string old_background_wallet_file = make_background_wallet_file_name(m_wallet_file);
+ const std::string old_background_keys_file = make_background_keys_file_name(m_wallet_file);
+ const std::string old_background_address_file = old_background_wallet_file + ".address.txt";
+
+ // Make sure no other program is using the background wallet
+ THROW_WALLET_EXCEPTION_IF(!lock_background_keys_file(old_background_keys_file),
+ error::background_wallet_already_open, old_background_wallet_file);
+
+ if (boost::filesystem::exists(old_background_wallet_file))
+ if (!boost::filesystem::remove(old_background_wallet_file))
+ LOG_ERROR("Error deleting background wallet file: " << old_background_wallet_file);
+
+ if (boost::filesystem::exists(old_background_keys_file))
+ if (!boost::filesystem::remove(old_background_keys_file))
+ LOG_ERROR("Error deleting background keys file: " << old_background_keys_file);
+
+ if (boost::filesystem::exists(old_background_address_file))
+ if (!boost::filesystem::remove(old_background_address_file))
+ LOG_ERROR("Error deleting background address file: " << old_background_address_file);
+ }
+
+ m_background_sync_type = background_sync_type;
+ m_custom_background_key = boost::none;
+
+ // Write the new files
+ switch (background_sync_type)
+ {
+ case BackgroundSyncOff:
+ case BackgroundSyncReusePassword: rewrite(m_wallet_file, wallet_password); break;
+ case BackgroundSyncCustomPassword: write_background_sync_wallet(wallet_password, background_cache_password.get()); break;
+ default: THROW_WALLET_EXCEPTION(error::wallet_internal_error, "unknown background sync type");
+ }
+
+ MDEBUG("Done setting background sync type");
+}
+//----------------------------------------------------------------------------------------------------
+/*
+ When background syncing, the wallet scans using just the view key, without
+ keeping the spend key in decrypted state. When a user returns to the wallet
+ and decrypts the spend key, the wallet processes the background synced txs,
+ then the wallet picks up scanning normally right where the background sync
+ left off.
+*/
+void wallet2::start_background_sync()
+{
+ THROW_WALLET_EXCEPTION_IF(m_background_sync_type == BackgroundSyncOff, error::wallet_internal_error,
+ "must setup background sync first before using background sync");
+ THROW_WALLET_EXCEPTION_IF(m_is_background_wallet, error::wallet_internal_error,
+ "Can't start background syncing from a background wallet (it is always background syncing)");
+
+ MDEBUG("Starting background sync");
+
+ if (m_background_syncing)
+ {
+ MDEBUG("Already background syncing");
+ return;
+ }
+
+ if (m_background_sync_type == BackgroundSyncCustomPassword && !m_wallet_file.empty())
+ {
+ // Save the current state of the wallet cache. Only necessary when using a
+ // custom background password which uses distinct background wallet to sync.
+ // When reusing wallet password to sync we reuse the main wallet cache.
+ store();
+
+ // Wipe user data from the background wallet cache not needed to sync.
+ // Only wipe user data from background cache if wallet cache is stored
+ // on disk; otherwise we could lose the data.
+ clear_user_data();
+
+ // Wipe m_cache_key since it can be used to decrypt main wallet cache
+ m_cache_key.scrub();
+ }
+
+ reset_background_sync_data(m_background_sync_data);
+ m_background_syncing = true;
+
+ // Wipe the spend key from memory
+ m_account.forget_spend_key();
+
+ MDEBUG("Background sync started at height " << m_background_sync_data.start_height);
+}
+//----------------------------------------------------------------------------------------------------
+void wallet2::stop_background_sync(const epee::wipeable_string &wallet_password, const crypto::secret_key &spend_secret_key)
+{
+ MDEBUG("Stopping background sync");
+
+ // Verify provided password and spend secret key. If no spend secret key is
+ // provided, recover it from the wallet keys file
+ crypto::secret_key recovered_spend_key = crypto::null_skey;
+ if (!m_wallet_file.empty())
+ {
+ THROW_WALLET_EXCEPTION_IF(!verify_password(wallet_password, recovered_spend_key), error::invalid_password);
+ }
+ else
+ {
+ verify_password_with_cached_key(wallet_password);
+ }
+
+ if (spend_secret_key != crypto::null_skey)
+ {
+ THROW_WALLET_EXCEPTION_IF(!m_wallet_file.empty() && spend_secret_key != recovered_spend_key,
+ error::invalid_spend_key);
+ MDEBUG("Setting spend secret key with the provided key");
+ recovered_spend_key = spend_secret_key;
+ }
+
+ // Verify private spend key derives to wallet's public spend key
+ const auto verify_spend_key = [this](crypto::secret_key &recovered_spend_key) -> bool
+ {
+ crypto::public_key spend_public_key;
+ return recovered_spend_key != crypto::null_skey &&
+ crypto::secret_key_to_public_key(recovered_spend_key, spend_public_key) &&
+ m_account.get_keys().m_account_address.m_spend_public_key == spend_public_key;
+ };
+ THROW_WALLET_EXCEPTION_IF(!verify_spend_key(recovered_spend_key), error::invalid_spend_key);
+
+ THROW_WALLET_EXCEPTION_IF(m_background_sync_type == BackgroundSyncOff, error::wallet_internal_error,
+ "must setup background sync first before using background sync");
+ THROW_WALLET_EXCEPTION_IF(m_is_background_wallet, error::wallet_internal_error,
+ "Can't stop background syncing from a background wallet");
+
+ if (!m_background_syncing)
+ return;
+
+ // Copy background cache, we're about to overwrite it
+ const background_sync_data_t background_sync_data = m_background_sync_data;
+ const hashchain background_synced_chain = m_blockchain;
+ const uint64_t last_block_reward = m_last_block_reward;
+
+ if (m_background_sync_type == BackgroundSyncCustomPassword && !m_wallet_file.empty())
+ {
+ // Reload the wallet from disk
+ load(m_wallet_file, wallet_password);
+ THROW_WALLET_EXCEPTION_IF(!verify_spend_key(recovered_spend_key), error::invalid_spend_key);
+ }
+ m_background_syncing = false;
+
+ // Set the plaintext spend key
+ m_account.set_spend_key(recovered_spend_key);
+
+ // Encrypt the spend key when done if needed
+ epee::misc_utils::auto_scope_leave_caller keys_reencryptor;
+ if (m_ask_password == AskPasswordToDecrypt && !m_unattended && !m_watch_only)
+ keys_reencryptor = epee::misc_utils::create_scope_leave_handler([&, this]{encrypt_keys(wallet_password);});
+
+ // Now we can use the decrypted spend key to process background cache
+ process_background_cache(background_sync_data, background_synced_chain, last_block_reward);
+
+ // Reset the background cache after processing
+ reset_background_sync_data(m_background_sync_data);
+
+ MDEBUG("Background sync stopped");
+}
+//----------------------------------------------------------------------------------------------------
wallet2::payment_container wallet2::export_payments() const
{
payment_container payments;
@@ -14302,9 +15243,13 @@ void wallet2::generate_genesis(cryptonote::block& b) const {
//----------------------------------------------------------------------------------------------------
mms::multisig_wallet_state wallet2::get_multisig_wallet_state() const
{
+ const multisig::multisig_account_status ms_status{get_multisig_status()};
+
mms::multisig_wallet_state state;
state.nettype = m_nettype;
- state.multisig = multisig(&state.multisig_is_ready);
+ state.multisig = ms_status.multisig_is_active;
+ state.multisig_is_ready = ms_status.is_ready;
+ state.multisig_kex_is_done = ms_status.kex_is_done;
state.has_multisig_partial_key_images = has_multisig_partial_key_images();
state.multisig_rounds_passed = m_multisig_rounds_passed;
state.num_transfer_details = m_transfers.size();
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index 5f884e374..34833bed6 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -57,6 +57,7 @@
#include "common/util.h"
#include "crypto/chacha.h"
#include "crypto/hash.h"
+#include "multisig/multisig_account.h"
#include "ringct/rctTypes.h"
#include "ringct/rctOps.h"
#include "checkpoints/checkpoints.h"
@@ -85,6 +86,7 @@
class Serialization_portability_wallet_Test;
class wallet_accessor_test;
+namespace multisig { class multisig_account; }
namespace tools
{
@@ -248,6 +250,20 @@ private:
BackgroundMiningNo = 2,
};
+ enum BackgroundSyncType {
+ BackgroundSyncOff = 0,
+ BackgroundSyncReusePassword = 1,
+ BackgroundSyncCustomPassword = 2,
+ };
+
+ static BackgroundSyncType background_sync_type_from_str(const std::string &background_sync_type_str)
+ {
+ if (background_sync_type_str == "off") return BackgroundSyncOff;
+ if (background_sync_type_str == "reuse-wallet-password") return BackgroundSyncReusePassword;
+ if (background_sync_type_str == "custom-background-password") return BackgroundSyncCustomPassword;
+ throw std::logic_error("Unknown background sync type");
+ };
+
enum ExportFormat {
Binary = 0,
Ascii,
@@ -274,7 +290,12 @@ private:
//! Just parses variables.
static std::unique_ptr<wallet2> make_dummy(const boost::program_options::variables_map& vm, bool unattended, const std::function<boost::optional<password_container>(const char *, bool)> &password_prompter);
- static bool verify_password(const std::string& keys_file_name, const epee::wipeable_string& password, bool no_spend_key, hw::device &hwdev, uint64_t kdf_rounds);
+ static bool verify_password(const std::string& keys_file_name, const epee::wipeable_string& password, bool no_spend_key, hw::device &hwdev, uint64_t kdf_rounds)
+ {
+ crypto::secret_key spend_key = crypto::null_skey;
+ return verify_password(keys_file_name, password, no_spend_key, hwdev, kdf_rounds, spend_key);
+ };
+ static bool verify_password(const std::string& keys_file_name, const epee::wipeable_string& password, bool no_spend_key, hw::device &hwdev, uint64_t kdf_rounds, crypto::secret_key &spend_key_out);
static bool query_device(hw::device::device_type& device_type, const std::string& keys_file_name, const epee::wipeable_string& password, uint64_t kdf_rounds = 1);
wallet2(cryptonote::network_type nettype = cryptonote::MAINNET, uint64_t kdf_rounds = 1, bool unattended = false, std::unique_ptr<epee::net_utils::http::http_client_factory> http_client_factory = std::unique_ptr<epee::net_utils::http::http_client_factory>(new net::http::client_factory()));
@@ -784,6 +805,54 @@ private:
END_SERIALIZE()
};
+ struct background_synced_tx_t
+ {
+ uint64_t index_in_background_sync_data;
+ cryptonote::transaction tx;
+ std::vector<uint64_t> output_indices;
+ uint64_t height;
+ uint64_t block_timestamp;
+ bool double_spend_seen;
+
+ BEGIN_SERIALIZE_OBJECT()
+ VERSION_FIELD(0)
+ VARINT_FIELD(index_in_background_sync_data)
+
+ // prune tx; don't need to keep signature data
+ if (!tx.serialize_base(ar))
+ return false;
+
+ FIELD(output_indices)
+ VARINT_FIELD(height)
+ VARINT_FIELD(block_timestamp)
+ FIELD(double_spend_seen)
+ END_SERIALIZE()
+ };
+
+ struct background_sync_data_t
+ {
+ bool first_refresh_done = false;
+ uint64_t start_height = 0;
+ std::unordered_map<crypto::hash, background_synced_tx_t> txs;
+
+ // Relevant wallet settings
+ uint64_t wallet_refresh_from_block_height;
+ size_t subaddress_lookahead_major;
+ size_t subaddress_lookahead_minor;
+ RefreshType wallet_refresh_type;
+
+ BEGIN_SERIALIZE_OBJECT()
+ VERSION_FIELD(0)
+ FIELD(first_refresh_done)
+ FIELD(start_height)
+ FIELD(txs)
+ FIELD(wallet_refresh_from_block_height)
+ VARINT_FIELD(subaddress_lookahead_major)
+ VARINT_FIELD(subaddress_lookahead_minor)
+ VARINT_FIELD(wallet_refresh_type)
+ END_SERIALIZE()
+ };
+
typedef std::tuple<uint64_t, crypto::public_key, rct::key> get_outs_entry;
struct parsed_block
@@ -891,6 +960,23 @@ private:
*/
void restore(const std::string& wallet_, const epee::wipeable_string& password, const std::string &device_name, bool create_address_file = false);
+ private:
+ /*!
+ * \brief Decrypts the account keys
+ * \return an RAII reencryptor for the account keys
+ */
+ epee::misc_utils::auto_scope_leave_caller decrypt_account_for_multisig(const epee::wipeable_string &password);
+ /*!
+ * \brief Creates an uninitialized multisig account
+ * \outparam: the uninitialized multisig account
+ */
+ void get_uninitialized_multisig_account(multisig::multisig_account &account_out) const;
+ /*!
+ * \brief Reconstructs a multisig account from wallet2 state
+ * \outparam: the reconstructed multisig account
+ */
+ void get_reconstructed_multisig_account(multisig::multisig_account &account_out) const;
+ public:
/*!
* \brief Creates a multisig wallet
* \return empty if done, non empty if we need to send another string
@@ -913,6 +999,13 @@ private:
*/
std::string get_multisig_first_kex_msg() const;
/*!
+ * \brief Use multisig kex messages for an in-progress kex round to 'boost' the following round for another group member
+ */
+ std::string get_multisig_key_exchange_booster(const epee::wipeable_string &password,
+ const std::vector<std::string> &kex_messages,
+ const std::uint32_t threshold,
+ const std::uint32_t num_signers);
+ /*!
* Export multisig info
* This will generate and remember new k values
*/
@@ -972,7 +1065,8 @@ private:
/*!
* \brief verifies given password is correct for default wallet keys file
*/
- bool verify_password(const epee::wipeable_string& password);
+ bool verify_password(const epee::wipeable_string& password) {crypto::secret_key key = crypto::null_skey; return verify_password(password, key);};
+ bool verify_password(const epee::wipeable_string& password, crypto::secret_key &spend_key_out);
cryptonote::account_base& get_account(){return m_account;}
const cryptonote::account_base& get_account()const{return m_account;}
@@ -991,13 +1085,13 @@ private:
uint64_t max_reorg_depth() const {return m_max_reorg_depth;}
bool deinit();
- bool init(std::string daemon_address = "http://localhost:8080",
+ bool init(std::string daemon_address,
boost::optional<epee::net_utils::http::login> daemon_login = boost::none,
const std::string &proxy = "",
uint64_t upper_transaction_weight_limit = 0,
bool trusted_daemon = true,
epee::net_utils::ssl_options_t ssl_options = epee::net_utils::ssl_support_t::e_ssl_support_autodetect);
- bool set_daemon(std::string daemon_address = "http://localhost:8080",
+ bool set_daemon(std::string daemon_address,
boost::optional<epee::net_utils::http::login> daemon_login = boost::none, bool trusted_daemon = true,
epee::net_utils::ssl_options_t ssl_options = epee::net_utils::ssl_support_t::e_ssl_support_autodetect,
const std::string &proxy = "");
@@ -1059,7 +1153,8 @@ private:
cryptonote::network_type nettype() const { return m_nettype; }
bool watch_only() const { return m_watch_only; }
- bool multisig(bool *ready = NULL, uint32_t *threshold = NULL, uint32_t *total = NULL) const;
+ bool is_background_wallet() const { return m_is_background_wallet; }
+ multisig::multisig_account_status get_multisig_status() const;
bool has_multisig_partial_key_images() const;
bool has_unknown_key_images() const;
bool get_multisig_seed(epee::wipeable_string& seed, const epee::wipeable_string &passphrase = std::string()) const;
@@ -1079,10 +1174,10 @@ private:
template<typename T>
void transfer_selected(const std::vector<cryptonote::tx_destination_entry>& dsts, const std::vector<size_t>& selected_transfers, size_t fake_outputs_count,
std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs, std::unordered_set<crypto::public_key> &valid_public_keys_cache,
- uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, T destination_split_strategy, const tx_dust_policy& dust_policy, cryptonote::transaction& tx, pending_tx &ptx, const bool use_view_tags);
+ uint64_t fee, const std::vector<uint8_t>& extra, T destination_split_strategy, const tx_dust_policy& dust_policy, cryptonote::transaction& tx, pending_tx &ptx, const bool use_view_tags);
void transfer_selected_rct(std::vector<cryptonote::tx_destination_entry> dsts, const std::vector<size_t>& selected_transfers, size_t fake_outputs_count,
std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs, std::unordered_set<crypto::public_key> &valid_public_keys_cache,
- uint64_t unlock_time, uint64_t fee, const std::vector<uint8_t>& extra, cryptonote::transaction& tx, pending_tx &ptx, const rct::RCTConfig &rct_config, const bool use_view_tags);
+ uint64_t fee, const std::vector<uint8_t>& extra, cryptonote::transaction& tx, pending_tx &ptx, const rct::RCTConfig &rct_config, const bool use_view_tags);
void commit_tx(pending_tx& ptx_vector);
void commit_tx(std::vector<pending_tx>& ptx_vector);
@@ -1104,10 +1199,10 @@ private:
bool parse_unsigned_tx_from_str(const std::string &unsigned_tx_st, unsigned_tx_set &exported_txs) const;
bool load_tx(const std::string &signed_filename, std::vector<tools::wallet2::pending_tx> &ptx, std::function<bool(const signed_tx_set&)> accept_func = NULL);
bool parse_tx_from_str(const std::string &signed_tx_st, std::vector<tools::wallet2::pending_tx> &ptx, std::function<bool(const signed_tx_set &)> accept_func);
- std::vector<wallet2::pending_tx> create_transactions_2(std::vector<cryptonote::tx_destination_entry> dsts, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t>& extra, uint32_t subaddr_account, std::set<uint32_t> subaddr_indices, const unique_index_container& subtract_fee_from_outputs = {}); // pass subaddr_indices by value on purpose
- std::vector<wallet2::pending_tx> create_transactions_all(uint64_t below, const cryptonote::account_public_address &address, bool is_subaddress, const size_t outputs, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t>& extra, uint32_t subaddr_account, std::set<uint32_t> subaddr_indices);
- std::vector<wallet2::pending_tx> create_transactions_single(const crypto::key_image &ki, const cryptonote::account_public_address &address, bool is_subaddress, const size_t outputs, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t>& extra);
- std::vector<wallet2::pending_tx> create_transactions_from(const cryptonote::account_public_address &address, bool is_subaddress, const size_t outputs, std::vector<size_t> unused_transfers_indices, std::vector<size_t> unused_dust_indices, const size_t fake_outs_count, const uint64_t unlock_time, uint32_t priority, const std::vector<uint8_t>& extra);
+ std::vector<wallet2::pending_tx> create_transactions_2(std::vector<cryptonote::tx_destination_entry> dsts, const size_t fake_outs_count, uint32_t priority, const std::vector<uint8_t>& extra, uint32_t subaddr_account, std::set<uint32_t> subaddr_indices, const unique_index_container& subtract_fee_from_outputs = {}); // pass subaddr_indices by value on purpose
+ std::vector<wallet2::pending_tx> create_transactions_all(uint64_t below, const cryptonote::account_public_address &address, bool is_subaddress, const size_t outputs, const size_t fake_outs_count, uint32_t priority, const std::vector<uint8_t>& extra, uint32_t subaddr_account, std::set<uint32_t> subaddr_indices);
+ std::vector<wallet2::pending_tx> create_transactions_single(const crypto::key_image &ki, const cryptonote::account_public_address &address, bool is_subaddress, const size_t outputs, const size_t fake_outs_count, uint32_t priority, const std::vector<uint8_t>& extra);
+ std::vector<wallet2::pending_tx> create_transactions_from(const cryptonote::account_public_address &address, bool is_subaddress, const size_t outputs, std::vector<size_t> unused_transfers_indices, std::vector<size_t> unused_dust_indices, const size_t fake_outs_count, uint32_t priority, const std::vector<uint8_t>& extra);
bool sanity_check(const std::vector<wallet2::pending_tx> &ptx_vector, const std::vector<cryptonote::tx_destination_entry>& dsts, const unique_index_container& subtract_fee_from_outputs = {}) const;
void cold_tx_aux_import(const std::vector<pending_tx>& ptx, const std::vector<std::string>& tx_device_aux);
void cold_sign_tx(const std::vector<pending_tx>& ptx_vector, signed_tx_set &exported_txs, std::vector<cryptonote::address_parse_info> &dsts_info, std::vector<std::string> & tx_device_aux);
@@ -1268,11 +1363,17 @@ private:
return;
}
a & m_has_ever_refreshed_from_node;
+ if(ver < 31)
+ {
+ m_background_sync_data = background_sync_data_t{};
+ return;
+ }
+ a & m_background_sync_data;
}
BEGIN_SERIALIZE_OBJECT()
MAGIC_FIELD("monero wallet cache")
- VERSION_FIELD(1)
+ VERSION_FIELD(2)
FIELD(m_blockchain)
FIELD(m_transfers)
FIELD(m_account_public_address)
@@ -1305,6 +1406,12 @@ private:
return true;
}
FIELD(m_has_ever_refreshed_from_node)
+ if (version < 2)
+ {
+ m_background_sync_data = background_sync_data_t{};
+ return true;
+ }
+ FIELD(m_background_sync_data)
END_SERIALIZE()
/*!
@@ -1320,6 +1427,8 @@ private:
* \return Whether path is valid format
*/
static bool wallet_valid_path_format(const std::string& file_path);
+ static std::string make_background_wallet_file_name(const std::string &wallet_file);
+ static std::string make_background_keys_file_name(const std::string &wallet_file);
static bool parse_long_payment_id(const std::string& payment_id_str, crypto::hash& payment_id);
static bool parse_short_payment_id(const std::string& payment_id_str, crypto::hash8& payment_id);
static bool parse_payment_id(const std::string& payment_id_str, crypto::hash& payment_id);
@@ -1366,6 +1475,9 @@ private:
void ignore_outputs_below(uint64_t value) { m_ignore_outputs_below = value; }
bool track_uses() const { return m_track_uses; }
void track_uses(bool value) { m_track_uses = value; }
+ BackgroundSyncType background_sync_type() const { return m_background_sync_type; }
+ void setup_background_sync(BackgroundSyncType background_sync_type, const epee::wipeable_string &wallet_password, const boost::optional<epee::wipeable_string> &background_cache_password);
+ bool is_background_syncing() const { return m_background_syncing; }
bool show_wallet_name_when_locked() const { return m_show_wallet_name_when_locked; }
void show_wallet_name_when_locked(bool value) { m_show_wallet_name_when_locked = value; }
BackgroundMiningSetupType setup_background_mining() const { return m_setup_background_mining; }
@@ -1640,6 +1752,9 @@ private:
uint64_t get_bytes_sent() const;
uint64_t get_bytes_received() const;
+ void start_background_sync();
+ void stop_background_sync(const epee::wipeable_string &wallet_password, const crypto::secret_key &spend_secret_key = crypto::null_skey);
+
// MMS -------------------------------------------------------------------------------------------------
mms::message_store& get_message_store() { return m_message_store; };
const mms::message_store& get_message_store() const { return m_message_store; };
@@ -1672,6 +1787,9 @@ private:
* \return Whether it was successful.
*/
bool store_keys(const std::string& keys_file_name, const epee::wipeable_string& password, bool watch_only = false);
+ bool store_keys(const std::string& keys_file_name, const crypto::chacha_key& key, bool watch_only = false, bool background_keys_file = false);
+ boost::optional<wallet2::keys_file_data> get_keys_file_data(const crypto::chacha_key& key, bool watch_only = false, bool background_keys_file = false);
+ bool store_keys_file_data(const std::string& keys_file_name, wallet2::keys_file_data &keys_file_data, bool background_keys_file = false);
/*!
* \brief Load wallet keys information from wallet file.
* \param keys_file_name Name of wallet file
@@ -1685,6 +1803,7 @@ private:
*/
bool load_keys_buf(const std::string& keys_buf, const epee::wipeable_string& password);
bool load_keys_buf(const std::string& keys_buf, const epee::wipeable_string& password, boost::optional<crypto::chacha_key>& keys_to_encrypt);
+ void load_wallet_cache(const bool use_fs, const std::string& cache_buf = "");
void process_new_transaction(const crypto::hash &txid, const cryptonote::transaction& tx, const std::vector<uint64_t> &o_indices, uint64_t height, uint8_t block_version, uint64_t ts, bool miner_tx, bool pool, bool double_spend_seen, const tx_cache_data &tx_cache_data, std::map<std::pair<uint64_t, uint64_t>, size_t> *output_tracker_cache = NULL, bool ignore_callbacks = false);
bool should_skip_block(const cryptonote::block &b, uint64_t height) const;
void process_new_blockchain_entry(const cryptonote::block& b, const cryptonote::block_complete_entry& bche, const parsed_block &parsed_block, const crypto::hash& bl_id, uint64_t height, const std::vector<tx_cache_data> &tx_cache_data, size_t tx_cache_data_offset, std::map<std::pair<uint64_t, uint64_t>, size_t> *output_tracker_cache = NULL);
@@ -1693,6 +1812,15 @@ private:
void get_short_chain_history(std::list<crypto::hash>& ids, uint64_t granularity = 1) const;
bool clear();
void clear_soft(bool keep_key_images=false);
+ /*
+ * clear_user_data clears data created by the user, which is mostly data
+ * that a view key cannot identify on chain. This function was initially
+ * added to ensure that a "background" wallet (a wallet that syncs with just
+ * a view key hot in memory) does not have any sensitive data loaded that it
+ * does not need in order to sync. Future devs should take care to ensure
+ * that this function deletes data that is not useful for background syncing
+ */
+ void clear_user_data();
void pull_blocks(bool first, bool try_incremental, uint64_t start_height, uint64_t& blocks_start_height, const std::list<crypto::hash> &short_chain_history, std::vector<cryptonote::block_complete_entry> &blocks, std::vector<cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::block_output_indices> &o_indices, uint64_t &current_height, std::vector<std::tuple<cryptonote::transaction, crypto::hash, bool>>& process_pool_txs);
void pull_hashes(uint64_t start_height, uint64_t& blocks_start_height, const std::list<crypto::hash> &short_chain_history, std::vector<crypto::hash> &hashes);
void fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height, std::list<crypto::hash> &short_chain_history, bool force = false);
@@ -1744,10 +1872,23 @@ private:
bool get_ring(const crypto::chacha_key &key, const crypto::key_image &key_image, std::vector<uint64_t> &outs);
crypto::chacha_key get_ringdb_key();
void setup_keys(const epee::wipeable_string &password);
+ const crypto::chacha_key get_cache_key();
+ void verify_password_with_cached_key(const epee::wipeable_string &password);
+ void verify_password_with_cached_key(const crypto::chacha_key &key);
size_t get_transfer_details(const crypto::key_image &ki) const;
tx_entry_data get_tx_entries(const std::unordered_set<crypto::hash> &txids);
void sort_scan_tx_entries(std::vector<process_tx_entry_t> &unsorted_tx_entries);
void process_scan_txs(const tx_entry_data &txs_to_scan, const tx_entry_data &txs_to_reprocess, const std::unordered_set<crypto::hash> &tx_hashes_to_reprocess, detached_blockchain_data &dbd);
+ void write_background_sync_wallet(const epee::wipeable_string &wallet_password, const epee::wipeable_string &background_cache_password);
+ void process_background_cache_on_open();
+ void process_background_cache(const background_sync_data_t &background_sync_data, const hashchain &background_chain, uint64_t last_block_reward);
+ void reset_background_sync_data(background_sync_data_t &background_sync_data);
+ void store_background_cache(const crypto::chacha_key &custom_background_key, const bool do_reset_background_sync_data = true);
+ void store_background_keys(const crypto::chacha_key &custom_background_key);
+
+ bool lock_background_keys_file(const std::string &background_keys_file);
+ bool unlock_background_keys_file();
+ bool is_background_keys_file_locked() const;
void register_devices();
hw::device& lookup_device(const std::string & device_descriptor);
@@ -1859,6 +2000,8 @@ private:
uint64_t m_ignore_outputs_above;
uint64_t m_ignore_outputs_below;
bool m_track_uses;
+ bool m_is_background_wallet;
+ BackgroundSyncType m_background_sync_type;
bool m_show_wallet_name_when_locked;
uint32_t m_inactivity_lock_timeout;
BackgroundMiningSetupType m_setup_background_mining;
@@ -1886,6 +2029,7 @@ private:
uint64_t m_last_block_reward;
std::unique_ptr<tools::file_locker> m_keys_file_locker;
+ std::unique_ptr<tools::file_locker> m_background_keys_file_locker;
mms::message_store m_message_store;
bool m_original_keys_available;
@@ -1893,6 +2037,7 @@ private:
crypto::secret_key m_original_view_secret_key;
crypto::chacha_key m_cache_key;
+ boost::optional<crypto::chacha_key> m_custom_background_key = boost::none;
std::shared_ptr<wallet_keys_unlocker> m_encrypt_keys_after_refresh;
bool m_unattended;
@@ -1908,9 +2053,13 @@ private:
static boost::mutex default_daemon_address_lock;
static std::string default_daemon_address;
+
+ bool m_background_syncing;
+ bool m_processing_background_cache;
+ background_sync_data_t m_background_sync_data;
};
}
-BOOST_CLASS_VERSION(tools::wallet2, 30)
+BOOST_CLASS_VERSION(tools::wallet2, 31)
BOOST_CLASS_VERSION(tools::wallet2::transfer_details, 12)
BOOST_CLASS_VERSION(tools::wallet2::multisig_info, 1)
BOOST_CLASS_VERSION(tools::wallet2::multisig_info::LR, 0)
@@ -1926,6 +2075,8 @@ BOOST_CLASS_VERSION(tools::wallet2::signed_tx_set, 1)
BOOST_CLASS_VERSION(tools::wallet2::tx_construction_data, 4)
BOOST_CLASS_VERSION(tools::wallet2::pending_tx, 3)
BOOST_CLASS_VERSION(tools::wallet2::multisig_sig, 1)
+BOOST_CLASS_VERSION(tools::wallet2::background_synced_tx_t, 0)
+BOOST_CLASS_VERSION(tools::wallet2::background_sync_data_t, 0)
namespace boost
{
@@ -2424,6 +2575,29 @@ namespace boost
return;
a & x.multisig_sigs;
}
+
+ template <class Archive>
+ inline void serialize(Archive& a, tools::wallet2::background_synced_tx_t &x, const boost::serialization::version_type ver)
+ {
+ a & x.index_in_background_sync_data;
+ a & x.tx;
+ a & x.output_indices;
+ a & x.height;
+ a & x.block_timestamp;
+ a & x.double_spend_seen;
+ }
+
+ template <class Archive>
+ inline void serialize(Archive& a, tools::wallet2::background_sync_data_t &x, const boost::serialization::version_type ver)
+ {
+ a & x.first_refresh_done;
+ a & x.start_height;
+ a & x.txs;
+ a & x.wallet_refresh_from_block_height;
+ a & x.subaddress_lookahead_major;
+ a & x.subaddress_lookahead_minor;
+ a & x.wallet_refresh_type;
+ }
}
}
diff --git a/src/wallet/wallet_errors.h b/src/wallet/wallet_errors.h
index 5166f868f..0315a7102 100644
--- a/src/wallet/wallet_errors.h
+++ b/src/wallet/wallet_errors.h
@@ -63,6 +63,7 @@ namespace tools
// invalid_password
// invalid_priority
// invalid_multisig_seed
+ // invalid_spend_key
// refresh_error *
// acc_outs_lookup_error
// block_parse_error
@@ -86,6 +87,7 @@ namespace tools
// zero_amount
// zero_destination
// subtract_fee_from_bad_index
+ // nonzero_unlock_time
// wallet_rpc_error *
// daemon_busy
// no_connection_to_daemon
@@ -96,6 +98,9 @@ namespace tools
// wallet_files_doesnt_correspond
// scan_tx_error *
// wont_reprocess_recent_txs_via_untrusted_daemon
+ // background_sync_error *
+ // background_wallet_already_open
+ // background_custom_password_same_as_wallet_password
//
// * - class with protected ctor
@@ -303,6 +308,16 @@ namespace tools
std::string to_string() const { return wallet_logic_error::to_string(); }
};
+ struct invalid_spend_key : public wallet_logic_error
+ {
+ explicit invalid_spend_key(std::string&& loc)
+ : wallet_logic_error(std::move(loc), "invalid spend key")
+ {
+ }
+
+ std::string to_string() const { return wallet_logic_error::to_string(); }
+ };
+
//----------------------------------------------------------------------------------------------------
struct invalid_pregenerated_random : public wallet_logic_error
{
@@ -592,20 +607,17 @@ namespace tools
std::string && loc
, sources_t const & sources
, destinations_t const & destinations
- , uint64_t unlock_time
, cryptonote::network_type nettype
)
: transfer_error(std::move(loc), "transaction was not constructed")
, m_sources(sources)
, m_destinations(destinations)
- , m_unlock_time(unlock_time)
, m_nettype(nettype)
{
}
const sources_t& sources() const { return m_sources; }
const destinations_t& destinations() const { return m_destinations; }
- uint64_t unlock_time() const { return m_unlock_time; }
std::string to_string() const
{
@@ -637,15 +649,12 @@ namespace tools
cryptonote::print_money(dst.amount);
}
- ss << "\nunlock_time: " << m_unlock_time;
-
return ss.str();
}
private:
sources_t m_sources;
destinations_t m_destinations;
- uint64_t m_unlock_time;
cryptonote::network_type m_nettype;
};
//----------------------------------------------------------------------------------------------------
@@ -789,6 +798,14 @@ namespace tools
}
};
//----------------------------------------------------------------------------------------------------
+ struct nonzero_unlock_time : public transfer_error
+ {
+ explicit nonzero_unlock_time(std::string&& loc)
+ : transfer_error(std::move(loc), "transaction cannot have non-zero unlock time")
+ {
+ }
+ };
+ //----------------------------------------------------------------------------------------------------
struct wallet_rpc_error : public wallet_logic_error
{
const std::string& request() const { return m_request; }
@@ -945,6 +962,31 @@ namespace tools
}
};
//----------------------------------------------------------------------------------------------------
+ struct background_sync_error : public wallet_logic_error
+ {
+ protected:
+ explicit background_sync_error(std::string&& loc, const std::string& message)
+ : wallet_logic_error(std::move(loc), message)
+ {
+ }
+ };
+ //----------------------------------------------------------------------------------------------------
+ struct background_wallet_already_open : public background_sync_error
+ {
+ explicit background_wallet_already_open(std::string&& loc, const std::string& background_wallet_file)
+ : background_sync_error(std::move(loc), "background wallet " + background_wallet_file + " is already opened by another wallet program")
+ {
+ }
+ };
+ //----------------------------------------------------------------------------------------------------
+ struct background_custom_password_same_as_wallet_password : public background_sync_error
+ {
+ explicit background_custom_password_same_as_wallet_password(std::string&& loc)
+ : background_sync_error(std::move(loc), "custom background password must be different than wallet password")
+ {
+ }
+ };
+ //----------------------------------------------------------------------------------------------------
#if !defined(_MSC_VER)
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index d7aa80e0a..f998c88b7 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -65,7 +65,7 @@ using namespace epee;
#define CHECK_MULTISIG_ENABLED() \
do \
{ \
- if (m_wallet->multisig() && !m_wallet->is_multisig_enabled()) \
+ if (m_wallet->get_multisig_status().multisig_is_active && !m_wallet->is_multisig_enabled()) \
{ \
er.code = WALLET_RPC_ERROR_CODE_DISABLED; \
er.message = "This wallet is multisig, and multisig is disabled. Multisig is an experimental feature and may have bugs. Things that could go wrong include: funds sent to a multisig wallet can't be spent at all, can only be spent with the participation of a malicious group member, or can be stolen by a malicious group member. You can enable it by running this once in monero-wallet-cli: set enable-multisig-experimental 1"; \
@@ -73,6 +73,54 @@ using namespace epee;
} \
} while(0)
+#define CHECK_IF_BACKGROUND_SYNCING() \
+ do \
+ { \
+ if (!m_wallet) { return not_open(er); } \
+ if (m_wallet->is_background_wallet()) \
+ { \
+ er.code = WALLET_RPC_ERROR_CODE_IS_BACKGROUND_WALLET; \
+ er.message = "This command is disabled for background wallets."; \
+ return false; \
+ } \
+ if (m_wallet->is_background_syncing()) \
+ { \
+ er.code = WALLET_RPC_ERROR_CODE_IS_BACKGROUND_SYNCING; \
+ er.message = "This command is disabled while background syncing. Stop background syncing to use this command."; \
+ return false; \
+ } \
+ } while(0)
+
+#define PRE_VALIDATE_BACKGROUND_SYNC() \
+ do \
+ { \
+ if (!m_wallet) { return not_open(er); } \
+ if (m_restricted) \
+ { \
+ er.code = WALLET_RPC_ERROR_CODE_DENIED; \
+ er.message = "Command unavailable in restricted mode."; \
+ return false; \
+ } \
+ if (m_wallet->key_on_device()) \
+ { \
+ er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; \
+ er.message = "Command not supported by HW wallet"; \
+ return false; \
+ } \
+ if (m_wallet->get_multisig_status().multisig_is_active) \
+ { \
+ er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; \
+ er.message = "Multisig wallet cannot enable background sync"; \
+ return false; \
+ } \
+ if (m_wallet->watch_only()) \
+ { \
+ er.code = WALLET_RPC_ERROR_CODE_WATCH_ONLY; \
+ er.message = "Watch-only wallet cannot enable background sync"; \
+ return false; \
+ } \
+ } while (0)
+
namespace
{
const command_line::arg_descriptor<std::string, true> arg_rpc_bind_port = {"rpc-bind-port", "Sets bind port for server"};
@@ -245,7 +293,7 @@ namespace tools
);
std::string temp = "monero-wallet-rpc." + bind_port + ".login";
- rpc_login_file = tools::private_file::create(temp);
+ rpc_login_file = tools::private_file::drop_and_recreate(temp);
if (!rpc_login_file.handle())
{
LOG_ERROR(tr("Failed to create file ") << temp << tr(". Check permissions or remove file"));
@@ -291,6 +339,9 @@ namespace tools
{
if (!m_wallet)
return;
+ // Background mining can be toggled from the main wallet
+ if (m_wallet->is_background_wallet() || m_wallet->is_background_syncing())
+ return;
tools::wallet2::BackgroundMiningSetupType setup = m_wallet->setup_background_mining();
if (setup == tools::wallet2::BackgroundMiningNo)
@@ -459,7 +510,7 @@ namespace tools
{
res.balance = req.all_accounts ? m_wallet->balance_all(req.strict) : m_wallet->balance(req.account_index, req.strict);
res.unlocked_balance = req.all_accounts ? m_wallet->unlocked_balance_all(req.strict, &res.blocks_to_unlock, &res.time_to_unlock) : m_wallet->unlocked_balance(req.account_index, req.strict, &res.blocks_to_unlock, &res.time_to_unlock);
- res.multisig_import_needed = m_wallet->multisig() && m_wallet->has_multisig_partial_key_images();
+ res.multisig_import_needed = m_wallet->get_multisig_status().multisig_is_active && m_wallet->has_multisig_partial_key_images();
std::map<uint32_t, std::map<uint32_t, uint64_t>> balance_per_subaddress_per_account;
std::map<uint32_t, std::map<uint32_t, std::pair<uint64_t, std::pair<uint64_t, uint64_t>>>> unlocked_balance_per_subaddress_per_account;
if (req.all_accounts)
@@ -581,6 +632,7 @@ namespace tools
bool wallet_rpc_server::on_create_address(const wallet_rpc::COMMAND_RPC_CREATE_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_CREATE_ADDRESS::response& res, epee::json_rpc::error& er, const connection_context *ctx)
{
if (!m_wallet) return not_open(er);
+ CHECK_IF_BACKGROUND_SYNCING();
try
{
if (req.count < 1 || req.count > 65536) {
@@ -618,6 +670,7 @@ namespace tools
bool wallet_rpc_server::on_label_address(const wallet_rpc::COMMAND_RPC_LABEL_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_LABEL_ADDRESS::response& res, epee::json_rpc::error& er, const connection_context *ctx)
{
if (!m_wallet) return not_open(er);
+ CHECK_IF_BACKGROUND_SYNCING();
try
{
m_wallet->set_subaddress_label(req.index, req.label);
@@ -680,6 +733,7 @@ namespace tools
bool wallet_rpc_server::on_create_account(const wallet_rpc::COMMAND_RPC_CREATE_ACCOUNT::request& req, wallet_rpc::COMMAND_RPC_CREATE_ACCOUNT::response& res, epee::json_rpc::error& er, const connection_context *ctx)
{
if (!m_wallet) return not_open(er);
+ CHECK_IF_BACKGROUND_SYNCING();
try
{
m_wallet->add_subaddress_account(req.label);
@@ -697,6 +751,7 @@ namespace tools
bool wallet_rpc_server::on_label_account(const wallet_rpc::COMMAND_RPC_LABEL_ACCOUNT::request& req, wallet_rpc::COMMAND_RPC_LABEL_ACCOUNT::response& res, epee::json_rpc::error& er, const connection_context *ctx)
{
if (!m_wallet) return not_open(er);
+ CHECK_IF_BACKGROUND_SYNCING();
try
{
m_wallet->set_subaddress_label({req.account_index, 0}, req.label);
@@ -712,6 +767,7 @@ namespace tools
bool wallet_rpc_server::on_get_account_tags(const wallet_rpc::COMMAND_RPC_GET_ACCOUNT_TAGS::request& req, wallet_rpc::COMMAND_RPC_GET_ACCOUNT_TAGS::response& res, epee::json_rpc::error& er, const connection_context *ctx)
{
if (!m_wallet) return not_open(er);
+ CHECK_IF_BACKGROUND_SYNCING();
const std::pair<std::map<std::string, std::string>, std::vector<std::string>> account_tags = m_wallet->get_account_tags();
for (const std::pair<const std::string, std::string>& p : account_tags.first)
{
@@ -731,6 +787,7 @@ namespace tools
bool wallet_rpc_server::on_tag_accounts(const wallet_rpc::COMMAND_RPC_TAG_ACCOUNTS::request& req, wallet_rpc::COMMAND_RPC_TAG_ACCOUNTS::response& res, epee::json_rpc::error& er, const connection_context *ctx)
{
if (!m_wallet) return not_open(er);
+ CHECK_IF_BACKGROUND_SYNCING();
try
{
m_wallet->set_account_tag(req.accounts, req.tag);
@@ -746,6 +803,7 @@ namespace tools
bool wallet_rpc_server::on_untag_accounts(const wallet_rpc::COMMAND_RPC_UNTAG_ACCOUNTS::request& req, wallet_rpc::COMMAND_RPC_UNTAG_ACCOUNTS::response& res, epee::json_rpc::error& er, const connection_context *ctx)
{
if (!m_wallet) return not_open(er);
+ CHECK_IF_BACKGROUND_SYNCING();
try
{
m_wallet->set_account_tag(req.accounts, "");
@@ -761,6 +819,7 @@ namespace tools
bool wallet_rpc_server::on_set_account_tag_description(const wallet_rpc::COMMAND_RPC_SET_ACCOUNT_TAG_DESCRIPTION::request& req, wallet_rpc::COMMAND_RPC_SET_ACCOUNT_TAG_DESCRIPTION::response& res, epee::json_rpc::error& er, const connection_context *ctx)
{
if (!m_wallet) return not_open(er);
+ CHECK_IF_BACKGROUND_SYNCING();
try
{
m_wallet->set_account_tag_description(req.tag, req.description);
@@ -791,6 +850,7 @@ namespace tools
bool wallet_rpc_server::on_freeze(const wallet_rpc::COMMAND_RPC_FREEZE::request& req, wallet_rpc::COMMAND_RPC_FREEZE::response& res, epee::json_rpc::error& er, const connection_context *ctx)
{
if (!m_wallet) return not_open(er);
+ CHECK_IF_BACKGROUND_SYNCING();
try
{
if (req.key_image.empty())
@@ -819,6 +879,7 @@ namespace tools
bool wallet_rpc_server::on_thaw(const wallet_rpc::COMMAND_RPC_THAW::request& req, wallet_rpc::COMMAND_RPC_THAW::response& res, epee::json_rpc::error& er, const connection_context *ctx)
{
if (!m_wallet) return not_open(er);
+ CHECK_IF_BACKGROUND_SYNCING();
try
{
if (req.key_image.empty())
@@ -847,6 +908,7 @@ namespace tools
bool wallet_rpc_server::on_frozen(const wallet_rpc::COMMAND_RPC_FROZEN::request& req, wallet_rpc::COMMAND_RPC_FROZEN::response& res, epee::json_rpc::error& er, const connection_context *ctx)
{
if (!m_wallet) return not_open(er);
+ CHECK_IF_BACKGROUND_SYNCING();
try
{
if (req.key_image.empty())
@@ -874,6 +936,8 @@ namespace tools
//------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::validate_transfer(const std::list<wallet_rpc::transfer_destination>& destinations, const std::string& payment_id, std::vector<cryptonote::tx_destination_entry>& dsts, std::vector<uint8_t>& extra, bool at_least_one_destination, epee::json_rpc::error& er)
{
+ CHECK_IF_BACKGROUND_SYNCING();
+
crypto::hash8 integrated_payment_id = crypto::null_hash8;
std::string extra_nonce;
for (auto it = destinations.begin(); it != destinations.end(); it++)
@@ -1024,7 +1088,7 @@ namespace tools
fill(spent_key_images, key_image_list);
}
- if (m_wallet->multisig())
+ if (m_wallet->get_multisig_status().multisig_is_active)
{
multisig_txset = epee::string_tools::buff_to_hex_nodelimer(m_wallet->save_multisig_tx(ptx_vector));
if (multisig_txset.empty())
@@ -1079,6 +1143,12 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
+ else if (req.unlock_time)
+ {
+ er.code = WALLET_RPC_ERROR_CODE_NONZERO_UNLOCK_TIME;
+ er.message = "Transaction cannot have non-zero unlock time";
+ return false;
+ }
CHECK_MULTISIG_ENABLED();
@@ -1092,7 +1162,7 @@ namespace tools
{
uint64_t mixin = m_wallet->adjust_mixin(req.ring_size ? req.ring_size - 1 : 0);
uint32_t priority = m_wallet->adjust_priority(req.priority);
- std::vector<wallet2::pending_tx> ptx_vector = m_wallet->create_transactions_2(dsts, mixin, req.unlock_time, priority, extra, req.account_index, req.subaddr_indices, req.subtract_fee_from_outputs);
+ std::vector<wallet2::pending_tx> ptx_vector = m_wallet->create_transactions_2(dsts, mixin, priority, extra, req.account_index, req.subaddr_indices, req.subtract_fee_from_outputs);
if (ptx_vector.empty())
{
@@ -1133,6 +1203,12 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
+ else if (req.unlock_time)
+ {
+ er.code = WALLET_RPC_ERROR_CODE_NONZERO_UNLOCK_TIME;
+ er.message = "Transaction cannot have non-zero unlock time";
+ return false;
+ }
CHECK_MULTISIG_ENABLED();
@@ -1147,7 +1223,7 @@ namespace tools
uint64_t mixin = m_wallet->adjust_mixin(req.ring_size ? req.ring_size - 1 : 0);
uint32_t priority = m_wallet->adjust_priority(req.priority);
LOG_PRINT_L2("on_transfer_split calling create_transactions_2");
- std::vector<wallet2::pending_tx> ptx_vector = m_wallet->create_transactions_2(dsts, mixin, req.unlock_time, priority, extra, req.account_index, req.subaddr_indices);
+ std::vector<wallet2::pending_tx> ptx_vector = m_wallet->create_transactions_2(dsts, mixin, priority, extra, req.account_index, req.subaddr_indices);
LOG_PRINT_L2("on_transfer_split called create_transactions_2");
if (ptx_vector.empty())
@@ -1191,6 +1267,7 @@ namespace tools
}
CHECK_MULTISIG_ENABLED();
+ CHECK_IF_BACKGROUND_SYNCING();
cryptonote::blobdata blob;
if (!epee::string_tools::parse_hexstr_to_binbuff(req.unsigned_txset, blob))
@@ -1272,6 +1349,7 @@ namespace tools
er.message = "command not supported by watch-only wallet";
return false;
}
+ CHECK_IF_BACKGROUND_SYNCING();
if(req.unsigned_txset.empty() && req.multisig_txset.empty())
{
er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
@@ -1541,6 +1619,7 @@ namespace tools
}
CHECK_MULTISIG_ENABLED();
+ CHECK_IF_BACKGROUND_SYNCING();
try
{
@@ -1569,6 +1648,12 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
+ else if (req.unlock_time)
+ {
+ er.code = WALLET_RPC_ERROR_CODE_NONZERO_UNLOCK_TIME;
+ er.message = "Transaction cannot have non-zero unlock time";
+ return false;
+ }
CHECK_MULTISIG_ENABLED();
@@ -1604,7 +1689,7 @@ namespace tools
{
uint64_t mixin = m_wallet->adjust_mixin(req.ring_size ? req.ring_size - 1 : 0);
uint32_t priority = m_wallet->adjust_priority(req.priority);
- std::vector<wallet2::pending_tx> ptx_vector = m_wallet->create_transactions_all(req.below_amount, dsts[0].addr, dsts[0].is_subaddress, req.outputs, mixin, req.unlock_time, priority, extra, req.account_index, subaddr_indices);
+ std::vector<wallet2::pending_tx> ptx_vector = m_wallet->create_transactions_all(req.below_amount, dsts[0].addr, dsts[0].is_subaddress, req.outputs, mixin, priority, extra, req.account_index, subaddr_indices);
return fill_response(ptx_vector, req.get_tx_keys, res.tx_key_list, res.amount_list, res.amounts_by_dest_list, res.fee_list, res.weight_list, res.multisig_txset, res.unsigned_txset, req.do_not_relay,
res.tx_hash_list, req.get_tx_hex, res.tx_blob_list, req.get_tx_metadata, res.tx_metadata_list, res.spent_key_images_list, er);
@@ -1629,6 +1714,12 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
+ else if (req.unlock_time)
+ {
+ er.code = WALLET_RPC_ERROR_CODE_NONZERO_UNLOCK_TIME;
+ er.message = "Transaction cannot have non-zero unlock time";
+ return false;
+ }
if (req.outputs < 1)
{
@@ -1661,7 +1752,7 @@ namespace tools
{
uint64_t mixin = m_wallet->adjust_mixin(req.ring_size ? req.ring_size - 1 : 0);
uint32_t priority = m_wallet->adjust_priority(req.priority);
- std::vector<wallet2::pending_tx> ptx_vector = m_wallet->create_transactions_single(ki, dsts[0].addr, dsts[0].is_subaddress, req.outputs, mixin, req.unlock_time, priority, extra);
+ std::vector<wallet2::pending_tx> ptx_vector = m_wallet->create_transactions_single(ki, dsts[0].addr, dsts[0].is_subaddress, req.outputs, mixin, priority, extra);
if (ptx_vector.empty())
{
@@ -2066,10 +2157,11 @@ namespace tools
if (req.key_type.compare("mnemonic") == 0)
{
epee::wipeable_string seed;
- bool ready;
- if (m_wallet->multisig(&ready))
+ const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
+
+ if (ms_status.multisig_is_active)
{
- if (!ready)
+ if (!ms_status.is_ready)
{
er.code = WALLET_RPC_ERROR_CODE_NOT_MULTISIG;
er.message = "This wallet is multisig, but not yet finalized";
@@ -2090,6 +2182,7 @@ namespace tools
er.message = "The wallet is watch-only. Cannot retrieve seed.";
return false;
}
+ CHECK_IF_BACKGROUND_SYNCING();
if (!m_wallet->is_deterministic())
{
er.code = WALLET_RPC_ERROR_CODE_NON_DETERMINISTIC;
@@ -2118,6 +2211,7 @@ namespace tools
er.message = "The wallet is watch-only. Cannot retrieve spend key.";
return false;
}
+ CHECK_IF_BACKGROUND_SYNCING();
epee::wipeable_string key = epee::to_hex::wipeable_string(m_wallet->get_account().get_keys().m_spend_secret_key);
res.key = std::string(key.data(), key.size());
}
@@ -2139,6 +2233,7 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
+ CHECK_IF_BACKGROUND_SYNCING();
try
{
@@ -2152,6 +2247,79 @@ namespace tools
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
+ bool wallet_rpc_server::on_setup_background_sync(const wallet_rpc::COMMAND_RPC_SETUP_BACKGROUND_SYNC::request& req, wallet_rpc::COMMAND_RPC_SETUP_BACKGROUND_SYNC::response& res, epee::json_rpc::error& er, const connection_context *ctx)
+ {
+ try
+ {
+ PRE_VALIDATE_BACKGROUND_SYNC();
+ const tools::wallet2::BackgroundSyncType background_sync_type = tools::wallet2::background_sync_type_from_str(req.background_sync_type);
+ boost::optional<epee::wipeable_string> background_cache_password = boost::none;
+ if (background_sync_type == tools::wallet2::BackgroundSyncCustomPassword)
+ background_cache_password = boost::optional<epee::wipeable_string>(req.background_cache_password);
+ m_wallet->setup_background_sync(background_sync_type, req.wallet_password, background_cache_password);
+ }
+ catch (...)
+ {
+ handle_rpc_exception(std::current_exception(), er, WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR);
+ return false;
+ }
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
+ bool wallet_rpc_server::on_start_background_sync(const wallet_rpc::COMMAND_RPC_START_BACKGROUND_SYNC::request& req, wallet_rpc::COMMAND_RPC_START_BACKGROUND_SYNC::response& res, epee::json_rpc::error& er, const connection_context *ctx)
+ {
+ try
+ {
+ PRE_VALIDATE_BACKGROUND_SYNC();
+ m_wallet->start_background_sync();
+ }
+ catch (...)
+ {
+ handle_rpc_exception(std::current_exception(), er, WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR);
+ return false;
+ }
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
+ bool wallet_rpc_server::on_stop_background_sync(const wallet_rpc::COMMAND_RPC_STOP_BACKGROUND_SYNC::request& req, wallet_rpc::COMMAND_RPC_STOP_BACKGROUND_SYNC::response& res, epee::json_rpc::error& er, const connection_context *ctx)
+ {
+ try
+ {
+ PRE_VALIDATE_BACKGROUND_SYNC();
+ crypto::secret_key spend_secret_key = crypto::null_skey;
+
+ // Load the spend key from seed if seed is provided
+ if (!req.seed.empty())
+ {
+ crypto::secret_key recovery_key;
+ std::string language;
+
+ if (!crypto::ElectrumWords::words_to_bytes(req.seed, recovery_key, language))
+ {
+ er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
+ er.message = "Electrum-style word list failed verification";
+ return false;
+ }
+
+ if (!req.seed_offset.empty())
+ recovery_key = cryptonote::decrypt_key(recovery_key, req.seed_offset);
+
+ // generate spend key
+ cryptonote::account_base account;
+ account.generate(recovery_key, true, false);
+ spend_secret_key = account.get_keys().m_spend_secret_key;
+ }
+
+ m_wallet->stop_background_sync(req.wallet_password, spend_secret_key);
+ }
+ catch (...)
+ {
+ handle_rpc_exception(std::current_exception(), er, WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR);
+ return false;
+ }
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_sign(const wallet_rpc::COMMAND_RPC_SIGN::request& req, wallet_rpc::COMMAND_RPC_SIGN::response& res, epee::json_rpc::error& er, const connection_context *ctx)
{
if (!m_wallet) return not_open(er);
@@ -2161,6 +2329,7 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
+ CHECK_IF_BACKGROUND_SYNCING();
tools::wallet2::message_signature_type_t signature_type = tools::wallet2::sign_with_spend_key;
if (req.signature_type == "spend" || req.signature_type == "")
@@ -2253,6 +2422,7 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
+ CHECK_IF_BACKGROUND_SYNCING();
if (req.txids.size() != req.notes.size())
{
@@ -2325,6 +2495,7 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
+ CHECK_IF_BACKGROUND_SYNCING();
m_wallet->set_attribute(req.key, req.value);
@@ -2352,6 +2523,7 @@ namespace tools
bool wallet_rpc_server::on_get_tx_key(const wallet_rpc::COMMAND_RPC_GET_TX_KEY::request& req, wallet_rpc::COMMAND_RPC_GET_TX_KEY::response& res, epee::json_rpc::error& er, const connection_context *ctx)
{
if (!m_wallet) return not_open(er);
+ CHECK_IF_BACKGROUND_SYNCING();
crypto::hash txid;
if (!epee::string_tools::hex_to_pod(req.txid, txid))
@@ -2443,6 +2615,7 @@ namespace tools
bool wallet_rpc_server::on_get_tx_proof(const wallet_rpc::COMMAND_RPC_GET_TX_PROOF::request& req, wallet_rpc::COMMAND_RPC_GET_TX_PROOF::response& res, epee::json_rpc::error& er, const connection_context *ctx)
{
if (!m_wallet) return not_open(er);
+ CHECK_IF_BACKGROUND_SYNCING();
crypto::hash txid;
if (!epee::string_tools::hex_to_pod(req.txid, txid))
@@ -2559,6 +2732,7 @@ namespace tools
bool wallet_rpc_server::on_get_reserve_proof(const wallet_rpc::COMMAND_RPC_GET_RESERVE_PROOF::request& req, wallet_rpc::COMMAND_RPC_GET_RESERVE_PROOF::response& res, epee::json_rpc::error& er, const connection_context *ctx)
{
if (!m_wallet) return not_open(er);
+ CHECK_IF_BACKGROUND_SYNCING();
boost::optional<std::pair<uint32_t, uint64_t>> account_minreserve;
if (!req.all)
@@ -2801,6 +2975,7 @@ namespace tools
er.message = "command not supported by HW wallet";
return false;
}
+ CHECK_IF_BACKGROUND_SYNCING();
try
{
@@ -2830,6 +3005,7 @@ namespace tools
er.message = "command not supported by HW wallet";
return false;
}
+ CHECK_IF_BACKGROUND_SYNCING();
cryptonote::blobdata blob;
if (!epee::string_tools::parse_hexstr_to_binbuff(req.outputs_data_hex, blob))
@@ -2855,6 +3031,7 @@ namespace tools
bool wallet_rpc_server::on_export_key_images(const wallet_rpc::COMMAND_RPC_EXPORT_KEY_IMAGES::request& req, wallet_rpc::COMMAND_RPC_EXPORT_KEY_IMAGES::response& res, epee::json_rpc::error& er, const connection_context *ctx)
{
if (!m_wallet) return not_open(er);
+ CHECK_IF_BACKGROUND_SYNCING();
try
{
std::pair<uint64_t, std::vector<std::pair<crypto::key_image, crypto::signature>>> ski = m_wallet->export_key_images(req.all);
@@ -2891,6 +3068,7 @@ namespace tools
er.message = "This command requires a trusted daemon.";
return false;
}
+ CHECK_IF_BACKGROUND_SYNCING();
try
{
std::vector<std::pair<crypto::key_image, crypto::signature>> ski;
@@ -2959,6 +3137,7 @@ namespace tools
bool wallet_rpc_server::on_get_address_book(const wallet_rpc::COMMAND_RPC_GET_ADDRESS_BOOK_ENTRY::request& req, wallet_rpc::COMMAND_RPC_GET_ADDRESS_BOOK_ENTRY::response& res, epee::json_rpc::error& er, const connection_context *ctx)
{
if (!m_wallet) return not_open(er);
+ CHECK_IF_BACKGROUND_SYNCING();
const auto ab = m_wallet->get_address_book();
if (req.entries.empty())
{
@@ -3004,6 +3183,7 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
+ CHECK_IF_BACKGROUND_SYNCING();
cryptonote::address_parse_info info;
er.message = "";
@@ -3046,6 +3226,7 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
+ CHECK_IF_BACKGROUND_SYNCING();
const auto ab = m_wallet->get_address_book();
if (req.index >= ab.size())
@@ -3108,6 +3289,7 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
+ CHECK_IF_BACKGROUND_SYNCING();
const auto ab = m_wallet->get_address_book();
if (req.index >= ab.size())
@@ -3178,6 +3360,7 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
+ CHECK_IF_BACKGROUND_SYNCING();
std::unordered_set<crypto::hash> txids;
std::list<std::string>::const_iterator i = req.txids.begin();
@@ -3217,6 +3400,7 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
+ CHECK_IF_BACKGROUND_SYNCING();
try
{
m_wallet->rescan_spent();
@@ -3481,6 +3665,7 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
+ CHECK_IF_BACKGROUND_SYNCING();
if (m_wallet->verify_password(req.old_password))
{
try
@@ -3979,7 +4164,14 @@ namespace tools
bool wallet_rpc_server::on_is_multisig(const wallet_rpc::COMMAND_RPC_IS_MULTISIG::request& req, wallet_rpc::COMMAND_RPC_IS_MULTISIG::response& res, epee::json_rpc::error& er, const connection_context *ctx)
{
if (!m_wallet) return not_open(er);
- res.multisig = m_wallet->multisig(&res.ready, &res.threshold, &res.total);
+ const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
+
+ res.multisig = ms_status.multisig_is_active;
+ res.kex_is_done = ms_status.kex_is_done;
+ res.ready = ms_status.is_ready;
+ res.threshold = ms_status.threshold;
+ res.total = ms_status.total;
+
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
@@ -3992,7 +4184,7 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
- if (m_wallet->multisig())
+ if (m_wallet->get_multisig_status().multisig_is_active)
{
er.code = WALLET_RPC_ERROR_CODE_ALREADY_MULTISIG;
er.message = "This wallet is already multisig";
@@ -4007,6 +4199,7 @@ namespace tools
er.message = "wallet is watch-only and cannot be made multisig";
return false;
}
+ CHECK_IF_BACKGROUND_SYNCING();
res.multisig_info = m_wallet->get_multisig_first_kex_msg();
return true;
@@ -4021,7 +4214,7 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
- if (m_wallet->multisig())
+ if (m_wallet->get_multisig_status().multisig_is_active)
{
er.code = WALLET_RPC_ERROR_CODE_ALREADY_MULTISIG;
er.message = "This wallet is already multisig";
@@ -4034,6 +4227,7 @@ namespace tools
er.message = "wallet is watch-only and cannot be made multisig";
return false;
}
+ CHECK_IF_BACKGROUND_SYNCING();
try
{
@@ -4059,14 +4253,15 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
- bool ready;
- if (!m_wallet->multisig(&ready))
+ const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
+
+ if (!ms_status.multisig_is_active)
{
er.code = WALLET_RPC_ERROR_CODE_NOT_MULTISIG;
er.message = "This wallet is not multisig";
return false;
}
- if (!ready)
+ if (!ms_status.is_ready)
{
er.code = WALLET_RPC_ERROR_CODE_NOT_MULTISIG;
er.message = "This wallet is multisig, but not yet finalized";
@@ -4100,15 +4295,15 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
- bool ready;
- uint32_t threshold, total;
- if (!m_wallet->multisig(&ready, &threshold, &total))
+ const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
+
+ if (!ms_status.multisig_is_active)
{
er.code = WALLET_RPC_ERROR_CODE_NOT_MULTISIG;
er.message = "This wallet is not multisig";
return false;
}
- if (!ready)
+ if (!ms_status.is_ready)
{
er.code = WALLET_RPC_ERROR_CODE_NOT_MULTISIG;
er.message = "This wallet is multisig, but not yet finalized";
@@ -4116,7 +4311,7 @@ namespace tools
}
CHECK_MULTISIG_ENABLED();
- if (req.info.size() < threshold - 1)
+ if (req.info.size() + 1 < ms_status.threshold)
{
er.code = WALLET_RPC_ERROR_CODE_THRESHOLD_NOT_REACHED;
er.message = "Needs multisig export info from more participants";
@@ -4180,9 +4375,9 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
- bool ready;
- uint32_t threshold, total;
- if (!m_wallet->multisig(&ready, &threshold, &total))
+ multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
+
+ if (!ms_status.multisig_is_active)
{
er.code = WALLET_RPC_ERROR_CODE_NOT_MULTISIG;
er.message = "This wallet is not multisig";
@@ -4190,7 +4385,7 @@ namespace tools
}
CHECK_MULTISIG_ENABLED();
- if (req.multisig_info.size() + 1 < total)
+ if (req.multisig_info.size() + 1 < ms_status.total)
{
er.code = WALLET_RPC_ERROR_CODE_THRESHOLD_NOT_REACHED;
er.message = "Needs multisig info from more participants";
@@ -4200,8 +4395,8 @@ namespace tools
try
{
res.multisig_info = m_wallet->exchange_multisig_keys(req.password, req.multisig_info, req.force_update_use_with_caution);
- m_wallet->multisig(&ready);
- if (ready)
+ ms_status = m_wallet->get_multisig_status();
+ if (ms_status.is_ready)
{
res.address = m_wallet->get_account().get_public_address_str(m_wallet->nettype());
}
@@ -4215,6 +4410,47 @@ namespace tools
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
+ bool wallet_rpc_server::on_get_multisig_key_exchange_booster(const wallet_rpc::COMMAND_RPC_GET_MULTISIG_KEY_EXCHANGE_BOOSTER::request& req, wallet_rpc::COMMAND_RPC_GET_MULTISIG_KEY_EXCHANGE_BOOSTER::response& res, epee::json_rpc::error& er, const connection_context *ctx)
+ {
+ if (!m_wallet) return not_open(er);
+ if (m_restricted)
+ {
+ er.code = WALLET_RPC_ERROR_CODE_DENIED;
+ er.message = "Command unavailable in restricted mode.";
+ return false;
+ }
+ const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
+
+ if (ms_status.is_ready)
+ {
+ er.code = WALLET_RPC_ERROR_CODE_ALREADY_MULTISIG;
+ er.message = "This wallet is multisig, and already finalized";
+ return false;
+ }
+
+ if (req.multisig_info.size() == 0)
+ {
+ er.code = WALLET_RPC_ERROR_CODE_THRESHOLD_NOT_REACHED;
+ er.message = "Needs multisig info from more participants";
+ return false;
+ }
+
+ try
+ {
+ res.multisig_info = m_wallet->get_multisig_key_exchange_booster(req.password,
+ req.multisig_info,
+ req.threshold,
+ req.num_signers);
+ }
+ catch (const std::exception &e)
+ {
+ er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
+ er.message = std::string("Error calling exchange_multisig_info_booster: ") + e.what();
+ return false;
+ }
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_sign_multisig(const wallet_rpc::COMMAND_RPC_SIGN_MULTISIG::request& req, wallet_rpc::COMMAND_RPC_SIGN_MULTISIG::response& res, epee::json_rpc::error& er, const connection_context *ctx)
{
if (!m_wallet) return not_open(er);
@@ -4224,15 +4460,15 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
- bool ready;
- uint32_t threshold, total;
- if (!m_wallet->multisig(&ready, &threshold, &total))
+ const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
+
+ if (!ms_status.multisig_is_active)
{
er.code = WALLET_RPC_ERROR_CODE_NOT_MULTISIG;
er.message = "This wallet is not multisig";
return false;
}
- if (!ready)
+ if (!ms_status.is_ready)
{
er.code = WALLET_RPC_ERROR_CODE_NOT_MULTISIG;
er.message = "This wallet is multisig, but not yet finalized";
@@ -4294,15 +4530,15 @@ namespace tools
er.message = "Command unavailable in restricted mode.";
return false;
}
- bool ready;
- uint32_t threshold, total;
- if (!m_wallet->multisig(&ready, &threshold, &total))
+ const multisig::multisig_account_status ms_status{m_wallet->get_multisig_status()};
+
+ if (!ms_status.multisig_is_active)
{
er.code = WALLET_RPC_ERROR_CODE_NOT_MULTISIG;
er.message = "This wallet is not multisig";
return false;
}
- if (!ready)
+ if (!ms_status.is_ready)
{
er.code = WALLET_RPC_ERROR_CODE_NOT_MULTISIG;
er.message = "This wallet is multisig, but not yet finalized";
@@ -4327,7 +4563,7 @@ namespace tools
return false;
}
- if (txs.m_signers.size() < threshold)
+ if (txs.m_signers.size() < ms_status.threshold)
{
er.code = WALLET_RPC_ERROR_CODE_THRESHOLD_NOT_REACHED;
er.message = "Not enough signers signed this transaction.";
diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h
index bfb7013e2..954316b52 100644
--- a/src/wallet/wallet_rpc_server.h
+++ b/src/wallet/wallet_rpc_server.h
@@ -151,6 +151,7 @@ namespace tools
MAP_JON_RPC_WE("import_multisig_info", on_import_multisig, wallet_rpc::COMMAND_RPC_IMPORT_MULTISIG)
MAP_JON_RPC_WE("finalize_multisig", on_finalize_multisig, wallet_rpc::COMMAND_RPC_FINALIZE_MULTISIG)
MAP_JON_RPC_WE("exchange_multisig_keys", on_exchange_multisig_keys, wallet_rpc::COMMAND_RPC_EXCHANGE_MULTISIG_KEYS)
+ MAP_JON_RPC_WE("get_multisig_key_exchange_booster", on_get_multisig_key_exchange_booster, wallet_rpc::COMMAND_RPC_GET_MULTISIG_KEY_EXCHANGE_BOOSTER)
MAP_JON_RPC_WE("sign_multisig", on_sign_multisig, wallet_rpc::COMMAND_RPC_SIGN_MULTISIG)
MAP_JON_RPC_WE("submit_multisig", on_submit_multisig, wallet_rpc::COMMAND_RPC_SUBMIT_MULTISIG)
MAP_JON_RPC_WE("validate_address", on_validate_address, wallet_rpc::COMMAND_RPC_VALIDATE_ADDRESS)
@@ -159,6 +160,9 @@ namespace tools
MAP_JON_RPC_WE("set_log_categories", on_set_log_categories, wallet_rpc::COMMAND_RPC_SET_LOG_CATEGORIES)
MAP_JON_RPC_WE("estimate_tx_size_and_weight", on_estimate_tx_size_and_weight, wallet_rpc::COMMAND_RPC_ESTIMATE_TX_SIZE_AND_WEIGHT)
MAP_JON_RPC_WE("get_version", on_get_version, wallet_rpc::COMMAND_RPC_GET_VERSION)
+ MAP_JON_RPC_WE("setup_background_sync", on_setup_background_sync, wallet_rpc::COMMAND_RPC_SETUP_BACKGROUND_SYNC)
+ MAP_JON_RPC_WE("start_background_sync", on_start_background_sync, wallet_rpc::COMMAND_RPC_START_BACKGROUND_SYNC)
+ MAP_JON_RPC_WE("stop_background_sync", on_stop_background_sync, wallet_rpc::COMMAND_RPC_STOP_BACKGROUND_SYNC)
END_JSON_RPC_MAP()
END_URI_MAP2()
@@ -242,6 +246,7 @@ namespace tools
bool on_import_multisig(const wallet_rpc::COMMAND_RPC_IMPORT_MULTISIG::request& req, wallet_rpc::COMMAND_RPC_IMPORT_MULTISIG::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
bool on_finalize_multisig(const wallet_rpc::COMMAND_RPC_FINALIZE_MULTISIG::request& req, wallet_rpc::COMMAND_RPC_FINALIZE_MULTISIG::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
bool on_exchange_multisig_keys(const wallet_rpc::COMMAND_RPC_EXCHANGE_MULTISIG_KEYS::request& req, wallet_rpc::COMMAND_RPC_EXCHANGE_MULTISIG_KEYS::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
+ bool on_get_multisig_key_exchange_booster(const wallet_rpc::COMMAND_RPC_GET_MULTISIG_KEY_EXCHANGE_BOOSTER::request& req, wallet_rpc::COMMAND_RPC_GET_MULTISIG_KEY_EXCHANGE_BOOSTER::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
bool on_sign_multisig(const wallet_rpc::COMMAND_RPC_SIGN_MULTISIG::request& req, wallet_rpc::COMMAND_RPC_SIGN_MULTISIG::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
bool on_submit_multisig(const wallet_rpc::COMMAND_RPC_SUBMIT_MULTISIG::request& req, wallet_rpc::COMMAND_RPC_SUBMIT_MULTISIG::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
bool on_validate_address(const wallet_rpc::COMMAND_RPC_VALIDATE_ADDRESS::request& req, wallet_rpc::COMMAND_RPC_VALIDATE_ADDRESS::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
@@ -250,6 +255,9 @@ namespace tools
bool on_set_log_categories(const wallet_rpc::COMMAND_RPC_SET_LOG_CATEGORIES::request& req, wallet_rpc::COMMAND_RPC_SET_LOG_CATEGORIES::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
bool on_estimate_tx_size_and_weight(const wallet_rpc::COMMAND_RPC_ESTIMATE_TX_SIZE_AND_WEIGHT::request& req, wallet_rpc::COMMAND_RPC_ESTIMATE_TX_SIZE_AND_WEIGHT::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
bool on_get_version(const wallet_rpc::COMMAND_RPC_GET_VERSION::request& req, wallet_rpc::COMMAND_RPC_GET_VERSION::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
+ bool on_setup_background_sync(const wallet_rpc::COMMAND_RPC_SETUP_BACKGROUND_SYNC::request& req, wallet_rpc::COMMAND_RPC_SETUP_BACKGROUND_SYNC::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
+ bool on_start_background_sync(const wallet_rpc::COMMAND_RPC_START_BACKGROUND_SYNC::request& req, wallet_rpc::COMMAND_RPC_START_BACKGROUND_SYNC::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
+ bool on_stop_background_sync(const wallet_rpc::COMMAND_RPC_STOP_BACKGROUND_SYNC::request& req, wallet_rpc::COMMAND_RPC_STOP_BACKGROUND_SYNC::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
//json rpc v2
bool on_query_key(const wallet_rpc::COMMAND_RPC_QUERY_KEY::request& req, wallet_rpc::COMMAND_RPC_QUERY_KEY::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
diff --git a/src/wallet/wallet_rpc_server_commands_defs.h b/src/wallet/wallet_rpc_server_commands_defs.h
index f9f534097..816004ccb 100644
--- a/src/wallet/wallet_rpc_server_commands_defs.h
+++ b/src/wallet/wallet_rpc_server_commands_defs.h
@@ -2323,12 +2323,14 @@ namespace wallet_rpc
struct response_t
{
bool multisig;
+ bool kex_is_done;
bool ready;
uint32_t threshold;
uint32_t total;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(multisig)
+ KV_SERIALIZE(kex_is_done)
KV_SERIALIZE(ready)
KV_SERIALIZE(threshold)
KV_SERIALIZE(total)
@@ -2479,6 +2481,35 @@ namespace wallet_rpc
typedef epee::misc_utils::struct_init<response_t> response;
};
+ struct COMMAND_RPC_GET_MULTISIG_KEY_EXCHANGE_BOOSTER
+ {
+ struct request_t
+ {
+ std::string password;
+ std::vector<std::string> multisig_info;
+ uint32_t threshold;
+ uint32_t num_signers;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(password)
+ KV_SERIALIZE(multisig_info)
+ KV_SERIALIZE(threshold)
+ KV_SERIALIZE(num_signers)
+ END_KV_SERIALIZE_MAP()
+ };
+ typedef epee::misc_utils::struct_init<request_t> request;
+
+ struct response_t
+ {
+ std::string multisig_info;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(multisig_info)
+ END_KV_SERIALIZE_MAP()
+ };
+ typedef epee::misc_utils::struct_init<response_t> response;
+ };
+
struct COMMAND_RPC_SIGN_MULTISIG
{
struct request_t
@@ -2698,5 +2729,69 @@ namespace wallet_rpc
typedef epee::misc_utils::struct_init<response_t> response;
};
+ struct COMMAND_RPC_SETUP_BACKGROUND_SYNC
+ {
+ struct request_t
+ {
+ std::string background_sync_type;
+ std::string wallet_password;
+ std::string background_cache_password;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(background_sync_type)
+ KV_SERIALIZE(wallet_password)
+ KV_SERIALIZE_OPT(background_cache_password, (std::string)"")
+ END_KV_SERIALIZE_MAP()
+ };
+ typedef epee::misc_utils::struct_init<request_t> request;
+
+ struct response_t
+ {
+ BEGIN_KV_SERIALIZE_MAP()
+ END_KV_SERIALIZE_MAP()
+ };
+ typedef epee::misc_utils::struct_init<response_t> response;
+ };
+
+ struct COMMAND_RPC_START_BACKGROUND_SYNC
+ {
+ struct request_t
+ {
+ BEGIN_KV_SERIALIZE_MAP()
+ END_KV_SERIALIZE_MAP()
+ };
+ typedef epee::misc_utils::struct_init<request_t> request;
+
+ struct response_t
+ {
+ BEGIN_KV_SERIALIZE_MAP()
+ END_KV_SERIALIZE_MAP()
+ };
+ typedef epee::misc_utils::struct_init<response_t> response;
+ };
+
+ struct COMMAND_RPC_STOP_BACKGROUND_SYNC
+ {
+ struct request_t
+ {
+ std::string wallet_password;
+ std::string seed;
+ std::string seed_offset;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(wallet_password)
+ KV_SERIALIZE_OPT(seed, (std::string)"")
+ KV_SERIALIZE_OPT(seed_offset, (std::string)"")
+ END_KV_SERIALIZE_MAP()
+ };
+ typedef epee::misc_utils::struct_init<request_t> request;
+
+ struct response_t
+ {
+ BEGIN_KV_SERIALIZE_MAP()
+ END_KV_SERIALIZE_MAP()
+ };
+ typedef epee::misc_utils::struct_init<response_t> response;
+ };
}
}
diff --git a/src/wallet/wallet_rpc_server_error_codes.h b/src/wallet/wallet_rpc_server_error_codes.h
index 2988f52ad..8b0797b41 100644
--- a/src/wallet/wallet_rpc_server_error_codes.h
+++ b/src/wallet/wallet_rpc_server_error_codes.h
@@ -80,3 +80,6 @@
#define WALLET_RPC_ERROR_CODE_INVALID_SIGNATURE_TYPE -47
#define WALLET_RPC_ERROR_CODE_DISABLED -48
#define WALLET_RPC_ERROR_CODE_PROXY_ALREADY_DEFINED -49
+#define WALLET_RPC_ERROR_CODE_NONZERO_UNLOCK_TIME -50
+#define WALLET_RPC_ERROR_CODE_IS_BACKGROUND_WALLET -51
+#define WALLET_RPC_ERROR_CODE_IS_BACKGROUND_SYNCING -52
diff --git a/tests/block_weight/block_weight.cpp b/tests/block_weight/block_weight.cpp
index 4b00fc63f..676d56006 100644
--- a/tests/block_weight/block_weight.cpp
+++ b/tests/block_weight/block_weight.cpp
@@ -138,7 +138,7 @@ static uint32_t lcg()
static void test(test_t t, uint64_t blocks)
{
- PREFIX(10);
+ PREFIX(HF_VERSION_2021_SCALING);
for (uint64_t h = 0; h < LONG_TERM_BLOCK_WEIGHT_WINDOW; ++h)
{
@@ -177,8 +177,8 @@ static void test(test_t t, uint64_t blocks)
}
uint64_t ltw = bc->get_next_long_term_block_weight(w);
cryptonote::block b;
- b.major_version = 10;
- b.minor_version = 10;
+ b.major_version = HF_VERSION_2021_SCALING;
+ b.minor_version = HF_VERSION_2021_SCALING;
bc->get_db().add_block(std::make_pair(std::move(b), ""), w, ltw, bc->get_db().height(), bc->get_db().height(), {});
if (!bc->update_next_cumulative_weight_limit())
diff --git a/tests/block_weight/block_weight.py b/tests/block_weight/block_weight.py
index 5ec09896d..cfd0900fb 100755
--- a/tests/block_weight/block_weight.py
+++ b/tests/block_weight/block_weight.py
@@ -18,14 +18,20 @@ ltembw = MEDIAN_THRESHOLD
weights = [MEDIAN_THRESHOLD]*MEDIAN_WINDOW_SMALL # weights of recent blocks (B), with index -1 most recent
lt_weights = [MEDIAN_THRESHOLD]*MEDIAN_WINDOW_BIG # long-term weights
+# see contrib/epee/include/misc_language.h, get_mid
+def get_mid(a, b):
+ return (a//2) + (b//2) + ((a - 2*(a//2)) + (b - 2*(b//2)))//2;
+
# Compute the median of a list
def get_median(vec):
- #temp = vec
+ if len(vec) == 1:
+ return vec[0]
temp = sorted(vec)
+ n = len(temp) // 2
if len(temp) % 2 == 1:
- return temp[len(temp)//2]
+ return temp[n]
else:
- return int((temp[len(temp)//2]+temp[len(temp)//2-1])//2)
+ return get_mid(temp[n-1], temp[n])
def LCG():
global lcg_seed
@@ -46,7 +52,7 @@ def run(t, blocks):
# determine the effective weight
stmedian = get_median(weights[-MEDIAN_WINDOW_SMALL:])
- embw = min(max(MEDIAN_THRESHOLD,stmedian),int(MULTIPLIER_BIG*ltembw))
+ embw = min(max(ltembw,stmedian),int(MULTIPLIER_BIG*ltembw))
# drop the lowest values
weights = weights[1:]
@@ -64,7 +70,7 @@ def run(t, blocks):
else:
sys.exit(1)
weights.append(max_weight)
- lt_weights.append(min(max_weight,int(ltembw + int(ltembw * 2 / 5))))
+ lt_weights.append(min(max(max_weight, ltembw * 10 // 17),int(ltembw + int(ltembw * 7 / 10))))
#print "H %u, r %u, BW %u, EMBW %u, LTBW %u, LTEMBW %u, ltmedian %u" % (block, r, max_weight, embw, lt_weights[-1], ltembw, ltmedian)
print("H %u, BW %u, EMBW %u, LTBW %u" % (block, max_weight, embw, lt_weights[-1]))
diff --git a/tests/core_tests/block_validation.cpp b/tests/core_tests/block_validation.cpp
index 071d2198e..fd5ab5a7f 100644
--- a/tests/core_tests/block_validation.cpp
+++ b/tests/core_tests/block_validation.cpp
@@ -350,7 +350,7 @@ bool gen_block_miner_tx_has_2_in::generate(std::vector<test_event_entry>& events
destinations.push_back(de);
transaction tmp_tx;
- if (!construct_tx(miner_account.get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tmp_tx, 0))
+ if (!construct_tx(miner_account.get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tmp_tx))
return false;
MAKE_MINER_TX_MANUALLY(miner_tx, blk_0);
@@ -393,7 +393,7 @@ bool gen_block_miner_tx_with_txin_to_key::generate(std::vector<test_event_entry>
destinations.push_back(de);
transaction tmp_tx;
- if (!construct_tx(miner_account.get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tmp_tx, 0))
+ if (!construct_tx(miner_account.get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tmp_tx))
return false;
MAKE_MINER_TX_MANUALLY(miner_tx, blk_1);
diff --git a/tests/core_tests/bulletproof_plus.cpp b/tests/core_tests/bulletproof_plus.cpp
index ece03dd77..742670063 100644
--- a/tests/core_tests/bulletproof_plus.cpp
+++ b/tests/core_tests/bulletproof_plus.cpp
@@ -136,7 +136,7 @@ bool gen_bpp_tx_validation_base::generate_with(std::vector<test_event_entry>& ev
std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
subaddresses[miner_accounts[n].get_keys().m_account_address.m_spend_public_key] = {0,0};
rct_txes.resize(rct_txes.size() + 1);
- bool r = construct_tx_and_get_tx_key(miner_accounts[n].get_keys(), subaddresses, sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), rct_txes.back(), 0, tx_key, additional_tx_keys, true, rct_config[n]);
+ bool r = construct_tx_and_get_tx_key(miner_accounts[n].get_keys(), subaddresses, sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), rct_txes.back(), tx_key, additional_tx_keys, true, rct_config[n]);
CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction");
if (post_tx && !post_tx(rct_txes.back(), n))
diff --git a/tests/core_tests/bulletproofs.cpp b/tests/core_tests/bulletproofs.cpp
index f875edf74..278bf46a2 100644
--- a/tests/core_tests/bulletproofs.cpp
+++ b/tests/core_tests/bulletproofs.cpp
@@ -136,7 +136,7 @@ bool gen_bp_tx_validation_base::generate_with(std::vector<test_event_entry>& eve
std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
subaddresses[miner_accounts[n].get_keys().m_account_address.m_spend_public_key] = {0,0};
rct_txes.resize(rct_txes.size() + 1);
- bool r = construct_tx_and_get_tx_key(miner_accounts[n].get_keys(), subaddresses, sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), rct_txes.back(), 0, tx_key, additional_tx_keys, true, rct_config[n]);
+ bool r = construct_tx_and_get_tx_key(miner_accounts[n].get_keys(), subaddresses, sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), rct_txes.back(), tx_key, additional_tx_keys, true, rct_config[n]);
CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction");
if (post_tx && !post_tx(rct_txes.back(), n))
diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp
index 9aa0de8e5..8b2c2a577 100644
--- a/tests/core_tests/chaingen.cpp
+++ b/tests/core_tests/chaingen.cpp
@@ -1043,7 +1043,7 @@ bool construct_tx_to_key(const std::vector<test_event_entry>& events, cryptonote
vector<tx_destination_entry> destinations;
fill_tx_sources_and_destinations(events, blk_head, from, get_address(to), amount, fee, nmix, sources, destinations, check_unlock_time, fnc_tx_in_accept);
- return construct_tx_rct(from.get_keys(), sources, destinations, from.get_keys().m_account_address, std::vector<uint8_t>(), tx, 0, rct, range_proof_type, bp_version);
+ return construct_tx_rct(from.get_keys(), sources, destinations, from.get_keys().m_account_address, std::vector<uint8_t>(), tx, rct, range_proof_type, bp_version);
}
bool construct_tx_to_key(const std::vector<test_event_entry>& events, cryptonote::transaction& tx, const cryptonote::block& blk_head,
@@ -1060,7 +1060,7 @@ bool construct_tx_to_key(const std::vector<test_event_entry>& events, cryptonote
fill_tx_destinations(from, destinations, fee, sources, destinations_all, false);
- return construct_tx_rct(from.get_keys(), sources, destinations_all, get_address(from), std::vector<uint8_t>(), tx, 0, rct, range_proof_type, bp_version);
+ return construct_tx_rct(from.get_keys(), sources, destinations_all, get_address(from), std::vector<uint8_t>(), tx, rct, range_proof_type, bp_version);
}
bool construct_tx_to_key(cryptonote::transaction& tx,
@@ -1070,7 +1070,7 @@ bool construct_tx_to_key(cryptonote::transaction& tx,
{
vector<tx_destination_entry> destinations;
fill_tx_destinations(from, get_address(to), amount, fee, sources, destinations, rct);
- return construct_tx_rct(from.get_keys(), sources, destinations, get_address(from), std::vector<uint8_t>(), tx, 0, rct, range_proof_type, bp_version);
+ return construct_tx_rct(from.get_keys(), sources, destinations, get_address(from), std::vector<uint8_t>(), tx, rct, range_proof_type, bp_version);
}
bool construct_tx_to_key(cryptonote::transaction& tx,
@@ -1081,10 +1081,10 @@ bool construct_tx_to_key(cryptonote::transaction& tx,
{
vector<tx_destination_entry> all_destinations;
fill_tx_destinations(from, destinations, fee, sources, all_destinations, rct);
- return construct_tx_rct(from.get_keys(), sources, all_destinations, get_address(from), std::vector<uint8_t>(), tx, 0, rct, range_proof_type, bp_version);
+ return construct_tx_rct(from.get_keys(), sources, all_destinations, get_address(from), std::vector<uint8_t>(), tx, rct, range_proof_type, bp_version);
}
-bool construct_tx_rct(const cryptonote::account_keys& sender_account_keys, std::vector<cryptonote::tx_source_entry>& sources, const std::vector<cryptonote::tx_destination_entry>& destinations, const boost::optional<cryptonote::account_public_address>& change_addr, std::vector<uint8_t> extra, cryptonote::transaction& tx, uint64_t unlock_time, bool rct, rct::RangeProofType range_proof_type, int bp_version)
+bool construct_tx_rct(const cryptonote::account_keys& sender_account_keys, std::vector<cryptonote::tx_source_entry>& sources, const std::vector<cryptonote::tx_destination_entry>& destinations, const boost::optional<cryptonote::account_public_address>& change_addr, std::vector<uint8_t> extra, cryptonote::transaction& tx, bool rct, rct::RangeProofType range_proof_type, int bp_version)
{
std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
subaddresses[sender_account_keys.m_account_address.m_spend_public_key] = {0, 0};
@@ -1092,7 +1092,7 @@ bool construct_tx_rct(const cryptonote::account_keys& sender_account_keys, std::
std::vector<crypto::secret_key> additional_tx_keys;
std::vector<tx_destination_entry> destinations_copy = destinations;
rct::RCTConfig rct_config = {range_proof_type, bp_version};
- return construct_tx_and_get_tx_key(sender_account_keys, subaddresses, sources, destinations_copy, change_addr, extra, tx, unlock_time, tx_key, additional_tx_keys, rct, rct_config);
+ return construct_tx_and_get_tx_key(sender_account_keys, subaddresses, sources, destinations_copy, change_addr, extra, tx, tx_key, additional_tx_keys, rct, rct_config);
}
transaction construct_tx_with_fee(std::vector<test_event_entry>& events, const block& blk_head,
diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h
index 41f7275d3..0a1eb232d 100644
--- a/tests/core_tests/chaingen.h
+++ b/tests/core_tests/chaingen.h
@@ -472,7 +472,7 @@ bool construct_tx_rct(const cryptonote::account_keys& sender_account_keys,
std::vector<cryptonote::tx_source_entry>& sources,
const std::vector<cryptonote::tx_destination_entry>& destinations,
const boost::optional<cryptonote::account_public_address>& change_addr,
- std::vector<uint8_t> extra, cryptonote::transaction& tx, uint64_t unlock_time,
+ std::vector<uint8_t> extra, cryptonote::transaction& tx,
bool rct=false, rct::RangeProofType range_proof_type=rct::RangeProofBorromean, int bp_version = 0);
diff --git a/tests/core_tests/chaingen_serialization.h b/tests/core_tests/chaingen_serialization.h
index 7eac3987f..5a43e970e 100644
--- a/tests/core_tests/chaingen_serialization.h
+++ b/tests/core_tests/chaingen_serialization.h
@@ -35,6 +35,7 @@
#include <boost/archive/portable_binary_iarchive.hpp>
#include <boost/filesystem/operations.hpp>
+#include "common/util.h"
namespace tools
{
@@ -110,7 +111,7 @@ namespace tools
catch(...)
{
// if failed, try reading in unportable mode
- boost::filesystem::copy_file(file_path, file_path + ".unportable", boost::filesystem::copy_option::overwrite_if_exists);
+ tools::copy_file(file_path, file_path + ".unportable");
data_file.close();
data_file.open( file_path, std::ios_base::binary | std::ios_base::in);
if(data_file.fail())
diff --git a/tests/core_tests/double_spend.inl b/tests/core_tests/double_spend.inl
index b6e3726cc..5ccf4de98 100644
--- a/tests/core_tests/double_spend.inl
+++ b/tests/core_tests/double_spend.inl
@@ -138,7 +138,7 @@ bool gen_double_spend_in_tx<txs_keeped_by_block>::generate(std::vector<test_even
destinations.push_back(de);
cryptonote::transaction tx_1;
- if (!construct_tx(bob_account.get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tx_1, 0))
+ if (!construct_tx(bob_account.get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tx_1))
return false;
SET_EVENT_VISITOR_SETT(events, txs_keeped_by_block ? event_visitor_settings::set_txs_keeped_by_block : 0);
diff --git a/tests/core_tests/integer_overflow.cpp b/tests/core_tests/integer_overflow.cpp
index 6ffc3786b..2f48ec04a 100644
--- a/tests/core_tests/integer_overflow.cpp
+++ b/tests/core_tests/integer_overflow.cpp
@@ -174,7 +174,7 @@ bool gen_uint_overflow_2::generate(std::vector<test_event_entry>& events) const
destinations.push_back(tx_destination_entry(sources.front().amount - MONEY_SUPPLY - MONEY_SUPPLY + 1 - TESTS_DEFAULT_FEE, bob_addr, false));
cryptonote::transaction tx_1;
- if (!construct_tx(miner_account.get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tx_1, 0))
+ if (!construct_tx(miner_account.get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tx_1))
return false;
events.push_back(tx_1);
@@ -200,7 +200,7 @@ bool gen_uint_overflow_2::generate(std::vector<test_event_entry>& events) const
destinations.push_back(de);
cryptonote::transaction tx_2;
- if (!construct_tx(bob_account.get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tx_2, 0))
+ if (!construct_tx(bob_account.get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tx_2))
return false;
events.push_back(tx_2);
diff --git a/tests/core_tests/multisig.cpp b/tests/core_tests/multisig.cpp
index ed6fd68b5..e33803325 100644
--- a/tests/core_tests/multisig.cpp
+++ b/tests/core_tests/multisig.cpp
@@ -310,7 +310,7 @@ bool gen_multisig_tx_validation_base::generate_with(std::vector<test_event_entry
crypto::secret_key multisig_tx_key_entropy;
auto sources_copy = sources;
multisig::signing::tx_builder_ringct_t tx_builder;
- CHECK_AND_ASSERT_MES(tx_builder.init(miner_account[creator].get_keys(), {}, 0, 0, {0}, sources, destinations, {}, {rct::RangeProofPaddedBulletproof, 4}, true, false, tx_key, additional_tx_secret_keys, multisig_tx_key_entropy, tx), false, "error: multisig::signing::tx_builder_ringct_t::init");
+ CHECK_AND_ASSERT_MES(tx_builder.init(miner_account[creator].get_keys(), {}, 0, {0}, sources, destinations, {}, {rct::RangeProofPaddedBulletproof, 4}, true, false, tx_key, additional_tx_secret_keys, multisig_tx_key_entropy, tx), false, "error: multisig::signing::tx_builder_ringct_t::init");
// work out the permutation done on sources
std::vector<size_t> ins_order;
@@ -399,7 +399,7 @@ bool gen_multisig_tx_validation_base::generate_with(std::vector<test_event_entry
}
tools::apply_permutation(ins_order, k);
multisig::signing::tx_builder_ringct_t signer_tx_builder;
- CHECK_AND_ASSERT_MES(signer_tx_builder.init(miner_account[signer].get_keys(), {}, 0, 0, {0}, sources, destinations, {}, {rct::RangeProofPaddedBulletproof, 4}, true, true, tx_key, additional_tx_secret_keys, multisig_tx_key_entropy, tx), false, "error: multisig::signing::tx_builder_ringct_t::init");
+ CHECK_AND_ASSERT_MES(signer_tx_builder.init(miner_account[signer].get_keys(), {}, 0, {0}, sources, destinations, {}, {rct::RangeProofPaddedBulletproof, 4}, true, true, tx_key, additional_tx_secret_keys, multisig_tx_key_entropy, tx), false, "error: multisig::signing::tx_builder_ringct_t::init");
MDEBUG("signing with k size " << k.size());
for (size_t n = 0; n < multisig::signing::kAlphaComponents; ++n)
diff --git a/tests/core_tests/rct.cpp b/tests/core_tests/rct.cpp
index 3f2cfbea3..9ea7a8e3b 100644
--- a/tests/core_tests/rct.cpp
+++ b/tests/core_tests/rct.cpp
@@ -122,7 +122,7 @@ bool gen_rct_tx_validation_base::generate_with_full(std::vector<test_event_entry
std::vector<crypto::secret_key> additional_tx_keys;
std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
subaddresses[miner_accounts[n].get_keys().m_account_address.m_spend_public_key] = {0,0};
- bool r = construct_tx_and_get_tx_key(miner_accounts[n].get_keys(), subaddresses, sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), rct_txes[n], 0, tx_key, additional_tx_keys, true);
+ bool r = construct_tx_and_get_tx_key(miner_accounts[n].get_keys(), subaddresses, sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), rct_txes[n], tx_key, additional_tx_keys, true);
CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction");
events.push_back(rct_txes[n]);
starting_rct_tx_hashes.push_back(get_transaction_hash(rct_txes[n]));
@@ -229,7 +229,7 @@ bool gen_rct_tx_validation_base::generate_with_full(std::vector<test_event_entry
std::vector<crypto::secret_key> additional_tx_keys;
std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
subaddresses[miner_accounts[0].get_keys().m_account_address.m_spend_public_key] = {0,0};
- bool r = construct_tx_and_get_tx_key(miner_accounts[0].get_keys(), subaddresses, sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), tx, 0, tx_key, additional_tx_keys, true, rct_config, use_view_tags);
+ bool r = construct_tx_and_get_tx_key(miner_accounts[0].get_keys(), subaddresses, sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), tx, tx_key, additional_tx_keys, true, rct_config, use_view_tags);
CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction");
if (post_tx)
diff --git a/tests/core_tests/rct2.cpp b/tests/core_tests/rct2.cpp
index c8e0f6260..28e97b06d 100644
--- a/tests/core_tests/rct2.cpp
+++ b/tests/core_tests/rct2.cpp
@@ -136,7 +136,7 @@ bool gen_rct2_tx_validation_base::generate_with(std::vector<test_event_entry>& e
std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
subaddresses[miner_accounts[n].get_keys().m_account_address.m_spend_public_key] = {0,0};
rct_txes.resize(rct_txes.size() + 1);
- bool r = construct_tx_and_get_tx_key(miner_accounts[n].get_keys(), subaddresses, sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), rct_txes.back(), 0, tx_key, additional_tx_keys, true, rct_config[n]);
+ bool r = construct_tx_and_get_tx_key(miner_accounts[n].get_keys(), subaddresses, sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), rct_txes.back(), tx_key, additional_tx_keys, true, rct_config[n]);
CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction");
if (post_tx && !post_tx(rct_txes.back(), n))
diff --git a/tests/core_tests/transaction_tests.cpp b/tests/core_tests/transaction_tests.cpp
index b5ecba9ae..c27e6b375 100644
--- a/tests/core_tests/transaction_tests.cpp
+++ b/tests/core_tests/transaction_tests.cpp
@@ -102,7 +102,7 @@ bool test_transaction_generation_and_ring_signature()
destinations.push_back(td);
transaction tx_rc1;
- bool r = construct_tx(miner_acc2.get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tx_rc1, 0);
+ bool r = construct_tx(miner_acc2.get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tx_rc1);
CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction");
crypto::hash pref_hash = get_transaction_prefix_hash(tx_rc1);
diff --git a/tests/core_tests/tx_validation.cpp b/tests/core_tests/tx_validation.cpp
index bc8622539..a46b2a06a 100644
--- a/tests/core_tests/tx_validation.cpp
+++ b/tests/core_tests/tx_validation.cpp
@@ -212,7 +212,7 @@ bool gen_tx_unlock_time::generate(std::vector<test_event_entry>& events) const
GENERATE_ACCOUNT(miner_account);
MAKE_GENESIS_BLOCK(events, blk_0, miner_account, ts_start);
- REWIND_BLOCKS_N(events, blk_1, blk_0, miner_account, 10);
+ REWIND_BLOCKS_N(events, blk_1, blk_0, miner_account, 20);
REWIND_BLOCKS(events, blk_1r, blk_1, miner_account);
auto make_tx_with_unlock_time = [&](uint64_t unlock_time) -> transaction
@@ -222,9 +222,34 @@ bool gen_tx_unlock_time::generate(std::vector<test_event_entry>& events) const
std::list<transaction> txs_0;
+ // Let's make sure that non-zero unlock times fail with a normal relay method
+ SET_EVENT_VISITOR_SETT(events, 0); // set relay_method::fluff
+
txs_0.push_back(make_tx_with_unlock_time(0));
events.push_back(txs_0.back());
+ DO_CALLBACK(events, "mark_invalid_tx");
+ events.push_back(make_tx_with_unlock_time(get_block_height(blk_1r) - 1));
+
+ DO_CALLBACK(events, "mark_invalid_tx");
+ events.push_back(make_tx_with_unlock_time(get_block_height(blk_1r)));
+
+ DO_CALLBACK(events, "mark_invalid_tx");
+ events.push_back(make_tx_with_unlock_time(get_block_height(blk_1r) + 1));
+
+ DO_CALLBACK(events, "mark_invalid_tx");
+ events.push_back(make_tx_with_unlock_time(get_block_height(blk_1r) + 2));
+
+ DO_CALLBACK(events, "mark_invalid_tx");
+ events.push_back(make_tx_with_unlock_time(ts_start - 1));
+
+ DO_CALLBACK(events, "mark_invalid_tx");
+ events.push_back(make_tx_with_unlock_time(time(0) + 60 * 60));
+
+ // We want to try adding these transactions with non-zero unlock times to the pool, but relay
+ // rules enforce otherwise, so we set the relay method to block
+ SET_EVENT_VISITOR_SETT(events, event_visitor_settings::set_txs_keeped_by_block); // set relay_method::block
+
txs_0.push_back(make_tx_with_unlock_time(get_block_height(blk_1r) - 1));
events.push_back(txs_0.back());
@@ -596,6 +621,7 @@ bool gen_tx_check_input_unlock_time::generate(std::vector<test_event_entry>& eve
events.push_back(txs_0.back());
};
+ SET_EVENT_VISITOR_SETT(events, event_visitor_settings::set_txs_keeped_by_block); // set relay_method::block
uint64_t blk_3_height = get_block_height(blk_1r) + 2;
make_tx_to_acc(0, 0);
make_tx_to_acc(1, blk_3_height - 1);
@@ -604,6 +630,7 @@ bool gen_tx_check_input_unlock_time::generate(std::vector<test_event_entry>& eve
make_tx_to_acc(4, time(0) - 1);
make_tx_to_acc(5, time(0) + 60 * 60);
MAKE_NEXT_BLOCK_TX_LIST(events, blk_2, blk_1r, miner_account, txs_0);
+ SET_EVENT_VISITOR_SETT(events, 0); // set relay_method::fluff
std::list<transaction> txs_1;
auto make_tx_from_acc = [&](size_t acc_idx, bool invalid)
diff --git a/tests/core_tests/v2_tests.cpp b/tests/core_tests/v2_tests.cpp
index f2d0121b6..9030f22ba 100644
--- a/tests/core_tests/v2_tests.cpp
+++ b/tests/core_tests/v2_tests.cpp
@@ -107,7 +107,7 @@ bool gen_v2_tx_validation_base::generate_with(std::vector<test_event_entry>& eve
destinations.push_back(td);
transaction tx;
- bool r = construct_tx(miner_accounts[0].get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tx, 0);
+ bool r = construct_tx(miner_accounts[0].get_keys(), sources, destinations, boost::none, std::vector<uint8_t>(), tx);
CHECK_AND_ASSERT_MES(r, false, "failed to construct transaction");
if (!valid)
DO_CALLBACK(events, "mark_invalid_tx");
diff --git a/tests/core_tests/wallet_tools.cpp b/tests/core_tests/wallet_tools.cpp
index ee29fdad1..c81abbbaf 100644
--- a/tests/core_tests/wallet_tools.cpp
+++ b/tests/core_tests/wallet_tools.cpp
@@ -271,7 +271,7 @@ bool construct_tx_to_key(cryptonote::transaction& tx,
{
vector<tx_destination_entry> destinations;
fill_tx_destinations(sender_wallet->get_account(), get_address(to), amount, fee, sources, destinations, rct);
- return construct_tx_rct(sender_wallet, sources, destinations, get_address(sender_wallet), std::vector<uint8_t>(), tx, 0, rct, range_proof_type, bp_version);
+ return construct_tx_rct(sender_wallet, sources, destinations, get_address(sender_wallet), std::vector<uint8_t>(), tx, rct, range_proof_type, bp_version);
}
bool construct_tx_to_key(cryptonote::transaction& tx,
@@ -282,15 +282,15 @@ bool construct_tx_to_key(cryptonote::transaction& tx,
{
vector<tx_destination_entry> all_destinations;
fill_tx_destinations(sender_wallet->get_account(), destinations, fee, sources, all_destinations, rct);
- return construct_tx_rct(sender_wallet, sources, all_destinations, get_address(sender_wallet), std::vector<uint8_t>(), tx, 0, rct, range_proof_type, bp_version);
+ return construct_tx_rct(sender_wallet, sources, all_destinations, get_address(sender_wallet), std::vector<uint8_t>(), tx, rct, range_proof_type, bp_version);
}
-bool construct_tx_rct(tools::wallet2 * sender_wallet, std::vector<cryptonote::tx_source_entry>& sources, const std::vector<cryptonote::tx_destination_entry>& destinations, const boost::optional<cryptonote::account_public_address>& change_addr, std::vector<uint8_t> extra, cryptonote::transaction& tx, uint64_t unlock_time, bool rct, rct::RangeProofType range_proof_type, int bp_version)
+bool construct_tx_rct(tools::wallet2 * sender_wallet, std::vector<cryptonote::tx_source_entry>& sources, const std::vector<cryptonote::tx_destination_entry>& destinations, const boost::optional<cryptonote::account_public_address>& change_addr, std::vector<uint8_t> extra, cryptonote::transaction& tx, bool rct, rct::RangeProofType range_proof_type, int bp_version)
{
subaddresses_t & subaddresses = wallet_accessor_test::get_subaddresses(sender_wallet);
crypto::secret_key tx_key;
std::vector<crypto::secret_key> additional_tx_keys;
std::vector<tx_destination_entry> destinations_copy = destinations;
rct::RCTConfig rct_config = {range_proof_type, bp_version};
- return construct_tx_and_get_tx_key(sender_wallet->get_account().get_keys(), subaddresses, sources, destinations_copy, change_addr, extra, tx, unlock_time, tx_key, additional_tx_keys, rct, rct_config);
+ return construct_tx_and_get_tx_key(sender_wallet->get_account().get_keys(), subaddresses, sources, destinations_copy, change_addr, extra, tx, tx_key, additional_tx_keys, rct, rct_config);
}
diff --git a/tests/core_tests/wallet_tools.h b/tests/core_tests/wallet_tools.h
index 2201e11f4..94921e56e 100644
--- a/tests/core_tests/wallet_tools.h
+++ b/tests/core_tests/wallet_tools.h
@@ -53,6 +53,7 @@ class wallet_accessor_test
{
public:
static void set_account(tools::wallet2 * wallet, cryptonote::account_base& account);
+ static void set_password(tools::wallet2 * wallet, const epee::wipeable_string & password) { wallet->setup_keys(password); }
static tools::wallet2::transfer_container & get_transfers(tools::wallet2 * wallet) { return wallet->m_transfers; }
static subaddresses_t & get_subaddresses(tools::wallet2 * wallet) { return wallet->m_subaddresses; }
static void process_parsed_blocks(tools::wallet2 * wallet, uint64_t start_height, const std::vector<cryptonote::block_complete_entry> &blocks, const std::vector<tools::wallet2::parsed_block> &parsed_blocks, uint64_t& blocks_added);
@@ -92,5 +93,5 @@ bool construct_tx_rct(tools::wallet2 * sender_wallet,
std::vector<cryptonote::tx_source_entry>& sources,
const std::vector<cryptonote::tx_destination_entry>& destinations,
const boost::optional<cryptonote::account_public_address>& change_addr,
- std::vector<uint8_t> extra, cryptonote::transaction& tx, uint64_t unlock_time,
+ std::vector<uint8_t> extra, cryptonote::transaction& tx,
bool rct=false, rct::RangeProofType range_proof_type=rct::RangeProofBorromean, int bp_version = 0);
diff --git a/tests/functional_tests/functional_tests_rpc.py b/tests/functional_tests/functional_tests_rpc.py
index 7e4d49ffa..e483352a4 100755
--- a/tests/functional_tests/functional_tests_rpc.py
+++ b/tests/functional_tests/functional_tests_rpc.py
@@ -12,8 +12,8 @@ import os
USAGE = 'usage: functional_tests_rpc.py <python> <srcdir> <builddir> [<tests-to-run> | all]'
DEFAULT_TESTS = [
'address_book', 'bans', 'blockchain', 'cold_signing', 'daemon_info', 'get_output_distribution',
- 'integrated_address', 'k_anonymity', 'mining', 'multisig', 'p2p', 'proofs', 'rpc_payment',
- 'sign_message', 'transfer', 'txpool', 'uri', 'validate_address', 'wallet'
+ 'http_digest_auth', 'integrated_address', 'k_anonymity', 'mining', 'multisig', 'p2p', 'proofs',
+ 'rpc_payment', 'sign_message', 'transfer', 'txpool', 'uri', 'validate_address', 'wallet'
]
try:
python = sys.argv[1]
@@ -41,12 +41,12 @@ except:
# a main offline monerod, does most of the tests
# a restricted RPC monerod setup with RPC payment
# two local online monerods connected to each other
-N_MONERODS = 4
+N_MONERODS = 5
# 4 wallets connected to the main offline monerod
# 1 wallet connected to the first local online monerod
# 1 offline wallet
-N_WALLETS = 6
+N_WALLETS = 7
WALLET_DIRECTORY = builddir + "/functional-tests-directory"
FUNCTIONAL_TESTS_DIRECTORY = builddir + "/tests/functional_tests"
@@ -58,15 +58,17 @@ monerod_extra = [
["--rpc-payment-address", "44SKxxLQw929wRF6BA9paQ1EWFshNnKhXM3qz6Mo3JGDE2YG3xyzVutMStEicxbQGRfrYvAAYxH6Fe8rnD56EaNwUiqhcwR", "--rpc-payment-difficulty", str(DIFFICULTY), "--rpc-payment-credits", "5000", "--offline"],
["--add-exclusive-node", "127.0.0.1:18283"],
["--add-exclusive-node", "127.0.0.1:18282"],
+ ["--rpc-login", "md5_lover:Z1ON0101", "--offline"],
]
-wallet_base = [builddir + "/bin/monero-wallet-rpc", "--wallet-dir", WALLET_DIRECTORY, "--rpc-bind-port", "wallet_port", "--disable-rpc-login", "--rpc-ssl", "disabled", "--daemon-ssl", "disabled", "--log-level", "1", "--allow-mismatched-daemon-version"]
+wallet_base = [builddir + "/bin/monero-wallet-rpc", "--wallet-dir", WALLET_DIRECTORY, "--rpc-bind-port", "wallet_port", "--rpc-ssl", "disabled", "--daemon-ssl", "disabled", "--log-level", "1", "--allow-mismatched-daemon-version"]
wallet_extra = [
- ["--daemon-port", "18180"],
- ["--daemon-port", "18180"],
- ["--daemon-port", "18180"],
- ["--daemon-port", "18180"],
- ["--daemon-port", "18182"],
- ["--offline"],
+ ["--daemon-port", "18180", "--disable-rpc-login"],
+ ["--daemon-port", "18180", "--disable-rpc-login"],
+ ["--daemon-port", "18180", "--disable-rpc-login"],
+ ["--daemon-port", "18180", "--disable-rpc-login"],
+ ["--daemon-port", "18182", "--disable-rpc-login"],
+ ["--offline", "--disable-rpc-login"],
+ ["--daemon-port", "18184", "--daemon-login", "md5_lover:Z1ON0101", "--rpc-login", "kyle:reveille"],
]
command_lines = []
diff --git a/tests/functional_tests/http_digest_auth.py b/tests/functional_tests/http_digest_auth.py
new file mode 100644
index 000000000..7c22f9f30
--- /dev/null
+++ b/tests/functional_tests/http_digest_auth.py
@@ -0,0 +1,110 @@
+#!/usr/bin/env python3
+
+# Copyright (c) 2024, 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.
+
+from framework.daemon import Daemon
+from framework.wallet import Wallet
+
+import time
+
+
+DAEMON_IDX = 4
+DAEMON_USER = "md5_lover"
+DAEMON_PASS = "Z1ON0101"
+WALLET_IDX = 6
+WALLET_USER = "kyle"
+WALLET_PASS = "reveille"
+WALLET_SEED = "velvet lymph giddy number token physics poetry unquoted nibs useful sabotage limits \
+ benches lifestyle eden nitrogen anvil fewest avoid batch vials washing fences goat unquoted"
+
+class HttpDigestAuthTest():
+ def run_test(self):
+ self.test_daemon_login_required()
+ self.test_wallet_login_required()
+
+ self.make_daemon_conn()
+ self.create_wallet()
+
+ self.mine_through_wallet()
+
+ def test_daemon_login_required(self):
+ print('Attempting to connect to daemon loginless with RPC digest authentication required...')
+ bad_daemon = Daemon(idx = DAEMON_IDX)
+ try:
+ res = bad_daemon.get_height()
+ assert(False)
+ except:
+ pass
+
+ def test_wallet_login_required(self):
+ print('Attempting to connect to wallet server loginless with RPC digest authentication required...')
+ bad_wallet = Wallet(idx = WALLET_IDX)
+ try:
+ res = bad_wallet.get_balance()
+ assert(False)
+ except:
+ pass
+
+ def make_daemon_conn(self):
+ print('Connecting to daemon with RPC digest authentication required...')
+ self.daemon = Daemon(idx = DAEMON_IDX, username = DAEMON_USER, password = DAEMON_PASS)
+ res = self.daemon.get_height()
+ self.daemon.pop_blocks(res.height - 1)
+ self.daemon.flush_txpool()
+
+ def create_wallet(self):
+ print('Connecting to wallet server with RPC digest authentication required...')
+ self.wallet = Wallet(idx = WALLET_IDX, username = WALLET_USER, password = WALLET_PASS)
+ # close the wallet if any, will throw if none is loaded
+ try: self.wallet.close_wallet()
+ except: pass
+ res = self.wallet.restore_deterministic_wallet(seed = WALLET_SEED)
+
+ def mine_through_wallet(self):
+ print('Telling login-required daemon to start mining through login-required wallet server...')
+ start_height = self.daemon.get_height().height
+ self.wallet.start_mining(2)
+
+ print("Waiting a few seconds for mining to occur...")
+ for tries in range(20):
+ time.sleep(1)
+
+ stop_height = self.daemon.get_height().height
+ if stop_height > start_height:
+ break
+
+ print('Telling login-required daemon to stop mining through login-required wallet server...')
+ self.wallet.stop_mining()
+
+ num_blocks_mined = stop_height - start_height
+ assert num_blocks_mined > 0
+ print('Mined {} blocks!'.format(num_blocks_mined))
+
+if __name__ == '__main__':
+ HttpDigestAuthTest().run_test()
diff --git a/tests/functional_tests/transactions_flow_test.cpp b/tests/functional_tests/transactions_flow_test.cpp
index 8c4b27d24..a15348bca 100644
--- a/tests/functional_tests/transactions_flow_test.cpp
+++ b/tests/functional_tests/transactions_flow_test.cpp
@@ -85,7 +85,7 @@ bool do_send_money(tools::wallet2& w1, tools::wallet2& w2, size_t mix_in_factor,
try
{
std::vector<tools::wallet2::pending_tx> ptx;
- ptx = w1.create_transactions_2(dsts, mix_in_factor, 0, 0, std::vector<uint8_t>(), 0, {});
+ ptx = w1.create_transactions_2(dsts, mix_in_factor, 0, std::vector<uint8_t>(), 0, {});
for (auto &p: ptx)
w1.commit_tx(p);
return true;
diff --git a/tests/functional_tests/transfer.py b/tests/functional_tests/transfer.py
index 56a2514d9..1da075318 100755
--- a/tests/functional_tests/transfer.py
+++ b/tests/functional_tests/transfer.py
@@ -30,6 +30,7 @@
from __future__ import print_function
import json
+import util_resources
import pprint
from deepdiff import DeepDiff
pp = pprint.PrettyPrinter(indent=2)
@@ -46,6 +47,17 @@ seeds = [
'dilute gutter certain antics pamphlet macro enjoy left slid guarded bogeys upload nineteen bomb jubilee enhanced irritate turnip eggs swung jukebox loudly reduce sedan slid',
]
+def diff_transfers(actual_transfers, expected_transfers, ignore_order = True):
+ # The payments containers aren't ordered; re-scanning can lead to diff orders
+ diff = DeepDiff(actual_transfers, expected_transfers, ignore_order = ignore_order)
+ if diff != {}:
+ pp.pprint(diff)
+ assert diff == {}
+
+def diff_incoming_transfers(actual_transfers, expected_transfers):
+ # wallet2 m_transfers container is ordered and order should be the same across rescans
+ diff_transfers(actual_transfers, expected_transfers, ignore_order = False)
+
class TransferTest():
def run_test(self):
self.reset()
@@ -64,6 +76,8 @@ class TransferTest():
self.check_multiple_submissions()
self.check_scan_tx()
self.check_subtract_fee_from_outputs()
+ self.check_background_sync()
+ self.check_background_sync_reorg_recovery()
def reset(self):
print('Resetting blockchain')
@@ -875,12 +889,6 @@ class TransferTest():
print('Testing scan_tx')
- def diff_transfers(actual_transfers, expected_transfers):
- diff = DeepDiff(actual_transfers, expected_transfers)
- if diff != {}:
- pp.pprint(diff)
- assert diff == {}
-
# set up sender_wallet
sender_wallet = self.wallet[0]
try: sender_wallet.close_wallet()
@@ -1162,5 +1170,385 @@ class TransferTest():
except AssertionError:
pass
+ def check_background_sync(self):
+ daemon = Daemon()
+
+ print('Testing background sync')
+
+ # Some helper functions
+ def stop_with_wrong_inputs(wallet, wallet_password, seed = ''):
+ invalid = False
+ try: wallet.stop_background_sync(wallet_password = wallet_password, seed = seed)
+ except: invalid = True
+ assert invalid
+
+ def open_with_wrong_password(wallet, filename, password):
+ invalid_password = False
+ try: wallet.open_wallet(filename, password = password)
+ except: invalid_password = True
+ assert invalid_password
+
+ def restore_wallet(wallet, seed, filename = '', password = ''):
+ wallet.close_wallet()
+ if filename != '':
+ util_resources.remove_wallet_files(filename)
+ wallet.restore_deterministic_wallet(seed = seed, filename = filename, password = password)
+ wallet.auto_refresh(enable = False)
+ assert wallet.get_transfers() == {}
+
+ def assert_correct_transfers(wallet, expected_transfers, expected_inc_transfers, expected_balance):
+ diff_transfers(wallet.get_transfers(), expected_transfers)
+ diff_incoming_transfers(wallet.incoming_transfers(transfer_type = 'all'), expected_inc_transfers)
+ assert wallet.get_balance().balance == expected_balance
+
+ # Set up sender_wallet. Prepare to sweep single output to receiver.
+ # We're testing a sweep because it makes sure background sync can
+ # properly pick up txs which do not have a change output back to sender.
+ sender_wallet = self.wallet[0]
+ try: sender_wallet.close_wallet()
+ except: pass
+ sender_wallet.restore_deterministic_wallet(seed = seeds[0])
+ sender_wallet.auto_refresh(enable = False)
+ sender_wallet.refresh()
+ res = sender_wallet.incoming_transfers(transfer_type = 'available')
+ unlocked = [x for x in res.transfers if x.unlocked and x.amount > 0]
+ assert len(unlocked) > 0
+ ki = unlocked[0].key_image
+ amount = unlocked[0].amount
+ spent_txid = unlocked[0].tx_hash
+ sender_wallet.refresh()
+ res = sender_wallet.get_transfers()
+ out_len = 0 if 'out' not in res else len(res.out)
+ sender_starting_balance = sender_wallet.get_balance().balance
+
+ # Background sync type options
+ reuse_password = sender_wallet.background_sync_options.reuse_password
+ custom_password = sender_wallet.background_sync_options.custom_password
+
+ # set up receiver_wallet
+ receiver_wallet = self.wallet[1]
+ try: receiver_wallet.close_wallet()
+ except: pass
+ receiver_wallet.restore_deterministic_wallet(seed = seeds[1])
+ receiver_wallet.auto_refresh(enable = False)
+ receiver_wallet.refresh()
+ res = receiver_wallet.get_transfers()
+ in_len = 0 if 'in' not in res else len(res['in'])
+ receiver_starting_balance = receiver_wallet.get_balance().balance
+
+ # transfer from sender_wallet to receiver_wallet
+ dst = '44Kbx4sJ7JDRDV5aAhLJzQCjDz2ViLRduE3ijDZu3osWKBjMGkV1XPk4pfDUMqt1Aiezvephdqm6YD19GKFD9ZcXVUTp6BW'
+ res = sender_wallet.sweep_single(dst, key_image = ki)
+ assert len(res.tx_hash) == 32*2
+ txid = res.tx_hash
+ assert res.fee > 0
+ fee = res.fee
+ assert res.amount == amount - fee
+
+ expected_sender_balance = sender_starting_balance - amount
+ expected_receiver_balance = receiver_starting_balance + (amount - fee)
+
+ print('Checking background sync on outgoing wallet')
+ sender_wallet.setup_background_sync(background_sync_type = reuse_password)
+ sender_wallet.start_background_sync()
+ # Mine block to an uninvolved wallet
+ daemon.generateblocks('46r4nYSevkfBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCLGwTerK', 1)
+ # sender should still be able to scan the transfer normally because we
+ # spent an output that had a known key image
+ sender_wallet.refresh()
+ transfers = sender_wallet.get_transfers()
+ assert 'pending' not in transfers or len(transfers.pending) == 0
+ assert 'pool' not in transfers or len (transfers.pool) == 0
+ assert len(transfers.out) == out_len + 1
+ tx = [x for x in transfers.out if x.txid == txid]
+ assert len(tx) == 1
+ tx = tx[0]
+ assert tx.amount == amount - fee
+ assert tx.fee == fee
+ assert len(tx.destinations) == 1
+ assert tx.destinations[0].amount == amount - fee
+ assert tx.destinations[0].address == dst
+ incoming_transfers = sender_wallet.incoming_transfers(transfer_type = 'all')
+ assert len([x for x in incoming_transfers.transfers if x.tx_hash == spent_txid and x.key_image == ki and x.spent]) == 1
+ assert sender_wallet.get_balance().balance == expected_sender_balance
+
+ # Restore and check background syncing outgoing wallet
+ restore_wallet(sender_wallet, seeds[0])
+ sender_wallet.setup_background_sync(background_sync_type = reuse_password)
+ sender_wallet.start_background_sync()
+ sender_wallet.refresh()
+ for i, out_tx in enumerate(transfers.out):
+ if 'destinations' in out_tx:
+ del transfers.out[i]['destinations'] # destinations are not expected after wallet restore
+ # sender's balance should be higher because can't detect spends while
+ # background sync enabled, only receives
+ background_bal = sender_wallet.get_balance().balance
+ assert background_bal > expected_sender_balance
+ background_transfers = sender_wallet.get_transfers()
+ assert 'out' not in background_transfers or len(background_transfers.out) == 0
+ assert 'in' in background_transfers and len(background_transfers['in']) > 0
+ background_incoming_transfers = sender_wallet.incoming_transfers(transfer_type = 'all')
+ assert len(background_incoming_transfers) == len(incoming_transfers)
+ assert len([x for x in background_incoming_transfers.transfers if x.spent or x.key_image != '']) == 0
+ assert len([x for x in background_incoming_transfers.transfers if x.tx_hash == spent_txid]) == 1
+
+ # Try to stop background sync with the wrong seed
+ stop_with_wrong_inputs(sender_wallet, wallet_password = '', seed = seeds[1])
+
+ # Stop background sync and check transfers update correctly
+ sender_wallet.stop_background_sync(wallet_password = '', seed = seeds[0])
+ assert_correct_transfers(sender_wallet, transfers, incoming_transfers, expected_sender_balance)
+
+ # Check stopping a wallet with wallet files saved to disk
+ for background_sync_type in [reuse_password, custom_password]:
+ restore_wallet(sender_wallet, seeds[0], 'test1', 'test_password')
+ background_cache_password = None if background_sync_type == reuse_password else 'background_password'
+ sender_wallet.setup_background_sync(background_sync_type = background_sync_type, wallet_password = 'test_password', background_cache_password = background_cache_password)
+ sender_wallet.start_background_sync()
+ sender_wallet.refresh()
+ assert_correct_transfers(sender_wallet, background_transfers, background_incoming_transfers, background_bal)
+ stop_with_wrong_inputs(sender_wallet, 'wrong_password')
+ sender_wallet.stop_background_sync(wallet_password = 'test_password')
+ assert_correct_transfers(sender_wallet, transfers, incoming_transfers, expected_sender_balance)
+
+ # Close wallet while background syncing, then reopen
+ for background_sync_type in [reuse_password, custom_password]:
+ restore_wallet(sender_wallet, seeds[0], 'test1', 'test_password')
+ background_cache_password = None if background_sync_type == reuse_password else 'background_password'
+ sender_wallet.setup_background_sync(background_sync_type = background_sync_type, wallet_password = 'test_password', background_cache_password = background_cache_password)
+ sender_wallet.start_background_sync()
+ sender_wallet.refresh()
+ assert_correct_transfers(sender_wallet, background_transfers, background_incoming_transfers, background_bal)
+ sender_wallet.close_wallet()
+ open_with_wrong_password(sender_wallet, 'test1', 'wrong_password')
+ sender_wallet.open_wallet('test1', password = 'test_password')
+ # It should reopen with spend key loaded and correctly scan all transfers
+ assert_correct_transfers(sender_wallet, transfers, incoming_transfers, expected_sender_balance)
+
+ # Close wallet while syncing normally, then reopen
+ for background_sync_type in [reuse_password, custom_password]:
+ restore_wallet(sender_wallet, seeds[0], 'test1', 'test_password')
+ background_cache_password = None if background_sync_type == reuse_password else 'background_password'
+ sender_wallet.setup_background_sync(background_sync_type = background_sync_type, wallet_password = 'test_password', background_cache_password = background_cache_password)
+ sender_wallet.refresh()
+ assert_correct_transfers(sender_wallet, transfers, incoming_transfers, expected_sender_balance)
+ sender_wallet.close_wallet()
+ open_with_wrong_password(sender_wallet, 'test1', 'wrong_password')
+ sender_wallet.open_wallet('test1', password = 'test_password')
+ assert_correct_transfers(sender_wallet, transfers, incoming_transfers, expected_sender_balance)
+
+ # Create background cache using custom password, then use it to sync, then reopen main wallet
+ for background_cache_password in ['background_password', '']:
+ restore_wallet(sender_wallet, seeds[0], 'test1', 'test_password')
+ assert not util_resources.file_exists('test1.background')
+ assert not util_resources.file_exists('test1.background.keys')
+ sender_wallet.setup_background_sync(background_sync_type = custom_password, wallet_password = 'test_password', background_cache_password = background_cache_password)
+ assert util_resources.file_exists('test1.background')
+ assert util_resources.file_exists('test1.background.keys')
+ sender_wallet.close_wallet()
+ open_with_wrong_password(sender_wallet, 'test1.background', 'test_password')
+ sender_wallet.open_wallet('test1.background', password = background_cache_password)
+ sender_wallet.refresh()
+ assert_correct_transfers(sender_wallet, background_transfers, background_incoming_transfers, background_bal)
+ sender_wallet.close_wallet()
+ sender_wallet.open_wallet('test1', password = 'test_password')
+ assert_correct_transfers(sender_wallet, transfers, incoming_transfers, expected_sender_balance)
+
+ # Check that main wallet keeps background cache encrypted with custom password in sync
+ restore_wallet(sender_wallet, seeds[0], 'test1', 'test_password')
+ sender_wallet.setup_background_sync(background_sync_type = background_sync_type, wallet_password = 'test_password', background_cache_password = 'background_password')
+ sender_wallet.refresh()
+ assert_correct_transfers(sender_wallet, transfers, incoming_transfers, expected_sender_balance)
+ sender_wallet.close_wallet()
+ sender_wallet.open_wallet('test1.background', password = 'background_password')
+ assert_correct_transfers(sender_wallet, transfers, incoming_transfers, expected_sender_balance)
+
+ # Try using wallet password as custom background password
+ restore_wallet(sender_wallet, seeds[0], 'test1', 'test_password')
+ assert not util_resources.file_exists('test1.background')
+ assert not util_resources.file_exists('test1.background.keys')
+ same_password = False
+ try: sender_wallet.setup_background_sync(background_sync_type = custom_password, wallet_password = 'test_password', background_cache_password = 'test_password')
+ except: same_password = True
+ assert same_password
+ assert not util_resources.file_exists('test1.background')
+ assert not util_resources.file_exists('test1.background.keys')
+
+ # Turn off background sync
+ for background_sync_type in [reuse_password, custom_password]:
+ restore_wallet(sender_wallet, seeds[0], 'test1', 'test_password')
+ background_cache_password = None if background_sync_type == reuse_password else 'background_password'
+ sender_wallet.setup_background_sync(background_sync_type = background_sync_type, wallet_password = 'test_password', background_cache_password = background_cache_password)
+ if background_sync_type == custom_password:
+ assert util_resources.file_exists('test1.background')
+ assert util_resources.file_exists('test1.background.keys')
+ sender_wallet.close_wallet()
+ assert util_resources.file_exists('test1.background')
+ assert util_resources.file_exists('test1.background.keys')
+ else:
+ assert not util_resources.file_exists('test1.background')
+ assert not util_resources.file_exists('test1.background.keys')
+ sender_wallet.close_wallet()
+ assert not util_resources.file_exists('test1.background')
+ assert not util_resources.file_exists('test1.background.keys')
+ sender_wallet.open_wallet('test1', password = 'test_password')
+ sender_wallet.setup_background_sync(background_sync_type = sender_wallet.background_sync_options.off, wallet_password = 'test_password')
+ assert not util_resources.file_exists('test1.background')
+ assert not util_resources.file_exists('test1.background.keys')
+ sender_wallet.close_wallet()
+ assert not util_resources.file_exists('test1.background')
+ assert not util_resources.file_exists('test1.background.keys')
+ sender_wallet.open_wallet('test1', password = 'test_password')
+
+ # Sanity check against outgoing wallet restored at height 0
+ sender_wallet.close_wallet()
+ sender_wallet.restore_deterministic_wallet(seed = seeds[0], restore_height = 0)
+ sender_wallet.refresh()
+ assert_correct_transfers(sender_wallet, transfers, incoming_transfers, expected_sender_balance)
+
+ print('Checking background sync on incoming wallet')
+ receiver_wallet.setup_background_sync(background_sync_type = reuse_password)
+ receiver_wallet.start_background_sync()
+ receiver_wallet.refresh()
+ transfers = receiver_wallet.get_transfers()
+ assert 'pending' not in transfers or len(transfers.pending) == 0
+ assert 'pool' not in transfers or len (transfers.pool) == 0
+ assert len(transfers['in']) == in_len + 1
+ tx = [x for x in transfers['in'] if x.txid == txid]
+ assert len(tx) == 1
+ tx = tx[0]
+ assert tx.amount == amount - fee
+ assert tx.fee == fee
+ incoming_transfers = receiver_wallet.incoming_transfers(transfer_type = 'all')
+ assert len([x for x in incoming_transfers.transfers if x.tx_hash == txid and x.key_image == '' and not x.spent]) == 1
+ assert receiver_wallet.get_balance().balance == expected_receiver_balance
+
+ # Restore and check background syncing incoming wallet
+ restore_wallet(receiver_wallet, seeds[1])
+ receiver_wallet.setup_background_sync(background_sync_type = reuse_password)
+ receiver_wallet.start_background_sync()
+ receiver_wallet.refresh()
+ if 'out' in transfers:
+ for i, out_tx in enumerate(transfers.out):
+ if 'destinations' in out_tx:
+ del transfers.out[i]['destinations'] # destinations are not expected after wallet restore
+ background_bal = receiver_wallet.get_balance().balance
+ assert background_bal >= expected_receiver_balance
+ background_transfers = receiver_wallet.get_transfers()
+ assert 'out' not in background_transfers or len(background_transfers.out) == 0
+ assert 'in' in background_transfers and len(background_transfers['in']) > 0
+ background_incoming_transfers = receiver_wallet.incoming_transfers(transfer_type = 'all')
+ assert len(background_incoming_transfers) == len(incoming_transfers)
+ assert len([x for x in background_incoming_transfers.transfers if x.spent or x.key_image != '']) == 0
+ assert len([x for x in background_incoming_transfers.transfers if x.tx_hash == txid]) == 1
+
+ # Stop background sync and check transfers update correctly
+ receiver_wallet.stop_background_sync(wallet_password = '', seed = seeds[1])
+ diff_transfers(receiver_wallet.get_transfers(), transfers)
+ incoming_transfers = receiver_wallet.incoming_transfers(transfer_type = 'all')
+ assert len(background_incoming_transfers) == len(incoming_transfers)
+ assert len([x for x in incoming_transfers.transfers if x.tx_hash == txid and x.key_image != '' and not x.spent]) == 1
+ assert receiver_wallet.get_balance().balance == expected_receiver_balance
+
+ # Check a fresh incoming wallet with wallet files saved to disk and encrypted with password
+ restore_wallet(receiver_wallet, seeds[1], 'test2', 'test_password')
+ receiver_wallet.setup_background_sync(background_sync_type = reuse_password, wallet_password = 'test_password')
+ receiver_wallet.start_background_sync()
+ receiver_wallet.refresh()
+ assert_correct_transfers(receiver_wallet, background_transfers, background_incoming_transfers, background_bal)
+ stop_with_wrong_inputs(receiver_wallet, 'wrong_password')
+ receiver_wallet.stop_background_sync(wallet_password = 'test_password')
+ assert_correct_transfers(receiver_wallet, transfers, incoming_transfers, expected_receiver_balance)
+
+ # Close receiver's wallet while background sync is enabled then reopen
+ restore_wallet(receiver_wallet, seeds[1], 'test2', 'test_password')
+ receiver_wallet.setup_background_sync(background_sync_type = reuse_password, wallet_password = 'test_password')
+ receiver_wallet.start_background_sync()
+ receiver_wallet.refresh()
+ diff_transfers(receiver_wallet.get_transfers(), background_transfers)
+ diff_incoming_transfers(receiver_wallet.incoming_transfers(transfer_type = 'all'), background_incoming_transfers)
+ assert receiver_wallet.get_balance().balance == background_bal
+ receiver_wallet.close_wallet()
+ receiver_wallet.open_wallet('test2', password = 'test_password')
+ # It should reopen with spend key loaded and correctly scan all transfers
+ assert_correct_transfers(receiver_wallet, transfers, incoming_transfers, expected_receiver_balance)
+
+ # Sanity check against incoming wallet restored at height 0
+ receiver_wallet.close_wallet()
+ receiver_wallet.restore_deterministic_wallet(seed = seeds[1], restore_height = 0)
+ receiver_wallet.refresh()
+ assert_correct_transfers(receiver_wallet, transfers, incoming_transfers, expected_receiver_balance)
+
+ # Clean up
+ util_resources.remove_wallet_files('test1')
+ util_resources.remove_wallet_files('test2')
+ for i in range(2):
+ self.wallet[i].close_wallet()
+ self.wallet[i].restore_deterministic_wallet(seed = seeds[i])
+
+ def check_background_sync_reorg_recovery(self):
+ daemon = Daemon()
+
+ print('Testing background sync reorg recovery')
+
+ # Disconnect daemon from peers
+ daemon.out_peers(0)
+
+ # Background sync type options
+ sender_wallet = self.wallet[0]
+ reuse_password = sender_wallet.background_sync_options.reuse_password
+ custom_password = sender_wallet.background_sync_options.custom_password
+
+ for background_sync_type in [reuse_password, custom_password]:
+ # Set up wallet saved to disk
+ sender_wallet.close_wallet()
+ util_resources.remove_wallet_files('test1')
+ sender_wallet.restore_deterministic_wallet(seed = seeds[0], filename = 'test1', password = '')
+ sender_wallet.auto_refresh(enable = False)
+ sender_wallet.refresh()
+ sender_starting_balance = sender_wallet.get_balance().balance
+
+ # Send tx and mine a block
+ amount = 1000000000000
+ assert sender_starting_balance > amount
+ dst = {'address': '44Kbx4sJ7JDRDV5aAhLJzQCjDz2ViLRduE3ijDZu3osWKBjMGkV1XPk4pfDUMqt1Aiezvephdqm6YD19GKFD9ZcXVUTp6BW', 'amount': amount}
+ res = sender_wallet.transfer([dst])
+ assert len(res.tx_hash) == 32*2
+ txid = res.tx_hash
+
+ daemon.generateblocks('46r4nYSevkfBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCLGwTerK', 1)
+
+ # Make sure the wallet can see the tx
+ sender_wallet.refresh()
+ transfers = sender_wallet.get_transfers()
+ assert 'pool' not in transfers or len (transfers.pool) == 0
+ tx = [x for x in transfers.out if x.txid == txid]
+ assert len(tx) == 1
+ tx = tx[0]
+ assert sender_wallet.get_balance().balance < (sender_starting_balance - amount)
+
+ # Pop the block while background syncing
+ background_cache_password = None if background_sync_type == reuse_password else 'background_password'
+ sender_wallet.setup_background_sync(background_sync_type = background_sync_type, wallet_password = '', background_cache_password = background_cache_password)
+ sender_wallet.start_background_sync()
+ daemon.pop_blocks(1)
+ daemon.flush_txpool()
+
+ daemon.generateblocks('46r4nYSevkfBUMhuykdK3gQ98XDqDTYW1hNLaXNvjpsJaSbNtdXh1sKMsdVgqkaihChAzEy29zEDPMR3NHQvGoZCLGwTerK', 1)
+
+ # Make sure the wallet can no longer see the tx
+ sender_wallet.refresh()
+ sender_wallet.stop_background_sync(wallet_password = '', seed = seeds[0])
+ transfers = sender_wallet.get_transfers()
+ no_tx = [x for x in transfers.out if x.txid == txid]
+ assert len(no_tx) == 0
+ assert sender_wallet.get_balance().balance == sender_starting_balance
+
+ # Clean up
+ daemon.out_peers(12)
+ util_resources.remove_wallet_files('test1')
+ self.wallet[0].close_wallet()
+ self.wallet[0].restore_deterministic_wallet(seed = seeds[0])
+
if __name__ == '__main__':
TransferTest().run_test()
diff --git a/tests/functional_tests/util_resources.py b/tests/functional_tests/util_resources.py
index c12506146..36a5fa32c 100755
--- a/tests/functional_tests/util_resources.py
+++ b/tests/functional_tests/util_resources.py
@@ -37,6 +37,8 @@
from __future__ import print_function
import subprocess
import psutil
+import os
+import errno
def available_ram_gb():
ram_bytes = psutil.virtual_memory().available
@@ -51,3 +53,26 @@ def get_time_pi_seconds(cores, app_dir='.'):
miliseconds = int(decoded)
return miliseconds / 1000.0
+
+def remove_file(name):
+ WALLET_DIRECTORY = os.environ['WALLET_DIRECTORY']
+ assert WALLET_DIRECTORY != ''
+ try:
+ os.unlink(WALLET_DIRECTORY + '/' + name)
+ except OSError as e:
+ if e.errno != errno.ENOENT:
+ raise
+
+def get_file_path(name):
+ WALLET_DIRECTORY = os.environ['WALLET_DIRECTORY']
+ assert WALLET_DIRECTORY != ''
+ return WALLET_DIRECTORY + '/' + name
+
+def remove_wallet_files(name):
+ for suffix in ['', '.keys', '.background', '.background.keys', '.address.txt']:
+ remove_file(name + suffix)
+
+def file_exists(name):
+ WALLET_DIRECTORY = os.environ['WALLET_DIRECTORY']
+ assert WALLET_DIRECTORY != ''
+ return os.path.isfile(WALLET_DIRECTORY + '/' + name)
diff --git a/tests/functional_tests/wallet.py b/tests/functional_tests/wallet.py
index 3bb4459d6..f3b011f8b 100755
--- a/tests/functional_tests/wallet.py
+++ b/tests/functional_tests/wallet.py
@@ -34,8 +34,7 @@
from __future__ import print_function
import sys
-import os
-import errno
+import util_resources
from framework.wallet import Wallet
from framework.daemon import Daemon
@@ -54,24 +53,6 @@ class WalletTest():
self.change_password()
self.store()
- def remove_file(self, name):
- WALLET_DIRECTORY = os.environ['WALLET_DIRECTORY']
- assert WALLET_DIRECTORY != ''
- try:
- os.unlink(WALLET_DIRECTORY + '/' + name)
- except OSError as e:
- if e.errno != errno.ENOENT:
- raise
-
- def remove_wallet_files(self, name):
- for suffix in ['', '.keys']:
- self.remove_file(name + suffix)
-
- def file_exists(self, name):
- WALLET_DIRECTORY = os.environ['WALLET_DIRECTORY']
- assert WALLET_DIRECTORY != ''
- return os.path.isfile(WALLET_DIRECTORY + '/' + name)
-
def reset(self):
print('Resetting blockchain')
daemon = Daemon()
@@ -333,7 +314,7 @@ class WalletTest():
try: wallet.close_wallet()
except: pass
- self.remove_wallet_files('test1')
+ util_resources.remove_wallet_files('test1')
seed = 'velvet lymph giddy number token physics poetry unquoted nibs useful sabotage limits benches lifestyle eden nitrogen anvil fewest avoid batch vials washing fences goat unquoted'
res = wallet.restore_deterministic_wallet(seed = seed, filename = 'test1')
@@ -359,7 +340,7 @@ class WalletTest():
wallet.close_wallet()
- self.remove_wallet_files('test1')
+ util_resources.remove_wallet_files('test1')
def store(self):
print('Testing store')
@@ -369,22 +350,26 @@ class WalletTest():
try: wallet.close_wallet()
except: pass
- self.remove_wallet_files('test1')
+ util_resources.remove_wallet_files('test1')
seed = 'velvet lymph giddy number token physics poetry unquoted nibs useful sabotage limits benches lifestyle eden nitrogen anvil fewest avoid batch vials washing fences goat unquoted'
res = wallet.restore_deterministic_wallet(seed = seed, filename = 'test1')
assert res.address == '42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm'
assert res.seed == seed
- self.remove_file('test1')
- assert self.file_exists('test1.keys')
- assert not self.file_exists('test1')
+ util_resources.remove_file('test1')
+ assert util_resources.file_exists('test1.keys')
+ assert not util_resources.file_exists('test1')
wallet.store()
- assert self.file_exists('test1.keys')
- assert self.file_exists('test1')
+ assert util_resources.file_exists('test1.keys')
+ assert util_resources.file_exists('test1')
wallet.close_wallet()
- self.remove_wallet_files('test1')
+
+ wallet.open_wallet(filename = 'test1', password = '')
+ wallet.close_wallet()
+
+ util_resources.remove_wallet_files('test1')
if __name__ == '__main__':
diff --git a/tests/hash/main.cpp b/tests/hash/main.cpp
index 23455f7f3..c1ad80c7c 100644
--- a/tests/hash/main.cpp
+++ b/tests/hash/main.cpp
@@ -43,7 +43,7 @@
#include "warnings.h"
#include "crypto/hash.h"
#include "crypto/variant2_int_sqrt.h"
-#include "randomx/src/blake2/blake2.h"
+#include "crypto/blake2b.h"
#include "../io.h"
using namespace std;
diff --git a/tests/performance_tests/check_tx_signature.h b/tests/performance_tests/check_tx_signature.h
index de979856a..2ae4a2613 100644
--- a/tests/performance_tests/check_tx_signature.h
+++ b/tests/performance_tests/check_tx_signature.h
@@ -72,7 +72,7 @@ public:
std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
subaddresses[this->m_miners[this->real_source_idx].get_keys().m_account_address.m_spend_public_key] = {0,0};
rct::RCTConfig rct_config{range_proof_type, bp_version};
- if (!construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), m_tx, 0, tx_key, additional_tx_keys, rct, rct_config))
+ if (!construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), m_tx, tx_key, additional_tx_keys, rct, rct_config))
return false;
get_transaction_prefix_hash(m_tx, m_tx_prefix_hash);
@@ -136,7 +136,7 @@ public:
m_txes.resize(a_num_txes + (extra_outs > 0 ? 1 : 0));
for (size_t n = 0; n < a_num_txes; ++n)
{
- if (!construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), m_txes[n], 0, tx_key, additional_tx_keys, true, {rct::RangeProofPaddedBulletproof, 2}))
+ if (!construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), m_txes[n], tx_key, additional_tx_keys, true, {rct::RangeProofPaddedBulletproof, 2}))
return false;
}
@@ -147,7 +147,7 @@ public:
for (size_t n = 1; n < extra_outs; ++n)
destinations.push_back(tx_destination_entry(1, m_alice.get_keys().m_account_address, false));
- if (!construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), m_txes.back(), 0, tx_key, additional_tx_keys, true, {rct::RangeProofMultiOutputBulletproof, 2}))
+ if (!construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), m_txes.back(), tx_key, additional_tx_keys, true, {rct::RangeProofMultiOutputBulletproof, 2}))
return false;
}
diff --git a/tests/performance_tests/construct_tx.h b/tests/performance_tests/construct_tx.h
index 4b3f061c4..14a603ca5 100644
--- a/tests/performance_tests/construct_tx.h
+++ b/tests/performance_tests/construct_tx.h
@@ -74,7 +74,7 @@ public:
std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
subaddresses[this->m_miners[this->real_source_idx].get_keys().m_account_address.m_spend_public_key] = {0,0};
rct::RCTConfig rct_config{range_proof_type, bp_version};
- return cryptonote::construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, m_destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), m_tx, 0, tx_key, additional_tx_keys, rct, rct_config);
+ return cryptonote::construct_tx_and_get_tx_key(this->m_miners[this->real_source_idx].get_keys(), subaddresses, this->m_sources, m_destinations, cryptonote::account_public_address{}, std::vector<uint8_t>(), m_tx, tx_key, additional_tx_keys, rct, rct_config);
}
private:
diff --git a/tests/performance_tests/ge_frombytes_vartime.h b/tests/performance_tests/ge_frombytes_vartime.h
index d543ed720..d3d717195 100644
--- a/tests/performance_tests/ge_frombytes_vartime.h
+++ b/tests/performance_tests/ge_frombytes_vartime.h
@@ -57,7 +57,7 @@ public:
std::vector<tx_destination_entry> destinations;
destinations.push_back(tx_destination_entry(1, m_alice.get_keys().m_account_address, false));
- if (!construct_tx(this->m_miners[this->real_source_idx].get_keys(), this->m_sources, destinations, boost::none, std::vector<uint8_t>(), m_tx, 0))
+ if (!construct_tx(this->m_miners[this->real_source_idx].get_keys(), this->m_sources, destinations, boost::none, std::vector<uint8_t>(), m_tx))
return false;
const cryptonote::txin_to_key& txin = boost::get<cryptonote::txin_to_key>(m_tx.vin[0]);
diff --git a/tests/performance_tests/ge_tobytes.h b/tests/performance_tests/ge_tobytes.h
index a3c6121b1..7adf1dcea 100644
--- a/tests/performance_tests/ge_tobytes.h
+++ b/tests/performance_tests/ge_tobytes.h
@@ -57,7 +57,7 @@ public:
std::vector<tx_destination_entry> destinations;
destinations.push_back(tx_destination_entry(1, m_alice.get_keys().m_account_address, false));
- if (!construct_tx(this->m_miners[this->real_source_idx].get_keys(), this->m_sources, destinations, boost::none, std::vector<uint8_t>(), m_tx, 0))
+ if (!construct_tx(this->m_miners[this->real_source_idx].get_keys(), this->m_sources, destinations, boost::none, std::vector<uint8_t>(), m_tx))
return false;
const cryptonote::txin_to_key& txin = boost::get<cryptonote::txin_to_key>(m_tx.vin[0]);
diff --git a/tests/performance_tests/performance_tests.h b/tests/performance_tests/performance_tests.h
index 0f16ff8fc..68679a36c 100644
--- a/tests/performance_tests/performance_tests.h
+++ b/tests/performance_tests/performance_tests.h
@@ -249,7 +249,7 @@ bool run_test(const std::string &filter, ParamsT &params_shuttle, const char* te
double stddev = runner.get_stddev();
double npskew = runner.get_non_parametric_skew();
- std::vector<TimingsDatabase::instance> prev_instances = params.td.get(test_name);
+ const TimingsDatabase::instance* prev_instance = params.td.get_most_recent(test_name);
params.td.add(test_name, {time(NULL), runner.get_size(), min, max, mean, med, stddev, npskew, quantiles});
std::cout << (params.verbose ? " time per call: " : " ") << time_per_call << " " << unit << "/call" << (params.verbose ? "\n" : "");
@@ -260,15 +260,14 @@ bool run_test(const std::string &filter, ParamsT &params_shuttle, const char* te
uint64_t p95s = quantiles[9] / scale;
uint64_t stddevs = stddev / scale;
std::string cmp;
- if (!prev_instances.empty())
+ if (prev_instance)
{
- const TimingsDatabase::instance &prev_instance = prev_instances.back();
- if (!runner.is_same_distribution(prev_instance.npoints, prev_instance.mean, prev_instance.stddev))
+ if (!runner.is_same_distribution(prev_instance->npoints, prev_instance->mean, prev_instance->stddev))
{
- double pc = fabs(100. * (prev_instance.mean - runner.get_mean()) / prev_instance.mean);
- cmp = ", " + std::to_string(pc) + "% " + (mean > prev_instance.mean ? "slower" : "faster");
+ double pc = fabs(100. * (prev_instance->mean - runner.get_mean()) / prev_instance->mean);
+ cmp = ", " + std::to_string(pc) + "% " + (mean > prev_instance->mean ? "slower" : "faster");
}
- cmp += " -- " + std::to_string(prev_instance.mean);
+ cmp += " -- " + std::to_string(prev_instance->mean);
}
std::cout << " (min " << mins << " " << unit << ", 90th " << p95s << " " << unit << ", median " << meds << " " << unit << ", std dev " << stddevs << " " << unit << ")" << cmp;
}
diff --git a/tests/trezor/trezor_tests.cpp b/tests/trezor/trezor_tests.cpp
index b21da95c0..0fcd10cef 100644
--- a/tests/trezor/trezor_tests.cpp
+++ b/tests/trezor/trezor_tests.cpp
@@ -2206,6 +2206,7 @@ bool gen_trezor_wallet_passphrase::generate(std::vector<test_event_entry>& event
const auto wallet_path = (m_wallet_dir / "alice2").string();
const epee::wipeable_string& password = epee::wipeable_string("test-pass");
+ wallet_accessor_test::set_password(m_wl_alice2.get(), password);
m_wl_alice2->store_to(wallet_path, password);
// Positive load
diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt
index 212f834d2..567ca8b00 100644
--- a/tests/unit_tests/CMakeLists.txt
+++ b/tests/unit_tests/CMakeLists.txt
@@ -51,7 +51,6 @@ set(unit_tests_sources
epee_serialization.cpp
epee_utils.cpp
expect.cpp
- fee.cpp
json_serialization.cpp
get_xtype_from_string.cpp
hashchain.cpp
diff --git a/tests/unit_tests/crypto.cpp b/tests/unit_tests/crypto.cpp
index 88ecb5853..9f79ed60e 100644
--- a/tests/unit_tests/crypto.cpp
+++ b/tests/unit_tests/crypto.cpp
@@ -112,6 +112,7 @@ TEST(Crypto, tree_branch)
{
crypto::hash inputs[6];
crypto::hash branch[8];
+ crypto::hash branch_1[8 + 1];
crypto::hash root, root2;
size_t depth;
uint32_t path, path2;
@@ -296,12 +297,16 @@ TEST(Crypto, tree_branch)
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));
+ // a version with an extra (dummy) hash
+ memcpy(branch_1, branch, sizeof(branch));
+ branch_1[depth] = crypto::null_hash;
+
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_1, 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));
+ ASSERT_FALSE(crypto::is_branch_in_tree(inputs[4].data, root.data, (const char(*)[32])(branch_1 + 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));
diff --git a/tests/unit_tests/fee.cpp b/tests/unit_tests/fee.cpp
deleted file mode 100644
index 1df1a4f04..000000000
--- a/tests/unit_tests/fee.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-// Copyright (c) 2014-2023, 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.
-//
-// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
-
-#include "gtest/gtest.h"
-
-#include "cryptonote_core/blockchain.h"
-
-using namespace cryptonote;
-
-namespace
-{
- static uint64_t clamp_fee(uint64_t fee)
- {
- static uint64_t mask = 0;
- if (mask == 0)
- {
- mask = 1;
- for (size_t n = PER_KB_FEE_QUANTIZATION_DECIMALS; n < CRYPTONOTE_DISPLAY_DECIMAL_POINT; ++n)
- mask *= 10;
- }
- return (fee + mask - 1) / mask * mask;
- }
-
- //--------------------------------------------------------------------------------------------------------------------
- class fee : public ::testing::Test
- {
- };
-
- // try with blocks ~ 1GB. Passing 2 GB will break on 32 bit systems
-
- TEST_F(fee, 10xmr)
- {
- // CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 and lower are clamped
- ASSERT_EQ(Blockchain::get_dynamic_base_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2, 3), clamp_fee(2000000000));
- ASSERT_EQ(Blockchain::get_dynamic_base_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 2, 3), clamp_fee(2000000000));
- ASSERT_EQ(Blockchain::get_dynamic_base_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 100, 3), clamp_fee(2000000000));
- ASSERT_EQ(Blockchain::get_dynamic_base_fee(10000000000000, 1, 3), 2000000000);
-
- // higher is inverse proportional
- ASSERT_EQ(Blockchain::get_dynamic_base_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 2, 3), clamp_fee(2000000000 / 2));
- ASSERT_EQ(Blockchain::get_dynamic_base_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 10, 3), clamp_fee(2000000000 / 10));
- ASSERT_EQ(Blockchain::get_dynamic_base_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 1000, 3), clamp_fee(2000000000 / 1000));
- ASSERT_EQ(Blockchain::get_dynamic_base_fee(10000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 20000ull, 3), clamp_fee(2000000000 / 20000));
- }
-
- TEST_F(fee, 1xmr)
- {
- // CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 and lower are clamped
- ASSERT_EQ(Blockchain::get_dynamic_base_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2, 3), clamp_fee(200000000));
- ASSERT_EQ(Blockchain::get_dynamic_base_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 2, 3), clamp_fee(200000000));
- ASSERT_EQ(Blockchain::get_dynamic_base_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 100, 3), clamp_fee(200000000));
- ASSERT_EQ(Blockchain::get_dynamic_base_fee(1000000000000, 1, 3), 200000000);
-
- // higher is inverse proportional
- ASSERT_EQ(Blockchain::get_dynamic_base_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 2, 3), clamp_fee(200000000 / 2));
- ASSERT_EQ(Blockchain::get_dynamic_base_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 10, 3), clamp_fee(200000000 / 10));
- ASSERT_EQ(Blockchain::get_dynamic_base_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 1000, 3), clamp_fee(200000000 / 1000));
- ASSERT_EQ(Blockchain::get_dynamic_base_fee(1000000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 20000ull, 3), clamp_fee(200000000 / 20000));
- }
-
- TEST_F(fee, dot3xmr)
- {
- // CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 and lower are clamped
- ASSERT_EQ(Blockchain::get_dynamic_base_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2, 3), clamp_fee(60000000));
- ASSERT_EQ(Blockchain::get_dynamic_base_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 2, 3), clamp_fee(60000000));
- ASSERT_EQ(Blockchain::get_dynamic_base_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 / 100, 3), clamp_fee(60000000));
- ASSERT_EQ(Blockchain::get_dynamic_base_fee(300000000000, 1, 3), 60000000);
-
- // higher is inverse proportional
- ASSERT_EQ(Blockchain::get_dynamic_base_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 2, 3), clamp_fee(60000000 / 2));
- ASSERT_EQ(Blockchain::get_dynamic_base_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 10, 3), clamp_fee(60000000 / 10));
- ASSERT_EQ(Blockchain::get_dynamic_base_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 1000, 3), clamp_fee(60000000 / 1000));
- ASSERT_EQ(Blockchain::get_dynamic_base_fee(300000000000, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 20000ull, 3), clamp_fee(60000000 / 20000));
- }
-
- static bool is_more_or_less(double x, double y)
- {
- return fabs(y - x) < 0.001;
- }
-
- static const double MAX_MULTIPLIER = 166.f;
-
- TEST_F(fee, double_at_full)
- {
- static const uint64_t block_rewards[] = {
- 20000000000000ull, // 20 monero
- 13000000000000ull,
- 1000000000000ull,
- 600000000000ull, // .6 monero, minimum reward per block at 2min
- 300000000000ull, // .3 monero, minimum reward per block at 1min
- };
- static const uint64_t median_block_weights[] = {
- CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2,
- CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 2,
- CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 10,
- CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 1000,
- // with clamping, the formula does not hold for such large blocks and small fees
- // CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 * 20000ull
- };
-
- for (uint64_t block_reward: block_rewards)
- {
- for (uint64_t median_block_weight: median_block_weights)
- {
- ASSERT_TRUE(is_more_or_less(Blockchain::get_dynamic_base_fee(block_reward, median_block_weight, 3) * (median_block_weight / 1024.) * MAX_MULTIPLIER / (double)block_reward, 1.992 * 1000 / 1024));
- }
- }
- }
-}
diff --git a/tests/unit_tests/json_serialization.cpp b/tests/unit_tests/json_serialization.cpp
index aa46b68dc..9525d23ea 100644
--- a/tests/unit_tests/json_serialization.cpp
+++ b/tests/unit_tests/json_serialization.cpp
@@ -78,7 +78,7 @@ namespace test
std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses;
subaddresses[from.m_account_address.m_spend_public_key] = {0,0};
- if (!cryptonote::construct_tx_and_get_tx_key(from, subaddresses, actual_sources, to, boost::none, {}, tx, 0, tx_key, extra_keys, rct, { bulletproof ? rct::RangeProofBulletproof : rct::RangeProofBorromean, bulletproof ? 2 : 0 }))
+ if (!cryptonote::construct_tx_and_get_tx_key(from, subaddresses, actual_sources, to, boost::none, {}, tx, tx_key, extra_keys, rct, { bulletproof ? rct::RangeProofBulletproof : rct::RangeProofBorromean, bulletproof ? 2 : 0 }))
throw std::runtime_error{"transaction construction error"};
return tx;
diff --git a/tests/unit_tests/levin.cpp b/tests/unit_tests/levin.cpp
index 15ece14a8..d686df87d 100644
--- a/tests/unit_tests/levin.cpp
+++ b/tests/unit_tests/levin.cpp
@@ -591,6 +591,7 @@ TEST_F(levin_notify, defaulted)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_FALSE(status.has_outgoing);
}
EXPECT_TRUE(notifier.send_txs({}, random_generator_(), cryptonote::relay_method::local));
@@ -611,6 +612,7 @@ TEST_F(levin_notify, fluff_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -658,6 +660,7 @@ TEST_F(levin_notify, stem_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -731,6 +734,7 @@ TEST_F(levin_notify, stem_no_outs_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_FALSE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -788,6 +792,7 @@ TEST_F(levin_notify, local_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -897,6 +902,7 @@ TEST_F(levin_notify, forward_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -970,6 +976,7 @@ TEST_F(levin_notify, block_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1000,6 +1007,7 @@ TEST_F(levin_notify, none_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1030,6 +1038,7 @@ TEST_F(levin_notify, fluff_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1077,6 +1086,7 @@ TEST_F(levin_notify, stem_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1145,6 +1155,7 @@ TEST_F(levin_notify, stem_no_outs_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_FALSE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1202,6 +1213,7 @@ TEST_F(levin_notify, local_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1303,6 +1315,7 @@ TEST_F(levin_notify, forward_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1371,6 +1384,7 @@ TEST_F(levin_notify, block_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1401,6 +1415,7 @@ TEST_F(levin_notify, none_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1431,6 +1446,7 @@ TEST_F(levin_notify, private_fluff_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1483,6 +1499,7 @@ TEST_F(levin_notify, private_stem_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1535,6 +1552,7 @@ TEST_F(levin_notify, private_local_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1587,6 +1605,7 @@ TEST_F(levin_notify, private_forward_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1639,6 +1658,7 @@ TEST_F(levin_notify, private_block_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1670,6 +1690,7 @@ TEST_F(levin_notify, private_none_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1700,6 +1721,7 @@ TEST_F(levin_notify, private_fluff_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1751,6 +1773,7 @@ TEST_F(levin_notify, private_stem_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1802,6 +1825,7 @@ TEST_F(levin_notify, private_local_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1853,6 +1877,7 @@ TEST_F(levin_notify, private_forward_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1904,6 +1929,7 @@ TEST_F(levin_notify, private_block_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1934,6 +1960,7 @@ TEST_F(levin_notify, private_none_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1966,6 +1993,7 @@ TEST_F(levin_notify, stem_mappings)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -2090,6 +2118,7 @@ TEST_F(levin_notify, fluff_multiple)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -2206,12 +2235,14 @@ TEST_F(levin_notify, noise)
const auto status = notifier.get_status();
EXPECT_TRUE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_FALSE(status.has_outgoing);
}
ASSERT_LT(0u, io_service_.poll());
{
const auto status = notifier.get_status();
EXPECT_TRUE(status.has_noise);
EXPECT_TRUE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.run_stems();
@@ -2298,12 +2329,14 @@ TEST_F(levin_notify, noise_stem)
const auto status = notifier.get_status();
EXPECT_TRUE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
+ EXPECT_FALSE(status.has_outgoing);
}
ASSERT_LT(0u, io_service_.poll());
{
const auto status = notifier.get_status();
EXPECT_TRUE(status.has_noise);
EXPECT_TRUE(status.connections_filled);
+ EXPECT_TRUE(status.has_outgoing);
}
notifier.run_stems();
diff --git a/tests/unit_tests/multisig.cpp b/tests/unit_tests/multisig.cpp
index a79b81e84..1b3a455c0 100644
--- a/tests/unit_tests/multisig.cpp
+++ b/tests/unit_tests/multisig.cpp
@@ -149,6 +149,7 @@ static void check_results(const std::vector<std::string> &intermediate_infos,
std::unordered_set<crypto::secret_key> unique_privkeys;
rct::key composite_pubkey = rct::identity();
+ ASSERT_TRUE(wallets.size() > 0);
wallets[0].decrypt_keys("");
crypto::public_key spend_pubkey = wallets[0].get_account().get_keys().m_account_address.m_spend_public_key;
crypto::secret_key view_privkey = wallets[0].get_account().get_keys().m_view_secret_key;
@@ -156,32 +157,48 @@ static void check_results(const std::vector<std::string> &intermediate_infos,
EXPECT_TRUE(crypto::secret_key_to_public_key(view_privkey, view_pubkey));
wallets[0].encrypt_keys("");
- for (size_t i = 0; i < wallets.size(); ++i)
+ // at the end of multisig kex, all wallets should emit a post-kex message with the same two pubkeys
+ std::vector<crypto::public_key> post_kex_msg_pubkeys;
+ ASSERT_TRUE(intermediate_infos.size() == wallets.size());
+ for (const std::string &intermediate_info : intermediate_infos)
{
- EXPECT_TRUE(!intermediate_infos[i].empty());
- bool ready;
- uint32_t threshold, total;
- EXPECT_TRUE(wallets[i].multisig(&ready, &threshold, &total));
- EXPECT_TRUE(ready);
- EXPECT_TRUE(threshold == M);
- EXPECT_TRUE(total == wallets.size());
+ multisig::multisig_kex_msg post_kex_msg;
+ EXPECT_TRUE(!intermediate_info.empty());
+ EXPECT_NO_THROW(post_kex_msg = intermediate_info);
- wallets[i].decrypt_keys("");
+ if (post_kex_msg_pubkeys.size() != 0)
+ EXPECT_TRUE(post_kex_msg_pubkeys == post_kex_msg.get_msg_pubkeys()); //assumes sorting is always the same
+ else
+ post_kex_msg_pubkeys = post_kex_msg.get_msg_pubkeys();
- if (i != 0)
- {
- // "equals" is transitive relation so we need only to compare first wallet's address to each others' addresses.
- // no need to compare 0's address with itself.
- EXPECT_TRUE(wallets[0].get_account().get_public_address_str(cryptonote::TESTNET) ==
- wallets[i].get_account().get_public_address_str(cryptonote::TESTNET));
-
- EXPECT_EQ(spend_pubkey, wallets[i].get_account().get_keys().m_account_address.m_spend_public_key);
- EXPECT_EQ(view_privkey, wallets[i].get_account().get_keys().m_view_secret_key);
- EXPECT_EQ(view_pubkey, wallets[i].get_account().get_keys().m_account_address.m_view_public_key);
- }
+ EXPECT_TRUE(post_kex_msg_pubkeys.size() == 2);
+ }
+
+ // the post-kex pubkeys should equal the account's public view and spend keys
+ EXPECT_TRUE(std::find(post_kex_msg_pubkeys.begin(), post_kex_msg_pubkeys.end(), spend_pubkey) != post_kex_msg_pubkeys.end());
+ EXPECT_TRUE(std::find(post_kex_msg_pubkeys.begin(), post_kex_msg_pubkeys.end(), view_pubkey) != post_kex_msg_pubkeys.end());
+
+ // each wallet should have the same state (private view key, public spend key), and the public spend key should be
+ // reproducible from the private spend keys found in each account
+ for (tools::wallet2 &wallet : wallets)
+ {
+ wallet.decrypt_keys("");
+ const multisig::multisig_account_status ms_status{wallet.get_multisig_status()};
+ EXPECT_TRUE(ms_status.multisig_is_active);
+ EXPECT_TRUE(ms_status.kex_is_done);
+ EXPECT_TRUE(ms_status.is_ready);
+ EXPECT_TRUE(ms_status.threshold == M);
+ EXPECT_TRUE(ms_status.total == wallets.size());
+
+ EXPECT_TRUE(wallets[0].get_account().get_public_address_str(cryptonote::TESTNET) ==
+ wallet.get_account().get_public_address_str(cryptonote::TESTNET));
+
+ EXPECT_EQ(spend_pubkey, wallet.get_account().get_keys().m_account_address.m_spend_public_key);
+ EXPECT_EQ(view_privkey, wallet.get_account().get_keys().m_view_secret_key);
+ EXPECT_EQ(view_pubkey, wallet.get_account().get_keys().m_account_address.m_view_public_key);
// sum together unique multisig keys
- for (const auto &privkey : wallets[i].get_account().get_keys().m_multisig_keys)
+ for (const auto &privkey : wallet.get_account().get_keys().m_multisig_keys)
{
EXPECT_NE(privkey, crypto::null_skey);
@@ -189,17 +206,17 @@ static void check_results(const std::vector<std::string> &intermediate_infos,
{
unique_privkeys.insert(privkey);
crypto::public_key pubkey;
- crypto::secret_key_to_public_key(privkey, pubkey);
+ EXPECT_TRUE(crypto::secret_key_to_public_key(privkey, pubkey));
EXPECT_NE(privkey, crypto::null_skey);
EXPECT_NE(pubkey, crypto::null_pkey);
EXPECT_NE(pubkey, rct::rct2pk(rct::identity()));
rct::addKeys(composite_pubkey, composite_pubkey, rct::pk2rct(pubkey));
}
}
- wallets[i].encrypt_keys("");
+ wallet.encrypt_keys("");
}
- // final key via sums should equal the wallets' public spend key
+ // final key via sum of privkeys should equal the wallets' public spend key
wallets[0].decrypt_keys("");
EXPECT_EQ(wallets[0].get_account().get_keys().m_account_address.m_spend_public_key, rct::rct2pk(composite_pubkey));
wallets[0].encrypt_keys("");
@@ -226,10 +243,8 @@ static void make_wallets(const unsigned int M, const unsigned int N, const bool
}
// wallets should not be multisig yet
- for (const auto &wallet: wallets)
- {
- ASSERT_FALSE(wallet.multisig());
- }
+ for (const auto& wallet: wallets)
+ ASSERT_FALSE(wallet.get_multisig_status().multisig_is_active);
// make wallets multisig, get second round kex messages (if appropriate)
std::vector<std::string> intermediate_infos(wallets.size());
@@ -242,16 +257,15 @@ static void make_wallets(const unsigned int M, const unsigned int N, const bool
++rounds_complete;
// perform kex rounds until kex is complete
- bool ready;
- wallets[0].multisig(&ready);
- while (!ready)
+ multisig::multisig_account_status ms_status{wallets[0].get_multisig_status()};
+ while (!ms_status.is_ready)
{
if (force_update)
intermediate_infos = exchange_round_force_update(wallets, intermediate_infos, rounds_complete + 1);
else
intermediate_infos = exchange_round(wallets, intermediate_infos);
- wallets[0].multisig(&ready);
+ ms_status = wallets[0].get_multisig_status();
++rounds_complete;
}
@@ -260,6 +274,104 @@ static void make_wallets(const unsigned int M, const unsigned int N, const bool
check_results(intermediate_infos, wallets, M);
}
+static void make_wallets_boosting(std::vector<tools::wallet2>& wallets, unsigned int M)
+{
+ ASSERT_TRUE(wallets.size() > 1 && wallets.size() <= KEYS_COUNT);
+ ASSERT_TRUE(M <= wallets.size());
+ std::uint32_t kex_rounds_required = multisig::multisig_kex_rounds_required(wallets.size(), M);
+ std::uint32_t rounds_required = multisig::multisig_setup_rounds_required(wallets.size(), M);
+ std::uint32_t rounds_complete{0};
+
+ // initialize wallets, get first round multisig kex msgs
+ std::vector<std::string> initial_infos(wallets.size());
+
+ for (size_t i = 0; i < wallets.size(); ++i)
+ {
+ make_wallet(i, wallets[i]);
+
+ wallets[i].decrypt_keys("");
+ initial_infos[i] = wallets[i].get_multisig_first_kex_msg();
+ wallets[i].encrypt_keys("");
+ }
+
+ // wallets should not be multisig yet
+ for (const auto &wallet: wallets)
+ {
+ const multisig::multisig_account_status ms_status{wallet.get_multisig_status()};
+ ASSERT_FALSE(ms_status.multisig_is_active);
+ }
+
+ // get round 2 booster messages for wallet0 (if appropriate)
+ auto initial_infos_truncated = initial_infos;
+ initial_infos_truncated.erase(initial_infos_truncated.begin());
+
+ std::vector<std::string> wallet0_booster_infos;
+ wallet0_booster_infos.reserve(wallets.size() - 1);
+
+ if (rounds_complete + 1 < kex_rounds_required)
+ {
+ for (size_t i = 1; i < wallets.size(); ++i)
+ {
+ wallet0_booster_infos.push_back(
+ wallets[i].get_multisig_key_exchange_booster("", initial_infos_truncated, M, wallets.size())
+ );
+ }
+ }
+
+ // make wallets multisig
+ std::vector<std::string> intermediate_infos(wallets.size());
+
+ for (size_t i = 0; i < wallets.size(); ++i)
+ intermediate_infos[i] = wallets[i].make_multisig("", initial_infos, M);
+
+ ++rounds_complete;
+
+ // perform all kex rounds
+ // boost wallet0 each round, so wallet0 is always 1 round ahead
+ std::string wallet0_intermediate_info;
+ std::vector<std::string> new_infos(intermediate_infos.size());
+ multisig::multisig_account_status ms_status{wallets[0].get_multisig_status()};
+ while (!ms_status.is_ready)
+ {
+ // use booster infos to update wallet0 'early'
+ if (rounds_complete < kex_rounds_required)
+ new_infos[0] = wallets[0].exchange_multisig_keys("", wallet0_booster_infos);
+ else
+ {
+ // force update the post-kex round with wallet0's post-kex message since wallet0 is 'ahead' of the other wallets
+ wallet0_booster_infos = {wallets[0].exchange_multisig_keys("", {})};
+ new_infos[0] = wallets[0].exchange_multisig_keys("", wallet0_booster_infos, true);
+ }
+
+ // get wallet0 booster infos for next round
+ if (rounds_complete + 1 < kex_rounds_required)
+ {
+ // remove wallet0 info for this round (so boosters have incomplete kex message set)
+ auto intermediate_infos_truncated = intermediate_infos;
+ intermediate_infos_truncated.erase(intermediate_infos_truncated.begin());
+
+ // obtain booster messages from all other wallets
+ for (size_t i = 1; i < wallets.size(); ++i)
+ {
+ wallet0_booster_infos[i-1] =
+ wallets[i].get_multisig_key_exchange_booster("", intermediate_infos_truncated, M, wallets.size());
+ }
+ }
+
+ // update other wallets
+ for (size_t i = 1; i < wallets.size(); ++i)
+ new_infos[i] = wallets[i].exchange_multisig_keys("", intermediate_infos);
+
+ intermediate_infos = new_infos;
+ ++rounds_complete;
+ ms_status = wallets[0].get_multisig_status();
+ }
+
+ EXPECT_EQ(rounds_required, rounds_complete);
+
+ check_results(intermediate_infos, wallets, M);
+}
+
TEST(multisig, make_1_2)
{
make_wallets(1, 2, false);
@@ -296,6 +408,12 @@ TEST(multisig, make_2_4)
make_wallets(2, 4, true);
}
+TEST(multisig, make_2_4_boosting)
+{
+ std::vector<tools::wallet2> wallets(4);
+ make_wallets_boosting(wallets, 2);
+}
+
TEST(multisig, multisig_kex_msg)
{
using namespace multisig;
diff --git a/tests/unit_tests/scaling_2021.cpp b/tests/unit_tests/scaling_2021.cpp
index d90f0f9e6..59e036d10 100644
--- a/tests/unit_tests/scaling_2021.cpp
+++ b/tests/unit_tests/scaling_2021.cpp
@@ -30,68 +30,26 @@
// - https://github.com/ArticMine/Monero-Documents/blob/master/MoneroScaling2021.pdf
// - https://github.com/monero-project/research-lab/issues/70
-#define IN_UNIT_TESTS
-
#include "gtest/gtest.h"
#include "cryptonote_core/blockchain.h"
-#include "cryptonote_core/tx_pool.h"
-#include "cryptonote_core/cryptonote_core.h"
-#include "blockchain_db/testdb.h"
-
-namespace
-{
-
-class TestDB: public cryptonote::BaseTestDB
-{
-public:
- TestDB() { m_open = true; }
-};
-
-}
-
-#define PREFIX_WINDOW(hf_version,window) \
- struct get_test_options { \
- const std::pair<uint8_t, uint64_t> hard_forks[3]; \
- const cryptonote::test_options test_options = { \
- hard_forks, \
- window, \
- }; \
- get_test_options(): hard_forks{std::make_pair(1, (uint64_t)0), std::make_pair((uint8_t)hf_version, (uint64_t)1), std::make_pair((uint8_t)0, (uint64_t)0)} {} \
- } opts; \
- cryptonote::BlockchainAndPool bap; \
- cryptonote::Blockchain *blockchain = &bap.blockchain; \
- cryptonote::Blockchain *bc = blockchain; \
- bool r = blockchain->init(new TestDB(), cryptonote::FAKECHAIN, true, &opts.test_options, 0, NULL); \
- ASSERT_TRUE(r)
-
-#define PREFIX(hf_version) PREFIX_WINDOW(hf_version, TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW)
TEST(fee_2021_scaling, relay_fee_cases_from_pdf)
{
- PREFIX_WINDOW(HF_VERSION_2021_SCALING, CRYPTONOTE_LONG_TERM_BLOCK_WEIGHT_WINDOW_SIZE);
-
- ASSERT_EQ(bc->get_dynamic_base_fee(1200000000000, 300000, HF_VERSION_2021_SCALING-1), 8000);
- ASSERT_EQ(bc->get_dynamic_base_fee(1200000000000, 300000, HF_VERSION_2021_SCALING), 38000);
- ASSERT_EQ(bc->get_dynamic_base_fee(1200000000000, 1425000, HF_VERSION_2021_SCALING-1), 1684 /*1680*/);
- ASSERT_EQ(bc->get_dynamic_base_fee(1200000000000, 1425000, HF_VERSION_2021_SCALING), 1684 /*1680*/);
- ASSERT_EQ(bc->get_dynamic_base_fee(1200000000000, 1500000, HF_VERSION_2021_SCALING-1), 1600);
- ASSERT_EQ(bc->get_dynamic_base_fee(1200000000000, 1500000, HF_VERSION_2021_SCALING), 1520);
-
- ASSERT_EQ(bc->get_dynamic_base_fee(600000000000, 300000, HF_VERSION_2021_SCALING-1), 4000);
- ASSERT_EQ(bc->get_dynamic_base_fee(600000000000, 300000, HF_VERSION_2021_SCALING), 19000);
- ASSERT_EQ(bc->get_dynamic_base_fee(600000000000, 1425000, HF_VERSION_2021_SCALING-1), 842 /*840*/);
- ASSERT_EQ(bc->get_dynamic_base_fee(600000000000, 1425000, HF_VERSION_2021_SCALING), 842 /*840*/);
- ASSERT_EQ(bc->get_dynamic_base_fee(600000000000, 1500000, HF_VERSION_2021_SCALING-1), 800);
- ASSERT_EQ(bc->get_dynamic_base_fee(600000000000, 1500000, HF_VERSION_2021_SCALING), 760);
+ ASSERT_EQ(cryptonote::Blockchain::get_dynamic_base_fee(1200000000000, 300000), 38000);
+ ASSERT_EQ(cryptonote::Blockchain::get_dynamic_base_fee(1200000000000, 1425000), 1684 /*1680*/);
+ ASSERT_EQ(cryptonote::Blockchain::get_dynamic_base_fee(1200000000000, 1500000), 1520);
+
+ ASSERT_EQ(cryptonote::Blockchain::get_dynamic_base_fee(600000000000, 300000), 19000);
+ ASSERT_EQ(cryptonote::Blockchain::get_dynamic_base_fee(600000000000, 1425000), 842 /*840*/);
+ ASSERT_EQ(cryptonote::Blockchain::get_dynamic_base_fee(600000000000, 1500000), 760);
}
TEST(fee_2021_scaling, wallet_fee_cases_from_pdf)
{
- PREFIX_WINDOW(HF_VERSION_2021_SCALING, CRYPTONOTE_LONG_TERM_BLOCK_WEIGHT_WINDOW_SIZE);
std::vector<uint64_t> fees;
fees.clear();
- bc->get_dynamic_base_fee_estimate_2021_scaling(10, 600000000000, 300000, 300000, fees);
+ cryptonote::Blockchain::get_dynamic_base_fee_estimate_2021_scaling(600000000000, 300000, 300000, fees);
ASSERT_EQ(fees.size(), 4);
ASSERT_EQ(fees[0], 20000);
ASSERT_EQ(fees[1], 80000);
@@ -99,7 +57,7 @@ TEST(fee_2021_scaling, wallet_fee_cases_from_pdf)
ASSERT_EQ(fees[3], 4000000);
fees.clear();
- bc->get_dynamic_base_fee_estimate_2021_scaling(10, 600000000000, 15000000, 300000, fees);
+ cryptonote::Blockchain::get_dynamic_base_fee_estimate_2021_scaling(600000000000, 15000000, 300000, fees);
ASSERT_EQ(fees.size(), 4);
ASSERT_EQ(fees[0], 20000);
ASSERT_EQ(fees[1], 80000);
@@ -107,7 +65,7 @@ TEST(fee_2021_scaling, wallet_fee_cases_from_pdf)
ASSERT_EQ(fees[3], 1300000);
fees.clear();
- bc->get_dynamic_base_fee_estimate_2021_scaling(10, 600000000000, 1425000, 1425000, fees);
+ cryptonote::Blockchain::get_dynamic_base_fee_estimate_2021_scaling(600000000000, 1425000, 1425000, fees);
ASSERT_EQ(fees.size(), 4);
ASSERT_EQ(fees[0], 890);
ASSERT_EQ(fees[1], 3600);
@@ -115,7 +73,7 @@ TEST(fee_2021_scaling, wallet_fee_cases_from_pdf)
ASSERT_EQ(fees[3], 850000 /* 842000 */);
fees.clear();
- bc->get_dynamic_base_fee_estimate_2021_scaling(10, 600000000000, 1500000, 1500000, fees);
+ cryptonote::Blockchain::get_dynamic_base_fee_estimate_2021_scaling(600000000000, 1500000, 1500000, fees);
ASSERT_EQ(fees.size(), 4);
ASSERT_EQ(fees[0], 800);
ASSERT_EQ(fees[1], 3200);
@@ -123,7 +81,7 @@ TEST(fee_2021_scaling, wallet_fee_cases_from_pdf)
ASSERT_EQ(fees[3], 800000);
fees.clear();
- bc->get_dynamic_base_fee_estimate_2021_scaling(10, 600000000000, 75000000, 1500000, fees);
+ cryptonote::Blockchain::get_dynamic_base_fee_estimate_2021_scaling(600000000000, 75000000, 1500000, fees);
ASSERT_EQ(fees.size(), 4);
ASSERT_EQ(fees[0], 800);
ASSERT_EQ(fees[1], 3200);
diff --git a/tests/unit_tests/serialization.cpp b/tests/unit_tests/serialization.cpp
index ab81acefc..2af8012ed 100644
--- a/tests/unit_tests/serialization.cpp
+++ b/tests/unit_tests/serialization.cpp
@@ -51,11 +51,21 @@
using namespace std;
using namespace crypto;
+static_assert(!std::is_trivially_copyable<std::vector<unsigned char>>(),
+ "should fail to compile when applying blob serializer");
+static_assert(!std::is_trivially_copyable<std::string>(),
+ "should fail to compile when applying blob serializer");
+
struct Struct
{
int32_t a;
int32_t b;
char blob[8];
+
+ bool operator==(const Struct &other) const
+ {
+ return a == other.a && b == other.b && 0 == memcmp(blob, other.blob, sizeof(blob));
+ }
};
template <class Archive>
@@ -1207,3 +1217,90 @@ TEST(Serialization, adl_free_function)
const std::string expected = "{\"custom_fieldname\": " + std::to_string(msg.size()) + '"' + epee::string_tools::buff_to_hex_nodelimer(msg) + "\"}";
EXPECT_EQ(expected, ss.str());
}
+
+using Tuple3 = std::tuple<uint16_t, std::string, uint64_t>;
+using Tuple4 = std::tuple<int32_t, std::string, uint64_t, Struct>;
+
+TEST(Serialization, tuple_3_4_backwards_compatibility)
+{
+ std::string serialized;
+
+ ////////////////////////////////////////
+
+ Tuple3 t3{1876, "Hullabaloo", 1963};
+ EXPECT_TRUE(::serialization::dump_binary(t3, serialized));
+
+ EXPECT_EQ("0354070a48756c6c6162616c6f6fab0f",
+ epee::string_tools::buff_to_hex_nodelimer(serialized));
+
+ Tuple3 t3_recovered;
+ EXPECT_TRUE(::serialization::parse_binary(serialized, t3_recovered));
+ EXPECT_EQ(t3, t3_recovered);
+
+ /////////////////////////////////////////
+
+ Tuple4 t4{1999, "Caneck Caneck", (uint64_t)-1, {20229, 242, {1, 1, 2, 3, 5, 8, 13, 21}}};
+ EXPECT_TRUE(::serialization::dump_binary(t4, serialized));
+
+ EXPECT_EQ("04cf0700000d43616e65636b2043616e65636bffffffffffffffffff01054f0000f20000000101020305080d15",
+ epee::string_tools::buff_to_hex_nodelimer(serialized));
+
+ Tuple4 t4_recovered;
+ EXPECT_TRUE(::serialization::parse_binary(serialized, t4_recovered));
+ EXPECT_EQ(t4, t4_recovered);
+}
+
+struct Tupler
+{
+ std::tuple<> t0;
+ std::tuple<int8_t> t1;
+ std::tuple<uint8_t, int16_t> t2;
+ Tuple3 t3_backcompat;
+ Tuple3 t3_compact;
+ Tuple4 t4_backcompat;
+ Tuple4 t4_compact;
+ std::tuple<uint32_t, std::string, bool, int64_t, Struct> t5;
+
+ BEGIN_SERIALIZE_OBJECT()
+ FIELD(t0)
+ FIELD(t1)
+ FIELD(t2)
+ FIELD(t3_backcompat)
+ TUPLE_COMPACT_FIELD(t3_compact)
+ FIELD(t4_backcompat)
+ TUPLE_COMPACT_FIELD(t4_compact)
+ TUPLE_COMPACT_FIELD(t5)
+ END_SERIALIZE()
+};
+
+bool operator==(const Tupler &a, const Tupler &b)
+{
+ return a.t0 == b.t0 && a.t1 == b.t1 && a.t2 == b.t2 && a.t3_backcompat == b.t3_backcompat &&
+ a.t3_compact == b.t3_compact && a.t4_backcompat == b.t4_backcompat && a.t5 == b.t5;
+}
+
+TEST(Serialization, tuple_many_tuples)
+{
+ Tupler tupler{
+ {},
+ {69},
+ {42, 420},
+ {1876, "Hullabaloo", 1963},
+ {1876, "Hullabaloo", 1963},
+ {1999, "Caneck Caneck", (uint64_t)-1, {20229, 242, {1, 1, 2, 3, 5, 8, 13, 21}}},
+ {1999, "Caneck Caneck", (uint64_t)-1, {20229, 242, {1, 1, 2, 3, 5, 8, 13, 21}}},
+ {72982, "He is now rising from affluence to poverty.", false, 256,
+ {
+ 13, 37, { 1, 1, 1, 2, 3, 7, 11, 26 }
+ }
+ }
+ };
+
+ std::string serialized;
+ EXPECT_TRUE(::serialization::dump_binary(tupler, serialized));
+
+ Tupler tupler_recovered;
+ EXPECT_TRUE(::serialization::parse_binary(serialized, tupler_recovered));
+
+ EXPECT_EQ(tupler, tupler_recovered);
+}
diff --git a/tests/unit_tests/wallet_storage.cpp b/tests/unit_tests/wallet_storage.cpp
index ff01e452c..c38839a1c 100644
--- a/tests/unit_tests/wallet_storage.cpp
+++ b/tests/unit_tests/wallet_storage.cpp
@@ -33,6 +33,7 @@
#include "file_io_utils.h"
#include "wallet/wallet2.h"
+#include "common/util.h"
using namespace boost::filesystem;
using namespace epee::file_io_utils;
@@ -52,8 +53,8 @@ TEST(wallet_storage, store_to_file2file)
ASSERT_TRUE(is_file_exist(source_wallet_file.string()));
ASSERT_TRUE(is_file_exist(source_wallet_file.string() + ".keys"));
- copy_file(source_wallet_file, interm_wallet_file, copy_option::overwrite_if_exists);
- copy_file(source_wallet_file.string() + ".keys", interm_wallet_file.string() + ".keys", copy_option::overwrite_if_exists);
+ tools::copy_file(source_wallet_file.string(), interm_wallet_file.string());
+ tools::copy_file(source_wallet_file.string() + ".keys", interm_wallet_file.string() + ".keys");
ASSERT_TRUE(is_file_exist(interm_wallet_file.string()));
ASSERT_TRUE(is_file_exist(interm_wallet_file.string() + ".keys"));
@@ -143,8 +144,8 @@ TEST(wallet_storage, change_password_same_file)
ASSERT_TRUE(is_file_exist(source_wallet_file.string()));
ASSERT_TRUE(is_file_exist(source_wallet_file.string() + ".keys"));
- copy_file(source_wallet_file, interm_wallet_file, copy_option::overwrite_if_exists);
- copy_file(source_wallet_file.string() + ".keys", interm_wallet_file.string() + ".keys", copy_option::overwrite_if_exists);
+ tools::copy_file(source_wallet_file.string(), interm_wallet_file.string());
+ tools::copy_file(source_wallet_file.string() + ".keys", interm_wallet_file.string() + ".keys");
ASSERT_TRUE(is_file_exist(interm_wallet_file.string()));
ASSERT_TRUE(is_file_exist(interm_wallet_file.string() + ".keys"));
@@ -182,8 +183,8 @@ TEST(wallet_storage, change_password_different_file)
ASSERT_TRUE(is_file_exist(source_wallet_file.string()));
ASSERT_TRUE(is_file_exist(source_wallet_file.string() + ".keys"));
- copy_file(source_wallet_file, interm_wallet_file, copy_option::overwrite_if_exists);
- copy_file(source_wallet_file.string() + ".keys", interm_wallet_file.string() + ".keys", copy_option::overwrite_if_exists);
+ tools::copy_file(source_wallet_file.string(), interm_wallet_file.string());
+ tools::copy_file(source_wallet_file.string() + ".keys", interm_wallet_file.string() + ".keys");
ASSERT_TRUE(is_file_exist(interm_wallet_file.string()));
ASSERT_TRUE(is_file_exist(interm_wallet_file.string() + ".keys"));
diff --git a/tests/unit_tests/wipeable_string.cpp b/tests/unit_tests/wipeable_string.cpp
index f1bb90a41..9eecd509a 100644
--- a/tests/unit_tests/wipeable_string.cpp
+++ b/tests/unit_tests/wipeable_string.cpp
@@ -211,3 +211,15 @@ TEST(wipeable_string, to_hex)
ASSERT_TRUE(epee::to_hex::wipeable_string(epee::span<const uint8_t>((const uint8_t*)"", 0)) == epee::wipeable_string(""));
ASSERT_TRUE(epee::to_hex::wipeable_string(epee::span<const uint8_t>((const uint8_t*)"abc", 3)) == epee::wipeable_string("616263"));
}
+
+TEST(wipeable_string, to_string)
+{
+ // Converting a wipeable_string to a string defeats the purpose of wipeable_string,
+ // but nice to know this works
+ std::string str;
+ {
+ epee::wipeable_string wipeable_str("foo");
+ str = std::string(wipeable_str.data(), wipeable_str.size());
+ }
+ ASSERT_TRUE(str == std::string("foo"));
+}
diff --git a/utils/python-rpc/framework/daemon.py b/utils/python-rpc/framework/daemon.py
index c7831d1ee..4ac24332d 100644
--- a/utils/python-rpc/framework/daemon.py
+++ b/utils/python-rpc/framework/daemon.py
@@ -33,11 +33,12 @@ from .rpc import JSONRPC
class Daemon(object):
- def __init__(self, protocol='http', host='127.0.0.1', port=0, idx=0, restricted_rpc = False):
+ def __init__(self, protocol='http', host='127.0.0.1', port=0, idx=0, restricted_rpc = False, username=None, password=None):
base = 18480 if restricted_rpc else 18180
self.host = host
self.port = port
- self.rpc = JSONRPC('{protocol}://{host}:{port}'.format(protocol=protocol, host=host, port=port if port else base+idx))
+ self.rpc = JSONRPC('{protocol}://{host}:{port}'.format(protocol=protocol, host=host, port=port if port else base+idx),
+ username, password)
def getblocktemplate(self, address, prev_block = "", client = ""):
getblocktemplate = {
diff --git a/utils/python-rpc/framework/rpc.py b/utils/python-rpc/framework/rpc.py
index 6d9a4b27e..567bdd78d 100644
--- a/utils/python-rpc/framework/rpc.py
+++ b/utils/python-rpc/framework/rpc.py
@@ -28,6 +28,7 @@
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import requests
+from requests.auth import HTTPDigestAuth
import json
class Response(dict):
@@ -60,14 +61,17 @@ class Response(dict):
return True
class JSONRPC(object):
- def __init__(self, url):
+ def __init__(self, url, username=None, password=None):
self.url = url
+ self.username = username
+ self.password = password
def send_request(self, path, inputs, result_field = None):
res = requests.post(
self.url + path,
data=json.dumps(inputs),
- headers={'content-type': 'application/json'})
+ headers={'content-type': 'application/json'},
+ auth=HTTPDigestAuth(self.username, self.password) if self.username is not None else None)
res = res.json()
assert 'error' not in res, res
diff --git a/utils/python-rpc/framework/wallet.py b/utils/python-rpc/framework/wallet.py
index 18af4edc4..8e67b0107 100644
--- a/utils/python-rpc/framework/wallet.py
+++ b/utils/python-rpc/framework/wallet.py
@@ -33,10 +33,11 @@ from .rpc import JSONRPC
class Wallet(object):
- def __init__(self, protocol='http', host='127.0.0.1', port=0, idx=0):
+ def __init__(self, protocol='http', host='127.0.0.1', port=0, idx=0, username=None, password=None):
self.host = host
self.port = port
- self.rpc = JSONRPC('{protocol}://{host}:{port}'.format(protocol=protocol, host=host, port=port if port else 18090+idx))
+ self.rpc = JSONRPC('{protocol}://{host}:{port}'.format(protocol=protocol, host=host,
+ port=port if port else 18090+idx), username, password)
def transfer(self, destinations, account_index = 0, subaddr_indices = [], priority = 0, ring_size = 0, unlock_time = 0, payment_id = '', get_tx_key = True, do_not_relay = False, get_tx_hex = False, get_tx_metadata = False, subtract_fee_from_outputs = []):
transfer = {
@@ -539,6 +540,20 @@ class Wallet(object):
}
return self.rpc.send_json_rpc_request(exchange_multisig_keys)
+ def get_multisig_key_exchange_booster(self, multisig_info, threshold, num_signers, password = ''):
+ exchange_multisig_keys = {
+ 'method': 'get_multisig_key_exchange_booster',
+ 'params' : {
+ 'multisig_info': multisig_info,
+ 'threshold': threshold,
+ 'num_signers': num_signers,
+ 'password': password,
+ },
+ 'jsonrpc': '2.0',
+ 'id': '0'
+ }
+ return self.rpc.send_json_rpc_request(get_multisig_key_exchange_booster)
+
def export_multisig_info(self):
export_multisig_info = {
'method': 'export_multisig_info',
@@ -1138,3 +1153,45 @@ class Wallet(object):
'id': '0'
}
return self.rpc.send_json_rpc_request(frozen)
+
+ class BackgroundSyncOptions(object):
+ def __init__(self):
+ self.off = 'off'
+ self.reuse_password = 'reuse-wallet-password'
+ self.custom_password = 'custom-background-password'
+ background_sync_options = BackgroundSyncOptions()
+
+ def setup_background_sync(self, background_sync_type = background_sync_options.off, wallet_password = '', background_cache_password = ''):
+ setup_background_sync = {
+ 'method': 'setup_background_sync',
+ 'jsonrpc': '2.0',
+ 'params' : {
+ 'background_sync_type': background_sync_type,
+ 'wallet_password': wallet_password,
+ 'background_cache_password': background_cache_password,
+ },
+ 'id': '0'
+ }
+ return self.rpc.send_json_rpc_request(setup_background_sync)
+
+ def start_background_sync(self):
+ start_background_sync = {
+ 'method': 'start_background_sync',
+ 'jsonrpc': '2.0',
+ 'params' : {},
+ 'id': '0'
+ }
+ return self.rpc.send_json_rpc_request(start_background_sync)
+
+ def stop_background_sync(self, wallet_password = '', seed = '', seed_offset = ''):
+ stop_background_sync = {
+ 'method': 'stop_background_sync',
+ 'jsonrpc': '2.0',
+ 'params' : {
+ 'wallet_password': wallet_password,
+ 'seed': seed,
+ 'seed_offset': seed_offset,
+ },
+ 'id': '0'
+ }
+ return self.rpc.send_json_rpc_request(stop_background_sync)