aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml14
-rw-r--r--ANONYMITY_NETWORKS.md57
-rw-r--r--CMakeLists.txt10
-rw-r--r--CMakeLists_IOS.txt2
-rw-r--r--LICENSE2
-rw-r--r--Makefile6
-rw-r--r--README.md36
-rw-r--r--cmake/32-bit-toolchain.cmake2
-rw-r--r--cmake/64-bit-toolchain.cmake2
-rw-r--r--cmake/CheckTrezor.cmake17
-rw-r--r--cmake/FindUnbound.cmake2
-rw-r--r--cmake/GenVersion.cmake2
-rw-r--r--cmake/Version.cmake2
-rw-r--r--cmake/test-libusb-version.c2
-rw-r--r--cmake/test-protobuf.cpp2
-rw-r--r--cmake/test-static-assert.c2
-rw-r--r--cmake/test-static-assert.cpp2
-rw-r--r--contrib/CMakeLists.txt2
-rw-r--r--contrib/depends/Makefile4
-rw-r--r--contrib/depends/packages/cmake/conf/mxe-conf.cmake.in67
-rw-r--r--contrib/depends/packages/cmake/conf/target-cmake.in29
-rw-r--r--contrib/depends/packages/cmake/test/CMakeLists.txt18
-rw-r--r--contrib/depends/packages/icu4c.mk4
-rw-r--r--contrib/depends/packages/native_protobuf.mk5
-rw-r--r--contrib/depends/packages/openssl.mk12
-rw-r--r--contrib/depends/packages/packages.mk3
-rw-r--r--contrib/depends/packages/readline.mk10
-rw-r--r--contrib/depends/patches/readline/readline-1.patch187
-rw-r--r--contrib/depends/toolchain.cmake.in7
-rw-r--r--contrib/epee/CMakeLists.txt2
-rw-r--r--contrib/epee/demo/iface/transport_defs.h12
-rw-r--r--contrib/epee/include/hex.h9
-rw-r--r--contrib/epee/include/int-util.h2
-rw-r--r--contrib/epee/include/math_helper.h1
-rw-r--r--contrib/epee/include/memwipe.h2
-rw-r--r--contrib/epee/include/misc_language.h5
-rw-r--r--contrib/epee/include/net/abstract_tcp_server2.h53
-rw-r--r--contrib/epee/include/net/abstract_tcp_server2.inl348
-rw-r--r--contrib/epee/include/net/connection_basic.hpp48
-rw-r--r--contrib/epee/include/net/http_auth.h2
-rw-r--r--contrib/epee/include/net/http_client.h27
-rw-r--r--contrib/epee/include/net/http_protocol_handler.inl2
-rw-r--r--contrib/epee/include/net/http_server_impl_base.h9
-rw-r--r--contrib/epee/include/net/jsonrpc_structs.h14
-rw-r--r--contrib/epee/include/net/net_helper.h199
-rw-r--r--contrib/epee/include/net/net_ssl.h68
-rw-r--r--contrib/epee/include/net/net_utils_base.h16
-rw-r--r--contrib/epee/include/net/network_throttle-detail.hpp5
-rw-r--r--contrib/epee/include/net/network_throttle.hpp2
-rw-r--r--contrib/epee/include/span.h2
-rw-r--r--contrib/epee/include/stats.h58
-rw-r--r--contrib/epee/include/stats.inl359
-rw-r--r--contrib/epee/include/wipeable_string.h2
-rw-r--r--contrib/epee/src/CMakeLists.txt4
-rw-r--r--contrib/epee/src/connection_basic.cpp48
-rw-r--r--contrib/epee/src/hex.cpp65
-rw-r--r--contrib/epee/src/http_auth.cpp2
-rw-r--r--contrib/epee/src/memwipe.c2
-rw-r--r--contrib/epee/src/net_ssl.cpp324
-rw-r--r--contrib/epee/src/network_throttle-detail.cpp8
-rw-r--r--contrib/epee/src/network_throttle.cpp2
-rw-r--r--contrib/epee/src/wipeable_string.cpp2
-rw-r--r--contrib/epee/tests/src/net/test_net.h13
-rw-r--r--contrib/gitian/README.md74
-rwxr-xr-xcontrib/gitian/gitian-build.py2
-rw-r--r--contrib/gitian/gitian-osx.yml4
-rw-r--r--external/CMakeLists.txt2
-rw-r--r--external/db_drivers/CMakeLists.txt2
-rw-r--r--external/db_drivers/liblmdb/CMakeLists.txt2
-rw-r--r--external/db_drivers/liblmdb/mdb.c2
-rw-r--r--external/easylogging++/CMakeLists.txt2
-rw-r--r--include/INode.h2
-rw-r--r--include/IWallet.h2
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/blockchain_db/CMakeLists.txt2
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.cpp2
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.h2
-rw-r--r--src/blockchain_db/blockchain_db.cpp25
-rw-r--r--src/blockchain_db/blockchain_db.h31
-rw-r--r--src/blockchain_db/db_types.h2
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp274
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.h17
-rw-r--r--src/blockchain_db/testdb.h (renamed from tests/unit_tests/testdb.h)15
-rw-r--r--src/blockchain_utilities/CMakeLists.txt2
-rw-r--r--src/blockchain_utilities/README.md2
-rw-r--r--src/blockchain_utilities/blockchain_ancestry.cpp2
-rw-r--r--src/blockchain_utilities/blockchain_blackball.cpp2
-rw-r--r--src/blockchain_utilities/blockchain_depth.cpp2
-rw-r--r--src/blockchain_utilities/blockchain_export.cpp2
-rw-r--r--src/blockchain_utilities/blockchain_import.cpp21
-rw-r--r--src/blockchain_utilities/blockchain_prune.cpp18
-rw-r--r--src/blockchain_utilities/blockchain_prune_known_spent_data.cpp2
-rw-r--r--src/blockchain_utilities/blockchain_stats.cpp2
-rw-r--r--src/blockchain_utilities/blockchain_usage.cpp2
-rw-r--r--src/blockchain_utilities/blockchain_utilities.h2
-rw-r--r--src/blockchain_utilities/blocksdat_file.cpp2
-rw-r--r--src/blockchain_utilities/blocksdat_file.h2
-rw-r--r--src/blockchain_utilities/bootstrap_file.cpp2
-rw-r--r--src/blockchain_utilities/bootstrap_file.h2
-rw-r--r--src/blockchain_utilities/bootstrap_serialization.h2
-rw-r--r--src/blocks/CMakeLists.txt2
-rw-r--r--src/blocks/checkpoints.datbin208420 -> 221956 bytes
-rw-r--r--src/checkpoints/CMakeLists.txt2
-rw-r--r--src/checkpoints/checkpoints.cpp3
-rw-r--r--src/checkpoints/checkpoints.h2
-rw-r--r--src/common/CMakeLists.txt4
-rw-r--r--src/common/aligned.c2
-rw-r--r--src/common/apply_permutation.h2
-rw-r--r--src/common/base58.cpp2
-rw-r--r--src/common/base58.h2
-rw-r--r--src/common/boost_serialization_helper.h2
-rw-r--r--src/common/command_line.cpp2
-rw-r--r--src/common/command_line.h2
-rw-r--r--src/common/common_fwd.h2
-rw-r--r--src/common/compat/glibc_compat.cpp2
-rw-r--r--src/common/dns_utils.cpp10
-rw-r--r--src/common/dns_utils.h2
-rw-r--r--src/common/download.cpp6
-rw-r--r--src/common/download.h2
-rw-r--r--src/common/http_connection.h2
-rw-r--r--src/common/i18n.cpp2
-rw-r--r--src/common/i18n.h2
-rw-r--r--src/common/json_util.h2
-rw-r--r--src/common/notify.cpp2
-rw-r--r--src/common/password.cpp2
-rw-r--r--src/common/password.h2
-rw-r--r--src/common/perf_timer.cpp2
-rw-r--r--src/common/perf_timer.h3
-rw-r--r--src/common/pod-class.h2
-rw-r--r--src/common/rpc_client.h2
-rw-r--r--src/common/scoped_message_writer.h2
-rw-r--r--src/common/sfinae_helpers.h2
-rw-r--r--src/common/stack_trace.cpp2
-rw-r--r--src/common/stack_trace.h2
-rw-r--r--src/common/threadpool.cpp2
-rw-r--r--src/common/threadpool.h2
-rw-r--r--src/common/timings.cc125
-rw-r--r--src/common/timings.h34
-rw-r--r--src/common/unordered_containers_boost_serialization.h2
-rw-r--r--src/common/updates.cpp2
-rw-r--r--src/common/updates.h2
-rw-r--r--src/common/util.cpp2
-rw-r--r--src/common/util.h2
-rw-r--r--src/common/varint.h2
-rw-r--r--src/crypto/CMakeLists.txt14
-rw-r--r--src/crypto/CryptonightR_JIT.c110
-rw-r--r--src/crypto/CryptonightR_JIT.h22
-rw-r--r--src/crypto/CryptonightR_template.S1590
-rw-r--r--src/crypto/CryptonightR_template.h1043
-rw-r--r--src/crypto/blake256.c2
-rw-r--r--src/crypto/blake256.h2
-rw-r--r--src/crypto/chacha.h10
-rw-r--r--src/crypto/crypto-ops-data.c2
-rw-r--r--src/crypto/crypto-ops.c2
-rw-r--r--src/crypto/crypto-ops.h2
-rw-r--r--src/crypto/crypto.cpp2
-rw-r--r--src/crypto/crypto.h2
-rw-r--r--src/crypto/crypto_ops_builder/README.md2
-rw-r--r--src/crypto/crypto_ops_builder/crypto-ops-data.c2
-rw-r--r--src/crypto/crypto_ops_builder/crypto-ops-old.c2
-rw-r--r--src/crypto/crypto_ops_builder/crypto-ops.h2
-rw-r--r--src/crypto/crypto_ops_builder/ref10CommentedCombined/MakeCryptoOps.py2
-rw-r--r--src/crypto/crypto_ops_builder/ref10CommentedCombined/crypto-ops.h2
-rw-r--r--src/crypto/generic-ops.h2
-rw-r--r--src/crypto/groestl.h2
-rw-r--r--src/crypto/groestl_tables.h2
-rw-r--r--src/crypto/hash-extra-blake.c2
-rw-r--r--src/crypto/hash-extra-groestl.c2
-rw-r--r--src/crypto/hash-extra-jh.c2
-rw-r--r--src/crypto/hash-extra-skein.c2
-rw-r--r--src/crypto/hash-ops.h4
-rw-r--r--src/crypto/hash.c2
-rw-r--r--src/crypto/hash.h10
-rw-r--r--src/crypto/initializer.h2
-rw-r--r--src/crypto/random.c2
-rw-r--r--src/crypto/random.h2
-rw-r--r--src/crypto/skein_port.h2
-rw-r--r--src/crypto/slow-hash.c259
-rw-r--r--src/crypto/tree-hash.c2
-rw-r--r--src/crypto/variant4_random_math.h441
-rw-r--r--src/cryptonote_basic/CMakeLists.txt2
-rw-r--r--src/cryptonote_basic/account.cpp2
-rw-r--r--src/cryptonote_basic/account.h2
-rw-r--r--src/cryptonote_basic/account_boost_serialization.h2
-rw-r--r--src/cryptonote_basic/blobdatatype.h2
-rw-r--r--src/cryptonote_basic/connection_context.h2
-rw-r--r--src/cryptonote_basic/cryptonote_basic.h27
-rw-r--r--src/cryptonote_basic/cryptonote_basic_impl.cpp2
-rw-r--r--src/cryptonote_basic/cryptonote_basic_impl.h2
-rw-r--r--src/cryptonote_basic/cryptonote_boost_serialization.h19
-rw-r--r--src/cryptonote_basic/cryptonote_format_utils.cpp83
-rw-r--r--src/cryptonote_basic/cryptonote_format_utils.h9
-rw-r--r--src/cryptonote_basic/cryptonote_stat_info.h5
-rw-r--r--src/cryptonote_basic/difficulty.cpp2
-rw-r--r--src/cryptonote_basic/difficulty.h2
-rw-r--r--src/cryptonote_basic/hardfork.cpp4
-rw-r--r--src/cryptonote_basic/hardfork.h2
-rw-r--r--src/cryptonote_basic/miner.cpp88
-rw-r--r--src/cryptonote_basic/miner.h7
-rw-r--r--src/cryptonote_basic/subaddress_index.h2
-rw-r--r--src/cryptonote_basic/tx_extra.h2
-rw-r--r--src/cryptonote_basic/verification_context.h2
-rw-r--r--src/cryptonote_config.h7
-rw-r--r--src/cryptonote_core/CMakeLists.txt2
-rw-r--r--src/cryptonote_core/blockchain.cpp287
-rw-r--r--src/cryptonote_core/blockchain.h27
-rw-r--r--src/cryptonote_core/blockchain_storage_boost_serialization.h2
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp109
-rw-r--r--src/cryptonote_core/cryptonote_core.h19
-rw-r--r--src/cryptonote_core/cryptonote_tx_utils.cpp47
-rw-r--r--src/cryptonote_core/cryptonote_tx_utils.h8
-rw-r--r--src/cryptonote_core/tx_pool.cpp6
-rw-r--r--src/cryptonote_core/tx_pool.h7
-rw-r--r--src/cryptonote_protocol/CMakeLists.txt2
-rw-r--r--src/cryptonote_protocol/block_queue.cpp2
-rw-r--r--src/cryptonote_protocol/block_queue.h2
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_defs.h27
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp2
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler.h2
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler.inl44
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler_common.h2
-rw-r--r--src/daemon/CMakeLists.txt2
-rw-r--r--src/daemon/command_line_args.h2
-rw-r--r--src/daemon/command_parser_executor.cpp15
-rw-r--r--src/daemon/command_parser_executor.h2
-rw-r--r--src/daemon/command_server.cpp6
-rw-r--r--src/daemon/command_server.h2
-rw-r--r--src/daemon/core.h2
-rw-r--r--src/daemon/daemon.cpp2
-rw-r--r--src/daemon/daemon.h2
-rw-r--r--src/daemon/executor.cpp2
-rw-r--r--src/daemon/executor.h2
-rw-r--r--src/daemon/main.cpp2
-rw-r--r--src/daemon/p2p.h2
-rw-r--r--src/daemon/protocol.h2
-rw-r--r--src/daemon/rpc.h2
-rw-r--r--src/daemon/rpc_command_executor.cpp5
-rw-r--r--src/daemon/rpc_command_executor.h2
-rw-r--r--src/daemonizer/CMakeLists.txt2
-rw-r--r--src/daemonizer/daemonizer.h2
-rw-r--r--src/daemonizer/posix_daemonizer.inl2
-rw-r--r--src/daemonizer/posix_fork.h2
-rw-r--r--src/daemonizer/windows_daemonizer.inl2
-rw-r--r--src/daemonizer/windows_service.cpp2
-rw-r--r--src/daemonizer/windows_service.h2
-rw-r--r--src/daemonizer/windows_service_runner.h2
-rw-r--r--src/debug_utilities/CMakeLists.txt2
-rw-r--r--src/debug_utilities/cn_deserialize.cpp2
-rw-r--r--src/debug_utilities/object_sizes.cpp2
-rw-r--r--src/device/CMakeLists.txt2
-rw-r--r--src/device/device.cpp2
-rw-r--r--src/device/device.hpp12
-rw-r--r--src/device/device_cold.hpp2
-rw-r--r--src/device/device_default.cpp55
-rw-r--r--src/device/device_default.hpp11
-rw-r--r--src/device/device_io.hpp2
-rw-r--r--src/device/device_io_hid.cpp2
-rw-r--r--src/device/device_io_hid.hpp2
-rw-r--r--src/device/device_ledger.cpp297
-rw-r--r--src/device/device_ledger.hpp21
-rw-r--r--src/device/log.cpp6
-rw-r--r--src/device/log.hpp2
-rw-r--r--src/device_trezor/CMakeLists.txt8
-rw-r--r--src/device_trezor/device_trezor.cpp19
-rw-r--r--src/device_trezor/device_trezor.hpp2
-rw-r--r--src/device_trezor/device_trezor_base.cpp118
-rw-r--r--src/device_trezor/device_trezor_base.hpp55
-rw-r--r--src/device_trezor/trezor.hpp2
-rw-r--r--src/device_trezor/trezor/debug_link.cpp90
-rw-r--r--src/device_trezor/trezor/debug_link.hpp93
-rw-r--r--src/device_trezor/trezor/exceptions.hpp2
-rw-r--r--src/device_trezor/trezor/messages_map.cpp13
-rw-r--r--src/device_trezor/trezor/messages_map.hpp8
-rw-r--r--src/device_trezor/trezor/protocol.cpp2
-rw-r--r--src/device_trezor/trezor/protocol.hpp2
-rw-r--r--src/device_trezor/trezor/tools/build_protob.py10
-rw-r--r--src/device_trezor/trezor/transport.cpp152
-rw-r--r--src/device_trezor/trezor/transport.hpp23
-rw-r--r--src/device_trezor/trezor/trezor_defs.hpp2
-rw-r--r--src/gen_multisig/CMakeLists.txt2
-rw-r--r--src/gen_multisig/gen_multisig.cpp2
-rw-r--r--src/mnemonics/CMakeLists.txt2
-rw-r--r--src/mnemonics/chinese_simplified.h2
-rw-r--r--src/mnemonics/dutch.h2
-rw-r--r--src/mnemonics/electrum-words.cpp2
-rw-r--r--src/mnemonics/electrum-words.h2
-rw-r--r--src/mnemonics/english.h2
-rw-r--r--src/mnemonics/english_old.h2
-rw-r--r--src/mnemonics/esperanto.h2
-rw-r--r--src/mnemonics/french.h2
-rw-r--r--src/mnemonics/german.h2
-rw-r--r--src/mnemonics/italian.h2
-rw-r--r--src/mnemonics/japanese.h2
-rw-r--r--src/mnemonics/language_base.h2
-rw-r--r--src/mnemonics/lojban.h2
-rw-r--r--src/mnemonics/portuguese.h2
-rw-r--r--src/mnemonics/russian.h2
-rw-r--r--src/mnemonics/singleton.h2
-rw-r--r--src/mnemonics/spanish.h2
-rw-r--r--src/multisig/CMakeLists.txt2
-rw-r--r--src/multisig/multisig.cpp2
-rw-r--r--src/multisig/multisig.h2
-rw-r--r--src/net/CMakeLists.txt6
-rw-r--r--src/net/fwd.h1
-rw-r--r--src/net/i2p_address.cpp200
-rw-r--r--src/net/i2p_address.h140
-rw-r--r--src/net/parse.cpp3
-rw-r--r--src/net/parse.h4
-rw-r--r--src/net/socks.cpp8
-rw-r--r--src/net/socks.h3
-rw-r--r--src/p2p/CMakeLists.txt2
-rw-r--r--src/p2p/net_node.cpp17
-rw-r--r--src/p2p/net_node.h15
-rw-r--r--src/p2p/net_node.inl27
-rw-r--r--src/p2p/net_node_common.h2
-rw-r--r--src/p2p/net_peerlist.h2
-rw-r--r--src/p2p/net_peerlist_boost_serialization.h47
-rw-r--r--src/p2p/p2p_protocol_defs.h47
-rw-r--r--src/p2p/stdafx.h2
-rw-r--r--src/platform/mingw/alloca.h2
-rw-r--r--src/platform/msc/alloca.h2
-rw-r--r--src/platform/msc/inline_c.h2
-rw-r--r--src/platform/msc/stdbool.h2
-rw-r--r--src/platform/msc/sys/param.h2
-rw-r--r--src/ringct/CMakeLists.txt2
-rw-r--r--src/ringct/bulletproofs.cc30
-rw-r--r--src/ringct/bulletproofs.h2
-rw-r--r--src/ringct/rctCryptoOps.c2
-rw-r--r--src/ringct/rctCryptoOps.h2
-rw-r--r--src/ringct/rctSigs.cpp3
-rw-r--r--src/rpc/CMakeLists.txt2
-rw-r--r--src/rpc/core_rpc_server.cpp85
-rw-r--r--src/rpc/core_rpc_server.h8
-rw-r--r--src/rpc/core_rpc_server_commands_defs.h403
-rw-r--r--src/rpc/core_rpc_server_error_codes.h2
-rw-r--r--src/rpc/daemon_handler.cpp2
-rw-r--r--src/rpc/daemon_handler.h2
-rw-r--r--src/rpc/daemon_messages.cpp2
-rw-r--r--src/rpc/daemon_messages.h2
-rw-r--r--src/rpc/daemon_rpc_version.h2
-rw-r--r--src/rpc/instanciations.cpp2
-rw-r--r--src/rpc/message.cpp2
-rw-r--r--src/rpc/message.h2
-rw-r--r--src/rpc/message_data_structs.h2
-rw-r--r--src/rpc/rpc_args.cpp2
-rw-r--r--src/rpc/rpc_args.h2
-rw-r--r--src/rpc/rpc_handler.h2
-rw-r--r--src/rpc/zmq_server.cpp2
-rw-r--r--src/rpc/zmq_server.h2
-rw-r--r--src/serialization/CMakeLists.txt2
-rw-r--r--src/serialization/binary_archive.h4
-rw-r--r--src/serialization/binary_utils.h2
-rw-r--r--src/serialization/container.h2
-rw-r--r--src/serialization/crypto.h2
-rw-r--r--src/serialization/debug_archive.h2
-rw-r--r--src/serialization/deque.h2
-rw-r--r--src/serialization/json_archive.h2
-rw-r--r--src/serialization/json_object.cpp3
-rw-r--r--src/serialization/json_object.h2
-rw-r--r--src/serialization/json_utils.h2
-rw-r--r--src/serialization/list.h2
-rw-r--r--src/serialization/pair.h2
-rw-r--r--src/serialization/serialization.h2
-rw-r--r--src/serialization/set.h2
-rw-r--r--src/serialization/string.h2
-rw-r--r--src/serialization/unordered_set.h2
-rw-r--r--src/serialization/variant.h2
-rw-r--r--src/serialization/vector.h2
-rw-r--r--src/simplewallet/CMakeLists.txt2
-rw-r--r--src/simplewallet/simplewallet.cpp13
-rw-r--r--src/simplewallet/simplewallet.h2
-rw-r--r--src/version.cpp.in4
-rw-r--r--src/wallet/CMakeLists.txt2
-rw-r--r--src/wallet/api/CMakeLists.txt2
-rw-r--r--src/wallet/api/address_book.cpp2
-rw-r--r--src/wallet/api/address_book.h2
-rw-r--r--src/wallet/api/pending_transaction.cpp2
-rw-r--r--src/wallet/api/pending_transaction.h2
-rw-r--r--src/wallet/api/subaddress.cpp2
-rw-r--r--src/wallet/api/subaddress.h2
-rw-r--r--src/wallet/api/subaddress_account.cpp2
-rw-r--r--src/wallet/api/subaddress_account.h2
-rw-r--r--src/wallet/api/transaction_history.cpp2
-rw-r--r--src/wallet/api/transaction_history.h2
-rw-r--r--src/wallet/api/transaction_info.cpp2
-rw-r--r--src/wallet/api/transaction_info.h2
-rw-r--r--src/wallet/api/unsigned_transaction.cpp2
-rw-r--r--src/wallet/api/unsigned_transaction.h2
-rw-r--r--src/wallet/api/utils.cpp2
-rw-r--r--src/wallet/api/wallet.cpp7
-rw-r--r--src/wallet/api/wallet.h2
-rw-r--r--src/wallet/api/wallet2_api.h2
-rw-r--r--src/wallet/api/wallet_manager.cpp2
-rw-r--r--src/wallet/api/wallet_manager.h2
-rw-r--r--src/wallet/message_transporter.cpp18
-rw-r--r--src/wallet/message_transporter.h3
-rw-r--r--src/wallet/node_rpc_proxy.cpp2
-rw-r--r--src/wallet/node_rpc_proxy.h2
-rw-r--r--src/wallet/wallet2.cpp118
-rw-r--r--src/wallet/wallet2.h15
-rw-r--r--src/wallet/wallet_args.cpp2
-rw-r--r--src/wallet/wallet_args.h2
-rw-r--r--src/wallet/wallet_errors.h25
-rw-r--r--src/wallet/wallet_rpc_server.cpp384
-rw-r--r--src/wallet/wallet_rpc_server.h6
-rw-r--r--src/wallet/wallet_rpc_server_commands_defs.h536
-rw-r--r--src/wallet/wallet_rpc_server_error_codes.h2
-rw-r--r--tests/CMakeLists.txt8
-rw-r--r--tests/block_weight/CMakeLists.txt45
-rw-r--r--tests/block_weight/block_weight.cpp185
-rwxr-xr-xtests/block_weight/block_weight.py74
-rwxr-xr-xtests/block_weight/compare.py13
-rw-r--r--tests/core_proxy/CMakeLists.txt2
-rw-r--r--tests/core_proxy/core_proxy.cpp4
-rw-r--r--tests/core_proxy/core_proxy.h6
-rw-r--r--tests/core_tests/CMakeLists.txt9
-rw-r--r--tests/core_tests/block_reward.cpp2
-rw-r--r--tests/core_tests/block_reward.h2
-rw-r--r--tests/core_tests/block_validation.cpp2
-rw-r--r--tests/core_tests/block_validation.h2
-rw-r--r--tests/core_tests/bulletproofs.cpp2
-rw-r--r--tests/core_tests/bulletproofs.h2
-rw-r--r--tests/core_tests/chain_split_1.cpp2
-rw-r--r--tests/core_tests/chain_split_1.h2
-rw-r--r--tests/core_tests/chain_switch_1.cpp2
-rw-r--r--tests/core_tests/chain_switch_1.h2
-rw-r--r--tests/core_tests/chaingen.cpp624
-rw-r--r--tests/core_tests/chaingen.h467
-rw-r--r--tests/core_tests/chaingen001.cpp2
-rw-r--r--tests/core_tests/chaingen_main.cpp2
-rw-r--r--tests/core_tests/chaingen_tests_list.h2
-rw-r--r--tests/core_tests/double_spend.cpp2
-rw-r--r--tests/core_tests/double_spend.h2
-rw-r--r--tests/core_tests/double_spend.inl2
-rw-r--r--tests/core_tests/integer_overflow.cpp2
-rw-r--r--tests/core_tests/integer_overflow.h2
-rw-r--r--tests/core_tests/multisig.cpp2
-rw-r--r--tests/core_tests/multisig.h2
-rw-r--r--tests/core_tests/rct.cpp2
-rw-r--r--tests/core_tests/rct.h2
-rw-r--r--tests/core_tests/ring_signature_1.cpp2
-rw-r--r--tests/core_tests/ring_signature_1.h2
-rw-r--r--tests/core_tests/transaction_tests.cpp2
-rw-r--r--tests/core_tests/transaction_tests.h2
-rw-r--r--tests/core_tests/tx_validation.cpp2
-rw-r--r--tests/core_tests/tx_validation.h2
-rw-r--r--tests/core_tests/v2_tests.cpp2
-rw-r--r--tests/core_tests/v2_tests.h4
-rw-r--r--tests/core_tests/wallet_tools.cpp287
-rw-r--r--tests/core_tests/wallet_tools.h86
-rw-r--r--tests/crypto/CMakeLists.txt16
-rw-r--r--tests/crypto/cnv4-jit.c119
-rw-r--r--tests/crypto/crypto-ops-data.c2
-rw-r--r--tests/crypto/crypto-ops.c2
-rw-r--r--tests/crypto/crypto-tests.h2
-rw-r--r--tests/crypto/crypto.cpp2
-rw-r--r--tests/crypto/hash.c2
-rw-r--r--tests/crypto/main.cpp2
-rw-r--r--tests/crypto/random.c2
-rw-r--r--tests/cryptolib.pl2
-rw-r--r--tests/cryptotest.pl2
-rw-r--r--tests/daemon_tests/CMakeLists.txt2
-rw-r--r--tests/daemon_tests/transfers.cpp2
-rw-r--r--tests/difficulty/CMakeLists.txt2
-rw-r--r--tests/difficulty/difficulty.cpp2
-rwxr-xr-xtests/difficulty/generate-data2
-rw-r--r--tests/functional_tests/CMakeLists.txt2
-rw-r--r--tests/functional_tests/main.cpp2
-rw-r--r--tests/functional_tests/transactions_flow_test.cpp2
-rw-r--r--tests/functional_tests/transactions_flow_test.h2
-rw-r--r--tests/functional_tests/transactions_generation_from_blockchain.cpp2
-rw-r--r--tests/functional_tests/transactions_generation_from_blockchain.h2
-rw-r--r--tests/fuzz/CMakeLists.txt2
-rw-r--r--tests/fuzz/base58.cpp2
-rw-r--r--tests/fuzz/block.cpp2
-rw-r--r--tests/fuzz/bulletproof.cpp2
-rw-r--r--tests/fuzz/cold-outputs.cpp2
-rw-r--r--tests/fuzz/cold-transaction.cpp2
-rw-r--r--tests/fuzz/fuzzer.cpp2
-rw-r--r--tests/fuzz/fuzzer.h2
-rw-r--r--tests/fuzz/http-client.cpp2
-rw-r--r--tests/fuzz/levin.cpp2
-rw-r--r--tests/fuzz/load_from_binary.cpp2
-rw-r--r--tests/fuzz/load_from_json.cpp2
-rw-r--r--tests/fuzz/parse_url.cpp2
-rw-r--r--tests/fuzz/signature.cpp2
-rw-r--r--tests/fuzz/transaction.cpp2
-rw-r--r--tests/hash-target.cpp2
-rw-r--r--tests/hash/CMakeLists.txt4
-rw-r--r--tests/hash/main.cpp31
-rw-r--r--tests/hash/tests-slow-4.txt10
-rw-r--r--tests/io.h2
-rw-r--r--tests/libwallet_api_tests/CMakeLists.txt2
-rw-r--r--tests/libwallet_api_tests/main.cpp2
-rw-r--r--tests/net_load_tests/CMakeLists.txt2
-rw-r--r--tests/net_load_tests/clt.cpp2
-rw-r--r--tests/net_load_tests/net_load_tests.h2
-rw-r--r--tests/net_load_tests/srv.cpp2
-rw-r--r--tests/performance_tests/CMakeLists.txt2
-rw-r--r--tests/performance_tests/bulletproof.h2
-rw-r--r--tests/performance_tests/check_tx_signature.h2
-rw-r--r--tests/performance_tests/cn_fast_hash.h2
-rw-r--r--tests/performance_tests/cn_slow_hash.h17
-rw-r--r--tests/performance_tests/construct_tx.h2
-rw-r--r--tests/performance_tests/crypto_ops.h2
-rw-r--r--tests/performance_tests/derive_public_key.h2
-rw-r--r--tests/performance_tests/derive_secret_key.h2
-rw-r--r--tests/performance_tests/equality.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/generate_key_derivation.h2
-rw-r--r--tests/performance_tests/generate_key_image.h2
-rw-r--r--tests/performance_tests/generate_key_image_helper.h2
-rw-r--r--tests/performance_tests/generate_keypair.h2
-rw-r--r--tests/performance_tests/is_out_to_acc.h2
-rw-r--r--tests/performance_tests/main.cpp12
-rw-r--r--tests/performance_tests/multi_tx_test_base.h2
-rw-r--r--tests/performance_tests/performance_tests.h118
-rw-r--r--tests/performance_tests/performance_utils.h2
-rw-r--r--tests/performance_tests/range_proof.h2
-rw-r--r--tests/performance_tests/rct_mlsag.h2
-rw-r--r--tests/performance_tests/sc_reduce32.h2
-rw-r--r--tests/performance_tests/signature.h2
-rw-r--r--tests/performance_tests/single_tx_test_base.h2
-rw-r--r--tests/performance_tests/subaddress_expand.h2
-rw-r--r--tests/trezor/CMakeLists.txt63
-rw-r--r--tests/trezor/trezor_tests.cpp1409
-rw-r--r--tests/trezor/trezor_tests.h248
-rw-r--r--tests/unit_tests/CMakeLists.txt3
-rw-r--r--tests/unit_tests/account.cpp2
-rw-r--r--tests/unit_tests/address_from_url.cpp2
-rw-r--r--tests/unit_tests/apply_permutation.cpp2
-rw-r--r--tests/unit_tests/ban.cpp6
-rw-r--r--tests/unit_tests/base58.cpp2
-rw-r--r--tests/unit_tests/block_queue.cpp2
-rw-r--r--tests/unit_tests/block_reward.cpp2
-rw-r--r--tests/unit_tests/blockchain_db.cpp44
-rw-r--r--tests/unit_tests/bulletproofs.cpp2
-rw-r--r--tests/unit_tests/canonical_amounts.cpp2
-rw-r--r--tests/unit_tests/chacha.cpp2
-rw-r--r--tests/unit_tests/checkpoints.cpp2
-rw-r--r--tests/unit_tests/command_line.cpp2
-rw-r--r--tests/unit_tests/crypto.cpp2
-rw-r--r--tests/unit_tests/decompose_amount_into_digits.cpp2
-rw-r--r--tests/unit_tests/dns_resolver.cpp2
-rw-r--r--tests/unit_tests/epee_boosted_tcp_server.cpp2
-rw-r--r--tests/unit_tests/epee_levin_protocol_handler_async.cpp2
-rw-r--r--tests/unit_tests/epee_utils.cpp21
-rw-r--r--tests/unit_tests/fee.cpp2
-rw-r--r--tests/unit_tests/get_xtype_from_string.cpp2
-rw-r--r--tests/unit_tests/hardfork.cpp43
-rw-r--r--tests/unit_tests/hashchain.cpp2
-rw-r--r--tests/unit_tests/http.cpp2
-rw-r--r--tests/unit_tests/logging.cpp2
-rw-r--r--tests/unit_tests/long_term_block_weight.cpp386
-rw-r--r--tests/unit_tests/main.cpp2
-rw-r--r--tests/unit_tests/memwipe.cpp2
-rw-r--r--tests/unit_tests/mnemonics.cpp2
-rw-r--r--tests/unit_tests/mul_div.cpp2
-rw-r--r--tests/unit_tests/multisig.cpp2
-rw-r--r--tests/unit_tests/notify.cpp1
-rw-r--r--tests/unit_tests/output_distribution.cpp4
-rw-r--r--tests/unit_tests/output_selection.cpp2
-rw-r--r--tests/unit_tests/parse_amount.cpp2
-rw-r--r--tests/unit_tests/ringct.cpp2
-rw-r--r--tests/unit_tests/serialization.cpp2
-rw-r--r--tests/unit_tests/sha256.cpp2
-rw-r--r--tests/unit_tests/slow_memmem.cpp2
-rw-r--r--tests/unit_tests/subaddress.cpp2
-rw-r--r--tests/unit_tests/test_peerlist.cpp2
-rw-r--r--tests/unit_tests/test_protocol_pack.cpp2
-rw-r--r--tests/unit_tests/test_tx_utils.cpp2
-rw-r--r--tests/unit_tests/unbound.cpp2
-rw-r--r--tests/unit_tests/unit_tests_utils.h2
-rw-r--r--tests/unit_tests/uri.cpp2
-rw-r--r--tests/unit_tests/varint.cpp2
-rw-r--r--tests/unit_tests/vercmp.cpp2
-rw-r--r--translations/CMakeLists.txt2
-rw-r--r--translations/generate_translations_header.c2
-rw-r--r--utils/build_scripts/windows.bat2
-rw-r--r--utils/munin_plugins/alt_blocks_count2
-rw-r--r--utils/munin_plugins/difficulty2
-rw-r--r--utils/munin_plugins/grey_peerlist_size2
-rw-r--r--utils/munin_plugins/height2
-rw-r--r--utils/munin_plugins/incoming_connections_count2
-rw-r--r--utils/munin_plugins/outgoing_connections_count2
-rw-r--r--utils/munin_plugins/tx_count2
-rw-r--r--utils/munin_plugins/tx_pool_size2
-rw-r--r--utils/munin_plugins/white_peerlist_size2
589 files changed, 13254 insertions, 2331 deletions
diff --git a/.travis.yml b/.travis.yml
index ffb31fc08..d83675869 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -10,16 +10,12 @@ cache:
env:
global:
- MAKEJOBS=-j3
- - RUN_TESTS=false
- - BOOST_TEST_RANDOM=1$TRAVIS_BUILD_ID
- CCACHE_SIZE=100M
- CCACHE_TEMPDIR=/tmp/.ccache-temp
- CCACHE_COMPRESS=1
- CCACHE_DIR=$HOME/.ccache
- BASE_OUTDIR=$TRAVIS_BUILD_DIR/out
- SDK_URL=https://bitcoincore.org/depends-sources/sdks
- - PYTHON_DEBUG=1
- - WINEDEBUG=fixme-all
- DOCKER_PACKAGES="build-essential libtool cmake autotools-dev automake pkg-config bsdmainutils curl git ca-certificates ccache"
matrix:
# ARM v7
@@ -27,20 +23,20 @@ env:
# ARM v8
- HOST=aarch64-linux-gnu PACKAGES="python3 gperf g++-aarch64-linux-gnu"
# i686 Win
- - HOST=i686-w64-mingw32 PACKAGES="python3 nsis g++-mingw-w64-i686"
+ - HOST=i686-w64-mingw32 DEP_OPTS="NO_QT=1" PACKAGES="python3 g++-mingw-w64-i686 qttools5-dev-tools"
# i686 Linux
- - HOST=i686-pc-linux-gnu PACKAGES="gperf cmake g++-multilib bc python3-zmq" RUN_TESTS=true
+ - HOST=i686-pc-linux-gnu PACKAGES="gperf cmake g++-multilib python3-zmq"
# Win64
- - HOST=x86_64-w64-mingw32 PACKAGES="cmake python3 nsis g++-mingw-w64-x86-64 wine-binfmt wine64 bc" RUN_TESTS=true
+ - HOST=x86_64-w64-mingw32 DEP_OPTS="NO_QT=1" PACKAGES="cmake python3 g++-mingw-w64-x86-64 qttools5-dev-tools"
# x86_64 Linux
- - HOST=x86_64-unknown-linux-gnu PACKAGES="gperf cmake python3-zmq libdbus-1-dev libharfbuzz-dev" RUN_TESTS=true
+ - HOST=x86_64-unknown-linux-gnu PACKAGES="gperf cmake python3-zmq libdbus-1-dev libharfbuzz-dev"
# Cross-Mac
- HOST=x86_64-apple-darwin11 PACKAGES="cmake imagemagick libcap-dev librsvg2-bin libz-dev libbz2-dev libtiff-tools python-dev python3-setuptools-git" OSX_SDK=10.11
before_install:
- export PATH=$(echo $PATH | tr ':' "\n" | sed '/\/opt\/python/d' | tr "\n" ":" | sed "s|::|:|g")
install:
- - env | grep -E '^(CCACHE_|WINEDEBUG|DISPLAY|BOOST_TEST_RANDOM|CONFIG_SHELL)' | tee /tmp/env
+ - env | grep -E '^(CCACHE_|DISPLAY|CONFIG_SHELL)' | tee /tmp/env
- if [[ $HOST = *-mingw32 ]]; then DOCKER_ADMIN="--cap-add SYS_ADMIN"; fi
- DOCKER_ID=$(docker run $DOCKER_ADMIN -idt --mount type=bind,src=$TRAVIS_BUILD_DIR,dst=$TRAVIS_BUILD_DIR --mount type=bind,src=$CCACHE_DIR,dst=$CCACHE_DIR -w $TRAVIS_BUILD_DIR --env-file /tmp/env ubuntu:18.04)
- DOCKER_EXEC="docker exec $DOCKER_ID"
diff --git a/ANONYMITY_NETWORKS.md b/ANONYMITY_NETWORKS.md
index 6ac8cd999..a5f18010e 100644
--- a/ANONYMITY_NETWORKS.md
+++ b/ANONYMITY_NETWORKS.md
@@ -1,7 +1,6 @@
# Anonymity Networks with Monero
-Currently only Tor has been integrated into Monero. Providing support for
-Kovri/I2P should be minimal, but has not yet been attempted. The usage of
+Currently only Tor and I2P have been integrated into Monero. The usage of
these networks is still considered experimental - there are a few pessimistic
cases where privacy is leaked. The design is intended to maximize privacy of
the source of a transaction by broadcasting it over an anonymity network, while
@@ -23,8 +22,8 @@ connections enabled.
## P2P Commands
-Only handshakes, peer timed syncs, and transaction broadcast messages are
-supported over anonymity networks. If one `--add-exclusive-node` onion address
+Only handshakes, peer timed syncs and transaction broadcast messages are
+supported over anonymity networks. If one `--add-exclusive-node` p2p address
is specified, then no syncing will take place and only transaction broadcasting
can occur. It is therefore recommended that `--add-exclusive-node` be combined
with additional exclusive IPv4 address(es).
@@ -47,9 +46,9 @@ separate process. On most systems the configuration will look like:
which tells `monerod` that ".onion" p2p addresses can be forwarded to a socks
proxy at IP 127.0.0.1 port 9050 with a max of 10 outgoing connections and
-".i2p" p2p addresses can be forwarded to a socks proxy at IP 127.0.0.1 port 9000
-with the default max outgoing connections. Since there are no seed nodes for
-anonymity connections, peers must be manually specified:
+".b32.i2p" p2p addresses can be forwarded to a socks proxy at IP 127.0.0.1 port
+9000 with the default max outgoing connections. Since there are no seed nodes
+for anonymity connections, peers must be manually specified:
> `--add-exclusive-node rveahdfho7wo4b2m.onion:28083`
> `--add-peer rveahdfho7wo4b2m.onion:28083`
@@ -64,27 +63,28 @@ Receiving anonymity connections is done through the option
`--anonymous-inbound`. This option tells `monerod` the inbound address, network
type, and max connections:
-> `--anonymous-inbound rveahdfho7wo4b2m.onion:28083,127.0.0.28083,25`
-> `--anonymous-inbound foobar.i2p:5000,127.0.0.1:30000`
+> `--anonymous-inbound rveahdfho7wo4b2m.onion:28083,127.0.0.1:28083,25`
+> `--anonymous-inbound cmeua5767mz2q5jsaelk2rxhf67agrwuetaso5dzbenyzwlbkg2q.b32.i2p:5000,127.0.0.1:30000`
which tells `monerod` that a max of 25 inbound Tor connections are being
received at address "rveahdfho7wo4b2m.onion:28083" and forwarded to `monerod`
localhost port 28083, and a default max I2P connections are being received at
-address "foobar.i2p:5000" and forwarded to `monerod` localhost port 30000.
+address "cmeua5767mz2q5jsaelk2rxhf67agrwuetaso5dzbenyzwlbkg2q.b32.i2p:5000" and
+forwarded to `monerod` localhost port 30000.
These addresses will be shared with outgoing peers, over the same network type,
otherwise the peer will not be notified of the peer address by the proxy.
### Network Types
-#### Tor
+#### Tor & I2P
-Options `--add-exclusive-node` and `--add-peer` recognize ".onion" addresses,
-and will properly forward those addresses to the proxy provided with
-`--proxy tor,...`.
+Options `--add-exclusive-node` and `--add-peer` recognize ".onion" and
+".b32.i2p" addresses, and will properly forward those addresses to the proxy
+provided with `--proxy tor,...` or `--proxy i2p,...`.
-Option `--anonymous-inbound` also recognizes ".onion" addresses, and will
-automatically be sent out to outgoing Tor connections so the peer can
-distribute the address to its other peers.
+Option `--anonymous-inbound` also recognizes ".onion" and ".b32.i2p" addresses,
+and will automatically be sent out to outgoing Tor/I2P connections so the peer
+can distribute the address to its other peers.
##### Configuration
@@ -99,11 +99,8 @@ This will store key information in `/var/lib/tor/data/monero` and will forward
`/usr/lib/tor/data/monero/hostname` will contain the ".onion" address for use
with `--anonymous-inbound`.
-#### Kovri/I2P
-
-Support for this network has not been implemented. Using ".i2p" addresses or
-specifying "i2p" will currently generate an error.
-
+I2P must be configured with a standard server tunnel. Configuration differs by
+I2P implementation.
## Privacy Limitations
@@ -132,11 +129,11 @@ more difficult.
### Bandwidth Usage
An ISP can passively monitor `monerod` connections from a node and observe when
-a transaction is sent over a Tor/Kovri connection via timing analysis + size of
-data sent during that timeframe. Kovri should provide better protection against
+a transaction is sent over a Tor/I2P connection via timing analysis + size of
+data sent during that timeframe. I2P should provide better protection against
this attack - its connections are not circuit based. However, if a node is
-only using Kovri for broadcasting Monero transactions, the total aggregate of
-Kovri/I2P data would also leak information.
+only using I2P for broadcasting Monero transactions, the total aggregate of
+I2P data would also leak information.
#### Mitigation
@@ -165,15 +162,15 @@ simply a best effort attempt.
### Active Bandwidth Shaping
An attacker could attempt to bandwidth shape traffic in an attempt to determine
-the source of a Tor/Kovri/I2P connection. There isn't great mitigation against
-this, but Kovri/I2P should provide better protection against this attack since
+the source of a Tor/I2P connection. There isn't great mitigation against
+this, but I2P should provide better protection against this attack since
the connections are not circuit based.
#### Mitigation
-The best mitigiation is to use Kovri/I2P instead of Tor. However, Kovri/I2P
+The best mitigiation is to use I2P instead of Tor. However, I2P
has a smaller set of users (less cover traffic) and academic reviews, so there
is a tradeoff in potential isses. Also, anyone attempting this strategy really
wants to uncover a user, it seems unlikely that this would be performed against
-every Tor/Kovri/I2P user.
+every Tor/I2P user.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 31c3dbd21..b2d47706b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
@@ -44,6 +44,8 @@ message(STATUS "CMake version ${CMAKE_VERSION}")
project(monero)
+enable_language(C ASM)
+
function (die msg)
if (NOT WIN32)
string(ASCII 27 Esc)
@@ -113,6 +115,9 @@ string(TOLOWER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_LOWER)
# to identify the target architecture, to direct logic in this cmake script.
# Since ARCH is a cached variable, it will not be set on first cmake invocation.
if (NOT ARCH OR ARCH STREQUAL "" OR ARCH STREQUAL "native" OR ARCH STREQUAL "default")
+ if(CMAKE_SYSTEM_PROCESSOR STREQUAL "")
+ set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR})
+ endif()
set(ARCH_ID "${CMAKE_SYSTEM_PROCESSOR}")
else()
set(ARCH_ID "${ARCH}")
@@ -687,7 +692,6 @@ else()
endif()
if(BACKCOMPAT)
- add_definitions(-DFDELT_TYPE=long\ int)
add_linker_flag_if_supported(-Wl,--wrap=__divmoddi4 LD_BACKCOMPAT_FLAGS)
add_linker_flag_if_supported(-Wl,--wrap=glob LD_BACKCOMPAT_FLAGS)
message(STATUS "Using Lib C back compat flags: ${LD_BACKCOMPAT_FLAGS}")
@@ -898,7 +902,7 @@ if(MINGW)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wa,-mbig-obj")
set(EXTRA_LIBRARIES mswsock;ws2_32;iphlpapi;crypt32;bcrypt)
if(DEPENDS)
- set(ICU_LIBRARIES sicuio sicuin sicuuc sicudt sicutu iconv)
+ set(ICU_LIBRARIES icuio icui18n icuuc icudata icutu iconv)
else()
set(ICU_LIBRARIES icuio icuin icuuc icudt icutu iconv)
endif()
diff --git a/CMakeLists_IOS.txt b/CMakeLists_IOS.txt
index 9273af19f..3b7eacc8a 100644
--- a/CMakeLists_IOS.txt
+++ b/CMakeLists_IOS.txt
@@ -1,4 +1,4 @@
-# Portions Copyright (c) 2017-2018, The Monero Project
+# Portions Copyright (c) 2017-2019, The Monero Project
# This file is based off of the https://code.google.com/archive/p/ios-cmake/
# It has been altered for Monero iOS development
#
diff --git a/LICENSE b/LICENSE
index 733f09f23..f48fcda87 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-Copyright (c) 2014-2018, The Monero Project
+Copyright (c) 2014-2019, The Monero Project
All rights reserved.
diff --git a/Makefile b/Makefile
index f21038b74..1fd310915 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
@@ -63,6 +63,10 @@ debug-test:
mkdir -p $(builddir)/debug
cd $(builddir)/debug && cmake -D BUILD_TESTS=ON -D CMAKE_BUILD_TYPE=Debug $(topdir) && $(MAKE) && $(MAKE) ARGS="-E libwallet_api_tests" test
+debug-test-trezor:
+ mkdir -p $(builddir)/debug
+ cd $(builddir)/debug && cmake -D BUILD_TESTS=ON -D TREZOR_DEBUG=ON -D CMAKE_BUILD_TYPE=Debug $(topdir) && $(MAKE) && $(MAKE) ARGS="-E libwallet_api_tests" test
+
debug-all:
mkdir -p $(builddir)/debug
cd $(builddir)/debug && cmake -D BUILD_TESTS=ON -D BUILD_SHARED_LIBS=OFF -D CMAKE_BUILD_TYPE=Debug $(topdir) && $(MAKE)
diff --git a/README.md b/README.md
index ffef796ff..35b2f701a 100644
--- a/README.md
+++ b/README.md
@@ -29,6 +29,12 @@ Our researchers are available on IRC in [#monero-research-lab on Freenode](https
- You can subscribe to an [announcement listserv](https://lists.getmonero.org) to get critical announcements from the Monero core team. The announcement list can be very helpful for knowing when software updates are needed.
+## Translations
+The CLI wallet is available in different languages. If you want to help translate it, join Pootle, our self-hosted localization platform: [translate.getmonero.org](https://translate.getmonero.org). Every translation *must* be uploaded on Pootle, pull requests directly editing the code on this repository will be closed.
+ 
+
+If you need help/support/info, contact the localization workgroup. You can do so in various ways: by email (translate[at]getmonero[dot]org), on the official chat (#monero-translations). A complete list of contacts can be found on the repository of the workgroup: [monero-ecosystem/monero-translations](https://github.com/monero-ecosystem/monero-translations#contacts).
+
## Build
### IMPORTANT
@@ -41,9 +47,9 @@ These builds are of the master branch, which is used for active development and
| Ubuntu 16.04 | amd64 | [![Ubuntu 16.04 amd64](https://build.getmonero.org/png?builder=monero-static-ubuntu-amd64)](https://build.getmonero.org/builders/monero-static-ubuntu-amd64)
| Ubuntu 16.04 | armv7 | [![Ubuntu 16.04 armv7](https://build.getmonero.org/png?builder=monero-static-ubuntu-arm7)](https://build.getmonero.org/builders/monero-static-ubuntu-arm7)
| Debian Stable | armv8 | [![Debian armv8](https://build.getmonero.org/png?builder=monero-static-debian-armv8)](https://build.getmonero.org/builders/monero-static-debian-armv8)
-| OSX 10.11 | amd64 | [![OSX 10.11 amd64](https://build.getmonero.org/png?builder=monero-static-osx-10.11)](https://build.getmonero.org/builders/monero-static-osx-10.11)
-| OSX 10.12 | amd64 | [![OSX 10.12 amd64](https://build.getmonero.org/png?builder=monero-static-osx-10.12)](https://build.getmonero.org/builders/monero-static-osx-10.12)
-| OSX 10.13 | amd64 | [![OSX 10.13 amd64](https://build.getmonero.org/png?builder=monero-static-osx-10.13)](https://build.getmonero.org/builders/monero-static-osx-10.13)
+| macOS 10.11 | amd64 | [![macOS 10.11 amd64](https://build.getmonero.org/png?builder=monero-static-osx-10.11)](https://build.getmonero.org/builders/monero-static-osx-10.11)
+| macOS 10.12 | amd64 | [![macOS 10.12 amd64](https://build.getmonero.org/png?builder=monero-static-osx-10.12)](https://build.getmonero.org/builders/monero-static-osx-10.12)
+| macOS 10.13 | amd64 | [![macOS 10.13 amd64](https://build.getmonero.org/png?builder=monero-static-osx-10.13)](https://build.getmonero.org/builders/monero-static-osx-10.13)
| FreeBSD 11 | amd64 | [![FreeBSD 11 amd64](https://build.getmonero.org/png?builder=monero-static-freebsd64)](https://build.getmonero.org/builders/monero-static-freebsd64)
| DragonFly BSD 4.6 | amd64 | [![DragonFly BSD amd64](https://build.getmonero.org/png?builder=monero-static-dragonflybsd-amd64)](https://build.getmonero.org/builders/monero-static-dragonflybsd-amd64)
| Windows (MSYS2/MinGW) | i686 | [![Windows (MSYS2/MinGW) i686](https://build.getmonero.org/png?builder=monero-static-win32)](https://build.getmonero.org/builders/monero-static-win32)
@@ -119,7 +125,8 @@ Dates are provided in the format YYYY-MM-DD.
| 1546000 | 2018-04-06 | v7 | v0.12.0.0 | v0.12.3.0 | Cryptonight variant 1, ringsize >= 7, sorted inputs
| 1685555 | 2018-10-18 | v8 | v0.13.0.0 | v0.13.0.4 | max transaction size at half the penalty free block size, bulletproofs enabled, cryptonight variant 2, fixed ringsize [11](https://youtu.be/KOO5S4vxi0o)
| 1686275 | 2018-10-19 | v9 | v0.13.0.0 | v0.13.0.4 | bulletproofs required
-| XXXXXXX | 2019-04-XX | XX | XXXXXXXXX | XXXXXXXXX | X
+| 1788000 | 2019-03-09 | v10 | v0.14.0.0 | v0.14.0.2 | Cryptonight-R PoW, new block weight algorithm, slightly more efficient RingCT format
+| 1788720 | 2019-03-10 | v11 | v0.14.0.0 | v0.14.0.2 | forbid old RingCT transaction format
X's indicate that these details have not been determined as of commit date.
@@ -169,6 +176,9 @@ build the library binary manually. This can be done with the following command `
Debian / Ubuntu one liner for all dependencies
``` sudo apt update && sudo apt install build-essential cmake pkg-config libboost-all-dev libssl-dev libzmq3-dev libunbound-dev libsodium-dev libunwind8-dev liblzma-dev libreadline6-dev libldns-dev libexpat1-dev doxygen graphviz libpgm-dev```
+FreeBSD one liner for required to build dependencies
+```pkg install git gmake cmake pkgconf boost-libs cppzmq libsodium```
+
### Cloning the repository
Clone recursively to pull-in needed submodule(s):
@@ -184,13 +194,13 @@ If you already have a repo cloned, initialize and update:
Monero uses the CMake build system and a top-level [Makefile](Makefile) that
invokes cmake commands as needed.
-#### On Linux and OS X
+#### On Linux and macOS
* Install the dependencies
* Change to the root of the source code directory, change to the most recent release branch, and build:
cd monero
- git checkout v0.13.0.4
+ git checkout release-v0.14
make
*Optional*: If your machine has several cores and enough memory, enable
@@ -198,7 +208,7 @@ invokes cmake commands as needed.
this to be worthwhile, the machine should have one core and about 2GB of RAM
available per thread.
- *Note*: If cmake can not find zmq.hpp file on OS X, installing `zmq.hpp` from
+ *Note*: If cmake can not find zmq.hpp file on macOS, installing `zmq.hpp` from
https://github.com/zeromq/cppzmq to `/usr/local/include` should fix that error.
*Note*: The instructions above will compile the most stable release of the
@@ -250,11 +260,11 @@ Tested on a Raspberry Pi Zero with a clean install of minimal Raspbian Stretch (
```
* If using an external hard disk without an external power supply, ensure it gets enough power to avoid hardware issues when syncing, by adding the line "max_usb_current=1" to /boot/config.txt
-* Clone monero and checkout most recent release version:
+* Clone monero and checkout the most recent release version:
```
git clone https://github.com/monero-project/monero.git
cd monero
- git checkout tags/v0.13.0.4
+ git checkout tags/v0.14.1.0
```
* Build:
```
@@ -351,9 +361,9 @@ application.
cd monero
-* If you would like a specific [version/tag](https://github.com/monero-project/monero/tags), do a git checkout for that version. eg. 'v0.13.0.0'. If you dont care about the version and just want binaries from master, skip this step:
-
- git checkout v0.13.0.4
+* If you would like a specific [version/tag](https://github.com/monero-project/monero/tags), do a git checkout for that version. eg. 'v0.14.1.0'. If you dont care about the version and just want binaries from master, skip this step:
+
+ git checkout v0.14.1.0
* If you are on a 64-bit system, run:
@@ -377,7 +387,7 @@ application.
### On FreeBSD:
-The project can be built from scratch by following instructions for Linux above. If you are running monero in a jail you need to add the flag: `allow.sysvipc=1` to your jail configuration, otherwise lmdb will throw the error message: `Failed to open lmdb environment: Function not implemented`.
+The project can be built from scratch by following instructions for Linux above(but use `gmake` instead of `make`). If you are running monero in a jail you need to add the flag: `allow.sysvipc=1` to your jail configuration, otherwise lmdb will throw the error message: `Failed to open lmdb environment: Function not implemented`.
We expect to add Monero into the ports tree in the near future, which will aid in managing installations using ports or packages.
diff --git a/cmake/32-bit-toolchain.cmake b/cmake/32-bit-toolchain.cmake
index 253523e66..2d53adf06 100644
--- a/cmake/32-bit-toolchain.cmake
+++ b/cmake/32-bit-toolchain.cmake
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/cmake/64-bit-toolchain.cmake b/cmake/64-bit-toolchain.cmake
index b4b528347..7c56eef95 100644
--- a/cmake/64-bit-toolchain.cmake
+++ b/cmake/64-bit-toolchain.cmake
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/cmake/CheckTrezor.cmake b/cmake/CheckTrezor.cmake
index 71214363d..6aabdda36 100644
--- a/cmake/CheckTrezor.cmake
+++ b/cmake/CheckTrezor.cmake
@@ -1,6 +1,8 @@
OPTION(USE_DEVICE_TREZOR "Trezor support compilation" ON)
OPTION(USE_DEVICE_TREZOR_LIBUSB "Trezor LibUSB compilation" ON)
OPTION(USE_DEVICE_TREZOR_UDP_RELEASE "Trezor UdpTransport in release mode" OFF)
+OPTION(USE_DEVICE_TREZOR_DEBUG "Trezor Debugging enabled" OFF)
+OPTION(TREZOR_DEBUG "Main trezor debugging switch" OFF)
# Helper function to fix cmake < 3.6.0 FindProtobuf variables
function(_trezor_protobuf_fix_vars)
@@ -53,6 +55,14 @@ if (USE_DEVICE_TREZOR)
set(Protobuf_FOUND 1) # override found if all rquired info was provided by variables
endif()
+ if(TREZOR_DEBUG)
+ set(USE_DEVICE_TREZOR_DEBUG 1)
+ endif()
+
+ # Compile debugging support (for tests)
+ if (USE_DEVICE_TREZOR_DEBUG)
+ add_definitions(-DWITH_TREZOR_DEBUGGING=1)
+ endif()
else()
message(STATUS "Trezor support disabled by USE_DEVICE_TREZOR")
endif()
@@ -106,7 +116,12 @@ endif()
if(Protobuf_FOUND AND USE_DEVICE_TREZOR AND TREZOR_PYTHON AND Protobuf_COMPILE_TEST_PASSED)
set(ENV{PROTOBUF_INCLUDE_DIRS} "${Protobuf_INCLUDE_DIR}")
set(ENV{PROTOBUF_PROTOC_EXECUTABLE} "${Protobuf_PROTOC_EXECUTABLE}")
- execute_process(COMMAND ${TREZOR_PYTHON} tools/build_protob.py WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../src/device_trezor/trezor RESULT_VARIABLE RET OUTPUT_VARIABLE OUT ERROR_VARIABLE ERR)
+ set(TREZOR_PROTOBUF_PARAMS "")
+ if (USE_DEVICE_TREZOR_DEBUG)
+ set(TREZOR_PROTOBUF_PARAMS "--debug")
+ endif()
+
+ execute_process(COMMAND ${TREZOR_PYTHON} tools/build_protob.py ${TREZOR_PROTOBUF_PARAMS} WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../src/device_trezor/trezor RESULT_VARIABLE RET OUTPUT_VARIABLE OUT ERROR_VARIABLE ERR)
if(RET)
message(WARNING "Trezor protobuf messages could not be regenerated (err=${RET}, python ${PYTHON})."
"OUT: ${OUT}, ERR: ${ERR}."
diff --git a/cmake/FindUnbound.cmake b/cmake/FindUnbound.cmake
index a392d59ca..e3eb3d67e 100644
--- a/cmake/FindUnbound.cmake
+++ b/cmake/FindUnbound.cmake
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are
diff --git a/cmake/GenVersion.cmake b/cmake/GenVersion.cmake
index 289115175..1ea5b209c 100644
--- a/cmake/GenVersion.cmake
+++ b/cmake/GenVersion.cmake
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/cmake/Version.cmake b/cmake/Version.cmake
index 3677e80d7..632c1431c 100644
--- a/cmake/Version.cmake
+++ b/cmake/Version.cmake
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/cmake/test-libusb-version.c b/cmake/test-libusb-version.c
index 309e4ad27..b80191b58 100644
--- a/cmake/test-libusb-version.c
+++ b/cmake/test-libusb-version.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/cmake/test-protobuf.cpp b/cmake/test-protobuf.cpp
index 532df7cbe..0a1ca82be 100644
--- a/cmake/test-protobuf.cpp
+++ b/cmake/test-protobuf.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/cmake/test-static-assert.c b/cmake/test-static-assert.c
index 28a80a972..2e6c84839 100644
--- a/cmake/test-static-assert.c
+++ b/cmake/test-static-assert.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/cmake/test-static-assert.cpp b/cmake/test-static-assert.cpp
index 28a80a972..2e6c84839 100644
--- a/cmake/test-static-assert.cpp
+++ b/cmake/test-static-assert.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt
index 3bebbe0d2..0db645ce9 100644
--- a/contrib/CMakeLists.txt
+++ b/contrib/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/contrib/depends/Makefile b/contrib/depends/Makefile
index bf33d706d..afa61b93b 100644
--- a/contrib/depends/Makefile
+++ b/contrib/depends/Makefile
@@ -94,8 +94,8 @@ $(host_arch)_$(host_os)_id_string+=$(shell $(host_CXX) --version 2>/dev/null)
$(host_arch)_$(host_os)_id_string+=$(shell $(host_RANLIB) --version 2>/dev/null)
$(host_arch)_$(host_os)_id_string+=$(shell $(host_STRIP) --version 2>/dev/null)
-
-packages += $($(host_arch)_$(host_os)_packages) $($(host_os)_packages)
+qt_packages_$(NO_QT) = $(qt_packages)
+packages += $($(host_arch)_$(host_os)_packages) $($(host_os)_packages) $(qt_packages_)
native_packages += $($(host_arch)_$(host_os)_native_packages) $($(host_os)_native_packages)
all_packages = $(packages) $(native_packages)
diff --git a/contrib/depends/packages/cmake/conf/mxe-conf.cmake.in b/contrib/depends/packages/cmake/conf/mxe-conf.cmake.in
deleted file mode 100644
index 8bd4cf1f7..000000000
--- a/contrib/depends/packages/cmake/conf/mxe-conf.cmake.in
+++ /dev/null
@@ -1,67 +0,0 @@
-# This file is part of MXE. See LICENSE.md for licensing information.
-
-# https://cmake.org/cmake/help/latest
-
-# Can't set `cmake_minimum_required` or `cmake_policy` in toolchain
-# since toolchain is read before CMakeLists.txt
-# See `target-cmake.in` for CMAKE_POLICY_DEFAULT_CMPNNNN
-
-# Check if we are using mxe supplied version
-# - toolchain is included multiple times so set a guard in
-# environment to suppress duplicate messages
-if(NOT ${CMAKE_COMMAND} STREQUAL @PREFIX@/@BUILD@/bin/cmake AND NOT DEFINED ENV{_MXE_CMAKE_TOOLCHAIN_INCLUDED})
- message(WARNING "
-** Warning: direct use of toolchain file is deprecated
-** Please use prefixed wrapper script instead:
- @TARGET@-cmake [options] <path-to-source>
- - uses mxe supplied cmake version @CMAKE_VERSION@
- - loads toolchain
- - loads common run results
- - sets various policy defaults
- ")
- set(ENV{_MXE_CMAKE_TOOLCHAIN_INCLUDED} TRUE)
-endif()
-
-## General configuration
-set(CMAKE_SYSTEM_NAME Windows)
-set(MSYS 1)
-set(CMAKE_EXPORT_NO_PACKAGE_REGISTRY ON)
-# Workaround for https://www.cmake.org/Bug/view.php?id=14075
-set(CMAKE_CROSS_COMPILING ON)
-
-
-## Library config
-set(BUILD_SHARED_LIBS @CMAKE_SHARED_BOOL@ CACHE BOOL "BUILD_SHARED_LIBS" FORCE)
-set(BUILD_STATIC_LIBS @CMAKE_STATIC_BOOL@ CACHE BOOL "BUILD_STATIC_LIBS" FORCE)
-set(BUILD_SHARED @CMAKE_SHARED_BOOL@ CACHE BOOL "BUILD_SHARED" FORCE)
-set(BUILD_STATIC @CMAKE_STATIC_BOOL@ CACHE BOOL "BUILD_STATIC" FORCE)
-set(LIBTYPE @LIBTYPE@)
-
-
-## Paths etc.
-set(CMAKE_FIND_ROOT_PATH @PREFIX@/@TARGET@)
-set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
-set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
-set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
-set(CMAKE_PREFIX_PATH @PREFIX@/@TARGET@)
-set(CMAKE_INSTALL_PREFIX @PREFIX@/@TARGET@ CACHE PATH "Installation Prefix")
-# For custom mxe FindPackage scripts
-set(CMAKE_MODULE_PATH "@PREFIX@/share/cmake/modules" ${CMAKE_MODULE_PATH})
-
-
-## Programs
-set(CMAKE_C_COMPILER @PREFIX@/bin/@TARGET@-gcc)
-set(CMAKE_CXX_COMPILER @PREFIX@/bin/@TARGET@-g++)
-set(CMAKE_Fortran_COMPILER @PREFIX@/bin/@TARGET@-gfortran)
-set(CMAKE_RC_COMPILER @PREFIX@/bin/@TARGET@-windres)
-# CMAKE_RC_COMPILE_OBJECT is defined in:
-# <cmake root>/share/cmake-X.Y/Modules/Platform/Windows-windres.cmake
-set(CPACK_NSIS_EXECUTABLE @TARGET@-makensis)
-
-## Individual package configuration
-file(GLOB mxe_cmake_files
- "@CMAKE_TOOLCHAIN_DIR@/*.cmake"
-)
-foreach(mxe_cmake_file ${mxe_cmake_files})
- include(${mxe_cmake_file})
-endforeach()
diff --git a/contrib/depends/packages/cmake/conf/target-cmake.in b/contrib/depends/packages/cmake/conf/target-cmake.in
deleted file mode 100644
index a78bcf58d..000000000
--- a/contrib/depends/packages/cmake/conf/target-cmake.in
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/usr/bin/env bash
-echo "== Using MXE wrapper: @PREFIX@/bin/@TARGET@-cmake"
-
-# https://cmake.org/cmake/help/latest/manual/cmake-policies.7.html
-# https://cmake.org/cmake/help/latest/variable/CMAKE_POLICY_DEFAULT_CMPNNNN.html
-POLICIES=(0017,0020)
-
-unset NO_MXE_TOOLCHAIN
-if echo -- "$@" | grep -Ewq "(--build|-E|--system-information)" ; then
- NO_MXE_TOOLCHAIN=1
-fi
-if [[ "$NO_MXE_TOOLCHAIN" == "1" ]]; then
- echo "== Skip using MXE toolchain: @CMAKE_TOOLCHAIN_FILE@"
- # see https://github.com/mxe/mxe/issues/932
- exec "@PREFIX@/@BUILD@/bin/cmake" "$@"
-else
- echo " - cmake version @CMAKE_VERSION@"
- echo " - warnings for unused CMAKE_POLICY_DEFAULT variables can be ignored"
- echo "== Using MXE toolchain: @CMAKE_TOOLCHAIN_FILE@"
- echo "== Using MXE runresult: @CMAKE_RUNRESULT_FILE@"
- if ! ( echo "$@" | grep --silent "DCMAKE_BUILD_TYPE" ) ; then
- echo '== Adding "-DCMAKE_BUILD_TYPE=Release"'
- set -- "-DCMAKE_BUILD_TYPE=Release" "$@"
- fi
- exec "@PREFIX@/@BUILD@/bin/cmake" \
- -DCMAKE_TOOLCHAIN_FILE="@CMAKE_TOOLCHAIN_FILE@" \
- `eval echo -DCMAKE_POLICY_DEFAULT_CMP{$POLICIES}=NEW` \
- -C"@CMAKE_RUNRESULT_FILE@" "$@"
-fi
diff --git a/contrib/depends/packages/cmake/test/CMakeLists.txt b/contrib/depends/packages/cmake/test/CMakeLists.txt
deleted file mode 100644
index 6075a8f5a..000000000
--- a/contrib/depends/packages/cmake/test/CMakeLists.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-# This file is part of MXE. See LICENSE.md for licensing information.
-
-# 2.8.9 is Debian Wheezy version
-cmake_minimum_required(VERSION 2.8.9)
-
-# use default C and CXX languages
-project(mxe)
-
-# see cmake --help-policy <cmp> for details
-cmake_policy(SET CMP0017 NEW)
-if (POLICY CMP0020)
- cmake_policy(SET CMP0020 NEW)
-endif()
-
-# so we can find pkg-test.cmake files to include
-set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../.. ${CMAKE_MODULE_PATH})
-
-include(${PKG}-test)
diff --git a/contrib/depends/packages/icu4c.mk b/contrib/depends/packages/icu4c.mk
index 370a02683..2b3845488 100644
--- a/contrib/depends/packages/icu4c.mk
+++ b/contrib/depends/packages/icu4c.mk
@@ -6,7 +6,7 @@ $(package)_sha256_hash=1f912c54035533fb4268809701d65c7468d00e292efbc31e644490845
$(package)_patches=icu-001-dont-build-static-dynamic-twice.patch
define $(package)_set_vars
- $(package)_build_opts=CFLAGS="$($(package)_cflags) $($(package)_cppflags) -DU_USING_ICU_NAMESPACE=0 --std=gnu++0x -DU_STATIC_IMPLEMENTATION -DU_COMBINED_IMPLEMENTATION -fPIC -DENABLE_STATIC=YES -DPGKDATA_MODE=static"
+ $(package)_build_opts=CFLAGS="$($(package)_cflags) $($(package)_cppflags) -DU_USING_ICU_NAMESPACE=0 -DU_STATIC_IMPLEMENTATION -DU_COMBINED_IMPLEMENTATION -fPIC -DENABLE_STATIC=YES -DPGKDATA_MODE=static"
endef
define $(package)_config_cmds
@@ -17,7 +17,7 @@ define $(package)_config_cmds
sh ../source/runConfigureICU Linux &&\
make &&\
cd ../buildb &&\
- sh ../source/$($(package)_autoconf) --enable-static=yes --disable-shared --disable-layout --disable-layoutex --disable-tests --disable-samples --prefix=$(host_prefix) --with-cross-build=`pwd`/../builda &&\
+ sh ../source/runConfigureICU MinGW --enable-static=yes --disable-shared --disable-layout --disable-layoutex --disable-tests --disable-samples --prefix=$(host_prefix) --with-cross-build=`pwd`/../builda &&\
$(MAKE) $($(package)_build_opts)
endef
diff --git a/contrib/depends/packages/native_protobuf.mk b/contrib/depends/packages/native_protobuf.mk
index 83e602341..35f648b9a 100644
--- a/contrib/depends/packages/native_protobuf.mk
+++ b/contrib/depends/packages/native_protobuf.mk
@@ -15,12 +15,11 @@ define $(package)_config_cmds
endef
define $(package)_build_cmds
- $(MAKE) -C src libprotobuf.la all
+ $(MAKE) -C src
endef
define $(package)_stage_cmds
- $(MAKE) DESTDIR=$($(package)_staging_dir) -C src install install-libLTLIBRARIES install-nobase_includeHEADERS &&\
- $(MAKE) DESTDIR=$($(package)_staging_dir) install-pkgconfigDATA
+ $(MAKE) DESTDIR=$($(package)_staging_dir) -C src install
endef
define $(package)_postprocess_cmds
diff --git a/contrib/depends/packages/openssl.mk b/contrib/depends/packages/openssl.mk
index 5ee9f17a6..e920b4409 100644
--- a/contrib/depends/packages/openssl.mk
+++ b/contrib/depends/packages/openssl.mk
@@ -1,35 +1,28 @@
package=openssl
-$(package)_version=1.0.1k
+$(package)_version=1.0.2q
$(package)_download_path=https://www.openssl.org/source
$(package)_file_name=$(package)-$($(package)_version).tar.gz
-$(package)_sha256_hash=8f9faeaebad088e772f4ef5e38252d472be4d878c6b3a2718c10a4fcebe7a41c
+$(package)_sha256_hash=5744cfcbcec2b1b48629f7354203bc1e5e9b5466998bbccc5b5fcde3b18eb684
define $(package)_set_vars
$(package)_config_env=AR="$($(package)_ar)" RANLIB="$($(package)_ranlib)" CC="$($(package)_cc)"
$(package)_config_opts=--prefix=$(host_prefix) --openssldir=$(host_prefix)/etc/openssl
-$(package)_config_opts+=no-camellia
$(package)_config_opts+=no-capieng
-$(package)_config_opts+=no-cast
-$(package)_config_opts+=no-comp
$(package)_config_opts+=no-dso
$(package)_config_opts+=no-dtls1
$(package)_config_opts+=no-ec_nistp_64_gcc_128
$(package)_config_opts+=no-gost
$(package)_config_opts+=no-gmp
$(package)_config_opts+=no-heartbeats
-$(package)_config_opts+=no-idea
$(package)_config_opts+=no-jpake
$(package)_config_opts+=no-krb5
$(package)_config_opts+=no-libunbound
$(package)_config_opts+=no-md2
-$(package)_config_opts+=no-mdc2
-$(package)_config_opts+=no-rc4
$(package)_config_opts+=no-rc5
$(package)_config_opts+=no-rdrand
$(package)_config_opts+=no-rfc3779
$(package)_config_opts+=no-rsax
$(package)_config_opts+=no-sctp
-$(package)_config_opts+=no-seed
$(package)_config_opts+=no-sha0
$(package)_config_opts+=no-shared
$(package)_config_opts+=no-ssl-trace
@@ -39,7 +32,6 @@ $(package)_config_opts+=no-static_engine
$(package)_config_opts+=no-store
$(package)_config_opts+=no-unit-test
$(package)_config_opts+=no-weak-ssl-ciphers
-$(package)_config_opts+=no-whirlpool
$(package)_config_opts+=no-zlib
$(package)_config_opts+=no-zlib-dynamic
$(package)_config_opts+=$($(package)_cflags) $($(package)_cppflags)
diff --git a/contrib/depends/packages/packages.mk b/contrib/depends/packages/packages.mk
index 4800c9936..1db50580b 100644
--- a/contrib/depends/packages/packages.mk
+++ b/contrib/depends/packages/packages.mk
@@ -1,10 +1,11 @@
-packages:=boost openssl zeromq cppzmq expat ldns cppzmq readline libiconv qt hidapi protobuf libusb
+packages:=boost openssl zeromq cppzmq expat ldns cppzmq readline libiconv hidapi protobuf libusb
native_packages := native_ccache native_protobuf
darwin_native_packages = native_biplist native_ds_store native_mac_alias
darwin_packages = sodium-darwin
linux_packages = eudev
+qt_packages = qt
ifeq ($(host_os),linux)
packages += unwind
diff --git a/contrib/depends/packages/readline.mk b/contrib/depends/packages/readline.mk
index 826c1029e..afefc7f07 100644
--- a/contrib/depends/packages/readline.mk
+++ b/contrib/depends/packages/readline.mk
@@ -1,9 +1,8 @@
package=readline
-$(package)_version=6.3
-$(package)_download_path=ftp://ftp.cwru.edu/pub/bash/
+$(package)_version=8.0
+$(package)_download_path=https://ftp.gnu.org/gnu/readline
$(package)_file_name=$(package)-$($(package)_version).tar.gz
-$(package)_sha256_hash=56ba6071b9462f980c5a72ab0023893b65ba6debb4eeb475d7a563dc65cafd43
-$(package)_patches=readline-1.patch
+$(package)_sha256_hash=e339f51971478d369f8a053a330a190781acb9864cf4c541060f12078948e461
define $(package)_set_vars
$(package)_build_opts=CC="$($(package)_cc)"
@@ -15,7 +14,6 @@ define $(package)_set_vars
endef
define $(package)_config_cmds
- patch -p1 < $($(package)_patch_dir)/readline-1.patch &&\
export bash_cv_have_mbstate_t=yes &&\
export bash_cv_wcwidth_broken=yes &&\
./configure $($(package)_config_opts)
@@ -29,5 +27,3 @@ define $(package)_stage_cmds
$(MAKE) DESTDIR=$($(package)_staging_dir) install
endef
-define $(package)_postprocess_cmds
-endef
diff --git a/contrib/depends/patches/readline/readline-1.patch b/contrib/depends/patches/readline/readline-1.patch
deleted file mode 100644
index 7610a29eb..000000000
--- a/contrib/depends/patches/readline/readline-1.patch
+++ /dev/null
@@ -1,187 +0,0 @@
-From c0572cecbeadc8fe24c70c5c39d49210a39ac719 Mon Sep 17 00:00:00 2001
-From: Timothy Gu <timothygu99@gmail.com>
-Date: Tue, 30 Sep 2014 10:32:33 -0700
-Subject: [PATCH 1/2] signals: safeguard the remaining usage of frequently
- missing signals
-
-diff --git a/input.c b/input.c
-index 117dfe8..465f0b9 100644
---- a/input.c
-+++ b/input.c
-@@ -532,9 +532,17 @@ rl_getc (stream)
- Otherwise (not EINTR), some error occurred, also signifying EOF. */
- if (errno != EINTR)
- return (RL_ISSTATE (RL_STATE_READCMD) ? READERR : EOF);
-- else if (_rl_caught_signal == SIGHUP || _rl_caught_signal == SIGTERM)
-+ else if (_rl_caught_signal == SIGTERM
-+#if defined(SIGHUP)
-+ || _rl_caught_signal == SIGHUP
-+#endif
-+ )
- return (RL_ISSTATE (RL_STATE_READCMD) ? READERR : EOF);
-- else if (_rl_caught_signal == SIGINT || _rl_caught_signal == SIGQUIT)
-+ else if (_rl_caught_signal == SIGINT
-+#if defined(SIGQUIT)
-+ || _rl_caught_signal == SIGQUIT
-+#endif
-+ )
- RL_CHECK_SIGNALS ();
-
- if (rl_signal_event_hook)
-diff --git a/signals.c b/signals.c
-index 61f02f9..7c921d6 100644
---- a/signals.c
-+++ b/signals.c
-@@ -216,7 +216,9 @@ _rl_handle_signal (sig)
- /* FALLTHROUGH */
-
- case SIGTERM:
-+#if defined (SIGHUP)
- case SIGHUP:
-+#endif
- #if defined (SIGTSTP)
- case SIGTSTP:
- case SIGTTOU:
-@@ -426,7 +428,9 @@ rl_set_signals ()
-
- rl_maybe_set_sighandler (SIGINT, rl_signal_handler, &old_int);
- rl_maybe_set_sighandler (SIGTERM, rl_signal_handler, &old_term);
-+#if defined (SIGHUP)
- rl_maybe_set_sighandler (SIGHUP, rl_signal_handler, &old_hup);
-+#endif
- #if defined (SIGQUIT)
- rl_maybe_set_sighandler (SIGQUIT, rl_signal_handler, &old_quit);
- #endif
-@@ -491,7 +495,9 @@ rl_clear_signals ()
- overhead */
- rl_maybe_restore_sighandler (SIGINT, &old_int);
- rl_maybe_restore_sighandler (SIGTERM, &old_term);
-+#if defined (SIGHUP)
- rl_maybe_restore_sighandler (SIGHUP, &old_hup);
-+#endif
- #if defined (SIGQUIT)
- rl_maybe_restore_sighandler (SIGQUIT, &old_quit);
- #endif
---
-1.8.3.2
-
-
-From 6896ffa4fc85bf0dfae58e69a860d2076c1d9fd2 Mon Sep 17 00:00:00 2001
-From: Timothy Gu <timothygu99@gmail.com>
-Date: Tue, 30 Sep 2014 17:16:32 -0700
-Subject: [PATCH 2/2] Handle missing S_IS* macros more gracefully
-
-diff --git a/colors.c b/colors.c
-index 89d9035..ec19844 100644
---- a/colors.c
-+++ b/colors.c
-@@ -152,14 +152,22 @@ _rl_print_color_indicator (char *f)
- {
- colored_filetype = C_FILE;
-
-+#if defined (S_ISUID)
- if ((mode & S_ISUID) != 0 && is_colored (C_SETUID))
- colored_filetype = C_SETUID;
-- else if ((mode & S_ISGID) != 0 && is_colored (C_SETGID))
-+ else
-+#endif
-+#if defined (S_ISGID)
-+ if ((mode & S_ISGID) != 0 && is_colored (C_SETGID))
- colored_filetype = C_SETGID;
-- else if (is_colored (C_CAP) && 0) //f->has_capability)
-+ else
-+#endif
-+ if (is_colored (C_CAP) && 0) //f->has_capability)
- colored_filetype = C_CAP;
-+#if defined(S_IXUGO)
- else if ((mode & S_IXUGO) != 0 && is_colored (C_EXEC))
- colored_filetype = C_EXEC;
-+#endif
- else if ((1 < astat.st_nlink) && is_colored (C_MULTIHARDLINK))
- colored_filetype = C_MULTIHARDLINK;
- }
-@@ -173,8 +181,10 @@ _rl_print_color_indicator (char *f)
- colored_filetype = C_STICKY_OTHER_WRITABLE;
- else
- #endif
-+#if defined (S_IWOTH)
- if ((mode & S_IWOTH) != 0 && is_colored (C_OTHER_WRITABLE))
- colored_filetype = C_OTHER_WRITABLE;
-+#endif
- #if defined (S_ISVTX)
- else if ((mode & S_ISVTX) != 0 && is_colored (C_STICKY))
- colored_filetype = C_STICKY;
-diff --git a/colors.h b/colors.h
-index fc926e5..e62edd0 100644
---- a/colors.h
-+++ b/colors.h
-@@ -96,7 +96,7 @@ enum indicator_no
- };
-
-
--#if !S_IXUGO
-+#if !S_IXUGO && defined(S_IXUSR) && defined(S_IXGRP) && defined(S_IXOTH)
- # define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
- #endif
-
-diff --git a/posixstat.h b/posixstat.h
-index 3eb7f29..854a2c9 100644
---- a/posixstat.h
-+++ b/posixstat.h
-@@ -78,30 +78,44 @@
-
- #if defined (S_IFBLK) && !defined (S_ISBLK)
- #define S_ISBLK(m) (((m)&S_IFMT) == S_IFBLK) /* block device */
-+#elif !defined (S_IFBLK)
-+#define S_ISBLK(m) 0
- #endif
-
- #if defined (S_IFCHR) && !defined (S_ISCHR)
- #define S_ISCHR(m) (((m)&S_IFMT) == S_IFCHR) /* character device */
-+#elif !defined (S_IFCHR)
-+#define S_ISCHR(m) 0
- #endif
-
- #if defined (S_IFDIR) && !defined (S_ISDIR)
- #define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) /* directory */
-+#elif !defined (S_IFDIR)
-+#define S_ISDIR(m) 0
- #endif
-
- #if defined (S_IFREG) && !defined (S_ISREG)
- #define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) /* file */
-+#elif !defined (S_IFREG)
-+#define S_ISREG(m) 0
- #endif
-
- #if defined (S_IFIFO) && !defined (S_ISFIFO)
- #define S_ISFIFO(m) (((m)&S_IFMT) == S_IFIFO) /* fifo - named pipe */
-+#elif !defined (S_IFIFO)
-+#define S_ISFIFO(m) 0
- #endif
-
- #if defined (S_IFLNK) && !defined (S_ISLNK)
- #define S_ISLNK(m) (((m)&S_IFMT) == S_IFLNK) /* symbolic link */
-+#elif !defined (S_IFLNK)
-+#define S_ISLNK(m) 0
- #endif
-
- #if defined (S_IFSOCK) && !defined (S_ISSOCK)
- #define S_ISSOCK(m) (((m)&S_IFMT) == S_IFSOCK) /* socket */
-+#elif !defined (S_IFSOCK)
-+#define S_ISSOCK(m) 0
- #endif
-
- /*
-@@ -137,6 +151,8 @@
- /* These are non-standard, but are used in builtins.c$symbolic_umask() */
- #define S_IRUGO (S_IRUSR | S_IRGRP | S_IROTH)
- #define S_IWUGO (S_IWUSR | S_IWGRP | S_IWOTH)
-+#if defined(S_IXUSR) && defined(S_IXGRP) && defined(S_IXOTH)
- #define S_IXUGO (S_IXUSR | S_IXGRP | S_IXOTH)
-+#endif
-
- #endif /* _POSIXSTAT_H_ */
---
-1.8.3.2
-
diff --git a/contrib/depends/toolchain.cmake.in b/contrib/depends/toolchain.cmake.in
index 547b59108..b0af7bd6b 100644
--- a/contrib/depends/toolchain.cmake.in
+++ b/contrib/depends/toolchain.cmake.in
@@ -47,6 +47,8 @@ set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # Find programs on host
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) # Find libs in target
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) # Find includes in target
+set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR} CACHE STRING "" FORCE)
+
# specify the cross compiler to be used. Darwin uses clang provided by the SDK.
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
SET(CMAKE_C_COMPILER @prefix@/native/bin/clang)
@@ -88,6 +90,11 @@ endif()
if(ARCHITECTURE STREQUAL "i686" AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
SET(LINUX_32 ON)
+ SET(ARCH_ID "i386")
+endif()
+
+if(ARCHITECTURE STREQUAL "x86_64" AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ SET(ARCH_ID "x86_64")
endif()
#Create a new global cmake flag that indicates building with depends
diff --git a/contrib/epee/CMakeLists.txt b/contrib/epee/CMakeLists.txt
index 035b24b36..a2c636304 100644
--- a/contrib/epee/CMakeLists.txt
+++ b/contrib/epee/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/contrib/epee/demo/iface/transport_defs.h b/contrib/epee/demo/iface/transport_defs.h
index 746694aa3..8638b5db9 100644
--- a/contrib/epee/demo/iface/transport_defs.h
+++ b/contrib/epee/demo/iface/transport_defs.h
@@ -81,7 +81,7 @@ namespace demo
{
const static int ID = 1000;
- struct request
+ struct request_t
{
std::string example_string_data;
some_test_data sub;
@@ -91,9 +91,10 @@ namespace demo
KV_SERIALIZE(sub)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
bool m_success;
std::list<some_test_data> subs;
@@ -104,6 +105,7 @@ namespace demo
END_KV_SERIALIZE_MAP()
};
};
+ typedef epee::misc_utils::struct_init<response_t> response;
@@ -111,7 +113,7 @@ namespace demo
{
const static int ID = 1001;
- struct request
+ struct request_t
{
std::string example_string_data2;
@@ -119,8 +121,9 @@ namespace demo
KV_SERIALIZE(example_string_data2)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
bool m_success;
@@ -129,6 +132,7 @@ namespace demo
KV_SERIALIZE(m_success)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
diff --git a/contrib/epee/include/hex.h b/contrib/epee/include/hex.h
index 901c666a9..6e720f128 100644
--- a/contrib/epee/include/hex.h
+++ b/contrib/epee/include/hex.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
@@ -32,6 +32,7 @@
#include <cstdint>
#include <iosfwd>
#include <string>
+#include <boost/utility/string_ref.hpp>
#include "wipeable_string.h"
#include "span.h"
@@ -68,4 +69,10 @@ namespace epee
//! Write `src` bytes as hex to `out`. `out` must be twice the length
static void buffer_unchecked(char* out, const span<const std::uint8_t> src) noexcept;
};
+
+ struct from_hex
+ {
+ //! \return An std::vector of unsigned integers from the `src`
+ static std::vector<uint8_t> vector(boost::string_ref src);
+ };
}
diff --git a/contrib/epee/include/int-util.h b/contrib/epee/include/int-util.h
index 3bcc085e2..0ed6505ff 100644
--- a/contrib/epee/include/int-util.h
+++ b/contrib/epee/include/int-util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/contrib/epee/include/math_helper.h b/contrib/epee/include/math_helper.h
index e22e8ee6e..35b649972 100644
--- a/contrib/epee/include/math_helper.h
+++ b/contrib/epee/include/math_helper.h
@@ -243,6 +243,7 @@ namespace math_helper
present = present << 32;
present |= fileTime.dwLowDateTime;
present /= 10; // mic-sec
+ return present;
#else
struct timeval tv;
gettimeofday(&tv, NULL);
diff --git a/contrib/epee/include/memwipe.h b/contrib/epee/include/memwipe.h
index 0d8f491b7..d586608cb 100644
--- a/contrib/epee/include/memwipe.h
+++ b/contrib/epee/include/memwipe.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/contrib/epee/include/misc_language.h b/contrib/epee/include/misc_language.h
index 7e4eb337d..5f7202150 100644
--- a/contrib/epee/include/misc_language.h
+++ b/contrib/epee/include/misc_language.h
@@ -159,5 +159,10 @@ namespace misc_utils
return slc;
}
+ template<typename T> struct struct_init: T
+ {
+ struct_init(): T{} {}
+ };
+
}
}
diff --git a/contrib/epee/include/net/abstract_tcp_server2.h b/contrib/epee/include/net/abstract_tcp_server2.h
index 37f4c782d..ec08c0f4b 100644
--- a/contrib/epee/include/net/abstract_tcp_server2.h
+++ b/contrib/epee/include/net/abstract_tcp_server2.h
@@ -46,6 +46,7 @@
#include <memory>
#include <boost/asio.hpp>
+#include <boost/asio/ssl.hpp>
#include <boost/array.hpp>
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
@@ -102,15 +103,19 @@ namespace net_utils
/// Construct a connection with the given io_service.
explicit connection( boost::asio::io_service& io_service,
boost::shared_ptr<shared_state> state,
- t_connection_type connection_type);
+ t_connection_type connection_type,
+ epee::net_utils::ssl_support_t ssl_support,
+ ssl_context_t &ssl_context);
explicit connection( boost::asio::ip::tcp::socket&& sock,
- boost::shared_ptr<shared_state> state,
- t_connection_type connection_type);
+ boost::shared_ptr<shared_state> state,
+ t_connection_type connection_type,
+ epee::net_utils::ssl_support_t ssl_support,
+ ssl_context_t &ssl_context);
+
+
virtual ~connection() noexcept(false);
- /// Get the socket associated with the connection.
- boost::asio::ip::tcp::socket& socket();
/// Start the first asynchronous operation for the connection.
bool start(bool is_income, bool is_multithreaded);
@@ -143,6 +148,10 @@ namespace net_utils
//------------------------------------------------------
boost::shared_ptr<connection<t_protocol_handler> > safe_shared_from_this();
bool shutdown();
+ /// Handle completion of a receive operation.
+ void handle_receive(const boost::system::error_code& e,
+ std::size_t bytes_transferred);
+
/// Handle completion of a read operation.
void handle_read(const boost::system::error_code& e,
std::size_t bytes_transferred);
@@ -160,7 +169,7 @@ namespace net_utils
/// Buffer for incoming data.
boost::array<char, 8192> buffer_;
- //boost::array<char, 1024> buffer_;
+ size_t buffer_ssl_init_fill;
t_connection_context context;
@@ -199,6 +208,13 @@ namespace net_utils
class boosted_tcp_server
: private boost::noncopyable
{
+ enum try_connect_result_t
+ {
+ CONNECT_SUCCESS,
+ CONNECT_FAILURE,
+ CONNECT_NO_SSL,
+ };
+
public:
typedef boost::shared_ptr<connection<t_protocol_handler> > connection_ptr;
typedef typename t_protocol_handler::connection_context t_connection_context;
@@ -212,8 +228,8 @@ namespace net_utils
std::map<std::string, t_connection_type> server_type_map;
void create_server_type_map();
- bool init_server(uint32_t port, const std::string address = "0.0.0.0");
- bool init_server(const std::string port, const std::string& address = "0.0.0.0");
+ bool init_server(uint32_t port, const std::string address = "0.0.0.0", epee::net_utils::ssl_support_t ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_autodetect, const std::pair<std::string, std::string> &private_key_and_certificate_path = std::make_pair(std::string(), std::string()), const std::list<std::string> &allowed_certificates = {}, const std::vector<std::vector<uint8_t>> &allowed_fingerprints = {}, bool allow_any_cert = false);
+ bool init_server(const std::string port, const std::string& address = "0.0.0.0", epee::net_utils::ssl_support_t ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_autodetect, const std::pair<std::string, std::string> &private_key_and_certificate_path = std::make_pair(std::string(), std::string()), const std::list<std::string> &allowed_certificates = {}, const std::vector<std::vector<uint8_t>> &allowed_fingerprints = {}, bool allow_any_cert = false);
/// Run the server's io_service loop.
bool run_server(size_t threads_count, bool wait = true, const boost::thread::attributes& attrs = boost::thread::attributes());
@@ -241,10 +257,11 @@ namespace net_utils
default_remote = std::move(remote);
}
- bool add_connection(t_connection_context& out, boost::asio::ip::tcp::socket&& sock, network_address real_remote);
- bool connect(const std::string& adr, const std::string& port, uint32_t conn_timeot, t_connection_context& cn, const std::string& bind_ip = "0.0.0.0");
+ bool add_connection(t_connection_context& out, boost::asio::ip::tcp::socket&& sock, network_address real_remote, epee::net_utils::ssl_support_t ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_autodetect);
+ try_connect_result_t try_connect(connection_ptr new_connection_l, const std::string& adr, const std::string& port, boost::asio::ip::tcp::socket &sock_, const boost::asio::ip::tcp::endpoint &remote_endpoint, const std::string &bind_ip, uint32_t conn_timeout, epee::net_utils::ssl_support_t ssl_support);
+ bool connect(const std::string& adr, const std::string& port, uint32_t conn_timeot, t_connection_context& cn, const std::string& bind_ip = "0.0.0.0", epee::net_utils::ssl_support_t ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_autodetect);
template<class t_callback>
- bool connect_async(const std::string& adr, const std::string& port, uint32_t conn_timeot, const t_callback &cb, const std::string& bind_ip = "0.0.0.0");
+ bool connect_async(const std::string& adr, const std::string& port, uint32_t conn_timeot, const t_callback &cb, const std::string& bind_ip = "0.0.0.0", epee::net_utils::ssl_support_t ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_autodetect);
typename t_protocol_handler::config_type& get_config_object()
{
@@ -330,7 +347,16 @@ namespace net_utils
const boost::shared_ptr<typename connection<t_protocol_handler>::shared_state> m_state;
/// The io_service used to perform asynchronous operations.
- std::unique_ptr<boost::asio::io_service> m_io_service_local_instance;
+ struct worker
+ {
+ worker()
+ : io_service(), work(io_service)
+ {}
+
+ boost::asio::io_service io_service;
+ boost::asio::io_service::work work;
+ };
+ std::unique_ptr<worker> m_io_service_local_instance;
boost::asio::io_service& io_service_;
/// Acceptor used to listen for incoming connections.
@@ -355,6 +381,9 @@ namespace net_utils
boost::mutex connections_mutex;
std::set<connection_ptr> connections_;
+ ssl_context_t m_ssl_context;
+ std::list<std::string> m_allowed_certificates;
+
}; // class <>boosted_tcp_server
diff --git a/contrib/epee/include/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl
index 9c89a18cf..f5548c585 100644
--- a/contrib/epee/include/net/abstract_tcp_server2.inl
+++ b/contrib/epee/include/net/abstract_tcp_server2.inl
@@ -78,19 +78,23 @@ PRAGMA_WARNING_DISABLE_VS(4355)
template<class t_protocol_handler>
connection<t_protocol_handler>::connection( boost::asio::io_service& io_service,
boost::shared_ptr<shared_state> state,
- t_connection_type connection_type
+ t_connection_type connection_type,
+ epee::net_utils::ssl_support_t ssl_support,
+ ssl_context_t &ssl_context
)
- : connection(boost::asio::ip::tcp::socket{io_service}, std::move(state), connection_type)
+ : connection(boost::asio::ip::tcp::socket{io_service}, std::move(state), connection_type, ssl_support, ssl_context)
{
}
template<class t_protocol_handler>
connection<t_protocol_handler>::connection( boost::asio::ip::tcp::socket&& sock,
boost::shared_ptr<shared_state> state,
- t_connection_type connection_type
+ t_connection_type connection_type,
+ epee::net_utils::ssl_support_t ssl_support,
+ ssl_context_t &ssl_context
)
:
- connection_basic(std::move(sock), state),
+ connection_basic(std::move(sock), state, ssl_support, ssl_context),
m_protocol_handler(this, check_and_get(state).config, context),
m_connection_type( connection_type ),
m_throttle_speed_in("speed_in", "throttle_speed_in"),
@@ -109,17 +113,11 @@ PRAGMA_WARNING_DISABLE_VS(4355)
{
if(!m_was_shutdown)
{
- _dbg3("[sock " << socket_.native_handle() << "] Socket destroyed without shutdown.");
+ _dbg3("[sock " << socket().native_handle() << "] Socket destroyed without shutdown.");
shutdown();
}
- _dbg3("[sock " << socket_.native_handle() << "] Socket destroyed");
- }
- //---------------------------------------------------------------------------------
- template<class t_protocol_handler>
- boost::asio::ip::tcp::socket& connection<t_protocol_handler>::socket()
- {
- return socket_;
+ _dbg3("[sock " << socket().native_handle() << "] Socket destroyed");
}
//---------------------------------------------------------------------------------
template<class t_protocol_handler>
@@ -142,7 +140,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
TRY_ENTRY();
boost::system::error_code ec;
- auto remote_ep = socket_.remote_endpoint(ec);
+ auto remote_ep = socket().remote_endpoint(ec);
CHECK_AND_NO_ASSERT_MES(!ec, false, "Failed to get remote endpoint: " << ec.message() << ':' << ec.value());
CHECK_AND_NO_ASSERT_MES(remote_ep.address().is_v4(), false, "IPv6 not supported here");
@@ -168,10 +166,11 @@ PRAGMA_WARNING_DISABLE_VS(4355)
const boost::uuids::uuid random_uuid = boost::uuids::random_generator()();
context = t_connection_context{};
- context.set_details(random_uuid, std::move(real_remote), is_income);
+ bool ssl = m_ssl_support == epee::net_utils::ssl_support_t::e_ssl_support_enabled;
+ context.set_details(random_uuid, std::move(real_remote), is_income, ssl);
boost::system::error_code ec;
- auto local_ep = socket_.local_endpoint(ec);
+ auto local_ep = socket().local_endpoint(ec);
CHECK_AND_NO_ASSERT_MES(!ec, false, "Failed to get local endpoint: " << ec.message() << ':' << ec.value());
_dbg3("[sock " << socket_.native_handle() << "] new connection from " << print_connection_context_short(context) <<
@@ -180,7 +179,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
if(static_cast<shared_state&>(get_stats()).pfilter && !static_cast<shared_state&>(get_stats()).pfilter->is_remote_host_allowed(context.m_remote_address))
{
- _dbg2("[sock " << socket_.native_handle() << "] host denied " << context.m_remote_address.host_str() << ", shutdowning connection");
+ _dbg2("[sock " << socket().native_handle() << "] host denied " << context.m_remote_address.host_str() << ", shutdowning connection");
close();
return false;
}
@@ -192,11 +191,21 @@ PRAGMA_WARNING_DISABLE_VS(4355)
reset_timer(get_default_timeout(), false);
- socket_.async_read_some(boost::asio::buffer(buffer_),
- strand_.wrap(
- boost::bind(&connection<t_protocol_handler>::handle_read, self,
- boost::asio::placeholders::error,
- boost::asio::placeholders::bytes_transferred)));
+ // first read on the raw socket to detect SSL for the server
+ buffer_ssl_init_fill = 0;
+ if (is_income && m_ssl_support != epee::net_utils::ssl_support_t::e_ssl_support_disabled)
+ socket().async_receive(boost::asio::buffer(buffer_),
+ boost::asio::socket_base::message_peek,
+ strand_.wrap(
+ boost::bind(&connection<t_protocol_handler>::handle_receive, self,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred)));
+ else
+ async_read_some(boost::asio::buffer(buffer_),
+ strand_.wrap(
+ boost::bind(&connection<t_protocol_handler>::handle_read, self,
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred)));
#if !defined(_WIN32) || !defined(__i686)
// not supported before Windows7, too lazy for runtime check
// Just exclude for 32bit windows builds
@@ -204,12 +213,12 @@ PRAGMA_WARNING_DISABLE_VS(4355)
int tos = get_tos_flag();
boost::asio::detail::socket_option::integer< IPPROTO_IP, IP_TOS >
optionTos( tos );
- socket_.set_option( optionTos );
+ socket().set_option( optionTos );
//_dbg1("Set ToS flag to " << tos);
#endif
boost::asio::ip::tcp::no_delay noDelayOption(false);
- socket_.set_option(noDelayOption);
+ socket().set_option(noDelayOption);
return true;
@@ -234,7 +243,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
template<class t_protocol_handler>
boost::asio::io_service& connection<t_protocol_handler>::get_io_service()
{
- return socket_.get_io_service();
+ return socket().get_io_service();
}
//---------------------------------------------------------------------------------
template<class t_protocol_handler>
@@ -246,9 +255,9 @@ PRAGMA_WARNING_DISABLE_VS(4355)
auto self = safe_shared_from_this();
if(!self)
return false;
- //_dbg3("[sock " << socket_.native_handle() << "] add_ref, m_peer_number=" << mI->m_peer_number);
+ //_dbg3("[sock " << socket().native_handle() << "] add_ref, m_peer_number=" << mI->m_peer_number);
CRITICAL_REGION_LOCAL(self->m_self_refs_lock);
- //_dbg3("[sock " << socket_.native_handle() << "] add_ref 2, m_peer_number=" << mI->m_peer_number);
+ //_dbg3("[sock " << socket().native_handle() << "] add_ref 2, m_peer_number=" << mI->m_peer_number);
if(m_was_shutdown)
return false;
++m_reference_count;
@@ -262,9 +271,9 @@ PRAGMA_WARNING_DISABLE_VS(4355)
{
TRY_ENTRY();
boost::shared_ptr<connection<t_protocol_handler> > back_connection_copy;
- LOG_TRACE_CC(context, "[sock " << socket_.native_handle() << "] release");
+ LOG_TRACE_CC(context, "[sock " << socket().native_handle() << "] release");
CRITICAL_REGION_BEGIN(m_self_refs_lock);
- CHECK_AND_ASSERT_MES(m_reference_count, false, "[sock " << socket_.native_handle() << "] m_reference_count already at 0 at connection<t_protocol_handler>::release() call");
+ CHECK_AND_ASSERT_MES(m_reference_count, false, "[sock " << socket().native_handle() << "] m_reference_count already at 0 at connection<t_protocol_handler>::release() call");
// is this the last reference?
if (--m_reference_count == 0) {
// move the held reference to a local variable, keeping the object alive until the function terminates
@@ -290,7 +299,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
std::string address, port;
boost::system::error_code e;
- boost::asio::ip::tcp::endpoint endpoint = socket_.remote_endpoint(e);
+ boost::asio::ip::tcp::endpoint endpoint = socket().remote_endpoint(e);
if (e)
{
address = "<not connected>";
@@ -302,7 +311,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
port = boost::lexical_cast<std::string>(endpoint.port());
}
MDEBUG(" connection type " << to_string( m_connection_type ) << " "
- << socket_.local_endpoint().address().to_string() << ":" << socket_.local_endpoint().port()
+ << socket().local_endpoint().address().to_string() << ":" << socket().local_endpoint().port()
<< " <--> " << context.m_remote_address.str() << " (via " << address << ":" << port << ")");
}
//---------------------------------------------------------------------------------
@@ -311,7 +320,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
std::size_t bytes_transferred)
{
TRY_ENTRY();
- //_info("[sock " << socket_.native_handle() << "] Async read calledback.");
+ //_info("[sock " << socket().native_handle() << "] Async read calledback.");
if (!e)
{
@@ -347,7 +356,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
} while(delay > 0);
} // any form of sleeping
- //_info("[sock " << socket_.native_handle() << "] RECV " << bytes_transferred);
+ //_info("[sock " << socket().native_handle() << "] RECV " << bytes_transferred);
logger_handle_net_read(bytes_transferred);
context.m_last_recv = time(NULL);
context.m_recv_cnt += bytes_transferred;
@@ -355,7 +364,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
bool recv_res = m_protocol_handler.handle_recv(buffer_.data(), bytes_transferred);
if(!recv_res)
{
- //_info("[sock " << socket_.native_handle() << "] protocol_want_close");
+ //_info("[sock " << socket().native_handle() << "] protocol_want_close");
//some error in protocol, protocol handler ask to close connection
boost::interprocess::ipcdetail::atomic_write32(&m_want_close_connection, 1);
@@ -369,24 +378,24 @@ PRAGMA_WARNING_DISABLE_VS(4355)
}else
{
reset_timer(get_timeout_from_bytes_read(bytes_transferred), false);
- socket_.async_read_some(boost::asio::buffer(buffer_),
+ async_read_some(boost::asio::buffer(buffer_),
strand_.wrap(
boost::bind(&connection<t_protocol_handler>::handle_read, connection<t_protocol_handler>::shared_from_this(),
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred)));
- //_info("[sock " << socket_.native_handle() << "]Async read requested.");
+ //_info("[sock " << socket().native_handle() << "]Async read requested.");
}
}else
{
- _dbg3("[sock " << socket_.native_handle() << "] Some not success at read: " << e.message() << ':' << e.value());
+ _dbg3("[sock " << socket().native_handle() << "] Some not success at read: " << e.message() << ':' << e.value());
if(e.value() != 2)
{
- _dbg3("[sock " << socket_.native_handle() << "] Some problems at read: " << e.message() << ':' << e.value());
+ _dbg3("[sock " << socket().native_handle() << "] Some problems at read: " << e.message() << ':' << e.value());
shutdown();
}
else
{
- _dbg3("[sock " << socket_.native_handle() << "] peer closed connection");
+ _dbg3("[sock " << socket().native_handle() << "] peer closed connection");
if (m_ready_to_close)
shutdown();
}
@@ -400,13 +409,85 @@ PRAGMA_WARNING_DISABLE_VS(4355)
}
//---------------------------------------------------------------------------------
template<class t_protocol_handler>
+ void connection<t_protocol_handler>::handle_receive(const boost::system::error_code& e,
+ std::size_t bytes_transferred)
+ {
+ TRY_ENTRY();
+ if (e)
+ {
+ // offload the error case
+ handle_read(e, bytes_transferred);
+ return;
+ }
+
+ reset_timer(get_timeout_from_bytes_read(bytes_transferred), false);
+
+ buffer_ssl_init_fill += bytes_transferred;
+ if (buffer_ssl_init_fill <= get_ssl_magic_size())
+ {
+ socket().async_receive(boost::asio::buffer(buffer_.data() + buffer_ssl_init_fill, buffer_.size() - buffer_ssl_init_fill),
+ boost::asio::socket_base::message_peek,
+ strand_.wrap(
+ boost::bind(&connection<t_protocol_handler>::handle_receive, connection<t_protocol_handler>::shared_from_this(),
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred)));
+ return;
+ }
+
+ // detect SSL
+ if (m_ssl_support == epee::net_utils::ssl_support_t::e_ssl_support_autodetect)
+ {
+ if (is_ssl((const unsigned char*)buffer_.data(), buffer_ssl_init_fill))
+ {
+ MDEBUG("That looks like SSL");
+ m_ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_enabled; // read/write to the SSL socket
+ }
+ else
+ {
+ MDEBUG("That does not look like SSL");
+ m_ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_disabled; // read/write to the raw socket
+ }
+ }
+
+ if (m_ssl_support == epee::net_utils::ssl_support_t::e_ssl_support_enabled)
+ {
+ // Handshake
+ if (!handshake(boost::asio::ssl::stream_base::server))
+ {
+ MERROR("SSL handshake failed");
+ boost::interprocess::ipcdetail::atomic_write32(&m_want_close_connection, 1);
+ bool do_shutdown = false;
+ CRITICAL_REGION_BEGIN(m_send_que_lock);
+ if(!m_send_que.size())
+ do_shutdown = true;
+ CRITICAL_REGION_END();
+ if(do_shutdown)
+ shutdown();
+ return;
+ }
+ }
+
+ async_read_some(boost::asio::buffer(buffer_),
+ strand_.wrap(
+ boost::bind(&connection<t_protocol_handler>::handle_read, connection<t_protocol_handler>::shared_from_this(),
+ boost::asio::placeholders::error,
+ boost::asio::placeholders::bytes_transferred)));
+
+ // If an error occurs then no new asynchronous operations are started. This
+ // means that all shared_ptr references to the connection object will
+ // disappear and the object will be destroyed automatically after this
+ // handler returns. The connection class's destructor closes the socket.
+ CATCH_ENTRY_L0("connection<t_protocol_handler>::handle_receive", void());
+ }
+ //---------------------------------------------------------------------------------
+ template<class t_protocol_handler>
bool connection<t_protocol_handler>::call_run_once_service_io()
{
TRY_ENTRY();
if(!m_is_multithreaded)
{
//single thread model, we can wait in blocked call
- size_t cnt = socket_.get_io_service().run_one();
+ size_t cnt = socket().get_io_service().run_one();
if(!cnt)//service is going to quit
return false;
}else
@@ -416,7 +497,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
//if no handlers were called
//TODO: Maybe we need to have have critical section + event + callback to upper protocol to
//ask it inside(!) critical region if we still able to go in event wait...
- size_t cnt = socket_.get_io_service().poll_one();
+ size_t cnt = socket().get_io_service().poll_one();
if(!cnt)
misc_utils::sleep_no_w(1);
}
@@ -525,7 +606,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
context.m_max_speed_up = std::max(context.m_max_speed_up, context.m_current_speed_up);
}
- //_info("[sock " << socket_.native_handle() << "] SEND " << cb);
+ //_info("[sock " << socket().native_handle() << "] SEND " << cb);
context.m_last_send = time(NULL);
context.m_send_cnt += cb;
//some data should be wrote to stream
@@ -570,7 +651,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
MDEBUG("do_send_chunk() NOW just queues: packet="<<size_now<<" B, is added to queue-size="<<m_send_que.size());
//do_send_handler_delayed( ptr , size_now ); // (((H))) // empty function
- LOG_TRACE_CC(context, "[sock " << socket_.native_handle() << "] Async send requested " << m_send_que.front().size());
+ LOG_TRACE_CC(context, "[sock " << socket().native_handle() << "] Async send requested " << m_send_que.front().size());
}
else
{ // no active operation
@@ -588,14 +669,14 @@ PRAGMA_WARNING_DISABLE_VS(4355)
CHECK_AND_ASSERT_MES( size_now == m_send_que.front().size(), false, "Unexpected queue size");
reset_timer(get_default_timeout(), false);
- boost::asio::async_write(socket_, boost::asio::buffer(m_send_que.front().data(), size_now ) ,
+ async_write(boost::asio::buffer(m_send_que.front().data(), size_now ) ,
//strand_.wrap(
boost::bind(&connection<t_protocol_handler>::handle_write, self, _1, _2)
//)
);
//_dbg3("(chunk): " << size_now);
//logger_handle_net_write(size_now);
- //_info("[sock " << socket_.native_handle() << "] Async send requested " << m_send_que.front().size());
+ //_info("[sock " << socket().native_handle() << "] Async send requested " << m_send_que.front().size());
}
//do_send_handler_stop( ptr , cb ); // empty function
@@ -680,7 +761,8 @@ PRAGMA_WARNING_DISABLE_VS(4355)
// Initiate graceful connection closure.
m_timer.cancel();
boost::system::error_code ignored_ec;
- socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec);
+ socket().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec);
+ socket().close();
if (!m_host.empty())
{
try { host_count(m_host, -1); } catch (...) { /* ignore */ }
@@ -698,7 +780,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
auto self = safe_shared_from_this();
if(!self)
return false;
- //_info("[sock " << socket_.native_handle() << "] Que Shutdown called.");
+ //_info("[sock " << socket().native_handle() << "] Que Shutdown called.");
m_timer.cancel();
size_t send_que_size = 0;
CRITICAL_REGION_BEGIN(m_send_que_lock);
@@ -733,11 +815,11 @@ PRAGMA_WARNING_DISABLE_VS(4355)
void connection<t_protocol_handler>::handle_write(const boost::system::error_code& e, size_t cb)
{
TRY_ENTRY();
- LOG_TRACE_CC(context, "[sock " << socket_.native_handle() << "] Async send calledback " << cb);
+ LOG_TRACE_CC(context, "[sock " << socket().native_handle() << "] Async send calledback " << cb);
if (e)
{
- _dbg1("[sock " << socket_.native_handle() << "] Some problems at write: " << e.message() << ':' << e.value());
+ _dbg1("[sock " << socket().native_handle() << "] Some problems at write: " << e.message() << ':' << e.value());
shutdown();
return;
}
@@ -752,7 +834,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
CRITICAL_REGION_BEGIN(m_send_que_lock);
if(m_send_que.empty())
{
- _erro("[sock " << socket_.native_handle() << "] m_send_que.size() == 0 at handle_write!");
+ _erro("[sock " << socket().native_handle() << "] m_send_que.size() == 0 at handle_write!");
return;
}
@@ -772,11 +854,11 @@ PRAGMA_WARNING_DISABLE_VS(4355)
if (speed_limit_is_enabled())
do_send_handler_write_from_queue(e, m_send_que.front().size() , m_send_que.size()); // (((H)))
CHECK_AND_ASSERT_MES( size_now == m_send_que.front().size(), void(), "Unexpected queue size");
- boost::asio::async_write(socket_, boost::asio::buffer(m_send_que.front().data(), size_now) ,
- // strand_.wrap(
- boost::bind(&connection<t_protocol_handler>::handle_write, connection<t_protocol_handler>::shared_from_this(), _1, _2)
- // )
- );
+ async_write(boost::asio::buffer(m_send_que.front().data(), size_now) ,
+ // strand_.wrap(
+ boost::bind(&connection<t_protocol_handler>::handle_write, connection<t_protocol_handler>::shared_from_this(), _1, _2)
+ // )
+ );
//_dbg3("(normal)" << size_now);
}
CRITICAL_REGION_END();
@@ -809,15 +891,16 @@ PRAGMA_WARNING_DISABLE_VS(4355)
template<class t_protocol_handler>
boosted_tcp_server<t_protocol_handler>::boosted_tcp_server( t_connection_type connection_type ) :
m_state(boost::make_shared<typename connection<t_protocol_handler>::shared_state>()),
- m_io_service_local_instance(new boost::asio::io_service()),
- io_service_(*m_io_service_local_instance.get()),
+ m_io_service_local_instance(new worker()),
+ io_service_(m_io_service_local_instance->io_service),
acceptor_(io_service_),
default_remote(),
m_stop_signal_sent(false), m_port(0),
m_threads_count(0),
m_thread_index(0),
m_connection_type( connection_type ),
- new_connection_()
+ new_connection_(),
+ m_ssl_context({boost::asio::ssl::context(boost::asio::ssl::context::tlsv12), {}})
{
create_server_type_map();
m_thread_name_prefix = "NET";
@@ -833,7 +916,8 @@ PRAGMA_WARNING_DISABLE_VS(4355)
m_threads_count(0),
m_thread_index(0),
m_connection_type(connection_type),
- new_connection_()
+ new_connection_(),
+ m_ssl_context({boost::asio::ssl::context(boost::asio::ssl::context::sslv23), {}})
{
create_server_type_map();
m_thread_name_prefix = "NET";
@@ -855,12 +939,14 @@ PRAGMA_WARNING_DISABLE_VS(4355)
}
//---------------------------------------------------------------------------------
template<class t_protocol_handler>
- bool boosted_tcp_server<t_protocol_handler>::init_server(uint32_t port, const std::string address)
+ bool boosted_tcp_server<t_protocol_handler>::init_server(uint32_t port, const std::string address, epee::net_utils::ssl_support_t ssl_support, const std::pair<std::string, std::string> &private_key_and_certificate_path, const std::list<std::string> &allowed_certificates, const std::vector<std::vector<uint8_t>> &allowed_fingerprints, bool allow_any_cert)
{
TRY_ENTRY();
m_stop_signal_sent = false;
m_port = port;
m_address = address;
+ if (ssl_support != epee::net_utils::ssl_support_t::e_ssl_support_disabled)
+ m_ssl_context = create_ssl_context(private_key_and_certificate_path, allowed_certificates, allowed_fingerprints, allow_any_cert);
// Open the acceptor with the option to reuse the address (i.e. SO_REUSEADDR).
boost::asio::ip::tcp::resolver resolver(io_service_);
boost::asio::ip::tcp::resolver::query query(address, boost::lexical_cast<std::string>(port), boost::asio::ip::tcp::resolver::query::canonical_name);
@@ -872,7 +958,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
boost::asio::ip::tcp::endpoint binded_endpoint = acceptor_.local_endpoint();
m_port = binded_endpoint.port();
MDEBUG("start accept");
- new_connection_.reset(new connection<t_protocol_handler>(io_service_, m_state, m_connection_type));
+ new_connection_.reset(new connection<t_protocol_handler>(io_service_, m_state, m_connection_type, ssl_support, m_ssl_context));
acceptor_.async_accept(new_connection_->socket(),
boost::bind(&boosted_tcp_server<t_protocol_handler>::handle_accept, this,
boost::asio::placeholders::error));
@@ -894,7 +980,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
PUSH_WARNINGS
DISABLE_GCC_WARNING(maybe-uninitialized)
template<class t_protocol_handler>
- bool boosted_tcp_server<t_protocol_handler>::init_server(const std::string port, const std::string& address)
+ bool boosted_tcp_server<t_protocol_handler>::init_server(const std::string port, const std::string& address, epee::net_utils::ssl_support_t ssl_support, const std::pair<std::string, std::string> &private_key_and_certificate_path, const std::list<std::string> &allowed_certificates, const std::vector<std::vector<uint8_t>> &allowed_fingerprints, bool allow_any_cert)
{
uint32_t p = 0;
@@ -902,7 +988,7 @@ DISABLE_GCC_WARNING(maybe-uninitialized)
MERROR("Failed to convert port no = " << port);
return false;
}
- return this->init_server(p, address);
+ return this->init_server(p, address, ssl_support, private_key_and_certificate_path, allowed_certificates, allowed_fingerprints, allow_any_cert);
}
POP_WARNINGS
//---------------------------------------------------------------------------------
@@ -919,9 +1005,8 @@ POP_WARNINGS
{
try
{
- size_t cnt = io_service_.run();
- if (cnt == 0)
- misc_utils::sleep_no_w(1);
+ io_service_.run();
+ return true;
}
catch(const std::exception& ex)
{
@@ -1067,11 +1152,18 @@ POP_WARNINGS
if (!e)
{
if (m_connection_type == e_connection_type_RPC) {
- MDEBUG("New server for RPC connections");
+ const char *ssl_message = "unknown";
+ switch (new_connection_->get_ssl_support())
+ {
+ case epee::net_utils::ssl_support_t::e_ssl_support_disabled: ssl_message = "disabled"; break;
+ case epee::net_utils::ssl_support_t::e_ssl_support_enabled: ssl_message = "enabled"; break;
+ case epee::net_utils::ssl_support_t::e_ssl_support_autodetect: ssl_message = "autodetection"; break;
+ }
+ MDEBUG("New server for RPC connections, SSL " << ssl_message);
new_connection_->setRpcStation(); // hopefully this is not needed actually
}
connection_ptr conn(std::move(new_connection_));
- new_connection_.reset(new connection<t_protocol_handler>(io_service_, m_state, m_connection_type));
+ new_connection_.reset(new connection<t_protocol_handler>(io_service_, m_state, m_connection_type, conn->get_ssl_support(), m_ssl_context));
acceptor_.async_accept(new_connection_->socket(),
boost::bind(&boosted_tcp_server<t_protocol_handler>::handle_accept, this,
boost::asio::placeholders::error));
@@ -1079,10 +1171,16 @@ POP_WARNINGS
boost::asio::socket_base::keep_alive opt(true);
conn->socket().set_option(opt);
+ bool res;
if (default_remote.get_type_id() == net_utils::address_type::invalid)
- conn->start(true, 1 < m_threads_count);
+ res = conn->start(true, 1 < m_threads_count);
else
- conn->start(true, 1 < m_threads_count, default_remote);
+ res = conn->start(true, 1 < m_threads_count, default_remote);
+ if (!res)
+ {
+ conn->cancel();
+ return;
+ }
conn->save_dbg_log();
return;
}
@@ -1100,18 +1198,18 @@ POP_WARNINGS
assert(m_state != nullptr); // always set in constructor
_erro("Some problems at accept: " << e.message() << ", connections_count = " << m_state->sock_count);
misc_utils::sleep_no_w(100);
- new_connection_.reset(new connection<t_protocol_handler>(io_service_, m_state, m_connection_type));
+ new_connection_.reset(new connection<t_protocol_handler>(io_service_, m_state, m_connection_type, new_connection_->get_ssl_support(), m_ssl_context));
acceptor_.async_accept(new_connection_->socket(),
boost::bind(&boosted_tcp_server<t_protocol_handler>::handle_accept, this,
boost::asio::placeholders::error));
}
//---------------------------------------------------------------------------------
template<class t_protocol_handler>
- bool boosted_tcp_server<t_protocol_handler>::add_connection(t_connection_context& out, boost::asio::ip::tcp::socket&& sock, network_address real_remote)
+ bool boosted_tcp_server<t_protocol_handler>::add_connection(t_connection_context& out, boost::asio::ip::tcp::socket&& sock, network_address real_remote, epee::net_utils::ssl_support_t ssl_support)
{
if(std::addressof(get_io_service()) == std::addressof(sock.get_io_service()))
{
- connection_ptr conn(new connection<t_protocol_handler>(std::move(sock), m_state, m_connection_type));
+ connection_ptr conn(new connection<t_protocol_handler>(std::move(sock), m_state, m_connection_type, ssl_support, m_ssl_context));
if(conn->start(false, 1 < m_threads_count, std::move(real_remote)))
{
conn->get_context(out);
@@ -1127,34 +1225,10 @@ POP_WARNINGS
}
//---------------------------------------------------------------------------------
template<class t_protocol_handler>
- bool boosted_tcp_server<t_protocol_handler>::connect(const std::string& adr, const std::string& port, uint32_t conn_timeout, t_connection_context& conn_context, const std::string& bind_ip)
+ typename boosted_tcp_server<t_protocol_handler>::try_connect_result_t boosted_tcp_server<t_protocol_handler>::try_connect(connection_ptr new_connection_l, const std::string& adr, const std::string& port, boost::asio::ip::tcp::socket &sock_, const boost::asio::ip::tcp::endpoint &remote_endpoint, const std::string &bind_ip, uint32_t conn_timeout, epee::net_utils::ssl_support_t ssl_support)
{
TRY_ENTRY();
- connection_ptr new_connection_l(new connection<t_protocol_handler>(io_service_, m_state, m_connection_type) );
- connections_mutex.lock();
- connections_.insert(new_connection_l);
- MDEBUG("connections_ size now " << connections_.size());
- connections_mutex.unlock();
- epee::misc_utils::auto_scope_leave_caller scope_exit_handler = epee::misc_utils::create_scope_leave_handler([&](){ CRITICAL_REGION_LOCAL(connections_mutex); connections_.erase(new_connection_l); });
- boost::asio::ip::tcp::socket& sock_ = new_connection_l->socket();
-
- //////////////////////////////////////////////////////////////////////////
- boost::asio::ip::tcp::resolver resolver(io_service_);
- boost::asio::ip::tcp::resolver::query query(boost::asio::ip::tcp::v4(), adr, port, boost::asio::ip::tcp::resolver::query::canonical_name);
- boost::asio::ip::tcp::resolver::iterator iterator = resolver.resolve(query);
- boost::asio::ip::tcp::resolver::iterator end;
- if(iterator == end)
- {
- _erro("Failed to resolve " << adr);
- return false;
- }
- //////////////////////////////////////////////////////////////////////////
-
-
- //boost::asio::ip::tcp::endpoint remote_endpoint(boost::asio::ip::address::from_string(addr.c_str()), port);
- boost::asio::ip::tcp::endpoint remote_endpoint(*iterator);
-
sock_.open(remote_endpoint.protocol());
if(bind_ip != "0.0.0.0" && bind_ip != "0" && bind_ip != "" )
{
@@ -1166,7 +1240,7 @@ POP_WARNINGS
MERROR("Error binding to " << bind_ip << ": " << ec.message());
if (sock_.is_open())
sock_.close();
- return false;
+ return CONNECT_FAILURE;
}
}
@@ -1200,14 +1274,14 @@ POP_WARNINGS
{
if (sock_.is_open())
sock_.close();
- return false;
+ return CONNECT_FAILURE;
}
if(local_shared_context->ec == boost::asio::error::would_block && !r)
{
//timeout
sock_.close();
_dbg3("Failed to connect to " << adr << ":" << port << ", because of timeout (" << conn_timeout << ")");
- return false;
+ return CONNECT_FAILURE;
}
}
ec = local_shared_context->ec;
@@ -1217,11 +1291,79 @@ POP_WARNINGS
_dbg3("Some problems at connect, message: " << ec.message());
if (sock_.is_open())
sock_.close();
- return false;
+ return CONNECT_FAILURE;
}
_dbg3("Connected success to " << adr << ':' << port);
+ const epee::net_utils::ssl_support_t ssl_support = new_connection_l->get_ssl_support();
+ if (ssl_support == epee::net_utils::ssl_support_t::e_ssl_support_enabled || ssl_support == epee::net_utils::ssl_support_t::e_ssl_support_autodetect)
+ {
+ // Handshake
+ MDEBUG("Handshaking SSL...");
+ if (!new_connection_l->handshake(boost::asio::ssl::stream_base::client))
+ {
+ if (ssl_support == epee::net_utils::ssl_support_t::e_ssl_support_autodetect)
+ {
+ boost::system::error_code ignored_ec;
+ sock_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec);
+ sock_.close();
+ return CONNECT_NO_SSL;
+ }
+ MERROR("SSL handshake failed");
+ if (sock_.is_open())
+ sock_.close();
+ return CONNECT_FAILURE;
+ }
+ }
+
+ return CONNECT_SUCCESS;
+
+ CATCH_ENTRY_L0("boosted_tcp_server<t_protocol_handler>::try_connect", CONNECT_FAILURE);
+ }
+ //---------------------------------------------------------------------------------
+ template<class t_protocol_handler>
+ bool boosted_tcp_server<t_protocol_handler>::connect(const std::string& adr, const std::string& port, uint32_t conn_timeout, t_connection_context& conn_context, const std::string& bind_ip, epee::net_utils::ssl_support_t ssl_support)
+ {
+ TRY_ENTRY();
+
+ connection_ptr new_connection_l(new connection<t_protocol_handler>(io_service_, m_state, m_connection_type, ssl_support, m_ssl_context) );
+ connections_mutex.lock();
+ connections_.insert(new_connection_l);
+ MDEBUG("connections_ size now " << connections_.size());
+ connections_mutex.unlock();
+ epee::misc_utils::auto_scope_leave_caller scope_exit_handler = epee::misc_utils::create_scope_leave_handler([&](){ CRITICAL_REGION_LOCAL(connections_mutex); connections_.erase(new_connection_l); });
+ boost::asio::ip::tcp::socket& sock_ = new_connection_l->socket();
+
+ //////////////////////////////////////////////////////////////////////////
+ boost::asio::ip::tcp::resolver resolver(io_service_);
+ boost::asio::ip::tcp::resolver::query query(boost::asio::ip::tcp::v4(), adr, port, boost::asio::ip::tcp::resolver::query::canonical_name);
+ boost::asio::ip::tcp::resolver::iterator iterator = resolver.resolve(query);
+ boost::asio::ip::tcp::resolver::iterator end;
+ if(iterator == end)
+ {
+ _erro("Failed to resolve " << adr);
+ return false;
+ }
+ //////////////////////////////////////////////////////////////////////////
+
+
+ //boost::asio::ip::tcp::endpoint remote_endpoint(boost::asio::ip::address::from_string(addr.c_str()), port);
+ boost::asio::ip::tcp::endpoint remote_endpoint(*iterator);
+
+ auto try_connect_result = try_connect(new_connection_l, adr, port, sock_, remote_endpoint, bind_ip, conn_timeout, ssl_support);
+ if (try_connect_result == CONNECT_FAILURE)
+ return false;
+ if (ssl_support == epee::net_utils::ssl_support_t::e_ssl_support_autodetect && try_connect_result == CONNECT_NO_SSL)
+ {
+ // we connected, but could not connect with SSL, try without
+ MERROR("SSL handshake failed on an autodetect connection, reconnecting without SSL");
+ new_connection_l->disable_ssl();
+ try_connect_result = try_connect(new_connection_l, adr, port, sock_, remote_endpoint, bind_ip, conn_timeout, epee::net_utils::ssl_support_t::e_ssl_support_disabled);
+ if (try_connect_result != CONNECT_SUCCESS)
+ return false;
+ }
+
// start adds the connection to the config object's list, so we don't need to have it locally anymore
connections_mutex.lock();
connections_.erase(new_connection_l);
@@ -1246,10 +1388,10 @@ POP_WARNINGS
}
//---------------------------------------------------------------------------------
template<class t_protocol_handler> template<class t_callback>
- bool boosted_tcp_server<t_protocol_handler>::connect_async(const std::string& adr, const std::string& port, uint32_t conn_timeout, const t_callback &cb, const std::string& bind_ip)
+ bool boosted_tcp_server<t_protocol_handler>::connect_async(const std::string& adr, const std::string& port, uint32_t conn_timeout, const t_callback &cb, const std::string& bind_ip, epee::net_utils::ssl_support_t ssl_support)
{
TRY_ENTRY();
- connection_ptr new_connection_l(new connection<t_protocol_handler>(io_service_, m_state, m_connection_type) );
+ connection_ptr new_connection_l(new connection<t_protocol_handler>(io_service_, m_state, m_connection_type, ssl_support, m_ssl_context) );
connections_mutex.lock();
connections_.insert(new_connection_l);
MDEBUG("connections_ size now " << connections_.size());
diff --git a/contrib/epee/include/net/connection_basic.hpp b/contrib/epee/include/net/connection_basic.hpp
index b1b271db9..feedc6895 100644
--- a/contrib/epee/include/net/connection_basic.hpp
+++ b/contrib/epee/include/net/connection_basic.hpp
@@ -8,7 +8,7 @@
// ! (how ever if in some wonderful juristdictions that is not the case, then why not make another sub-class withat that members and licence it as epee part)
// ! Working on above premise, IF this is valid in your juristdictions, then consider this code as released as:
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -47,8 +47,10 @@
#include <memory>
#include <boost/asio.hpp>
+#include <boost/asio/ssl.hpp>
#include "net/net_utils_base.h"
+#include "net/net_ssl.h"
#include "syncobj.h"
namespace epee
@@ -95,16 +97,56 @@ class connection_basic { // not-templated base class for rapid developmet of som
/// Strand to ensure the connection's handlers are not called concurrently.
boost::asio::io_service::strand strand_;
/// Socket for the connection.
- boost::asio::ip::tcp::socket socket_;
+ ssl_context_t &m_ssl_context;
+ ssl_support_t m_ssl_support;
+ boost::asio::ssl::stream<boost::asio::ip::tcp::socket> socket_;
public:
// first counter is the ++/-- count of current sockets, the other socket_number is only-increasing ++ number generator
- connection_basic(boost::asio::ip::tcp::socket&& socket, boost::shared_ptr<socket_stats> stats);
+ connection_basic(boost::asio::ip::tcp::socket&& socket, boost::shared_ptr<socket_stats> stats, ssl_support_t ssl_support, ssl_context_t &ssl_context);
+ connection_basic(boost::asio::io_service &io_service, boost::shared_ptr<socket_stats> stats, ssl_support_t ssl_support, ssl_context_t &ssl_context);
virtual ~connection_basic() noexcept(false);
//! \return `socket_stats` object passed in construction (ptr never changes).
socket_stats& get_stats() noexcept { return *m_stats; /* verified in constructor */ }
+ connection_basic(boost::asio::io_service& io_service, std::atomic<long> &ref_sock_count, std::atomic<long> &sock_number, ssl_support_t ssl, ssl_context_t &ssl_context);
+
+ boost::asio::ip::tcp::socket& socket() { return socket_.next_layer(); }
+ ssl_support_t get_ssl_support() const { return m_ssl_support; }
+ void disable_ssl() { m_ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_disabled; }
+
+ bool handshake(boost::asio::ssl::stream_base::handshake_type type)
+ {
+ return ssl_handshake(socket_, type, m_ssl_context);
+ }
+
+ template<typename MutableBufferSequence, typename ReadHandler>
+ void async_read_some(const MutableBufferSequence &buffers, ReadHandler &&handler)
+ {
+ if (m_ssl_support == epee::net_utils::ssl_support_t::e_ssl_support_enabled)
+ socket_.async_read_some(buffers, std::forward<ReadHandler>(handler));
+ else
+ socket().async_read_some(buffers, std::forward<ReadHandler>(handler));
+ }
+
+ template<typename ConstBufferSequence, typename WriteHandler>
+ void async_write_some(const ConstBufferSequence &buffers, WriteHandler &&handler)
+ {
+ if (m_ssl_support == epee::net_utils::ssl_support_t::e_ssl_support_enabled)
+ socket_.async_write_some(buffers, std::forward<WriteHandler>(handler));
+ else
+ socket().async_write_some(buffers, std::forward<WriteHandler>(handler));
+ }
+
+ template<typename ConstBufferSequence, typename WriteHandler>
+ void async_write(const ConstBufferSequence &buffers, WriteHandler &&handler)
+ {
+ if (m_ssl_support == epee::net_utils::ssl_support_t::e_ssl_support_enabled)
+ boost::asio::async_write(socket_, buffers, std::forward<WriteHandler>(handler));
+ else
+ boost::asio::async_write(socket(), buffers, std::forward<WriteHandler>(handler));
+ }
// various handlers to be called from connection class:
void do_send_handler_write(const void * ptr , size_t cb);
diff --git a/contrib/epee/include/net/http_auth.h b/contrib/epee/include/net/http_auth.h
index 4324c41fd..00b9750b7 100644
--- a/contrib/epee/include/net/http_auth.h
+++ b/contrib/epee/include/net/http_auth.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/contrib/epee/include/net/http_client.h b/contrib/epee/include/net/http_client.h
index e01691794..58a8e6888 100644
--- a/contrib/epee/include/net/http_client.h
+++ b/contrib/epee/include/net/http_client.h
@@ -275,7 +275,11 @@ namespace net_utils
chunked_state m_chunked_state;
std::string m_chunked_cache;
critical_section m_lock;
- bool m_ssl;
+ epee::net_utils::ssl_support_t m_ssl_support;
+ std::pair<std::string, std::string> m_ssl_private_key_and_certificate_path;
+ std::list<std::string> m_ssl_allowed_certificates;
+ std::vector<std::vector<uint8_t>> m_ssl_allowed_fingerprints;
+ bool m_ssl_allow_any_cert;
public:
explicit http_simple_client_template()
@@ -293,35 +297,40 @@ namespace net_utils
, m_chunked_state()
, m_chunked_cache()
, m_lock()
- , m_ssl(false)
+ , m_ssl_support(epee::net_utils::ssl_support_t::e_ssl_support_autodetect)
{}
const std::string &get_host() const { return m_host_buff; };
const std::string &get_port() const { return m_port; };
- bool set_server(const std::string& address, boost::optional<login> user, bool ssl = false)
+ bool set_server(const std::string& address, boost::optional<login> user, epee::net_utils::ssl_support_t ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_autodetect, const std::pair<std::string, std::string> &private_key_and_certificate_path = {}, const std::list<std::string> &allowed_ssl_certificates = {}, const std::vector<std::vector<uint8_t>> &allowed_ssl_fingerprints = {}, bool allow_any_cert = false)
{
http::url_content parsed{};
const bool r = parse_url(address, parsed);
CHECK_AND_ASSERT_MES(r, false, "failed to parse url: " << address);
- set_server(std::move(parsed.host), std::to_string(parsed.port), std::move(user), ssl);
+ set_server(std::move(parsed.host), std::to_string(parsed.port), std::move(user), ssl_support, private_key_and_certificate_path, allowed_ssl_certificates, allowed_ssl_fingerprints, allow_any_cert);
return true;
}
- void set_server(std::string host, std::string port, boost::optional<login> user, bool ssl = false)
+ void set_server(std::string host, std::string port, boost::optional<login> user, epee::net_utils::ssl_support_t ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_autodetect, const std::pair<std::string, std::string> &private_key_and_certificate_path = {}, const std::list<std::string> &allowed_ssl_certificates = {}, const std::vector<std::vector<uint8_t>> &allowed_ssl_fingerprints = {}, bool allow_any_cert = false)
{
CRITICAL_REGION_LOCAL(m_lock);
disconnect();
m_host_buff = std::move(host);
m_port = std::move(port);
m_auth = user ? http_client_auth{std::move(*user)} : http_client_auth{};
- m_ssl = ssl;
+ m_ssl_support = ssl_support;
+ m_ssl_private_key_and_certificate_path = private_key_and_certificate_path;
+ m_ssl_allowed_certificates = allowed_ssl_certificates;
+ m_ssl_allowed_fingerprints = allowed_ssl_fingerprints;
+ m_ssl_allow_any_cert = allow_any_cert;
+ m_net_client.set_ssl(m_ssl_support, m_ssl_private_key_and_certificate_path, m_ssl_allowed_certificates, m_ssl_allowed_fingerprints, m_ssl_allow_any_cert);
}
bool connect(std::chrono::milliseconds timeout)
{
CRITICAL_REGION_LOCAL(m_lock);
- return m_net_client.connect(m_host_buff, m_port, timeout, m_ssl);
+ return m_net_client.connect(m_host_buff, m_port, timeout, "0.0.0.0");
}
//---------------------------------------------------------------------------
bool disconnect()
@@ -330,10 +339,10 @@ namespace net_utils
return m_net_client.disconnect();
}
//---------------------------------------------------------------------------
- bool is_connected()
+ bool is_connected(bool *ssl = NULL)
{
CRITICAL_REGION_LOCAL(m_lock);
- return m_net_client.is_connected();
+ return m_net_client.is_connected(ssl);
}
//---------------------------------------------------------------------------
virtual bool handle_target_data(std::string& piece_of_transfer)
diff --git a/contrib/epee/include/net/http_protocol_handler.inl b/contrib/epee/include/net/http_protocol_handler.inl
index b53bdc200..ae8e43477 100644
--- a/contrib/epee/include/net/http_protocol_handler.inl
+++ b/contrib/epee/include/net/http_protocol_handler.inl
@@ -677,7 +677,7 @@ namespace net_utils
//add additional fields, if it is
for(fields_list::const_iterator it = response.m_additional_fields.begin(); it!=response.m_additional_fields.end(); it++)
- buf += it->first + ":" + it->second + "\r\n";
+ buf += it->first + ": " + it->second + "\r\n";
buf+="\r\n";
diff --git a/contrib/epee/include/net/http_server_impl_base.h b/contrib/epee/include/net/http_server_impl_base.h
index 5669824c1..0922f21f2 100644
--- a/contrib/epee/include/net/http_server_impl_base.h
+++ b/contrib/epee/include/net/http_server_impl_base.h
@@ -58,7 +58,12 @@ namespace epee
bool init(std::function<void(size_t, uint8_t*)> rng, const std::string& bind_port = "0", const std::string& bind_ip = "0.0.0.0",
std::vector<std::string> access_control_origins = std::vector<std::string>(),
- boost::optional<net_utils::http::login> user = boost::none)
+ boost::optional<net_utils::http::login> user = boost::none,
+ epee::net_utils::ssl_support_t ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_autodetect,
+ const std::pair<std::string, std::string> &private_key_and_certificate_path = {},
+ std::list<std::string> allowed_certificates = {},
+ std::vector<std::vector<uint8_t>> allowed_fingerprints = {},
+ bool allow_any_cert = false)
{
//set self as callback handler
@@ -75,7 +80,7 @@ namespace epee
m_net_server.get_config_object().m_user = std::move(user);
MGINFO("Binding on " << bind_ip << ":" << bind_port);
- bool res = m_net_server.init_server(bind_port, bind_ip);
+ bool res = m_net_server.init_server(bind_port, bind_ip, ssl_support, private_key_and_certificate_path, std::move(allowed_certificates), std::move(allowed_fingerprints), allow_any_cert);
if(!res)
{
LOG_ERROR("Failed to bind server");
diff --git a/contrib/epee/include/net/jsonrpc_structs.h b/contrib/epee/include/net/jsonrpc_structs.h
index 9df9e2596..b61c369f2 100644
--- a/contrib/epee/include/net/jsonrpc_structs.h
+++ b/contrib/epee/include/net/jsonrpc_structs.h
@@ -18,6 +18,8 @@ namespace epee
epee::serialization::storage_entry id;
t_param params;
+ request(): id{}, params{} {}
+
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(jsonrpc)
KV_SERIALIZE(id)
@@ -30,6 +32,9 @@ namespace epee
{
int64_t code;
std::string message;
+
+ error(): code(0) {}
+
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(code)
KV_SERIALIZE(message)
@@ -55,6 +60,9 @@ namespace epee
t_param result;
epee::serialization::storage_entry id;
t_error error;
+
+ response(): result{}, id(), error{} {}
+
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(jsonrpc)
KV_SERIALIZE(id)
@@ -69,6 +77,9 @@ namespace epee
std::string jsonrpc;
t_param result;
epee::serialization::storage_entry id;
+
+ response(): result{}, id{} {}
+
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(jsonrpc)
KV_SERIALIZE(id)
@@ -82,6 +93,9 @@ namespace epee
std::string jsonrpc;
t_error error;
epee::serialization::storage_entry id;
+
+ response(): error{}, id{} {}
+
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(jsonrpc)
KV_SERIALIZE(id)
diff --git a/contrib/epee/include/net/net_helper.h b/contrib/epee/include/net/net_helper.h
index 94744ac21..742cf916e 100644
--- a/contrib/epee/include/net/net_helper.h
+++ b/contrib/epee/include/net/net_helper.h
@@ -40,6 +40,7 @@
#include <boost/lambda/lambda.hpp>
#include <boost/interprocess/detail/atomic.hpp>
#include "net/net_utils_base.h"
+#include "net/net_ssl.h"
#include "misc_language.h"
#undef MONERO_DEFAULT_LOG_CATEGORY
@@ -57,6 +58,13 @@ namespace net_utils
class blocked_mode_client
{
+ enum try_connect_result_t
+ {
+ CONNECT_SUCCESS,
+ CONNECT_FAILURE,
+ CONNECT_NO_SSL,
+ };
+
struct handler_obj
@@ -84,9 +92,9 @@ namespace net_utils
m_connected(false),
m_deadline(m_io_service),
m_shutdowned(0),
- m_ssl(false),
- m_ctx(boost::asio::ssl::context::sslv23),
- m_ssl_socket(m_io_service,m_ctx)
+ m_ssl_support(epee::net_utils::ssl_support_t::e_ssl_support_autodetect),
+ m_ctx({boost::asio::ssl::context(boost::asio::ssl::context::tlsv12), {}}),
+ m_ssl_socket(new boost::asio::ssl::stream<boost::asio::ip::tcp::socket>(m_io_service,m_ctx.context))
{
@@ -110,28 +118,92 @@ namespace net_utils
catch(...) { /* ignore */ }
}
+ inline void set_ssl(epee::net_utils::ssl_support_t ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_autodetect, const std::pair<std::string, std::string> &private_key_and_certificate_path = {}, std::list<std::string> allowed_certificates = {}, std::vector<std::vector<uint8_t>> allowed_fingerprints = {}, bool allow_any_cert = false)
+ {
+ if (ssl_support == epee::net_utils::ssl_support_t::e_ssl_support_disabled)
+ m_ctx = {boost::asio::ssl::context(boost::asio::ssl::context::tlsv12), {}, {}};
+ else
+ m_ctx = create_ssl_context(private_key_and_certificate_path, std::move(allowed_certificates), std::move(allowed_fingerprints), allow_any_cert);
+ m_ssl_support = ssl_support;
+ }
+
inline
- bool connect(const std::string& addr, int port, std::chrono::milliseconds timeout, bool ssl = false, const std::string& bind_ip = "0.0.0.0")
+ bool connect(const std::string& addr, int port, std::chrono::milliseconds timeout, const std::string& bind_ip = "0.0.0.0")
{
- return connect(addr, std::to_string(port), timeout, ssl, bind_ip);
+ return connect(addr, std::to_string(port), timeout, bind_ip);
}
inline
- bool connect(const std::string& addr, const std::string& port, std::chrono::milliseconds timeout, bool ssl = false, const std::string& bind_ip = "0.0.0.0")
+ try_connect_result_t try_connect(const std::string& addr, const std::string& port, const boost::asio::ip::tcp::endpoint &remote_endpoint, std::chrono::milliseconds timeout, const std::string& bind_ip, epee::net_utils::ssl_support_t ssl_support)
{
- m_connected = false;
- m_ssl = ssl;
+ m_ssl_socket->next_layer().open(remote_endpoint.protocol());
+ if(bind_ip != "0.0.0.0" && bind_ip != "0" && bind_ip != "" )
+ {
+ boost::asio::ip::tcp::endpoint local_endpoint(boost::asio::ip::address::from_string(addr.c_str()), 0);
+ m_ssl_socket->next_layer().bind(local_endpoint);
+ }
+
+
+ m_deadline.expires_from_now(timeout);
+
+ boost::system::error_code ec = boost::asio::error::would_block;
+
+ m_ssl_socket->next_layer().async_connect(remote_endpoint, boost::lambda::var(ec) = boost::lambda::_1);
+ while (ec == boost::asio::error::would_block)
+ {
+ m_io_service.run_one();
+ }
+
+ if (!ec && m_ssl_socket->next_layer().is_open())
+ {
+ m_connected = true;
+ m_deadline.expires_at(std::chrono::steady_clock::time_point::max());
+ // SSL Options
+ if (ssl_support == epee::net_utils::ssl_support_t::e_ssl_support_enabled || ssl_support == epee::net_utils::ssl_support_t::e_ssl_support_autodetect)
+ {
+ if (!ssl_handshake(*m_ssl_socket, boost::asio::ssl::stream_base::client, m_ctx))
+ {
+ if (ssl_support == epee::net_utils::ssl_support_t::e_ssl_support_autodetect)
+ {
+ boost::system::error_code ignored_ec;
+ m_ssl_socket->next_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored_ec);
+ m_ssl_socket->next_layer().close();
+ m_connected = false;
+ return CONNECT_NO_SSL;
+ }
+ else
+ {
+ MWARNING("Failed to establish SSL connection");
+ m_connected = false;
+ return CONNECT_FAILURE;
+ }
+ }
+ m_ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_enabled;
+ }
+ return CONNECT_SUCCESS;
+ }else
+ {
+ MWARNING("Some problems at connect, message: " << ec.message());
+ return CONNECT_FAILURE;
+ }
+
+ }
+
+ inline
+ bool connect(const std::string& addr, const std::string& port, std::chrono::milliseconds timeout, const std::string& bind_ip = "0.0.0.0")
+ {
+ m_connected = false;
try
{
- m_ssl_socket.next_layer().close();
+ m_ssl_socket->next_layer().close();
// Set SSL options
// disable sslv2
- m_ctx.set_options(boost::asio::ssl::context::default_workarounds | boost::asio::ssl::context::no_sslv2);
- m_ctx.set_default_verify_paths();
+ m_ctx.context.set_options(boost::asio::ssl::context::default_workarounds | boost::asio::ssl::context::no_sslv2);
+ m_ctx.context.set_default_verify_paths();
+ m_ssl_socket.reset(new boost::asio::ssl::stream<boost::asio::ip::tcp::socket>(m_io_service, m_ctx.context));
// Get a list of endpoints corresponding to the server name.
-
//////////////////////////////////////////////////////////////////////////
@@ -151,45 +223,20 @@ namespace net_utils
//boost::asio::ip::tcp::endpoint remote_endpoint(boost::asio::ip::address::from_string(addr.c_str()), port);
boost::asio::ip::tcp::endpoint remote_endpoint(*iterator);
-
- m_ssl_socket.next_layer().open(remote_endpoint.protocol());
- if(bind_ip != "0.0.0.0" && bind_ip != "0" && bind_ip != "" )
- {
- boost::asio::ip::tcp::endpoint local_endpoint(boost::asio::ip::address::from_string(addr.c_str()), 0);
- m_ssl_socket.next_layer().bind(local_endpoint);
- }
-
-
- m_deadline.expires_from_now(timeout);
-
-
- boost::system::error_code ec = boost::asio::error::would_block;
-
- m_ssl_socket.next_layer().async_connect(remote_endpoint, boost::lambda::var(ec) = boost::lambda::_1);
- while (ec == boost::asio::error::would_block)
- {
- m_io_service.run_one();
- }
-
- if (!ec && m_ssl_socket.next_layer().is_open())
+ try_connect_result_t try_connect_result = try_connect(addr, port, remote_endpoint, timeout, bind_ip, m_ssl_support);
+ if (try_connect_result == CONNECT_FAILURE)
+ return false;
+ if (m_ssl_support == epee::net_utils::ssl_support_t::e_ssl_support_autodetect)
{
- m_connected = true;
- m_deadline.expires_at(std::chrono::steady_clock::time_point::max());
- // SSL Options
- if(m_ssl) {
- // Disable verification of host certificate
- m_ssl_socket.set_verify_mode(boost::asio::ssl::verify_peer);
- // Handshake
- m_ssl_socket.next_layer().set_option(boost::asio::ip::tcp::no_delay(true));
- m_ssl_socket.handshake(boost::asio::ssl::stream_base::client);
+ m_ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_enabled;
+ if (try_connect_result == CONNECT_NO_SSL)
+ {
+ MERROR("SSL handshake failed on an autodetect connection, reconnecting without SSL");
+ m_ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_disabled;
+ if (try_connect(addr, port, remote_endpoint, timeout, bind_ip, m_ssl_support) != CONNECT_SUCCESS)
+ return false;
}
- return true;
- }else
- {
- MWARNING("Some problems at connect, message: " << ec.message());
- return false;
}
-
}
catch(const boost::system::system_error& er)
{
@@ -213,9 +260,9 @@ namespace net_utils
if(m_connected)
{
m_connected = false;
- if(m_ssl)
+ if(m_ssl_support != epee::net_utils::ssl_support_t::e_ssl_support_disabled)
shutdown_ssl();
- m_ssl_socket.next_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both);
+ m_ssl_socket->next_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both);
}
}
@@ -342,9 +389,13 @@ namespace net_utils
return true;
}
- bool is_connected()
+ bool is_connected(bool *ssl = NULL)
{
- return m_connected && m_ssl_socket.next_layer().is_open();
+ if (!m_connected || !m_ssl_socket->next_layer().is_open())
+ return false;
+ if (ssl)
+ *ssl = m_ssl_support == epee::net_utils::ssl_support_t::e_ssl_support_enabled;
+ return true;
}
inline
@@ -506,15 +557,15 @@ namespace net_utils
{
m_deadline.cancel();
boost::system::error_code ec;
- if(m_ssl)
+ if(m_ssl_support != epee::net_utils::ssl_support_t::e_ssl_support_disabled)
shutdown_ssl();
- m_ssl_socket.next_layer().cancel(ec);
+ m_ssl_socket->next_layer().cancel(ec);
if(ec)
MDEBUG("Problems at cancel: " << ec.message());
- m_ssl_socket.next_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
+ m_ssl_socket->next_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
if(ec)
MDEBUG("Problems at shutdown: " << ec.message());
- m_ssl_socket.next_layer().close(ec);
+ m_ssl_socket->next_layer().close(ec);
if(ec)
MDEBUG("Problems at close: " << ec.message());
boost::interprocess::ipcdetail::atomic_write32(&m_shutdowned, 1);
@@ -533,7 +584,7 @@ namespace net_utils
boost::asio::ip::tcp::socket& get_socket()
{
- return m_ssl_socket.next_layer();
+ return m_ssl_socket->next_layer();
}
private:
@@ -550,7 +601,7 @@ namespace net_utils
// connect(), read_line() or write_line() functions to return.
LOG_PRINT_L3("Timed out socket");
m_connected = false;
- m_ssl_socket.next_layer().close();
+ m_ssl_socket->next_layer().close();
// There is no longer an active deadline. The expiry is set to positive
// infinity so that the actor takes no action until a new deadline is set.
@@ -565,7 +616,7 @@ namespace net_utils
// ssl socket shutdown blocks if server doesn't respond. We close after 2 secs
boost::system::error_code ec = boost::asio::error::would_block;
m_deadline.expires_from_now(std::chrono::milliseconds(2000));
- m_ssl_socket.async_shutdown(boost::lambda::var(ec) = boost::lambda::_1);
+ m_ssl_socket->async_shutdown(boost::lambda::var(ec) = boost::lambda::_1);
while (ec == boost::asio::error::would_block)
{
m_io_service.run_one();
@@ -586,35 +637,39 @@ namespace net_utils
bool write(const void* data, size_t sz, boost::system::error_code& ec)
{
bool success;
- if(m_ssl)
- success = boost::asio::write(m_ssl_socket, boost::asio::buffer(data, sz), ec);
+ if(m_ssl_support == epee::net_utils::ssl_support_t::e_ssl_support_enabled)
+ success = boost::asio::write(*m_ssl_socket, boost::asio::buffer(data, sz), ec);
else
- success = boost::asio::write(m_ssl_socket.next_layer(), boost::asio::buffer(data, sz), ec);
+ success = boost::asio::write(m_ssl_socket->next_layer(), boost::asio::buffer(data, sz), ec);
return success;
}
void async_write(const void* data, size_t sz, boost::system::error_code& ec)
{
- if(m_ssl)
- boost::asio::async_write(m_ssl_socket, boost::asio::buffer(data, sz), boost::lambda::var(ec) = boost::lambda::_1);
+ if(m_ssl_support == epee::net_utils::ssl_support_t::e_ssl_support_enabled)
+ boost::asio::async_write(*m_ssl_socket, boost::asio::buffer(data, sz), boost::lambda::var(ec) = boost::lambda::_1);
else
- boost::asio::async_write(m_ssl_socket.next_layer(), boost::asio::buffer(data, sz), boost::lambda::var(ec) = boost::lambda::_1);
+ boost::asio::async_write(m_ssl_socket->next_layer(), boost::asio::buffer(data, sz), boost::lambda::var(ec) = boost::lambda::_1);
}
void async_read(char* buff, size_t sz, boost::asio::detail::transfer_at_least_t transfer_at_least, handler_obj& hndlr)
{
- if(!m_ssl)
- boost::asio::async_read(m_ssl_socket.next_layer(), boost::asio::buffer(buff, sz), transfer_at_least, hndlr);
+ if(m_ssl_support != epee::net_utils::ssl_support_t::e_ssl_support_enabled)
+ boost::asio::async_read(m_ssl_socket->next_layer(), boost::asio::buffer(buff, sz), transfer_at_least, hndlr);
else
- boost::asio::async_read(m_ssl_socket, boost::asio::buffer(buff, sz), transfer_at_least, hndlr);
+ boost::asio::async_read(*m_ssl_socket, boost::asio::buffer(buff, sz), transfer_at_least, hndlr);
}
protected:
boost::asio::io_service m_io_service;
- boost::asio::ssl::context m_ctx;
- boost::asio::ssl::stream<boost::asio::ip::tcp::socket> m_ssl_socket;
- bool m_ssl;
+ epee::net_utils::ssl_context_t m_ctx;
+ std::shared_ptr<boost::asio::ssl::stream<boost::asio::ip::tcp::socket>> m_ssl_socket;
+ epee::net_utils::ssl_support_t m_ssl_support;
+ std::string m_ssl_private_key;
+ std::string m_ssl_certificate;
+ std::list<std::string> m_ssl_allowed_certificates;
+ bool m_ssl_allow_any_cerl;
bool m_initialized;
bool m_connected;
boost::asio::steady_timer m_deadline;
@@ -722,7 +777,7 @@ namespace net_utils
// asynchronous operations are cancelled. This allows the blocked
// connect(), read_line() or write_line() functions to return.
LOG_PRINT_L3("Timed out socket");
- m_ssl_socket.next_layer().close();
+ m_ssl_socket->next_layer().close();
// There is no longer an active deadline. The expiry is set to positive
// infinity so that the actor takes no action until a new deadline is set.
diff --git a/contrib/epee/include/net/net_ssl.h b/contrib/epee/include/net/net_ssl.h
new file mode 100644
index 000000000..f7b102164
--- /dev/null
+++ b/contrib/epee/include/net/net_ssl.h
@@ -0,0 +1,68 @@
+// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// * Neither the name of the Andrey N. Sabelnikov nor the
+// names of its contributors may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
+// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+
+
+
+#ifndef _NET_SSL_H
+#define _NET_SSL_H
+
+#include <stdint.h>
+#include <string>
+#include <list>
+#include <boost/utility/string_ref.hpp>
+#include <boost/asio/ip/tcp.hpp>
+#include <boost/asio/ssl.hpp>
+
+namespace epee
+{
+namespace net_utils
+{
+ enum class ssl_support_t: uint8_t {
+ e_ssl_support_disabled,
+ e_ssl_support_enabled,
+ e_ssl_support_autodetect,
+ };
+
+ struct ssl_context_t
+ {
+ boost::asio::ssl::context context;
+ std::list<std::string> allowed_certificates;
+ std::vector<std::vector<uint8_t>> allowed_fingerprints;
+ bool allow_any_cert;
+ };
+
+ // https://security.stackexchange.com/questions/34780/checking-client-hello-for-https-classification
+ constexpr size_t get_ssl_magic_size() { return 9; }
+ bool is_ssl(const unsigned char *data, size_t len);
+ ssl_context_t create_ssl_context(const std::pair<std::string, std::string> &private_key_and_certificate_path, std::list<std::string> allowed_certificates, std::vector<std::vector<uint8_t>> allowed_fingerprints, bool allow_any_cert);
+ void use_ssl_certificate(ssl_context_t &ssl_context, const std::pair<std::string, std::string> &private_key_and_certificate_path);
+ bool is_certificate_allowed(boost::asio::ssl::verify_context &ctx, const ssl_context_t &ssl_context);
+ bool ssl_handshake(boost::asio::ssl::stream<boost::asio::ip::tcp::socket> &socket, boost::asio::ssl::stream_base::handshake_type type, const epee::net_utils::ssl_context_t &ssl_context);
+ bool ssl_support_from_string(ssl_support_t &ssl, boost::string_ref s);
+}
+}
+
+#endif //_NET_SSL_H
diff --git a/contrib/epee/include/net/net_utils_base.h b/contrib/epee/include/net/net_utils_base.h
index 82f8a7fe8..7b5b07ef2 100644
--- a/contrib/epee/include/net/net_utils_base.h
+++ b/contrib/epee/include/net/net_utils_base.h
@@ -47,6 +47,7 @@
namespace net
{
class tor_address;
+ class i2p_address;
}
namespace epee
@@ -196,7 +197,7 @@ namespace net_utils
template<typename Type> const Type &as() const { return as_mutable<const Type>(); }
BEGIN_KV_SERIALIZE_MAP()
- // need to `#include "net/tor_address.h"` when serializing `network_address`
+ // need to `#include "net/[i2p|tor]_address.h"` when serializing `network_address`
static constexpr std::integral_constant<bool, is_store> is_store_{};
std::uint8_t type = std::uint8_t(is_store ? this_ref.get_type_id() : address_type::invalid);
@@ -209,6 +210,8 @@ namespace net_utils
return this_ref.template serialize_addr<ipv4_network_address>(is_store_, stg, hparent_section);
case address_type::tor:
return this_ref.template serialize_addr<net::tor_address>(is_store_, stg, hparent_section);
+ case address_type::i2p:
+ return this_ref.template serialize_addr<net::i2p_address>(is_store_, stg, hparent_section);
case address_type::invalid:
default:
break;
@@ -241,6 +244,7 @@ namespace net_utils
const network_address m_remote_address;
const bool m_is_income;
const time_t m_started;
+ const time_t m_ssl;
time_t m_last_recv;
time_t m_last_send;
uint64_t m_recv_cnt;
@@ -251,13 +255,14 @@ namespace net_utils
double m_max_speed_up;
connection_context_base(boost::uuids::uuid connection_id,
- const network_address &remote_address, bool is_income,
+ const network_address &remote_address, bool is_income, bool ssl,
time_t last_recv = 0, time_t last_send = 0,
uint64_t recv_cnt = 0, uint64_t send_cnt = 0):
m_connection_id(connection_id),
m_remote_address(remote_address),
m_is_income(is_income),
m_started(time(NULL)),
+ m_ssl(ssl),
m_last_recv(last_recv),
m_last_send(last_send),
m_recv_cnt(recv_cnt),
@@ -272,6 +277,7 @@ namespace net_utils
m_remote_address(),
m_is_income(false),
m_started(time(NULL)),
+ m_ssl(false),
m_last_recv(0),
m_last_send(0),
m_recv_cnt(0),
@@ -284,17 +290,17 @@ namespace net_utils
connection_context_base& operator=(const connection_context_base& a)
{
- set_details(a.m_connection_id, a.m_remote_address, a.m_is_income);
+ set_details(a.m_connection_id, a.m_remote_address, a.m_is_income, a.m_ssl);
return *this;
}
private:
template<class t_protocol_handler>
friend class connection;
- void set_details(boost::uuids::uuid connection_id, const network_address &remote_address, bool is_income)
+ void set_details(boost::uuids::uuid connection_id, const network_address &remote_address, bool is_income, bool ssl)
{
this->~connection_context_base();
- new(this) connection_context_base(connection_id, remote_address, is_income);
+ new(this) connection_context_base(connection_id, remote_address, is_income, ssl);
}
};
diff --git a/contrib/epee/include/net/network_throttle-detail.hpp b/contrib/epee/include/net/network_throttle-detail.hpp
index 955668d62..d7f2cc37a 100644
--- a/contrib/epee/include/net/network_throttle-detail.hpp
+++ b/contrib/epee/include/net/network_throttle-detail.hpp
@@ -2,7 +2,7 @@
/// @author rfree (current maintainer in monero.cc project)
/// @brief implementaion for throttling of connection (count and rate-limit speed etc)
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -36,6 +36,7 @@
#ifndef INCLUDED_throttle_detail_hpp
#define INCLUDED_throttle_detail_hpp
+#include <boost/circular_buffer.hpp>
#include "network_throttle.hpp"
namespace epee
@@ -61,7 +62,7 @@ class network_throttle : public i_network_throttle {
network_time_seconds m_slot_size; // the size of one slot. TODO: now hardcoded for 1 second e.g. in time_to_slot()
// TODO for big window size, for performance better the substract on change of m_last_sample_time instead of recalculating average of eg >100 elements
- std::vector< packet_info > m_history; // the history of bw usage
+ boost::circular_buffer< packet_info > m_history; // the history of bw usage
network_time_seconds m_last_sample_time; // time of last history[0] - so we know when to rotate the buffer
network_time_seconds m_start_time; // when we were created
bool m_any_packet_yet; // did we yet got any packet to count
diff --git a/contrib/epee/include/net/network_throttle.hpp b/contrib/epee/include/net/network_throttle.hpp
index 7df79a908..5092241a4 100644
--- a/contrib/epee/include/net/network_throttle.hpp
+++ b/contrib/epee/include/net/network_throttle.hpp
@@ -2,7 +2,7 @@
/// @author rfree (current maintainer in monero.cc project)
/// @brief interface for throttling of connection (count and rate-limit speed etc)
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/contrib/epee/include/span.h b/contrib/epee/include/span.h
index cfb5b1a17..19720ea8b 100644
--- a/contrib/epee/include/span.h
+++ b/contrib/epee/include/span.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/contrib/epee/include/stats.h b/contrib/epee/include/stats.h
new file mode 100644
index 000000000..1cf9c68fb
--- /dev/null
+++ b/contrib/epee/include/stats.h
@@ -0,0 +1,58 @@
+#pragma once
+
+#include <vector>
+
+template<typename T, typename Tpod = T>
+class Stats
+{
+public:
+ Stats(const std::vector<T> &v): values(v), cached(0) {}
+ ~Stats() {}
+
+ size_t get_size() const;
+ Tpod get_min() const;
+ Tpod get_max() const;
+ Tpod get_median() const;
+ double get_mean() const;
+ double get_confidence_interval_95() const;
+ double get_confidence_interval_99() const;
+ double get_standard_deviation() const;
+ double get_standard_error() const;
+ double get_variance() const;
+ double get_kurtosis() const;
+ double get_non_parametric_skew() const;
+ double get_t_test(T t) const;
+ double get_t_test(size_t npoints, double mean, double stddev) const;
+ double get_t_test(const Stats<T> &other) const;
+ double get_z_test(const Stats<T> &other) const;
+ double get_test(const Stats<T> &other) const;
+ std::vector<Tpod> get_quantiles(unsigned int quantiles) const;
+ std::vector<size_t> get_bins(unsigned int bins) const;
+ bool is_same_distribution_95(size_t npoints, double mean, double stddev) const;
+ bool is_same_distribution_95(const Stats<T> &other) const;
+ bool is_same_distribution_99(size_t npoints, double mean, double stddev) const;
+ bool is_same_distribution_99(const Stats<T> &other) const;
+
+ double get_cdf95(size_t df) const;
+ double get_cdf95(const Stats<T> &other) const;
+ double get_cdf99(size_t df) const;
+ double get_cdf99(const Stats<T> &other) const;
+
+private:
+ inline bool is_cached(int bit) const;
+ inline void set_cached(int bit) const;
+
+ const std::vector<T> &values;
+
+ mutable uint64_t cached;
+ mutable Tpod min;
+ mutable Tpod max;
+ mutable Tpod median;
+ mutable double mean;
+ mutable double standard_deviation;
+ mutable double standard_error;
+ mutable double variance;
+ mutable double kurtosis;
+};
+
+#include "stats.inl"
diff --git a/contrib/epee/include/stats.inl b/contrib/epee/include/stats.inl
new file mode 100644
index 000000000..5a5cd0b93
--- /dev/null
+++ b/contrib/epee/include/stats.inl
@@ -0,0 +1,359 @@
+#include <math.h>
+#include <limits>
+#include <algorithm>
+#include "stats.h"
+
+enum
+{
+ bit_min = 0,
+ bit_max,
+ bit_median,
+ bit_mean,
+ bit_standard_deviation,
+ bit_standard_error,
+ bit_variance,
+ bit_kurtosis,
+};
+
+static inline double square(double x)
+{
+ return x * x;
+}
+
+template<typename T>
+static inline double interpolate(T v, T v0, double i0, T v1, double i1)
+{
+ return i0 + (i1 - i0) * (v - v0) / (v1 - v0);
+}
+
+template<typename T, typename Tpod>
+inline bool Stats<T, Tpod>::is_cached(int bit) const
+{
+ return cached & (1<<bit);
+}
+
+template<typename T, typename Tpod>
+inline void Stats<T, Tpod>::set_cached(int bit) const
+{
+ cached |= 1<<bit;
+}
+
+template<typename T, typename Tpod>
+size_t Stats<T, Tpod>::get_size() const
+{
+ return values.size();
+}
+
+template<typename T, typename Tpod>
+Tpod Stats<T, Tpod>::get_min() const
+{
+ if (!is_cached(bit_min))
+ {
+ min = std::numeric_limits<Tpod>::max();
+ for (const T &v: values)
+ min = std::min<Tpod>(min, v);
+ set_cached(bit_min);
+ }
+ return min;
+}
+
+template<typename T, typename Tpod>
+Tpod Stats<T, Tpod>::get_max() const
+{
+ if (!is_cached(bit_max))
+ {
+ max = std::numeric_limits<Tpod>::min();
+ for (const T &v: values)
+ max = std::max<Tpod>(max, v);
+ set_cached(bit_max);
+ }
+ return max;
+}
+
+template<typename T, typename Tpod>
+Tpod Stats<T, Tpod>::get_median() const
+{
+ if (!is_cached(bit_median))
+ {
+ std::vector<Tpod> sorted;
+ sorted.reserve(values.size());
+ for (const T &v: values)
+ sorted.push_back(v);
+ std::sort(sorted.begin(), sorted.end());
+ if (sorted.size() & 1)
+ {
+ median = sorted[sorted.size() / 2];
+ }
+ else
+ {
+ median = (sorted[(sorted.size() - 1) / 2] + sorted[sorted.size() / 2]) / 2;
+ }
+ set_cached(bit_median);
+ }
+ return median;
+}
+
+template<typename T, typename Tpod>
+double Stats<T, Tpod>::get_mean() const
+{
+ if (values.empty())
+ return 0.0;
+ if (!is_cached(bit_mean))
+ {
+ mean = 0.0;
+ for (const T &v: values)
+ mean += v;
+ mean /= values.size();
+ set_cached(bit_mean);
+ }
+ return mean;
+}
+
+template<typename T, typename Tpod>
+double Stats<T, Tpod>::get_cdf95(size_t df) const
+{
+ static const double p[101] = {
+ -1, 12.706, 4.3027, 3.1824, 2.7765, 2.5706, 2.4469, 2.3646, 2.3060, 2.2622, 2.2281, 2.2010, 2.1788, 2.1604, 2.1448, 2.1315,
+ 2.1199, 2.1098, 2.1009, 2.0930, 2.0860, 2.0796, 2.0739, 2.0687, 2.0639, 2.0595, 2.0555, 2.0518, 2.0484, 2.0452, 2.0423, 2.0395,
+ 2.0369, 2.0345, 2.0322, 2.0301, 2.0281, 2.0262, 2.0244, 2.0227, 2.0211, 2.0195, 2.0181, 2.0167, 2.0154, 2.0141, 2.0129, 2.0117,
+ 2.0106, 2.0096, 2.0086, 2.0076, 2.0066, 2.0057, 2.0049, 2.0040, 2.0032, 2.0025, 2.0017, 2.0010, 2.0003, 1.9996, 1.9990, 1.9983,
+ 1.9977, 1.9971, 1.9966, 1.9960, 1.9955, 1.9949, 1.9944, 1.9939, 1.9935, 1.9930, 1.9925, 1.9921, 1.9917, 1.9913, 1.9908, 1.9905,
+ 1.9901, 1.9897, 1.9893, 1.9890, 1.9886, 1.9883, 1.9879, 1.9876, 1.9873, 1.9870, 1.9867, 1.9864, 1.9861, 1.9858, 1.9855, 1.9852,
+ 1.9850, 1.9847, 1.9845, 1.9842, 1.9840,
+ };
+ if (df <= 100)
+ return p[df];
+ if (df <= 120)
+ return interpolate<size_t>(df, 100, 1.9840, 120, 1.98);
+ return 1.96;
+}
+
+template<typename T, typename Tpod>
+double Stats<T, Tpod>::get_cdf95(const Stats<T> &other) const
+{
+ return get_cdf95(get_size() + other.get_size() - 2);
+}
+
+template<typename T, typename Tpod>
+double Stats<T, Tpod>::get_cdf99(size_t df) const
+{
+ static const double p[101] = {
+ -1, 9.9250, 5.8408, 4.6041, 4.0321, 3.7074, 3.4995, 3.3554, 3.2498, 3.1693, 3.1058, 3.0545, 3.0123, 2.9768, 2.9467, 2.9208, 2.8982,
+ 2.8784, 2.8609, 2.8453, 2.8314, 2.8188, 2.8073, 2.7970, 2.7874, 2.7787, 2.7707, 2.7633, 2.7564, 2.7500, 2.7440, 2.7385, 2.7333,
+ 2.7284, 2.7238, 2.7195, 2.7154, 2.7116, 2.7079, 2.7045, 2.7012, 2.6981, 2.6951, 2.6923, 2.6896, 2.6870, 2.6846, 2.6822, 2.6800,
+ 2.6778, 2.6757, 2.6737, 2.6718, 2.6700, 2.6682, 2.6665, 2.6649, 2.6633, 2.6618, 2.6603, 2.6589, 2.6575, 2.6561, 2.6549, 2.6536,
+ 2.6524, 2.6512, 2.6501, 2.6490, 2.6479, 2.6469, 2.6458, 2.6449, 2.6439, 2.6430, 2.6421, 2.6412, 2.6403, 2.6395, 2.6387, 2.6379,
+ 2.6371, 2.6364, 2.6356, 2.6349, 2.6342, 2.6335, 2.6329, 2.6322, 2.6316, 2.6309, 2.6303, 2.6297, 2.6291, 2.6286, 2.6280, 2.6275,
+ 2.6269, 2.6264, 2.6259,
+ };
+ if (df <= 100)
+ return p[df];
+ if (df <= 120)
+ return interpolate<size_t>(df, 100, 2.6529, 120, 2.617);
+ return 2.576;
+}
+
+template<typename T, typename Tpod>
+double Stats<T, Tpod>::get_cdf99(const Stats<T> &other) const
+{
+ return get_cdf99(get_size() + other.get_size() - 2);
+}
+
+template<typename T, typename Tpod>
+double Stats<T, Tpod>::get_confidence_interval_95() const
+{
+ const size_t df = get_size() - 1;
+ return get_standard_error() * get_cdf95(df);
+}
+
+template<typename T, typename Tpod>
+double Stats<T, Tpod>::get_confidence_interval_99() const
+{
+ const size_t df = get_size() - 1;
+ return get_standard_error() * get_cdf99(df);
+}
+
+template<typename T, typename Tpod>
+bool Stats<T, Tpod>::is_same_distribution_95(size_t npoints, double mean, double stddev) const
+{
+ return fabs(get_t_test(npoints, mean, stddev)) < get_cdf95(get_size() + npoints - 2);
+}
+
+template<typename T, typename Tpod>
+bool Stats<T, Tpod>::is_same_distribution_95(const Stats<T> &other) const
+{
+ return fabs(get_t_test(other)) < get_cdf95(other);
+}
+
+template<typename T, typename Tpod>
+bool Stats<T, Tpod>::is_same_distribution_99(size_t npoints, double mean, double stddev) const
+{
+ return fabs(get_t_test(npoints, mean, stddev)) < get_cdf99(get_size() + npoints - 2);
+}
+
+template<typename T, typename Tpod>
+bool Stats<T, Tpod>::is_same_distribution_99(const Stats<T> &other) const
+{
+ return fabs(get_t_test(other)) < get_cdf99(other);
+}
+
+template<typename T, typename Tpod>
+double Stats<T, Tpod>::get_standard_deviation() const
+{
+ if (values.size() <= 1)
+ return 0.0;
+ if (!is_cached(bit_standard_deviation))
+ {
+ Tpod m = get_mean(), t = 0;
+ for (const T &v: values)
+ t += ((T)v - m) * ((T)v - m);
+ standard_deviation = sqrt(t / ((double)values.size() - 1));
+ set_cached(bit_standard_deviation);
+ }
+ return standard_deviation;
+}
+
+template<typename T, typename Tpod>
+double Stats<T, Tpod>::get_standard_error() const
+{
+ if (!is_cached(bit_standard_error))
+ {
+ standard_error = get_standard_deviation() / sqrt(get_size());
+ set_cached(bit_standard_error);
+ }
+ return standard_error;
+}
+
+template<typename T, typename Tpod>
+double Stats<T, Tpod>::get_variance() const
+{
+ if (!is_cached(bit_variance))
+ {
+ double stddev = get_standard_deviation();
+ variance = stddev * stddev;
+ set_cached(bit_variance);
+ }
+ return variance;
+}
+
+template<typename T, typename Tpod>
+double Stats<T, Tpod>::get_kurtosis() const
+{
+ if (values.empty())
+ return 0.0;
+ if (!is_cached(bit_kurtosis))
+ {
+ double m = get_mean();
+ double n = 0, d = 0;
+ for (const T &v: values)
+ {
+ T p2 = (v - m) * (v - m);
+ T p4 = p2 * p2;
+ n += p4;
+ d += p2;
+ }
+ n /= values.size();
+ d /= values.size();
+ d *= d;
+ kurtosis = n / d;
+ set_cached(bit_kurtosis);
+ }
+ return kurtosis;
+}
+
+template<typename T, typename Tpod>
+double Stats<T, Tpod>::get_non_parametric_skew() const
+{
+ return (get_mean() - get_median()) / get_standard_deviation();
+}
+
+template<typename T, typename Tpod>
+double Stats<T, Tpod>::get_t_test(T t) const
+{
+ const double n = get_mean() - t;
+ const double d = get_standard_deviation() / sqrt(get_size());
+ return n / d;
+}
+
+template<typename T, typename Tpod>
+double Stats<T, Tpod>::get_t_test(size_t npoints, double mean, double stddev) const
+{
+ const double n = get_mean() - mean;
+ const double d = sqrt(get_variance() / get_size() + square(stddev) / npoints);
+ return n / d;
+}
+
+template<typename T, typename Tpod>
+double Stats<T, Tpod>::get_t_test(const Stats<T> &other) const
+{
+ const double n = get_mean() - other.get_mean();
+ const double d = sqrt(get_variance() / get_size() + other.get_variance() / other.get_size());
+ return n / d;
+}
+
+template<typename T, typename Tpod>
+double Stats<T, Tpod>::get_z_test(const Stats<T> &other) const
+{
+ const double m0 = get_mean();
+ const double m1 = other.get_mean();
+ const double sd0 = get_standard_deviation();
+ const double sd1 = other.get_standard_deviation();
+ const size_t s0 = get_size();
+ const size_t s1 = other.get_size();
+
+ const double n = m0 - m1;
+ const double d = sqrt(square(sd0 / sqrt(s0)) + square(sd1 / sqrt(s1)));
+
+ return n / d;
+}
+
+template<typename T, typename Tpod>
+double Stats<T, Tpod>::get_test(const Stats<T> &other) const
+{
+ if (get_size() >= 30 && other.get_size() >= 30)
+ return get_z_test(other);
+ else
+ return get_t_test(other);
+}
+
+template<typename T, typename Tpod>
+std::vector<Tpod> Stats<T, Tpod>::get_quantiles(unsigned int quantiles) const
+{
+ std::vector<Tpod> sorted;
+ sorted.reserve(values.size());
+ for (const T &v: values)
+ sorted.push_back(v);
+ std::sort(sorted.begin(), sorted.end());
+ std::vector<Tpod> q(quantiles + 1, 0);
+ for (unsigned int i = 1; i <= quantiles; ++i)
+ {
+ unsigned idx = (unsigned)ceil(values.size() * i / (double)quantiles);
+ q[i] = sorted[idx - 1];
+ }
+ if (!is_cached(bit_min))
+ {
+ min = sorted.front();
+ set_cached(bit_min);
+ }
+ q[0] = min;
+ if (!is_cached(bit_max))
+ {
+ max = sorted.back();
+ set_cached(bit_max);
+ }
+ return q;
+}
+
+template<typename T, typename Tpod>
+std::vector<size_t> Stats<T, Tpod>::get_bins(unsigned int bins) const
+{
+ std::vector<size_t> b(bins, 0);
+ const double scale = 1.0 / (get_max() - get_min());
+ const T base = get_min();
+ for (const T &v: values)
+ {
+ unsigned int idx = (v - base) * scale;
+ ++b[idx];
+ }
+ return b;
+}
diff --git a/contrib/epee/include/wipeable_string.h b/contrib/epee/include/wipeable_string.h
index 31854fe2e..f0e526b92 100644
--- a/contrib/epee/include/wipeable_string.h
+++ b/contrib/epee/include/wipeable_string.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/contrib/epee/src/CMakeLists.txt b/contrib/epee/src/CMakeLists.txt
index cea50c9dd..0787a9d08 100644
--- a/contrib/epee/src/CMakeLists.txt
+++ b/contrib/epee/src/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
@@ -27,7 +27,7 @@
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
add_library(epee STATIC hex.cpp http_auth.cpp mlog.cpp net_utils_base.cpp string_tools.cpp wipeable_string.cpp memwipe.c
- connection_basic.cpp network_throttle.cpp network_throttle-detail.cpp mlocker.cpp buffer.cpp)
+ connection_basic.cpp network_throttle.cpp network_throttle-detail.cpp mlocker.cpp buffer.cpp net_ssl.cpp)
if (USE_READLINE AND GNU_READLINE_FOUND)
add_library(epee_readline STATIC readline_buffer.cpp)
endif()
diff --git a/contrib/epee/src/connection_basic.cpp b/contrib/epee/src/connection_basic.cpp
index f5f9b59fe..83db171d8 100644
--- a/contrib/epee/src/connection_basic.cpp
+++ b/contrib/epee/src/connection_basic.cpp
@@ -2,7 +2,7 @@
/// @author rfree (current maintainer in monero.cc project)
/// @brief base for connection, contains e.g. the ratelimit hooks
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -48,7 +48,7 @@
#include "net/network_throttle-detail.hpp"
#undef MONERO_DEFAULT_LOG_CATEGORY
-#define MONERO_DEFAULT_LOG_CATEGORY "net.p2p"
+#define MONERO_DEFAULT_LOG_CATEGORY "net.conn"
// ################################################################################################
// local (TU local) headers
@@ -113,14 +113,41 @@ connection_basic_pimpl::connection_basic_pimpl(const std::string &name) : m_thro
int connection_basic_pimpl::m_default_tos;
// methods:
-connection_basic::connection_basic(boost::asio::ip::tcp::socket&& socket, boost::shared_ptr<socket_stats> stats)
+connection_basic::connection_basic(boost::asio::ip::tcp::socket&& sock, boost::shared_ptr<socket_stats> stats, ssl_support_t ssl_support, ssl_context_t &ssl_context)
:
m_stats(std::move(stats)),
mI( new connection_basic_pimpl("peer") ),
- strand_(socket.get_io_service()),
- socket_(std::move(socket)),
+ strand_(sock.get_io_service()),
+ socket_(sock.get_io_service(), ssl_context.context),
+ m_want_close_connection(false),
+ m_was_shutdown(false),
+ m_ssl_support(ssl_support),
+ m_ssl_context(ssl_context)
+{
+ // add nullptr checks if removed
+ CHECK_AND_ASSERT_THROW_MES(bool(m_stats), "stats shared_ptr cannot be null");
+
+ socket_.next_layer() = std::move(sock);
+
+ ++(m_stats->sock_count); // increase the global counter
+ mI->m_peer_number = m_stats->sock_number.fetch_add(1); // use, and increase the generated number
+
+ std::string remote_addr_str = "?";
+ try { boost::system::error_code e; remote_addr_str = socket().remote_endpoint(e).address().to_string(); } catch(...){} ;
+
+ _note("Spawned connection #"<<mI->m_peer_number<<" to " << remote_addr_str << " currently we have sockets count:" << m_stats->sock_count);
+}
+
+connection_basic::connection_basic(boost::asio::io_service &io_service, boost::shared_ptr<socket_stats> stats, ssl_support_t ssl_support, ssl_context_t &ssl_context)
+ :
+ m_stats(std::move(stats)),
+ mI( new connection_basic_pimpl("peer") ),
+ strand_(io_service),
+ socket_(io_service, ssl_context.context),
m_want_close_connection(false),
- m_was_shutdown(false)
+ m_was_shutdown(false),
+ m_ssl_support(ssl_support),
+ m_ssl_context(ssl_context)
{
// add nullptr checks if removed
CHECK_AND_ASSERT_THROW_MES(bool(m_stats), "stats shared_ptr cannot be null");
@@ -129,17 +156,18 @@ connection_basic::connection_basic(boost::asio::ip::tcp::socket&& socket, boost:
mI->m_peer_number = m_stats->sock_number.fetch_add(1); // use, and increase the generated number
std::string remote_addr_str = "?";
- try { boost::system::error_code e; remote_addr_str = socket_.remote_endpoint(e).address().to_string(); } catch(...){} ;
+ try { boost::system::error_code e; remote_addr_str = socket().remote_endpoint(e).address().to_string(); } catch(...){} ;
- _note("Spawned connection p2p#"<<mI->m_peer_number<<" to " << remote_addr_str << " currently we have sockets count:" << m_stats->sock_count);
+ _note("Spawned connection #"<<mI->m_peer_number<<" to " << remote_addr_str << " currently we have sockets count:" << m_stats->sock_count);
}
connection_basic::~connection_basic() noexcept(false) {
--(m_stats->sock_count);
std::string remote_addr_str = "?";
- try { boost::system::error_code e; remote_addr_str = socket_.remote_endpoint(e).address().to_string(); } catch(...){} ;
- _note("Destructing connection p2p#"<<mI->m_peer_number << " to " << remote_addr_str);
+ try { boost::system::error_code e; remote_addr_str = socket().remote_endpoint(e).address().to_string(); } catch(...){} ;
+ _note("Destructing connection #"<<mI->m_peer_number << " to " << remote_addr_str);
+try { throw 0; } catch(...){}
}
void connection_basic::set_rate_up_limit(uint64_t limit) {
diff --git a/contrib/epee/src/hex.cpp b/contrib/epee/src/hex.cpp
index 5c8acc8be..558983f7e 100644
--- a/contrib/epee/src/hex.cpp
+++ b/contrib/epee/src/hex.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
@@ -83,4 +83,67 @@ namespace epee
{
return write_hex(out, src);
}
+
+ std::vector<uint8_t> from_hex::vector(boost::string_ref src)
+ {
+ // should we include a specific character
+ auto include = [](char input) {
+ // we ignore spaces and colons
+ return !std::isspace(input) && input != ':';
+ };
+
+ // the number of relevant characters to decode
+ auto count = std::count_if(src.begin(), src.end(), include);
+
+ // this must be a multiple of two, otherwise we have a truncated input
+ if (count % 2) {
+ throw std::length_error{ "Invalid hexadecimal input length" };
+ }
+
+ std::vector<uint8_t> result;
+ result.reserve(count / 2);
+
+ // the data to work with (std::string is always null-terminated)
+ auto data = src.data();
+
+ // convert a single hex character to an unsigned integer
+ auto char_to_int = [](const char *input) {
+ switch (std::tolower(*input)) {
+ case '0': return 0;
+ case '1': return 1;
+ case '2': return 2;
+ case '3': return 3;
+ case '4': return 4;
+ case '5': return 5;
+ case '6': return 6;
+ case '7': return 7;
+ case '8': return 8;
+ case '9': return 9;
+ case 'a': return 10;
+ case 'b': return 11;
+ case 'c': return 12;
+ case 'd': return 13;
+ case 'e': return 14;
+ case 'f': return 15;
+ default: throw std::range_error{ "Invalid hexadecimal input" };
+ }
+ };
+
+ // keep going until we reach the end
+ while (data[0] != '\0') {
+ // skip unwanted characters
+ if (!include(data[0])) {
+ ++data;
+ continue;
+ }
+
+ // convert two matching characters to int
+ auto high = char_to_int(data++);
+ auto low = char_to_int(data++);
+
+ result.push_back(high << 4 | low);
+ }
+
+ return result;
+ }
}
diff --git a/contrib/epee/src/http_auth.cpp b/contrib/epee/src/http_auth.cpp
index dc968d971..289069daa 100644
--- a/contrib/epee/src/http_auth.cpp
+++ b/contrib/epee/src/http_auth.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/contrib/epee/src/memwipe.c b/contrib/epee/src/memwipe.c
index c2a26c392..ad1ef510d 100644
--- a/contrib/epee/src/memwipe.c
+++ b/contrib/epee/src/memwipe.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/contrib/epee/src/net_ssl.cpp b/contrib/epee/src/net_ssl.cpp
new file mode 100644
index 000000000..eb0b0ad65
--- /dev/null
+++ b/contrib/epee/src/net_ssl.cpp
@@ -0,0 +1,324 @@
+// Copyright (c) 2018, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include <string.h>
+#include <boost/asio/ssl.hpp>
+#include <openssl/ssl.h>
+#include <openssl/pem.h>
+#include "misc_log_ex.h"
+#include "net/net_ssl.h"
+
+#undef MONERO_DEFAULT_LOG_CATEGORY
+#define MONERO_DEFAULT_LOG_CATEGORY "net.ssl"
+
+// openssl genrsa -out /tmp/KEY 4096
+// openssl req -new -key /tmp/KEY -out /tmp/REQ
+// openssl x509 -req -days 999999 -sha256 -in /tmp/REQ -signkey /tmp/KEY -out /tmp/CERT
+
+namespace
+{
+ struct openssl_bio_free
+ {
+ void operator()(BIO* ptr) const noexcept
+ {
+ if (ptr)
+ BIO_free(ptr);
+ }
+ };
+ using openssl_bio = std::unique_ptr<BIO, openssl_bio_free>;
+
+ struct openssl_pkey_free
+ {
+ void operator()(EVP_PKEY* ptr) const noexcept
+ {
+ if (ptr)
+ EVP_PKEY_free(ptr);
+ }
+ };
+ using openssl_pkey = std::unique_ptr<EVP_PKEY, openssl_pkey_free>;
+
+}
+
+namespace epee
+{
+namespace net_utils
+{
+
+// https://stackoverflow.com/questions/256405/programmatically-create-x509-certificate-using-openssl
+bool create_ssl_certificate(EVP_PKEY *&pkey, X509 *&cert)
+{
+ MGINFO("Generating SSL certificate");
+ pkey = EVP_PKEY_new();
+ if (!pkey)
+ {
+ MERROR("Failed to create new private key");
+ return false;
+ }
+
+ openssl_pkey pkey_deleter{pkey};
+ RSA *rsa = RSA_generate_key(4096, RSA_F4, NULL, NULL);
+ if (!rsa)
+ {
+ MERROR("Error generating RSA private key");
+ return false;
+ }
+ if (EVP_PKEY_assign_RSA(pkey, rsa) <= 0) // The RSA will be automatically freed when the EVP_PKEY structure is freed.
+ {
+ MERROR("Error assigning RSA private key");
+ RSA_free(rsa);
+ return false;
+ }
+
+ cert = X509_new();
+ if (!cert)
+ {
+ MERROR("Failed to create new X509 certificate");
+ return false;
+ }
+ ASN1_INTEGER_set(X509_get_serialNumber(cert), 1);
+ X509_gmtime_adj(X509_get_notBefore(cert), 0);
+ X509_gmtime_adj(X509_get_notAfter(cert), 3600 * 24 * 182); // half a year
+ if (!X509_set_pubkey(cert, pkey))
+ {
+ MERROR("Error setting pubkey on certificate");
+ X509_free(cert);
+ return false;
+ }
+ X509_NAME *name = X509_get_subject_name(cert);
+ X509_set_issuer_name(cert, name);
+
+ if (X509_sign(cert, pkey, EVP_sha256()) == 0)
+ {
+ MERROR("Error signing certificate");
+ X509_free(cert);
+ return false;
+ }
+ (void)pkey_deleter.release();
+ return true;
+}
+
+ssl_context_t create_ssl_context(const std::pair<std::string, std::string> &private_key_and_certificate_path, std::list<std::string> allowed_certificates, std::vector<std::vector<uint8_t>> allowed_fingerprints, bool allow_any_cert)
+{
+ ssl_context_t ssl_context{boost::asio::ssl::context(boost::asio::ssl::context::tlsv12), std::move(allowed_certificates), std::move(allowed_fingerprints)};
+
+ // only allow tls v1.2 and up
+ ssl_context.context.set_options(boost::asio::ssl::context::default_workarounds);
+ ssl_context.context.set_options(boost::asio::ssl::context::no_sslv2);
+ ssl_context.context.set_options(boost::asio::ssl::context::no_sslv3);
+ ssl_context.context.set_options(boost::asio::ssl::context::no_tlsv1);
+ ssl_context.context.set_options(boost::asio::ssl::context::no_tlsv1_1);
+
+ // only allow a select handful of tls v1.3 and v1.2 ciphers to be used
+ SSL_CTX_set_cipher_list(ssl_context.context.native_handle(), "ECDHE-ECDSA-CHACHA20-POLY1305-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-CHACHA20-POLY1305");
+
+ // set options on the SSL context for added security
+ SSL_CTX *ctx = ssl_context.context.native_handle();
+ CHECK_AND_ASSERT_THROW_MES(ctx, "Failed to get SSL context");
+ SSL_CTX_clear_options(ctx, SSL_OP_LEGACY_SERVER_CONNECT); // SSL_CTX_SET_OPTIONS(3)
+ SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_OFF); // https://stackoverflow.com/questions/22378442
+#ifdef SSL_OP_NO_TICKET
+ SSL_CTX_set_options(ctx, SSL_OP_NO_TICKET); // https://stackoverflow.com/questions/22378442
+#endif
+#ifdef SSL_OP_NO_RENEGOTIATION
+ SSL_CTX_set_options(ctx, SSL_OP_NO_RENEGOTIATION);
+#endif
+#ifdef SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION
+ SSL_CTX_set_options(ctx, SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION);
+#endif
+#ifdef SSL_OP_NO_COMPRESSION
+ SSL_CTX_set_options(ctx, SSL_OP_NO_COMPRESSION);
+#endif
+ ssl_context.context.set_default_verify_paths();
+
+ CHECK_AND_ASSERT_THROW_MES(private_key_and_certificate_path.first.empty() == private_key_and_certificate_path.second.empty(), "private key and certificate must be either both given or both empty");
+ if (private_key_and_certificate_path.second.empty())
+ {
+ EVP_PKEY *pkey;
+ X509 *cert;
+ CHECK_AND_ASSERT_THROW_MES(create_ssl_certificate(pkey, cert), "Failed to create certificate");
+ CHECK_AND_ASSERT_THROW_MES(SSL_CTX_use_certificate(ctx, cert), "Failed to use generated certificate");
+ // don't free the cert, the CTX owns it now
+ CHECK_AND_ASSERT_THROW_MES(SSL_CTX_use_PrivateKey(ctx, pkey), "Failed to use generated private key");
+ EVP_PKEY_free(pkey);
+ }
+ else
+ {
+ ssl_context.context.use_private_key_file(private_key_and_certificate_path.first, boost::asio::ssl::context::pem);
+ ssl_context.context.use_certificate_file(private_key_and_certificate_path.second, boost::asio::ssl::context::pem);
+ }
+ ssl_context.allow_any_cert = allow_any_cert;
+
+ return ssl_context;
+}
+
+void use_ssl_certificate(ssl_context_t &ssl_context, const std::pair<std::string, std::string> &private_key_and_certificate_path)
+{
+ ssl_context.context.use_private_key_file(private_key_and_certificate_path.first, boost::asio::ssl::context::pem);
+ ssl_context.context.use_certificate_file(private_key_and_certificate_path.second, boost::asio::ssl::context::pem);
+}
+
+bool is_ssl(const unsigned char *data, size_t len)
+{
+ if (len < get_ssl_magic_size())
+ return false;
+
+ // https://security.stackexchange.com/questions/34780/checking-client-hello-for-https-classification
+ MDEBUG("SSL detection buffer, " << len << " bytes: "
+ << (unsigned)(unsigned char)data[0] << " " << (unsigned)(unsigned char)data[1] << " "
+ << (unsigned)(unsigned char)data[2] << " " << (unsigned)(unsigned char)data[3] << " "
+ << (unsigned)(unsigned char)data[4] << " " << (unsigned)(unsigned char)data[5] << " "
+ << (unsigned)(unsigned char)data[6] << " " << (unsigned)(unsigned char)data[7] << " "
+ << (unsigned)(unsigned char)data[8]);
+ if (data[0] == 0x16) // record
+ if (data[1] == 3) // major version
+ if (data[5] == 1) // ClientHello
+ if (data[6] == 0 && data[3]*256 + data[4] == data[7]*256 + data[8] + 4) // length check
+ return true;
+ return false;
+}
+
+bool is_certificate_allowed(boost::asio::ssl::verify_context &ctx, const ssl_context_t &ssl_context)
+{
+ X509_STORE_CTX *sctx = ctx.native_handle();
+ if (!sctx)
+ {
+ MERROR("Error getting verify_context handle");
+ return false;
+ }
+ X509 *cert =X509_STORE_CTX_get_current_cert(sctx);
+ if (!cert)
+ {
+ MERROR("No certificate found in verify_context");
+ return false;
+ }
+
+ // can we check the certificate against a list of fingerprints?
+ if (!ssl_context.allowed_fingerprints.empty()) {
+ // buffer for the certificate digest and the size of the result
+ std::vector<uint8_t> digest(EVP_MAX_MD_SIZE);
+ unsigned int size{ 0 };
+
+ // create the digest from the certificate
+ if (!X509_digest(cert, EVP_sha1(), digest.data(), &size)) {
+ MERROR("Failed to create certificate fingerprint");
+ return false;
+ }
+
+ // strip unnecessary bytes from the digest
+ digest.resize(size);
+
+ // is the certificate fingerprint inside the list of allowed fingerprints?
+ if (std::find(ssl_context.allowed_fingerprints.begin(), ssl_context.allowed_fingerprints.end(), digest) != ssl_context.allowed_fingerprints.end())
+ return true;
+ }
+
+ if (!ssl_context.allowed_certificates.empty()) {
+ BIO *bio_cert = BIO_new(BIO_s_mem());
+ bool success = PEM_write_bio_X509(bio_cert, cert);
+ if (!success)
+ {
+ BIO_free(bio_cert);
+ MERROR("Failed to print certificate");
+ return false;
+ }
+ BUF_MEM *buf = NULL;
+ BIO_get_mem_ptr(bio_cert, &buf);
+ if (!buf || !buf->data || !buf->length)
+ {
+ BIO_free(bio_cert);
+ MERROR("Failed to write certificate: " << ERR_get_error());
+ return false;
+ }
+ std::string certificate(std::string(buf->data, buf->length));
+ BIO_free(bio_cert);
+ if (std::find(ssl_context.allowed_certificates.begin(), ssl_context.allowed_certificates.end(), certificate) != ssl_context.allowed_certificates.end())
+ return true;
+ }
+
+ // if either checklist is non-empty we must have failed it
+ return ssl_context.allowed_fingerprints.empty() && ssl_context.allowed_certificates.empty();
+}
+
+bool ssl_handshake(boost::asio::ssl::stream<boost::asio::ip::tcp::socket> &socket, boost::asio::ssl::stream_base::handshake_type type, const epee::net_utils::ssl_context_t &ssl_context)
+{
+ bool verified = false;
+ socket.next_layer().set_option(boost::asio::ip::tcp::no_delay(true));
+ socket.set_verify_mode(boost::asio::ssl::verify_peer);
+ socket.set_verify_callback([&](bool preverified, boost::asio::ssl::verify_context &ctx)
+ {
+ if (!preverified)
+ {
+ const int err = X509_STORE_CTX_get_error(ctx.native_handle());
+ const int depth = X509_STORE_CTX_get_error_depth(ctx.native_handle());
+ if (err != X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT || depth != 0)
+ {
+ MERROR("Invalid SSL certificate, error " << err << " at depth " << depth << ", connection dropped");
+ return false;
+ }
+ }
+ if (!ssl_context.allow_any_cert && !is_certificate_allowed(ctx, ssl_context))
+ {
+ MERROR("Certificate is not in the allowed list, connection droppped");
+ return false;
+ }
+ verified = true;
+ return true;
+ });
+
+ boost::system::error_code ec;
+ socket.handshake(type, ec);
+ if (ec)
+ {
+ MERROR("handshake failed, connection dropped: " << ec.message());
+ return false;
+ }
+ if (!ssl_context.allow_any_cert && !verified)
+ {
+ MERROR("Peer did not provide a certificate in the allowed list, connection dropped");
+ return false;
+ }
+ MDEBUG("SSL handshake success");
+ return true;
+}
+
+bool ssl_support_from_string(ssl_support_t &ssl, boost::string_ref s)
+{
+ if (s == "enabled")
+ ssl = epee::net_utils::ssl_support_t::e_ssl_support_enabled;
+ else if (s == "disabled")
+ ssl = epee::net_utils::ssl_support_t::e_ssl_support_disabled;
+ else if (s == "autodetect")
+ ssl = epee::net_utils::ssl_support_t::e_ssl_support_autodetect;
+ else
+ return false;
+ return true;
+}
+
+} // namespace
+} // namespace
+
diff --git a/contrib/epee/src/network_throttle-detail.cpp b/contrib/epee/src/network_throttle-detail.cpp
index d2e776df0..f89e7aec0 100644
--- a/contrib/epee/src/network_throttle-detail.cpp
+++ b/contrib/epee/src/network_throttle-detail.cpp
@@ -2,7 +2,7 @@
/// @author rfree (current maintainer in monero.cc project)
/// @brief implementaion for throttling of connection (count and rate-limit speed etc)
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -135,6 +135,7 @@ network_throttle::network_throttle(const std::string &nameshort, const std::stri
m_slot_size = 1.0; // hard coded in few places
m_target_speed = 16 * 1024; // other defaults are probably defined in the command-line parsing code when this class is used e.g. as main global throttle
m_last_sample_time = 0;
+ m_history.resize(m_window_size);
}
void network_throttle::set_name(const std::string &name)
@@ -168,8 +169,7 @@ void network_throttle::tick()
{
_dbg3("Moving counter buffer by 1 second " << last_sample_time_slot << " < " << current_sample_time_slot << " (last time " << m_last_sample_time<<")");
// rotate buffer
- for (size_t i=m_history.size()-1; i>=1; --i) m_history[i] = m_history[i-1];
- m_history[0] = packet_info();
+ m_history.push_front(packet_info());
if (! m_any_packet_yet)
{
m_last_sample_time = time_now;
@@ -191,7 +191,7 @@ void network_throttle::_handle_trafic_exact(size_t packet_size, size_t orginal_s
calculate_times_struct cts ; calculate_times(packet_size, cts , false, -1);
calculate_times_struct cts2; calculate_times(packet_size, cts2, false, 5);
- m_history[0].m_size += packet_size;
+ m_history.front().m_size += packet_size;
std::ostringstream oss; oss << "["; for (auto sample: m_history) oss << sample.m_size << " "; oss << "]" << std::ends;
std::string history_str = oss.str();
diff --git a/contrib/epee/src/network_throttle.cpp b/contrib/epee/src/network_throttle.cpp
index 167738855..f4f0b2c46 100644
--- a/contrib/epee/src/network_throttle.cpp
+++ b/contrib/epee/src/network_throttle.cpp
@@ -26,7 +26,7 @@ Throttling work by:
*/
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/contrib/epee/src/wipeable_string.cpp b/contrib/epee/src/wipeable_string.cpp
index 69f92e106..3a6ee5dac 100644
--- a/contrib/epee/src/wipeable_string.cpp
+++ b/contrib/epee/src/wipeable_string.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/contrib/epee/tests/src/net/test_net.h b/contrib/epee/tests/src/net/test_net.h
index 51b1f1ec6..f99639afc 100644
--- a/contrib/epee/tests/src/net/test_net.h
+++ b/contrib/epee/tests/src/net/test_net.h
@@ -62,7 +62,7 @@ namespace tests
{
const static int ID = 1000;
- struct request
+ struct request_t
{
std::string example_string_data;
@@ -75,9 +75,9 @@ namespace tests
SERIALIZE_T(sub)
END_NAMED_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
-
- struct response
+ struct response_t
{
bool m_success;
uint64_t example_id_data;
@@ -89,13 +89,14 @@ namespace tests
SERIALIZE_STL_CONTAINER_T(subs)
END_NAMED_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_EXAMPLE_2
{
const static int ID = 1001;
- struct request
+ struct request_t
{
std::string example_string_data2;
uint64_t example_id_data;
@@ -105,8 +106,9 @@ namespace tests
SERIALIZE_STL_ANSI_STRING(example_string_data2)
END_NAMED_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
bool m_success;
uint64_t example_id_data;
@@ -116,6 +118,7 @@ namespace tests
SERIALIZE_POD(m_success)
END_NAMED_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
typedef boost::uuids::uuid uuid;
diff --git a/contrib/gitian/README.md b/contrib/gitian/README.md
index 0b13df344..b869bde87 100644
--- a/contrib/gitian/README.md
+++ b/contrib/gitian/README.md
@@ -1,7 +1,7 @@
Gitian building
================
-*Setup instructions for a Gitian build of Monero using a VM or physical system.*
+*Setup instructions for a Gitian build of Monero.*
Gitian is the deterministic build process that is used to build the Monero CLI
executables. It provides a way to be reasonably sure that the
@@ -13,6 +13,10 @@ Multiple developers build the source code by following a specific descriptor
These results are compared and only if they match, the build is accepted and provided
for download.
+Gitian runs compilation steps in an isolated container. It is flexible and gives you full
+control over the build environment, while still ensuring reproducibility and consistent output
+formats.
+
More independent Gitian builders are needed, which is why this guide exists.
It is preferred you follow these steps yourself instead of using someone else's
VM image to avoid 'contaminating' the build.
@@ -22,11 +26,17 @@ Preparing the Gitian builder host
The first step is to prepare the host environment that will be used to perform the Gitian builds.
This guide explains how to set up the environment, and how to start the builds.
+Gitian offers to build with either `kvm`, `docker` or `lxc`. The default build
+path chosen is `lxc`, but its setup is more complicated. You need to be logged in as the `gitianuser`.
+If this user does not exist yet on your system, create it. Gitian can use
+either kvm, lxc or docker as a host environment. This documentation will show
+how to build with lxc and docker. While the docker setup is easy, the lxc setup
+is more involved.
+
+LXC
+---
-Gitian builds are for now executed on Ubuntu 18.04 "Bionic Beaver". A solution is being worked on to run
-it in docker in the future. Please run Ubuntu in either a VM, or on your physical machine.
-You need to be logged in as the `gitianuser` in order to build gitian builds. If this user does not exist yet on your system,
-create it.
+LXC builds should be run on Ubuntu 18.04 "Bionic Beaver".
Note that a version of `lxc-execute` higher or equal to 2.1.1 is required.
You can check the version with `lxc-execute --version`.
@@ -63,15 +73,28 @@ reboot
This setup is required to enable networking in the container.
+Docker
+------
+
+Building in docker does not require much setup. Install docker on your host, then type the following:
+
+```bash
+sudo apt-get install git make curl
+sudo usermod -aG docker gitianuser
+```
+
Manual and Building
-------------------
-The instructions below use the automated script [gitian-build.py](https://github.com/betcoin/bitcoin/blob/master/contrib/gitian-build.py) which only works in Ubuntu.
-It calls all available descriptors. Help for the build steps taken can be accessed with `./gitian-build.py --help`.
+
+The instructions below use the automated script [gitian-build.py](gitian-build.py) which only works in Ubuntu.
+It calls all available .yml descriptors, which in turn pass the build configurations for different platforms to gitian.
+Help for the build steps taken can be accessed with `./gitian-build.py --help`.
Initial Gitian Setup
--------------------
-The `gitian-build.py` script will checkout different release tags, so it's best to copy it:
+
+The `gitian-build.py` script will checkout different release tags, so it's best to copy it to the top level directory:
```bash
cp monero/contrib/gitian/gitian-build.py .
@@ -79,11 +102,16 @@ cp monero/contrib/gitian/gitian-build.py .
Setup the required environment, you only need to do this once:
-```
+```bash
./gitian-build.py --setup fluffypony v0.14.0
```
-Where `fluffypony` is your Github name and `v0.14.0` is the version tag you want to build.
+Where `fluffypony` is your Github name and `v0.14.0` is the version tag you want to build.
+If you are using docker, run it with:
+
+```bash
+./gitian-build.py --setup --docker fluffypony v0.14.0
+```
While gitian and this build script does provide a way for you to sign the build directly, it is recommended to sign in a seperate step.
This script is only there for convenience. Seperate steps for building can still be taken.
@@ -98,9 +126,11 @@ git remote add fluffypony git@github.com:fluffypony/gitian.sigs.git
Build Binaries
-----------------------------
-To build the most recent tag:
+To build the most recent tag (pass in `--docker` after setting up with docker):
- `./gitian-build.py --detach-sign --no-commit -b fluffypony v0.14.0`
+```bash
+./gitian-build.py --detach-sign --no-commit -b fluffypony v0.14.0
+```
To speed up the build, use `-j 5 -m 5000` as the first arguments, where `5` is the number of CPU's you allocated to the VM plus one, and 5000 is a little bit less than then the MB's of RAM you allocated. If there is memory corruption on your machine, try to tweak these values.
@@ -108,7 +138,7 @@ If all went well, this produces a number of (uncommited) `.assert` files in the
If you do detached, offline signing, you need to copy these uncommited changes to your host machine, where you can sign them. For example:
-```
+```bash
export NAME=fluffypony
export VERSION=v0.14.0
gpg --output $VERSION-linux/$NAME/monero-linux-$VERSION-build.assert.sig --detach-sign $VERSION-linux/$NAME/monero-linux-$VERSION-build.assert
@@ -119,7 +149,7 @@ gpg --output $VERSION-win-unsigned/$NAME/monero-win-$VERSION-build.assert.sig --
Make a pull request (both the `.assert` and `.assert.sig` files) to the
[monero-project/gitian.sigs](https://github.com/monero-project/gitian.sigs/) repository:
-```
+```bash
git checkout -b v0.14.0
git commit -S -a -m "Add $NAME v0.14.0"
git push --set-upstream $NAME v0.14.0
@@ -131,3 +161,19 @@ git push --set-upstream $NAME v0.14.0
gpg --detach-sign ${VERSION}-osx-unsigned/${SIGNER}/monero-osx-*-build.assert
```
+More Build Options
+------------------
+
+You can choose your own remote and commit hash by running for example:
+```bash
+./gitian-build.py --detach-sign --no-commit --url https://github.com/moneromooo-monero/bitmonero -b moneromooo 1f5680c8db8f4cc7acc04a04c724b832003440fd
+```
+
+Note that you won't be able to build commits authored before the gitian scripts
+were added. Gitian clones the source files from the given url, be sure to push
+to the remote you provide before building.
+To get all build options run:
+```bash
+./gitian-build.py --help
+```
+
diff --git a/contrib/gitian/gitian-build.py b/contrib/gitian/gitian-build.py
index df1ba0d6b..cd88ecb20 100755
--- a/contrib/gitian/gitian-build.py
+++ b/contrib/gitian/gitian-build.py
@@ -116,7 +116,7 @@ def main():
parser.add_argument('-D', '--detach-sign', action='store_true', dest='detach_sign', help='Create the assert file for detached signing. Will not commit anything.')
parser.add_argument('-n', '--no-commit', action='store_false', dest='commit_files', help='Do not commit anything to git')
parser.add_argument('signer', help='GPG signer to sign each build assert file')
- parser.add_argument('version', help='Version number, commit, or branch to build. If building a commit or branch, the -c option must be specified')
+ parser.add_argument('version', help='Version number, commit, or branch to build.')
args = parser.parse_args()
workdir = os.getcwd()
diff --git a/contrib/gitian/gitian-osx.yml b/contrib/gitian/gitian-osx.yml
index a6fcff0da..7de302353 100644
--- a/contrib/gitian/gitian-osx.yml
+++ b/contrib/gitian/gitian-osx.yml
@@ -12,21 +12,17 @@ packages:
- "git"
- "pkg-config"
- "autoconf"
-- "librsvg2-bin"
-- "libtiff-tools"
- "libtool"
- "automake"
- "faketime"
- "bsdmainutils"
- "cmake"
-- "imagemagick"
- "libcap-dev"
- "libz-dev"
- "libbz2-dev"
- "python"
- "python-dev"
- "python-setuptools"
-- "fonts-tuffy"
remotes:
- "url": "https://github.com/monero-project/monero.git"
"dir": "monero"
diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt
index 7553f87ea..bc4344b34 100644
--- a/external/CMakeLists.txt
+++ b/external/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/external/db_drivers/CMakeLists.txt b/external/db_drivers/CMakeLists.txt
index d537ec029..04776c475 100644
--- a/external/db_drivers/CMakeLists.txt
+++ b/external/db_drivers/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/external/db_drivers/liblmdb/CMakeLists.txt b/external/db_drivers/liblmdb/CMakeLists.txt
index 2e8822f54..562ebb1eb 100644
--- a/external/db_drivers/liblmdb/CMakeLists.txt
+++ b/external/db_drivers/liblmdb/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/external/db_drivers/liblmdb/mdb.c b/external/db_drivers/liblmdb/mdb.c
index 3b2745f95..8e67d5981 100644
--- a/external/db_drivers/liblmdb/mdb.c
+++ b/external/db_drivers/liblmdb/mdb.c
@@ -9641,7 +9641,7 @@ mdb_page_split(MDB_cursor *mc, MDB_val *newkey, MDB_val *newdata, pgno_t newpgno
* the split so the new page is emptier than the old page.
* This yields better packing during sequential inserts.
*/
- if (nkeys < 20 || nsize > pmax/16 || newindx >= nkeys) {
+ if (nkeys < 32 || nsize > pmax/16 || newindx >= nkeys) {
/* Find split point */
psize = 0;
if (newindx <= split_indx || newindx >= nkeys) {
diff --git a/external/easylogging++/CMakeLists.txt b/external/easylogging++/CMakeLists.txt
index 78795d54b..8287024c2 100644
--- a/external/easylogging++/CMakeLists.txt
+++ b/external/easylogging++/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/include/INode.h b/include/INode.h
index 21be0b2f3..0d896ca69 100644
--- a/include/INode.h
+++ b/include/INode.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/include/IWallet.h b/include/IWallet.h
index 98110a9d6..98362895d 100644
--- a/include/IWallet.h
+++ b/include/IWallet.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f1454b48e..2ae72ee81 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/src/blockchain_db/CMakeLists.txt b/src/blockchain_db/CMakeLists.txt
index 277f4458e..db161fa5e 100644
--- a/src/blockchain_db/CMakeLists.txt
+++ b/src/blockchain_db/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp
index 60a7326f8..3eb24494f 100644
--- a/src/blockchain_db/berkeleydb/db_bdb.cpp
+++ b/src/blockchain_db/berkeleydb/db_bdb.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
diff --git a/src/blockchain_db/berkeleydb/db_bdb.h b/src/blockchain_db/berkeleydb/db_bdb.h
index e80adae9e..04a33d7c6 100644
--- a/src/blockchain_db/berkeleydb/db_bdb.h
+++ b/src/blockchain_db/berkeleydb/db_bdb.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
diff --git a/src/blockchain_db/blockchain_db.cpp b/src/blockchain_db/blockchain_db.cpp
index d3eefef6e..d772bf4bb 100644
--- a/src/blockchain_db/blockchain_db.cpp
+++ b/src/blockchain_db/blockchain_db.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -121,8 +121,10 @@ void BlockchainDB::pop_block()
pop_block(blk, txs);
}
-void BlockchainDB::add_transaction(const crypto::hash& blk_hash, const transaction& tx, const crypto::hash* tx_hash_ptr, const crypto::hash* tx_prunable_hash_ptr)
+void BlockchainDB::add_transaction(const crypto::hash& blk_hash, const std::pair<transaction, blobdata>& txp, const crypto::hash* tx_hash_ptr, const crypto::hash* tx_prunable_hash_ptr)
{
+ const transaction &tx = txp.first;
+
bool miner_tx = false;
crypto::hash tx_hash, tx_prunable_hash;
if (!tx_hash_ptr)
@@ -138,7 +140,7 @@ void BlockchainDB::add_transaction(const crypto::hash& blk_hash, const transacti
if (tx.version >= 2)
{
if (!tx_prunable_hash_ptr)
- tx_prunable_hash = get_transaction_prunable_hash(tx);
+ tx_prunable_hash = get_transaction_prunable_hash(tx, &txp.second);
else
tx_prunable_hash = *tx_prunable_hash_ptr;
}
@@ -168,7 +170,7 @@ void BlockchainDB::add_transaction(const crypto::hash& blk_hash, const transacti
}
}
- uint64_t tx_id = add_transaction_data(blk_hash, tx, tx_hash, tx_prunable_hash);
+ uint64_t tx_id = add_transaction_data(blk_hash, txp, tx_hash, tx_prunable_hash);
std::vector<uint64_t> amount_output_indices(tx.vout.size());
@@ -195,13 +197,16 @@ void BlockchainDB::add_transaction(const crypto::hash& blk_hash, const transacti
add_tx_amount_output_indices(tx_id, amount_output_indices);
}
-uint64_t BlockchainDB::add_block( const block& blk
+uint64_t BlockchainDB::add_block( const std::pair<block, blobdata>& blck
, size_t block_weight
+ , uint64_t long_term_block_weight
, const difficulty_type& cumulative_difficulty
, const uint64_t& coins_generated
- , const std::vector<transaction>& txs
+ , const std::vector<std::pair<transaction, blobdata>>& txs
)
{
+ const block &blk = blck.first;
+
// sanity
if (blk.tx_hashes.size() != txs.size())
throw std::runtime_error("Inconsistent tx/hashes sizes");
@@ -220,16 +225,16 @@ uint64_t BlockchainDB::add_block( const block& blk
time1 = epee::misc_utils::get_tick_count();
uint64_t num_rct_outs = 0;
- add_transaction(blk_hash, blk.miner_tx);
+ add_transaction(blk_hash, std::make_pair(blk.miner_tx, tx_to_blob(blk.miner_tx)));
if (blk.miner_tx.version == 2)
num_rct_outs += blk.miner_tx.vout.size();
int tx_i = 0;
crypto::hash tx_hash = crypto::null_hash;
- for (const transaction& tx : txs)
+ for (const std::pair<transaction, blobdata>& tx : txs)
{
tx_hash = blk.tx_hashes[tx_i];
add_transaction(blk_hash, tx, &tx_hash);
- for (const auto &vout: tx.vout)
+ for (const auto &vout: tx.first.vout)
{
if (vout.amount == 0)
++num_rct_outs;
@@ -241,7 +246,7 @@ uint64_t BlockchainDB::add_block( const block& blk
// call out to subclass implementation to add the block & metadata
time1 = epee::misc_utils::get_tick_count();
- add_block(blk, block_weight, cumulative_difficulty, coins_generated, num_rct_outs, blk_hash);
+ add_block(blk, block_weight, long_term_block_weight, cumulative_difficulty, coins_generated, num_rct_outs, blk_hash);
TIME_MEASURE_FINISH(time1);
time_add_block1 += time1;
diff --git a/src/blockchain_db/blockchain_db.h b/src/blockchain_db/blockchain_db.h
index 137d5958a..313e716e0 100644
--- a/src/blockchain_db/blockchain_db.h
+++ b/src/blockchain_db/blockchain_db.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -358,12 +358,14 @@ private:
*
* @param blk the block to be added
* @param block_weight the weight of the block (transactions and all)
+ * @param long_term_block_weight the long term block weight of the block (transactions and all)
* @param cumulative_difficulty the accumulated difficulty after this block
* @param coins_generated the number of coins generated total after this block
* @param blk_hash the hash of the block
*/
virtual void add_block( const block& blk
, size_t block_weight
+ , uint64_t long_term_block_weight
, const difficulty_type& cumulative_difficulty
, const uint64_t& coins_generated
, uint64_t num_rct_outs
@@ -375,7 +377,7 @@ private:
*
* The subclass implementing this will remove the block data from the top
* block in the chain. The data to be removed is that which was added in
- * BlockchainDB::add_block(const block& blk, size_t block_weight, const difficulty_type& cumulative_difficulty, const uint64_t& coins_generated, const crypto::hash& blk_hash)
+ * BlockchainDB::add_block(const block& blk, size_t block_weight, uint64_t long_term_block_weight, const difficulty_type& cumulative_difficulty, const uint64_t& coins_generated, const crypto::hash& blk_hash)
*
* If any of this cannot be done, the subclass should throw the corresponding
* subclass of DB_EXCEPTION
@@ -402,7 +404,7 @@ private:
* @param tx_prunable_hash the hash of the prunable part of the transaction
* @return the transaction ID
*/
- virtual uint64_t add_transaction_data(const crypto::hash& blk_hash, const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prunable_hash) = 0;
+ virtual uint64_t add_transaction_data(const crypto::hash& blk_hash, const std::pair<transaction, blobdata>& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prunable_hash) = 0;
/**
* @brief remove data about a transaction
@@ -530,7 +532,7 @@ protected:
* @param tx_hash_ptr the hash of the transaction, if already calculated
* @param tx_prunable_hash_ptr the hash of the prunable part of the transaction, if already calculated
*/
- void add_transaction(const crypto::hash& blk_hash, const transaction& tx, const crypto::hash* tx_hash_ptr = NULL, const crypto::hash* tx_prunable_hash_ptr = NULL);
+ void add_transaction(const crypto::hash& blk_hash, const std::pair<transaction, blobdata>& tx, const crypto::hash* tx_hash_ptr = NULL, const crypto::hash* tx_prunable_hash_ptr = NULL);
mutable uint64_t time_tx_exists = 0; //!< a performance metric
uint64_t time_commit1 = 0; //!< a performance metric
@@ -789,17 +791,19 @@ public:
*
* @param blk the block to be added
* @param block_weight the size of the block (transactions and all)
+ * @param long_term_block_weight the long term weight of the block (transactions and all)
* @param cumulative_difficulty the accumulated difficulty after this block
* @param coins_generated the number of coins generated total after this block
* @param txs the transactions in the block
*
* @return the height of the chain post-addition
*/
- virtual uint64_t add_block( const block& blk
+ virtual uint64_t add_block( const std::pair<block, blobdata>& blk
, size_t block_weight
+ , uint64_t long_term_block_weight
, const difficulty_type& cumulative_difficulty
, const uint64_t& coins_generated
- , const std::vector<transaction>& txs
+ , const std::vector<std::pair<transaction, blobdata>>& txs
);
/**
@@ -985,6 +989,17 @@ public:
virtual uint64_t get_block_already_generated_coins(const uint64_t& height) const = 0;
/**
+ * @brief fetch a block's long term weight
+ *
+ * If the block does not exist, the subclass should throw BLOCK_DNE
+ *
+ * @param height the height requested
+ *
+ * @return the long term weight
+ */
+ virtual uint64_t get_block_long_term_weight(const uint64_t& height) const = 0;
+
+ /**
* @brief fetch a block's hash
*
* The subclass should return hash of the block with the
@@ -1037,9 +1052,11 @@ public:
*
* The subclass should return the hash of the most recent block
*
+ * @param block_height if non NULL, returns the height of that block (ie, the blockchain height minus 1)
+ *
* @return the top block's hash
*/
- virtual crypto::hash top_block_hash() const = 0;
+ virtual crypto::hash top_block_hash(uint64_t *block_height = NULL) const = 0;
/**
* @brief fetch the top block
diff --git a/src/blockchain_db/db_types.h b/src/blockchain_db/db_types.h
index b8c7fa3e3..04cadbb10 100644
--- a/src/blockchain_db/db_types.h
+++ b/src/blockchain_db/db_types.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index 8a1303be9..becffed16 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
@@ -29,6 +29,7 @@
#include <boost/filesystem.hpp>
#include <boost/format.hpp>
+#include <boost/circular_buffer.hpp>
#include <memory> // std::unique_ptr
#include <cstring> // memcpy
@@ -53,7 +54,7 @@ using epee::string_tools::pod_to_hex;
using namespace crypto;
// Increase when the DB structure changes
-#define VERSION 3
+#define VERSION 4
namespace
{
@@ -267,7 +268,7 @@ inline void lmdb_db_open(MDB_txn* txn, const char* name, int flags, MDB_dbi& dbi
namespace cryptonote
{
-typedef struct mdb_block_info_old
+typedef struct mdb_block_info_1
{
uint64_t bi_height;
uint64_t bi_timestamp;
@@ -275,9 +276,9 @@ typedef struct mdb_block_info_old
uint64_t bi_weight; // a size_t really but we need 32-bit compat
difficulty_type bi_diff;
crypto::hash bi_hash;
-} mdb_block_info_old;
+} mdb_block_info_1;
-typedef struct mdb_block_info
+typedef struct mdb_block_info_2
{
uint64_t bi_height;
uint64_t bi_timestamp;
@@ -286,7 +287,21 @@ typedef struct mdb_block_info
difficulty_type bi_diff;
crypto::hash bi_hash;
uint64_t bi_cum_rct;
-} mdb_block_info;
+} mdb_block_info_2;
+
+typedef struct mdb_block_info_3
+{
+ uint64_t bi_height;
+ uint64_t bi_timestamp;
+ uint64_t bi_coins;
+ uint64_t bi_weight; // a size_t really but we need 32-bit compat
+ difficulty_type bi_diff;
+ crypto::hash bi_hash;
+ uint64_t bi_cum_rct;
+ uint64_t bi_long_term_block_weight;
+} mdb_block_info_3;
+
+typedef mdb_block_info_3 mdb_block_info;
typedef struct blk_height {
crypto::hash bh_hash;
@@ -504,7 +519,7 @@ void BlockchainLMDB::do_resize(uint64_t increase_size)
mdb_env_stat(m_env, &mst);
// add 1Gb per resize, instead of doing a percentage increase
- uint64_t new_mapsize = (double) mei.me_mapsize + add_size;
+ uint64_t new_mapsize = (uint64_t) mei.me_mapsize + add_size;
// If given, use increase_size instead of above way of resizing.
// This is currently used for increasing by an estimated size at start of new
@@ -694,7 +709,7 @@ estim:
return threshold_size;
}
-void BlockchainLMDB::add_block(const block& blk, size_t block_weight, const difficulty_type& cumulative_difficulty, const uint64_t& coins_generated,
+void BlockchainLMDB::add_block(const block& blk, size_t block_weight, uint64_t long_term_block_weight, const difficulty_type& cumulative_difficulty, const uint64_t& coins_generated,
uint64_t num_rct_outs, const crypto::hash& blk_hash)
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
@@ -754,6 +769,7 @@ void BlockchainLMDB::add_block(const block& blk, size_t block_weight, const diff
const mdb_block_info *bi_prev = (const mdb_block_info*)h.mv_data;
bi.bi_cum_rct += bi_prev->bi_cum_rct;
}
+ bi.bi_long_term_block_weight = long_term_block_weight;
MDB_val_set(val, bi);
result = mdb_cursor_put(m_cur_block_info, (MDB_val *)&zerokval, &val, MDB_APPENDDUP);
@@ -807,7 +823,7 @@ void BlockchainLMDB::remove_block()
throw1(DB_ERROR(lmdb_error("Failed to add removal of block info to db transaction: ", result).c_str()));
}
-uint64_t BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prunable_hash)
+uint64_t BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, const std::pair<transaction, blobdata>& txp, const crypto::hash& tx_hash, const crypto::hash& tx_prunable_hash)
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
@@ -833,6 +849,7 @@ uint64_t BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, cons
throw1(DB_ERROR(lmdb_error(std::string("Error checking if tx index exists for tx hash ") + epee::string_tools::pod_to_hex(tx_hash) + ": ", result).c_str()));
}
+ const cryptonote::transaction &tx = txp.first;
txindex ti;
ti.key = tx_hash;
ti.data.tx_id = tx_id;
@@ -846,24 +863,29 @@ uint64_t BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, cons
if (result)
throw0(DB_ERROR(lmdb_error("Failed to add tx data to db transaction: ", result).c_str()));
- cryptonote::blobdata blob = tx_to_blob(tx);
+ const cryptonote::blobdata &blob = txp.second;
MDB_val_sized(blobval, blob);
- std::stringstream ss;
- binary_archive<true> ba(ss);
- bool r = const_cast<cryptonote::transaction&>(tx).serialize_base(ba);
- if (!r)
- throw0(DB_ERROR("Failed to serialize pruned tx"));
- std::string pruned = ss.str();
- MDB_val_sized(pruned_blob, pruned);
+ unsigned int unprunable_size = tx.unprunable_size;
+ if (unprunable_size == 0)
+ {
+ std::stringstream ss;
+ binary_archive<true> ba(ss);
+ bool r = const_cast<cryptonote::transaction&>(tx).serialize_base(ba);
+ if (!r)
+ throw0(DB_ERROR("Failed to serialize pruned tx"));
+ unprunable_size = ss.str().size();
+ }
+
+ if (unprunable_size > blob.size())
+ throw0(DB_ERROR("pruned tx size is larger than tx size"));
+
+ MDB_val pruned_blob = {unprunable_size, (void*)blob.data()};
result = mdb_cursor_put(m_cur_txs_pruned, &val_tx_id, &pruned_blob, MDB_APPEND);
if (result)
throw0(DB_ERROR(lmdb_error("Failed to add pruned tx blob to db transaction: ", result).c_str()));
- if (pruned.size() > blob.size())
- throw0(DB_ERROR("pruned tx size is larger than tx size"));
- cryptonote::blobdata prunable(blob.data() + pruned.size(), blob.size() - pruned.size());
- MDB_val_sized(prunable_blob, prunable);
+ MDB_val prunable_blob = {blob.size() - unprunable_size, (void*)(blob.data() + unprunable_size)};
result = mdb_cursor_put(m_cur_txs_prunable, &val_tx_id, &prunable_blob, MDB_APPEND);
if (result)
throw0(DB_ERROR(lmdb_error("Failed to add prunable tx blob to db transaction: ", result).c_str()));
@@ -1313,14 +1335,14 @@ void BlockchainLMDB::open(const std::string& filename, const int db_flags)
MDB_envinfo mei;
mdb_env_info(m_env, &mei);
- uint64_t cur_mapsize = (double)mei.me_mapsize;
+ uint64_t cur_mapsize = (uint64_t)mei.me_mapsize;
if (cur_mapsize < mapsize)
{
if (auto result = mdb_env_set_mapsize(m_env, mapsize))
throw0(DB_ERROR(lmdb_error("Failed to set max memory map size: ", result).c_str()));
mdb_env_info(m_env, &mei);
- cur_mapsize = (double)mei.me_mapsize;
+ cur_mapsize = (uint64_t)mei.me_mapsize;
LOG_PRINT_L1("LMDB memory map size: " << cur_mapsize);
}
@@ -2486,6 +2508,29 @@ uint64_t BlockchainLMDB::get_block_already_generated_coins(const uint64_t& heigh
return ret;
}
+uint64_t BlockchainLMDB::get_block_long_term_weight(const uint64_t& height) const
+{
+ LOG_PRINT_L3("BlockchainLMDB::" << __func__);
+ check_open();
+
+ TXN_PREFIX_RDONLY();
+ RCURSOR(block_info);
+
+ MDB_val_set(result, height);
+ auto get_result = mdb_cursor_get(m_cur_block_info, (MDB_val *)&zerokval, &result, MDB_GET_BOTH);
+ if (get_result == MDB_NOTFOUND)
+ {
+ throw0(BLOCK_DNE(std::string("Attempt to get block long term weight from height ").append(boost::lexical_cast<std::string>(height)).append(" failed -- block info not in db").c_str()));
+ }
+ else if (get_result)
+ throw0(DB_ERROR("Error attempting to retrieve a long term block weight from the db"));
+
+ mdb_block_info *bi = (mdb_block_info *)result.mv_data;
+ uint64_t ret = bi->bi_long_term_block_weight;
+ TXN_POSTFIX_RDONLY();
+ return ret;
+}
+
crypto::hash BlockchainLMDB::get_block_hash_from_height(const uint64_t& height) const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
@@ -2537,11 +2582,13 @@ std::vector<crypto::hash> BlockchainLMDB::get_hashes_range(const uint64_t& h1, c
return v;
}
-crypto::hash BlockchainLMDB::top_block_hash() const
+crypto::hash BlockchainLMDB::top_block_hash(uint64_t *block_height) const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
uint64_t m_height = height();
+ if (block_height)
+ *block_height = m_height - 1;
if (m_height != 0)
{
return get_block_hash_from_height(m_height - 1);
@@ -3524,8 +3571,8 @@ void BlockchainLMDB::block_txn_abort()
}
}
-uint64_t BlockchainLMDB::add_block(const block& blk, size_t block_weight, const difficulty_type& cumulative_difficulty, const uint64_t& coins_generated,
- const std::vector<transaction>& txs)
+uint64_t BlockchainLMDB::add_block(const std::pair<block, blobdata>& blk, size_t block_weight, uint64_t long_term_block_weight, const difficulty_type& cumulative_difficulty, const uint64_t& coins_generated,
+ const std::vector<std::pair<transaction, blobdata>>& txs)
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
@@ -3543,7 +3590,7 @@ uint64_t BlockchainLMDB::add_block(const block& blk, size_t block_weight, const
try
{
- BlockchainDB::add_block(blk, block_weight, cumulative_difficulty, coins_generated, txs);
+ BlockchainDB::add_block(blk, block_weight, long_term_block_weight, cumulative_difficulty, coins_generated, txs);
}
catch (const DB_ERROR_TXN_START& e)
{
@@ -4087,7 +4134,7 @@ void BlockchainLMDB::migrate_0_1()
break;
}
MDB_dbi diffs, hashes, sizes, timestamps;
- mdb_block_info_old bi;
+ mdb_block_info_1 bi;
MDB_val_set(nv, bi);
lmdb_db_open(txn, "block_diffs", 0, diffs, "Failed to open db handle for block_diffs");
@@ -4444,7 +4491,7 @@ void BlockchainLMDB::migrate_0_1()
if (!parse_and_validate_block_from_blob(bd, b))
throw0(DB_ERROR("Failed to parse block from blob retrieved from the db"));
- add_transaction(null_hash, b.miner_tx);
+ add_transaction(null_hash, std::make_pair(b.miner_tx, tx_to_blob(b.miner_tx)));
for (unsigned int j = 0; j<b.tx_hashes.size(); j++) {
transaction tx;
hk.mv_data = &b.tx_hashes[j];
@@ -4454,7 +4501,7 @@ void BlockchainLMDB::migrate_0_1()
bd.assign(reinterpret_cast<char*>(v.mv_data), v.mv_size);
if (!parse_and_validate_tx_from_blob(bd, tx))
throw0(DB_ERROR("Failed to parse tx from blob retrieved from the db"));
- add_transaction(null_hash, tx, &b.tx_hashes[j]);
+ add_transaction(null_hash, std::make_pair(std::move(tx), bd), &b.tx_hashes[j]);
result = mdb_cursor_del(c_txs, 0);
if (result)
throw0(DB_ERROR(lmdb_error("Failed to get record from txs: ", result).c_str()));
@@ -4714,8 +4761,8 @@ void BlockchainLMDB::migrate_2_3()
}
else if (result)
throw0(DB_ERROR(lmdb_error("Failed to get a record from block_info: ", result).c_str()));
- const mdb_block_info_old *bi_old = (const mdb_block_info_old*)v.mv_data;
- mdb_block_info bi;
+ const mdb_block_info_1 *bi_old = (const mdb_block_info_1*)v.mv_data;
+ mdb_block_info_2 bi;
bi.bi_height = bi_old->bi_height;
bi.bi_timestamp = bi_old->bi_timestamp;
bi.bi_coins = bi_old->bi_coins;
@@ -4748,6 +4795,7 @@ void BlockchainLMDB::migrate_2_3()
throw0(DB_ERROR(lmdb_error("Failed to delete old block_info table: ", result).c_str()));
RENAME_DB("block_infn");
+ mdb_dbi_close(m_env, m_block_info);
lmdb_db_open(txn, "block_info", MDB_INTEGERKEY | MDB_CREATE | MDB_DUPSORT | MDB_DUPFIXED, m_block_info, "Failed to open db handle for block_infn");
mdb_set_dupsort(txn, m_block_info, compare_uint64);
@@ -4768,6 +4816,166 @@ void BlockchainLMDB::migrate_2_3()
txn.commit();
}
+void BlockchainLMDB::migrate_3_4()
+{
+ LOG_PRINT_L3("BlockchainLMDB::" << __func__);
+ uint64_t i;
+ int result;
+ mdb_txn_safe txn(false);
+ MDB_val k, v;
+ char *ptr;
+ bool past_long_term_weight = false;
+
+ MGINFO_YELLOW("Migrating blockchain from DB version 3 to 4 - this may take a while:");
+
+ do {
+ LOG_PRINT_L1("migrating block info:");
+
+ result = mdb_txn_begin(m_env, NULL, 0, txn);
+ if (result)
+ throw0(DB_ERROR(lmdb_error("Failed to create a transaction for the db: ", result).c_str()));
+
+ MDB_stat db_stats;
+ if ((result = mdb_stat(txn, m_blocks, &db_stats)))
+ throw0(DB_ERROR(lmdb_error("Failed to query m_blocks: ", result).c_str()));
+ const uint64_t blockchain_height = db_stats.ms_entries;
+
+ boost::circular_buffer<uint64_t> long_term_block_weights(CRYPTONOTE_LONG_TERM_BLOCK_WEIGHT_WINDOW_SIZE);
+
+ /* the block_info table name is the same but the old version and new version
+ * have incompatible data. Create a new table. We want the name to be similar
+ * to the old name so that it will occupy the same location in the DB.
+ */
+ MDB_dbi o_block_info = m_block_info;
+ lmdb_db_open(txn, "block_infn", MDB_INTEGERKEY | MDB_CREATE | MDB_DUPSORT | MDB_DUPFIXED, m_block_info, "Failed to open db handle for block_infn");
+ mdb_set_dupsort(txn, m_block_info, compare_uint64);
+
+
+ MDB_cursor *c_blocks;
+ result = mdb_cursor_open(txn, m_blocks, &c_blocks);
+ if (result)
+ throw0(DB_ERROR(lmdb_error("Failed to open a cursor for blocks: ", result).c_str()));
+
+ MDB_cursor *c_old, *c_cur;
+ i = 0;
+ while(1) {
+ if (!(i % 1000)) {
+ if (i) {
+ LOGIF(el::Level::Info) {
+ std::cout << i << " / " << blockchain_height << " \r" << std::flush;
+ }
+ txn.commit();
+ result = mdb_txn_begin(m_env, NULL, 0, txn);
+ if (result)
+ throw0(DB_ERROR(lmdb_error("Failed to create a transaction for the db: ", result).c_str()));
+ }
+ result = mdb_cursor_open(txn, m_block_info, &c_cur);
+ if (result)
+ throw0(DB_ERROR(lmdb_error("Failed to open a cursor for block_infn: ", result).c_str()));
+ result = mdb_cursor_open(txn, o_block_info, &c_old);
+ if (result)
+ throw0(DB_ERROR(lmdb_error("Failed to open a cursor for block_info: ", result).c_str()));
+ result = mdb_cursor_open(txn, m_blocks, &c_blocks);
+ if (result)
+ throw0(DB_ERROR(lmdb_error("Failed to open a cursor for blocks: ", result).c_str()));
+ if (!i) {
+ MDB_stat db_stat;
+ result = mdb_stat(txn, m_block_info, &db_stats);
+ if (result)
+ throw0(DB_ERROR(lmdb_error("Failed to query m_block_info: ", result).c_str()));
+ i = db_stats.ms_entries;
+ }
+ }
+ result = mdb_cursor_get(c_old, &k, &v, MDB_NEXT);
+ if (result == MDB_NOTFOUND) {
+ txn.commit();
+ break;
+ }
+ else if (result)
+ throw0(DB_ERROR(lmdb_error("Failed to get a record from block_info: ", result).c_str()));
+ const mdb_block_info_2 *bi_old = (const mdb_block_info_2*)v.mv_data;
+ mdb_block_info_3 bi;
+ bi.bi_height = bi_old->bi_height;
+ bi.bi_timestamp = bi_old->bi_timestamp;
+ bi.bi_coins = bi_old->bi_coins;
+ bi.bi_weight = bi_old->bi_weight;
+ bi.bi_diff = bi_old->bi_diff;
+ bi.bi_hash = bi_old->bi_hash;
+ bi.bi_cum_rct = bi_old->bi_cum_rct;
+
+ // get block major version to determine which rule is in place
+ if (!past_long_term_weight)
+ {
+ MDB_val_copy<uint64_t> kb(bi.bi_height);
+ MDB_val vb;
+ result = mdb_cursor_get(c_blocks, &kb, &vb, MDB_SET);
+ if (result)
+ throw0(DB_ERROR(lmdb_error("Failed to query m_blocks: ", result).c_str()));
+ if (vb.mv_size == 0)
+ throw0(DB_ERROR("Invalid data from m_blocks"));
+ const uint8_t block_major_version = *((const uint8_t*)vb.mv_data);
+ if (block_major_version >= HF_VERSION_LONG_TERM_BLOCK_WEIGHT)
+ past_long_term_weight = true;
+ }
+
+ uint64_t long_term_block_weight;
+ if (past_long_term_weight)
+ {
+ std::vector<uint64_t> weights(long_term_block_weights.begin(), long_term_block_weights.end());
+ uint64_t long_term_effective_block_median_weight = std::max<uint64_t>(CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5, epee::misc_utils::median(weights));
+ long_term_block_weight = std::min<uint64_t>(bi.bi_weight, long_term_effective_block_median_weight + long_term_effective_block_median_weight * 2 / 5);
+ }
+ else
+ {
+ long_term_block_weight = bi.bi_weight;
+ }
+ long_term_block_weights.push_back(long_term_block_weight);
+ bi.bi_long_term_block_weight = long_term_block_weight;
+
+ MDB_val_set(nv, bi);
+ result = mdb_cursor_put(c_cur, (MDB_val *)&zerokval, &nv, MDB_APPENDDUP);
+ if (result)
+ throw0(DB_ERROR(lmdb_error("Failed to put a record into block_infn: ", result).c_str()));
+ /* we delete the old records immediately, so the overall DB and mapsize should not grow.
+ * This is a little slower than just letting mdb_drop() delete it all at the end, but
+ * it saves a significant amount of disk space.
+ */
+ result = mdb_cursor_del(c_old, 0);
+ if (result)
+ throw0(DB_ERROR(lmdb_error("Failed to delete a record from block_info: ", result).c_str()));
+ i++;
+ }
+
+ result = mdb_txn_begin(m_env, NULL, 0, txn);
+ if (result)
+ throw0(DB_ERROR(lmdb_error("Failed to create a transaction for the db: ", result).c_str()));
+ /* Delete the old table */
+ result = mdb_drop(txn, o_block_info, 1);
+ if (result)
+ throw0(DB_ERROR(lmdb_error("Failed to delete old block_info table: ", result).c_str()));
+
+ RENAME_DB("block_infn");
+ mdb_dbi_close(m_env, m_block_info);
+
+ lmdb_db_open(txn, "block_info", MDB_INTEGERKEY | MDB_CREATE | MDB_DUPSORT | MDB_DUPFIXED, m_block_info, "Failed to open db handle for block_infn");
+ mdb_set_dupsort(txn, m_block_info, compare_uint64);
+
+ txn.commit();
+ } while(0);
+
+ uint32_t version = 4;
+ v.mv_data = (void *)&version;
+ v.mv_size = sizeof(version);
+ MDB_val_str(vk, "version");
+ result = mdb_txn_begin(m_env, NULL, 0, txn);
+ if (result)
+ throw0(DB_ERROR(lmdb_error("Failed to create a transaction for the db: ", result).c_str()));
+ result = mdb_put(txn, m_properties, &vk, &v, 0);
+ if (result)
+ throw0(DB_ERROR(lmdb_error("Failed to update version for the db: ", result).c_str()));
+ txn.commit();
+}
+
void BlockchainLMDB::migrate(const uint32_t oldversion)
{
if (oldversion < 1)
@@ -4776,6 +4984,8 @@ void BlockchainLMDB::migrate(const uint32_t oldversion)
migrate_1_2();
if (oldversion < 3)
migrate_2_3();
+ if (oldversion < 4)
+ migrate_3_4();
}
} // namespace cryptonote
diff --git a/src/blockchain_db/lmdb/db_lmdb.h b/src/blockchain_db/lmdb/db_lmdb.h
index c07ab8da5..7a04c5f0c 100644
--- a/src/blockchain_db/lmdb/db_lmdb.h
+++ b/src/blockchain_db/lmdb/db_lmdb.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
@@ -225,13 +225,15 @@ public:
virtual uint64_t get_block_already_generated_coins(const uint64_t& height) const;
+ virtual uint64_t get_block_long_term_weight(const uint64_t& height) const;
+
virtual crypto::hash get_block_hash_from_height(const uint64_t& height) const;
virtual std::vector<block> get_blocks_range(const uint64_t& h1, const uint64_t& h2) const;
virtual std::vector<crypto::hash> get_hashes_range(const uint64_t& h1, const uint64_t& h2) const;
- virtual crypto::hash top_block_hash() const;
+ virtual crypto::hash top_block_hash(uint64_t *block_height = NULL) const;
virtual block get_top_block() const;
@@ -290,11 +292,12 @@ public:
virtual bool for_all_outputs(std::function<bool(uint64_t amount, const crypto::hash &tx_hash, uint64_t height, size_t tx_idx)> f) const;
virtual bool for_all_outputs(uint64_t amount, const std::function<bool(uint64_t height)> &f) const;
- virtual uint64_t add_block( const block& blk
+ virtual uint64_t add_block( const std::pair<block, blobdata>& blk
, size_t block_weight
+ , uint64_t long_term_block_weight
, const difficulty_type& cumulative_difficulty
, const uint64_t& coins_generated
- , const std::vector<transaction>& txs
+ , const std::vector<std::pair<transaction, blobdata>>& txs
);
virtual void set_batch_transactions(bool batch_transactions);
@@ -341,6 +344,7 @@ private:
virtual void add_block( const block& blk
, size_t block_weight
+ , uint64_t long_term_block_weight
, const difficulty_type& cumulative_difficulty
, const uint64_t& coins_generated
, uint64_t num_rct_outs
@@ -349,7 +353,7 @@ private:
virtual void remove_block();
- virtual uint64_t add_transaction_data(const crypto::hash& blk_hash, const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prunable_hash);
+ virtual uint64_t add_transaction_data(const crypto::hash& blk_hash, const std::pair<transaction, blobdata>& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prunable_hash);
virtual void remove_transaction_data(const crypto::hash& tx_hash, const transaction& tx);
@@ -405,6 +409,9 @@ private:
// migrate from DB version 2 to 3
void migrate_2_3();
+ // migrate from DB version 3 to 4
+ void migrate_3_4();
+
void cleanup_batch();
private:
diff --git a/tests/unit_tests/testdb.h b/src/blockchain_db/testdb.h
index 8f5cf70e8..eb9c3e45a 100644
--- a/tests/unit_tests/testdb.h
+++ b/src/blockchain_db/testdb.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -33,9 +33,11 @@
#include <string>
#include <vector>
#include <map>
-#include "gtest/gtest.h"
-#include "blockchain_db/blockchain_db.h"
+#include "blockchain_db.h"
+
+namespace cryptonote
+{
class BaseTestDB: public cryptonote::BlockchainDB {
public:
@@ -73,10 +75,11 @@ public:
virtual cryptonote::difficulty_type get_block_cumulative_difficulty(const uint64_t& height) const { return 10; }
virtual cryptonote::difficulty_type get_block_difficulty(const uint64_t& height) const { return 0; }
virtual uint64_t get_block_already_generated_coins(const uint64_t& height) const { return 10000000000; }
+ virtual uint64_t get_block_long_term_weight(const uint64_t& height) const { return 128; }
virtual crypto::hash get_block_hash_from_height(const uint64_t& height) const { return crypto::hash(); }
virtual std::vector<cryptonote::block> get_blocks_range(const uint64_t& h1, const uint64_t& h2) const { return std::vector<cryptonote::block>(); }
virtual std::vector<crypto::hash> get_hashes_range(const uint64_t& h1, const uint64_t& h2) const { return std::vector<crypto::hash>(); }
- virtual crypto::hash top_block_hash() const { return crypto::hash(); }
+ virtual crypto::hash top_block_hash(uint64_t *block_height = NULL) const { if (block_height) *block_height = 0; return crypto::hash(); }
virtual cryptonote::block get_top_block() const { return cryptonote::block(); }
virtual uint64_t height() const { return 1; }
virtual bool tx_exists(const crypto::hash& h) const { return false; }
@@ -99,7 +102,7 @@ public:
virtual std::vector<std::vector<uint64_t>> get_tx_amount_output_indices(const uint64_t tx_index, size_t n_txes) const { return std::vector<std::vector<uint64_t>>(); }
virtual bool has_key_image(const crypto::key_image& img) const { return false; }
virtual void remove_block() { }
- virtual uint64_t add_transaction_data(const crypto::hash& blk_hash, const cryptonote::transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prunable_hash) {return 0;}
+ virtual uint64_t add_transaction_data(const crypto::hash& blk_hash, const std::pair<cryptonote::transaction, cryptonote::blobdata>& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prunable_hash) {return 0;}
virtual void remove_transaction_data(const crypto::hash& tx_hash, const cryptonote::transaction& tx) {}
virtual uint64_t add_output(const crypto::hash& tx_hash, const cryptonote::tx_out& tx_output, const uint64_t& local_index, const uint64_t unlock_time, const rct::key *commitment) {return 0;}
virtual void add_tx_amount_output_indices(const uint64_t tx_index, const std::vector<uint64_t>& amount_output_indices) {}
@@ -128,6 +131,7 @@ public:
virtual void add_block( const cryptonote::block& blk
, size_t block_weight
+ , uint64_t long_term_block_weight
, const cryptonote::difficulty_type& cumulative_difficulty
, const uint64_t& coins_generated
, uint64_t num_rct_outs
@@ -145,3 +149,4 @@ public:
virtual void prune_outputs(uint64_t amount) {}
};
+}
diff --git a/src/blockchain_utilities/CMakeLists.txt b/src/blockchain_utilities/CMakeLists.txt
index df74eb695..0ba7ee86c 100644
--- a/src/blockchain_utilities/CMakeLists.txt
+++ b/src/blockchain_utilities/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/src/blockchain_utilities/README.md b/src/blockchain_utilities/README.md
index 5d968cd75..ad5963f27 100644
--- a/src/blockchain_utilities/README.md
+++ b/src/blockchain_utilities/README.md
@@ -1,6 +1,6 @@
# Monero Blockchain Utilities
-Copyright (c) 2014-2018, The Monero Project
+Copyright (c) 2014-2019, The Monero Project
## Introduction
diff --git a/src/blockchain_utilities/blockchain_ancestry.cpp b/src/blockchain_utilities/blockchain_ancestry.cpp
index a64ce160a..a6ee0573f 100644
--- a/src/blockchain_utilities/blockchain_ancestry.cpp
+++ b/src/blockchain_utilities/blockchain_ancestry.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/blockchain_utilities/blockchain_blackball.cpp b/src/blockchain_utilities/blockchain_blackball.cpp
index 8b007e901..6ff184041 100644
--- a/src/blockchain_utilities/blockchain_blackball.cpp
+++ b/src/blockchain_utilities/blockchain_blackball.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/blockchain_utilities/blockchain_depth.cpp b/src/blockchain_utilities/blockchain_depth.cpp
index 8060b0de4..8be83ee67 100644
--- a/src/blockchain_utilities/blockchain_depth.cpp
+++ b/src/blockchain_utilities/blockchain_depth.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/blockchain_utilities/blockchain_export.cpp b/src/blockchain_utilities/blockchain_export.cpp
index 5c5bc7f69..fa1243c1f 100644
--- a/src/blockchain_utilities/blockchain_export.cpp
+++ b/src/blockchain_utilities/blockchain_export.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/blockchain_utilities/blockchain_import.cpp b/src/blockchain_utilities/blockchain_import.cpp
index 2a8a6f494..e4efdc3cb 100644
--- a/src/blockchain_utilities/blockchain_import.cpp
+++ b/src/blockchain_utilities/blockchain_import.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -193,8 +193,16 @@ int check_flush(cryptonote::core &core, std::vector<block_complete_entry> &block
}
core.prevalidate_block_hashes(core.get_blockchain_storage().get_db().height(), hashes);
- core.prepare_handle_incoming_blocks(blocks);
+ std::vector<block> pblocks;
+ core.prepare_handle_incoming_blocks(blocks, pblocks);
+ if (!pblocks.empty() && pblocks.size() != blocks.size())
+ {
+ MERROR("Unexpected parsed blocks size");
+ core.cleanup_handle_incoming_blocks();
+ return 1;
+ }
+ size_t blockidx = 0;
for(const block_complete_entry& block_entry: blocks)
{
// process transactions
@@ -215,7 +223,7 @@ int check_flush(cryptonote::core &core, std::vector<block_complete_entry> &block
block_verification_context bvc = boost::value_initialized<block_verification_context>();
- core.handle_incoming_block(block_entry.block, bvc, false); // <--- process block
+ core.handle_incoming_block(block_entry.block, pblocks.empty() ? NULL : &pblocks[blockidx++], bvc, false); // <--- process block
if(bvc.m_verifivation_failed)
{
@@ -455,7 +463,7 @@ int import_from_file(cryptonote::core& core, const std::string& import_file_path
}
else
{
- std::vector<transaction> txs;
+ std::vector<std::pair<transaction, blobdata>> txs;
std::vector<transaction> archived_txs;
archived_txs = bp.txs;
@@ -472,7 +480,7 @@ int import_from_file(cryptonote::core& core, const std::string& import_file_path
// because add_block() calls
// add_transaction(blk_hash, blk.miner_tx) first, and
// then a for loop for the transactions in txs.
- txs.push_back(tx);
+ txs.push_back(std::make_pair(tx, tx_to_blob(tx)));
}
size_t block_weight;
@@ -485,7 +493,8 @@ int import_from_file(cryptonote::core& core, const std::string& import_file_path
try
{
- core.get_blockchain_storage().get_db().add_block(b, block_weight, cumulative_difficulty, coins_generated, txs);
+ uint64_t long_term_block_weight = core.get_blockchain_storage().get_next_long_term_block_weight(block_weight);
+ core.get_blockchain_storage().get_db().add_block(std::make_pair(b, block_to_blob(b)), block_weight, long_term_block_weight, cumulative_difficulty, coins_generated, txs);
}
catch (const std::exception& e)
{
diff --git a/src/blockchain_utilities/blockchain_prune.cpp b/src/blockchain_utilities/blockchain_prune.cpp
index 8e13f2c04..36080aade 100644
--- a/src/blockchain_utilities/blockchain_prune.cpp
+++ b/src/blockchain_utilities/blockchain_prune.cpp
@@ -611,6 +611,24 @@ int main(int argc, char* argv[])
}
already_pruned = true;
}
+ if (n == 0)
+ {
+ const uint64_t blockchain_height = core_storage[0]->get_current_blockchain_height();
+ const crypto::hash hash = core_storage[0]->get_block_id_by_height(blockchain_height - 1);
+ cryptonote::block block;
+ if (core_storage[0]->get_block_by_hash(hash, block))
+ {
+ if (block.major_version < 10)
+ {
+ time_t now = time(NULL);
+ if (now < 1555286400) // 15 april 2019
+ {
+ MERROR("Pruning before v10 will confuse peers. Wait for v10 first");
+ return 1;
+ }
+ }
+ }
+ }
}
core_storage[0]->deinit();
core_storage[0].reset(NULL);
diff --git a/src/blockchain_utilities/blockchain_prune_known_spent_data.cpp b/src/blockchain_utilities/blockchain_prune_known_spent_data.cpp
index f6136c1ba..2d49b6ecd 100644
--- a/src/blockchain_utilities/blockchain_prune_known_spent_data.cpp
+++ b/src/blockchain_utilities/blockchain_prune_known_spent_data.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/blockchain_utilities/blockchain_stats.cpp b/src/blockchain_utilities/blockchain_stats.cpp
index aae8f333b..4cc84bf4a 100644
--- a/src/blockchain_utilities/blockchain_stats.cpp
+++ b/src/blockchain_utilities/blockchain_stats.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/blockchain_utilities/blockchain_usage.cpp b/src/blockchain_utilities/blockchain_usage.cpp
index 38a0b2648..bd73350b3 100644
--- a/src/blockchain_utilities/blockchain_usage.cpp
+++ b/src/blockchain_utilities/blockchain_usage.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/blockchain_utilities/blockchain_utilities.h b/src/blockchain_utilities/blockchain_utilities.h
index e690305c4..78487b995 100644
--- a/src/blockchain_utilities/blockchain_utilities.h
+++ b/src/blockchain_utilities/blockchain_utilities.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/blockchain_utilities/blocksdat_file.cpp b/src/blockchain_utilities/blocksdat_file.cpp
index 45ef33acb..f56ff5f94 100644
--- a/src/blockchain_utilities/blocksdat_file.cpp
+++ b/src/blockchain_utilities/blocksdat_file.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/blockchain_utilities/blocksdat_file.h b/src/blockchain_utilities/blocksdat_file.h
index 70a1f30a7..315713424 100644
--- a/src/blockchain_utilities/blocksdat_file.h
+++ b/src/blockchain_utilities/blocksdat_file.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/blockchain_utilities/bootstrap_file.cpp b/src/blockchain_utilities/bootstrap_file.cpp
index a8c46d661..fb9a24f5d 100644
--- a/src/blockchain_utilities/bootstrap_file.cpp
+++ b/src/blockchain_utilities/bootstrap_file.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/blockchain_utilities/bootstrap_file.h b/src/blockchain_utilities/bootstrap_file.h
index 187db0938..5fb2cf366 100644
--- a/src/blockchain_utilities/bootstrap_file.h
+++ b/src/blockchain_utilities/bootstrap_file.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/blockchain_utilities/bootstrap_serialization.h b/src/blockchain_utilities/bootstrap_serialization.h
index 278a7b40f..554c6d56e 100644
--- a/src/blockchain_utilities/bootstrap_serialization.h
+++ b/src/blockchain_utilities/bootstrap_serialization.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/blocks/CMakeLists.txt b/src/blocks/CMakeLists.txt
index ff48af6dc..0b7b02fee 100644
--- a/src/blocks/CMakeLists.txt
+++ b/src/blocks/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/src/blocks/checkpoints.dat b/src/blocks/checkpoints.dat
index 03e2cd2a8..adc433522 100644
--- a/src/blocks/checkpoints.dat
+++ b/src/blocks/checkpoints.dat
Binary files differ
diff --git a/src/checkpoints/CMakeLists.txt b/src/checkpoints/CMakeLists.txt
index 715006522..d324f518e 100644
--- a/src/checkpoints/CMakeLists.txt
+++ b/src/checkpoints/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/src/checkpoints/checkpoints.cpp b/src/checkpoints/checkpoints.cpp
index 96f575b2d..e31b96646 100644
--- a/src/checkpoints/checkpoints.cpp
+++ b/src/checkpoints/checkpoints.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -208,6 +208,7 @@ namespace cryptonote
ADD_CHECKPOINT(1530000, "01759bce497ec38e63c78b1038892169203bb78f87e488172f6b854fcd63ba7e");
ADD_CHECKPOINT(1579000, "7d0d7a2346373afd41ed1e744a939fc5d474a7dbaa257be5c6fff4009e789241");
ADD_CHECKPOINT(1668900, "ac2dcaf3d2f58ffcf8391639f0f1ebafcb8eac43c49479c7c37f611868d07568");
+ ADD_CHECKPOINT(1775600, "1c6e01c661dc22cab939e79ec6a5272190624ce8356d2f7b958e4f9a57fdb05e");
return true;
}
diff --git a/src/checkpoints/checkpoints.h b/src/checkpoints/checkpoints.h
index ad2b44d1a..a55b94bf0 100644
--- a/src/checkpoints/checkpoints.h
+++ b/src/checkpoints/checkpoints.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 212a1891e..f06737b31 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
@@ -45,6 +45,7 @@ set(common_sources
threadpool.cpp
updates.cpp
aligned.c
+ timings.cc
combinator.cpp)
if (STACK_TRACE)
@@ -84,6 +85,7 @@ set(common_private_headers
threadpool.h
updates.h
aligned.h
+ timings.h
combinator.h)
monero_private_headers(common
diff --git a/src/common/aligned.c b/src/common/aligned.c
index 763dfd0e7..6982409f7 100644
--- a/src/common/aligned.c
+++ b/src/common/aligned.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/apply_permutation.h b/src/common/apply_permutation.h
index ff346bab1..a4b2c8b78 100644
--- a/src/common/apply_permutation.h
+++ b/src/common/apply_permutation.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/base58.cpp b/src/common/base58.cpp
index 3562af486..ac1bf4b29 100644
--- a/src/common/base58.cpp
+++ b/src/common/base58.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/base58.h b/src/common/base58.h
index 69611859d..6bf2c3bb7 100644
--- a/src/common/base58.h
+++ b/src/common/base58.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/boost_serialization_helper.h b/src/common/boost_serialization_helper.h
index 3f5c623f8..2280f3312 100644
--- a/src/common/boost_serialization_helper.h
+++ b/src/common/boost_serialization_helper.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/command_line.cpp b/src/common/command_line.cpp
index 35135ea18..cae744ea5 100644
--- a/src/common/command_line.cpp
+++ b/src/common/command_line.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/command_line.h b/src/common/command_line.h
index 3a869bb26..b5e3d94a7 100644
--- a/src/common/command_line.h
+++ b/src/common/command_line.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/common_fwd.h b/src/common/common_fwd.h
index 2924d9cbe..7eaa6cdee 100644
--- a/src/common/common_fwd.h
+++ b/src/common/common_fwd.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/compat/glibc_compat.cpp b/src/common/compat/glibc_compat.cpp
index bf567987d..435e7930f 100644
--- a/src/common/compat/glibc_compat.cpp
+++ b/src/common/compat/glibc_compat.cpp
@@ -82,7 +82,7 @@ __explicit_bzero_chk (void *dst, size_t len, size_t dstlen)
#undef glob
extern "C" int glob_old(const char * pattern, int flags, int (*errfunc) (const char *epath, int eerrno), glob_t *pglob);
#ifdef __i386__
-__asm__(".symver glob_old,glob@GLIBC_2.1");
+__asm__(".symver glob_old,glob@GLIBC_2.0");
#elif defined(__amd64__)
__asm__(".symver glob_old,glob@GLIBC_2.2.5");
#elif defined(__arm__)
diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp
index 417b5b4ac..58227dfa7 100644
--- a/src/common/dns_utils.cpp
+++ b/src/common/dns_utils.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -514,12 +514,12 @@ bool load_txt_records_from_dns(std::vector<std::string> &good_records, const std
if (!avail[cur_index])
{
records[cur_index].clear();
- LOG_PRINT_L2("DNSSEC not available for checkpoint update at URL: " << url << ", skipping.");
+ LOG_PRINT_L2("DNSSEC not available for hostname: " << url << ", skipping.");
}
if (!valid[cur_index])
{
records[cur_index].clear();
- LOG_PRINT_L2("DNSSEC validation failed for checkpoint update at URL: " << url << ", skipping.");
+ LOG_PRINT_L2("DNSSEC validation failed for hostname: " << url << ", skipping.");
}
cur_index++;
@@ -541,7 +541,7 @@ bool load_txt_records_from_dns(std::vector<std::string> &good_records, const std
if (num_valid_records < 2)
{
- LOG_PRINT_L0("WARNING: no two valid MoneroPulse DNS checkpoint records were received");
+ LOG_PRINT_L0("WARNING: no two valid DNS TXT records were received");
return false;
}
@@ -563,7 +563,7 @@ bool load_txt_records_from_dns(std::vector<std::string> &good_records, const std
if (good_records_index < 0)
{
- LOG_PRINT_L0("WARNING: no two MoneroPulse DNS checkpoint records matched");
+ LOG_PRINT_L0("WARNING: no two DNS TXT records matched");
return false;
}
diff --git a/src/common/dns_utils.h b/src/common/dns_utils.h
index 3a6ef68a1..a6bc7463a 100644
--- a/src/common/dns_utils.h
+++ b/src/common/dns_utils.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/download.cpp b/src/common/download.cpp
index 58ce0595f..f07d6798d 100644
--- a/src/common/download.cpp
+++ b/src/common/download.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
@@ -179,8 +179,8 @@ namespace tools
lock.unlock();
- bool ssl = u_c.schema == "https";
- uint16_t port = u_c.port ? u_c.port : ssl ? 443 : 80;
+ epee::net_utils::ssl_support_t ssl = u_c.schema == "https" ? epee::net_utils::ssl_support_t::e_ssl_support_enabled : epee::net_utils::ssl_support_t::e_ssl_support_disabled;
+ uint16_t port = u_c.port ? u_c.port : ssl == epee::net_utils::ssl_support_t::e_ssl_support_enabled ? 443 : 80;
MDEBUG("Connecting to " << u_c.host << ":" << port);
client.set_server(u_c.host, std::to_string(port), boost::none, ssl);
if (!client.connect(std::chrono::seconds(30)))
diff --git a/src/common/download.h b/src/common/download.h
index 3097394bc..f8656a59c 100644
--- a/src/common/download.h
+++ b/src/common/download.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/http_connection.h b/src/common/http_connection.h
index 554dd832b..6b4294802 100644
--- a/src/common/http_connection.h
+++ b/src/common/http_connection.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/i18n.cpp b/src/common/i18n.cpp
index a32875945..9ac347263 100644
--- a/src/common/i18n.cpp
+++ b/src/common/i18n.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/i18n.h b/src/common/i18n.h
index d21d00275..82a07410d 100644
--- a/src/common/i18n.h
+++ b/src/common/i18n.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/json_util.h b/src/common/json_util.h
index c320c3956..96f4b90e6 100644
--- a/src/common/json_util.h
+++ b/src/common/json_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018, The Monero Project
+// Copyright (c) 2016-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/notify.cpp b/src/common/notify.cpp
index c3165fb05..e2df5096d 100644
--- a/src/common/notify.cpp
+++ b/src/common/notify.cpp
@@ -48,7 +48,7 @@ Notify::Notify(const char *spec)
{
CHECK_AND_ASSERT_THROW_MES(spec, "Null spec");
- boost::split(args, spec, boost::is_any_of(" "));
+ boost::split(args, spec, boost::is_any_of(" \t"), boost::token_compress_on);
CHECK_AND_ASSERT_THROW_MES(args.size() > 0, "Failed to parse spec");
if (strchr(spec, '\'') || strchr(spec, '\"') || strchr(spec, '\\'))
MWARNING("A notification spec contains a quote or backslash: note that these are handled verbatim, which may not be the intent");
diff --git a/src/common/password.cpp b/src/common/password.cpp
index 5f5cb800a..03d13db42 100644
--- a/src/common/password.cpp
+++ b/src/common/password.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/password.h b/src/common/password.h
index beb98283b..2837c70f3 100644
--- a/src/common/password.h
+++ b/src/common/password.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/perf_timer.cpp b/src/common/perf_timer.cpp
index 3e1357833..dda498088 100644
--- a/src/common/perf_timer.cpp
+++ b/src/common/perf_timer.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018, The Monero Project
+// Copyright (c) 2016-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/perf_timer.h b/src/common/perf_timer.h
index d859cf576..717391623 100644
--- a/src/common/perf_timer.h
+++ b/src/common/perf_timer.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018, The Monero Project
+// Copyright (c) 2016-2019, The Monero Project
//
// All rights reserved.
//
@@ -53,6 +53,7 @@ public:
void resume();
void reset();
uint64_t value() const;
+ operator uint64_t() const { return value(); }
protected:
uint64_t ticks;
diff --git a/src/common/pod-class.h b/src/common/pod-class.h
index 5f6709eef..200647590 100644
--- a/src/common/pod-class.h
+++ b/src/common/pod-class.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/rpc_client.h b/src/common/rpc_client.h
index 9665966ae..cb5f79da8 100644
--- a/src/common/rpc_client.h
+++ b/src/common/rpc_client.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/scoped_message_writer.h b/src/common/scoped_message_writer.h
index 42f439ad8..546377392 100644
--- a/src/common/scoped_message_writer.h
+++ b/src/common/scoped_message_writer.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/sfinae_helpers.h b/src/common/sfinae_helpers.h
index fa5052a2e..e9a98bb63 100644
--- a/src/common/sfinae_helpers.h
+++ b/src/common/sfinae_helpers.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018, The Monero Project
+// Copyright (c) 2016-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/stack_trace.cpp b/src/common/stack_trace.cpp
index 141621427..8d4f8c6f1 100644
--- a/src/common/stack_trace.cpp
+++ b/src/common/stack_trace.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018, The Monero Project
+// Copyright (c) 2016-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/stack_trace.h b/src/common/stack_trace.h
index 272fb89ae..ae6573885 100644
--- a/src/common/stack_trace.h
+++ b/src/common/stack_trace.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018, The Monero Project
+// Copyright (c) 2016-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/threadpool.cpp b/src/common/threadpool.cpp
index cbf7163c5..2748c798c 100644
--- a/src/common/threadpool.cpp
+++ b/src/common/threadpool.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/threadpool.h b/src/common/threadpool.h
index a43e38a76..5e490ee7d 100644
--- a/src/common/threadpool.h
+++ b/src/common/threadpool.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/timings.cc b/src/common/timings.cc
new file mode 100644
index 000000000..612ac2cc6
--- /dev/null
+++ b/src/common/timings.cc
@@ -0,0 +1,125 @@
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <algorithm>
+#include <boost/algorithm/string.hpp>
+#include "misc_log_ex.h"
+#include "timings.h"
+
+#define N_EXPECTED_FIELDS (8+11)
+
+TimingsDatabase::TimingsDatabase()
+{
+}
+
+TimingsDatabase::TimingsDatabase(const std::string &filename):
+ filename(filename)
+{
+ load();
+}
+
+TimingsDatabase::~TimingsDatabase()
+{
+ save();
+}
+
+bool TimingsDatabase::load()
+{
+ instances.clear();
+
+ if (filename.empty())
+ return true;
+
+ FILE *f = fopen(filename.c_str(), "r");
+ if (!f)
+ {
+ MDEBUG("Failed to load timings file " << filename << ": " << strerror(errno));
+ return false;
+ }
+ while (1)
+ {
+ char s[4096];
+ if (!fgets(s, sizeof(s), f))
+ break;
+ char *tab = strchr(s, '\t');
+ if (!tab)
+ {
+ MWARNING("Bad format: no tab found");
+ continue;
+ }
+ const std::string name = std::string(s, tab - s);
+ std::vector<std::string> fields;
+ char *ptr = tab + 1;
+ boost::split(fields, ptr, boost::is_any_of(" "));
+ if (fields.size() != N_EXPECTED_FIELDS)
+ {
+ MERROR("Bad format: wrong number of fields: got " << fields.size() << " expected " << N_EXPECTED_FIELDS);
+ continue;
+ }
+
+ instance i;
+
+ unsigned int idx = 0;
+ i.t = atoi(fields[idx++].c_str());
+ i.npoints = atoi(fields[idx++].c_str());
+ i.min = atof(fields[idx++].c_str());
+ i.max = atof(fields[idx++].c_str());
+ i.mean = atof(fields[idx++].c_str());
+ i.median = atof(fields[idx++].c_str());
+ i.stddev = atof(fields[idx++].c_str());
+ i.npskew = atof(fields[idx++].c_str());
+ i.deciles.reserve(11);
+ for (int n = 0; n < 11; ++n)
+ {
+ i.deciles.push_back(atoi(fields[idx++].c_str()));
+ }
+ instances.insert(std::make_pair(name, i));
+ }
+ fclose(f);
+ return true;
+}
+
+bool TimingsDatabase::save()
+{
+ if (filename.empty())
+ return true;
+
+ FILE *f = fopen(filename.c_str(), "w");
+ if (!f)
+ {
+ MERROR("Failed to write to file " << filename << ": " << strerror(errno));
+ return false;
+ }
+ for (const auto &i: instances)
+ {
+ 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);
+ fputc('\n', f);
+ }
+ fclose(f);
+ return true;
+}
+
+std::vector<TimingsDatabase::instance> TimingsDatabase::get(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;
+}
+
+void TimingsDatabase::add(const char *name, const instance &i)
+{
+ instances.insert(std::make_pair(name, i));
+}
diff --git a/src/common/timings.h b/src/common/timings.h
new file mode 100644
index 000000000..fb905611f
--- /dev/null
+++ b/src/common/timings.h
@@ -0,0 +1,34 @@
+#pragma once
+
+#include <stdint.h>
+#include <string>
+#include <vector>
+#include <map>
+
+class TimingsDatabase
+{
+public:
+ struct instance
+ {
+ time_t t;
+ size_t npoints;
+ double min, max, mean, median, stddev, npskew;
+ std::vector<uint64_t> deciles;
+ };
+
+public:
+ TimingsDatabase();
+ TimingsDatabase(const std::string &filename);
+ ~TimingsDatabase();
+
+ std::vector<instance> get(const char *name) const;
+ void add(const char *name, const instance &data);
+
+private:
+ bool load();
+ bool save();
+
+private:
+ std::string filename;
+ std::multimap<std::string, instance> instances;
+};
diff --git a/src/common/unordered_containers_boost_serialization.h b/src/common/unordered_containers_boost_serialization.h
index d78dc6a30..74e2c3f81 100644
--- a/src/common/unordered_containers_boost_serialization.h
+++ b/src/common/unordered_containers_boost_serialization.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/updates.cpp b/src/common/updates.cpp
index 9f12f8dbc..0bc6ff63c 100644
--- a/src/common/updates.cpp
+++ b/src/common/updates.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/updates.h b/src/common/updates.h
index 6ec22f183..8fda6d207 100644
--- a/src/common/updates.h
+++ b/src/common/updates.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/util.cpp b/src/common/util.cpp
index 28745eea4..80b8a9e81 100644
--- a/src/common/util.cpp
+++ b/src/common/util.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/util.h b/src/common/util.h
index d5aca15d1..ef2305bf4 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/common/varint.h b/src/common/varint.h
index 904255afc..a0d79be28 100644
--- a/src/common/varint.h
+++ b/src/common/varint.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/CMakeLists.txt b/src/crypto/CMakeLists.txt
index 0c635e7cb..84f002929 100644
--- a/src/crypto/CMakeLists.txt
+++ b/src/crypto/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
@@ -45,8 +45,13 @@ set(crypto_sources
random.c
skein.c
slow-hash.c
+ CryptonightR_JIT.c
tree-hash.c)
+if(ARCH_ID STREQUAL "i386" OR ARCH_ID STREQUAL "x86_64" OR ARCH_ID STREQUAL "x86-64")
+list(APPEND crypto_sources CryptonightR_template.S)
+endif()
+
set(crypto_headers)
set(crypto_private_headers
@@ -66,7 +71,9 @@ set(crypto_private_headers
oaes_lib.h
random.h
skein.h
- skein_port.h)
+ skein_port.h
+ CryptonightR_JIT.h
+ CryptonightR_template.h)
monero_private_headers(cncrypto
${crypto_private_headers})
@@ -101,4 +108,5 @@ if (ANDROID OR IOS)
endif()
endif()
-
+# cheat because cmake and ccache hate each other
+set_property(SOURCE CryptonightR_template.S PROPERTY LANGUAGE C)
diff --git a/src/crypto/CryptonightR_JIT.c b/src/crypto/CryptonightR_JIT.c
new file mode 100644
index 000000000..68258a959
--- /dev/null
+++ b/src/crypto/CryptonightR_JIT.c
@@ -0,0 +1,110 @@
+#include <assert.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <string.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "int-util.h"
+#include "hash-ops.h"
+#include "variant4_random_math.h"
+#include "CryptonightR_JIT.h"
+#include "CryptonightR_template.h"
+
+static const uint8_t prologue[] = {
+#if defined __i386 || defined __x86_64__
+ 0x4C, 0x8B, 0xD7, // mov r10, rdi
+ 0x53, // push rbx
+ 0x55, // push rbp
+ 0x41, 0x57, // push r15
+ 0x4C, 0x8B, 0xDC, // mov r11, rsp
+ 0x41, 0x8B, 0x1A, // mov ebx, DWORD PTR [r10]
+ 0x41, 0x8B, 0x72, 0x04, // mov esi, DWORD PTR [r10+4]
+ 0x41, 0x8B, 0x7A, 0x08, // mov edi, DWORD PTR [r10+8]
+ 0x41, 0x8B, 0x6A, 0x0C, // mov ebp, DWORD PTR [r10+12]
+ 0x41, 0x8B, 0x62, 0x10, // mov esp, DWORD PTR [r10+16]
+ 0x45, 0x8B, 0x7A, 0x14, // mov r15d, DWORD PTR [r10+20]
+ 0x41, 0x8B, 0x42, 0x18, // mov eax, DWORD PTR [r10+24]
+ 0x41, 0x8B, 0x52, 0x1C, // mov edx, DWORD PTR [r10+28]
+ 0x45, 0x8B, 0x4A, 0x20, // mov r9d, DWORD PTR [r10+32]
+#endif
+};
+
+static const uint8_t epilogue[] = {
+#if defined __i386 || defined __x86_64__
+ 0x49, 0x8B, 0xE3, // mov rsp, r11
+ 0x41, 0x89, 0x1A, // mov DWORD PTR [r10], ebx
+ 0x41, 0x89, 0x72, 0x04, // mov DWORD PTR [r10+4], esi
+ 0x41, 0x89, 0x7A, 0x08, // mov DWORD PTR [r10+8], edi
+ 0x41, 0x89, 0x6A, 0x0C, // mov DWORD PTR [r10+12], ebp
+ 0x41, 0x5F, // pop r15
+ 0x5D, // pop rbp
+ 0x5B, // pop rbx
+ 0xC3, // ret
+#endif
+};
+
+#define APPEND_CODE(src, size) \
+ do { \
+ if (JIT_code + (size) > JIT_code_end) \
+ return -1; \
+ memcpy(JIT_code, (src), (size)); \
+ JIT_code += (size); \
+ } while (0)
+
+int v4_generate_JIT_code(const struct V4_Instruction* code, v4_random_math_JIT_func buf, const size_t buf_size)
+{
+#if defined __i386 || defined __x86_64__
+ uint8_t* JIT_code = (uint8_t*) buf;
+ const uint8_t* JIT_code_end = JIT_code + buf_size;
+
+ APPEND_CODE(prologue, sizeof(prologue));
+
+ uint32_t prev_rot_src = 0xFFFFFFFFU;
+
+ for (int i = 0;; ++i)
+ {
+ const struct V4_Instruction inst = code[i];
+ if (inst.opcode == RET)
+ break;
+
+ const uint8_t opcode = (inst.opcode == MUL) ? inst.opcode : (inst.opcode + 2);
+
+ const uint32_t a = inst.dst_index;
+ const uint32_t b = inst.src_index;
+ const uint8_t c = opcode | (inst.dst_index << V4_OPCODE_BITS) | (((inst.src_index == 8) ? inst.dst_index : inst.src_index) << (V4_OPCODE_BITS + V4_DST_INDEX_BITS));
+
+ switch (inst.opcode)
+ {
+ case ROR:
+ case ROL:
+ if (b != prev_rot_src)
+ {
+ prev_rot_src = b;
+ const uint8_t* p1 = (const uint8_t*) instructions_mov[c];
+ const uint8_t* p2 = (const uint8_t*) instructions_mov[c + 1];
+ APPEND_CODE(p1, p2 - p1);
+ }
+ break;
+ }
+
+ if (a == prev_rot_src)
+ prev_rot_src = 0xFFFFFFFFU;
+
+ const uint8_t* p1 = (const uint8_t*) instructions[c];
+ const uint8_t* p2 = (const uint8_t*) instructions[c + 1];
+ APPEND_CODE(p1, p2 - p1);
+
+ if (inst.opcode == ADD)
+ *(uint32_t*)(JIT_code - 4) = inst.C;
+ }
+
+ APPEND_CODE(epilogue, sizeof(epilogue));
+
+ __builtin___clear_cache((char*)buf, (char*)JIT_code);
+
+ return 0;
+#else
+ return 1;
+#endif
+}
diff --git a/src/crypto/CryptonightR_JIT.h b/src/crypto/CryptonightR_JIT.h
new file mode 100644
index 000000000..cb32c3a79
--- /dev/null
+++ b/src/crypto/CryptonightR_JIT.h
@@ -0,0 +1,22 @@
+#ifndef CRYPTONIGHTR_JIT_H
+#define CRYPTONIGHTR_JIT_H
+
+// Minimalistic JIT code generator for random math sequence in CryptonightR
+//
+// Usage:
+// - Allocate writable and executable memory
+// - Call v4_generate_JIT_code with "buf" pointed to memory allocated on previous step
+// - Call the generated code instead of "v4_random_math(code, r)", omit the "code" parameter
+
+typedef void (*v4_random_math_JIT_func)(uint32_t* r)
+#if defined __i386 || defined __x86_64__
+__attribute__((sysv_abi))
+#endif
+;
+
+// Given the random math sequence, generates machine code (x86-64) for it
+// Returns 0 if code was generated successfully
+// Returns -1 if provided buffer was too small
+int v4_generate_JIT_code(const struct V4_Instruction* code, v4_random_math_JIT_func buf, const size_t buf_size);
+
+#endif // CRYPTONIGHTR_JIT_H
diff --git a/src/crypto/CryptonightR_template.S b/src/crypto/CryptonightR_template.S
new file mode 100644
index 000000000..068de22ec
--- /dev/null
+++ b/src/crypto/CryptonightR_template.S
@@ -0,0 +1,1590 @@
+#ifdef __APPLE__
+# define ALIGN(x) .align 6
+#else
+# define ALIGN(x) .align 64
+#endif
+.intel_syntax noprefix
+#ifdef __APPLE__
+# define FN_PREFIX(fn) _ ## fn
+.text
+#else
+# define FN_PREFIX(fn) fn
+.section .text
+#endif
+
+#define PUBLIC .global
+
+PUBLIC FN_PREFIX(CryptonightR_instruction0)
+PUBLIC FN_PREFIX(CryptonightR_instruction1)
+PUBLIC FN_PREFIX(CryptonightR_instruction2)
+PUBLIC FN_PREFIX(CryptonightR_instruction3)
+PUBLIC FN_PREFIX(CryptonightR_instruction4)
+PUBLIC FN_PREFIX(CryptonightR_instruction5)
+PUBLIC FN_PREFIX(CryptonightR_instruction6)
+PUBLIC FN_PREFIX(CryptonightR_instruction7)
+PUBLIC FN_PREFIX(CryptonightR_instruction8)
+PUBLIC FN_PREFIX(CryptonightR_instruction9)
+PUBLIC FN_PREFIX(CryptonightR_instruction10)
+PUBLIC FN_PREFIX(CryptonightR_instruction11)
+PUBLIC FN_PREFIX(CryptonightR_instruction12)
+PUBLIC FN_PREFIX(CryptonightR_instruction13)
+PUBLIC FN_PREFIX(CryptonightR_instruction14)
+PUBLIC FN_PREFIX(CryptonightR_instruction15)
+PUBLIC FN_PREFIX(CryptonightR_instruction16)
+PUBLIC FN_PREFIX(CryptonightR_instruction17)
+PUBLIC FN_PREFIX(CryptonightR_instruction18)
+PUBLIC FN_PREFIX(CryptonightR_instruction19)
+PUBLIC FN_PREFIX(CryptonightR_instruction20)
+PUBLIC FN_PREFIX(CryptonightR_instruction21)
+PUBLIC FN_PREFIX(CryptonightR_instruction22)
+PUBLIC FN_PREFIX(CryptonightR_instruction23)
+PUBLIC FN_PREFIX(CryptonightR_instruction24)
+PUBLIC FN_PREFIX(CryptonightR_instruction25)
+PUBLIC FN_PREFIX(CryptonightR_instruction26)
+PUBLIC FN_PREFIX(CryptonightR_instruction27)
+PUBLIC FN_PREFIX(CryptonightR_instruction28)
+PUBLIC FN_PREFIX(CryptonightR_instruction29)
+PUBLIC FN_PREFIX(CryptonightR_instruction30)
+PUBLIC FN_PREFIX(CryptonightR_instruction31)
+PUBLIC FN_PREFIX(CryptonightR_instruction32)
+PUBLIC FN_PREFIX(CryptonightR_instruction33)
+PUBLIC FN_PREFIX(CryptonightR_instruction34)
+PUBLIC FN_PREFIX(CryptonightR_instruction35)
+PUBLIC FN_PREFIX(CryptonightR_instruction36)
+PUBLIC FN_PREFIX(CryptonightR_instruction37)
+PUBLIC FN_PREFIX(CryptonightR_instruction38)
+PUBLIC FN_PREFIX(CryptonightR_instruction39)
+PUBLIC FN_PREFIX(CryptonightR_instruction40)
+PUBLIC FN_PREFIX(CryptonightR_instruction41)
+PUBLIC FN_PREFIX(CryptonightR_instruction42)
+PUBLIC FN_PREFIX(CryptonightR_instruction43)
+PUBLIC FN_PREFIX(CryptonightR_instruction44)
+PUBLIC FN_PREFIX(CryptonightR_instruction45)
+PUBLIC FN_PREFIX(CryptonightR_instruction46)
+PUBLIC FN_PREFIX(CryptonightR_instruction47)
+PUBLIC FN_PREFIX(CryptonightR_instruction48)
+PUBLIC FN_PREFIX(CryptonightR_instruction49)
+PUBLIC FN_PREFIX(CryptonightR_instruction50)
+PUBLIC FN_PREFIX(CryptonightR_instruction51)
+PUBLIC FN_PREFIX(CryptonightR_instruction52)
+PUBLIC FN_PREFIX(CryptonightR_instruction53)
+PUBLIC FN_PREFIX(CryptonightR_instruction54)
+PUBLIC FN_PREFIX(CryptonightR_instruction55)
+PUBLIC FN_PREFIX(CryptonightR_instruction56)
+PUBLIC FN_PREFIX(CryptonightR_instruction57)
+PUBLIC FN_PREFIX(CryptonightR_instruction58)
+PUBLIC FN_PREFIX(CryptonightR_instruction59)
+PUBLIC FN_PREFIX(CryptonightR_instruction60)
+PUBLIC FN_PREFIX(CryptonightR_instruction61)
+PUBLIC FN_PREFIX(CryptonightR_instruction62)
+PUBLIC FN_PREFIX(CryptonightR_instruction63)
+PUBLIC FN_PREFIX(CryptonightR_instruction64)
+PUBLIC FN_PREFIX(CryptonightR_instruction65)
+PUBLIC FN_PREFIX(CryptonightR_instruction66)
+PUBLIC FN_PREFIX(CryptonightR_instruction67)
+PUBLIC FN_PREFIX(CryptonightR_instruction68)
+PUBLIC FN_PREFIX(CryptonightR_instruction69)
+PUBLIC FN_PREFIX(CryptonightR_instruction70)
+PUBLIC FN_PREFIX(CryptonightR_instruction71)
+PUBLIC FN_PREFIX(CryptonightR_instruction72)
+PUBLIC FN_PREFIX(CryptonightR_instruction73)
+PUBLIC FN_PREFIX(CryptonightR_instruction74)
+PUBLIC FN_PREFIX(CryptonightR_instruction75)
+PUBLIC FN_PREFIX(CryptonightR_instruction76)
+PUBLIC FN_PREFIX(CryptonightR_instruction77)
+PUBLIC FN_PREFIX(CryptonightR_instruction78)
+PUBLIC FN_PREFIX(CryptonightR_instruction79)
+PUBLIC FN_PREFIX(CryptonightR_instruction80)
+PUBLIC FN_PREFIX(CryptonightR_instruction81)
+PUBLIC FN_PREFIX(CryptonightR_instruction82)
+PUBLIC FN_PREFIX(CryptonightR_instruction83)
+PUBLIC FN_PREFIX(CryptonightR_instruction84)
+PUBLIC FN_PREFIX(CryptonightR_instruction85)
+PUBLIC FN_PREFIX(CryptonightR_instruction86)
+PUBLIC FN_PREFIX(CryptonightR_instruction87)
+PUBLIC FN_PREFIX(CryptonightR_instruction88)
+PUBLIC FN_PREFIX(CryptonightR_instruction89)
+PUBLIC FN_PREFIX(CryptonightR_instruction90)
+PUBLIC FN_PREFIX(CryptonightR_instruction91)
+PUBLIC FN_PREFIX(CryptonightR_instruction92)
+PUBLIC FN_PREFIX(CryptonightR_instruction93)
+PUBLIC FN_PREFIX(CryptonightR_instruction94)
+PUBLIC FN_PREFIX(CryptonightR_instruction95)
+PUBLIC FN_PREFIX(CryptonightR_instruction96)
+PUBLIC FN_PREFIX(CryptonightR_instruction97)
+PUBLIC FN_PREFIX(CryptonightR_instruction98)
+PUBLIC FN_PREFIX(CryptonightR_instruction99)
+PUBLIC FN_PREFIX(CryptonightR_instruction100)
+PUBLIC FN_PREFIX(CryptonightR_instruction101)
+PUBLIC FN_PREFIX(CryptonightR_instruction102)
+PUBLIC FN_PREFIX(CryptonightR_instruction103)
+PUBLIC FN_PREFIX(CryptonightR_instruction104)
+PUBLIC FN_PREFIX(CryptonightR_instruction105)
+PUBLIC FN_PREFIX(CryptonightR_instruction106)
+PUBLIC FN_PREFIX(CryptonightR_instruction107)
+PUBLIC FN_PREFIX(CryptonightR_instruction108)
+PUBLIC FN_PREFIX(CryptonightR_instruction109)
+PUBLIC FN_PREFIX(CryptonightR_instruction110)
+PUBLIC FN_PREFIX(CryptonightR_instruction111)
+PUBLIC FN_PREFIX(CryptonightR_instruction112)
+PUBLIC FN_PREFIX(CryptonightR_instruction113)
+PUBLIC FN_PREFIX(CryptonightR_instruction114)
+PUBLIC FN_PREFIX(CryptonightR_instruction115)
+PUBLIC FN_PREFIX(CryptonightR_instruction116)
+PUBLIC FN_PREFIX(CryptonightR_instruction117)
+PUBLIC FN_PREFIX(CryptonightR_instruction118)
+PUBLIC FN_PREFIX(CryptonightR_instruction119)
+PUBLIC FN_PREFIX(CryptonightR_instruction120)
+PUBLIC FN_PREFIX(CryptonightR_instruction121)
+PUBLIC FN_PREFIX(CryptonightR_instruction122)
+PUBLIC FN_PREFIX(CryptonightR_instruction123)
+PUBLIC FN_PREFIX(CryptonightR_instruction124)
+PUBLIC FN_PREFIX(CryptonightR_instruction125)
+PUBLIC FN_PREFIX(CryptonightR_instruction126)
+PUBLIC FN_PREFIX(CryptonightR_instruction127)
+PUBLIC FN_PREFIX(CryptonightR_instruction128)
+PUBLIC FN_PREFIX(CryptonightR_instruction129)
+PUBLIC FN_PREFIX(CryptonightR_instruction130)
+PUBLIC FN_PREFIX(CryptonightR_instruction131)
+PUBLIC FN_PREFIX(CryptonightR_instruction132)
+PUBLIC FN_PREFIX(CryptonightR_instruction133)
+PUBLIC FN_PREFIX(CryptonightR_instruction134)
+PUBLIC FN_PREFIX(CryptonightR_instruction135)
+PUBLIC FN_PREFIX(CryptonightR_instruction136)
+PUBLIC FN_PREFIX(CryptonightR_instruction137)
+PUBLIC FN_PREFIX(CryptonightR_instruction138)
+PUBLIC FN_PREFIX(CryptonightR_instruction139)
+PUBLIC FN_PREFIX(CryptonightR_instruction140)
+PUBLIC FN_PREFIX(CryptonightR_instruction141)
+PUBLIC FN_PREFIX(CryptonightR_instruction142)
+PUBLIC FN_PREFIX(CryptonightR_instruction143)
+PUBLIC FN_PREFIX(CryptonightR_instruction144)
+PUBLIC FN_PREFIX(CryptonightR_instruction145)
+PUBLIC FN_PREFIX(CryptonightR_instruction146)
+PUBLIC FN_PREFIX(CryptonightR_instruction147)
+PUBLIC FN_PREFIX(CryptonightR_instruction148)
+PUBLIC FN_PREFIX(CryptonightR_instruction149)
+PUBLIC FN_PREFIX(CryptonightR_instruction150)
+PUBLIC FN_PREFIX(CryptonightR_instruction151)
+PUBLIC FN_PREFIX(CryptonightR_instruction152)
+PUBLIC FN_PREFIX(CryptonightR_instruction153)
+PUBLIC FN_PREFIX(CryptonightR_instruction154)
+PUBLIC FN_PREFIX(CryptonightR_instruction155)
+PUBLIC FN_PREFIX(CryptonightR_instruction156)
+PUBLIC FN_PREFIX(CryptonightR_instruction157)
+PUBLIC FN_PREFIX(CryptonightR_instruction158)
+PUBLIC FN_PREFIX(CryptonightR_instruction159)
+PUBLIC FN_PREFIX(CryptonightR_instruction160)
+PUBLIC FN_PREFIX(CryptonightR_instruction161)
+PUBLIC FN_PREFIX(CryptonightR_instruction162)
+PUBLIC FN_PREFIX(CryptonightR_instruction163)
+PUBLIC FN_PREFIX(CryptonightR_instruction164)
+PUBLIC FN_PREFIX(CryptonightR_instruction165)
+PUBLIC FN_PREFIX(CryptonightR_instruction166)
+PUBLIC FN_PREFIX(CryptonightR_instruction167)
+PUBLIC FN_PREFIX(CryptonightR_instruction168)
+PUBLIC FN_PREFIX(CryptonightR_instruction169)
+PUBLIC FN_PREFIX(CryptonightR_instruction170)
+PUBLIC FN_PREFIX(CryptonightR_instruction171)
+PUBLIC FN_PREFIX(CryptonightR_instruction172)
+PUBLIC FN_PREFIX(CryptonightR_instruction173)
+PUBLIC FN_PREFIX(CryptonightR_instruction174)
+PUBLIC FN_PREFIX(CryptonightR_instruction175)
+PUBLIC FN_PREFIX(CryptonightR_instruction176)
+PUBLIC FN_PREFIX(CryptonightR_instruction177)
+PUBLIC FN_PREFIX(CryptonightR_instruction178)
+PUBLIC FN_PREFIX(CryptonightR_instruction179)
+PUBLIC FN_PREFIX(CryptonightR_instruction180)
+PUBLIC FN_PREFIX(CryptonightR_instruction181)
+PUBLIC FN_PREFIX(CryptonightR_instruction182)
+PUBLIC FN_PREFIX(CryptonightR_instruction183)
+PUBLIC FN_PREFIX(CryptonightR_instruction184)
+PUBLIC FN_PREFIX(CryptonightR_instruction185)
+PUBLIC FN_PREFIX(CryptonightR_instruction186)
+PUBLIC FN_PREFIX(CryptonightR_instruction187)
+PUBLIC FN_PREFIX(CryptonightR_instruction188)
+PUBLIC FN_PREFIX(CryptonightR_instruction189)
+PUBLIC FN_PREFIX(CryptonightR_instruction190)
+PUBLIC FN_PREFIX(CryptonightR_instruction191)
+PUBLIC FN_PREFIX(CryptonightR_instruction192)
+PUBLIC FN_PREFIX(CryptonightR_instruction193)
+PUBLIC FN_PREFIX(CryptonightR_instruction194)
+PUBLIC FN_PREFIX(CryptonightR_instruction195)
+PUBLIC FN_PREFIX(CryptonightR_instruction196)
+PUBLIC FN_PREFIX(CryptonightR_instruction197)
+PUBLIC FN_PREFIX(CryptonightR_instruction198)
+PUBLIC FN_PREFIX(CryptonightR_instruction199)
+PUBLIC FN_PREFIX(CryptonightR_instruction200)
+PUBLIC FN_PREFIX(CryptonightR_instruction201)
+PUBLIC FN_PREFIX(CryptonightR_instruction202)
+PUBLIC FN_PREFIX(CryptonightR_instruction203)
+PUBLIC FN_PREFIX(CryptonightR_instruction204)
+PUBLIC FN_PREFIX(CryptonightR_instruction205)
+PUBLIC FN_PREFIX(CryptonightR_instruction206)
+PUBLIC FN_PREFIX(CryptonightR_instruction207)
+PUBLIC FN_PREFIX(CryptonightR_instruction208)
+PUBLIC FN_PREFIX(CryptonightR_instruction209)
+PUBLIC FN_PREFIX(CryptonightR_instruction210)
+PUBLIC FN_PREFIX(CryptonightR_instruction211)
+PUBLIC FN_PREFIX(CryptonightR_instruction212)
+PUBLIC FN_PREFIX(CryptonightR_instruction213)
+PUBLIC FN_PREFIX(CryptonightR_instruction214)
+PUBLIC FN_PREFIX(CryptonightR_instruction215)
+PUBLIC FN_PREFIX(CryptonightR_instruction216)
+PUBLIC FN_PREFIX(CryptonightR_instruction217)
+PUBLIC FN_PREFIX(CryptonightR_instruction218)
+PUBLIC FN_PREFIX(CryptonightR_instruction219)
+PUBLIC FN_PREFIX(CryptonightR_instruction220)
+PUBLIC FN_PREFIX(CryptonightR_instruction221)
+PUBLIC FN_PREFIX(CryptonightR_instruction222)
+PUBLIC FN_PREFIX(CryptonightR_instruction223)
+PUBLIC FN_PREFIX(CryptonightR_instruction224)
+PUBLIC FN_PREFIX(CryptonightR_instruction225)
+PUBLIC FN_PREFIX(CryptonightR_instruction226)
+PUBLIC FN_PREFIX(CryptonightR_instruction227)
+PUBLIC FN_PREFIX(CryptonightR_instruction228)
+PUBLIC FN_PREFIX(CryptonightR_instruction229)
+PUBLIC FN_PREFIX(CryptonightR_instruction230)
+PUBLIC FN_PREFIX(CryptonightR_instruction231)
+PUBLIC FN_PREFIX(CryptonightR_instruction232)
+PUBLIC FN_PREFIX(CryptonightR_instruction233)
+PUBLIC FN_PREFIX(CryptonightR_instruction234)
+PUBLIC FN_PREFIX(CryptonightR_instruction235)
+PUBLIC FN_PREFIX(CryptonightR_instruction236)
+PUBLIC FN_PREFIX(CryptonightR_instruction237)
+PUBLIC FN_PREFIX(CryptonightR_instruction238)
+PUBLIC FN_PREFIX(CryptonightR_instruction239)
+PUBLIC FN_PREFIX(CryptonightR_instruction240)
+PUBLIC FN_PREFIX(CryptonightR_instruction241)
+PUBLIC FN_PREFIX(CryptonightR_instruction242)
+PUBLIC FN_PREFIX(CryptonightR_instruction243)
+PUBLIC FN_PREFIX(CryptonightR_instruction244)
+PUBLIC FN_PREFIX(CryptonightR_instruction245)
+PUBLIC FN_PREFIX(CryptonightR_instruction246)
+PUBLIC FN_PREFIX(CryptonightR_instruction247)
+PUBLIC FN_PREFIX(CryptonightR_instruction248)
+PUBLIC FN_PREFIX(CryptonightR_instruction249)
+PUBLIC FN_PREFIX(CryptonightR_instruction250)
+PUBLIC FN_PREFIX(CryptonightR_instruction251)
+PUBLIC FN_PREFIX(CryptonightR_instruction252)
+PUBLIC FN_PREFIX(CryptonightR_instruction253)
+PUBLIC FN_PREFIX(CryptonightR_instruction254)
+PUBLIC FN_PREFIX(CryptonightR_instruction255)
+PUBLIC FN_PREFIX(CryptonightR_instruction256)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov0)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov1)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov2)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov3)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov4)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov5)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov6)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov7)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov8)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov9)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov10)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov11)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov12)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov13)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov14)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov15)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov16)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov17)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov18)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov19)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov20)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov21)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov22)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov23)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov24)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov25)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov26)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov27)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov28)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov29)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov30)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov31)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov32)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov33)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov34)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov35)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov36)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov37)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov38)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov39)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov40)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov41)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov42)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov43)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov44)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov45)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov46)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov47)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov48)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov49)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov50)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov51)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov52)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov53)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov54)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov55)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov56)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov57)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov58)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov59)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov60)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov61)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov62)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov63)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov64)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov65)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov66)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov67)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov68)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov69)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov70)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov71)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov72)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov73)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov74)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov75)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov76)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov77)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov78)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov79)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov80)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov81)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov82)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov83)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov84)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov85)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov86)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov87)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov88)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov89)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov90)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov91)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov92)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov93)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov94)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov95)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov96)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov97)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov98)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov99)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov100)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov101)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov102)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov103)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov104)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov105)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov106)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov107)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov108)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov109)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov110)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov111)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov112)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov113)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov114)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov115)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov116)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov117)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov118)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov119)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov120)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov121)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov122)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov123)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov124)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov125)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov126)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov127)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov128)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov129)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov130)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov131)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov132)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov133)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov134)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov135)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov136)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov137)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov138)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov139)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov140)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov141)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov142)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov143)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov144)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov145)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov146)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov147)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov148)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov149)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov150)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov151)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov152)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov153)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov154)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov155)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov156)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov157)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov158)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov159)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov160)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov161)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov162)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov163)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov164)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov165)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov166)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov167)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov168)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov169)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov170)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov171)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov172)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov173)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov174)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov175)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov176)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov177)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov178)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov179)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov180)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov181)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov182)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov183)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov184)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov185)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov186)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov187)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov188)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov189)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov190)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov191)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov192)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov193)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov194)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov195)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov196)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov197)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov198)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov199)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov200)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov201)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov202)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov203)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov204)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov205)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov206)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov207)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov208)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov209)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov210)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov211)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov212)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov213)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov214)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov215)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov216)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov217)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov218)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov219)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov220)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov221)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov222)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov223)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov224)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov225)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov226)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov227)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov228)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov229)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov230)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov231)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov232)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov233)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov234)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov235)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov236)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov237)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov238)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov239)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov240)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov241)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov242)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov243)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov244)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov245)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov246)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov247)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov248)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov249)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov250)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov251)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov252)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov253)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov254)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov255)
+PUBLIC FN_PREFIX(CryptonightR_instruction_mov256)
+
+FN_PREFIX(CryptonightR_instruction0):
+ imul ebx, ebx
+FN_PREFIX(CryptonightR_instruction1):
+ imul ebx, ebx
+FN_PREFIX(CryptonightR_instruction2):
+ imul ebx, ebx
+FN_PREFIX(CryptonightR_instruction3):
+ add ebx, r9d
+ add ebx, 2147483647
+FN_PREFIX(CryptonightR_instruction4):
+ sub ebx, r9d
+FN_PREFIX(CryptonightR_instruction5):
+ ror ebx, cl
+FN_PREFIX(CryptonightR_instruction6):
+ rol ebx, cl
+FN_PREFIX(CryptonightR_instruction7):
+ xor ebx, r9d
+FN_PREFIX(CryptonightR_instruction8):
+ imul esi, ebx
+FN_PREFIX(CryptonightR_instruction9):
+ imul esi, ebx
+FN_PREFIX(CryptonightR_instruction10):
+ imul esi, ebx
+FN_PREFIX(CryptonightR_instruction11):
+ add esi, ebx
+ add esi, 2147483647
+FN_PREFIX(CryptonightR_instruction12):
+ sub esi, ebx
+FN_PREFIX(CryptonightR_instruction13):
+ ror esi, cl
+FN_PREFIX(CryptonightR_instruction14):
+ rol esi, cl
+FN_PREFIX(CryptonightR_instruction15):
+ xor esi, ebx
+FN_PREFIX(CryptonightR_instruction16):
+ imul edi, ebx
+FN_PREFIX(CryptonightR_instruction17):
+ imul edi, ebx
+FN_PREFIX(CryptonightR_instruction18):
+ imul edi, ebx
+FN_PREFIX(CryptonightR_instruction19):
+ add edi, ebx
+ add edi, 2147483647
+FN_PREFIX(CryptonightR_instruction20):
+ sub edi, ebx
+FN_PREFIX(CryptonightR_instruction21):
+ ror edi, cl
+FN_PREFIX(CryptonightR_instruction22):
+ rol edi, cl
+FN_PREFIX(CryptonightR_instruction23):
+ xor edi, ebx
+FN_PREFIX(CryptonightR_instruction24):
+ imul ebp, ebx
+FN_PREFIX(CryptonightR_instruction25):
+ imul ebp, ebx
+FN_PREFIX(CryptonightR_instruction26):
+ imul ebp, ebx
+FN_PREFIX(CryptonightR_instruction27):
+ add ebp, ebx
+ add ebp, 2147483647
+FN_PREFIX(CryptonightR_instruction28):
+ sub ebp, ebx
+FN_PREFIX(CryptonightR_instruction29):
+ ror ebp, cl
+FN_PREFIX(CryptonightR_instruction30):
+ rol ebp, cl
+FN_PREFIX(CryptonightR_instruction31):
+ xor ebp, ebx
+FN_PREFIX(CryptonightR_instruction32):
+ imul ebx, esi
+FN_PREFIX(CryptonightR_instruction33):
+ imul ebx, esi
+FN_PREFIX(CryptonightR_instruction34):
+ imul ebx, esi
+FN_PREFIX(CryptonightR_instruction35):
+ add ebx, esi
+ add ebx, 2147483647
+FN_PREFIX(CryptonightR_instruction36):
+ sub ebx, esi
+FN_PREFIX(CryptonightR_instruction37):
+ ror ebx, cl
+FN_PREFIX(CryptonightR_instruction38):
+ rol ebx, cl
+FN_PREFIX(CryptonightR_instruction39):
+ xor ebx, esi
+FN_PREFIX(CryptonightR_instruction40):
+ imul esi, esi
+FN_PREFIX(CryptonightR_instruction41):
+ imul esi, esi
+FN_PREFIX(CryptonightR_instruction42):
+ imul esi, esi
+FN_PREFIX(CryptonightR_instruction43):
+ add esi, r9d
+ add esi, 2147483647
+FN_PREFIX(CryptonightR_instruction44):
+ sub esi, r9d
+FN_PREFIX(CryptonightR_instruction45):
+ ror esi, cl
+FN_PREFIX(CryptonightR_instruction46):
+ rol esi, cl
+FN_PREFIX(CryptonightR_instruction47):
+ xor esi, r9d
+FN_PREFIX(CryptonightR_instruction48):
+ imul edi, esi
+FN_PREFIX(CryptonightR_instruction49):
+ imul edi, esi
+FN_PREFIX(CryptonightR_instruction50):
+ imul edi, esi
+FN_PREFIX(CryptonightR_instruction51):
+ add edi, esi
+ add edi, 2147483647
+FN_PREFIX(CryptonightR_instruction52):
+ sub edi, esi
+FN_PREFIX(CryptonightR_instruction53):
+ ror edi, cl
+FN_PREFIX(CryptonightR_instruction54):
+ rol edi, cl
+FN_PREFIX(CryptonightR_instruction55):
+ xor edi, esi
+FN_PREFIX(CryptonightR_instruction56):
+ imul ebp, esi
+FN_PREFIX(CryptonightR_instruction57):
+ imul ebp, esi
+FN_PREFIX(CryptonightR_instruction58):
+ imul ebp, esi
+FN_PREFIX(CryptonightR_instruction59):
+ add ebp, esi
+ add ebp, 2147483647
+FN_PREFIX(CryptonightR_instruction60):
+ sub ebp, esi
+FN_PREFIX(CryptonightR_instruction61):
+ ror ebp, cl
+FN_PREFIX(CryptonightR_instruction62):
+ rol ebp, cl
+FN_PREFIX(CryptonightR_instruction63):
+ xor ebp, esi
+FN_PREFIX(CryptonightR_instruction64):
+ imul ebx, edi
+FN_PREFIX(CryptonightR_instruction65):
+ imul ebx, edi
+FN_PREFIX(CryptonightR_instruction66):
+ imul ebx, edi
+FN_PREFIX(CryptonightR_instruction67):
+ add ebx, edi
+ add ebx, 2147483647
+FN_PREFIX(CryptonightR_instruction68):
+ sub ebx, edi
+FN_PREFIX(CryptonightR_instruction69):
+ ror ebx, cl
+FN_PREFIX(CryptonightR_instruction70):
+ rol ebx, cl
+FN_PREFIX(CryptonightR_instruction71):
+ xor ebx, edi
+FN_PREFIX(CryptonightR_instruction72):
+ imul esi, edi
+FN_PREFIX(CryptonightR_instruction73):
+ imul esi, edi
+FN_PREFIX(CryptonightR_instruction74):
+ imul esi, edi
+FN_PREFIX(CryptonightR_instruction75):
+ add esi, edi
+ add esi, 2147483647
+FN_PREFIX(CryptonightR_instruction76):
+ sub esi, edi
+FN_PREFIX(CryptonightR_instruction77):
+ ror esi, cl
+FN_PREFIX(CryptonightR_instruction78):
+ rol esi, cl
+FN_PREFIX(CryptonightR_instruction79):
+ xor esi, edi
+FN_PREFIX(CryptonightR_instruction80):
+ imul edi, edi
+FN_PREFIX(CryptonightR_instruction81):
+ imul edi, edi
+FN_PREFIX(CryptonightR_instruction82):
+ imul edi, edi
+FN_PREFIX(CryptonightR_instruction83):
+ add edi, r9d
+ add edi, 2147483647
+FN_PREFIX(CryptonightR_instruction84):
+ sub edi, r9d
+FN_PREFIX(CryptonightR_instruction85):
+ ror edi, cl
+FN_PREFIX(CryptonightR_instruction86):
+ rol edi, cl
+FN_PREFIX(CryptonightR_instruction87):
+ xor edi, r9d
+FN_PREFIX(CryptonightR_instruction88):
+ imul ebp, edi
+FN_PREFIX(CryptonightR_instruction89):
+ imul ebp, edi
+FN_PREFIX(CryptonightR_instruction90):
+ imul ebp, edi
+FN_PREFIX(CryptonightR_instruction91):
+ add ebp, edi
+ add ebp, 2147483647
+FN_PREFIX(CryptonightR_instruction92):
+ sub ebp, edi
+FN_PREFIX(CryptonightR_instruction93):
+ ror ebp, cl
+FN_PREFIX(CryptonightR_instruction94):
+ rol ebp, cl
+FN_PREFIX(CryptonightR_instruction95):
+ xor ebp, edi
+FN_PREFIX(CryptonightR_instruction96):
+ imul ebx, ebp
+FN_PREFIX(CryptonightR_instruction97):
+ imul ebx, ebp
+FN_PREFIX(CryptonightR_instruction98):
+ imul ebx, ebp
+FN_PREFIX(CryptonightR_instruction99):
+ add ebx, ebp
+ add ebx, 2147483647
+FN_PREFIX(CryptonightR_instruction100):
+ sub ebx, ebp
+FN_PREFIX(CryptonightR_instruction101):
+ ror ebx, cl
+FN_PREFIX(CryptonightR_instruction102):
+ rol ebx, cl
+FN_PREFIX(CryptonightR_instruction103):
+ xor ebx, ebp
+FN_PREFIX(CryptonightR_instruction104):
+ imul esi, ebp
+FN_PREFIX(CryptonightR_instruction105):
+ imul esi, ebp
+FN_PREFIX(CryptonightR_instruction106):
+ imul esi, ebp
+FN_PREFIX(CryptonightR_instruction107):
+ add esi, ebp
+ add esi, 2147483647
+FN_PREFIX(CryptonightR_instruction108):
+ sub esi, ebp
+FN_PREFIX(CryptonightR_instruction109):
+ ror esi, cl
+FN_PREFIX(CryptonightR_instruction110):
+ rol esi, cl
+FN_PREFIX(CryptonightR_instruction111):
+ xor esi, ebp
+FN_PREFIX(CryptonightR_instruction112):
+ imul edi, ebp
+FN_PREFIX(CryptonightR_instruction113):
+ imul edi, ebp
+FN_PREFIX(CryptonightR_instruction114):
+ imul edi, ebp
+FN_PREFIX(CryptonightR_instruction115):
+ add edi, ebp
+ add edi, 2147483647
+FN_PREFIX(CryptonightR_instruction116):
+ sub edi, ebp
+FN_PREFIX(CryptonightR_instruction117):
+ ror edi, cl
+FN_PREFIX(CryptonightR_instruction118):
+ rol edi, cl
+FN_PREFIX(CryptonightR_instruction119):
+ xor edi, ebp
+FN_PREFIX(CryptonightR_instruction120):
+ imul ebp, ebp
+FN_PREFIX(CryptonightR_instruction121):
+ imul ebp, ebp
+FN_PREFIX(CryptonightR_instruction122):
+ imul ebp, ebp
+FN_PREFIX(CryptonightR_instruction123):
+ add ebp, r9d
+ add ebp, 2147483647
+FN_PREFIX(CryptonightR_instruction124):
+ sub ebp, r9d
+FN_PREFIX(CryptonightR_instruction125):
+ ror ebp, cl
+FN_PREFIX(CryptonightR_instruction126):
+ rol ebp, cl
+FN_PREFIX(CryptonightR_instruction127):
+ xor ebp, r9d
+FN_PREFIX(CryptonightR_instruction128):
+ imul ebx, esp
+FN_PREFIX(CryptonightR_instruction129):
+ imul ebx, esp
+FN_PREFIX(CryptonightR_instruction130):
+ imul ebx, esp
+FN_PREFIX(CryptonightR_instruction131):
+ add ebx, esp
+ add ebx, 2147483647
+FN_PREFIX(CryptonightR_instruction132):
+ sub ebx, esp
+FN_PREFIX(CryptonightR_instruction133):
+ ror ebx, cl
+FN_PREFIX(CryptonightR_instruction134):
+ rol ebx, cl
+FN_PREFIX(CryptonightR_instruction135):
+ xor ebx, esp
+FN_PREFIX(CryptonightR_instruction136):
+ imul esi, esp
+FN_PREFIX(CryptonightR_instruction137):
+ imul esi, esp
+FN_PREFIX(CryptonightR_instruction138):
+ imul esi, esp
+FN_PREFIX(CryptonightR_instruction139):
+ add esi, esp
+ add esi, 2147483647
+FN_PREFIX(CryptonightR_instruction140):
+ sub esi, esp
+FN_PREFIX(CryptonightR_instruction141):
+ ror esi, cl
+FN_PREFIX(CryptonightR_instruction142):
+ rol esi, cl
+FN_PREFIX(CryptonightR_instruction143):
+ xor esi, esp
+FN_PREFIX(CryptonightR_instruction144):
+ imul edi, esp
+FN_PREFIX(CryptonightR_instruction145):
+ imul edi, esp
+FN_PREFIX(CryptonightR_instruction146):
+ imul edi, esp
+FN_PREFIX(CryptonightR_instruction147):
+ add edi, esp
+ add edi, 2147483647
+FN_PREFIX(CryptonightR_instruction148):
+ sub edi, esp
+FN_PREFIX(CryptonightR_instruction149):
+ ror edi, cl
+FN_PREFIX(CryptonightR_instruction150):
+ rol edi, cl
+FN_PREFIX(CryptonightR_instruction151):
+ xor edi, esp
+FN_PREFIX(CryptonightR_instruction152):
+ imul ebp, esp
+FN_PREFIX(CryptonightR_instruction153):
+ imul ebp, esp
+FN_PREFIX(CryptonightR_instruction154):
+ imul ebp, esp
+FN_PREFIX(CryptonightR_instruction155):
+ add ebp, esp
+ add ebp, 2147483647
+FN_PREFIX(CryptonightR_instruction156):
+ sub ebp, esp
+FN_PREFIX(CryptonightR_instruction157):
+ ror ebp, cl
+FN_PREFIX(CryptonightR_instruction158):
+ rol ebp, cl
+FN_PREFIX(CryptonightR_instruction159):
+ xor ebp, esp
+FN_PREFIX(CryptonightR_instruction160):
+ imul ebx, r15d
+FN_PREFIX(CryptonightR_instruction161):
+ imul ebx, r15d
+FN_PREFIX(CryptonightR_instruction162):
+ imul ebx, r15d
+FN_PREFIX(CryptonightR_instruction163):
+ add ebx, r15d
+ add ebx, 2147483647
+FN_PREFIX(CryptonightR_instruction164):
+ sub ebx, r15d
+FN_PREFIX(CryptonightR_instruction165):
+ ror ebx, cl
+FN_PREFIX(CryptonightR_instruction166):
+ rol ebx, cl
+FN_PREFIX(CryptonightR_instruction167):
+ xor ebx, r15d
+FN_PREFIX(CryptonightR_instruction168):
+ imul esi, r15d
+FN_PREFIX(CryptonightR_instruction169):
+ imul esi, r15d
+FN_PREFIX(CryptonightR_instruction170):
+ imul esi, r15d
+FN_PREFIX(CryptonightR_instruction171):
+ add esi, r15d
+ add esi, 2147483647
+FN_PREFIX(CryptonightR_instruction172):
+ sub esi, r15d
+FN_PREFIX(CryptonightR_instruction173):
+ ror esi, cl
+FN_PREFIX(CryptonightR_instruction174):
+ rol esi, cl
+FN_PREFIX(CryptonightR_instruction175):
+ xor esi, r15d
+FN_PREFIX(CryptonightR_instruction176):
+ imul edi, r15d
+FN_PREFIX(CryptonightR_instruction177):
+ imul edi, r15d
+FN_PREFIX(CryptonightR_instruction178):
+ imul edi, r15d
+FN_PREFIX(CryptonightR_instruction179):
+ add edi, r15d
+ add edi, 2147483647
+FN_PREFIX(CryptonightR_instruction180):
+ sub edi, r15d
+FN_PREFIX(CryptonightR_instruction181):
+ ror edi, cl
+FN_PREFIX(CryptonightR_instruction182):
+ rol edi, cl
+FN_PREFIX(CryptonightR_instruction183):
+ xor edi, r15d
+FN_PREFIX(CryptonightR_instruction184):
+ imul ebp, r15d
+FN_PREFIX(CryptonightR_instruction185):
+ imul ebp, r15d
+FN_PREFIX(CryptonightR_instruction186):
+ imul ebp, r15d
+FN_PREFIX(CryptonightR_instruction187):
+ add ebp, r15d
+ add ebp, 2147483647
+FN_PREFIX(CryptonightR_instruction188):
+ sub ebp, r15d
+FN_PREFIX(CryptonightR_instruction189):
+ ror ebp, cl
+FN_PREFIX(CryptonightR_instruction190):
+ rol ebp, cl
+FN_PREFIX(CryptonightR_instruction191):
+ xor ebp, r15d
+FN_PREFIX(CryptonightR_instruction192):
+ imul ebx, eax
+FN_PREFIX(CryptonightR_instruction193):
+ imul ebx, eax
+FN_PREFIX(CryptonightR_instruction194):
+ imul ebx, eax
+FN_PREFIX(CryptonightR_instruction195):
+ add ebx, eax
+ add ebx, 2147483647
+FN_PREFIX(CryptonightR_instruction196):
+ sub ebx, eax
+FN_PREFIX(CryptonightR_instruction197):
+ ror ebx, cl
+FN_PREFIX(CryptonightR_instruction198):
+ rol ebx, cl
+FN_PREFIX(CryptonightR_instruction199):
+ xor ebx, eax
+FN_PREFIX(CryptonightR_instruction200):
+ imul esi, eax
+FN_PREFIX(CryptonightR_instruction201):
+ imul esi, eax
+FN_PREFIX(CryptonightR_instruction202):
+ imul esi, eax
+FN_PREFIX(CryptonightR_instruction203):
+ add esi, eax
+ add esi, 2147483647
+FN_PREFIX(CryptonightR_instruction204):
+ sub esi, eax
+FN_PREFIX(CryptonightR_instruction205):
+ ror esi, cl
+FN_PREFIX(CryptonightR_instruction206):
+ rol esi, cl
+FN_PREFIX(CryptonightR_instruction207):
+ xor esi, eax
+FN_PREFIX(CryptonightR_instruction208):
+ imul edi, eax
+FN_PREFIX(CryptonightR_instruction209):
+ imul edi, eax
+FN_PREFIX(CryptonightR_instruction210):
+ imul edi, eax
+FN_PREFIX(CryptonightR_instruction211):
+ add edi, eax
+ add edi, 2147483647
+FN_PREFIX(CryptonightR_instruction212):
+ sub edi, eax
+FN_PREFIX(CryptonightR_instruction213):
+ ror edi, cl
+FN_PREFIX(CryptonightR_instruction214):
+ rol edi, cl
+FN_PREFIX(CryptonightR_instruction215):
+ xor edi, eax
+FN_PREFIX(CryptonightR_instruction216):
+ imul ebp, eax
+FN_PREFIX(CryptonightR_instruction217):
+ imul ebp, eax
+FN_PREFIX(CryptonightR_instruction218):
+ imul ebp, eax
+FN_PREFIX(CryptonightR_instruction219):
+ add ebp, eax
+ add ebp, 2147483647
+FN_PREFIX(CryptonightR_instruction220):
+ sub ebp, eax
+FN_PREFIX(CryptonightR_instruction221):
+ ror ebp, cl
+FN_PREFIX(CryptonightR_instruction222):
+ rol ebp, cl
+FN_PREFIX(CryptonightR_instruction223):
+ xor ebp, eax
+FN_PREFIX(CryptonightR_instruction224):
+ imul ebx, edx
+FN_PREFIX(CryptonightR_instruction225):
+ imul ebx, edx
+FN_PREFIX(CryptonightR_instruction226):
+ imul ebx, edx
+FN_PREFIX(CryptonightR_instruction227):
+ add ebx, edx
+ add ebx, 2147483647
+FN_PREFIX(CryptonightR_instruction228):
+ sub ebx, edx
+FN_PREFIX(CryptonightR_instruction229):
+ ror ebx, cl
+FN_PREFIX(CryptonightR_instruction230):
+ rol ebx, cl
+FN_PREFIX(CryptonightR_instruction231):
+ xor ebx, edx
+FN_PREFIX(CryptonightR_instruction232):
+ imul esi, edx
+FN_PREFIX(CryptonightR_instruction233):
+ imul esi, edx
+FN_PREFIX(CryptonightR_instruction234):
+ imul esi, edx
+FN_PREFIX(CryptonightR_instruction235):
+ add esi, edx
+ add esi, 2147483647
+FN_PREFIX(CryptonightR_instruction236):
+ sub esi, edx
+FN_PREFIX(CryptonightR_instruction237):
+ ror esi, cl
+FN_PREFIX(CryptonightR_instruction238):
+ rol esi, cl
+FN_PREFIX(CryptonightR_instruction239):
+ xor esi, edx
+FN_PREFIX(CryptonightR_instruction240):
+ imul edi, edx
+FN_PREFIX(CryptonightR_instruction241):
+ imul edi, edx
+FN_PREFIX(CryptonightR_instruction242):
+ imul edi, edx
+FN_PREFIX(CryptonightR_instruction243):
+ add edi, edx
+ add edi, 2147483647
+FN_PREFIX(CryptonightR_instruction244):
+ sub edi, edx
+FN_PREFIX(CryptonightR_instruction245):
+ ror edi, cl
+FN_PREFIX(CryptonightR_instruction246):
+ rol edi, cl
+FN_PREFIX(CryptonightR_instruction247):
+ xor edi, edx
+FN_PREFIX(CryptonightR_instruction248):
+ imul ebp, edx
+FN_PREFIX(CryptonightR_instruction249):
+ imul ebp, edx
+FN_PREFIX(CryptonightR_instruction250):
+ imul ebp, edx
+FN_PREFIX(CryptonightR_instruction251):
+ add ebp, edx
+ add ebp, 2147483647
+FN_PREFIX(CryptonightR_instruction252):
+ sub ebp, edx
+FN_PREFIX(CryptonightR_instruction253):
+ ror ebp, cl
+FN_PREFIX(CryptonightR_instruction254):
+ rol ebp, cl
+FN_PREFIX(CryptonightR_instruction255):
+ xor ebp, edx
+FN_PREFIX(CryptonightR_instruction256):
+ imul ebx, ebx
+FN_PREFIX(CryptonightR_instruction_mov0):
+
+FN_PREFIX(CryptonightR_instruction_mov1):
+
+FN_PREFIX(CryptonightR_instruction_mov2):
+
+FN_PREFIX(CryptonightR_instruction_mov3):
+
+FN_PREFIX(CryptonightR_instruction_mov4):
+
+FN_PREFIX(CryptonightR_instruction_mov5):
+ mov ecx, ebx
+FN_PREFIX(CryptonightR_instruction_mov6):
+ mov ecx, ebx
+FN_PREFIX(CryptonightR_instruction_mov7):
+
+FN_PREFIX(CryptonightR_instruction_mov8):
+
+FN_PREFIX(CryptonightR_instruction_mov9):
+
+FN_PREFIX(CryptonightR_instruction_mov10):
+
+FN_PREFIX(CryptonightR_instruction_mov11):
+
+FN_PREFIX(CryptonightR_instruction_mov12):
+
+FN_PREFIX(CryptonightR_instruction_mov13):
+ mov ecx, ebx
+FN_PREFIX(CryptonightR_instruction_mov14):
+ mov ecx, ebx
+FN_PREFIX(CryptonightR_instruction_mov15):
+
+FN_PREFIX(CryptonightR_instruction_mov16):
+
+FN_PREFIX(CryptonightR_instruction_mov17):
+
+FN_PREFIX(CryptonightR_instruction_mov18):
+
+FN_PREFIX(CryptonightR_instruction_mov19):
+
+FN_PREFIX(CryptonightR_instruction_mov20):
+
+FN_PREFIX(CryptonightR_instruction_mov21):
+ mov ecx, ebx
+FN_PREFIX(CryptonightR_instruction_mov22):
+ mov ecx, ebx
+FN_PREFIX(CryptonightR_instruction_mov23):
+
+FN_PREFIX(CryptonightR_instruction_mov24):
+
+FN_PREFIX(CryptonightR_instruction_mov25):
+
+FN_PREFIX(CryptonightR_instruction_mov26):
+
+FN_PREFIX(CryptonightR_instruction_mov27):
+
+FN_PREFIX(CryptonightR_instruction_mov28):
+
+FN_PREFIX(CryptonightR_instruction_mov29):
+ mov ecx, ebx
+FN_PREFIX(CryptonightR_instruction_mov30):
+ mov ecx, ebx
+FN_PREFIX(CryptonightR_instruction_mov31):
+
+FN_PREFIX(CryptonightR_instruction_mov32):
+
+FN_PREFIX(CryptonightR_instruction_mov33):
+
+FN_PREFIX(CryptonightR_instruction_mov34):
+
+FN_PREFIX(CryptonightR_instruction_mov35):
+
+FN_PREFIX(CryptonightR_instruction_mov36):
+
+FN_PREFIX(CryptonightR_instruction_mov37):
+ mov ecx, esi
+FN_PREFIX(CryptonightR_instruction_mov38):
+ mov ecx, esi
+FN_PREFIX(CryptonightR_instruction_mov39):
+
+FN_PREFIX(CryptonightR_instruction_mov40):
+
+FN_PREFIX(CryptonightR_instruction_mov41):
+
+FN_PREFIX(CryptonightR_instruction_mov42):
+
+FN_PREFIX(CryptonightR_instruction_mov43):
+
+FN_PREFIX(CryptonightR_instruction_mov44):
+
+FN_PREFIX(CryptonightR_instruction_mov45):
+ mov ecx, esi
+FN_PREFIX(CryptonightR_instruction_mov46):
+ mov ecx, esi
+FN_PREFIX(CryptonightR_instruction_mov47):
+
+FN_PREFIX(CryptonightR_instruction_mov48):
+
+FN_PREFIX(CryptonightR_instruction_mov49):
+
+FN_PREFIX(CryptonightR_instruction_mov50):
+
+FN_PREFIX(CryptonightR_instruction_mov51):
+
+FN_PREFIX(CryptonightR_instruction_mov52):
+
+FN_PREFIX(CryptonightR_instruction_mov53):
+ mov ecx, esi
+FN_PREFIX(CryptonightR_instruction_mov54):
+ mov ecx, esi
+FN_PREFIX(CryptonightR_instruction_mov55):
+
+FN_PREFIX(CryptonightR_instruction_mov56):
+
+FN_PREFIX(CryptonightR_instruction_mov57):
+
+FN_PREFIX(CryptonightR_instruction_mov58):
+
+FN_PREFIX(CryptonightR_instruction_mov59):
+
+FN_PREFIX(CryptonightR_instruction_mov60):
+
+FN_PREFIX(CryptonightR_instruction_mov61):
+ mov ecx, esi
+FN_PREFIX(CryptonightR_instruction_mov62):
+ mov ecx, esi
+FN_PREFIX(CryptonightR_instruction_mov63):
+
+FN_PREFIX(CryptonightR_instruction_mov64):
+
+FN_PREFIX(CryptonightR_instruction_mov65):
+
+FN_PREFIX(CryptonightR_instruction_mov66):
+
+FN_PREFIX(CryptonightR_instruction_mov67):
+
+FN_PREFIX(CryptonightR_instruction_mov68):
+
+FN_PREFIX(CryptonightR_instruction_mov69):
+ mov ecx, edi
+FN_PREFIX(CryptonightR_instruction_mov70):
+ mov ecx, edi
+FN_PREFIX(CryptonightR_instruction_mov71):
+
+FN_PREFIX(CryptonightR_instruction_mov72):
+
+FN_PREFIX(CryptonightR_instruction_mov73):
+
+FN_PREFIX(CryptonightR_instruction_mov74):
+
+FN_PREFIX(CryptonightR_instruction_mov75):
+
+FN_PREFIX(CryptonightR_instruction_mov76):
+
+FN_PREFIX(CryptonightR_instruction_mov77):
+ mov ecx, edi
+FN_PREFIX(CryptonightR_instruction_mov78):
+ mov ecx, edi
+FN_PREFIX(CryptonightR_instruction_mov79):
+
+FN_PREFIX(CryptonightR_instruction_mov80):
+
+FN_PREFIX(CryptonightR_instruction_mov81):
+
+FN_PREFIX(CryptonightR_instruction_mov82):
+
+FN_PREFIX(CryptonightR_instruction_mov83):
+
+FN_PREFIX(CryptonightR_instruction_mov84):
+
+FN_PREFIX(CryptonightR_instruction_mov85):
+ mov ecx, edi
+FN_PREFIX(CryptonightR_instruction_mov86):
+ mov ecx, edi
+FN_PREFIX(CryptonightR_instruction_mov87):
+
+FN_PREFIX(CryptonightR_instruction_mov88):
+
+FN_PREFIX(CryptonightR_instruction_mov89):
+
+FN_PREFIX(CryptonightR_instruction_mov90):
+
+FN_PREFIX(CryptonightR_instruction_mov91):
+
+FN_PREFIX(CryptonightR_instruction_mov92):
+
+FN_PREFIX(CryptonightR_instruction_mov93):
+ mov ecx, edi
+FN_PREFIX(CryptonightR_instruction_mov94):
+ mov ecx, edi
+FN_PREFIX(CryptonightR_instruction_mov95):
+
+FN_PREFIX(CryptonightR_instruction_mov96):
+
+FN_PREFIX(CryptonightR_instruction_mov97):
+
+FN_PREFIX(CryptonightR_instruction_mov98):
+
+FN_PREFIX(CryptonightR_instruction_mov99):
+
+FN_PREFIX(CryptonightR_instruction_mov100):
+
+FN_PREFIX(CryptonightR_instruction_mov101):
+ mov ecx, ebp
+FN_PREFIX(CryptonightR_instruction_mov102):
+ mov ecx, ebp
+FN_PREFIX(CryptonightR_instruction_mov103):
+
+FN_PREFIX(CryptonightR_instruction_mov104):
+
+FN_PREFIX(CryptonightR_instruction_mov105):
+
+FN_PREFIX(CryptonightR_instruction_mov106):
+
+FN_PREFIX(CryptonightR_instruction_mov107):
+
+FN_PREFIX(CryptonightR_instruction_mov108):
+
+FN_PREFIX(CryptonightR_instruction_mov109):
+ mov ecx, ebp
+FN_PREFIX(CryptonightR_instruction_mov110):
+ mov ecx, ebp
+FN_PREFIX(CryptonightR_instruction_mov111):
+
+FN_PREFIX(CryptonightR_instruction_mov112):
+
+FN_PREFIX(CryptonightR_instruction_mov113):
+
+FN_PREFIX(CryptonightR_instruction_mov114):
+
+FN_PREFIX(CryptonightR_instruction_mov115):
+
+FN_PREFIX(CryptonightR_instruction_mov116):
+
+FN_PREFIX(CryptonightR_instruction_mov117):
+ mov ecx, ebp
+FN_PREFIX(CryptonightR_instruction_mov118):
+ mov ecx, ebp
+FN_PREFIX(CryptonightR_instruction_mov119):
+
+FN_PREFIX(CryptonightR_instruction_mov120):
+
+FN_PREFIX(CryptonightR_instruction_mov121):
+
+FN_PREFIX(CryptonightR_instruction_mov122):
+
+FN_PREFIX(CryptonightR_instruction_mov123):
+
+FN_PREFIX(CryptonightR_instruction_mov124):
+
+FN_PREFIX(CryptonightR_instruction_mov125):
+ mov ecx, ebp
+FN_PREFIX(CryptonightR_instruction_mov126):
+ mov ecx, ebp
+FN_PREFIX(CryptonightR_instruction_mov127):
+
+FN_PREFIX(CryptonightR_instruction_mov128):
+
+FN_PREFIX(CryptonightR_instruction_mov129):
+
+FN_PREFIX(CryptonightR_instruction_mov130):
+
+FN_PREFIX(CryptonightR_instruction_mov131):
+
+FN_PREFIX(CryptonightR_instruction_mov132):
+
+FN_PREFIX(CryptonightR_instruction_mov133):
+ mov ecx, esp
+FN_PREFIX(CryptonightR_instruction_mov134):
+ mov ecx, esp
+FN_PREFIX(CryptonightR_instruction_mov135):
+
+FN_PREFIX(CryptonightR_instruction_mov136):
+
+FN_PREFIX(CryptonightR_instruction_mov137):
+
+FN_PREFIX(CryptonightR_instruction_mov138):
+
+FN_PREFIX(CryptonightR_instruction_mov139):
+
+FN_PREFIX(CryptonightR_instruction_mov140):
+
+FN_PREFIX(CryptonightR_instruction_mov141):
+ mov ecx, esp
+FN_PREFIX(CryptonightR_instruction_mov142):
+ mov ecx, esp
+FN_PREFIX(CryptonightR_instruction_mov143):
+
+FN_PREFIX(CryptonightR_instruction_mov144):
+
+FN_PREFIX(CryptonightR_instruction_mov145):
+
+FN_PREFIX(CryptonightR_instruction_mov146):
+
+FN_PREFIX(CryptonightR_instruction_mov147):
+
+FN_PREFIX(CryptonightR_instruction_mov148):
+
+FN_PREFIX(CryptonightR_instruction_mov149):
+ mov ecx, esp
+FN_PREFIX(CryptonightR_instruction_mov150):
+ mov ecx, esp
+FN_PREFIX(CryptonightR_instruction_mov151):
+
+FN_PREFIX(CryptonightR_instruction_mov152):
+
+FN_PREFIX(CryptonightR_instruction_mov153):
+
+FN_PREFIX(CryptonightR_instruction_mov154):
+
+FN_PREFIX(CryptonightR_instruction_mov155):
+
+FN_PREFIX(CryptonightR_instruction_mov156):
+
+FN_PREFIX(CryptonightR_instruction_mov157):
+ mov ecx, esp
+FN_PREFIX(CryptonightR_instruction_mov158):
+ mov ecx, esp
+FN_PREFIX(CryptonightR_instruction_mov159):
+
+FN_PREFIX(CryptonightR_instruction_mov160):
+
+FN_PREFIX(CryptonightR_instruction_mov161):
+
+FN_PREFIX(CryptonightR_instruction_mov162):
+
+FN_PREFIX(CryptonightR_instruction_mov163):
+
+FN_PREFIX(CryptonightR_instruction_mov164):
+
+FN_PREFIX(CryptonightR_instruction_mov165):
+ mov ecx, r15d
+FN_PREFIX(CryptonightR_instruction_mov166):
+ mov ecx, r15d
+FN_PREFIX(CryptonightR_instruction_mov167):
+
+FN_PREFIX(CryptonightR_instruction_mov168):
+
+FN_PREFIX(CryptonightR_instruction_mov169):
+
+FN_PREFIX(CryptonightR_instruction_mov170):
+
+FN_PREFIX(CryptonightR_instruction_mov171):
+
+FN_PREFIX(CryptonightR_instruction_mov172):
+
+FN_PREFIX(CryptonightR_instruction_mov173):
+ mov ecx, r15d
+FN_PREFIX(CryptonightR_instruction_mov174):
+ mov ecx, r15d
+FN_PREFIX(CryptonightR_instruction_mov175):
+
+FN_PREFIX(CryptonightR_instruction_mov176):
+
+FN_PREFIX(CryptonightR_instruction_mov177):
+
+FN_PREFIX(CryptonightR_instruction_mov178):
+
+FN_PREFIX(CryptonightR_instruction_mov179):
+
+FN_PREFIX(CryptonightR_instruction_mov180):
+
+FN_PREFIX(CryptonightR_instruction_mov181):
+ mov ecx, r15d
+FN_PREFIX(CryptonightR_instruction_mov182):
+ mov ecx, r15d
+FN_PREFIX(CryptonightR_instruction_mov183):
+
+FN_PREFIX(CryptonightR_instruction_mov184):
+
+FN_PREFIX(CryptonightR_instruction_mov185):
+
+FN_PREFIX(CryptonightR_instruction_mov186):
+
+FN_PREFIX(CryptonightR_instruction_mov187):
+
+FN_PREFIX(CryptonightR_instruction_mov188):
+
+FN_PREFIX(CryptonightR_instruction_mov189):
+ mov ecx, r15d
+FN_PREFIX(CryptonightR_instruction_mov190):
+ mov ecx, r15d
+FN_PREFIX(CryptonightR_instruction_mov191):
+
+FN_PREFIX(CryptonightR_instruction_mov192):
+
+FN_PREFIX(CryptonightR_instruction_mov193):
+
+FN_PREFIX(CryptonightR_instruction_mov194):
+
+FN_PREFIX(CryptonightR_instruction_mov195):
+
+FN_PREFIX(CryptonightR_instruction_mov196):
+
+FN_PREFIX(CryptonightR_instruction_mov197):
+ mov ecx, eax
+FN_PREFIX(CryptonightR_instruction_mov198):
+ mov ecx, eax
+FN_PREFIX(CryptonightR_instruction_mov199):
+
+FN_PREFIX(CryptonightR_instruction_mov200):
+
+FN_PREFIX(CryptonightR_instruction_mov201):
+
+FN_PREFIX(CryptonightR_instruction_mov202):
+
+FN_PREFIX(CryptonightR_instruction_mov203):
+
+FN_PREFIX(CryptonightR_instruction_mov204):
+
+FN_PREFIX(CryptonightR_instruction_mov205):
+ mov ecx, eax
+FN_PREFIX(CryptonightR_instruction_mov206):
+ mov ecx, eax
+FN_PREFIX(CryptonightR_instruction_mov207):
+
+FN_PREFIX(CryptonightR_instruction_mov208):
+
+FN_PREFIX(CryptonightR_instruction_mov209):
+
+FN_PREFIX(CryptonightR_instruction_mov210):
+
+FN_PREFIX(CryptonightR_instruction_mov211):
+
+FN_PREFIX(CryptonightR_instruction_mov212):
+
+FN_PREFIX(CryptonightR_instruction_mov213):
+ mov ecx, eax
+FN_PREFIX(CryptonightR_instruction_mov214):
+ mov ecx, eax
+FN_PREFIX(CryptonightR_instruction_mov215):
+
+FN_PREFIX(CryptonightR_instruction_mov216):
+
+FN_PREFIX(CryptonightR_instruction_mov217):
+
+FN_PREFIX(CryptonightR_instruction_mov218):
+
+FN_PREFIX(CryptonightR_instruction_mov219):
+
+FN_PREFIX(CryptonightR_instruction_mov220):
+
+FN_PREFIX(CryptonightR_instruction_mov221):
+ mov ecx, eax
+FN_PREFIX(CryptonightR_instruction_mov222):
+ mov ecx, eax
+FN_PREFIX(CryptonightR_instruction_mov223):
+
+FN_PREFIX(CryptonightR_instruction_mov224):
+
+FN_PREFIX(CryptonightR_instruction_mov225):
+
+FN_PREFIX(CryptonightR_instruction_mov226):
+
+FN_PREFIX(CryptonightR_instruction_mov227):
+
+FN_PREFIX(CryptonightR_instruction_mov228):
+
+FN_PREFIX(CryptonightR_instruction_mov229):
+ mov ecx, edx
+FN_PREFIX(CryptonightR_instruction_mov230):
+ mov ecx, edx
+FN_PREFIX(CryptonightR_instruction_mov231):
+
+FN_PREFIX(CryptonightR_instruction_mov232):
+
+FN_PREFIX(CryptonightR_instruction_mov233):
+
+FN_PREFIX(CryptonightR_instruction_mov234):
+
+FN_PREFIX(CryptonightR_instruction_mov235):
+
+FN_PREFIX(CryptonightR_instruction_mov236):
+
+FN_PREFIX(CryptonightR_instruction_mov237):
+ mov ecx, edx
+FN_PREFIX(CryptonightR_instruction_mov238):
+ mov ecx, edx
+FN_PREFIX(CryptonightR_instruction_mov239):
+
+FN_PREFIX(CryptonightR_instruction_mov240):
+
+FN_PREFIX(CryptonightR_instruction_mov241):
+
+FN_PREFIX(CryptonightR_instruction_mov242):
+
+FN_PREFIX(CryptonightR_instruction_mov243):
+
+FN_PREFIX(CryptonightR_instruction_mov244):
+
+FN_PREFIX(CryptonightR_instruction_mov245):
+ mov ecx, edx
+FN_PREFIX(CryptonightR_instruction_mov246):
+ mov ecx, edx
+FN_PREFIX(CryptonightR_instruction_mov247):
+
+FN_PREFIX(CryptonightR_instruction_mov248):
+
+FN_PREFIX(CryptonightR_instruction_mov249):
+
+FN_PREFIX(CryptonightR_instruction_mov250):
+
+FN_PREFIX(CryptonightR_instruction_mov251):
+
+FN_PREFIX(CryptonightR_instruction_mov252):
+
+FN_PREFIX(CryptonightR_instruction_mov253):
+ mov ecx, edx
+FN_PREFIX(CryptonightR_instruction_mov254):
+ mov ecx, edx
+FN_PREFIX(CryptonightR_instruction_mov255):
+
+FN_PREFIX(CryptonightR_instruction_mov256):
diff --git a/src/crypto/CryptonightR_template.h b/src/crypto/CryptonightR_template.h
new file mode 100644
index 000000000..dab1bd750
--- /dev/null
+++ b/src/crypto/CryptonightR_template.h
@@ -0,0 +1,1043 @@
+#ifndef CRYPTONIGHTR_TEMPLATE_H
+#define CRYPTONIGHTR_TEMPLATE_H
+
+#if defined __i386 || defined __x86_64__
+
+void CryptonightR_instruction0(void);
+void CryptonightR_instruction1(void);
+void CryptonightR_instruction2(void);
+void CryptonightR_instruction3(void);
+void CryptonightR_instruction4(void);
+void CryptonightR_instruction5(void);
+void CryptonightR_instruction6(void);
+void CryptonightR_instruction7(void);
+void CryptonightR_instruction8(void);
+void CryptonightR_instruction9(void);
+void CryptonightR_instruction10(void);
+void CryptonightR_instruction11(void);
+void CryptonightR_instruction12(void);
+void CryptonightR_instruction13(void);
+void CryptonightR_instruction14(void);
+void CryptonightR_instruction15(void);
+void CryptonightR_instruction16(void);
+void CryptonightR_instruction17(void);
+void CryptonightR_instruction18(void);
+void CryptonightR_instruction19(void);
+void CryptonightR_instruction20(void);
+void CryptonightR_instruction21(void);
+void CryptonightR_instruction22(void);
+void CryptonightR_instruction23(void);
+void CryptonightR_instruction24(void);
+void CryptonightR_instruction25(void);
+void CryptonightR_instruction26(void);
+void CryptonightR_instruction27(void);
+void CryptonightR_instruction28(void);
+void CryptonightR_instruction29(void);
+void CryptonightR_instruction30(void);
+void CryptonightR_instruction31(void);
+void CryptonightR_instruction32(void);
+void CryptonightR_instruction33(void);
+void CryptonightR_instruction34(void);
+void CryptonightR_instruction35(void);
+void CryptonightR_instruction36(void);
+void CryptonightR_instruction37(void);
+void CryptonightR_instruction38(void);
+void CryptonightR_instruction39(void);
+void CryptonightR_instruction40(void);
+void CryptonightR_instruction41(void);
+void CryptonightR_instruction42(void);
+void CryptonightR_instruction43(void);
+void CryptonightR_instruction44(void);
+void CryptonightR_instruction45(void);
+void CryptonightR_instruction46(void);
+void CryptonightR_instruction47(void);
+void CryptonightR_instruction48(void);
+void CryptonightR_instruction49(void);
+void CryptonightR_instruction50(void);
+void CryptonightR_instruction51(void);
+void CryptonightR_instruction52(void);
+void CryptonightR_instruction53(void);
+void CryptonightR_instruction54(void);
+void CryptonightR_instruction55(void);
+void CryptonightR_instruction56(void);
+void CryptonightR_instruction57(void);
+void CryptonightR_instruction58(void);
+void CryptonightR_instruction59(void);
+void CryptonightR_instruction60(void);
+void CryptonightR_instruction61(void);
+void CryptonightR_instruction62(void);
+void CryptonightR_instruction63(void);
+void CryptonightR_instruction64(void);
+void CryptonightR_instruction65(void);
+void CryptonightR_instruction66(void);
+void CryptonightR_instruction67(void);
+void CryptonightR_instruction68(void);
+void CryptonightR_instruction69(void);
+void CryptonightR_instruction70(void);
+void CryptonightR_instruction71(void);
+void CryptonightR_instruction72(void);
+void CryptonightR_instruction73(void);
+void CryptonightR_instruction74(void);
+void CryptonightR_instruction75(void);
+void CryptonightR_instruction76(void);
+void CryptonightR_instruction77(void);
+void CryptonightR_instruction78(void);
+void CryptonightR_instruction79(void);
+void CryptonightR_instruction80(void);
+void CryptonightR_instruction81(void);
+void CryptonightR_instruction82(void);
+void CryptonightR_instruction83(void);
+void CryptonightR_instruction84(void);
+void CryptonightR_instruction85(void);
+void CryptonightR_instruction86(void);
+void CryptonightR_instruction87(void);
+void CryptonightR_instruction88(void);
+void CryptonightR_instruction89(void);
+void CryptonightR_instruction90(void);
+void CryptonightR_instruction91(void);
+void CryptonightR_instruction92(void);
+void CryptonightR_instruction93(void);
+void CryptonightR_instruction94(void);
+void CryptonightR_instruction95(void);
+void CryptonightR_instruction96(void);
+void CryptonightR_instruction97(void);
+void CryptonightR_instruction98(void);
+void CryptonightR_instruction99(void);
+void CryptonightR_instruction100(void);
+void CryptonightR_instruction101(void);
+void CryptonightR_instruction102(void);
+void CryptonightR_instruction103(void);
+void CryptonightR_instruction104(void);
+void CryptonightR_instruction105(void);
+void CryptonightR_instruction106(void);
+void CryptonightR_instruction107(void);
+void CryptonightR_instruction108(void);
+void CryptonightR_instruction109(void);
+void CryptonightR_instruction110(void);
+void CryptonightR_instruction111(void);
+void CryptonightR_instruction112(void);
+void CryptonightR_instruction113(void);
+void CryptonightR_instruction114(void);
+void CryptonightR_instruction115(void);
+void CryptonightR_instruction116(void);
+void CryptonightR_instruction117(void);
+void CryptonightR_instruction118(void);
+void CryptonightR_instruction119(void);
+void CryptonightR_instruction120(void);
+void CryptonightR_instruction121(void);
+void CryptonightR_instruction122(void);
+void CryptonightR_instruction123(void);
+void CryptonightR_instruction124(void);
+void CryptonightR_instruction125(void);
+void CryptonightR_instruction126(void);
+void CryptonightR_instruction127(void);
+void CryptonightR_instruction128(void);
+void CryptonightR_instruction129(void);
+void CryptonightR_instruction130(void);
+void CryptonightR_instruction131(void);
+void CryptonightR_instruction132(void);
+void CryptonightR_instruction133(void);
+void CryptonightR_instruction134(void);
+void CryptonightR_instruction135(void);
+void CryptonightR_instruction136(void);
+void CryptonightR_instruction137(void);
+void CryptonightR_instruction138(void);
+void CryptonightR_instruction139(void);
+void CryptonightR_instruction140(void);
+void CryptonightR_instruction141(void);
+void CryptonightR_instruction142(void);
+void CryptonightR_instruction143(void);
+void CryptonightR_instruction144(void);
+void CryptonightR_instruction145(void);
+void CryptonightR_instruction146(void);
+void CryptonightR_instruction147(void);
+void CryptonightR_instruction148(void);
+void CryptonightR_instruction149(void);
+void CryptonightR_instruction150(void);
+void CryptonightR_instruction151(void);
+void CryptonightR_instruction152(void);
+void CryptonightR_instruction153(void);
+void CryptonightR_instruction154(void);
+void CryptonightR_instruction155(void);
+void CryptonightR_instruction156(void);
+void CryptonightR_instruction157(void);
+void CryptonightR_instruction158(void);
+void CryptonightR_instruction159(void);
+void CryptonightR_instruction160(void);
+void CryptonightR_instruction161(void);
+void CryptonightR_instruction162(void);
+void CryptonightR_instruction163(void);
+void CryptonightR_instruction164(void);
+void CryptonightR_instruction165(void);
+void CryptonightR_instruction166(void);
+void CryptonightR_instruction167(void);
+void CryptonightR_instruction168(void);
+void CryptonightR_instruction169(void);
+void CryptonightR_instruction170(void);
+void CryptonightR_instruction171(void);
+void CryptonightR_instruction172(void);
+void CryptonightR_instruction173(void);
+void CryptonightR_instruction174(void);
+void CryptonightR_instruction175(void);
+void CryptonightR_instruction176(void);
+void CryptonightR_instruction177(void);
+void CryptonightR_instruction178(void);
+void CryptonightR_instruction179(void);
+void CryptonightR_instruction180(void);
+void CryptonightR_instruction181(void);
+void CryptonightR_instruction182(void);
+void CryptonightR_instruction183(void);
+void CryptonightR_instruction184(void);
+void CryptonightR_instruction185(void);
+void CryptonightR_instruction186(void);
+void CryptonightR_instruction187(void);
+void CryptonightR_instruction188(void);
+void CryptonightR_instruction189(void);
+void CryptonightR_instruction190(void);
+void CryptonightR_instruction191(void);
+void CryptonightR_instruction192(void);
+void CryptonightR_instruction193(void);
+void CryptonightR_instruction194(void);
+void CryptonightR_instruction195(void);
+void CryptonightR_instruction196(void);
+void CryptonightR_instruction197(void);
+void CryptonightR_instruction198(void);
+void CryptonightR_instruction199(void);
+void CryptonightR_instruction200(void);
+void CryptonightR_instruction201(void);
+void CryptonightR_instruction202(void);
+void CryptonightR_instruction203(void);
+void CryptonightR_instruction204(void);
+void CryptonightR_instruction205(void);
+void CryptonightR_instruction206(void);
+void CryptonightR_instruction207(void);
+void CryptonightR_instruction208(void);
+void CryptonightR_instruction209(void);
+void CryptonightR_instruction210(void);
+void CryptonightR_instruction211(void);
+void CryptonightR_instruction212(void);
+void CryptonightR_instruction213(void);
+void CryptonightR_instruction214(void);
+void CryptonightR_instruction215(void);
+void CryptonightR_instruction216(void);
+void CryptonightR_instruction217(void);
+void CryptonightR_instruction218(void);
+void CryptonightR_instruction219(void);
+void CryptonightR_instruction220(void);
+void CryptonightR_instruction221(void);
+void CryptonightR_instruction222(void);
+void CryptonightR_instruction223(void);
+void CryptonightR_instruction224(void);
+void CryptonightR_instruction225(void);
+void CryptonightR_instruction226(void);
+void CryptonightR_instruction227(void);
+void CryptonightR_instruction228(void);
+void CryptonightR_instruction229(void);
+void CryptonightR_instruction230(void);
+void CryptonightR_instruction231(void);
+void CryptonightR_instruction232(void);
+void CryptonightR_instruction233(void);
+void CryptonightR_instruction234(void);
+void CryptonightR_instruction235(void);
+void CryptonightR_instruction236(void);
+void CryptonightR_instruction237(void);
+void CryptonightR_instruction238(void);
+void CryptonightR_instruction239(void);
+void CryptonightR_instruction240(void);
+void CryptonightR_instruction241(void);
+void CryptonightR_instruction242(void);
+void CryptonightR_instruction243(void);
+void CryptonightR_instruction244(void);
+void CryptonightR_instruction245(void);
+void CryptonightR_instruction246(void);
+void CryptonightR_instruction247(void);
+void CryptonightR_instruction248(void);
+void CryptonightR_instruction249(void);
+void CryptonightR_instruction250(void);
+void CryptonightR_instruction251(void);
+void CryptonightR_instruction252(void);
+void CryptonightR_instruction253(void);
+void CryptonightR_instruction254(void);
+void CryptonightR_instruction255(void);
+void CryptonightR_instruction256(void);
+void CryptonightR_instruction_mov0(void);
+void CryptonightR_instruction_mov1(void);
+void CryptonightR_instruction_mov2(void);
+void CryptonightR_instruction_mov3(void);
+void CryptonightR_instruction_mov4(void);
+void CryptonightR_instruction_mov5(void);
+void CryptonightR_instruction_mov6(void);
+void CryptonightR_instruction_mov7(void);
+void CryptonightR_instruction_mov8(void);
+void CryptonightR_instruction_mov9(void);
+void CryptonightR_instruction_mov10(void);
+void CryptonightR_instruction_mov11(void);
+void CryptonightR_instruction_mov12(void);
+void CryptonightR_instruction_mov13(void);
+void CryptonightR_instruction_mov14(void);
+void CryptonightR_instruction_mov15(void);
+void CryptonightR_instruction_mov16(void);
+void CryptonightR_instruction_mov17(void);
+void CryptonightR_instruction_mov18(void);
+void CryptonightR_instruction_mov19(void);
+void CryptonightR_instruction_mov20(void);
+void CryptonightR_instruction_mov21(void);
+void CryptonightR_instruction_mov22(void);
+void CryptonightR_instruction_mov23(void);
+void CryptonightR_instruction_mov24(void);
+void CryptonightR_instruction_mov25(void);
+void CryptonightR_instruction_mov26(void);
+void CryptonightR_instruction_mov27(void);
+void CryptonightR_instruction_mov28(void);
+void CryptonightR_instruction_mov29(void);
+void CryptonightR_instruction_mov30(void);
+void CryptonightR_instruction_mov31(void);
+void CryptonightR_instruction_mov32(void);
+void CryptonightR_instruction_mov33(void);
+void CryptonightR_instruction_mov34(void);
+void CryptonightR_instruction_mov35(void);
+void CryptonightR_instruction_mov36(void);
+void CryptonightR_instruction_mov37(void);
+void CryptonightR_instruction_mov38(void);
+void CryptonightR_instruction_mov39(void);
+void CryptonightR_instruction_mov40(void);
+void CryptonightR_instruction_mov41(void);
+void CryptonightR_instruction_mov42(void);
+void CryptonightR_instruction_mov43(void);
+void CryptonightR_instruction_mov44(void);
+void CryptonightR_instruction_mov45(void);
+void CryptonightR_instruction_mov46(void);
+void CryptonightR_instruction_mov47(void);
+void CryptonightR_instruction_mov48(void);
+void CryptonightR_instruction_mov49(void);
+void CryptonightR_instruction_mov50(void);
+void CryptonightR_instruction_mov51(void);
+void CryptonightR_instruction_mov52(void);
+void CryptonightR_instruction_mov53(void);
+void CryptonightR_instruction_mov54(void);
+void CryptonightR_instruction_mov55(void);
+void CryptonightR_instruction_mov56(void);
+void CryptonightR_instruction_mov57(void);
+void CryptonightR_instruction_mov58(void);
+void CryptonightR_instruction_mov59(void);
+void CryptonightR_instruction_mov60(void);
+void CryptonightR_instruction_mov61(void);
+void CryptonightR_instruction_mov62(void);
+void CryptonightR_instruction_mov63(void);
+void CryptonightR_instruction_mov64(void);
+void CryptonightR_instruction_mov65(void);
+void CryptonightR_instruction_mov66(void);
+void CryptonightR_instruction_mov67(void);
+void CryptonightR_instruction_mov68(void);
+void CryptonightR_instruction_mov69(void);
+void CryptonightR_instruction_mov70(void);
+void CryptonightR_instruction_mov71(void);
+void CryptonightR_instruction_mov72(void);
+void CryptonightR_instruction_mov73(void);
+void CryptonightR_instruction_mov74(void);
+void CryptonightR_instruction_mov75(void);
+void CryptonightR_instruction_mov76(void);
+void CryptonightR_instruction_mov77(void);
+void CryptonightR_instruction_mov78(void);
+void CryptonightR_instruction_mov79(void);
+void CryptonightR_instruction_mov80(void);
+void CryptonightR_instruction_mov81(void);
+void CryptonightR_instruction_mov82(void);
+void CryptonightR_instruction_mov83(void);
+void CryptonightR_instruction_mov84(void);
+void CryptonightR_instruction_mov85(void);
+void CryptonightR_instruction_mov86(void);
+void CryptonightR_instruction_mov87(void);
+void CryptonightR_instruction_mov88(void);
+void CryptonightR_instruction_mov89(void);
+void CryptonightR_instruction_mov90(void);
+void CryptonightR_instruction_mov91(void);
+void CryptonightR_instruction_mov92(void);
+void CryptonightR_instruction_mov93(void);
+void CryptonightR_instruction_mov94(void);
+void CryptonightR_instruction_mov95(void);
+void CryptonightR_instruction_mov96(void);
+void CryptonightR_instruction_mov97(void);
+void CryptonightR_instruction_mov98(void);
+void CryptonightR_instruction_mov99(void);
+void CryptonightR_instruction_mov100(void);
+void CryptonightR_instruction_mov101(void);
+void CryptonightR_instruction_mov102(void);
+void CryptonightR_instruction_mov103(void);
+void CryptonightR_instruction_mov104(void);
+void CryptonightR_instruction_mov105(void);
+void CryptonightR_instruction_mov106(void);
+void CryptonightR_instruction_mov107(void);
+void CryptonightR_instruction_mov108(void);
+void CryptonightR_instruction_mov109(void);
+void CryptonightR_instruction_mov110(void);
+void CryptonightR_instruction_mov111(void);
+void CryptonightR_instruction_mov112(void);
+void CryptonightR_instruction_mov113(void);
+void CryptonightR_instruction_mov114(void);
+void CryptonightR_instruction_mov115(void);
+void CryptonightR_instruction_mov116(void);
+void CryptonightR_instruction_mov117(void);
+void CryptonightR_instruction_mov118(void);
+void CryptonightR_instruction_mov119(void);
+void CryptonightR_instruction_mov120(void);
+void CryptonightR_instruction_mov121(void);
+void CryptonightR_instruction_mov122(void);
+void CryptonightR_instruction_mov123(void);
+void CryptonightR_instruction_mov124(void);
+void CryptonightR_instruction_mov125(void);
+void CryptonightR_instruction_mov126(void);
+void CryptonightR_instruction_mov127(void);
+void CryptonightR_instruction_mov128(void);
+void CryptonightR_instruction_mov129(void);
+void CryptonightR_instruction_mov130(void);
+void CryptonightR_instruction_mov131(void);
+void CryptonightR_instruction_mov132(void);
+void CryptonightR_instruction_mov133(void);
+void CryptonightR_instruction_mov134(void);
+void CryptonightR_instruction_mov135(void);
+void CryptonightR_instruction_mov136(void);
+void CryptonightR_instruction_mov137(void);
+void CryptonightR_instruction_mov138(void);
+void CryptonightR_instruction_mov139(void);
+void CryptonightR_instruction_mov140(void);
+void CryptonightR_instruction_mov141(void);
+void CryptonightR_instruction_mov142(void);
+void CryptonightR_instruction_mov143(void);
+void CryptonightR_instruction_mov144(void);
+void CryptonightR_instruction_mov145(void);
+void CryptonightR_instruction_mov146(void);
+void CryptonightR_instruction_mov147(void);
+void CryptonightR_instruction_mov148(void);
+void CryptonightR_instruction_mov149(void);
+void CryptonightR_instruction_mov150(void);
+void CryptonightR_instruction_mov151(void);
+void CryptonightR_instruction_mov152(void);
+void CryptonightR_instruction_mov153(void);
+void CryptonightR_instruction_mov154(void);
+void CryptonightR_instruction_mov155(void);
+void CryptonightR_instruction_mov156(void);
+void CryptonightR_instruction_mov157(void);
+void CryptonightR_instruction_mov158(void);
+void CryptonightR_instruction_mov159(void);
+void CryptonightR_instruction_mov160(void);
+void CryptonightR_instruction_mov161(void);
+void CryptonightR_instruction_mov162(void);
+void CryptonightR_instruction_mov163(void);
+void CryptonightR_instruction_mov164(void);
+void CryptonightR_instruction_mov165(void);
+void CryptonightR_instruction_mov166(void);
+void CryptonightR_instruction_mov167(void);
+void CryptonightR_instruction_mov168(void);
+void CryptonightR_instruction_mov169(void);
+void CryptonightR_instruction_mov170(void);
+void CryptonightR_instruction_mov171(void);
+void CryptonightR_instruction_mov172(void);
+void CryptonightR_instruction_mov173(void);
+void CryptonightR_instruction_mov174(void);
+void CryptonightR_instruction_mov175(void);
+void CryptonightR_instruction_mov176(void);
+void CryptonightR_instruction_mov177(void);
+void CryptonightR_instruction_mov178(void);
+void CryptonightR_instruction_mov179(void);
+void CryptonightR_instruction_mov180(void);
+void CryptonightR_instruction_mov181(void);
+void CryptonightR_instruction_mov182(void);
+void CryptonightR_instruction_mov183(void);
+void CryptonightR_instruction_mov184(void);
+void CryptonightR_instruction_mov185(void);
+void CryptonightR_instruction_mov186(void);
+void CryptonightR_instruction_mov187(void);
+void CryptonightR_instruction_mov188(void);
+void CryptonightR_instruction_mov189(void);
+void CryptonightR_instruction_mov190(void);
+void CryptonightR_instruction_mov191(void);
+void CryptonightR_instruction_mov192(void);
+void CryptonightR_instruction_mov193(void);
+void CryptonightR_instruction_mov194(void);
+void CryptonightR_instruction_mov195(void);
+void CryptonightR_instruction_mov196(void);
+void CryptonightR_instruction_mov197(void);
+void CryptonightR_instruction_mov198(void);
+void CryptonightR_instruction_mov199(void);
+void CryptonightR_instruction_mov200(void);
+void CryptonightR_instruction_mov201(void);
+void CryptonightR_instruction_mov202(void);
+void CryptonightR_instruction_mov203(void);
+void CryptonightR_instruction_mov204(void);
+void CryptonightR_instruction_mov205(void);
+void CryptonightR_instruction_mov206(void);
+void CryptonightR_instruction_mov207(void);
+void CryptonightR_instruction_mov208(void);
+void CryptonightR_instruction_mov209(void);
+void CryptonightR_instruction_mov210(void);
+void CryptonightR_instruction_mov211(void);
+void CryptonightR_instruction_mov212(void);
+void CryptonightR_instruction_mov213(void);
+void CryptonightR_instruction_mov214(void);
+void CryptonightR_instruction_mov215(void);
+void CryptonightR_instruction_mov216(void);
+void CryptonightR_instruction_mov217(void);
+void CryptonightR_instruction_mov218(void);
+void CryptonightR_instruction_mov219(void);
+void CryptonightR_instruction_mov220(void);
+void CryptonightR_instruction_mov221(void);
+void CryptonightR_instruction_mov222(void);
+void CryptonightR_instruction_mov223(void);
+void CryptonightR_instruction_mov224(void);
+void CryptonightR_instruction_mov225(void);
+void CryptonightR_instruction_mov226(void);
+void CryptonightR_instruction_mov227(void);
+void CryptonightR_instruction_mov228(void);
+void CryptonightR_instruction_mov229(void);
+void CryptonightR_instruction_mov230(void);
+void CryptonightR_instruction_mov231(void);
+void CryptonightR_instruction_mov232(void);
+void CryptonightR_instruction_mov233(void);
+void CryptonightR_instruction_mov234(void);
+void CryptonightR_instruction_mov235(void);
+void CryptonightR_instruction_mov236(void);
+void CryptonightR_instruction_mov237(void);
+void CryptonightR_instruction_mov238(void);
+void CryptonightR_instruction_mov239(void);
+void CryptonightR_instruction_mov240(void);
+void CryptonightR_instruction_mov241(void);
+void CryptonightR_instruction_mov242(void);
+void CryptonightR_instruction_mov243(void);
+void CryptonightR_instruction_mov244(void);
+void CryptonightR_instruction_mov245(void);
+void CryptonightR_instruction_mov246(void);
+void CryptonightR_instruction_mov247(void);
+void CryptonightR_instruction_mov248(void);
+void CryptonightR_instruction_mov249(void);
+void CryptonightR_instruction_mov250(void);
+void CryptonightR_instruction_mov251(void);
+void CryptonightR_instruction_mov252(void);
+void CryptonightR_instruction_mov253(void);
+void CryptonightR_instruction_mov254(void);
+void CryptonightR_instruction_mov255(void);
+void CryptonightR_instruction_mov256(void);
+
+const void* instructions[257] = {
+ CryptonightR_instruction0,
+ CryptonightR_instruction1,
+ CryptonightR_instruction2,
+ CryptonightR_instruction3,
+ CryptonightR_instruction4,
+ CryptonightR_instruction5,
+ CryptonightR_instruction6,
+ CryptonightR_instruction7,
+ CryptonightR_instruction8,
+ CryptonightR_instruction9,
+ CryptonightR_instruction10,
+ CryptonightR_instruction11,
+ CryptonightR_instruction12,
+ CryptonightR_instruction13,
+ CryptonightR_instruction14,
+ CryptonightR_instruction15,
+ CryptonightR_instruction16,
+ CryptonightR_instruction17,
+ CryptonightR_instruction18,
+ CryptonightR_instruction19,
+ CryptonightR_instruction20,
+ CryptonightR_instruction21,
+ CryptonightR_instruction22,
+ CryptonightR_instruction23,
+ CryptonightR_instruction24,
+ CryptonightR_instruction25,
+ CryptonightR_instruction26,
+ CryptonightR_instruction27,
+ CryptonightR_instruction28,
+ CryptonightR_instruction29,
+ CryptonightR_instruction30,
+ CryptonightR_instruction31,
+ CryptonightR_instruction32,
+ CryptonightR_instruction33,
+ CryptonightR_instruction34,
+ CryptonightR_instruction35,
+ CryptonightR_instruction36,
+ CryptonightR_instruction37,
+ CryptonightR_instruction38,
+ CryptonightR_instruction39,
+ CryptonightR_instruction40,
+ CryptonightR_instruction41,
+ CryptonightR_instruction42,
+ CryptonightR_instruction43,
+ CryptonightR_instruction44,
+ CryptonightR_instruction45,
+ CryptonightR_instruction46,
+ CryptonightR_instruction47,
+ CryptonightR_instruction48,
+ CryptonightR_instruction49,
+ CryptonightR_instruction50,
+ CryptonightR_instruction51,
+ CryptonightR_instruction52,
+ CryptonightR_instruction53,
+ CryptonightR_instruction54,
+ CryptonightR_instruction55,
+ CryptonightR_instruction56,
+ CryptonightR_instruction57,
+ CryptonightR_instruction58,
+ CryptonightR_instruction59,
+ CryptonightR_instruction60,
+ CryptonightR_instruction61,
+ CryptonightR_instruction62,
+ CryptonightR_instruction63,
+ CryptonightR_instruction64,
+ CryptonightR_instruction65,
+ CryptonightR_instruction66,
+ CryptonightR_instruction67,
+ CryptonightR_instruction68,
+ CryptonightR_instruction69,
+ CryptonightR_instruction70,
+ CryptonightR_instruction71,
+ CryptonightR_instruction72,
+ CryptonightR_instruction73,
+ CryptonightR_instruction74,
+ CryptonightR_instruction75,
+ CryptonightR_instruction76,
+ CryptonightR_instruction77,
+ CryptonightR_instruction78,
+ CryptonightR_instruction79,
+ CryptonightR_instruction80,
+ CryptonightR_instruction81,
+ CryptonightR_instruction82,
+ CryptonightR_instruction83,
+ CryptonightR_instruction84,
+ CryptonightR_instruction85,
+ CryptonightR_instruction86,
+ CryptonightR_instruction87,
+ CryptonightR_instruction88,
+ CryptonightR_instruction89,
+ CryptonightR_instruction90,
+ CryptonightR_instruction91,
+ CryptonightR_instruction92,
+ CryptonightR_instruction93,
+ CryptonightR_instruction94,
+ CryptonightR_instruction95,
+ CryptonightR_instruction96,
+ CryptonightR_instruction97,
+ CryptonightR_instruction98,
+ CryptonightR_instruction99,
+ CryptonightR_instruction100,
+ CryptonightR_instruction101,
+ CryptonightR_instruction102,
+ CryptonightR_instruction103,
+ CryptonightR_instruction104,
+ CryptonightR_instruction105,
+ CryptonightR_instruction106,
+ CryptonightR_instruction107,
+ CryptonightR_instruction108,
+ CryptonightR_instruction109,
+ CryptonightR_instruction110,
+ CryptonightR_instruction111,
+ CryptonightR_instruction112,
+ CryptonightR_instruction113,
+ CryptonightR_instruction114,
+ CryptonightR_instruction115,
+ CryptonightR_instruction116,
+ CryptonightR_instruction117,
+ CryptonightR_instruction118,
+ CryptonightR_instruction119,
+ CryptonightR_instruction120,
+ CryptonightR_instruction121,
+ CryptonightR_instruction122,
+ CryptonightR_instruction123,
+ CryptonightR_instruction124,
+ CryptonightR_instruction125,
+ CryptonightR_instruction126,
+ CryptonightR_instruction127,
+ CryptonightR_instruction128,
+ CryptonightR_instruction129,
+ CryptonightR_instruction130,
+ CryptonightR_instruction131,
+ CryptonightR_instruction132,
+ CryptonightR_instruction133,
+ CryptonightR_instruction134,
+ CryptonightR_instruction135,
+ CryptonightR_instruction136,
+ CryptonightR_instruction137,
+ CryptonightR_instruction138,
+ CryptonightR_instruction139,
+ CryptonightR_instruction140,
+ CryptonightR_instruction141,
+ CryptonightR_instruction142,
+ CryptonightR_instruction143,
+ CryptonightR_instruction144,
+ CryptonightR_instruction145,
+ CryptonightR_instruction146,
+ CryptonightR_instruction147,
+ CryptonightR_instruction148,
+ CryptonightR_instruction149,
+ CryptonightR_instruction150,
+ CryptonightR_instruction151,
+ CryptonightR_instruction152,
+ CryptonightR_instruction153,
+ CryptonightR_instruction154,
+ CryptonightR_instruction155,
+ CryptonightR_instruction156,
+ CryptonightR_instruction157,
+ CryptonightR_instruction158,
+ CryptonightR_instruction159,
+ CryptonightR_instruction160,
+ CryptonightR_instruction161,
+ CryptonightR_instruction162,
+ CryptonightR_instruction163,
+ CryptonightR_instruction164,
+ CryptonightR_instruction165,
+ CryptonightR_instruction166,
+ CryptonightR_instruction167,
+ CryptonightR_instruction168,
+ CryptonightR_instruction169,
+ CryptonightR_instruction170,
+ CryptonightR_instruction171,
+ CryptonightR_instruction172,
+ CryptonightR_instruction173,
+ CryptonightR_instruction174,
+ CryptonightR_instruction175,
+ CryptonightR_instruction176,
+ CryptonightR_instruction177,
+ CryptonightR_instruction178,
+ CryptonightR_instruction179,
+ CryptonightR_instruction180,
+ CryptonightR_instruction181,
+ CryptonightR_instruction182,
+ CryptonightR_instruction183,
+ CryptonightR_instruction184,
+ CryptonightR_instruction185,
+ CryptonightR_instruction186,
+ CryptonightR_instruction187,
+ CryptonightR_instruction188,
+ CryptonightR_instruction189,
+ CryptonightR_instruction190,
+ CryptonightR_instruction191,
+ CryptonightR_instruction192,
+ CryptonightR_instruction193,
+ CryptonightR_instruction194,
+ CryptonightR_instruction195,
+ CryptonightR_instruction196,
+ CryptonightR_instruction197,
+ CryptonightR_instruction198,
+ CryptonightR_instruction199,
+ CryptonightR_instruction200,
+ CryptonightR_instruction201,
+ CryptonightR_instruction202,
+ CryptonightR_instruction203,
+ CryptonightR_instruction204,
+ CryptonightR_instruction205,
+ CryptonightR_instruction206,
+ CryptonightR_instruction207,
+ CryptonightR_instruction208,
+ CryptonightR_instruction209,
+ CryptonightR_instruction210,
+ CryptonightR_instruction211,
+ CryptonightR_instruction212,
+ CryptonightR_instruction213,
+ CryptonightR_instruction214,
+ CryptonightR_instruction215,
+ CryptonightR_instruction216,
+ CryptonightR_instruction217,
+ CryptonightR_instruction218,
+ CryptonightR_instruction219,
+ CryptonightR_instruction220,
+ CryptonightR_instruction221,
+ CryptonightR_instruction222,
+ CryptonightR_instruction223,
+ CryptonightR_instruction224,
+ CryptonightR_instruction225,
+ CryptonightR_instruction226,
+ CryptonightR_instruction227,
+ CryptonightR_instruction228,
+ CryptonightR_instruction229,
+ CryptonightR_instruction230,
+ CryptonightR_instruction231,
+ CryptonightR_instruction232,
+ CryptonightR_instruction233,
+ CryptonightR_instruction234,
+ CryptonightR_instruction235,
+ CryptonightR_instruction236,
+ CryptonightR_instruction237,
+ CryptonightR_instruction238,
+ CryptonightR_instruction239,
+ CryptonightR_instruction240,
+ CryptonightR_instruction241,
+ CryptonightR_instruction242,
+ CryptonightR_instruction243,
+ CryptonightR_instruction244,
+ CryptonightR_instruction245,
+ CryptonightR_instruction246,
+ CryptonightR_instruction247,
+ CryptonightR_instruction248,
+ CryptonightR_instruction249,
+ CryptonightR_instruction250,
+ CryptonightR_instruction251,
+ CryptonightR_instruction252,
+ CryptonightR_instruction253,
+ CryptonightR_instruction254,
+ CryptonightR_instruction255,
+ CryptonightR_instruction256,
+};
+
+const void* instructions_mov[257] = {
+ CryptonightR_instruction_mov0,
+ CryptonightR_instruction_mov1,
+ CryptonightR_instruction_mov2,
+ CryptonightR_instruction_mov3,
+ CryptonightR_instruction_mov4,
+ CryptonightR_instruction_mov5,
+ CryptonightR_instruction_mov6,
+ CryptonightR_instruction_mov7,
+ CryptonightR_instruction_mov8,
+ CryptonightR_instruction_mov9,
+ CryptonightR_instruction_mov10,
+ CryptonightR_instruction_mov11,
+ CryptonightR_instruction_mov12,
+ CryptonightR_instruction_mov13,
+ CryptonightR_instruction_mov14,
+ CryptonightR_instruction_mov15,
+ CryptonightR_instruction_mov16,
+ CryptonightR_instruction_mov17,
+ CryptonightR_instruction_mov18,
+ CryptonightR_instruction_mov19,
+ CryptonightR_instruction_mov20,
+ CryptonightR_instruction_mov21,
+ CryptonightR_instruction_mov22,
+ CryptonightR_instruction_mov23,
+ CryptonightR_instruction_mov24,
+ CryptonightR_instruction_mov25,
+ CryptonightR_instruction_mov26,
+ CryptonightR_instruction_mov27,
+ CryptonightR_instruction_mov28,
+ CryptonightR_instruction_mov29,
+ CryptonightR_instruction_mov30,
+ CryptonightR_instruction_mov31,
+ CryptonightR_instruction_mov32,
+ CryptonightR_instruction_mov33,
+ CryptonightR_instruction_mov34,
+ CryptonightR_instruction_mov35,
+ CryptonightR_instruction_mov36,
+ CryptonightR_instruction_mov37,
+ CryptonightR_instruction_mov38,
+ CryptonightR_instruction_mov39,
+ CryptonightR_instruction_mov40,
+ CryptonightR_instruction_mov41,
+ CryptonightR_instruction_mov42,
+ CryptonightR_instruction_mov43,
+ CryptonightR_instruction_mov44,
+ CryptonightR_instruction_mov45,
+ CryptonightR_instruction_mov46,
+ CryptonightR_instruction_mov47,
+ CryptonightR_instruction_mov48,
+ CryptonightR_instruction_mov49,
+ CryptonightR_instruction_mov50,
+ CryptonightR_instruction_mov51,
+ CryptonightR_instruction_mov52,
+ CryptonightR_instruction_mov53,
+ CryptonightR_instruction_mov54,
+ CryptonightR_instruction_mov55,
+ CryptonightR_instruction_mov56,
+ CryptonightR_instruction_mov57,
+ CryptonightR_instruction_mov58,
+ CryptonightR_instruction_mov59,
+ CryptonightR_instruction_mov60,
+ CryptonightR_instruction_mov61,
+ CryptonightR_instruction_mov62,
+ CryptonightR_instruction_mov63,
+ CryptonightR_instruction_mov64,
+ CryptonightR_instruction_mov65,
+ CryptonightR_instruction_mov66,
+ CryptonightR_instruction_mov67,
+ CryptonightR_instruction_mov68,
+ CryptonightR_instruction_mov69,
+ CryptonightR_instruction_mov70,
+ CryptonightR_instruction_mov71,
+ CryptonightR_instruction_mov72,
+ CryptonightR_instruction_mov73,
+ CryptonightR_instruction_mov74,
+ CryptonightR_instruction_mov75,
+ CryptonightR_instruction_mov76,
+ CryptonightR_instruction_mov77,
+ CryptonightR_instruction_mov78,
+ CryptonightR_instruction_mov79,
+ CryptonightR_instruction_mov80,
+ CryptonightR_instruction_mov81,
+ CryptonightR_instruction_mov82,
+ CryptonightR_instruction_mov83,
+ CryptonightR_instruction_mov84,
+ CryptonightR_instruction_mov85,
+ CryptonightR_instruction_mov86,
+ CryptonightR_instruction_mov87,
+ CryptonightR_instruction_mov88,
+ CryptonightR_instruction_mov89,
+ CryptonightR_instruction_mov90,
+ CryptonightR_instruction_mov91,
+ CryptonightR_instruction_mov92,
+ CryptonightR_instruction_mov93,
+ CryptonightR_instruction_mov94,
+ CryptonightR_instruction_mov95,
+ CryptonightR_instruction_mov96,
+ CryptonightR_instruction_mov97,
+ CryptonightR_instruction_mov98,
+ CryptonightR_instruction_mov99,
+ CryptonightR_instruction_mov100,
+ CryptonightR_instruction_mov101,
+ CryptonightR_instruction_mov102,
+ CryptonightR_instruction_mov103,
+ CryptonightR_instruction_mov104,
+ CryptonightR_instruction_mov105,
+ CryptonightR_instruction_mov106,
+ CryptonightR_instruction_mov107,
+ CryptonightR_instruction_mov108,
+ CryptonightR_instruction_mov109,
+ CryptonightR_instruction_mov110,
+ CryptonightR_instruction_mov111,
+ CryptonightR_instruction_mov112,
+ CryptonightR_instruction_mov113,
+ CryptonightR_instruction_mov114,
+ CryptonightR_instruction_mov115,
+ CryptonightR_instruction_mov116,
+ CryptonightR_instruction_mov117,
+ CryptonightR_instruction_mov118,
+ CryptonightR_instruction_mov119,
+ CryptonightR_instruction_mov120,
+ CryptonightR_instruction_mov121,
+ CryptonightR_instruction_mov122,
+ CryptonightR_instruction_mov123,
+ CryptonightR_instruction_mov124,
+ CryptonightR_instruction_mov125,
+ CryptonightR_instruction_mov126,
+ CryptonightR_instruction_mov127,
+ CryptonightR_instruction_mov128,
+ CryptonightR_instruction_mov129,
+ CryptonightR_instruction_mov130,
+ CryptonightR_instruction_mov131,
+ CryptonightR_instruction_mov132,
+ CryptonightR_instruction_mov133,
+ CryptonightR_instruction_mov134,
+ CryptonightR_instruction_mov135,
+ CryptonightR_instruction_mov136,
+ CryptonightR_instruction_mov137,
+ CryptonightR_instruction_mov138,
+ CryptonightR_instruction_mov139,
+ CryptonightR_instruction_mov140,
+ CryptonightR_instruction_mov141,
+ CryptonightR_instruction_mov142,
+ CryptonightR_instruction_mov143,
+ CryptonightR_instruction_mov144,
+ CryptonightR_instruction_mov145,
+ CryptonightR_instruction_mov146,
+ CryptonightR_instruction_mov147,
+ CryptonightR_instruction_mov148,
+ CryptonightR_instruction_mov149,
+ CryptonightR_instruction_mov150,
+ CryptonightR_instruction_mov151,
+ CryptonightR_instruction_mov152,
+ CryptonightR_instruction_mov153,
+ CryptonightR_instruction_mov154,
+ CryptonightR_instruction_mov155,
+ CryptonightR_instruction_mov156,
+ CryptonightR_instruction_mov157,
+ CryptonightR_instruction_mov158,
+ CryptonightR_instruction_mov159,
+ CryptonightR_instruction_mov160,
+ CryptonightR_instruction_mov161,
+ CryptonightR_instruction_mov162,
+ CryptonightR_instruction_mov163,
+ CryptonightR_instruction_mov164,
+ CryptonightR_instruction_mov165,
+ CryptonightR_instruction_mov166,
+ CryptonightR_instruction_mov167,
+ CryptonightR_instruction_mov168,
+ CryptonightR_instruction_mov169,
+ CryptonightR_instruction_mov170,
+ CryptonightR_instruction_mov171,
+ CryptonightR_instruction_mov172,
+ CryptonightR_instruction_mov173,
+ CryptonightR_instruction_mov174,
+ CryptonightR_instruction_mov175,
+ CryptonightR_instruction_mov176,
+ CryptonightR_instruction_mov177,
+ CryptonightR_instruction_mov178,
+ CryptonightR_instruction_mov179,
+ CryptonightR_instruction_mov180,
+ CryptonightR_instruction_mov181,
+ CryptonightR_instruction_mov182,
+ CryptonightR_instruction_mov183,
+ CryptonightR_instruction_mov184,
+ CryptonightR_instruction_mov185,
+ CryptonightR_instruction_mov186,
+ CryptonightR_instruction_mov187,
+ CryptonightR_instruction_mov188,
+ CryptonightR_instruction_mov189,
+ CryptonightR_instruction_mov190,
+ CryptonightR_instruction_mov191,
+ CryptonightR_instruction_mov192,
+ CryptonightR_instruction_mov193,
+ CryptonightR_instruction_mov194,
+ CryptonightR_instruction_mov195,
+ CryptonightR_instruction_mov196,
+ CryptonightR_instruction_mov197,
+ CryptonightR_instruction_mov198,
+ CryptonightR_instruction_mov199,
+ CryptonightR_instruction_mov200,
+ CryptonightR_instruction_mov201,
+ CryptonightR_instruction_mov202,
+ CryptonightR_instruction_mov203,
+ CryptonightR_instruction_mov204,
+ CryptonightR_instruction_mov205,
+ CryptonightR_instruction_mov206,
+ CryptonightR_instruction_mov207,
+ CryptonightR_instruction_mov208,
+ CryptonightR_instruction_mov209,
+ CryptonightR_instruction_mov210,
+ CryptonightR_instruction_mov211,
+ CryptonightR_instruction_mov212,
+ CryptonightR_instruction_mov213,
+ CryptonightR_instruction_mov214,
+ CryptonightR_instruction_mov215,
+ CryptonightR_instruction_mov216,
+ CryptonightR_instruction_mov217,
+ CryptonightR_instruction_mov218,
+ CryptonightR_instruction_mov219,
+ CryptonightR_instruction_mov220,
+ CryptonightR_instruction_mov221,
+ CryptonightR_instruction_mov222,
+ CryptonightR_instruction_mov223,
+ CryptonightR_instruction_mov224,
+ CryptonightR_instruction_mov225,
+ CryptonightR_instruction_mov226,
+ CryptonightR_instruction_mov227,
+ CryptonightR_instruction_mov228,
+ CryptonightR_instruction_mov229,
+ CryptonightR_instruction_mov230,
+ CryptonightR_instruction_mov231,
+ CryptonightR_instruction_mov232,
+ CryptonightR_instruction_mov233,
+ CryptonightR_instruction_mov234,
+ CryptonightR_instruction_mov235,
+ CryptonightR_instruction_mov236,
+ CryptonightR_instruction_mov237,
+ CryptonightR_instruction_mov238,
+ CryptonightR_instruction_mov239,
+ CryptonightR_instruction_mov240,
+ CryptonightR_instruction_mov241,
+ CryptonightR_instruction_mov242,
+ CryptonightR_instruction_mov243,
+ CryptonightR_instruction_mov244,
+ CryptonightR_instruction_mov245,
+ CryptonightR_instruction_mov246,
+ CryptonightR_instruction_mov247,
+ CryptonightR_instruction_mov248,
+ CryptonightR_instruction_mov249,
+ CryptonightR_instruction_mov250,
+ CryptonightR_instruction_mov251,
+ CryptonightR_instruction_mov252,
+ CryptonightR_instruction_mov253,
+ CryptonightR_instruction_mov254,
+ CryptonightR_instruction_mov255,
+ CryptonightR_instruction_mov256,
+};
+
+#endif
+
+#endif // CRYPTONIGHTR_TEMPLATE_H
diff --git a/src/crypto/blake256.c b/src/crypto/blake256.c
index 6ef7d4207..1e305b3a6 100644
--- a/src/crypto/blake256.c
+++ b/src/crypto/blake256.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/blake256.h b/src/crypto/blake256.h
index 073772289..309dbf3ec 100644
--- a/src/crypto/blake256.h
+++ b/src/crypto/blake256.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/chacha.h b/src/crypto/chacha.h
index 6e85ad0e9..a39823e5a 100644
--- a/src/crypto/chacha.h
+++ b/src/crypto/chacha.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -73,18 +73,18 @@ namespace crypto {
inline void generate_chacha_key(const void *data, size_t size, chacha_key& key, uint64_t kdf_rounds) {
static_assert(sizeof(chacha_key) <= sizeof(hash), "Size of hash must be at least that of chacha_key");
epee::mlocked<tools::scrubbed_arr<char, HASH_SIZE>> pwd_hash;
- crypto::cn_slow_hash(data, size, pwd_hash.data(), 0/*variant*/, 0/*prehashed*/);
+ crypto::cn_slow_hash(data, size, pwd_hash.data(), 0/*variant*/, 0/*prehashed*/, 0/*height*/);
for (uint64_t n = 1; n < kdf_rounds; ++n)
- crypto::cn_slow_hash(pwd_hash.data(), pwd_hash.size(), pwd_hash.data(), 0/*variant*/, 0/*prehashed*/);
+ crypto::cn_slow_hash(pwd_hash.data(), pwd_hash.size(), pwd_hash.data(), 0/*variant*/, 0/*prehashed*/, 0/*height*/);
memcpy(&unwrap(unwrap(key)), pwd_hash.data(), sizeof(key));
}
inline void generate_chacha_key_prehashed(const void *data, size_t size, chacha_key& key, uint64_t kdf_rounds) {
static_assert(sizeof(chacha_key) <= sizeof(hash), "Size of hash must be at least that of chacha_key");
epee::mlocked<tools::scrubbed_arr<char, HASH_SIZE>> pwd_hash;
- crypto::cn_slow_hash(data, size, pwd_hash.data(), 0/*variant*/, 1/*prehashed*/);
+ crypto::cn_slow_hash(data, size, pwd_hash.data(), 0/*variant*/, 1/*prehashed*/, 0/*height*/);
for (uint64_t n = 1; n < kdf_rounds; ++n)
- crypto::cn_slow_hash(pwd_hash.data(), pwd_hash.size(), pwd_hash.data(), 0/*variant*/, 0/*prehashed*/);
+ crypto::cn_slow_hash(pwd_hash.data(), pwd_hash.size(), pwd_hash.data(), 0/*variant*/, 0/*prehashed*/, 0/*height*/);
memcpy(&unwrap(unwrap(key)), pwd_hash.data(), sizeof(key));
}
diff --git a/src/crypto/crypto-ops-data.c b/src/crypto/crypto-ops-data.c
index 1f77513ca..c9530bb2a 100644
--- a/src/crypto/crypto-ops-data.c
+++ b/src/crypto/crypto-ops-data.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/crypto-ops.c b/src/crypto/crypto-ops.c
index 09296d6f9..5a3d994a6 100644
--- a/src/crypto/crypto-ops.c
+++ b/src/crypto/crypto-ops.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/crypto-ops.h b/src/crypto/crypto-ops.h
index 2910dafd4..7137437bc 100644
--- a/src/crypto/crypto-ops.h
+++ b/src/crypto/crypto-ops.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/crypto.cpp b/src/crypto/crypto.cpp
index ddf072f68..3f06c4f3f 100644
--- a/src/crypto/crypto.cpp
+++ b/src/crypto/crypto.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/crypto.h b/src/crypto/crypto.h
index f22df1230..22b182ab0 100644
--- a/src/crypto/crypto.h
+++ b/src/crypto/crypto.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/crypto_ops_builder/README.md b/src/crypto/crypto_ops_builder/README.md
index 326d2ca6e..4bb95cc4a 100644
--- a/src/crypto/crypto_ops_builder/README.md
+++ b/src/crypto/crypto_ops_builder/README.md
@@ -1,6 +1,6 @@
# Monero
-Copyright (c) 2014-2018, The Monero Project
+Copyright (c) 2014-2019, The Monero Project
## Crypto Ops Builder
diff --git a/src/crypto/crypto_ops_builder/crypto-ops-data.c b/src/crypto/crypto_ops_builder/crypto-ops-data.c
index 127e3e17b..45e9923b1 100644
--- a/src/crypto/crypto_ops_builder/crypto-ops-data.c
+++ b/src/crypto/crypto_ops_builder/crypto-ops-data.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/crypto_ops_builder/crypto-ops-old.c b/src/crypto/crypto_ops_builder/crypto-ops-old.c
index 9097bf95b..89c2ced6e 100644
--- a/src/crypto/crypto_ops_builder/crypto-ops-old.c
+++ b/src/crypto/crypto_ops_builder/crypto-ops-old.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/crypto_ops_builder/crypto-ops.h b/src/crypto/crypto_ops_builder/crypto-ops.h
index 9337b56b7..b4fcfca9c 100644
--- a/src/crypto/crypto_ops_builder/crypto-ops.h
+++ b/src/crypto/crypto_ops_builder/crypto-ops.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/crypto_ops_builder/ref10CommentedCombined/MakeCryptoOps.py b/src/crypto/crypto_ops_builder/ref10CommentedCombined/MakeCryptoOps.py
index 0ed97d5f4..dfba583f7 100644
--- a/src/crypto/crypto_ops_builder/ref10CommentedCombined/MakeCryptoOps.py
+++ b/src/crypto/crypto_ops_builder/ref10CommentedCombined/MakeCryptoOps.py
@@ -15,7 +15,7 @@ print("maybe someone smart can replace the sed with perl..")
a = ""
license = textwrap.dedent("""\
- // Copyright (c) 2014-2018, The Monero Project
+ // Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/crypto_ops_builder/ref10CommentedCombined/crypto-ops.h b/src/crypto/crypto_ops_builder/ref10CommentedCombined/crypto-ops.h
index c06af035f..f62ff441d 100644
--- a/src/crypto/crypto_ops_builder/ref10CommentedCombined/crypto-ops.h
+++ b/src/crypto/crypto_ops_builder/ref10CommentedCombined/crypto-ops.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/generic-ops.h b/src/crypto/generic-ops.h
index 42b98706e..d06726638 100644
--- a/src/crypto/generic-ops.h
+++ b/src/crypto/generic-ops.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/groestl.h b/src/crypto/groestl.h
index 19837f309..6628947dd 100644
--- a/src/crypto/groestl.h
+++ b/src/crypto/groestl.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/groestl_tables.h b/src/crypto/groestl_tables.h
index 12472dced..ca0c4fca6 100644
--- a/src/crypto/groestl_tables.h
+++ b/src/crypto/groestl_tables.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/hash-extra-blake.c b/src/crypto/hash-extra-blake.c
index d33103c97..9bada96f3 100644
--- a/src/crypto/hash-extra-blake.c
+++ b/src/crypto/hash-extra-blake.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/hash-extra-groestl.c b/src/crypto/hash-extra-groestl.c
index 228853a44..57866bf9d 100644
--- a/src/crypto/hash-extra-groestl.c
+++ b/src/crypto/hash-extra-groestl.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/hash-extra-jh.c b/src/crypto/hash-extra-jh.c
index e765a18f3..0dbac4fb5 100644
--- a/src/crypto/hash-extra-jh.c
+++ b/src/crypto/hash-extra-jh.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/hash-extra-skein.c b/src/crypto/hash-extra-skein.c
index 06d8f87cc..78f48609f 100644
--- a/src/crypto/hash-extra-skein.c
+++ b/src/crypto/hash-extra-skein.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/hash-ops.h b/src/crypto/hash-ops.h
index 77b52e2d4..859c810bd 100644
--- a/src/crypto/hash-ops.h
+++ b/src/crypto/hash-ops.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -79,7 +79,7 @@ enum {
};
void cn_fast_hash(const void *data, size_t length, char *hash);
-void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int prehashed);
+void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int prehashed, uint64_t height);
void hash_extra_blake(const void *data, size_t length, char *hash);
void hash_extra_groestl(const void *data, size_t length, char *hash);
diff --git a/src/crypto/hash.c b/src/crypto/hash.c
index 43ce32957..b66f3b010 100644
--- a/src/crypto/hash.c
+++ b/src/crypto/hash.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/hash.h b/src/crypto/hash.h
index 995e2294e..17071923d 100644
--- a/src/crypto/hash.h
+++ b/src/crypto/hash.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -71,12 +71,12 @@ namespace crypto {
return h;
}
- inline void cn_slow_hash(const void *data, std::size_t length, hash &hash, int variant = 0) {
- cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 0/*prehashed*/);
+ inline void cn_slow_hash(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
+ cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 0/*prehashed*/, height);
}
- inline void cn_slow_hash_prehashed(const void *data, std::size_t length, hash &hash, int variant = 0) {
- cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 1/*prehashed*/);
+ inline void cn_slow_hash_prehashed(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
+ cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 1/*prehashed*/, height);
}
inline void tree_hash(const hash *hashes, std::size_t count, hash &root_hash) {
diff --git a/src/crypto/initializer.h b/src/crypto/initializer.h
index 107988d2b..75d80f054 100644
--- a/src/crypto/initializer.h
+++ b/src/crypto/initializer.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/random.c b/src/crypto/random.c
index 9e1a70a2d..74b202661 100644
--- a/src/crypto/random.c
+++ b/src/crypto/random.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/random.h b/src/crypto/random.h
index 6468136cc..ccb9f4853 100644
--- a/src/crypto/random.h
+++ b/src/crypto/random.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/skein_port.h b/src/crypto/skein_port.h
index 8a1640e57..1ec07a4d1 100644
--- a/src/crypto/skein_port.h
+++ b/src/crypto/skein_port.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/slow-hash.c b/src/crypto/slow-hash.c
index ae0bd4e98..9dc6f5038 100644
--- a/src/crypto/slow-hash.c
+++ b/src/crypto/slow-hash.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -39,6 +39,11 @@
#include "hash-ops.h"
#include "oaes_lib.h"
#include "variant2_int_sqrt.h"
+#include "variant4_random_math.h"
+#include "CryptonightR_JIT.h"
+
+#include <errno.h>
+#include <string.h>
#define MEMORY (1 << 21) // 2MB scratchpad
#define ITER (1 << 20)
@@ -50,6 +55,41 @@
extern void aesb_single_round(const uint8_t *in, uint8_t *out, const uint8_t *expandedKey);
extern void aesb_pseudo_round(const uint8_t *in, uint8_t *out, const uint8_t *expandedKey);
+static void local_abort(const char *msg)
+{
+ fprintf(stderr, "%s\n", msg);
+#ifdef NDEBUG
+ _exit(1);
+#else
+ abort();
+#endif
+}
+
+volatile int use_v4_jit_flag = -1;
+
+static inline int use_v4_jit(void)
+{
+#if defined(__x86_64__)
+
+ if (use_v4_jit_flag != -1)
+ return use_v4_jit_flag;
+
+ const char *env = getenv("MONERO_USE_CNV4_JIT");
+ if (!env) {
+ use_v4_jit_flag = 0;
+ }
+ else if (!strcmp(env, "0") || !strcmp(env, "no")) {
+ use_v4_jit_flag = 0;
+ }
+ else {
+ use_v4_jit_flag = 1;
+ }
+ return use_v4_jit_flag;
+#else
+ return 0;
+#endif
+}
+
#define VARIANT1_1(p) \
do if (variant == 1) \
{ \
@@ -116,48 +156,74 @@ extern void aesb_pseudo_round(const uint8_t *in, uint8_t *out, const uint8_t *ex
#define VARIANT2_SHUFFLE_ADD_SSE2(base_ptr, offset) \
do if (variant >= 2) \
{ \
- const __m128i chunk1 = _mm_load_si128((__m128i *)((base_ptr) + ((offset) ^ 0x10))); \
+ __m128i chunk1 = _mm_load_si128((__m128i *)((base_ptr) + ((offset) ^ 0x10))); \
const __m128i chunk2 = _mm_load_si128((__m128i *)((base_ptr) + ((offset) ^ 0x20))); \
const __m128i chunk3 = _mm_load_si128((__m128i *)((base_ptr) + ((offset) ^ 0x30))); \
_mm_store_si128((__m128i *)((base_ptr) + ((offset) ^ 0x10)), _mm_add_epi64(chunk3, _b1)); \
_mm_store_si128((__m128i *)((base_ptr) + ((offset) ^ 0x20)), _mm_add_epi64(chunk1, _b)); \
_mm_store_si128((__m128i *)((base_ptr) + ((offset) ^ 0x30)), _mm_add_epi64(chunk2, _a)); \
+ if (variant >= 4) \
+ { \
+ chunk1 = _mm_xor_si128(chunk1, chunk2); \
+ _c = _mm_xor_si128(_c, chunk3); \
+ _c = _mm_xor_si128(_c, chunk1); \
+ } \
} while (0)
#define VARIANT2_SHUFFLE_ADD_NEON(base_ptr, offset) \
do if (variant >= 2) \
{ \
- const uint64x2_t chunk1 = vld1q_u64(U64((base_ptr) + ((offset) ^ 0x10))); \
+ uint64x2_t chunk1 = vld1q_u64(U64((base_ptr) + ((offset) ^ 0x10))); \
const uint64x2_t chunk2 = vld1q_u64(U64((base_ptr) + ((offset) ^ 0x20))); \
const uint64x2_t chunk3 = vld1q_u64(U64((base_ptr) + ((offset) ^ 0x30))); \
vst1q_u64(U64((base_ptr) + ((offset) ^ 0x10)), vaddq_u64(chunk3, vreinterpretq_u64_u8(_b1))); \
vst1q_u64(U64((base_ptr) + ((offset) ^ 0x20)), vaddq_u64(chunk1, vreinterpretq_u64_u8(_b))); \
vst1q_u64(U64((base_ptr) + ((offset) ^ 0x30)), vaddq_u64(chunk2, vreinterpretq_u64_u8(_a))); \
+ if (variant >= 4) \
+ { \
+ chunk1 = veorq_u64(chunk1, chunk2); \
+ _c = vreinterpretq_u8_u64(veorq_u64(vreinterpretq_u64_u8(_c), chunk3)); \
+ _c = vreinterpretq_u8_u64(veorq_u64(vreinterpretq_u64_u8(_c), chunk1)); \
+ } \
} while (0)
-#define VARIANT2_PORTABLE_SHUFFLE_ADD(base_ptr, offset) \
+#define VARIANT2_PORTABLE_SHUFFLE_ADD(out, a_, base_ptr, offset) \
do if (variant >= 2) \
{ \
uint64_t* chunk1 = U64((base_ptr) + ((offset) ^ 0x10)); \
uint64_t* chunk2 = U64((base_ptr) + ((offset) ^ 0x20)); \
uint64_t* chunk3 = U64((base_ptr) + ((offset) ^ 0x30)); \
\
- const uint64_t chunk1_old[2] = { chunk1[0], chunk1[1] }; \
+ uint64_t chunk1_old[2] = { SWAP64LE(chunk1[0]), SWAP64LE(chunk1[1]) }; \
+ const uint64_t chunk2_old[2] = { SWAP64LE(chunk2[0]), SWAP64LE(chunk2[1]) }; \
+ const uint64_t chunk3_old[2] = { SWAP64LE(chunk3[0]), SWAP64LE(chunk3[1]) }; \
\
uint64_t b1[2]; \
memcpy_swap64le(b1, b + 16, 2); \
- chunk1[0] = SWAP64LE(SWAP64LE(chunk3[0]) + b1[0]); \
- chunk1[1] = SWAP64LE(SWAP64LE(chunk3[1]) + b1[1]); \
+ chunk1[0] = SWAP64LE(chunk3_old[0] + b1[0]); \
+ chunk1[1] = SWAP64LE(chunk3_old[1] + b1[1]); \
\
uint64_t a0[2]; \
- memcpy_swap64le(a0, a, 2); \
- chunk3[0] = SWAP64LE(SWAP64LE(chunk2[0]) + a0[0]); \
- chunk3[1] = SWAP64LE(SWAP64LE(chunk2[1]) + a0[1]); \
+ memcpy_swap64le(a0, a_, 2); \
+ chunk3[0] = SWAP64LE(chunk2_old[0] + a0[0]); \
+ chunk3[1] = SWAP64LE(chunk2_old[1] + a0[1]); \
\
uint64_t b0[2]; \
memcpy_swap64le(b0, b, 2); \
- chunk2[0] = SWAP64LE(SWAP64LE(chunk1_old[0]) + b0[0]); \
+ chunk2[0] = SWAP64LE(chunk1_old[0] + b0[0]); \
chunk2[1] = SWAP64LE(SWAP64LE(chunk1_old[1]) + b0[1]); \
+ if (variant >= 4) \
+ { \
+ uint64_t out_copy[2]; \
+ memcpy_swap64le(out_copy, out, 2); \
+ chunk1_old[0] ^= chunk2_old[0]; \
+ chunk1_old[1] ^= chunk2_old[1]; \
+ out_copy[0] ^= chunk3_old[0]; \
+ out_copy[1] ^= chunk3_old[1]; \
+ out_copy[0] ^= chunk1_old[0]; \
+ out_copy[1] ^= chunk1_old[1]; \
+ memcpy_swap64le(out, out_copy, 2); \
+ } \
} while (0)
#define VARIANT2_INTEGER_MATH_DIVISION_STEP(b, ptr) \
@@ -172,7 +238,7 @@ extern void aesb_pseudo_round(const uint8_t *in, uint8_t *out, const uint8_t *ex
const uint64_t sqrt_input = SWAP64LE(((uint64_t*)(ptr))[0]) + division_result
#define VARIANT2_INTEGER_MATH_SSE2(b, ptr) \
- do if (variant >= 2) \
+ do if ((variant == 2) || (variant == 3)) \
{ \
VARIANT2_INTEGER_MATH_DIVISION_STEP(b, ptr); \
VARIANT2_INTEGER_MATH_SQRT_STEP_SSE2(); \
@@ -182,7 +248,7 @@ extern void aesb_pseudo_round(const uint8_t *in, uint8_t *out, const uint8_t *ex
#if defined DBL_MANT_DIG && (DBL_MANT_DIG >= 50)
// double precision floating point type has enough bits of precision on current platform
#define VARIANT2_PORTABLE_INTEGER_MATH(b, ptr) \
- do if (variant >= 2) \
+ do if ((variant == 2) || (variant == 3)) \
{ \
VARIANT2_INTEGER_MATH_DIVISION_STEP(b, ptr); \
VARIANT2_INTEGER_MATH_SQRT_STEP_FP64(); \
@@ -192,7 +258,7 @@ extern void aesb_pseudo_round(const uint8_t *in, uint8_t *out, const uint8_t *ex
// double precision floating point type is not good enough on current platform
// fall back to the reference code (integer only)
#define VARIANT2_PORTABLE_INTEGER_MATH(b, ptr) \
- do if (variant >= 2) \
+ do if ((variant == 2) || (variant == 3)) \
{ \
VARIANT2_INTEGER_MATH_DIVISION_STEP(b, ptr); \
VARIANT2_INTEGER_MATH_SQRT_STEP_REF(); \
@@ -200,13 +266,13 @@ extern void aesb_pseudo_round(const uint8_t *in, uint8_t *out, const uint8_t *ex
#endif
#define VARIANT2_2_PORTABLE() \
- if (variant >= 2) { \
+ if (variant == 2 || variant == 3) { \
xor_blocks(long_state + (j ^ 0x10), d); \
xor_blocks(d, long_state + (j ^ 0x20)); \
}
#define VARIANT2_2() \
- do if (variant >= 2) \
+ do if (variant == 2 || variant == 3) \
{ \
*U64(hp_state + (j ^ 0x10)) ^= SWAP64LE(hi); \
*(U64(hp_state + (j ^ 0x10)) + 1) ^= SWAP64LE(lo); \
@@ -214,6 +280,68 @@ extern void aesb_pseudo_round(const uint8_t *in, uint8_t *out, const uint8_t *ex
lo ^= SWAP64LE(*(U64(hp_state + (j ^ 0x20)) + 1)); \
} while (0)
+#define V4_REG_LOAD(dst, src) \
+ do { \
+ memcpy((dst), (src), sizeof(v4_reg)); \
+ if (sizeof(v4_reg) == sizeof(uint32_t)) \
+ *(dst) = SWAP32LE(*(dst)); \
+ else \
+ *(dst) = SWAP64LE(*(dst)); \
+ } while (0)
+
+#define VARIANT4_RANDOM_MATH_INIT() \
+ v4_reg r[9]; \
+ struct V4_Instruction code[NUM_INSTRUCTIONS_MAX + 1]; \
+ int jit = use_v4_jit(); \
+ do if (variant >= 4) \
+ { \
+ for (int i = 0; i < 4; ++i) \
+ V4_REG_LOAD(r + i, (uint8_t*)(state.hs.w + 12) + sizeof(v4_reg) * i); \
+ v4_random_math_init(code, height); \
+ if (jit) \
+ { \
+ int ret = v4_generate_JIT_code(code, hp_jitfunc, 4096); \
+ if (ret < 0) \
+ local_abort("Error generating CryptonightR code"); \
+ } \
+ } while (0)
+
+#define VARIANT4_RANDOM_MATH(a, b, r, _b, _b1) \
+ do if (variant >= 4) \
+ { \
+ uint64_t t[2]; \
+ memcpy(t, b, sizeof(uint64_t)); \
+ \
+ if (sizeof(v4_reg) == sizeof(uint32_t)) \
+ t[0] ^= SWAP64LE((r[0] + r[1]) | ((uint64_t)(r[2] + r[3]) << 32)); \
+ else \
+ t[0] ^= SWAP64LE((r[0] + r[1]) ^ (r[2] + r[3])); \
+ \
+ memcpy(b, t, sizeof(uint64_t)); \
+ \
+ V4_REG_LOAD(r + 4, a); \
+ V4_REG_LOAD(r + 5, (uint64_t*)(a) + 1); \
+ V4_REG_LOAD(r + 6, _b); \
+ V4_REG_LOAD(r + 7, _b1); \
+ V4_REG_LOAD(r + 8, (uint64_t*)(_b1) + 1); \
+ \
+ if (jit) \
+ (*hp_jitfunc)(r); \
+ else \
+ v4_random_math(code, r); \
+ \
+ memcpy(t, a, sizeof(uint64_t) * 2); \
+ \
+ if (sizeof(v4_reg) == sizeof(uint32_t)) { \
+ t[0] ^= SWAP64LE(r[2] | ((uint64_t)(r[3]) << 32)); \
+ t[1] ^= SWAP64LE(r[0] | ((uint64_t)(r[1]) << 32)); \
+ } else { \
+ t[0] ^= SWAP64LE(r[2] ^ r[3]); \
+ t[1] ^= SWAP64LE(r[0] ^ r[1]); \
+ } \
+ memcpy(a, t, sizeof(uint64_t) * 2); \
+ } while (0)
+
#if !defined NO_AES && (defined(__x86_64__) || (defined(_MSC_VER) && defined(_WIN64)))
// Optimised code below, uses x86-specific intrinsics, SSE2, AES-NI
@@ -298,6 +426,7 @@ extern void aesb_pseudo_round(const uint8_t *in, uint8_t *out, const uint8_t *ex
p = U64(&hp_state[j]); \
b[0] = p[0]; b[1] = p[1]; \
VARIANT2_INTEGER_MATH_SSE2(b, c); \
+ VARIANT4_RANDOM_MATH(a, b, r, &_b, &_b1); \
__mul(); \
VARIANT2_2(); \
VARIANT2_SHUFFLE_ADD_SSE2(hp_state, j); \
@@ -329,6 +458,9 @@ union cn_slow_hash_state
THREADV uint8_t *hp_state = NULL;
THREADV int hp_allocated = 0;
+THREADV v4_random_math_JIT_func hp_jitfunc = NULL;
+THREADV uint8_t *hp_jitfunc_memory = NULL;
+THREADV int hp_jitfunc_allocated = 0;
#if defined(_MSC_VER)
#define cpuid(info,x) __cpuidex(info,x,0)
@@ -638,6 +770,33 @@ void slow_hash_allocate_state(void)
hp_allocated = 0;
hp_state = (uint8_t *) malloc(MEMORY);
}
+
+
+#if defined(_MSC_VER) || defined(__MINGW32__)
+ hp_jitfunc_memory = (uint8_t *) VirtualAlloc(hp_jitfunc_memory, 4096 + 4095,
+ MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
+#else
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || \
+ defined(__DragonFly__) || defined(__NetBSD__)
+ hp_jitfunc_memory = mmap(0, 4096 + 4095, PROT_READ | PROT_WRITE | PROT_EXEC,
+ MAP_PRIVATE | MAP_ANON, 0, 0);
+#else
+ hp_jitfunc_memory = mmap(0, 4096 + 4095, PROT_READ | PROT_WRITE | PROT_EXEC,
+ MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+#endif
+ if(hp_jitfunc_memory == MAP_FAILED)
+ hp_jitfunc_memory = NULL;
+#endif
+ hp_jitfunc_allocated = 1;
+ if (hp_jitfunc_memory == NULL)
+ {
+ hp_jitfunc_allocated = 0;
+ hp_jitfunc_memory = malloc(4096 + 4095);
+ }
+ hp_jitfunc = (v4_random_math_JIT_func)((size_t)(hp_jitfunc_memory + 4095) & ~4095);
+#if !(defined(_MSC_VER) || defined(__MINGW32__))
+ mprotect(hp_jitfunc, 4096, PROT_READ | PROT_WRITE | PROT_EXEC);
+#endif
}
/**
@@ -660,8 +819,22 @@ void slow_hash_free_state(void)
#endif
}
+ if(!hp_jitfunc_allocated)
+ free(hp_jitfunc_memory);
+ else
+ {
+#if defined(_MSC_VER) || defined(__MINGW32__)
+ VirtualFree(hp_jitfunc_memory, 0, MEM_RELEASE);
+#else
+ munmap(hp_jitfunc_memory, 4096 + 4095);
+#endif
+ }
+
hp_state = NULL;
hp_allocated = 0;
+ hp_jitfunc = NULL;
+ hp_jitfunc_memory = NULL;
+ hp_jitfunc_allocated = 0;
}
/**
@@ -694,7 +867,7 @@ void slow_hash_free_state(void)
* @param length the length in bytes of the data
* @param hash a pointer to a buffer in which the final 256 bit hash will be stored
*/
-void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int prehashed)
+void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int prehashed, uint64_t height)
{
RDATA_ALIGN16 uint8_t expandedKey[240]; /* These buffers are aligned to use later with SSE functions */
@@ -730,6 +903,7 @@ void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int
VARIANT1_INIT64();
VARIANT2_INIT64();
+ VARIANT4_RANDOM_MATH_INIT();
/* CryptoNight Step 2: Iteratively encrypt the results from Keccak to fill
* the 2MB large random access buffer.
@@ -855,6 +1029,8 @@ void slow_hash_free_state(void)
#define U64(x) ((uint64_t *) (x))
+#define hp_jitfunc ((v4_random_math_JIT_func)NULL)
+
STATIC INLINE void xor64(uint64_t *a, const uint64_t b)
{
*a ^= b;
@@ -901,6 +1077,7 @@ union cn_slow_hash_state
p = U64(&hp_state[j]); \
b[0] = p[0]; b[1] = p[1]; \
VARIANT2_PORTABLE_INTEGER_MATH(b, c); \
+ VARIANT4_RANDOM_MATH(a, b, r, &_b, &_b1); \
__mul(); \
VARIANT2_2(); \
VARIANT2_SHUFFLE_ADD_NEON(hp_state, j); \
@@ -1063,7 +1240,7 @@ STATIC INLINE void aligned_free(void *ptr)
}
#endif /* FORCE_USE_HEAP */
-void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int prehashed)
+void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int prehashed, uint64_t height)
{
RDATA_ALIGN16 uint8_t expandedKey[240];
@@ -1100,6 +1277,7 @@ void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int
VARIANT1_INIT64();
VARIANT2_INIT64();
+ VARIANT4_RANDOM_MATH_INIT();
/* CryptoNight Step 2: Iteratively encrypt the results from Keccak to fill
* the 2MB large random access buffer.
@@ -1278,10 +1456,11 @@ STATIC INLINE void xor_blocks(uint8_t* a, const uint8_t* b)
U64(a)[1] ^= U64(b)[1];
}
-void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int prehashed)
+void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int prehashed, uint64_t height)
{
uint8_t text[INIT_SIZE_BYTE];
uint8_t a[AES_BLOCK_SIZE];
+ uint8_t a1[AES_BLOCK_SIZE];
uint8_t b[AES_BLOCK_SIZE * 2];
uint8_t c[AES_BLOCK_SIZE];
uint8_t c1[AES_BLOCK_SIZE];
@@ -1317,6 +1496,7 @@ void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int
VARIANT1_INIT64();
VARIANT2_INIT64();
+ VARIANT4_RANDOM_MATH_INIT();
// use aligned data
memcpy(expandedKey, aes_ctx->key->exp_data, aes_ctx->key->exp_data_len);
@@ -1340,10 +1520,10 @@ void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int
// Iteration 1
j = state_index(a);
p = &long_state[j];
- aesb_single_round(p, p, a);
- copy_block(c1, p);
+ aesb_single_round(p, c1, a);
- VARIANT2_PORTABLE_SHUFFLE_ADD(long_state, j);
+ VARIANT2_PORTABLE_SHUFFLE_ADD(c1, a, long_state, j);
+ copy_block(p, c1);
xor_blocks(p, b);
VARIANT1_1(p);
@@ -1352,13 +1532,15 @@ void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int
p = &long_state[j];
copy_block(c, p);
+ copy_block(a1, a);
VARIANT2_PORTABLE_INTEGER_MATH(c, c1);
+ VARIANT4_RANDOM_MATH(a1, c, r, b, b + AES_BLOCK_SIZE);
mul(c1, c, d);
VARIANT2_2_PORTABLE();
- VARIANT2_PORTABLE_SHUFFLE_ADD(long_state, j);
- sum_half_blocks(a, d);
- swap_blocks(a, c);
- xor_blocks(a, c);
+ VARIANT2_PORTABLE_SHUFFLE_ADD(c1, a, long_state, j);
+ sum_half_blocks(a1, d);
+ swap_blocks(a1, c);
+ xor_blocks(a1, c);
VARIANT1_2(U64(c) + 1);
copy_block(p, c);
@@ -1366,6 +1548,7 @@ void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int
copy_block(b + AES_BLOCK_SIZE, b);
}
copy_block(b, c1);
+ copy_block(a, a1);
}
memcpy(text, state.init, INIT_SIZE_BYTE);
@@ -1393,6 +1576,8 @@ void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int
#else
// Portable implementation as a fallback
+#define hp_jitfunc ((v4_random_math_JIT_func)NULL)
+
void slow_hash_allocate_state(void)
{
// Do nothing, this is just to maintain compatibility with the upgraded slow-hash.c
@@ -1476,7 +1661,7 @@ union cn_slow_hash_state {
};
#pragma pack(pop)
-void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int prehashed) {
+void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int prehashed, uint64_t height) {
#ifndef FORCE_USE_HEAP
uint8_t long_state[MEMORY];
#else
@@ -1486,6 +1671,7 @@ void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int
union cn_slow_hash_state state;
uint8_t text[INIT_SIZE_BYTE];
uint8_t a[AES_BLOCK_SIZE];
+ uint8_t a1[AES_BLOCK_SIZE];
uint8_t b[AES_BLOCK_SIZE * 2];
uint8_t c1[AES_BLOCK_SIZE];
uint8_t c2[AES_BLOCK_SIZE];
@@ -1505,6 +1691,7 @@ void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int
VARIANT1_PORTABLE_INIT();
VARIANT2_PORTABLE_INIT();
+ VARIANT4_RANDOM_MATH_INIT();
oaes_key_import_data(aes_ctx, aes_key, AES_KEY_SIZE);
for (i = 0; i < MEMORY / INIT_SIZE_BYTE; i++) {
@@ -1528,7 +1715,7 @@ void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int
j = e2i(a, MEMORY / AES_BLOCK_SIZE) * AES_BLOCK_SIZE;
copy_block(c1, &long_state[j]);
aesb_single_round(c1, c1, a);
- VARIANT2_PORTABLE_SHUFFLE_ADD(long_state, j);
+ VARIANT2_PORTABLE_SHUFFLE_ADD(c1, a, long_state, j);
copy_block(&long_state[j], c1);
xor_blocks(&long_state[j], b);
assert(j == e2i(a, MEMORY / AES_BLOCK_SIZE) * AES_BLOCK_SIZE);
@@ -1536,22 +1723,22 @@ void cn_slow_hash(const void *data, size_t length, char *hash, int variant, int
/* Iteration 2 */
j = e2i(c1, MEMORY / AES_BLOCK_SIZE) * AES_BLOCK_SIZE;
copy_block(c2, &long_state[j]);
+ copy_block(a1, a);
VARIANT2_PORTABLE_INTEGER_MATH(c2, c1);
+ VARIANT4_RANDOM_MATH(a1, c2, r, b, b + AES_BLOCK_SIZE);
mul(c1, c2, d);
VARIANT2_2_PORTABLE();
- VARIANT2_PORTABLE_SHUFFLE_ADD(long_state, j);
- swap_blocks(a, c1);
- sum_half_blocks(c1, d);
- swap_blocks(c1, c2);
- xor_blocks(c1, c2);
+ VARIANT2_PORTABLE_SHUFFLE_ADD(c1, a, long_state, j);
+ sum_half_blocks(a1, d);
+ swap_blocks(a1, c2);
+ xor_blocks(a1, c2);
VARIANT1_2(c2 + 8);
copy_block(&long_state[j], c2);
- assert(j == e2i(a, MEMORY / AES_BLOCK_SIZE) * AES_BLOCK_SIZE);
if (variant >= 2) {
copy_block(b + AES_BLOCK_SIZE, b);
}
- copy_block(b, a);
- copy_block(a, c1);
+ copy_block(b, c1);
+ copy_block(a, a1);
}
memcpy(text, state.init, INIT_SIZE_BYTE);
diff --git a/src/crypto/tree-hash.c b/src/crypto/tree-hash.c
index b2dc3ffb2..ce4b6cb75 100644
--- a/src/crypto/tree-hash.c
+++ b/src/crypto/tree-hash.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/crypto/variant4_random_math.h b/src/crypto/variant4_random_math.h
new file mode 100644
index 000000000..f3e41a001
--- /dev/null
+++ b/src/crypto/variant4_random_math.h
@@ -0,0 +1,441 @@
+#ifndef VARIANT4_RANDOM_MATH_H
+#define VARIANT4_RANDOM_MATH_H
+
+// Register size can be configured to either 32 bit (uint32_t) or 64 bit (uint64_t)
+typedef uint32_t v4_reg;
+
+enum V4_Settings
+{
+ // Generate code with minimal theoretical latency = 45 cycles, which is equivalent to 15 multiplications
+ TOTAL_LATENCY = 15 * 3,
+
+ // Always generate at least 60 instructions
+ NUM_INSTRUCTIONS_MIN = 60,
+
+ // Never generate more than 70 instructions (final RET instruction doesn't count here)
+ NUM_INSTRUCTIONS_MAX = 70,
+
+ // Available ALUs for MUL
+ // Modern CPUs typically have only 1 ALU which can do multiplications
+ ALU_COUNT_MUL = 1,
+
+ // Total available ALUs
+ // Modern CPUs have 4 ALUs, but we use only 3 because random math executes together with other main loop code
+ ALU_COUNT = 3,
+};
+
+enum V4_InstructionList
+{
+ MUL, // a*b
+ ADD, // a+b + C, C is an unsigned 32-bit constant
+ SUB, // a-b
+ ROR, // rotate right "a" by "b & 31" bits
+ ROL, // rotate left "a" by "b & 31" bits
+ XOR, // a^b
+ RET, // finish execution
+ V4_INSTRUCTION_COUNT = RET,
+};
+
+// V4_InstructionDefinition is used to generate code from random data
+// Every random sequence of bytes is a valid code
+//
+// There are 9 registers in total:
+// - 4 variable registers
+// - 5 constant registers initialized from loop variables
+// This is why dst_index is 2 bits
+enum V4_InstructionDefinition
+{
+ V4_OPCODE_BITS = 3,
+ V4_DST_INDEX_BITS = 2,
+ V4_SRC_INDEX_BITS = 3,
+};
+
+struct V4_Instruction
+{
+ uint8_t opcode;
+ uint8_t dst_index;
+ uint8_t src_index;
+ uint32_t C;
+};
+
+#ifndef FORCEINLINE
+#if defined(__GNUC__)
+#define FORCEINLINE __attribute__((always_inline)) inline
+#elif defined(_MSC_VER)
+#define FORCEINLINE __forceinline
+#else
+#define FORCEINLINE inline
+#endif
+#endif
+
+#ifndef UNREACHABLE_CODE
+#if defined(__GNUC__)
+#define UNREACHABLE_CODE __builtin_unreachable()
+#elif defined(_MSC_VER)
+#define UNREACHABLE_CODE __assume(false)
+#else
+#define UNREACHABLE_CODE
+#endif
+#endif
+
+// Random math interpreter's loop is fully unrolled and inlined to achieve 100% branch prediction on CPU:
+// every switch-case will point to the same destination on every iteration of Cryptonight main loop
+//
+// This is about as fast as it can get without using low-level machine code generation
+static FORCEINLINE void v4_random_math(const struct V4_Instruction* code, v4_reg* r)
+{
+ enum
+ {
+ REG_BITS = sizeof(v4_reg) * 8,
+ };
+
+#define V4_EXEC(i) \
+ { \
+ const struct V4_Instruction* op = code + i; \
+ const v4_reg src = r[op->src_index]; \
+ v4_reg* dst = r + op->dst_index; \
+ switch (op->opcode) \
+ { \
+ case MUL: \
+ *dst *= src; \
+ break; \
+ case ADD: \
+ *dst += src + op->C; \
+ break; \
+ case SUB: \
+ *dst -= src; \
+ break; \
+ case ROR: \
+ { \
+ const uint32_t shift = src % REG_BITS; \
+ *dst = (*dst >> shift) | (*dst << ((REG_BITS - shift) % REG_BITS)); \
+ } \
+ break; \
+ case ROL: \
+ { \
+ const uint32_t shift = src % REG_BITS; \
+ *dst = (*dst << shift) | (*dst >> ((REG_BITS - shift) % REG_BITS)); \
+ } \
+ break; \
+ case XOR: \
+ *dst ^= src; \
+ break; \
+ case RET: \
+ return; \
+ default: \
+ UNREACHABLE_CODE; \
+ break; \
+ } \
+ }
+
+#define V4_EXEC_10(j) \
+ V4_EXEC(j + 0) \
+ V4_EXEC(j + 1) \
+ V4_EXEC(j + 2) \
+ V4_EXEC(j + 3) \
+ V4_EXEC(j + 4) \
+ V4_EXEC(j + 5) \
+ V4_EXEC(j + 6) \
+ V4_EXEC(j + 7) \
+ V4_EXEC(j + 8) \
+ V4_EXEC(j + 9)
+
+ // Generated program can have 60 + a few more (usually 2-3) instructions to achieve required latency
+ // I've checked all block heights < 10,000,000 and here is the distribution of program sizes:
+ //
+ // 60 27960
+ // 61 105054
+ // 62 2452759
+ // 63 5115997
+ // 64 1022269
+ // 65 1109635
+ // 66 153145
+ // 67 8550
+ // 68 4529
+ // 69 102
+
+ // Unroll 70 instructions here
+ V4_EXEC_10(0); // instructions 0-9
+ V4_EXEC_10(10); // instructions 10-19
+ V4_EXEC_10(20); // instructions 20-29
+ V4_EXEC_10(30); // instructions 30-39
+ V4_EXEC_10(40); // instructions 40-49
+ V4_EXEC_10(50); // instructions 50-59
+ V4_EXEC_10(60); // instructions 60-69
+
+#undef V4_EXEC_10
+#undef V4_EXEC
+}
+
+// If we don't have enough data available, generate more
+static FORCEINLINE void check_data(size_t* data_index, const size_t bytes_needed, int8_t* data, const size_t data_size)
+{
+ if (*data_index + bytes_needed > data_size)
+ {
+ hash_extra_blake(data, data_size, (char*) data);
+ *data_index = 0;
+ }
+}
+
+// Generates as many random math operations as possible with given latency and ALU restrictions
+// "code" array must have space for NUM_INSTRUCTIONS_MAX+1 instructions
+static inline int v4_random_math_init(struct V4_Instruction* code, const uint64_t height)
+{
+ // MUL is 3 cycles, 3-way addition and rotations are 2 cycles, SUB/XOR are 1 cycle
+ // These latencies match real-life instruction latencies for Intel CPUs starting from Sandy Bridge and up to Skylake/Coffee lake
+ //
+ // AMD Ryzen has the same latencies except 1-cycle ROR/ROL, so it'll be a bit faster than Intel Sandy Bridge and newer processors
+ // Surprisingly, Intel Nehalem also has 1-cycle ROR/ROL, so it'll also be faster than Intel Sandy Bridge and newer processors
+ // AMD Bulldozer has 4 cycles latency for MUL (slower than Intel) and 1 cycle for ROR/ROL (faster than Intel), so average performance will be the same
+ // Source: https://www.agner.org/optimize/instruction_tables.pdf
+ const int op_latency[V4_INSTRUCTION_COUNT] = { 3, 2, 1, 2, 2, 1 };
+
+ // Instruction latencies for theoretical ASIC implementation
+ const int asic_op_latency[V4_INSTRUCTION_COUNT] = { 3, 1, 1, 1, 1, 1 };
+
+ // Available ALUs for each instruction
+ const int op_ALUs[V4_INSTRUCTION_COUNT] = { ALU_COUNT_MUL, ALU_COUNT, ALU_COUNT, ALU_COUNT, ALU_COUNT, ALU_COUNT };
+
+ int8_t data[32];
+ memset(data, 0, sizeof(data));
+ uint64_t tmp = SWAP64LE(height);
+ memcpy(data, &tmp, sizeof(uint64_t));
+ data[20] = -38; // change seed
+
+ // Set data_index past the last byte in data
+ // to trigger full data update with blake hash
+ // before we start using it
+ size_t data_index = sizeof(data);
+
+ int code_size;
+
+ // There is a small chance (1.8%) that register R8 won't be used in the generated program
+ // So we keep track of it and try again if it's not used
+ bool r8_used;
+ do {
+ int latency[9];
+ int asic_latency[9];
+
+ // Tracks previous instruction and value of the source operand for registers R0-R3 throughout code execution
+ // byte 0: current value of the destination register
+ // byte 1: instruction opcode
+ // byte 2: current value of the source register
+ //
+ // Registers R4-R8 are constant and are treated as having the same value because when we do
+ // the same operation twice with two constant source registers, it can be optimized into a single operation
+ uint32_t inst_data[9] = { 0, 1, 2, 3, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF };
+
+ bool alu_busy[TOTAL_LATENCY + 1][ALU_COUNT];
+ bool is_rotation[V4_INSTRUCTION_COUNT];
+ bool rotated[4];
+ int rotate_count = 0;
+
+ memset(latency, 0, sizeof(latency));
+ memset(asic_latency, 0, sizeof(asic_latency));
+ memset(alu_busy, 0, sizeof(alu_busy));
+ memset(is_rotation, 0, sizeof(is_rotation));
+ memset(rotated, 0, sizeof(rotated));
+ is_rotation[ROR] = true;
+ is_rotation[ROL] = true;
+
+ int num_retries = 0;
+ code_size = 0;
+
+ int total_iterations = 0;
+ r8_used = false;
+
+ // Generate random code to achieve minimal required latency for our abstract CPU
+ // Try to get this latency for all 4 registers
+ while (((latency[0] < TOTAL_LATENCY) || (latency[1] < TOTAL_LATENCY) || (latency[2] < TOTAL_LATENCY) || (latency[3] < TOTAL_LATENCY)) && (num_retries < 64))
+ {
+ // Fail-safe to guarantee loop termination
+ ++total_iterations;
+ if (total_iterations > 256)
+ break;
+
+ check_data(&data_index, 1, data, sizeof(data));
+
+ const uint8_t c = ((uint8_t*)data)[data_index++];
+
+ // MUL = opcodes 0-2
+ // ADD = opcode 3
+ // SUB = opcode 4
+ // ROR/ROL = opcode 5, shift direction is selected randomly
+ // XOR = opcodes 6-7
+ uint8_t opcode = c & ((1 << V4_OPCODE_BITS) - 1);
+ if (opcode == 5)
+ {
+ check_data(&data_index, 1, data, sizeof(data));
+ opcode = (data[data_index++] >= 0) ? ROR : ROL;
+ }
+ else if (opcode >= 6)
+ {
+ opcode = XOR;
+ }
+ else
+ {
+ opcode = (opcode <= 2) ? MUL : (opcode - 2);
+ }
+
+ uint8_t dst_index = (c >> V4_OPCODE_BITS) & ((1 << V4_DST_INDEX_BITS) - 1);
+ uint8_t src_index = (c >> (V4_OPCODE_BITS + V4_DST_INDEX_BITS)) & ((1 << V4_SRC_INDEX_BITS) - 1);
+
+ const int a = dst_index;
+ int b = src_index;
+
+ // Don't do ADD/SUB/XOR with the same register
+ if (((opcode == ADD) || (opcode == SUB) || (opcode == XOR)) && (a == b))
+ {
+ // Use register R8 as source instead
+ b = 8;
+ src_index = 8;
+ }
+
+ // Don't do rotation with the same destination twice because it's equal to a single rotation
+ if (is_rotation[opcode] && rotated[a])
+ {
+ continue;
+ }
+
+ // Don't do the same instruction (except MUL) with the same source value twice because all other cases can be optimized:
+ // 2xADD(a, b, C) = ADD(a, b*2, C1+C2), same for SUB and rotations
+ // 2xXOR(a, b) = NOP
+ if ((opcode != MUL) && ((inst_data[a] & 0xFFFF00) == (opcode << 8) + ((inst_data[b] & 255) << 16)))
+ {
+ continue;
+ }
+
+ // Find which ALU is available (and when) for this instruction
+ int next_latency = (latency[a] > latency[b]) ? latency[a] : latency[b];
+ int alu_index = -1;
+ while (next_latency < TOTAL_LATENCY)
+ {
+ for (int i = op_ALUs[opcode] - 1; i >= 0; --i)
+ {
+ if (!alu_busy[next_latency][i])
+ {
+ // ADD is implemented as two 1-cycle instructions on a real CPU, so do an additional availability check
+ if ((opcode == ADD) && alu_busy[next_latency + 1][i])
+ {
+ continue;
+ }
+
+ // Rotation can only start when previous rotation is finished, so do an additional availability check
+ if (is_rotation[opcode] && (next_latency < rotate_count * op_latency[opcode]))
+ {
+ continue;
+ }
+
+ alu_index = i;
+ break;
+ }
+ }
+ if (alu_index >= 0)
+ {
+ break;
+ }
+ ++next_latency;
+ }
+
+ // Don't generate instructions that leave some register unchanged for more than 7 cycles
+ if (next_latency > latency[a] + 7)
+ {
+ continue;
+ }
+
+ next_latency += op_latency[opcode];
+
+ if (next_latency <= TOTAL_LATENCY)
+ {
+ if (is_rotation[opcode])
+ {
+ ++rotate_count;
+ }
+
+ // Mark ALU as busy only for the first cycle when it starts executing the instruction because ALUs are fully pipelined
+ alu_busy[next_latency - op_latency[opcode]][alu_index] = true;
+ latency[a] = next_latency;
+
+ // ASIC is supposed to have enough ALUs to run as many independent instructions per cycle as possible, so latency calculation for ASIC is simple
+ asic_latency[a] = ((asic_latency[a] > asic_latency[b]) ? asic_latency[a] : asic_latency[b]) + asic_op_latency[opcode];
+
+ rotated[a] = is_rotation[opcode];
+
+ inst_data[a] = code_size + (opcode << 8) + ((inst_data[b] & 255) << 16);
+
+ code[code_size].opcode = opcode;
+ code[code_size].dst_index = dst_index;
+ code[code_size].src_index = src_index;
+ code[code_size].C = 0;
+
+ if (src_index == 8)
+ {
+ r8_used = true;
+ }
+
+ if (opcode == ADD)
+ {
+ // ADD instruction is implemented as two 1-cycle instructions on a real CPU, so mark ALU as busy for the next cycle too
+ alu_busy[next_latency - op_latency[opcode] + 1][alu_index] = true;
+
+ // ADD instruction requires 4 more random bytes for 32-bit constant "C" in "a = a + b + C"
+ check_data(&data_index, sizeof(uint32_t), data, sizeof(data));
+ uint32_t t;
+ memcpy(&t, data + data_index, sizeof(uint32_t));
+ code[code_size].C = SWAP32LE(t);
+ data_index += sizeof(uint32_t);
+ }
+
+ ++code_size;
+ if (code_size >= NUM_INSTRUCTIONS_MIN)
+ {
+ break;
+ }
+ }
+ else
+ {
+ ++num_retries;
+ }
+ }
+
+ // ASIC has more execution resources and can extract as much parallelism from the code as possible
+ // We need to add a few more MUL and ROR instructions to achieve minimal required latency for ASIC
+ // Get this latency for at least 1 of the 4 registers
+ const int prev_code_size = code_size;
+ while ((code_size < NUM_INSTRUCTIONS_MAX) && (asic_latency[0] < TOTAL_LATENCY) && (asic_latency[1] < TOTAL_LATENCY) && (asic_latency[2] < TOTAL_LATENCY) && (asic_latency[3] < TOTAL_LATENCY))
+ {
+ int min_idx = 0;
+ int max_idx = 0;
+ for (int i = 1; i < 4; ++i)
+ {
+ if (asic_latency[i] < asic_latency[min_idx]) min_idx = i;
+ if (asic_latency[i] > asic_latency[max_idx]) max_idx = i;
+ }
+
+ const uint8_t pattern[3] = { ROR, MUL, MUL };
+ const uint8_t opcode = pattern[(code_size - prev_code_size) % 3];
+ latency[min_idx] = latency[max_idx] + op_latency[opcode];
+ asic_latency[min_idx] = asic_latency[max_idx] + asic_op_latency[opcode];
+
+ code[code_size].opcode = opcode;
+ code[code_size].dst_index = min_idx;
+ code[code_size].src_index = max_idx;
+ code[code_size].C = 0;
+ ++code_size;
+ }
+
+ // There is ~98.15% chance that loop condition is false, so this loop will execute only 1 iteration most of the time
+ // It never does more than 4 iterations for all block heights < 10,000,000
+ } while (!r8_used || (code_size < NUM_INSTRUCTIONS_MIN) || (code_size > NUM_INSTRUCTIONS_MAX));
+
+ // It's guaranteed that NUM_INSTRUCTIONS_MIN <= code_size <= NUM_INSTRUCTIONS_MAX here
+ // Add final instruction to stop the interpreter
+ code[code_size].opcode = RET;
+ code[code_size].dst_index = 0;
+ code[code_size].src_index = 0;
+ code[code_size].C = 0;
+
+ return code_size;
+}
+
+#endif
diff --git a/src/cryptonote_basic/CMakeLists.txt b/src/cryptonote_basic/CMakeLists.txt
index 21445959d..5bb56e083 100644
--- a/src/cryptonote_basic/CMakeLists.txt
+++ b/src/cryptonote_basic/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/src/cryptonote_basic/account.cpp b/src/cryptonote_basic/account.cpp
index edbc2c561..a9aec163b 100644
--- a/src/cryptonote_basic/account.cpp
+++ b/src/cryptonote_basic/account.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/cryptonote_basic/account.h b/src/cryptonote_basic/account.h
index 021f84029..abf751b6e 100644
--- a/src/cryptonote_basic/account.h
+++ b/src/cryptonote_basic/account.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/cryptonote_basic/account_boost_serialization.h b/src/cryptonote_basic/account_boost_serialization.h
index 7379d787f..320a960dc 100644
--- a/src/cryptonote_basic/account_boost_serialization.h
+++ b/src/cryptonote_basic/account_boost_serialization.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/cryptonote_basic/blobdatatype.h b/src/cryptonote_basic/blobdatatype.h
index 82484c0a8..20f6b2421 100644
--- a/src/cryptonote_basic/blobdatatype.h
+++ b/src/cryptonote_basic/blobdatatype.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/cryptonote_basic/connection_context.h b/src/cryptonote_basic/connection_context.h
index 112c13049..b2eeb23b3 100644
--- a/src/cryptonote_basic/connection_context.h
+++ b/src/cryptonote_basic/connection_context.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/cryptonote_basic/cryptonote_basic.h b/src/cryptonote_basic/cryptonote_basic.h
index c9c783a56..03caafbb0 100644
--- a/src/cryptonote_basic/cryptonote_basic.h
+++ b/src/cryptonote_basic/cryptonote_basic.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -152,6 +152,10 @@ namespace cryptonote
};
+ template<typename T> static inline unsigned int getpos(T &ar) { return 0; }
+ template<> inline unsigned int getpos(binary_archive<true> &ar) { return ar.stream().tellp(); }
+ template<> inline unsigned int getpos(binary_archive<false> &ar) { return ar.stream().tellg(); }
+
class transaction_prefix
{
@@ -203,9 +207,12 @@ namespace cryptonote
bool pruned;
+ std::atomic<unsigned int> unprunable_size;
+ std::atomic<unsigned int> prefix_size;
+
transaction();
- transaction(const transaction &t): transaction_prefix(t), hash_valid(false), blob_size_valid(false), signatures(t.signatures), rct_signatures(t.rct_signatures), pruned(t.pruned) { if (t.is_hash_valid()) { hash = t.hash; set_hash_valid(true); } if (t.is_blob_size_valid()) { blob_size = t.blob_size; set_blob_size_valid(true); } }
- transaction &operator=(const transaction &t) { transaction_prefix::operator=(t); set_hash_valid(false); set_blob_size_valid(false); signatures = t.signatures; rct_signatures = t.rct_signatures; if (t.is_hash_valid()) { hash = t.hash; set_hash_valid(true); } if (t.is_blob_size_valid()) { blob_size = t.blob_size; set_blob_size_valid(true); } pruned = t.pruned; return *this; }
+ transaction(const transaction &t): transaction_prefix(t), hash_valid(false), blob_size_valid(false), signatures(t.signatures), rct_signatures(t.rct_signatures), pruned(t.pruned), unprunable_size(t.unprunable_size.load()), prefix_size(t.prefix_size.load()) { if (t.is_hash_valid()) { hash = t.hash; set_hash_valid(true); } if (t.is_blob_size_valid()) { blob_size = t.blob_size; set_blob_size_valid(true); } }
+ transaction &operator=(const transaction &t) { transaction_prefix::operator=(t); set_hash_valid(false); set_blob_size_valid(false); signatures = t.signatures; rct_signatures = t.rct_signatures; if (t.is_hash_valid()) { hash = t.hash; set_hash_valid(true); } if (t.is_blob_size_valid()) { blob_size = t.blob_size; set_blob_size_valid(true); } pruned = t.pruned; unprunable_size = t.unprunable_size.load(); prefix_size = t.prefix_size.load(); return *this; }
virtual ~transaction();
void set_null();
void invalidate_hashes();
@@ -223,10 +230,18 @@ namespace cryptonote
set_blob_size_valid(false);
}
+ const unsigned int start_pos = getpos(ar);
+
FIELDS(*static_cast<transaction_prefix *>(this))
+ if (std::is_same<Archive<W>, binary_archive<W>>())
+ prefix_size = getpos(ar) - start_pos;
+
if (version == 1)
{
+ if (std::is_same<Archive<W>, binary_archive<W>>())
+ unprunable_size = getpos(ar) - start_pos;
+
ar.tag("signatures");
ar.begin_array();
PREPARE_CUSTOM_VECTOR_SERIALIZATION(vin.size(), signatures);
@@ -265,6 +280,10 @@ namespace cryptonote
bool r = rct_signatures.serialize_rctsig_base(ar, vin.size(), vout.size());
if (!r || !ar.stream().good()) return false;
ar.end_object();
+
+ if (std::is_same<Archive<W>, binary_archive<W>>())
+ unprunable_size = getpos(ar) - start_pos;
+
if (!pruned && rct_signatures.type != rct::RCTTypeNull)
{
ar.tag("rctsig_prunable");
@@ -329,6 +348,8 @@ namespace cryptonote
set_hash_valid(false);
set_blob_size_valid(false);
pruned = false;
+ unprunable_size = 0;
+ prefix_size = 0;
}
inline
diff --git a/src/cryptonote_basic/cryptonote_basic_impl.cpp b/src/cryptonote_basic/cryptonote_basic_impl.cpp
index 23a5bd5bd..e336cc1d1 100644
--- a/src/cryptonote_basic/cryptonote_basic_impl.cpp
+++ b/src/cryptonote_basic/cryptonote_basic_impl.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/cryptonote_basic/cryptonote_basic_impl.h b/src/cryptonote_basic/cryptonote_basic_impl.h
index 0b8131a7a..036273f0e 100644
--- a/src/cryptonote_basic/cryptonote_basic_impl.h
+++ b/src/cryptonote_basic/cryptonote_basic_impl.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/cryptonote_basic/cryptonote_boost_serialization.h b/src/cryptonote_basic/cryptonote_boost_serialization.h
index a4228b849..4ce9f3eeb 100644
--- a/src/cryptonote_basic/cryptonote_boost_serialization.h
+++ b/src/cryptonote_basic/cryptonote_boost_serialization.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -45,8 +45,6 @@
#include "ringct/rctTypes.h"
#include "ringct/rctOps.h"
-BOOST_CLASS_VERSION(rct::ecdhTuple, 1)
-
//namespace cryptonote {
namespace boost
{
@@ -249,19 +247,8 @@ namespace boost
template <class Archive>
inline void serialize(Archive &a, rct::ecdhTuple &x, const boost::serialization::version_type ver)
{
- if (ver < 1)
- {
- a & x.mask;
- a & x.amount;
- return;
- }
- crypto::hash8 &amount = (crypto::hash8&)x.amount;
- if (!Archive::is_saving::value)
- {
- memset(&x.mask, 0, sizeof(x.mask));
- memset(&x.amount, 0, sizeof(x.amount));
- }
- a & amount;
+ a & x.mask;
+ a & x.amount;
}
template <class Archive>
diff --git a/src/cryptonote_basic/cryptonote_format_utils.cpp b/src/cryptonote_basic/cryptonote_format_utils.cpp
index f6daaab95..f40464bd1 100644
--- a/src/cryptonote_basic/cryptonote_format_utils.cpp
+++ b/src/cryptonote_basic/cryptonote_format_utils.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -210,7 +210,7 @@ namespace cryptonote
return true;
}
//---------------------------------------------------------------
- bool parse_and_validate_tx_from_blob(const blobdata& tx_blob, transaction& tx, crypto::hash& tx_hash, crypto::hash& tx_prefix_hash)
+ bool parse_and_validate_tx_from_blob(const blobdata& tx_blob, transaction& tx, crypto::hash& tx_hash)
{
std::stringstream ss;
ss << tx_blob;
@@ -222,6 +222,13 @@ namespace cryptonote
//TODO: validate tx
get_transaction_hash(tx, tx_hash);
+ return true;
+ }
+ //---------------------------------------------------------------
+ bool parse_and_validate_tx_from_blob(const blobdata& tx_blob, transaction& tx, crypto::hash& tx_hash, crypto::hash& tx_prefix_hash)
+ {
+ if (!parse_and_validate_tx_from_blob(tx_blob, tx, tx_hash))
+ return false;
get_transaction_prefix_hash(tx, tx_prefix_hash);
return true;
}
@@ -389,6 +396,7 @@ namespace cryptonote
for (const auto &bp: rv.p.bulletproofs)
nlr += bp.L.size() * 2;
const size_t bp_size = 32 * (9 + nlr);
+ CHECK_AND_ASSERT_THROW_MES_L1(n_outputs <= BULLETPROOF_MAX_OUTPUTS, "maximum number of outputs is " + std::to_string(BULLETPROOF_MAX_OUTPUTS) + " per transaction");
CHECK_AND_ASSERT_THROW_MES_L1(bp_base * n_padded_outputs >= bp_size, "Invalid bulletproof clawback");
const uint64_t bp_clawback = (bp_base * n_padded_outputs - bp_size) * 4 / 5;
CHECK_AND_ASSERT_THROW_MES_L1(bp_clawback <= std::numeric_limits<uint64_t>::max() - blob_size, "Weight overflow");
@@ -878,6 +886,11 @@ namespace cryptonote
return true;
}
//---------------------------------------------------------------
+ void get_blob_hash(const epee::span<const char>& blob, crypto::hash& res)
+ {
+ cn_fast_hash(blob.data(), blob.size(), res);
+ }
+ //---------------------------------------------------------------
void get_blob_hash(const blobdata& blob, crypto::hash& res)
{
cn_fast_hash(blob.data(), blob.size(), res);
@@ -946,6 +959,13 @@ namespace cryptonote
return h;
}
//---------------------------------------------------------------
+ crypto::hash get_blob_hash(const epee::span<const char>& blob)
+ {
+ crypto::hash h = null_hash;
+ get_blob_hash(blob, h);
+ return h;
+ }
+ //---------------------------------------------------------------
crypto::hash get_transaction_hash(const transaction& t)
{
crypto::hash h = null_hash;
@@ -958,26 +978,42 @@ namespace cryptonote
return get_transaction_hash(t, res, NULL);
}
//---------------------------------------------------------------
- bool calculate_transaction_prunable_hash(const transaction& t, crypto::hash& res)
+ bool calculate_transaction_prunable_hash(const transaction& t, const cryptonote::blobdata *blob, crypto::hash& res)
{
if (t.version == 1)
return false;
- transaction &tt = const_cast<transaction&>(t);
- std::stringstream ss;
- binary_archive<true> ba(ss);
- const size_t inputs = t.vin.size();
- const size_t outputs = t.vout.size();
- const size_t mixin = t.vin.empty() ? 0 : t.vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(t.vin[0]).key_offsets.size() - 1 : 0;
- bool r = tt.rct_signatures.p.serialize_rctsig_prunable(ba, t.rct_signatures.type, inputs, outputs, mixin);
- CHECK_AND_ASSERT_MES(r, false, "Failed to serialize rct signatures prunable");
- cryptonote::get_blob_hash(ss.str(), res);
+ static const crypto::hash empty_hash = { (char)0x70, (char)0xa4, (char)0x85, (char)0x5d, (char)0x04, (char)0xd8, (char)0xfa, (char)0x7b, (char)0x3b, (char)0x27, (char)0x82, (char)0xca, (char)0x53, (char)0xb6, (char)0x00, (char)0xe5, (char)0xc0, (char)0x03, (char)0xc7, (char)0xdc, (char)0xb2, (char)0x7d, (char)0x7e, (char)0x92, (char)0x3c, (char)0x23, (char)0xf7, (char)0x86, (char)0x01, (char)0x46, (char)0xd2, (char)0xc5 };
+ const unsigned int unprunable_size = t.unprunable_size;
+ if (blob && unprunable_size)
+ {
+ CHECK_AND_ASSERT_MES(unprunable_size <= blob->size(), false, "Inconsistent transaction unprunable and blob sizes");
+ if (blob->size() - unprunable_size == 0)
+ res = empty_hash;
+ else
+ cryptonote::get_blob_hash(epee::span<const char>(blob->data() + unprunable_size, blob->size() - unprunable_size), res);
+ }
+ else
+ {
+ transaction &tt = const_cast<transaction&>(t);
+ std::stringstream ss;
+ binary_archive<true> ba(ss);
+ const size_t inputs = t.vin.size();
+ const size_t outputs = t.vout.size();
+ const size_t mixin = t.vin.empty() ? 0 : t.vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(t.vin[0]).key_offsets.size() - 1 : 0;
+ bool r = tt.rct_signatures.p.serialize_rctsig_prunable(ba, t.rct_signatures.type, inputs, outputs, mixin);
+ CHECK_AND_ASSERT_MES(r, false, "Failed to serialize rct signatures prunable");
+ if (ss.str().empty())
+ res = empty_hash;
+ else
+ cryptonote::get_blob_hash(ss.str(), res);
+ }
return true;
}
//---------------------------------------------------------------
- crypto::hash get_transaction_prunable_hash(const transaction& t)
+ crypto::hash get_transaction_prunable_hash(const transaction& t, const cryptonote::blobdata *blobdata)
{
crypto::hash res;
- CHECK_AND_ASSERT_THROW_MES(calculate_transaction_prunable_hash(t, res), "Failed to calculate tx prunable hash");
+ CHECK_AND_ASSERT_THROW_MES(calculate_transaction_prunable_hash(t, blobdata, res), "Failed to calculate tx prunable hash");
return res;
}
//---------------------------------------------------------------
@@ -1030,16 +1066,13 @@ namespace cryptonote
transaction &tt = const_cast<transaction&>(t);
+ const blobdata blob = tx_to_blob(t);
+ const unsigned int unprunable_size = t.unprunable_size;
+ const unsigned int prefix_size = t.prefix_size;
+
// base rct
- {
- std::stringstream ss;
- binary_archive<true> ba(ss);
- const size_t inputs = t.vin.size();
- const size_t outputs = t.vout.size();
- bool r = tt.rct_signatures.serialize_rctsig_base(ba, inputs, outputs);
- CHECK_AND_ASSERT_MES(r, false, "Failed to serialize rct signatures base");
- cryptonote::get_blob_hash(ss.str(), hashes[1]);
- }
+ CHECK_AND_ASSERT_MES(prefix_size <= unprunable_size && unprunable_size <= blob.size(), false, "Inconsistent transaction prefix, unprunable and blob sizes");
+ cryptonote::get_blob_hash(epee::span<const char>(blob.data() + prefix_size, unprunable_size - prefix_size), hashes[1]);
// prunable rct
if (t.rct_signatures.type == rct::RCTTypeNull)
@@ -1048,7 +1081,7 @@ namespace cryptonote
}
else
{
- CHECK_AND_ASSERT_MES(calculate_transaction_prunable_hash(t, hashes[2]), false, "Failed to get tx prunable hash");
+ CHECK_AND_ASSERT_MES(calculate_transaction_prunable_hash(t, &blob, hashes[2]), false, "Failed to get tx prunable hash");
}
// the tx hash is the hash of the 3 hashes
@@ -1174,7 +1207,7 @@ namespace cryptonote
}
blobdata bd = get_block_hashing_blob(b);
const int cn_variant = b.major_version >= 7 ? b.major_version - 6 : 0;
- crypto::cn_slow_hash(bd.data(), bd.size(), res, cn_variant);
+ crypto::cn_slow_hash(bd.data(), bd.size(), res, cn_variant, height);
return true;
}
//---------------------------------------------------------------
diff --git a/src/cryptonote_basic/cryptonote_format_utils.h b/src/cryptonote_basic/cryptonote_format_utils.h
index 994978c10..40a9907be 100644
--- a/src/cryptonote_basic/cryptonote_format_utils.h
+++ b/src/cryptonote_basic/cryptonote_format_utils.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -51,6 +51,7 @@ namespace cryptonote
crypto::hash get_transaction_prefix_hash(const transaction_prefix& tx);
bool parse_and_validate_tx_prefix_from_blob(const blobdata& tx_blob, transaction_prefix& tx);
bool parse_and_validate_tx_from_blob(const blobdata& tx_blob, transaction& tx, crypto::hash& tx_hash, crypto::hash& tx_prefix_hash);
+ bool parse_and_validate_tx_from_blob(const blobdata& tx_blob, transaction& tx, crypto::hash& tx_hash);
bool parse_and_validate_tx_from_blob(const blobdata& tx_blob, transaction& tx);
bool parse_and_validate_tx_base_from_blob(const blobdata& tx_blob, transaction& tx);
bool is_v1_tx(const blobdata_ref& tx_blob);
@@ -98,15 +99,17 @@ namespace cryptonote
bool generate_key_image_helper(const account_keys& ack, const std::unordered_map<crypto::public_key, subaddress_index>& subaddresses, const crypto::public_key& out_key, const crypto::public_key& tx_public_key, const std::vector<crypto::public_key>& additional_tx_public_keys, size_t real_output_index, keypair& in_ephemeral, crypto::key_image& ki, hw::device &hwdev);
bool generate_key_image_helper_precomp(const account_keys& ack, const crypto::public_key& out_key, const crypto::key_derivation& recv_derivation, size_t real_output_index, const subaddress_index& received_index, keypair& in_ephemeral, crypto::key_image& ki, hw::device &hwdev);
void get_blob_hash(const blobdata& blob, crypto::hash& res);
+ void get_blob_hash(const epee::span<const char>& blob, crypto::hash& res);
crypto::hash get_blob_hash(const blobdata& blob);
+ crypto::hash get_blob_hash(const epee::span<const char>& blob);
std::string short_hash_str(const crypto::hash& h);
crypto::hash get_transaction_hash(const transaction& t);
bool get_transaction_hash(const transaction& t, crypto::hash& res);
bool get_transaction_hash(const transaction& t, crypto::hash& res, size_t& blob_size);
bool get_transaction_hash(const transaction& t, crypto::hash& res, size_t* blob_size);
- bool calculate_transaction_prunable_hash(const transaction& t, crypto::hash& res);
- crypto::hash get_transaction_prunable_hash(const transaction& t);
+ bool calculate_transaction_prunable_hash(const transaction& t, const cryptonote::blobdata *blob, crypto::hash& res);
+ crypto::hash get_transaction_prunable_hash(const transaction& t, const cryptonote::blobdata *blob = NULL);
bool calculate_transaction_hash(const transaction& t, crypto::hash& res, size_t* blob_size);
crypto::hash get_pruned_transaction_hash(const transaction& t, const crypto::hash &pruned_data_hash);
diff --git a/src/cryptonote_basic/cryptonote_stat_info.h b/src/cryptonote_basic/cryptonote_stat_info.h
index c0be2144e..4cc1bc764 100644
--- a/src/cryptonote_basic/cryptonote_stat_info.h
+++ b/src/cryptonote_basic/cryptonote_stat_info.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -34,7 +34,7 @@
namespace cryptonote
{
- struct core_stat_info
+ struct core_stat_info_t
{
uint64_t tx_pool_size;
uint64_t blockchain_height;
@@ -50,4 +50,5 @@ namespace cryptonote
KV_SERIALIZE(top_block_id_str)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<core_stat_info_t> core_stat_info;
}
diff --git a/src/cryptonote_basic/difficulty.cpp b/src/cryptonote_basic/difficulty.cpp
index 55e3e93b3..89b748a83 100644
--- a/src/cryptonote_basic/difficulty.cpp
+++ b/src/cryptonote_basic/difficulty.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/cryptonote_basic/difficulty.h b/src/cryptonote_basic/difficulty.h
index b06538467..8da355b22 100644
--- a/src/cryptonote_basic/difficulty.h
+++ b/src/cryptonote_basic/difficulty.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/cryptonote_basic/hardfork.cpp b/src/cryptonote_basic/hardfork.cpp
index 447d79aee..ebfe45f37 100644
--- a/src/cryptonote_basic/hardfork.cpp
+++ b/src/cryptonote_basic/hardfork.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -332,7 +332,7 @@ int HardFork::get_voted_fork_index(uint64_t height) const
{
CRITICAL_REGION_LOCAL(lock);
uint32_t accumulated_votes = 0;
- for (unsigned int n = heights.size() - 1; n > current_fork_index; --n) {
+ for (int n = heights.size() - 1; n >= 0; --n) {
uint8_t v = heights[n].version;
accumulated_votes += last_versions[v];
uint32_t threshold = (window_size * heights[n].threshold + 99) / 100;
diff --git a/src/cryptonote_basic/hardfork.h b/src/cryptonote_basic/hardfork.h
index a3fc25dfa..123978b12 100644
--- a/src/cryptonote_basic/hardfork.h
+++ b/src/cryptonote_basic/hardfork.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/cryptonote_basic/miner.cpp b/src/cryptonote_basic/miner.cpp
index 4f91a6ed1..6628c8448 100644
--- a/src/cryptonote_basic/miner.cpp
+++ b/src/cryptonote_basic/miner.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -73,6 +73,9 @@
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "miner"
+#define AUTODETECT_WINDOW 10 // seconds
+#define AUTODETECT_GAIN_THRESHOLD 1.02f // 2%
+
using namespace epee;
#include "miner.h"
@@ -108,6 +111,7 @@ namespace cryptonote
m_starter_nonce(0),
m_last_hr_merge_time(0),
m_hashes(0),
+ m_total_hashes(0),
m_do_print_hashrate(false),
m_do_mining(false),
m_current_hash_rate(0),
@@ -180,7 +184,12 @@ namespace cryptonote
merge_hr();
return true;
});
-
+
+ m_autodetect_interval.do_call([&](){
+ update_autodetection();
+ return true;
+ });
+
return true;
}
//-----------------------------------------------------------------------------------------------------
@@ -211,6 +220,60 @@ namespace cryptonote
m_hashes = 0;
}
//-----------------------------------------------------------------------------------------------------
+ void miner::update_autodetection()
+ {
+ if (m_threads_autodetect.empty())
+ return;
+
+ uint64_t now = epee::misc_utils::get_ns_count();
+ uint64_t dt = now - m_threads_autodetect.back().first;
+ if (dt < AUTODETECT_WINDOW * 1000000000ull)
+ return;
+
+ // work out how many more hashes we got
+ m_threads_autodetect.back().first = dt;
+ uint64_t dh = m_total_hashes - m_threads_autodetect.back().second;
+ m_threads_autodetect.back().second = dh;
+ float hs = dh / (dt / (float)1000000000);
+ MGINFO("Mining autodetection: " << m_threads_autodetect.size() << " threads: " << hs << " H/s");
+
+ // when we don't increase by at least 2%, stop, otherwise check next
+ // if N and N+1 have mostly the same hash rate, we want to "lighter" one
+ bool found = false;
+ if (m_threads_autodetect.size() > 1)
+ {
+ int previdx = m_threads_autodetect.size() - 2;
+ float previous_hs = m_threads_autodetect[previdx].second / (m_threads_autodetect[previdx].first / (float)1000000000);
+ if (previous_hs > 0 && hs / previous_hs < AUTODETECT_GAIN_THRESHOLD)
+ {
+ m_threads_total = m_threads_autodetect.size() - 1;
+ m_threads_autodetect.clear();
+ MGINFO("Optimal number of threads seems to be " << m_threads_total);
+ found = true;
+ }
+ }
+
+ if (!found)
+ {
+ // setup one more thread
+ m_threads_autodetect.push_back({now, m_total_hashes});
+ m_threads_total = m_threads_autodetect.size();
+ }
+
+ // restart all threads
+ {
+ CRITICAL_REGION_LOCAL(m_threads_lock);
+ boost::interprocess::ipcdetail::atomic_write32(&m_stop, 1);
+ for(boost::thread& th: m_threads)
+ th.join();
+ m_threads.clear();
+ }
+ boost::interprocess::ipcdetail::atomic_write32(&m_stop, 0);
+ boost::interprocess::ipcdetail::atomic_write32(&m_thread_index, 0);
+ for(size_t i = 0; i != m_threads_total; i++)
+ m_threads.push_back(boost::thread(m_attrs, boost::bind(&miner::worker_thread, this)));
+ }
+ //-----------------------------------------------------------------------------------------------------
void miner::init_options(boost::program_options::options_description& desc)
{
command_line::add_arg(desc, arg_extra_messages);
@@ -244,7 +307,8 @@ namespace cryptonote
}
m_config_folder_path = boost::filesystem::path(command_line::get_arg(vm, arg_extra_messages)).parent_path().string();
m_config = AUTO_VAL_INIT(m_config);
- epee::serialization::load_t_from_json_file(m_config, m_config_folder_path + "/" + MINER_CONFIG_FILE_NAME);
+ const std::string filename = m_config_folder_path + "/" + MINER_CONFIG_FILE_NAME;
+ CHECK_AND_ASSERT_MES(epee::serialization::load_t_from_json_file(m_config, filename), false, "Failed to load data from " << filename);
MINFO("Loaded " << m_extra_messages.size() << " extra messages, current index " << m_config.current_extra_message_index);
}
@@ -300,6 +364,13 @@ namespace cryptonote
m_block_reward = 0;
m_mine_address = adr;
m_threads_total = static_cast<uint32_t>(threads_count);
+ if (threads_count == 0)
+ {
+ m_threads_autodetect.clear();
+ m_threads_autodetect.push_back({epee::misc_utils::get_ns_count(), m_total_hashes});
+ m_threads_total = 1;
+ }
+ m_attrs = attrs;
m_starter_nonce = crypto::rand<uint32_t>();
CRITICAL_REGION_LOCAL(m_threads_lock);
if(is_mining())
@@ -321,12 +392,15 @@ namespace cryptonote
set_is_background_mining_enabled(do_background);
set_ignore_battery(ignore_battery);
- for(size_t i = 0; i != threads_count; i++)
+ for(size_t i = 0; i != m_threads_total; i++)
{
m_threads.push_back(boost::thread(attrs, boost::bind(&miner::worker_thread, this)));
}
- LOG_PRINT_L0("Mining has started with " << threads_count << " threads, good luck!" );
+ if (threads_count == 0)
+ MINFO("Mining has started, autodetecting optimal number of threads, good luck!" );
+ else
+ MINFO("Mining has started with " << threads_count << " threads, good luck!" );
if( get_is_background_mining_enabled() )
{
@@ -363,7 +437,7 @@ namespace cryptonote
if (!is_mining())
{
- MDEBUG("Not mining - nothing to stop" );
+ MTRACE("Not mining - nothing to stop" );
return true;
}
@@ -384,6 +458,7 @@ namespace cryptonote
MINFO("Mining has been stopped, " << m_threads.size() << " finished" );
m_threads.clear();
+ m_threads_autodetect.clear();
return true;
}
//-----------------------------------------------------------------------------------------------------
@@ -509,6 +584,7 @@ namespace cryptonote
}
nonce+=m_threads_total;
++m_hashes;
+ ++m_total_hashes;
}
slow_hash_free_state();
MGINFO("Miner thread stopped ["<< th_local_index << "]");
diff --git a/src/cryptonote_basic/miner.h b/src/cryptonote_basic/miner.h
index b0a8b4a45..08b1bd7f1 100644
--- a/src/cryptonote_basic/miner.h
+++ b/src/cryptonote_basic/miner.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -104,6 +104,7 @@ namespace cryptonote
bool worker_thread();
bool request_block_template();
void merge_hr();
+ void update_autodetection();
struct miner_config
{
@@ -133,16 +134,20 @@ namespace cryptonote
account_public_address m_mine_address;
epee::math_helper::once_a_time_seconds<5> m_update_block_template_interval;
epee::math_helper::once_a_time_seconds<2> m_update_merge_hr_interval;
+ epee::math_helper::once_a_time_seconds<1> m_autodetect_interval;
std::vector<blobdata> m_extra_messages;
miner_config m_config;
std::string m_config_folder_path;
std::atomic<uint64_t> m_last_hr_merge_time;
std::atomic<uint64_t> m_hashes;
+ std::atomic<uint64_t> m_total_hashes;
std::atomic<uint64_t> m_current_hash_rate;
epee::critical_section m_last_hash_rates_lock;
std::list<uint64_t> m_last_hash_rates;
bool m_do_print_hashrate;
bool m_do_mining;
+ std::vector<std::pair<uint64_t, uint64_t>> m_threads_autodetect;
+ boost::thread::attributes m_attrs;
// background mining stuffs ..
diff --git a/src/cryptonote_basic/subaddress_index.h b/src/cryptonote_basic/subaddress_index.h
index 9b71448f9..99933e229 100644
--- a/src/cryptonote_basic/subaddress_index.h
+++ b/src/cryptonote_basic/subaddress_index.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/cryptonote_basic/tx_extra.h b/src/cryptonote_basic/tx_extra.h
index 009e35ebe..ecb4c6040 100644
--- a/src/cryptonote_basic/tx_extra.h
+++ b/src/cryptonote_basic/tx_extra.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/cryptonote_basic/verification_context.h b/src/cryptonote_basic/verification_context.h
index 8d2b633a2..36b63f254 100644
--- a/src/cryptonote_basic/verification_context.h
+++ b/src/cryptonote_basic/verification_context.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h
index 93db71705..9beafe7c5 100644
--- a/src/cryptonote_config.h
+++ b/src/cryptonote_config.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -59,6 +59,8 @@
#define CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V2 60000 //size of block (bytes) after which reward for block calculated using block size
#define CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 20000 //size of block (bytes) after which reward for block calculated using block size - before first fork
#define CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 300000 //size of block (bytes) after which reward for block calculated using block size - second change, from v5
+#define CRYPTONOTE_LONG_TERM_BLOCK_WEIGHT_WINDOW_SIZE 100000 // size in blocks of the long term block weight median window
+#define CRYPTONOTE_SHORT_TERM_BLOCK_WEIGHT_SURGE_FACTOR 50
#define CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE 600
#define CRYPTONOTE_DISPLAY_DECIMAL_POINT 12
// COIN - number of smallest units in one coin
@@ -108,7 +110,7 @@
#define P2P_DEFAULT_PACKET_MAX_SIZE 50000000 //50000000 bytes maximum packet size
#define P2P_DEFAULT_PEERS_IN_HANDSHAKE 250
#define P2P_DEFAULT_CONNECTION_TIMEOUT 5000 //5 seconds
-#define P2P_DEFAULT_TOR_CONNECT_TIMEOUT 20 // seconds
+#define P2P_DEFAULT_SOCKS_CONNECT_TIMEOUT 45 // seconds
#define P2P_DEFAULT_PING_CONNECTION_TIMEOUT 2000 //2 seconds
#define P2P_DEFAULT_INVOKE_TIMEOUT 60*2*1000 //2 minutes
#define P2P_DEFAULT_HANDSHAKE_INVOKE_TIMEOUT 5000 //5 seconds
@@ -143,6 +145,7 @@
#define HF_VERSION_ENFORCE_RCT 6
#define HF_VERSION_PER_BYTE_FEE 8
#define HF_VERSION_SMALLER_BP 10
+#define HF_VERSION_LONG_TERM_BLOCK_WEIGHT 10
#define PER_KB_FEE_QUANTIZATION_DECIMALS 8
diff --git a/src/cryptonote_core/CMakeLists.txt b/src/cryptonote_core/CMakeLists.txt
index 231489fdb..fb96de226 100644
--- a/src/cryptonote_core/CMakeLists.txt
+++ b/src/cryptonote_core/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 41357e72e..3e903cd12 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -115,6 +115,12 @@ static const struct {
// version 9 starts from block 1686275, which is on or around the 19th of October, 2018. Fork time finalised on 2018-09-02.
{ 9, 1686275, 0, 1535889548 },
+
+ // version 10 starts from block 1788000, which is on or around the 9th of March, 2019. Fork time finalised on 2019-02-10.
+ { 10, 1788000, 0, 1549792439 },
+
+ // version 11 starts from block 1788720, which is on or around the 10th of March, 2019. Fork time finalised on 2019-02-15.
+ { 11, 1788720, 0, 1550225678 },
};
static const uint64_t mainnet_hard_fork_version_1_till = 1009826;
@@ -139,6 +145,8 @@ static const struct {
{ 7, 1057027, 0, 1512211236 },
{ 8, 1057058, 0, 1533211200 },
{ 9, 1057778, 0, 1533297600 },
+ { 10, 1154318, 0, 1550153694 },
+ { 11, 1155038, 0, 1550225678 },
};
static const uint64_t testnet_hard_fork_version_1_till = 624633;
@@ -160,12 +168,16 @@ static const struct {
{ 7, 37000, 0, 1521600000 },
{ 8, 176456, 0, 1537821770 },
{ 9, 177176, 0, 1537821771 },
+ { 10, 269000, 0, 1550153694 },
+ { 11, 269720, 0, 1550225678 },
};
//------------------------------------------------------------------
Blockchain::Blockchain(tx_memory_pool& tx_pool) :
m_db(), m_tx_pool(tx_pool), m_hardfork(NULL), m_timestamps_and_difficulties_height(0), m_current_block_cumul_weight_limit(0), m_current_block_cumul_weight_median(0),
m_enforce_dns_checkpoints(false), m_max_prepare_blocks_threads(4), m_db_sync_on_blocks(true), m_db_sync_threshold(1), m_db_sync_mode(db_async), m_db_default_sync(false), m_fast_sync(true), m_show_time_stats(false), m_sync_counter(0), m_bytes_to_sync(0), m_cancel(false),
+ m_long_term_block_weights_window(CRYPTONOTE_LONG_TERM_BLOCK_WEIGHT_WINDOW_SIZE),
+ m_long_term_effective_median_block_weight(0),
m_difficulty_for_next_block_top_hash(crypto::null_hash),
m_difficulty_for_next_block(1),
m_btc_valid(false)
@@ -435,9 +447,9 @@ bool Blockchain::init(BlockchainDB* db, const network_type nettype, bool offline
uint64_t top_block_timestamp = m_db->get_top_block_timestamp();
uint64_t timestamp_diff = time(NULL) - top_block_timestamp;
- // genesis block has no timestamp, could probably change it to have timestamp of 1341378000...
+ // genesis block has no timestamp, could probably change it to have timestamp of 1397818133...
if(!top_block_timestamp)
- timestamp_diff = time(NULL) - 1341378000;
+ timestamp_diff = time(NULL) - 1397818133;
// create general purpose async service queue
@@ -456,8 +468,8 @@ bool Blockchain::init(BlockchainDB* db, const network_type nettype, bool offline
uint64_t num_popped_blocks = 0;
while (!m_db->is_read_only())
{
- const uint64_t top_height = m_db->height() - 1;
- const crypto::hash top_id = m_db->top_block_hash();
+ uint64_t top_height;
+ const crypto::hash top_id = m_db->top_block_hash(&top_height);
const block top_block = m_db->get_top_block();
const uint8_t ideal_hf_version = get_ideal_hard_fork_version(top_height);
if (ideal_hf_version <= 1 || ideal_hf_version == top_block.major_version)
@@ -497,10 +509,16 @@ bool Blockchain::init(BlockchainDB* db, const network_type nettype, bool offline
{
m_timestamps_and_difficulties_height = 0;
m_hardfork->reorganize_from_chain_height(get_current_blockchain_height());
- m_tx_pool.on_blockchain_dec(m_db->height()-1, get_tail_id());
+ uint64_t top_block_height;
+ crypto::hash top_block_hash = get_tail_id(top_block_height);
+ m_tx_pool.on_blockchain_dec(top_block_height, top_block_hash);
}
- update_next_cumulative_weight_limit();
+ if (test_options && test_options->long_term_block_weight_window)
+ m_long_term_block_weights_window = test_options->long_term_block_weight_window;
+
+ if (!update_next_cumulative_weight_limit())
+ return false;
return true;
}
//------------------------------------------------------------------
@@ -685,8 +703,10 @@ block Blockchain::pop_block_from_blockchain()
m_blocks_txs_check.clear();
m_check_txin_table.clear();
- update_next_cumulative_weight_limit();
- m_tx_pool.on_blockchain_dec(m_db->height()-1, get_tail_id());
+ CHECK_AND_ASSERT_THROW_MES(update_next_cumulative_weight_limit(), "Error updating next cumulative weight limit");
+ uint64_t top_block_height;
+ crypto::hash top_block_hash = get_tail_id(top_block_height);
+ m_tx_pool.on_blockchain_dec(top_block_height, top_block_hash);
invalidate_block_template_cache();
return popped_block;
@@ -704,7 +724,8 @@ bool Blockchain::reset_and_set_genesis_block(const block& b)
block_verification_context bvc = boost::value_initialized<block_verification_context>();
add_new_block(b, bvc);
- update_next_cumulative_weight_limit();
+ if (!update_next_cumulative_weight_limit())
+ return false;
return bvc.m_added_to_main_chain && !bvc.m_verifivation_failed;
}
//------------------------------------------------------------------
@@ -712,8 +733,7 @@ crypto::hash Blockchain::get_tail_id(uint64_t& height) const
{
LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock);
- height = m_db->height() - 1;
- return get_tail_id();
+ return m_db->top_block_hash(&height);
}
//------------------------------------------------------------------
crypto::hash Blockchain::get_tail_id() const
@@ -874,8 +894,9 @@ difficulty_type Blockchain::get_difficulty_for_next_block()
CRITICAL_REGION_LOCAL(m_blockchain_lock);
std::vector<uint64_t> timestamps;
std::vector<difficulty_type> difficulties;
- auto height = m_db->height();
- top_hash = get_tail_id(); // get it again now that we have the lock
+ uint64_t height;
+ top_hash = get_tail_id(height); // get it again now that we have the lock
+ ++height; // top block height to blockchain height
// ND: Speedup
// 1. Keep a list of the last 735 (or less) blocks that is used to compute difficulty,
// then when the next block difficulty is queried, push the latest height data and
@@ -1049,6 +1070,7 @@ bool Blockchain::switch_to_alternative_blockchain(std::list<blocks_ext_by_hash::
}
// if we're to keep the disconnected blocks, add them as alternates
+ const size_t discarded_blocks = disconnected_chain.size();
if(!discard_disconnected_chain)
{
//pushing old chain as alternative chain
@@ -1076,7 +1098,7 @@ bool Blockchain::switch_to_alternative_blockchain(std::list<blocks_ext_by_hash::
std::shared_ptr<tools::Notify> reorg_notify = m_reorg_notify;
if (reorg_notify)
reorg_notify->notify("%s", std::to_string(split_height).c_str(), "%h", std::to_string(m_db->height()).c_str(),
- "%n", std::to_string(m_db->height() - split_height).c_str(), NULL);
+ "%n", std::to_string(m_db->height() - split_height).c_str(), "%d", std::to_string(discarded_blocks).c_str(), NULL);
MGINFO_GREEN("REORGANIZE SUCCESS! on height: " << split_height << ", new blockchain size: " << m_db->height());
return true;
@@ -1202,7 +1224,7 @@ bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_bl
}
}
- std::vector<size_t> last_blocks_weights;
+ std::vector<uint64_t> last_blocks_weights;
get_last_n_blocks_weights(last_blocks_weights, CRYPTONOTE_REWARD_BLOCKS_WINDOW);
if (!get_block_reward(epee::misc_utils::median(last_blocks_weights), cumulative_block_weight, already_generated_coins, base_reward, version))
{
@@ -1237,7 +1259,7 @@ bool Blockchain::validate_miner_transaction(const block& b, size_t cumulative_bl
}
//------------------------------------------------------------------
// get the block weights of the last <count> blocks, and return by reference <sz>.
-void Blockchain::get_last_n_blocks_weights(std::vector<size_t>& weights, size_t count) const
+void Blockchain::get_last_n_blocks_weights(std::vector<uint64_t>& weights, size_t count) const
{
LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_blockchain_lock);
@@ -1728,7 +1750,6 @@ bool Blockchain::handle_get_objects(NOTIFY_REQUEST_GET_OBJECTS::request& arg, NO
for (auto& bl: blocks)
{
std::vector<crypto::hash> missed_tx_ids;
- std::vector<cryptonote::blobdata> txs;
rsp.blocks.push_back(block_complete_entry());
block_complete_entry& e = rsp.blocks.back();
@@ -1756,7 +1777,6 @@ bool Blockchain::handle_get_objects(NOTIFY_REQUEST_GET_OBJECTS::request& arg, NO
e.block = std::move(bl.first);
}
//get and pack other transactions, if needed
- std::vector<cryptonote::blobdata> txs;
get_transactions_blobs(arg.txs, rsp.txs, rsp.missed_ids);
m_db->block_txn_stop();
@@ -1790,11 +1810,12 @@ uint64_t Blockchain::get_num_mature_outputs(uint64_t amount) const
uint64_t num_outs = m_db->get_num_outputs(amount);
// ensure we don't include outputs that aren't yet eligible to be used
// outpouts are sorted by height
+ const uint64_t blockchain_height = m_db->height();
while (num_outs > 0)
{
const tx_out_index toi = m_db->get_output_tx_and_index(amount, num_outs - 1);
const uint64_t height = m_db->get_tx_block_height(toi.first);
- if (height + CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE <= m_db->height())
+ if (height + CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE <= blockchain_height)
break;
--num_outs;
}
@@ -2527,7 +2548,19 @@ bool Blockchain::check_tx_outputs(const transaction& tx, tx_verification_context
if (tx.version >= 2) {
if (tx.rct_signatures.type == rct::RCTTypeBulletproof2)
{
- MERROR_VER("Bulletproofs v2 are not allowed before v" << HF_VERSION_SMALLER_BP);
+ MERROR_VER("Ringct type " << (unsigned)rct::RCTTypeBulletproof2 << " is not allowed before v" << HF_VERSION_SMALLER_BP);
+ tvc.m_invalid_output = true;
+ return false;
+ }
+ }
+ }
+
+ // from v11, allow only bulletproofs v2
+ if (hf_version > HF_VERSION_SMALLER_BP) {
+ if (tx.version >= 2) {
+ if (tx.rct_signatures.type == rct::RCTTypeBulletproof)
+ {
+ MERROR_VER("Ringct type " << (unsigned)rct::RCTTypeBulletproof << " is not allowed from v" << (HF_VERSION_SMALLER_BP + 1));
tvc.m_invalid_output = true;
return false;
}
@@ -2600,7 +2633,7 @@ bool Blockchain::expand_transaction_2(transaction &tx, const crypto::hash &tx_pr
for (size_t n = 0; n < tx.vin.size(); ++n)
rv.p.MGs[0].II[n] = rct::ki2rct(boost::get<txin_to_key>(tx.vin[n]).k_image);
}
- else if (rv.type == rct::RCTTypeSimple || rv.type == rct::RCTTypeBulletproof || rct::RCTTypeBulletproof2)
+ else if (rv.type == rct::RCTTypeSimple || rv.type == rct::RCTTypeBulletproof || rv.type == rct::RCTTypeBulletproof2)
{
CHECK_AND_ASSERT_MES(rv.p.MGs.size() == tx.vin.size(), false, "Bad MGs size");
for (size_t n = 0; n < tx.vin.size(); ++n)
@@ -3083,6 +3116,7 @@ uint64_t Blockchain::get_dynamic_base_fee(uint64_t block_reward, size_t median_b
bool Blockchain::check_fee(size_t tx_weight, uint64_t fee) const
{
const uint8_t version = get_current_hard_fork_version();
+ const uint64_t blockchain_height = m_db->height();
uint64_t median = 0;
uint64_t already_generated_coins = 0;
@@ -3090,7 +3124,7 @@ bool Blockchain::check_fee(size_t tx_weight, uint64_t fee) const
if (version >= HF_VERSION_DYNAMIC_FEE)
{
median = m_current_block_cumul_weight_limit / 2;
- already_generated_coins = m_db->height() ? m_db->get_block_already_generated_coins(m_db->height() - 1) : 0;
+ already_generated_coins = blockchain_height ? m_db->get_block_already_generated_coins(blockchain_height - 1) : 0;
if (!get_block_reward(median, 1, already_generated_coins, base_reward, version))
return false;
}
@@ -3098,7 +3132,8 @@ bool Blockchain::check_fee(size_t tx_weight, uint64_t fee) const
uint64_t needed_fee;
if (version >= HF_VERSION_PER_BYTE_FEE)
{
- uint64_t fee_per_byte = get_dynamic_base_fee(base_reward, median, version);
+ 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 ? m_long_term_effective_median_block_weight : median, version);
MDEBUG("Using " << print_money(fee_per_byte) << "/byte fee");
needed_fee = tx_weight * fee_per_byte;
// quantize fee up to 8 decimals
@@ -3135,6 +3170,7 @@ bool Blockchain::check_fee(size_t tx_weight, uint64_t fee) const
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;
@@ -3143,7 +3179,7 @@ uint64_t Blockchain::get_dynamic_base_fee_estimate(uint64_t grace_blocks) const
grace_blocks = CRYPTONOTE_REWARD_BLOCKS_WINDOW - 1;
const uint64_t min_block_weight = get_min_block_weight(version);
- std::vector<size_t> weights;
+ 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)
@@ -3153,7 +3189,7 @@ uint64_t Blockchain::get_dynamic_base_fee_estimate(uint64_t grace_blocks) const
if(median <= min_block_weight)
median = min_block_weight;
- uint64_t already_generated_coins = m_db->height() ? m_db->get_block_already_generated_coins(m_db->height() - 1) : 0;
+ 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(median, 1, already_generated_coins, base_reward, version))
{
@@ -3161,7 +3197,8 @@ uint64_t Blockchain::get_dynamic_base_fee_estimate(uint64_t grace_blocks) const
base_reward = BLOCK_REWARD_OVERESTIMATE;
}
- uint64_t fee = get_dynamic_base_fee(base_reward, median, version);
+ const bool use_long_term_median_in_fee = version >= HF_VERSION_LONG_TERM_BLOCK_WEIGHT;
+ uint64_t fee = get_dynamic_base_fee(base_reward, use_long_term_median_in_fee ? m_long_term_effective_median_block_weight : median, 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;
@@ -3293,14 +3330,15 @@ bool Blockchain::check_block_timestamp(const block& b, uint64_t& median_ts) cons
return false;
}
+ const auto h = m_db->height();
+
// if not enough blocks, no proper median yet, return true
- if(m_db->height() < BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW)
+ if(h < BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW)
{
return true;
}
std::vector<uint64_t> timestamps;
- auto h = m_db->height();
// need most recent 60 blocks, get index of first of those
size_t offset = h - BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW;
@@ -3313,7 +3351,7 @@ bool Blockchain::check_block_timestamp(const block& b, uint64_t& median_ts) cons
return check_block_timestamp(timestamps, b, median_ts);
}
//------------------------------------------------------------------
-void Blockchain::return_tx_to_pool(std::vector<transaction> &txs)
+void Blockchain::return_tx_to_pool(std::vector<std::pair<transaction, blobdata>> &txs)
{
uint8_t version = get_current_hard_fork_version();
for (auto& tx : txs)
@@ -3324,9 +3362,11 @@ void Blockchain::return_tx_to_pool(std::vector<transaction> &txs)
// that might not be always true. Unlikely though, and always relaying
// these again might cause a spike of traffic as many nodes re-relay
// all the transactions in a popped block when a reorg happens.
- if (!m_tx_pool.add_tx(tx, tvc, true, true, false, version))
+ const size_t weight = get_transaction_weight(tx.first, tx.second.size());
+ const crypto::hash tx_hash = get_transaction_hash(tx.first);
+ if (!m_tx_pool.add_tx(tx.first, tx_hash, tx.second, weight, tvc, true, true, false, version))
{
- MERROR("Failed to return taken transaction with hash: " << get_transaction_hash(tx) << " to tx_pool");
+ MERROR("Failed to return taken transaction with hash: " << get_transaction_hash(tx.first) << " to tx_pool");
}
}
}
@@ -3339,11 +3379,12 @@ bool Blockchain::flush_txes_from_pool(const std::vector<crypto::hash> &txids)
for (const auto &txid: txids)
{
cryptonote::transaction tx;
+ cryptonote::blobdata txblob;
size_t tx_weight;
uint64_t fee;
bool relayed, do_not_relay, double_spend_seen;
MINFO("Removing txid " << txid << " from the pool");
- if(m_tx_pool.have_tx(txid) && !m_tx_pool.take_tx(txid, tx, tx_weight, fee, relayed, do_not_relay, double_spend_seen))
+ if(m_tx_pool.have_tx(txid) && !m_tx_pool.take_tx(txid, tx, txblob, tx_weight, fee, relayed, do_not_relay, double_spend_seen))
{
MERROR("Failed to remove txid " << txid << " from the pool");
res = false;
@@ -3366,9 +3407,12 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash&
static bool seen_future_version = false;
m_db->block_txn_start(true);
- if(bl.prev_id != get_tail_id())
+ uint64_t blockchain_height;
+ const crypto::hash top_hash = get_tail_id(blockchain_height);
+ ++blockchain_height; // block height to chain height
+ if(bl.prev_id != top_hash)
{
- MERROR_VER("Block with id: " << id << std::endl << "has wrong prev_id: " << bl.prev_id << std::endl << "expected: " << get_tail_id());
+ MERROR_VER("Block with id: " << id << std::endl << "has wrong prev_id: " << bl.prev_id << std::endl << "expected: " << top_hash);
bvc.m_verifivation_failed = true;
leave:
m_db->block_txn_stop();
@@ -3437,13 +3481,12 @@ leave:
bool precomputed = false;
bool fast_check = false;
#if defined(PER_BLOCK_CHECKPOINT)
- if (m_db->height() < m_blocks_hash_check.size())
+ if (blockchain_height < m_blocks_hash_check.size())
{
- auto hash = get_block_hash(bl);
- const auto &expected_hash = m_blocks_hash_check[m_db->height()];
+ const auto &expected_hash = m_blocks_hash_check[blockchain_height];
if (expected_hash != crypto::null_hash)
{
- if (memcmp(&hash, &expected_hash, sizeof(hash)) != 0)
+ if (memcmp(&id, &expected_hash, sizeof(hash)) != 0)
{
MERROR_VER("Block with id is INVALID: " << id << ", expected " << expected_hash);
bvc.m_verifivation_failed = true;
@@ -3453,7 +3496,7 @@ leave:
}
else
{
- MCINFO("verify", "No pre-validated hash at height " << m_db->height() << ", verifying fully");
+ MCINFO("verify", "No pre-validated hash at height " << blockchain_height << ", verifying fully");
}
}
else
@@ -3466,12 +3509,12 @@ leave:
proof_of_work = it->second;
}
else
- proof_of_work = get_block_longhash(bl, m_db->height());
+ proof_of_work = get_block_longhash(bl, blockchain_height);
// validate proof_of_work versus difficulty target
if(!check_hash(proof_of_work, current_diffic))
{
- MERROR_VER("Block with id: " << id << std::endl << "does not have enough proof of work: " << proof_of_work << std::endl << "unexpected difficulty: " << current_diffic);
+ MERROR_VER("Block with id: " << id << std::endl << "does not have enough proof of work: " << proof_of_work << " at height " << blockchain_height << ", unexpected difficulty: " << current_diffic);
bvc.m_verifivation_failed = true;
goto leave;
}
@@ -3479,9 +3522,9 @@ leave:
// If we're at a checkpoint, ensure that our hardcoded checkpoint hash
// is correct.
- if(m_checkpoints.is_in_checkpoint_zone(get_current_blockchain_height()))
+ if(m_checkpoints.is_in_checkpoint_zone(blockchain_height))
{
- if(!m_checkpoints.check_block(get_current_blockchain_height(), id))
+ if(!m_checkpoints.check_block(blockchain_height, id))
{
LOG_ERROR("CHECKPOINT VALIDATION FAILED");
bvc.m_verifivation_failed = true;
@@ -3496,7 +3539,7 @@ leave:
TIME_MEASURE_START(t3);
// sanity check basic miner tx properties;
- if(!prevalidate_miner_transaction(bl, m_db->height()))
+ if(!prevalidate_miner_transaction(bl, blockchain_height))
{
MERROR_VER("Block with id: " << id << " failed to pass prevalidation");
bvc.m_verifivation_failed = true;
@@ -3506,7 +3549,7 @@ leave:
size_t coinbase_weight = get_transaction_weight(bl.miner_tx);
size_t cumulative_block_weight = coinbase_weight;
- std::vector<transaction> txs;
+ std::vector<std::pair<transaction, blobdata>> txs;
key_images_container keys;
uint64_t fee_summary = 0;
@@ -3525,7 +3568,8 @@ leave:
txs.reserve(bl.tx_hashes.size());
for (const crypto::hash& tx_id : bl.tx_hashes)
{
- transaction tx;
+ transaction tx_tmp;
+ blobdata txblob;
size_t tx_weight = 0;
uint64_t fee = 0;
bool relayed = false, do_not_relay = false, double_spend_seen = false;
@@ -3545,7 +3589,7 @@ leave:
TIME_MEASURE_START(bb);
// get transaction with hash <tx_id> from tx_pool
- if(!m_tx_pool.take_tx(tx_id, tx, tx_weight, fee, relayed, do_not_relay, double_spend_seen))
+ if(!m_tx_pool.take_tx(tx_id, tx_tmp, txblob, tx_weight, fee, relayed, do_not_relay, double_spend_seen))
{
MERROR_VER("Block with id: " << id << " has at least one unknown transaction with id: " << tx_id);
bvc.m_verifivation_failed = true;
@@ -3558,7 +3602,8 @@ leave:
// add the transaction to the temp list of transactions, so we can either
// store the list of transactions all at once or return the ones we've
// taken from the tx_pool back to it if the block fails verification.
- txs.push_back(tx);
+ txs.push_back(std::make_pair(std::move(tx_tmp), std::move(txblob)));
+ transaction &tx = txs.back().first;
TIME_MEASURE_START(dd);
// FIXME: the storage should not be responsible for validation.
@@ -3623,7 +3668,7 @@ leave:
TIME_MEASURE_START(vmt);
uint64_t base_reward = 0;
- uint64_t already_generated_coins = m_db->height() ? m_db->get_block_already_generated_coins(m_db->height() - 1) : 0;
+ uint64_t already_generated_coins = blockchain_height ? m_db->get_block_already_generated_coins(blockchain_height - 1) : 0;
if(!validate_miner_transaction(bl, cumulative_block_weight, fee_summary, base_reward, already_generated_coins, bvc.m_partial_block_reward, m_hardfork->get_current_version()))
{
MERROR_VER("Block with id: " << id << " has incorrect miner transaction");
@@ -3644,8 +3689,8 @@ leave:
// at MONEY_SUPPLY. already_generated_coins is only used to compute the block subsidy and MONEY_SUPPLY yields a
// subsidy of 0 under the base formula and therefore the minimum subsidy >0 in the tail state.
already_generated_coins = base_reward < (MONEY_SUPPLY-already_generated_coins) ? already_generated_coins + base_reward : MONEY_SUPPLY;
- if(m_db->height())
- cumulative_difficulty += m_db->get_block_cumulative_difficulty(m_db->height() - 1);
+ if(blockchain_height)
+ cumulative_difficulty += m_db->get_block_cumulative_difficulty(blockchain_height - 1);
TIME_MEASURE_FINISH(block_processing_time);
if(precomputed)
@@ -3658,7 +3703,9 @@ leave:
{
try
{
- new_height = m_db->add_block(bl, block_weight, cumulative_difficulty, already_generated_coins, txs);
+ uint64_t long_term_block_weight = get_next_long_term_block_weight(block_weight);
+ cryptonote::blobdata bd = cryptonote::block_to_blob(bl);
+ new_height = m_db->add_block(std::make_pair(std::move(bl), std::move(bd)), block_weight, long_term_block_weight, cumulative_difficulty, already_generated_coins, txs);
}
catch (const KEY_IMAGE_EXISTS& e)
{
@@ -3684,7 +3731,12 @@ leave:
TIME_MEASURE_FINISH(addblock);
// do this after updating the hard fork state since the weight limit may change due to fork
- update_next_cumulative_weight_limit();
+ if (!update_next_cumulative_weight_limit())
+ {
+ MERROR("Failed to update next cumulative weight limit");
+ pop_block_from_blockchain();
+ return false;
+ }
MINFO("+++++ BLOCK SUCCESSFULLY ADDED" << std::endl << "id:\t" << id << std::endl << "PoW:\t" << proof_of_work << std::endl << "HEIGHT " << new_height-1 << ", difficulty:\t" << current_diffic << std::endl << "block reward: " << print_money(fee_summary + base_reward) << "(" << print_money(base_reward) << " + " << print_money(fee_summary) << "), coinbase_weight: " << coinbase_weight << ", cumulative weight: " << cumulative_block_weight << ", " << block_processing_time << "(" << target_calculating_time << "/" << longhash_calculating_time << ")ms");
if(m_show_time_stats)
@@ -3740,28 +3792,106 @@ bool Blockchain::check_blockchain_pruning()
return m_db->check_pruning();
}
//------------------------------------------------------------------
-bool Blockchain::update_next_cumulative_weight_limit()
+uint64_t Blockchain::get_next_long_term_block_weight(uint64_t block_weight) const
+{
+ PERF_TIMER(get_next_long_term_block_weight);
+
+ const uint64_t db_height = m_db->height();
+ const uint64_t nblocks = std::min<uint64_t>(m_long_term_block_weights_window, db_height);
+
+ const uint8_t hf_version = get_current_hard_fork_version();
+ if (hf_version < HF_VERSION_LONG_TERM_BLOCK_WEIGHT)
+ return block_weight;
+
+ std::vector<uint64_t> weights;
+ weights.resize(nblocks);
+ for (uint64_t h = 0; h < nblocks; ++h)
+ weights[h] = m_db->get_block_long_term_weight(db_height - nblocks + h);
+ uint64_t long_term_median = epee::misc_utils::median(weights);
+ uint64_t long_term_effective_median_block_weight = std::max<uint64_t>(CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5, long_term_median);
+
+ uint64_t short_term_constraint = long_term_effective_median_block_weight + long_term_effective_median_block_weight * 2 / 5;
+ uint64_t long_term_block_weight = std::min<uint64_t>(block_weight, short_term_constraint);
+
+ return long_term_block_weight;
+}
+//------------------------------------------------------------------
+bool Blockchain::update_next_cumulative_weight_limit(uint64_t *long_term_effective_median_block_weight)
{
- uint64_t full_reward_zone = get_min_block_weight(get_current_hard_fork_version());
+ PERF_TIMER(update_next_cumulative_weight_limit);
LOG_PRINT_L3("Blockchain::" << __func__);
- std::vector<size_t> weights;
- get_last_n_blocks_weights(weights, CRYPTONOTE_REWARD_BLOCKS_WINDOW);
- uint64_t median = epee::misc_utils::median(weights);
- m_current_block_cumul_weight_median = median;
- if(median <= full_reward_zone)
- median = full_reward_zone;
+ // when we reach this, the last hf version is not yet written to the db
+ const uint64_t db_height = m_db->height();
+ const uint8_t hf_version = get_current_hard_fork_version();
+ uint64_t full_reward_zone = get_min_block_weight(hf_version);
+ uint64_t long_term_block_weight;
+
+ if (hf_version < HF_VERSION_LONG_TERM_BLOCK_WEIGHT)
+ {
+ std::vector<uint64_t> weights;
+ get_last_n_blocks_weights(weights, CRYPTONOTE_REWARD_BLOCKS_WINDOW);
+ m_current_block_cumul_weight_median = epee::misc_utils::median(weights);
+ long_term_block_weight = weights.back();
+ }
+ else
+ {
+ const uint64_t block_weight = m_db->get_block_weight(db_height - 1);
+
+ std::vector<uint64_t> weights, new_weights;
+ uint64_t long_term_median;
+ if (db_height == 1)
+ {
+ long_term_median = CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5;
+ }
+ else
+ {
+ uint64_t nblocks = std::min<uint64_t>(m_long_term_block_weights_window, db_height);
+ if (nblocks == db_height)
+ --nblocks;
+ weights.resize(nblocks);
+ for (uint64_t h = 0; h < nblocks; ++h)
+ weights[h] = m_db->get_block_long_term_weight(db_height - nblocks + h - 1);
+ new_weights = weights;
+ long_term_median = epee::misc_utils::median(weights);
+ }
+
+ m_long_term_effective_median_block_weight = std::max<uint64_t>(CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5, long_term_median);
+
+ uint64_t short_term_constraint = m_long_term_effective_median_block_weight + m_long_term_effective_median_block_weight * 2 / 5;
+ long_term_block_weight = std::min<uint64_t>(block_weight, short_term_constraint);
+
+ if (new_weights.empty())
+ new_weights.resize(1);
+ new_weights[0] = long_term_block_weight;
+ long_term_median = epee::misc_utils::median(new_weights);
+ m_long_term_effective_median_block_weight = std::max<uint64_t>(CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5, long_term_median);
+ short_term_constraint = m_long_term_effective_median_block_weight + m_long_term_effective_median_block_weight * 2 / 5;
+
+ weights.clear();
+ get_last_n_blocks_weights(weights, CRYPTONOTE_REWARD_BLOCKS_WINDOW);
+
+ uint64_t short_term_median = epee::misc_utils::median(weights);
+ uint64_t effective_median_block_weight = std::min<uint64_t>(std::max<uint64_t>(CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5, short_term_median), CRYPTONOTE_SHORT_TERM_BLOCK_WEIGHT_SURGE_FACTOR * m_long_term_effective_median_block_weight);
+
+ m_current_block_cumul_weight_median = effective_median_block_weight;
+ }
+
+ if (m_current_block_cumul_weight_median <= full_reward_zone)
+ m_current_block_cumul_weight_median = full_reward_zone;
+
+ m_current_block_cumul_weight_limit = m_current_block_cumul_weight_median * 2;
+
+ if (long_term_effective_median_block_weight)
+ *long_term_effective_median_block_weight = m_long_term_effective_median_block_weight;
- m_current_block_cumul_weight_limit = median*2;
return true;
}
//------------------------------------------------------------------
-bool Blockchain::add_new_block(const block& bl_, block_verification_context& bvc)
+bool Blockchain::add_new_block(const block& bl, block_verification_context& bvc)
{
LOG_PRINT_L3("Blockchain::" << __func__);
- //copy block here to let modify block.target
- block bl = bl_;
crypto::hash id = get_block_hash(bl);
CRITICAL_REGION_LOCAL(m_tx_pool);//to avoid deadlock lets lock tx_pool for whole add/reorganize process
CRITICAL_REGION_LOCAL1(m_blockchain_lock);
@@ -3800,10 +3930,11 @@ void Blockchain::check_against_checkpoints(const checkpoints& points, bool enfor
CRITICAL_REGION_LOCAL(m_blockchain_lock);
stop_batch = m_db->batch_start();
+ const uint64_t blockchain_height = m_db->height();
for (const auto& pt : pts)
{
// if the checkpoint is for a block we don't have yet, move on
- if (pt.first >= m_db->height())
+ if (pt.first >= blockchain_height)
{
continue;
}
@@ -4078,13 +4209,14 @@ uint64_t Blockchain::prevalidate_block_hashes(uint64_t height, const std::vector
// vs [k_image, output_keys] (m_scan_table). This is faster because it takes advantage of bulk queries
// and is threaded if possible. The table (m_scan_table) will be used later when querying output
// keys.
-bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete_entry> &blocks_entry)
+bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete_entry> &blocks_entry, std::vector<block> &blocks)
{
MTRACE("Blockchain::" << __func__);
TIME_MEASURE_START(prepare);
bool stop_batch;
uint64_t bytes = 0;
size_t total_txs = 0;
+ blocks.clear();
// Order of locking must be:
// m_incoming_tx_lock (optional)
@@ -4131,7 +4263,6 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
bool blocks_exist = false;
tools::threadpool& tpool = tools::threadpool::getInstance();
unsigned threads = tpool.get_max_concurrency();
- std::vector<block> blocks;
blocks.resize(blocks_entry.size());
if (1)
@@ -4147,6 +4278,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
auto it = blocks_entry.begin();
unsigned blockidx = 0;
+ const crypto::hash tophash = m_db->top_block_hash();
for (unsigned i = 0; i < threads; i++)
{
for (unsigned int j = 0; j < batches; j++, ++blockidx)
@@ -4159,18 +4291,15 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
// check first block and skip all blocks if its not chained properly
if (blockidx == 0)
{
- crypto::hash tophash = m_db->top_block_hash();
if (block.prev_id != tophash)
{
MDEBUG("Skipping prepare blocks. New blocks don't belong to chain.");
+ blocks.clear();
return true;
}
}
if (have_block(get_block_hash(block)))
- {
blocks_exist = true;
- break;
- }
std::advance(it, 1);
}
@@ -4184,10 +4313,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
return false;
if (have_block(get_block_hash(block)))
- {
blocks_exist = true;
- break;
- }
std::advance(it, 1);
}
@@ -4202,7 +4328,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
unsigned nblocks = batches;
if (i < extra)
++nblocks;
- tpool.submit(&waiter, boost::bind(&Blockchain::block_longhash_worker, this, thread_height, epee::span<const block>(&blocks[i], nblocks), std::ref(maps[i])), true);
+ tpool.submit(&waiter, boost::bind(&Blockchain::block_longhash_worker, this, thread_height, epee::span<const block>(&blocks[thread_height - height], nblocks), std::ref(maps[i])), true);
thread_height += nblocks;
}
@@ -4223,7 +4349,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
if (blocks_exist)
{
- MDEBUG("Skipping prepare blocks. Blocks exist.");
+ MDEBUG("Skipping remainder of prepare blocks. Blocks exist.");
return true;
}
@@ -4579,7 +4705,7 @@ void Blockchain::cancel()
}
#if defined(PER_BLOCK_CHECKPOINT)
-static const char expected_block_hashes_hash[] = "954cb2bbfa2fe6f74b2cdd22a1a4c767aea249ad47ad4f7c9445f0f03260f511";
+static const char expected_block_hashes_hash[] = "570ce2357b08fadac6058e34f95c5e08323f9325de260d07b091a281a948a7b0";
void Blockchain::load_compiled_in_block_hashes(const GetCheckpointsCallback& get_checkpoints)
{
if (get_checkpoints == nullptr || !m_fast_sync)
@@ -4652,10 +4778,11 @@ void Blockchain::load_compiled_in_block_hashes(const GetCheckpointsCallback& get
uint64_t fee;
bool relayed, do_not_relay, double_spend_seen;
transaction pool_tx;
+ blobdata txblob;
for(const transaction &tx : txs)
{
crypto::hash tx_hash = get_transaction_hash(tx);
- m_tx_pool.take_tx(tx_hash, pool_tx, tx_weight, fee, relayed, do_not_relay, double_spend_seen);
+ m_tx_pool.take_tx(tx_hash, pool_tx, txblob, tx_weight, fee, relayed, do_not_relay, double_spend_seen);
}
}
}
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index c742bec91..4744defc5 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -37,6 +37,7 @@
#include <boost/multi_index/global_fun.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/member.hpp>
+#include <boost/circular_buffer.hpp>
#include <atomic>
#include <functional>
#include <unordered_map>
@@ -229,11 +230,12 @@ namespace cryptonote
/**
* @brief performs some preprocessing on a group of incoming blocks to speed up verification
*
- * @param blocks a list of incoming blocks
+ * @param blocks_entry a list of incoming blocks
+ * @param blocks the parsed blocks
*
* @return false on erroneous blocks, else true
*/
- bool prepare_handle_incoming_blocks(const std::vector<block_complete_entry> &blocks);
+ bool prepare_handle_incoming_blocks(const std::vector<block_complete_entry> &blocks_entry, std::vector<block> &blocks);
/**
* @brief incoming blocks post-processing, cleanup, and disk sync
@@ -631,6 +633,13 @@ namespace cryptonote
uint64_t get_current_cumulative_block_weight_limit() const;
/**
+ * @brief gets the long term block weight for a new block
+ *
+ * @return the long term block weight
+ */
+ uint64_t get_next_long_term_block_weight(uint64_t block_weight) const;
+
+ /**
* @brief gets the block weight median based on recent blocks (same window as for the limit)
*
* @return the median
@@ -994,7 +1003,9 @@ namespace cryptonote
*/
void pop_blocks(uint64_t nblocks);
+#ifndef IN_UNIT_TESTS
private:
+#endif
// TODO: evaluate whether or not each of these typedefs are left over from blockchain_storage
typedef std::unordered_map<crypto::hash, size_t> blocks_by_id_index;
@@ -1047,6 +1058,8 @@ namespace cryptonote
std::vector<uint64_t> m_timestamps;
std::vector<difficulty_type> m_difficulties;
uint64_t m_timestamps_and_difficulties_height;
+ uint64_t m_long_term_block_weights_window;
+ uint64_t m_long_term_effective_median_block_weight;
epee::critical_section m_difficulty_lock;
crypto::hash m_difficulty_for_next_block_top_hash;
@@ -1280,7 +1293,7 @@ namespace cryptonote
* @param sz return-by-reference the list of weights
* @param count the number of blocks to get weights for
*/
- void get_last_n_blocks_weights(std::vector<size_t>& weights, size_t count) const;
+ void get_last_n_blocks_weights(std::vector<uint64_t>& weights, size_t count) const;
/**
* @brief checks if a transaction is unlocked (its outputs spendable)
@@ -1379,10 +1392,12 @@ namespace cryptonote
/**
* @brief calculate the block weight limit for the next block to be added
*
+ * @param long_term_effective_median_block_weight optionally return that value
+ *
* @return true
*/
- bool update_next_cumulative_weight_limit();
- void return_tx_to_pool(std::vector<transaction> &txs);
+ bool update_next_cumulative_weight_limit(uint64_t *long_term_effective_median_block_weight = NULL);
+ void return_tx_to_pool(std::vector<std::pair<transaction, blobdata>> &txs);
/**
* @brief make sure a transaction isn't attempting a double-spend
diff --git a/src/cryptonote_core/blockchain_storage_boost_serialization.h b/src/cryptonote_core/blockchain_storage_boost_serialization.h
index f4f9f20ca..cfeb5acfc 100644
--- a/src/cryptonote_core/blockchain_storage_boost_serialization.h
+++ b/src/cryptonote_core/blockchain_storage_boost_serialization.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 1513bb750..58acdb6bb 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -188,8 +188,21 @@ namespace cryptonote
static const command_line::arg_descriptor<std::string> arg_reorg_notify = {
"reorg-notify"
, "Run a program for each reorg, '%s' will be replaced by the split height, "
- "'%h' will be replaced by the new blockchain height, and '%n' will be "
- "replaced by the number of new blocks in the new chain"
+ "'%h' will be replaced by the new blockchain height, '%n' will be "
+ "replaced by the number of new blocks in the new chain, and '%d' will be "
+ "replaced by the number of blocks discarded from the old chain"
+ , ""
+ };
+ static const command_line::arg_descriptor<std::string> arg_block_rate_notify = {
+ "block-rate-notify"
+ , "Run a program when the block rate undergoes large fluctuations. This might "
+ "be a sign of large amounts of hash rate going on and off the Monero network, "
+ "and thus be of potential interest in predicting attacks. %t will be replaced "
+ "by the number of minutes for the observation window, %b by the number of "
+ "blocks observed within that window, and %e by the number of blocks that was "
+ "expected in that window. It is suggested that this notification is used to "
+ "automatically increase the number of confirmations required before a payment "
+ "is acted upon."
, ""
};
@@ -308,6 +321,7 @@ namespace cryptonote
command_line::add_arg(desc, arg_block_notify);
command_line::add_arg(desc, arg_prune_blockchain);
command_line::add_arg(desc, arg_reorg_notify);
+ command_line::add_arg(desc, arg_block_rate_notify);
miner::init_options(desc);
BlockchainDB::init_options(desc);
@@ -587,7 +601,7 @@ namespace cryptonote
}
catch (const std::exception &e)
{
- MERROR("Failed to parse block notify spec");
+ MERROR("Failed to parse block notify spec: " << e.what());
}
try
@@ -597,12 +611,23 @@ namespace cryptonote
}
catch (const std::exception &e)
{
- MERROR("Failed to parse reorg notify spec");
+ MERROR("Failed to parse reorg notify spec: " << e.what());
+ }
+
+ try
+ {
+ if (!command_line::is_arg_defaulted(vm, arg_block_rate_notify))
+ m_block_rate_notify.reset(new tools::Notify(command_line::get_arg(vm, arg_block_rate_notify).c_str()));
+ }
+ catch (const std::exception &e)
+ {
+ MERROR("Failed to parse block rate notify spec: " << e.what());
}
const std::pair<uint8_t, uint64_t> regtest_hard_forks[3] = {std::make_pair(1, 0), std::make_pair(Blockchain::get_hard_fork_heights(MAINNET).back().version, 1), std::make_pair(0, 0)};
const cryptonote::test_options regtest_test_options = {
- regtest_hard_forks
+ regtest_hard_forks,
+ 0
};
const difficulty_type fixed_difficulty = command_line::get_arg(vm, arg_fixed_difficulty);
r = m_blockchain_storage.init(db.release(), m_nettype, m_offline, regtest ? &regtest_test_options : test_options, fixed_difficulty, get_checkpoints);
@@ -699,7 +724,7 @@ namespace cryptonote
return false;
}
//-----------------------------------------------------------------------------------------------
- bool core::handle_incoming_tx_pre(const blobdata& tx_blob, tx_verification_context& tvc, cryptonote::transaction &tx, crypto::hash &tx_hash, crypto::hash &tx_prefixt_hash, bool keeped_by_block, bool relayed, bool do_not_relay)
+ bool core::handle_incoming_tx_pre(const blobdata& tx_blob, tx_verification_context& tvc, cryptonote::transaction &tx, crypto::hash &tx_hash, bool keeped_by_block, bool relayed, bool do_not_relay)
{
tvc = boost::value_initialized<tx_verification_context>();
@@ -712,9 +737,8 @@ namespace cryptonote
}
tx_hash = crypto::null_hash;
- tx_prefixt_hash = crypto::null_hash;
- if(!parse_tx_from_blob(tx, tx_hash, tx_prefixt_hash, tx_blob))
+ if(!parse_tx_from_blob(tx, tx_hash, tx_blob))
{
LOG_PRINT_L1("WRONG TRANSACTION BLOB, Failed to parse, rejected");
tvc.m_verifivation_failed = true;
@@ -747,7 +771,7 @@ namespace cryptonote
return true;
}
//-----------------------------------------------------------------------------------------------
- bool core::handle_incoming_tx_post(const blobdata& tx_blob, tx_verification_context& tvc, cryptonote::transaction &tx, crypto::hash &tx_hash, crypto::hash &tx_prefixt_hash, bool keeped_by_block, bool relayed, bool do_not_relay)
+ bool core::handle_incoming_tx_post(const blobdata& tx_blob, tx_verification_context& tvc, cryptonote::transaction &tx, crypto::hash &tx_hash, bool keeped_by_block, bool relayed, bool do_not_relay)
{
if(!check_tx_syntax(tx))
{
@@ -881,7 +905,7 @@ namespace cryptonote
TRY_ENTRY();
CRITICAL_REGION_LOCAL(m_incoming_tx_lock);
- struct result { bool res; cryptonote::transaction tx; crypto::hash hash; crypto::hash prefix_hash; };
+ struct result { bool res; cryptonote::transaction tx; crypto::hash hash; };
std::vector<result> results(tx_blobs.size());
tvc.resize(tx_blobs.size());
@@ -892,7 +916,7 @@ namespace cryptonote
tpool.submit(&waiter, [&, i, it] {
try
{
- results[i].res = handle_incoming_tx_pre(*it, tvc[i], results[i].tx, results[i].hash, results[i].prefix_hash, keeped_by_block, relayed, do_not_relay);
+ results[i].res = handle_incoming_tx_pre(*it, tvc[i], results[i].tx, results[i].hash, keeped_by_block, relayed, do_not_relay);
}
catch (const std::exception &e)
{
@@ -922,7 +946,7 @@ namespace cryptonote
tpool.submit(&waiter, [&, i, it] {
try
{
- results[i].res = handle_incoming_tx_post(*it, tvc[i], results[i].tx, results[i].hash, results[i].prefix_hash, keeped_by_block, relayed, do_not_relay);
+ results[i].res = handle_incoming_tx_post(*it, tvc[i], results[i].tx, results[i].hash, keeped_by_block, relayed, do_not_relay);
}
catch (const std::exception &e)
{
@@ -958,7 +982,7 @@ namespace cryptonote
continue;
const size_t weight = get_transaction_weight(results[i].tx, it->size());
- ok &= add_new_tx(results[i].tx, results[i].hash, tx_blobs[i], results[i].prefix_hash, weight, tvc[i], keeped_by_block, relayed, do_not_relay);
+ ok &= add_new_tx(results[i].tx, results[i].hash, tx_blobs[i], weight, tvc[i], keeped_by_block, relayed, do_not_relay);
if(tvc[i].m_verifivation_failed)
{MERROR_VER("Transaction verification failed: " << results[i].hash);}
else if(tvc[i].m_verifivation_impossible)
@@ -1172,11 +1196,10 @@ namespace cryptonote
bool core::add_new_tx(transaction& tx, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay)
{
crypto::hash tx_hash = get_transaction_hash(tx);
- crypto::hash tx_prefix_hash = get_transaction_prefix_hash(tx);
blobdata bl;
t_serializable_object_to_blob(tx, bl);
size_t tx_weight = get_transaction_weight(tx, bl.size());
- return add_new_tx(tx, tx_hash, bl, tx_prefix_hash, tx_weight, tvc, keeped_by_block, relayed, do_not_relay);
+ return add_new_tx(tx, tx_hash, bl, tx_weight, tvc, keeped_by_block, relayed, do_not_relay);
}
//-----------------------------------------------------------------------------------------------
size_t core::get_blockchain_total_transactions() const
@@ -1184,7 +1207,7 @@ namespace cryptonote
return m_blockchain_storage.get_total_transactions();
}
//-----------------------------------------------------------------------------------------------
- bool core::add_new_tx(transaction& tx, const crypto::hash& tx_hash, const cryptonote::blobdata &blob, const crypto::hash& tx_prefix_hash, size_t tx_weight, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay)
+ bool core::add_new_tx(transaction& tx, const crypto::hash& tx_hash, const cryptonote::blobdata &blob, size_t tx_weight, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay)
{
if(m_mempool.have_tx(tx_hash))
{
@@ -1225,8 +1248,8 @@ namespace cryptonote
{
std::vector<std::pair<crypto::hash, cryptonote::blobdata>> txs;
cryptonote::transaction tx;
- crypto::hash tx_hash, tx_prefix_hash;
- if (!parse_and_validate_tx_from_blob(tx_blob, tx, tx_hash, tx_prefix_hash))
+ crypto::hash tx_hash;
+ if (!parse_and_validate_tx_from_blob(tx_blob, tx, tx_hash))
{
LOG_ERROR("Failed to parse relayed transaction");
return;
@@ -1307,7 +1330,13 @@ namespace cryptonote
m_miner.resume();
return false;
}
- prepare_handle_incoming_blocks(blocks);
+ std::vector<block> pblocks;
+ if (!prepare_handle_incoming_blocks(blocks, pblocks))
+ {
+ MERROR("Block found, but failed to prepare to add");
+ m_miner.resume();
+ return false;
+ }
m_blockchain_storage.add_new_block(b, bvc);
cleanup_handle_incoming_blocks(true);
//anyway - update miner template
@@ -1358,10 +1387,14 @@ namespace cryptonote
}
//-----------------------------------------------------------------------------------------------
- bool core::prepare_handle_incoming_blocks(const std::vector<block_complete_entry> &blocks)
+ bool core::prepare_handle_incoming_blocks(const std::vector<block_complete_entry> &blocks_entry, std::vector<block> &blocks)
{
m_incoming_tx_lock.lock();
- m_blockchain_storage.prepare_handle_incoming_blocks(blocks);
+ if (!m_blockchain_storage.prepare_handle_incoming_blocks(blocks_entry, blocks))
+ {
+ cleanup_handle_incoming_blocks(false);
+ return false;
+ }
return true;
}
@@ -1378,7 +1411,7 @@ namespace cryptonote
}
//-----------------------------------------------------------------------------------------------
- bool core::handle_incoming_block(const blobdata& block_blob, block_verification_context& bvc, bool update_miner_blocktemplate)
+ bool core::handle_incoming_block(const blobdata& block_blob, const block *b, block_verification_context& bvc, bool update_miner_blocktemplate)
{
TRY_ENTRY();
@@ -1394,14 +1427,18 @@ namespace cryptonote
return false;
}
- block b = AUTO_VAL_INIT(b);
- if(!parse_and_validate_block_from_blob(block_blob, b))
+ block lb;
+ if (!b)
{
- LOG_PRINT_L1("Failed to parse and validate new block");
- bvc.m_verifivation_failed = true;
- return false;
+ if(!parse_and_validate_block_from_blob(block_blob, lb))
+ {
+ LOG_PRINT_L1("Failed to parse and validate new block");
+ bvc.m_verifivation_failed = true;
+ return false;
+ }
+ b = &lb;
}
- add_new_block(b, bvc);
+ add_new_block(*b, bvc);
if(update_miner_blocktemplate && bvc.m_added_to_main_chain)
update_miner_block_template();
return true;
@@ -1441,9 +1478,9 @@ namespace cryptonote
return m_blockchain_storage.have_block(id);
}
//-----------------------------------------------------------------------------------------------
- bool core::parse_tx_from_blob(transaction& tx, crypto::hash& tx_hash, crypto::hash& tx_prefix_hash, const blobdata& blob) const
+ bool core::parse_tx_from_blob(transaction& tx, crypto::hash& tx_hash, const blobdata& blob) const
{
- return parse_and_validate_tx_from_blob(blob, tx, tx_hash, tx_prefix_hash);
+ return parse_and_validate_tx_from_blob(blob, tx, tx_hash);
}
//-----------------------------------------------------------------------------------------------
bool core::check_tx_syntax(const transaction& tx) const
@@ -1764,7 +1801,7 @@ namespace cryptonote
const time_t now = time(NULL);
const std::vector<time_t> timestamps = m_blockchain_storage.get_last_block_timestamps(60);
- static const unsigned int seconds[] = { 5400, 1800, 600 };
+ static const unsigned int seconds[] = { 5400, 3600, 1800, 1200, 600 };
for (size_t n = 0; n < sizeof(seconds)/sizeof(seconds[0]); ++n)
{
unsigned int b = 0;
@@ -1775,6 +1812,14 @@ namespace cryptonote
if (p < threshold)
{
MWARNING("There were " << b << " blocks in the last " << seconds[n] / 60 << " minutes, there might be large hash rate changes, or we might be partitioned, cut off from the Monero network or under attack. Or it could be just sheer bad luck.");
+
+ std::shared_ptr<tools::Notify> block_rate_notify = m_block_rate_notify;
+ if (block_rate_notify)
+ {
+ auto expected = seconds[n] / DIFFICULTY_TARGET_V2;
+ block_rate_notify->notify("%t", std::to_string(seconds[n] / 60).c_str(), "%b", std::to_string(b).c_str(), "%e", std::to_string(expected).c_str(), NULL);
+ }
+
break; // no need to look further
}
}
diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h
index 4810fc891..356265dd6 100644
--- a/src/cryptonote_core/cryptonote_core.h
+++ b/src/cryptonote_core/cryptonote_core.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -54,6 +54,7 @@ namespace cryptonote
{
struct test_options {
const std::pair<uint8_t, uint64_t> *hard_forks;
+ const size_t long_term_block_weight_window;
};
extern const command_line::arg_descriptor<std::string, false, true, 2> arg_data_dir;
@@ -145,20 +146,21 @@ namespace cryptonote
* optionally updates the miner's block template.
*
* @param block_blob the block to be added
+ * @param block the block to be added, or NULL
* @param bvc return-by-reference metadata context about the block's validity
* @param update_miner_blocktemplate whether or not to update the miner's block template
*
* @return false if loading new checkpoints fails, or the block is not
* added, otherwise true
*/
- bool handle_incoming_block(const blobdata& block_blob, block_verification_context& bvc, bool update_miner_blocktemplate = true);
+ bool handle_incoming_block(const blobdata& block_blob, const block *b, block_verification_context& bvc, bool update_miner_blocktemplate = true);
/**
* @copydoc Blockchain::prepare_handle_incoming_blocks
*
* @note see Blockchain::prepare_handle_incoming_blocks
*/
- bool prepare_handle_incoming_blocks(const std::vector<block_complete_entry> &blocks);
+ bool prepare_handle_incoming_blocks(const std::vector<block_complete_entry> &blocks_entry, std::vector<block> &blocks);
/**
* @copydoc Blockchain::cleanup_handle_incoming_blocks
@@ -828,13 +830,12 @@ namespace cryptonote
*
* @param tx_hash the transaction's hash
* @param blob the transaction as a blob
- * @param tx_prefix_hash the transaction prefix' hash
* @param tx_weight the weight of the transaction
* @param relayed whether or not the transaction was relayed to us
* @param do_not_relay whether to prevent the transaction from being relayed
*
*/
- bool add_new_tx(transaction& tx, const crypto::hash& tx_hash, const cryptonote::blobdata &blob, const crypto::hash& tx_prefix_hash, size_t tx_weight, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay);
+ bool add_new_tx(transaction& tx, const crypto::hash& tx_hash, const cryptonote::blobdata &blob, size_t tx_weight, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay);
/**
* @brief add a new transaction to the transaction pool
@@ -874,7 +875,7 @@ namespace cryptonote
*
* @note see parse_tx_from_blob(transaction&, crypto::hash&, crypto::hash&, const blobdata&) const
*/
- bool parse_tx_from_blob(transaction& tx, crypto::hash& tx_hash, crypto::hash& tx_prefix_hash, const blobdata& blob) const;
+ bool parse_tx_from_blob(transaction& tx, crypto::hash& tx_hash, const blobdata& blob) const;
/**
* @brief check a transaction's syntax
@@ -907,8 +908,8 @@ namespace cryptonote
bool check_tx_semantic(const transaction& tx, bool keeped_by_block) const;
void set_semantics_failed(const crypto::hash &tx_hash);
- bool handle_incoming_tx_pre(const blobdata& tx_blob, tx_verification_context& tvc, cryptonote::transaction &tx, crypto::hash &tx_hash, crypto::hash &tx_prefixt_hash, bool keeped_by_block, bool relayed, bool do_not_relay);
- bool handle_incoming_tx_post(const blobdata& tx_blob, tx_verification_context& tvc, cryptonote::transaction &tx, crypto::hash &tx_hash, crypto::hash &tx_prefixt_hash, bool keeped_by_block, bool relayed, bool do_not_relay);
+ bool handle_incoming_tx_pre(const blobdata& tx_blob, tx_verification_context& tvc, cryptonote::transaction &tx, crypto::hash &tx_hash, bool keeped_by_block, bool relayed, bool do_not_relay);
+ bool handle_incoming_tx_post(const blobdata& tx_blob, tx_verification_context& tvc, cryptonote::transaction &tx, crypto::hash &tx_hash, bool keeped_by_block, bool relayed, bool do_not_relay);
struct tx_verification_batch_info { const cryptonote::transaction *tx; crypto::hash tx_hash; tx_verification_context &tvc; bool &result; };
bool handle_incoming_tx_accumulated_batch(std::vector<tx_verification_batch_info> &tx_info, bool keeped_by_block);
@@ -1061,6 +1062,8 @@ namespace cryptonote
bool m_fluffy_blocks_enabled;
bool m_offline;
bool m_pad_transactions;
+
+ std::shared_ptr<tools::Notify> m_block_rate_notify;
};
}
diff --git a/src/cryptonote_core/cryptonote_tx_utils.cpp b/src/cryptonote_core/cryptonote_tx_utils.cpp
index 0a04e0d38..854f3d1c5 100644
--- a/src/cryptonote_core/cryptonote_tx_utils.cpp
+++ b/src/cryptonote_core/cryptonote_tx_utils.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -405,49 +405,12 @@ namespace cryptonote
for(const tx_destination_entry& dst_entr: destinations)
{
CHECK_AND_ASSERT_MES(dst_entr.amount > 0 || tx.version > 1, false, "Destination with wrong amount: " << dst_entr.amount);
- crypto::key_derivation derivation;
crypto::public_key out_eph_public_key;
- // make additional tx pubkey if necessary
- keypair additional_txkey;
- if (need_additional_txkeys)
- {
- additional_txkey.sec = additional_tx_keys[output_index];
- if (dst_entr.is_subaddress)
- additional_txkey.pub = rct::rct2pk(hwdev.scalarmultKey(rct::pk2rct(dst_entr.addr.m_spend_public_key), rct::sk2rct(additional_txkey.sec)));
- else
- additional_txkey.pub = rct::rct2pk(hwdev.scalarmultBase(rct::sk2rct(additional_txkey.sec)));
- }
-
- bool r;
- if (change_addr && dst_entr.addr == *change_addr)
- {
- // sending change to yourself; derivation = a*R
- r = hwdev.generate_key_derivation(txkey_pub, sender_account_keys.m_view_secret_key, derivation);
- CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to generate_key_derivation(" << txkey_pub << ", " << sender_account_keys.m_view_secret_key << ")");
- }
- else
- {
- // sending to the recipient; derivation = r*A (or s*C in the subaddress scheme)
- r = hwdev.generate_key_derivation(dst_entr.addr.m_view_public_key, dst_entr.is_subaddress && need_additional_txkeys ? additional_txkey.sec : tx_key, derivation);
- CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to generate_key_derivation(" << dst_entr.addr.m_view_public_key << ", " << (dst_entr.is_subaddress && need_additional_txkeys ? additional_txkey.sec : tx_key) << ")");
- }
-
- if (need_additional_txkeys)
- {
- additional_tx_public_keys.push_back(additional_txkey.pub);
- }
-
- if (tx.version > 1)
- {
- crypto::secret_key scalar1;
- hwdev.derivation_to_scalar(derivation, output_index, scalar1);
- amount_keys.push_back(rct::sk2rct(scalar1));
- }
- r = hwdev.derive_public_key(derivation, output_index, dst_entr.addr.m_spend_public_key, out_eph_public_key);
- CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to derive_public_key(" << derivation << ", " << output_index << ", "<< dst_entr.addr.m_spend_public_key << ")");
-
- hwdev.add_output_key_mapping(dst_entr.addr.m_view_public_key, dst_entr.addr.m_spend_public_key, dst_entr.is_subaddress, output_index, amount_keys.back(), out_eph_public_key);
+ hwdev.generate_output_ephemeral_keys(tx.version,sender_account_keys, txkey_pub, tx_key,
+ dst_entr, change_addr, output_index,
+ need_additional_txkeys, additional_tx_keys,
+ additional_tx_public_keys, amount_keys, out_eph_public_key);
tx_out out;
out.amount = dst_entr.amount;
diff --git a/src/cryptonote_core/cryptonote_tx_utils.h b/src/cryptonote_core/cryptonote_tx_utils.h
index 85061668b..cb1561c2d 100644
--- a/src/cryptonote_core/cryptonote_tx_utils.h
+++ b/src/cryptonote_core/cryptonote_tx_utils.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -97,6 +97,12 @@ 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_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 }, rct::multisig_out *msout = NULL, bool shuffle_outs = 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 = false, const rct::RCTConfig &rct_config = { rct::RangeProofBorromean, 0 }, rct::multisig_out *msout = NULL);
+ 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,
+ std::vector<crypto::public_key> &additional_tx_public_keys,
+ std::vector<rct::key> &amount_keys,
+ crypto::public_key &out_eph_public_key) ;
bool generate_genesis_block(
block& bl
diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp
index 1c8f1c62c..c1cbe2acd 100644
--- a/src/cryptonote_core/tx_pool.cpp
+++ b/src/cryptonote_core/tx_pool.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -453,7 +453,7 @@ namespace cryptonote
return true;
}
//---------------------------------------------------------------------------------
- bool tx_memory_pool::take_tx(const crypto::hash &id, transaction &tx, size_t& tx_weight, uint64_t& fee, bool &relayed, bool &do_not_relay, bool &double_spend_seen)
+ bool tx_memory_pool::take_tx(const crypto::hash &id, transaction &tx, cryptonote::blobdata &txblob, size_t& tx_weight, uint64_t& fee, bool &relayed, bool &do_not_relay, bool &double_spend_seen)
{
CRITICAL_REGION_LOCAL(m_transactions_lock);
CRITICAL_REGION_LOCAL1(m_blockchain);
@@ -469,7 +469,7 @@ namespace cryptonote
MERROR("Failed to find tx in txpool");
return false;
}
- cryptonote::blobdata txblob = m_blockchain.get_txpool_tx_blob(id);
+ txblob = m_blockchain.get_txpool_tx_blob(id);
auto ci = m_parsed_tx_cache.find(id);
if (ci != m_parsed_tx_cache.end())
{
diff --git a/src/cryptonote_core/tx_pool.h b/src/cryptonote_core/tx_pool.h
index 670d70d77..877f2b82f 100644
--- a/src/cryptonote_core/tx_pool.h
+++ b/src/cryptonote_core/tx_pool.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -61,7 +61,7 @@ namespace cryptonote
class txCompare
{
public:
- bool operator()(const tx_by_fee_and_receive_time_entry& a, const tx_by_fee_and_receive_time_entry& b)
+ bool operator()(const tx_by_fee_and_receive_time_entry& a, const tx_by_fee_and_receive_time_entry& b) const
{
// sort by greatest first, not least
if (a.first.first > b.first.first) return true;
@@ -133,6 +133,7 @@ namespace cryptonote
*
* @param id the hash of the transaction
* @param tx return-by-reference the transaction taken
+ * @param txblob return-by-reference the transaction as a blob
* @param tx_weight return-by-reference the transaction's weight
* @param fee the transaction fee
* @param relayed return-by-reference was transaction relayed to us by the network?
@@ -141,7 +142,7 @@ namespace cryptonote
*
* @return true unless the transaction cannot be found in the pool
*/
- bool take_tx(const crypto::hash &id, transaction &tx, size_t& tx_weight, uint64_t& fee, bool &relayed, bool &do_not_relay, bool &double_spend_seen);
+ bool take_tx(const crypto::hash &id, transaction &tx, cryptonote::blobdata &txblob, size_t& tx_weight, uint64_t& fee, bool &relayed, bool &do_not_relay, bool &double_spend_seen);
/**
* @brief checks if the pool has a transaction with the given hash
diff --git a/src/cryptonote_protocol/CMakeLists.txt b/src/cryptonote_protocol/CMakeLists.txt
index 1189ccf22..bfcf42767 100644
--- a/src/cryptonote_protocol/CMakeLists.txt
+++ b/src/cryptonote_protocol/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/src/cryptonote_protocol/block_queue.cpp b/src/cryptonote_protocol/block_queue.cpp
index 716b0c8ba..b4f9daa74 100644
--- a/src/cryptonote_protocol/block_queue.cpp
+++ b/src/cryptonote_protocol/block_queue.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/cryptonote_protocol/block_queue.h b/src/cryptonote_protocol/block_queue.h
index c7d3af7ac..1bef01d67 100644
--- a/src/cryptonote_protocol/block_queue.h
+++ b/src/cryptonote_protocol/block_queue.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/cryptonote_protocol/cryptonote_protocol_defs.h b/src/cryptonote_protocol/cryptonote_protocol_defs.h
index c49371d48..289223b6d 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_defs.h
+++ b/src/cryptonote_protocol/cryptonote_protocol_defs.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -48,6 +48,7 @@ namespace cryptonote
bool incoming;
bool localhost;
bool local_ip;
+ bool ssl;
std::string address;
std::string host;
@@ -127,7 +128,7 @@ namespace cryptonote
{
const static int ID = BC_COMMANDS_POOL_BASE + 1;
- struct request
+ struct request_t
{
block_complete_entry b;
uint64_t current_blockchain_height;
@@ -137,6 +138,7 @@ namespace cryptonote
KV_SERIALIZE(current_blockchain_height)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
};
/************************************************************************/
@@ -146,7 +148,7 @@ namespace cryptonote
{
const static int ID = BC_COMMANDS_POOL_BASE + 2;
- struct request
+ struct request_t
{
std::vector<blobdata> txs;
std::string _; // padding
@@ -156,6 +158,7 @@ namespace cryptonote
KV_SERIALIZE(_)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
};
/************************************************************************/
/* */
@@ -164,7 +167,7 @@ namespace cryptonote
{
const static int ID = BC_COMMANDS_POOL_BASE + 3;
- struct request
+ struct request_t
{
std::vector<crypto::hash> txs;
std::vector<crypto::hash> blocks;
@@ -174,13 +177,14 @@ namespace cryptonote
KV_SERIALIZE_CONTAINER_POD_AS_BLOB(blocks)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
};
struct NOTIFY_RESPONSE_GET_OBJECTS
{
const static int ID = BC_COMMANDS_POOL_BASE + 4;
- struct request
+ struct request_t
{
std::vector<blobdata> txs;
std::vector<block_complete_entry> blocks;
@@ -194,6 +198,7 @@ namespace cryptonote
KV_SERIALIZE(current_blockchain_height)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
};
@@ -218,7 +223,7 @@ namespace cryptonote
{
const static int ID = BC_COMMANDS_POOL_BASE + 6;
- struct request
+ struct request_t
{
std::list<crypto::hash> block_ids; /*IDs of the first 10 blocks are sequential, next goes with pow(2,n) offset, like 2, 4, 8, 16, 32, 64 and so on, and the last one is always genesis block */
@@ -226,13 +231,14 @@ namespace cryptonote
KV_SERIALIZE_CONTAINER_POD_AS_BLOB(block_ids)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
};
struct NOTIFY_RESPONSE_CHAIN_ENTRY
{
const static int ID = BC_COMMANDS_POOL_BASE + 7;
- struct request
+ struct request_t
{
uint64_t start_height;
uint64_t total_height;
@@ -246,6 +252,7 @@ namespace cryptonote
KV_SERIALIZE_CONTAINER_POD_AS_BLOB(m_block_ids)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
};
/************************************************************************/
@@ -255,7 +262,7 @@ namespace cryptonote
{
const static int ID = BC_COMMANDS_POOL_BASE + 8;
- struct request
+ struct request_t
{
block_complete_entry b;
uint64_t current_blockchain_height;
@@ -265,6 +272,7 @@ namespace cryptonote
KV_SERIALIZE(current_blockchain_height)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
};
/************************************************************************/
@@ -274,7 +282,7 @@ namespace cryptonote
{
const static int ID = BC_COMMANDS_POOL_BASE + 9;
- struct request
+ struct request_t
{
crypto::hash block_hash;
uint64_t current_blockchain_height;
@@ -286,6 +294,7 @@ namespace cryptonote
KV_SERIALIZE_CONTAINER_POD_AS_BLOB(missing_tx_indices)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
};
}
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp b/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp
index 6d9ad9028..225418980 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp
@@ -2,7 +2,7 @@
/// @author rfree (current maintainer in monero.cc project)
/// @brief This is the place to implement our handlers for protocol network actions, e.g. for ratelimit for download-requests
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.h b/src/cryptonote_protocol/cryptonote_protocol_handler.h
index efd986b53..fc7db629c 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler.h
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler.h
@@ -2,7 +2,7 @@
/// @author rfree (current maintainer/user in monero.cc project - most of code is from CryptoNote)
/// @brief This is the original cryptonote protocol network-events handler, modified by us
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
index c1459cbb6..9d52935f1 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
@@ -2,7 +2,7 @@
/// @author rfree (current maintainer/user in monero.cc project - most of code is from CryptoNote)
/// @brief This is the original cryptonote protocol network-events handler, modified by us
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -268,6 +268,7 @@ namespace cryptonote
cnx.current_upload = cntxt.m_current_speed_up / 1024;
cnx.connection_id = epee::string_tools::pod_to_hex(cntxt.m_connection_id);
+ cnx.ssl = cntxt.m_ssl;
cnx.height = cntxt.m_remote_blockchain_height;
cnx.pruning_seed = cntxt.m_pruning_seed;
@@ -417,7 +418,14 @@ namespace cryptonote
m_core.pause_mine();
std::vector<block_complete_entry> blocks;
blocks.push_back(arg.b);
- m_core.prepare_handle_incoming_blocks(blocks);
+ std::vector<block> pblocks;
+ if (!m_core.prepare_handle_incoming_blocks(blocks, pblocks))
+ {
+ LOG_PRINT_CCONTEXT_L1("Block verification failed: prepare_handle_incoming_blocks failed, dropping connection");
+ drop_connection(context, false, false);
+ m_core.resume_mine();
+ return 1;
+ }
for(auto tx_blob_it = arg.b.txs.begin(); tx_blob_it!=arg.b.txs.end();tx_blob_it++)
{
cryptonote::tx_verification_context tvc = AUTO_VAL_INIT(tvc);
@@ -433,7 +441,7 @@ namespace cryptonote
}
block_verification_context bvc = boost::value_initialized<block_verification_context>();
- m_core.handle_incoming_block(arg.b.block, bvc); // got block from handle_notify_new_block
+ m_core.handle_incoming_block(arg.b.block, pblocks.empty() ? NULL : &pblocks[0], bvc); // got block from handle_notify_new_block
if (!m_core.cleanup_handle_incoming_blocks(true))
{
LOG_PRINT_CCONTEXT_L0("Failure in cleanup_handle_incoming_blocks");
@@ -696,10 +704,16 @@ namespace cryptonote
std::vector<block_complete_entry> blocks;
blocks.push_back(b);
- m_core.prepare_handle_incoming_blocks(blocks);
+ std::vector<block> pblocks;
+ if (!m_core.prepare_handle_incoming_blocks(blocks, pblocks))
+ {
+ LOG_PRINT_CCONTEXT_L0("Failure in prepare_handle_incoming_blocks");
+ m_core.resume_mine();
+ return 1;
+ }
block_verification_context bvc = boost::value_initialized<block_verification_context>();
- m_core.handle_incoming_block(arg.b.block, bvc); // got block from handle_notify_new_block
+ m_core.handle_incoming_block(arg.b.block, pblocks.empty() ? NULL : &pblocks[0], bvc); // got block from handle_notify_new_block
if (!m_core.cleanup_handle_incoming_blocks(true))
{
LOG_PRINT_CCONTEXT_L0("Failure in cleanup_handle_incoming_blocks");
@@ -1173,10 +1187,21 @@ namespace cryptonote
}
}
- m_core.prepare_handle_incoming_blocks(blocks);
+ std::vector<block> pblocks;
+ if (!m_core.prepare_handle_incoming_blocks(blocks, pblocks))
+ {
+ LOG_ERROR_CCONTEXT("Failure in prepare_handle_incoming_blocks");
+ return 1;
+ }
+ if (!pblocks.empty() && pblocks.size() != blocks.size())
+ {
+ m_core.cleanup_handle_incoming_blocks();
+ LOG_ERROR_CCONTEXT("Internal error: blocks.size() != block_entry.txs.size()");
+ return 1;
+ }
uint64_t block_process_time_full = 0, transactions_process_time_full = 0;
- size_t num_txs = 0;
+ size_t num_txs = 0, blockidx = 0;
for(const block_complete_entry& block_entry: blocks)
{
if (m_stopping)
@@ -1228,7 +1253,7 @@ namespace cryptonote
TIME_MEASURE_START(block_process_time);
block_verification_context bvc = boost::value_initialized<block_verification_context>();
- m_core.handle_incoming_block(block_entry.block, bvc, false); // <--- process block
+ m_core.handle_incoming_block(block_entry.block, pblocks.empty() ? NULL : &pblocks[blockidx], bvc, false); // <--- process block
if(bvc.m_verifivation_failed)
{
@@ -1271,6 +1296,7 @@ namespace cryptonote
TIME_MEASURE_FINISH(block_process_time);
block_process_time_full += block_process_time;
+ ++blockidx;
} // each download block
@@ -2111,7 +2137,7 @@ skip:
MDEBUG("Attempting to conceal origin of tx via anonymity network connection(s)");
// no check for success, so tell core they're relayed unconditionally
- const bool pad_transactions = m_core.pad_transactions();
+ const bool pad_transactions = m_core.pad_transactions() || hide_tx_broadcast;
size_t bytes = pad_transactions ? 9 /* header */ + 4 /* 1 + 'txs' */ + tools::get_varint_data(arg.txs.size()).size() : 0;
for(auto tx_blob_it = arg.txs.begin(); tx_blob_it!=arg.txs.end(); ++tx_blob_it)
{
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler_common.h b/src/cryptonote_protocol/cryptonote_protocol_handler_common.h
index 2b9f201ec..a67178c52 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler_common.h
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler_common.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/daemon/CMakeLists.txt b/src/daemon/CMakeLists.txt
index 117790455..d9bfd9a20 100644
--- a/src/daemon/CMakeLists.txt
+++ b/src/daemon/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/src/daemon/command_line_args.h b/src/daemon/command_line_args.h
index cba71bf3b..b75d7381f 100644
--- a/src/daemon/command_line_args.h
+++ b/src/daemon/command_line_args.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/daemon/command_parser_executor.cpp b/src/daemon/command_parser_executor.cpp
index 5d11dabb1..b324ab99d 100644
--- a/src/daemon/command_parser_executor.cpp
+++ b/src/daemon/command_parser_executor.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -302,7 +302,7 @@ bool t_command_parser_executor::start_mining(const std::vector<std::string>& arg
{
if(!args.size())
{
- std::cout << "Please specify a wallet address to mine for: start_mining <addr> [<threads>]" << std::endl;
+ std::cout << "Please specify a wallet address to mine for: start_mining <addr> [<threads>|auto]" << std::endl;
return true;
}
@@ -388,8 +388,15 @@ bool t_command_parser_executor::start_mining(const std::vector<std::string>& arg
if(args.size() >= 2)
{
- bool ok = epee::string_tools::get_xtype_from_string(threads_count, args[1]);
- threads_count = (ok && 0 < threads_count) ? threads_count : 1;
+ if (args[1] == "auto" || args[1] == "autodetect")
+ {
+ threads_count = 0;
+ }
+ else
+ {
+ bool ok = epee::string_tools::get_xtype_from_string(threads_count, args[1]);
+ threads_count = (ok && 0 < threads_count) ? threads_count : 1;
+ }
}
m_executor.start_mining(info.address, threads_count, nettype, do_background_mining, ignore_battery);
diff --git a/src/daemon/command_parser_executor.h b/src/daemon/command_parser_executor.h
index de94039c3..bec6e4522 100644
--- a/src/daemon/command_parser_executor.h
+++ b/src/daemon/command_parser_executor.h
@@ -6,7 +6,7 @@
*/
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/daemon/command_server.cpp b/src/daemon/command_server.cpp
index 45a1e9d98..94e4a8bf1 100644
--- a/src/daemon/command_server.cpp
+++ b/src/daemon/command_server.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -104,8 +104,8 @@ t_command_server::t_command_server(
m_command_lookup.set_handler(
"start_mining"
, std::bind(&t_command_parser_executor::start_mining, &m_parser, p::_1)
- , "start_mining <addr> [<threads>] [do_background_mining] [ignore_battery]"
- , "Start mining for specified address. Defaults to 1 thread and no background mining."
+ , "start_mining <addr> [<threads>|auto] [do_background_mining] [ignore_battery]"
+ , "Start mining for specified address. Defaults to 1 thread and no background mining. Use \"auto\" to autodetect optimal number of threads."
);
m_command_lookup.set_handler(
"stop_mining"
diff --git a/src/daemon/command_server.h b/src/daemon/command_server.h
index aff74da45..c8e77f551 100644
--- a/src/daemon/command_server.h
+++ b/src/daemon/command_server.h
@@ -9,7 +9,7 @@ Passing RPC commands:
*/
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/daemon/core.h b/src/daemon/core.h
index c15d8d236..91dbb7a4b 100644
--- a/src/daemon/core.h
+++ b/src/daemon/core.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp
index 88fba8372..d31468ff3 100644
--- a/src/daemon/daemon.cpp
+++ b/src/daemon/daemon.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/daemon/daemon.h b/src/daemon/daemon.h
index 1e356ef5f..0ce5f8e8f 100644
--- a/src/daemon/daemon.h
+++ b/src/daemon/daemon.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/daemon/executor.cpp b/src/daemon/executor.cpp
index fbc7d04fd..3a4f7141b 100644
--- a/src/daemon/executor.cpp
+++ b/src/daemon/executor.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/daemon/executor.h b/src/daemon/executor.h
index 79d70567a..819538907 100644
--- a/src/daemon/executor.h
+++ b/src/daemon/executor.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/daemon/main.cpp b/src/daemon/main.cpp
index 35017d9ef..d21cac970 100644
--- a/src/daemon/main.cpp
+++ b/src/daemon/main.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/daemon/p2p.h b/src/daemon/p2p.h
index 0f01c746d..267b99c89 100644
--- a/src/daemon/p2p.h
+++ b/src/daemon/p2p.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/daemon/protocol.h b/src/daemon/protocol.h
index fd1d1b638..51a2bce1f 100644
--- a/src/daemon/protocol.h
+++ b/src/daemon/protocol.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/daemon/rpc.h b/src/daemon/rpc.h
index 37dffc097..213593aa7 100644
--- a/src/daemon/rpc.h
+++ b/src/daemon/rpc.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp
index af7beef46..8aaf9ba66 100644
--- a/src/daemon/rpc_command_executor.cpp
+++ b/src/daemon/rpc_command_executor.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -79,6 +79,7 @@ namespace {
<< "POW hash: " << header.pow_hash << std::endl
<< "block size: " << header.block_size << std::endl
<< "block weight: " << header.block_weight << std::endl
+ << "long term weight: " << header.long_term_weight << std::endl
<< "num txes: " << header.num_txes << std::endl
<< "reward: " << cryptonote::print_money(header.reward);
}
@@ -585,6 +586,7 @@ bool t_rpc_command_executor::print_connections() {
}
tools::msg_writer() << std::setw(30) << std::left << "Remote Host"
+ << std::setw(6) << "SSL"
<< std::setw(20) << "Peer id"
<< std::setw(20) << "Support Flags"
<< std::setw(30) << "Recv/Sent (inactive,sec)"
@@ -604,6 +606,7 @@ bool t_rpc_command_executor::print_connections() {
tools::msg_writer()
//<< std::setw(30) << std::left << in_out
<< std::setw(30) << std::left << address
+ << std::setw(6) << (info.ssl ? "yes" : "no")
<< std::setw(20) << epee::string_tools::pad_string(info.peer_id, 16, '0', true)
<< std::setw(20) << info.support_flags
<< std::setw(30) << std::to_string(info.recv_count) + "(" + std::to_string(info.recv_idle_time) + ")/" + std::to_string(info.send_count) + "(" + std::to_string(info.send_idle_time) + ")"
diff --git a/src/daemon/rpc_command_executor.h b/src/daemon/rpc_command_executor.h
index 5221a8cf1..423132b79 100644
--- a/src/daemon/rpc_command_executor.h
+++ b/src/daemon/rpc_command_executor.h
@@ -6,7 +6,7 @@
*/
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/daemonizer/CMakeLists.txt b/src/daemonizer/CMakeLists.txt
index 2753d0003..d540adc10 100644
--- a/src/daemonizer/CMakeLists.txt
+++ b/src/daemonizer/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/src/daemonizer/daemonizer.h b/src/daemonizer/daemonizer.h
index c5852b59c..a45a2b44f 100644
--- a/src/daemonizer/daemonizer.h
+++ b/src/daemonizer/daemonizer.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/daemonizer/posix_daemonizer.inl b/src/daemonizer/posix_daemonizer.inl
index b3f3f262f..9ec09c678 100644
--- a/src/daemonizer/posix_daemonizer.inl
+++ b/src/daemonizer/posix_daemonizer.inl
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/daemonizer/posix_fork.h b/src/daemonizer/posix_fork.h
index 9294b00e2..27b4ac18d 100644
--- a/src/daemonizer/posix_fork.h
+++ b/src/daemonizer/posix_fork.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/daemonizer/windows_daemonizer.inl b/src/daemonizer/windows_daemonizer.inl
index 7e61e3603..701c098f6 100644
--- a/src/daemonizer/windows_daemonizer.inl
+++ b/src/daemonizer/windows_daemonizer.inl
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/daemonizer/windows_service.cpp b/src/daemonizer/windows_service.cpp
index 1302fa578..7d53b07c7 100644
--- a/src/daemonizer/windows_service.cpp
+++ b/src/daemonizer/windows_service.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/daemonizer/windows_service.h b/src/daemonizer/windows_service.h
index aacf3d039..12429c78a 100644
--- a/src/daemonizer/windows_service.h
+++ b/src/daemonizer/windows_service.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/daemonizer/windows_service_runner.h b/src/daemonizer/windows_service_runner.h
index 06e180823..703795ce9 100644
--- a/src/daemonizer/windows_service_runner.h
+++ b/src/daemonizer/windows_service_runner.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/debug_utilities/CMakeLists.txt b/src/debug_utilities/CMakeLists.txt
index 1bcbfd0cf..7bc2c324f 100644
--- a/src/debug_utilities/CMakeLists.txt
+++ b/src/debug_utilities/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/src/debug_utilities/cn_deserialize.cpp b/src/debug_utilities/cn_deserialize.cpp
index f08f2b928..87ded76bd 100644
--- a/src/debug_utilities/cn_deserialize.cpp
+++ b/src/debug_utilities/cn_deserialize.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/debug_utilities/object_sizes.cpp b/src/debug_utilities/object_sizes.cpp
index 2281d0734..302f0a206 100644
--- a/src/debug_utilities/object_sizes.cpp
+++ b/src/debug_utilities/object_sizes.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/device/CMakeLists.txt b/src/device/CMakeLists.txt
index 91d670b73..ffa1458b0 100644
--- a/src/device/CMakeLists.txt
+++ b/src/device/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2017, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/src/device/device.cpp b/src/device/device.cpp
index d5e3031ff..fbd77dab9 100644
--- a/src/device/device.cpp
+++ b/src/device/device.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/device/device.hpp b/src/device/device.hpp
index bdb608907..7f1a60c9f 100644
--- a/src/device/device.hpp
+++ b/src/device/device.hpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
@@ -69,6 +69,7 @@ namespace cryptonote
struct account_public_address;
struct account_keys;
struct subaddress_index;
+ struct tx_destination_entry;
}
namespace hw {
@@ -211,9 +212,12 @@ namespace hw {
virtual bool ecdhEncode(rct::ecdhTuple & unmasked, const rct::key & sharedSec, bool short_amount) = 0;
virtual bool ecdhDecode(rct::ecdhTuple & masked, const rct::key & sharedSec, bool short_amount) = 0;
- virtual bool add_output_key_mapping(const crypto::public_key &Aout, const crypto::public_key &Bout, const bool is_subaddress, const size_t real_output_index,
- const rct::key &amount_key, const crypto::public_key &out_eph_public_key) = 0;
-
+ virtual 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,
+ std::vector<crypto::public_key> &additional_tx_public_keys,
+ std::vector<rct::key> &amount_keys,
+ crypto::public_key &out_eph_public_key) = 0;
virtual bool mlsag_prehash(const std::string &blob, size_t inputs_size, size_t outputs_size, const rct::keyV &hashes, const rct::ctkeyV &outPk, rct::key &prehash) = 0;
virtual bool mlsag_prepare(const rct::key &H, const rct::key &xx, rct::key &a, rct::key &aG, rct::key &aHP, rct::key &rvII) = 0;
diff --git a/src/device/device_cold.hpp b/src/device/device_cold.hpp
index 22128cec1..8b8cdf6d2 100644
--- a/src/device/device_cold.hpp
+++ b/src/device/device_cold.hpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/device/device_default.cpp b/src/device/device_default.cpp
index cb2f4e266..999fbc22f 100644
--- a/src/device/device_default.cpp
+++ b/src/device/device_default.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
@@ -34,8 +34,10 @@
#include "int-util.h"
#include "cryptonote_basic/account.h"
#include "cryptonote_basic/subaddress_index.h"
+#include "cryptonote_core/cryptonote_tx_utils.h"
#include "ringct/rctOps.h"
+#include "log.hpp"
#define ENCRYPTED_PAYMENT_ID_TAIL 0x8d
#define CHACHA8_KEY_TAIL 0x8c
@@ -278,10 +280,55 @@ namespace hw {
return true;
}
+ bool device_default::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,
+ std::vector<crypto::public_key> &additional_tx_public_keys,
+ std::vector<rct::key> &amount_keys, crypto::public_key &out_eph_public_key) {
- bool device_default::add_output_key_mapping(const crypto::public_key &Aout, const crypto::public_key &Bout, const bool is_subaddress, const size_t real_output_index,
- const rct::key &amount_key, const crypto::public_key &out_eph_public_key) {
- return true;
+ crypto::key_derivation derivation;
+
+ // make additional tx pubkey if necessary
+ cryptonote::keypair additional_txkey;
+ if (need_additional_txkeys)
+ {
+ additional_txkey.sec = additional_tx_keys[output_index];
+ if (dst_entr.is_subaddress)
+ additional_txkey.pub = rct::rct2pk(rct::scalarmultKey(rct::pk2rct(dst_entr.addr.m_spend_public_key), rct::sk2rct(additional_txkey.sec)));
+ else
+ additional_txkey.pub = rct::rct2pk(rct::scalarmultBase(rct::sk2rct(additional_txkey.sec)));
+ }
+
+ bool r;
+ if (change_addr && dst_entr.addr == *change_addr)
+ {
+ // sending change to yourself; derivation = a*R
+ r = generate_key_derivation(txkey_pub, sender_account_keys.m_view_secret_key, derivation);
+ CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to generate_key_derivation(" << txkey_pub << ", " << sender_account_keys.m_view_secret_key << ")");
+ }
+ else
+ {
+ // sending to the recipient; derivation = r*A (or s*C in the subaddress scheme)
+ r = generate_key_derivation(dst_entr.addr.m_view_public_key, dst_entr.is_subaddress && need_additional_txkeys ? additional_txkey.sec : tx_key, derivation);
+ CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to generate_key_derivation(" << dst_entr.addr.m_view_public_key << ", " << (dst_entr.is_subaddress && need_additional_txkeys ? additional_txkey.sec : tx_key) << ")");
+ }
+
+ if (need_additional_txkeys)
+ {
+ additional_tx_public_keys.push_back(additional_txkey.pub);
+ }
+
+ if (tx_version > 1)
+ {
+ crypto::secret_key scalar1;
+ derivation_to_scalar(derivation, output_index, scalar1);
+ amount_keys.push_back(rct::sk2rct(scalar1));
+ }
+ r = derive_public_key(derivation, output_index, dst_entr.addr.m_spend_public_key, out_eph_public_key);
+ CHECK_AND_ASSERT_MES(r, false, "at creation outs: failed to derive_public_key(" << derivation << ", " << output_index << ", "<< dst_entr.addr.m_spend_public_key << ")");
+
+ return r;
}
bool device_default::encrypt_payment_id(crypto::hash8 &payment_id, const crypto::public_key &public_key, const crypto::secret_key &secret_key) {
diff --git a/src/device/device_default.hpp b/src/device/device_default.hpp
index 54d159b11..90d39495b 100644
--- a/src/device/device_default.hpp
+++ b/src/device/device_default.hpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
@@ -114,9 +114,12 @@ namespace hw {
bool ecdhEncode(rct::ecdhTuple & unmasked, const rct::key & sharedSec, bool short_amount) override;
bool ecdhDecode(rct::ecdhTuple & masked, const rct::key & sharedSec, bool short_amount) override;
- bool add_output_key_mapping(const crypto::public_key &Aout, const crypto::public_key &Bout, const bool is_subaddress, const size_t real_output_index,
- const rct::key &amount_key, const crypto::public_key &out_eph_public_key) override;
-
+ 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,
+ std::vector<crypto::public_key> &additional_tx_public_keys,
+ std::vector<rct::key> &amount_keys,
+ crypto::public_key &out_eph_public_key) override;
bool mlsag_prehash(const std::string &blob, size_t inputs_size, size_t outputs_size, const rct::keyV &hashes, const rct::ctkeyV &outPk, rct::key &prehash) override;
bool mlsag_prepare(const rct::key &H, const rct::key &xx, rct::key &a, rct::key &aG, rct::key &aHP, rct::key &rvII) override;
diff --git a/src/device/device_io.hpp b/src/device/device_io.hpp
index 1d5e3564c..fe66736f7 100644
--- a/src/device/device_io.hpp
+++ b/src/device/device_io.hpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/device/device_io_hid.cpp b/src/device/device_io_hid.cpp
index 36c7a241b..f07e0eaae 100644
--- a/src/device/device_io_hid.cpp
+++ b/src/device/device_io_hid.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/device/device_io_hid.hpp b/src/device/device_io_hid.hpp
index c47eefad2..ed22058d6 100644
--- a/src/device/device_io_hid.hpp
+++ b/src/device/device_io_hid.hpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/device/device_ledger.cpp b/src/device/device_ledger.cpp
index 9daf62d37..0f197272c 100644
--- a/src/device/device_ledger.cpp
+++ b/src/device/device_ledger.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
@@ -32,6 +32,7 @@
#include "ringct/rctOps.h"
#include "cryptonote_basic/account.h"
#include "cryptonote_basic/subaddress_index.h"
+#include "cryptonote_core/cryptonote_tx_utils.h"
#include <boost/thread/locks.hpp>
#include <boost/thread/lock_guard.hpp>
@@ -67,10 +68,12 @@ namespace hw {
/* === Keymap ==== */
/* ===================================================================== */
- ABPkeys::ABPkeys(const rct::key& A, const rct::key& B, const bool is_subaddr, const size_t real_output_index, const rct::key& P, const rct::key& AK) {
+ ABPkeys::ABPkeys(const rct::key& A, const rct::key& B, const bool is_subaddr, const bool is_change, const bool need_additional_txkeys, const size_t real_output_index, const rct::key& P, const rct::key& AK) {
Aout = A;
Bout = B;
is_subaddress = is_subaddr;
+ is_change_address = is_change;
+ additional_key = need_additional_txkeys;
index = real_output_index;
Pout = P;
AKout = AK;
@@ -80,6 +83,8 @@ namespace hw {
Aout = keys.Aout;
Bout = keys.Bout;
is_subaddress = keys.is_subaddress;
+ is_change_address = keys.is_change_address;
+ additional_key = keys.additional_key;
index = keys.index;
Pout = keys.Pout;
AKout = keys.AKout;
@@ -137,6 +142,8 @@ namespace hw {
static int device_id = 0;
+ #define PROTOCOL_VERSION 2
+
#define INS_NONE 0x00
#define INS_RESET 0x02
@@ -168,6 +175,7 @@ namespace hw {
#define INS_STEALTH 0x76
#define INS_BLIND 0x78
#define INS_UNBLIND 0x7A
+ #define INS_GEN_TXOUT_KEYS 0x7B
#define INS_VALIDATE 0x7C
#define INS_MLSAG 0x7E
#define INS_CLOSE_TX 0x80
@@ -267,8 +275,7 @@ namespace hw {
int device_ledger::set_command_header(unsigned char ins, unsigned char p1, unsigned char p2) {
reset_buffer();
- int offset = 0;
- this->buffer_send[0] = 0x00;
+ this->buffer_send[0] = PROTOCOL_VERSION;
this->buffer_send[1] = ins;
this->buffer_send[2] = p1;
this->buffer_send[3] = p2;
@@ -508,11 +515,11 @@ namespace hw {
}
const std::size_t output_index_x = output_index;
crypto::public_key derived_pub_x;
- hw::ledger::log_hexbuffer("derive_subaddress_public_key: [[IN]] pub ", pub_x.data, 32);
- hw::ledger::log_hexbuffer("derive_subaddress_public_key: [[IN]] derivation", derivation_x.data, 32);
- hw::ledger::log_message ("derive_subaddress_public_key: [[IN]] index ", std::to_string((int)output_index_x));
+ log_hexbuffer("derive_subaddress_public_key: [[IN]] pub ", pub_x.data, 32);
+ log_hexbuffer("derive_subaddress_public_key: [[IN]] derivation", derivation_x.data, 32);
+ log_message ("derive_subaddress_public_key: [[IN]] index ", std::to_string((int)output_index_x));
this->controle_device->derive_subaddress_public_key(pub_x, derivation_x,output_index_x,derived_pub_x);
- hw::ledger::log_hexbuffer("derive_subaddress_public_key: [[OUT]] derived_pub", derived_pub_x.data, 32);
+ log_hexbuffer("derive_subaddress_public_key: [[OUT]] derived_pub", derived_pub_x.data, 32);
#endif
if ((this->mode == TRANSACTION_PARSE) && has_view_key) {
@@ -558,11 +565,11 @@ namespace hw {
const cryptonote::account_keys keys_x = hw::ledger::decrypt(keys);
const cryptonote::subaddress_index index_x = index;
crypto::public_key D_x;
- hw::ledger::log_hexbuffer("get_subaddress_spend_public_key: [[IN]] keys.m_view_secret_key ", keys_x.m_view_secret_key.data,32);
- hw::ledger::log_hexbuffer("get_subaddress_spend_public_key: [[IN]] keys.m_spend_secret_key", keys_x.m_spend_secret_key.data,32);
- hw::ledger::log_message ("get_subaddress_spend_public_key: [[IN]] index ", std::to_string(index_x.major)+"."+std::to_string(index_x.minor));
+ log_hexbuffer("get_subaddress_spend_public_key: [[IN]] keys.m_view_secret_key ", keys_x.m_view_secret_key.data,32);
+ log_hexbuffer("get_subaddress_spend_public_key: [[IN]] keys.m_spend_secret_key", keys_x.m_spend_secret_key.data,32);
+ log_message ("get_subaddress_spend_public_key: [[IN]] index ", std::to_string(index_x.major)+"."+std::to_string(index_x.minor));
D_x = this->controle_device->get_subaddress_spend_public_key(keys_x, index_x);
- hw::ledger::log_hexbuffer("get_subaddress_spend_public_key: [[OUT]] derivation ", D_x.data, 32);
+ log_hexbuffer("get_subaddress_spend_public_key: [[OUT]] derivation ", D_x.data, 32);
#endif
if (index.is_zero()) {
@@ -609,14 +616,14 @@ namespace hw {
const cryptonote::account_keys keys_x = hw::ledger::decrypt(keys);
const cryptonote::subaddress_index index_x = index;
cryptonote::account_public_address address_x;
- hw::ledger::log_hexbuffer("get_subaddress: [[IN]] keys.m_view_secret_key ", keys_x.m_view_secret_key.data, 32);
- hw::ledger::log_hexbuffer("get_subaddress: [[IN]] keys.m_view_public_key", keys_x.m_account_address.m_view_public_key.data, 32);
- hw::ledger::log_hexbuffer("get_subaddress: [[IN]] keys.m_view_secret_key ", keys_x.m_view_secret_key.data, 32);
- hw::ledger::log_hexbuffer("get_subaddress: [[IN]] keys.m_spend_public_key", keys_x.m_account_address.m_spend_public_key.data, 32);
- hw::ledger::log_message ("get_subaddress: [[IN]] index ", std::to_string(index_x.major)+"."+std::to_string(index_x.minor));
+ log_hexbuffer("get_subaddress: [[IN]] keys.m_view_secret_key ", keys_x.m_view_secret_key.data, 32);
+ log_hexbuffer("get_subaddress: [[IN]] keys.m_view_public_key", keys_x.m_account_address.m_view_public_key.data, 32);
+ log_hexbuffer("get_subaddress: [[IN]] keys.m_view_secret_key ", keys_x.m_view_secret_key.data, 32);
+ log_hexbuffer("get_subaddress: [[IN]] keys.m_spend_public_key", keys_x.m_account_address.m_spend_public_key.data, 32);
+ log_message ("get_subaddress: [[IN]] index ", std::to_string(index_x.major)+"."+std::to_string(index_x.minor));
address_x = this->controle_device->get_subaddress(keys_x, index_x);
- hw::ledger::log_hexbuffer("get_subaddress: [[OUT]] keys.m_view_public_key ", address_x.m_view_public_key.data, 32);
- hw::ledger::log_hexbuffer("get_subaddress: [[OUT]] keys.m_spend_public_key", address_x.m_spend_public_key.data, 32);
+ log_hexbuffer("get_subaddress: [[OUT]] keys.m_view_public_key ", address_x.m_view_public_key.data, 32);
+ log_hexbuffer("get_subaddress: [[OUT]] keys.m_spend_public_key", address_x.m_spend_public_key.data, 32);
#endif
if (index.is_zero()) {
@@ -652,10 +659,10 @@ namespace hw {
const crypto::secret_key sec_x = hw::ledger::decrypt(sec);
const cryptonote::subaddress_index index_x = index;
crypto::secret_key sub_sec_x;
- hw::ledger::log_message ("get_subaddress_secret_key: [[IN]] index ", std::to_string(index.major)+"."+std::to_string(index.minor));
- hw::ledger::log_hexbuffer("get_subaddress_secret_key: [[IN]] sec ", sec_x.data, 32);
+ log_message ("get_subaddress_secret_key: [[IN]] index ", std::to_string(index.major)+"."+std::to_string(index.minor));
+ log_hexbuffer("get_subaddress_secret_key: [[IN]] sec ", sec_x.data, 32);
sub_sec_x = this->controle_device->get_subaddress_secret_key(sec_x, index_x);
- hw::ledger::log_hexbuffer("get_subaddress_secret_key: [[OUT]] sub_sec", sub_sec_x.data, 32);
+ log_hexbuffer("get_subaddress_secret_key: [[OUT]] sub_sec", sub_sec_x.data, 32);
#endif
int offset = set_command_header_noopt(INS_GET_SUBADDRESS_SECRET_KEY);
@@ -687,7 +694,7 @@ namespace hw {
bool device_ledger::verify_keys(const crypto::secret_key &secret_key, const crypto::public_key &public_key) {
AUTO_LOCK_CMD();
- int offset, sw;
+ int offset;
offset = set_command_header_noopt(INS_VERIFY_KEY);
//sec
@@ -717,10 +724,10 @@ namespace hw {
const rct::key P_x = P;
const rct::key a_x = hw::ledger::decrypt(a);
rct::key aP_x;
- hw::ledger::log_hexbuffer("scalarmultKey: [[IN]] P ", (char*)P_x.bytes, 32);
- hw::ledger::log_hexbuffer("scalarmultKey: [[IN]] a ", (char*)a_x.bytes, 32);
+ log_hexbuffer("scalarmultKey: [[IN]] P ", (char*)P_x.bytes, 32);
+ log_hexbuffer("scalarmultKey: [[IN]] a ", (char*)a_x.bytes, 32);
this->controle_device->scalarmultKey(aP_x, P_x, a_x);
- hw::ledger::log_hexbuffer("scalarmultKey: [[OUT]] aP", (char*)aP_x.bytes, 32);
+ log_hexbuffer("scalarmultKey: [[OUT]] aP", (char*)aP_x.bytes, 32);
#endif
int offset = set_command_header_noopt(INS_SECRET_SCAL_MUL_KEY);
@@ -752,9 +759,9 @@ namespace hw {
#ifdef DEBUG_HWDEVICE
const rct::key a_x = hw::ledger::decrypt(a);
rct::key aG_x;
- hw::ledger::log_hexbuffer("scalarmultKey: [[IN]] a ", (char*)a_x.bytes, 32);
+ log_hexbuffer("scalarmultKey: [[IN]] a ", (char*)a_x.bytes, 32);
this->controle_device->scalarmultBase(aG_x, a_x);
- hw::ledger::log_hexbuffer("scalarmultKey: [[OUT]] aG", (char*)aG_x.bytes, 32);
+ log_hexbuffer("scalarmultKey: [[OUT]] aG", (char*)aG_x.bytes, 32);
#endif
int offset = set_command_header_noopt(INS_SECRET_SCAL_MUL_BASE);
@@ -845,10 +852,10 @@ namespace hw {
const crypto::public_key pub_x = pub;
const crypto::secret_key sec_x = hw::ledger::decrypt(sec);
crypto::key_derivation derivation_x;
- hw::ledger::log_hexbuffer("generate_key_derivation: [[IN]] pub ", pub_x.data, 32);
- hw::ledger::log_hexbuffer("generate_key_derivation: [[IN]] sec ", sec_x.data, 32);
+ log_hexbuffer("generate_key_derivation: [[IN]] pub ", pub_x.data, 32);
+ log_hexbuffer("generate_key_derivation: [[IN]] sec ", sec_x.data, 32);
this->controle_device->generate_key_derivation(pub_x, sec_x, derivation_x);
- hw::ledger::log_hexbuffer("generate_key_derivation: [[OUT]] derivation", derivation_x.data, 32);
+ log_hexbuffer("generate_key_derivation: [[OUT]] derivation", derivation_x.data, 32);
#endif
if ((this->mode == TRANSACTION_PARSE) && has_view_key) {
@@ -914,10 +921,10 @@ namespace hw {
const crypto::key_derivation derivation_x = hw::ledger::decrypt(derivation);
const size_t output_index_x = output_index;
crypto::ec_scalar res_x;
- hw::ledger::log_hexbuffer("derivation_to_scalar: [[IN]] derivation ", derivation_x.data, 32);
- hw::ledger::log_message ("derivation_to_scalar: [[IN]] output_index ", std::to_string(output_index_x));
+ log_hexbuffer("derivation_to_scalar: [[IN]] derivation ", derivation_x.data, 32);
+ log_message ("derivation_to_scalar: [[IN]] output_index ", std::to_string(output_index_x));
this->controle_device->derivation_to_scalar(derivation_x, output_index_x, res_x);
- hw::ledger::log_hexbuffer("derivation_to_scalar: [[OUT]] res ", res_x.data, 32);
+ log_hexbuffer("derivation_to_scalar: [[OUT]] res ", res_x.data, 32);
#endif
int offset = set_command_header_noopt(INS_DERIVATION_TO_SCALAR);
@@ -954,11 +961,11 @@ namespace hw {
const std::size_t output_index_x = output_index;
const crypto::secret_key sec_x = hw::ledger::decrypt(sec);
crypto::secret_key derived_sec_x;
- hw::ledger::log_hexbuffer("derive_secret_key: [[IN]] derivation ", derivation_x.data, 32);
- hw::ledger::log_message ("derive_secret_key: [[IN]] index ", std::to_string(output_index_x));
- hw::ledger::log_hexbuffer("derive_secret_key: [[IN]] sec ", sec_x.data, 32);
+ log_hexbuffer("derive_secret_key: [[IN]] derivation ", derivation_x.data, 32);
+ log_message ("derive_secret_key: [[IN]] index ", std::to_string(output_index_x));
+ log_hexbuffer("derive_secret_key: [[IN]] sec ", sec_x.data, 32);
this->controle_device->derive_secret_key(derivation_x, output_index_x, sec_x, derived_sec_x);
- hw::ledger::log_hexbuffer("derive_secret_key: [[OUT]] derived_sec", derived_sec_x.data, 32);
+ log_hexbuffer("derive_secret_key: [[OUT]] derived_sec", derived_sec_x.data, 32);
#endif
int offset = set_command_header_noopt(INS_DERIVE_SECRET_KEY);
@@ -998,11 +1005,11 @@ namespace hw {
const std::size_t output_index_x = output_index;
const crypto::public_key pub_x = pub;
crypto::public_key derived_pub_x;
- hw::ledger::log_hexbuffer("derive_public_key: [[IN]] derivation ", derivation_x.data, 32);
- hw::ledger::log_message ("derive_public_key: [[IN]] output_index", std::to_string(output_index_x));
- hw::ledger::log_hexbuffer("derive_public_key: [[IN]] pub ", pub_x.data, 32);
+ log_hexbuffer("derive_public_key: [[IN]] derivation ", derivation_x.data, 32);
+ log_message ("derive_public_key: [[IN]] output_index", std::to_string(output_index_x));
+ log_hexbuffer("derive_public_key: [[IN]] pub ", pub_x.data, 32);
this->controle_device->derive_public_key(derivation_x, output_index_x, pub_x, derived_pub_x);
- hw::ledger::log_hexbuffer("derive_public_key: [[OUT]] derived_pub ", derived_pub_x.data, 32);
+ log_hexbuffer("derive_public_key: [[OUT]] derived_pub ", derived_pub_x.data, 32);
#endif
int offset = set_command_header_noopt(INS_DERIVE_PUBLIC_KEY);
@@ -1039,11 +1046,11 @@ namespace hw {
#ifdef DEBUG_HWDEVICE
const crypto::secret_key sec_x = hw::ledger::decrypt(sec);
crypto::public_key pub_x;
- hw::ledger::log_hexbuffer("secret_key_to_public_key: [[IN]] sec ", sec_x.data, 32);
+ log_hexbuffer("secret_key_to_public_key: [[IN]] sec ", sec_x.data, 32);
bool rc = this->controle_device->secret_key_to_public_key(sec_x, pub_x);
- hw::ledger::log_hexbuffer("secret_key_to_public_key: [[OUT]] pub", pub_x.data, 32);
+ log_hexbuffer("secret_key_to_public_key: [[OUT]] pub", pub_x.data, 32);
if (!rc){
- hw::ledger::log_message("secret_key_to_public_key", "secret_key rejected");
+ log_message("secret_key_to_public_key", "secret_key rejected");
}
#endif
@@ -1073,10 +1080,10 @@ namespace hw {
const crypto::public_key pub_x = pub;
const crypto::secret_key sec_x = hw::ledger::decrypt(sec);
crypto::key_image image_x;
- hw::ledger::log_hexbuffer("generate_key_image: [[IN]] pub ", pub_x.data, 32);
- hw::ledger::log_hexbuffer("generate_key_image: [[IN]] sec ", sec_x.data, 32);
+ log_hexbuffer("generate_key_image: [[IN]] pub ", pub_x.data, 32);
+ log_hexbuffer("generate_key_image: [[IN]] sec ", sec_x.data, 32);
this->controle_device->generate_key_image(pub_x, sec_x, image_x);
- hw::ledger::log_hexbuffer("generate_key_image: [[OUT]] image ", image_x.data, 32);
+ log_hexbuffer("generate_key_image: [[OUT]] image ", image_x.data, 32);
#endif
int offset = set_command_header_noopt(INS_GEN_KEY_IMAGE);
@@ -1160,10 +1167,139 @@ namespace hw {
return true;
}
- bool device_ledger::add_output_key_mapping(const crypto::public_key &Aout, const crypto::public_key &Bout, const bool is_subaddress, const size_t real_output_index,
- const rct::key &amount_key, const crypto::public_key &out_eph_public_key) {
- AUTO_LOCK_CMD();
- key_map.add(ABPkeys(rct::pk2rct(Aout),rct::pk2rct(Bout), is_subaddress, real_output_index, rct::pk2rct(out_eph_public_key), amount_key));
+
+ bool device_ledger::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,
+ std::vector<crypto::public_key> &additional_tx_public_keys,
+ std::vector<rct::key> &amount_keys,
+ crypto::public_key &out_eph_public_key) {
+ AUTO_LOCK_CMD();
+
+ #ifdef DEBUG_HWDEVICE
+ const size_t &tx_version_x = tx_version;
+ const cryptonote::account_keys sender_account_keys_x = sender_account_keys;
+ memmove((void*)sender_account_keys_x.m_view_secret_key.data, dbg_viewkey.data, 32);
+
+ const crypto::public_key &txkey_pub_x = txkey_pub;
+ const crypto::secret_key &tx_key_x = tx_key;
+ const cryptonote::tx_destination_entry &dst_entr_x = dst_entr;
+ const boost::optional<cryptonote::account_public_address> &change_addr_x = change_addr;
+ const size_t &output_index_x = output_index;
+ const bool &need_additional_txkeys_x = need_additional_txkeys;
+ const std::vector<crypto::secret_key> &additional_tx_keys_x = additional_tx_keys;
+ std::vector<crypto::public_key> additional_tx_public_keys_x;
+ std::vector<rct::key> amount_keys_x;
+ crypto::public_key out_eph_public_key_x;
+ this->controle_device->generate_output_ephemeral_keys(tx_version_x, sender_account_keys_x, txkey_pub_x, tx_key_x, dst_entr_x, change_addr_x, output_index_x, need_additional_txkeys_x, additional_tx_keys_x,
+ additional_tx_public_keys_x, amount_keys_x, out_eph_public_key_x);
+ #endif
+
+ // make additional tx pubkey if necessary
+ cryptonote::keypair additional_txkey;
+ if (need_additional_txkeys) {
+ additional_txkey.sec = additional_tx_keys[output_index];
+ }
+
+ //compute derivation, out_eph_public_key, and amount key in one shot on device, to ensure checkable link
+ const crypto::secret_key *sec;
+ bool is_change;
+
+ if (change_addr && dst_entr.addr == *change_addr)
+ {
+ // sending change to yourself; derivation = a*R
+ is_change = true;
+ sec = &sender_account_keys.m_view_secret_key;
+ }
+ else
+ {
+ is_change = false;
+ if (dst_entr.is_subaddress && need_additional_txkeys) {
+ sec = &additional_txkey.sec;
+ } else {
+ sec = &tx_key;
+ }
+ }
+
+ int offset = set_command_header_noopt(INS_GEN_TXOUT_KEYS);
+ //tx_version
+ this->buffer_send[offset+0] = tx_version>>24;
+ this->buffer_send[offset+1] = tx_version>>16;
+ this->buffer_send[offset+2] = tx_version>>8;
+ this->buffer_send[offset+3] = tx_version>>0;
+ offset += 4;
+ //tx_sec
+ memmove(&this->buffer_send[offset], sec->data, 32);
+ offset += 32;
+ //Aout
+ memmove(&this->buffer_send[offset], dst_entr.addr.m_view_public_key.data, 32);
+ offset += 32;
+ //Bout
+ memmove(&this->buffer_send[offset], dst_entr.addr.m_spend_public_key.data, 32);
+ offset += 32;
+ //output index
+ this->buffer_send[offset+0] = output_index>>24;
+ this->buffer_send[offset+1] = output_index>>16;
+ this->buffer_send[offset+2] = output_index>>8;
+ this->buffer_send[offset+3] = output_index>>0;
+ offset += 4;
+ //is_change,
+ this->buffer_send[offset] = is_change;
+ offset++;
+ //is_subaddress
+ this->buffer_send[offset] = dst_entr.is_subaddress;
+ offset++;
+ //need_additional_key
+ this->buffer_send[offset] = need_additional_txkeys;
+ offset++;
+
+ this->buffer_send[4] = offset-5;
+ this->length_send = offset;
+ this->exchange();
+
+ offset = 0;
+ unsigned int recv_len = this->length_recv;
+ if (need_additional_txkeys)
+ {
+ ASSERT_X(recv_len>=32, "Not enought data from device");
+ memmove(additional_txkey.pub.data, &this->buffer_recv[offset], 32);
+ additional_tx_public_keys.push_back(additional_txkey.pub);
+ offset += 32;
+ recv_len -= 32;
+ }
+ if (tx_version > 1)
+ {
+ ASSERT_X(recv_len>=32, "Not enought data from device");
+ crypto::secret_key scalar1;
+ memmove(scalar1.data, &this->buffer_recv[offset],32);
+ amount_keys.push_back(rct::sk2rct(scalar1));
+ offset += 32;
+ recv_len -= 32;
+ }
+ ASSERT_X(recv_len>=32, "Not enought data from device");
+ memmove(out_eph_public_key.data, &this->buffer_recv[offset], 32);
+ recv_len -= 32;
+
+ // add ABPkeys
+ this->add_output_key_mapping(dst_entr.addr.m_view_public_key, dst_entr.addr.m_spend_public_key, dst_entr.is_subaddress, is_change,
+ need_additional_txkeys, output_index,
+ amount_keys.back(), out_eph_public_key);
+
+ #ifdef DEBUG_HWDEVICE
+ hw::ledger::check32("generate_output_ephemeral_keys", "amount_key", (const char*)amount_keys_x.back().bytes, (const char*)hw::ledger::decrypt(amount_keys.back()).bytes);
+ if (need_additional_txkeys) {
+ hw::ledger::check32("generate_output_ephemeral_keys", "additional_tx_key", additional_tx_keys_x.back().data, additional_tx_keys.back().data);
+ }
+ hw::ledger::check32("generate_output_ephemeral_keys", "out_eph_public_key", out_eph_public_key_x.data, out_eph_public_key.data);
+ #endif
+
+ return true;
+ }
+
+ bool device_ledger::add_output_key_mapping(const crypto::public_key &Aout, const crypto::public_key &Bout, const bool is_subaddress, const bool is_change,
+ const bool need_additional, const size_t real_output_index,
+ const rct::key &amount_key, const crypto::public_key &out_eph_public_key) {
+ key_map.add(ABPkeys(rct::pk2rct(Aout),rct::pk2rct(Bout), is_subaddress, is_change, need_additional, real_output_index, rct::pk2rct(out_eph_public_key), amount_key));
return true;
}
@@ -1176,7 +1312,10 @@ namespace hw {
this->controle_device->ecdhEncode(unmasked_x, AKout_x, short_amount);
#endif
- int offset = set_command_header_noopt(INS_BLIND);
+ int offset = set_command_header(INS_BLIND);
+ //options
+ this->buffer_send[offset] = short_amount?0x02:0x00;
+ offset += 1;
// AKout
memmove(this->buffer_send+offset, AKout.bytes, 32);
offset += 32;
@@ -1198,7 +1337,7 @@ namespace hw {
hw::ledger::check32("ecdhEncode", "amount", (char*)unmasked_x.amount.bytes, (char*)unmasked.amount.bytes);
hw::ledger::check32("ecdhEncode", "mask", (char*)unmasked_x.mask.bytes, (char*)unmasked.mask.bytes);
- hw::ledger::log_hexbuffer("Blind AKV input", (char*)&this->buffer_recv[64], 3*32);
+ log_hexbuffer("Blind AKV input", (char*)&this->buffer_recv[64], 3*32);
#endif
return true;
@@ -1213,8 +1352,10 @@ namespace hw {
this->controle_device->ecdhDecode(masked_x, AKout_x, short_amount);
#endif
- int offset = set_command_header_noopt(INS_UNBLIND);
-
+ int offset = set_command_header(INS_UNBLIND);
+ //options
+ this->buffer_send[offset] = short_amount?0x02:0x00;
+ offset += 1;
// AKout
memmove(this->buffer_send+offset, AKout.bytes, 32);
offset += 32;
@@ -1310,7 +1451,11 @@ namespace hw {
// ====== Aout, Bout, AKout, C, v, k ======
kv_offset = data_offset;
- C_offset = kv_offset+ (32*2)*outputs_size;
+ if (type==rct::RCTTypeBulletproof2) {
+ C_offset = kv_offset+ (8)*outputs_size;
+ } else {
+ C_offset = kv_offset+ (32+32)*outputs_size;
+ }
for ( i = 0; i < outputs_size; i++) {
ABPkeys outKeys;
bool found;
@@ -1323,11 +1468,15 @@ namespace hw {
offset = set_command_header(INS_VALIDATE, 0x02, i+1);
//options
this->buffer_send[offset] = (i==outputs_size-1)? 0x00:0x80 ;
+ this->buffer_send[offset] |= (type==rct::RCTTypeBulletproof2)?0x02:0x00;
offset += 1;
if (found) {
//is_subaddress
this->buffer_send[offset] = outKeys.is_subaddress;
offset++;
+ //is_change_address
+ this->buffer_send[offset] = outKeys.is_change_address;
+ offset++;
//Aout
memmove(this->buffer_send+offset, outKeys.Aout.bytes, 32);
offset+=32;
@@ -1339,27 +1488,38 @@ namespace hw {
offset+=32;
} else {
// dummy: is_subaddress Aout Bout AKout
- offset += 1+32*3;
+ offset += 2+32*3;
}
//C
memmove(this->buffer_send+offset, data+C_offset,32);
offset += 32;
C_offset += 32;
- //k
- memmove(this->buffer_send+offset, data+kv_offset,32);
- offset += 32;
- //v
- kv_offset += 32;
- memmove(this->buffer_send+offset, data+kv_offset,32);
- offset += 32;
- kv_offset += 32;
+ if (type==rct::RCTTypeBulletproof2) {
+ //k
+ memset(this->buffer_send+offset, 0, 32);
+ offset += 32;
+ //v
+ memset(this->buffer_send+offset, 0, 32);
+ memmove(this->buffer_send+offset, data+kv_offset,8);
+ offset += 32;
+ kv_offset += 8;
+ } else {
+ //k
+ memmove(this->buffer_send+offset, data+kv_offset,32);
+ offset += 32;
+ kv_offset += 32;
+ //v
+ memmove(this->buffer_send+offset, data+kv_offset,32);
+ offset += 32;
+ kv_offset += 32;
+ }
this->buffer_send[4] = offset-5;
this->length_send = offset;
// check transaction user input
CHECK_AND_ASSERT_THROW_MES(this->exchange_wait_on_input() == 0, "Transaction denied on device.");
#ifdef DEBUG_HWDEVICE
- hw::ledger::log_hexbuffer("Prehash AKV input", (char*)&this->buffer_recv[64], 3*32);
+ log_hexbuffer("Prehash AKV input", (char*)&this->buffer_recv[64], 3*32);
#endif
}
@@ -1406,7 +1566,6 @@ namespace hw {
bool device_ledger::mlsag_prepare(const rct::key &H, const rct::key &xx,
rct::key &a, rct::key &aG, rct::key &aHP, rct::key &II) {
AUTO_LOCK_CMD();
- unsigned char options;
#ifdef DEBUG_HWDEVICE
const rct::key H_x = H;
@@ -1450,7 +1609,6 @@ namespace hw {
bool device_ledger::mlsag_prepare(rct::key &a, rct::key &aG) {
AUTO_LOCK_CMD();
- unsigned char options;
#ifdef DEBUG_HWDEVICE
rct::key a_x;
@@ -1473,7 +1631,6 @@ namespace hw {
bool device_ledger::mlsag_hash(const rct::keyV &long_message, rct::key &c) {
AUTO_LOCK_CMD();
- unsigned char options;
size_t cnt;
#ifdef DEBUG_HWDEVICE
diff --git a/src/device/device_ledger.hpp b/src/device/device_ledger.hpp
index 584f1e096..252354e1c 100644
--- a/src/device/device_ledger.hpp
+++ b/src/device/device_ledger.hpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
@@ -56,12 +56,14 @@ namespace hw {
rct::key Aout;
rct::key Bout;
bool is_subaddress;
+ bool is_change_address;
+ bool additional_key ;
size_t index;
rct::key Pout;
rct::key AKout;
- ABPkeys(const rct::key& A, const rct::key& B, const bool is_subaddr, size_t index, const rct::key& P,const rct::key& AK);
+ ABPkeys(const rct::key& A, const rct::key& B, const bool is_subaddr, bool is_subaddress, bool is_change_address, size_t index, const rct::key& P,const rct::key& AK);
ABPkeys(const ABPkeys& keys) ;
- ABPkeys() {index=0;is_subaddress=false;}
+ ABPkeys() {index=0;is_subaddress=false;is_subaddress=false;is_change_address=false;}
};
class Keymap {
@@ -105,7 +107,9 @@ namespace hw {
device_mode mode;
// map public destination key to ephemeral destination key
Keymap key_map;
-
+ bool add_output_key_mapping(const crypto::public_key &Aout, const crypto::public_key &Bout, const bool is_subaddress, const bool is_change,
+ const bool need_additional, const size_t real_output_index,
+ const rct::key &amount_key, const crypto::public_key &out_eph_public_key);
// To speed up blockchain parsing the view key maybe handle here.
crypto::secret_key viewkey;
bool has_view_key;
@@ -194,9 +198,12 @@ namespace hw {
bool ecdhEncode(rct::ecdhTuple & unmasked, const rct::key & sharedSec, bool short_format) override;
bool ecdhDecode(rct::ecdhTuple & masked, const rct::key & sharedSec, bool short_format) override;
- bool add_output_key_mapping(const crypto::public_key &Aout, const crypto::public_key &Bout, const bool is_subaddress, const size_t real_output_index,
- const rct::key &amount_key, const crypto::public_key &out_eph_public_key) override;
-
+ 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,
+ std::vector<crypto::public_key> &additional_tx_public_keys,
+ std::vector<rct::key> &amount_keys,
+ crypto::public_key &out_eph_public_key) override;
bool mlsag_prehash(const std::string &blob, size_t inputs_size, size_t outputs_size, const rct::keyV &hashes, const rct::ctkeyV &outPk, rct::key &prehash) override;
bool mlsag_prepare(const rct::key &H, const rct::key &xx, rct::key &a, rct::key &aG, rct::key &aHP, rct::key &rvII) override;
diff --git a/src/device/log.cpp b/src/device/log.cpp
index c9d3b551b..616ad8e90 100644
--- a/src/device/log.cpp
+++ b/src/device/log.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
@@ -66,7 +66,7 @@ namespace hw {
void decrypt(char* buf, size_t len) {
- #ifdef IODUMMYCRYPT_HWDEVICE
+ #if defined(IODUMMYCRYPT_HWDEVICE) || defined(IONOCRYPT_HWDEVICE)
size_t i;
if (len == 32) {
//view key?
@@ -86,11 +86,13 @@ namespace hw {
return;
}
}
+ #if defined(IODUMMYCRYPT_HWDEVICE)
//std decrypt: XOR.55h
for (i = 0; i<len;i++) {
buf[i] ^= 0x55;
}
#endif
+ #endif
}
crypto::key_derivation decrypt(const crypto::key_derivation &derivation) {
diff --git a/src/device/log.hpp b/src/device/log.hpp
index 25a214a6c..fb7ba1fb0 100644
--- a/src/device/log.hpp
+++ b/src/device/log.hpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/device_trezor/CMakeLists.txt b/src/device_trezor/CMakeLists.txt
index 7f979389a..250939da7 100644
--- a/src/device_trezor/CMakeLists.txt
+++ b/src/device_trezor/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2017, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
@@ -67,6 +67,12 @@ set(trezor_private_headers)
if(DEVICE_TREZOR_READY)
message(STATUS "Trezor support enabled")
+ if(USE_DEVICE_TREZOR_DEBUG)
+ list(APPEND trezor_headers trezor/debug_link.hpp trezor/messages/messages-debug.pb.h)
+ list(APPEND trezor_sources trezor/debug_link.cpp trezor/messages/messages-debug.pb.cc)
+ message(STATUS "Trezor debugging enabled")
+ endif()
+
monero_private_headers(device_trezor
${device_private_headers})
diff --git a/src/device_trezor/device_trezor.cpp b/src/device_trezor/device_trezor.cpp
index 8868fb995..ceb6111e0 100644
--- a/src/device_trezor/device_trezor.cpp
+++ b/src/device_trezor/device_trezor.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
@@ -97,7 +97,14 @@ namespace trezor {
auto res = get_view_key();
CHECK_AND_ASSERT_MES(res->watch_key().size() == 32, false, "Trezor returned invalid view key");
+ // Trezor does not make use of spendkey of the device API.
+ // Ledger loads encrypted spendkey, Trezor loads null key (never leaves device).
+ // In the test (debugging mode) we need to leave this field intact as it is already set by
+ // the debugging code and need to remain same for the testing purposes.
+#ifndef WITH_TREZOR_DEBUGGING
spendkey = crypto::null_skey; // not given
+#endif
+
memcpy(viewkey.data, res->watch_key().data(), 32);
return true;
@@ -362,13 +369,9 @@ namespace trezor {
CHECK_AND_ASSERT_THROW_MES(m_features, "Device state not initialized"); // make sure the caller did not reset features
const bool nonce_required = init_msg->tsx_data().has_payment_id() && init_msg->tsx_data().payment_id().size() > 0;
- if (nonce_required){
+ if (nonce_required && init_msg->tsx_data().payment_id().size() == 8){
// Versions 2.0.9 and lower do not support payment ID
- CHECK_AND_ASSERT_THROW_MES(m_features->has_major_version() && m_features->has_minor_version() && m_features->has_patch_version(), "Invalid Trezor firmware version information");
- const uint32_t vma = m_features->major_version();
- const uint32_t vmi = m_features->minor_version();
- const uint32_t vpa = m_features->patch_version();
- if (vma < 2 || (vma == 2 && vmi == 0 && vpa <= 9)) {
+ if (get_version() <= pack_version(2, 0, 9)) {
throw exc::TrezorException("Trezor firmware 2.0.9 and lower does not support transactions with short payment IDs or integrated addresses. Please update.");
}
}
@@ -393,7 +396,7 @@ namespace trezor {
const bool nonce_required = tdata.tsx_data.has_payment_id() && tdata.tsx_data.payment_id().size() > 0;
const bool has_nonce = cryptonote::find_tx_extra_field_by_type(tx_extra_fields, nonce);
- CHECK_AND_ASSERT_THROW_MES(has_nonce == nonce_required, "Transaction nonce presence inconsistent");
+ CHECK_AND_ASSERT_THROW_MES(has_nonce || !nonce_required, "Transaction nonce not present");
if (nonce_required){
const std::string & payment_id = tdata.tsx_data.payment_id();
diff --git a/src/device_trezor/device_trezor.hpp b/src/device_trezor/device_trezor.hpp
index 1f08be887..75f6d5875 100644
--- a/src/device_trezor/device_trezor.hpp
+++ b/src/device_trezor/device_trezor.hpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/device_trezor/device_trezor_base.cpp b/src/device_trezor/device_trezor_base.cpp
index 5071932ee..1892b47d9 100644
--- a/src/device_trezor/device_trezor_base.cpp
+++ b/src/device_trezor/device_trezor_base.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
@@ -44,7 +44,9 @@ namespace trezor {
const uint32_t device_trezor_base::DEFAULT_BIP44_PATH[] = {0x8000002c, 0x80000080};
device_trezor_base::device_trezor_base(): m_callback(nullptr) {
-
+#ifdef WITH_TREZOR_DEBUGGING
+ m_debug = false;
+#endif
}
device_trezor_base::~device_trezor_base() {
@@ -130,6 +132,10 @@ namespace trezor {
}
m_transport->open();
+
+#ifdef WITH_TREZOR_DEBUGGING
+ setup_debug();
+#endif
return true;
} catch(std::exception const& e){
@@ -153,6 +159,13 @@ namespace trezor {
return false;
}
}
+
+#ifdef WITH_TREZOR_DEBUGGING
+ if (m_debug_callback) {
+ m_debug_callback->on_disconnect();
+ m_debug_callback = nullptr;
+ }
+#endif
return true;
}
@@ -355,6 +368,32 @@ namespace trezor {
device_state_reset_unsafe();
}
+#ifdef WITH_TREZOR_DEBUGGING
+#define TREZOR_CALLBACK(method, ...) do { \
+ if (m_debug_callback) m_debug_callback->method(__VA_ARGS__); \
+ if (m_callback) m_callback->method(__VA_ARGS__); \
+}while(0)
+
+ void device_trezor_base::setup_debug(){
+ if (!m_debug){
+ return;
+ }
+
+ if (!m_debug_callback){
+ CHECK_AND_ASSERT_THROW_MES(m_transport, "Transport does not exist");
+ auto debug_transport = m_transport->find_debug();
+ if (debug_transport) {
+ m_debug_callback = std::make_shared<trezor_debug_callback>(debug_transport);
+ } else {
+ MDEBUG("Transport does not have debug link option");
+ }
+ }
+ }
+
+#else
+#define TREZOR_CALLBACK(method, ...) do { if (m_callback) m_callback->method(__VA_ARGS__); } while(0)
+#endif
+
void device_trezor_base::on_button_request(GenericMessage & resp, const messages::common::ButtonRequest * msg)
{
CHECK_AND_ASSERT_THROW_MES(msg, "Empty message");
@@ -363,10 +402,7 @@ namespace trezor {
messages::common::ButtonAck ack;
write_raw(&ack);
- if (m_callback){
- m_callback->on_button_request();
- }
-
+ TREZOR_CALLBACK(on_button_request);
resp = read_raw();
}
@@ -377,9 +413,7 @@ namespace trezor {
epee::wipeable_string pin;
- if (m_callback){
- m_callback->on_pin_request(pin);
- }
+ TREZOR_CALLBACK(on_pin_request, pin);
// TODO: remove PIN from memory
messages::common::PinMatrixAck m;
@@ -393,9 +427,7 @@ namespace trezor {
MDEBUG("on_passhprase_request, on device: " << msg->on_device());
epee::wipeable_string passphrase;
- if (m_callback){
- m_callback->on_passphrase_request(msg->on_device(), passphrase);
- }
+ TREZOR_CALLBACK(on_passphrase_request, msg->on_device(), passphrase);
messages::common::PassphraseAck m;
if (!msg->on_device()){
@@ -421,5 +453,67 @@ namespace trezor {
resp = call_raw(&m);
}
+#ifdef WITH_TREZOR_DEBUGGING
+ void device_trezor_base::wipe_device()
+ {
+ auto msg = std::make_shared<messages::management::WipeDevice>();
+ auto ret = client_exchange<messages::common::Success>(msg);
+ (void)ret;
+ init_device();
+ }
+
+ void device_trezor_base::init_device()
+ {
+ auto msg = std::make_shared<messages::management::Initialize>();
+ m_features = client_exchange<messages::management::Features>(msg);
+ }
+
+ void device_trezor_base::load_device(const std::string & mnemonic, const std::string & pin,
+ bool passphrase_protection, const std::string & label, const std::string & language,
+ bool skip_checksum, bool expand)
+ {
+ if (m_features && m_features->initialized()){
+ throw std::runtime_error("Device is initialized already. Call device.wipe() and try again.");
+ }
+
+ auto msg = std::make_shared<messages::management::LoadDevice>();
+ msg->set_mnemonic(mnemonic);
+ msg->set_pin(pin);
+ msg->set_passphrase_protection(passphrase_protection);
+ msg->set_label(label);
+ msg->set_language(language);
+ msg->set_skip_checksum(skip_checksum);
+ auto ret = client_exchange<messages::common::Success>(msg);
+ (void)ret;
+
+ init_device();
+ }
+
+ trezor_debug_callback::trezor_debug_callback(std::shared_ptr<Transport> & debug_transport){
+ m_debug_link = std::make_shared<DebugLink>();
+ m_debug_link->init(debug_transport);
+ }
+
+ void trezor_debug_callback::on_button_request() {
+ if (m_debug_link) m_debug_link->press_yes();
+ }
+
+ void trezor_debug_callback::on_pin_request(epee::wipeable_string &pin) {
+
+ }
+
+ void trezor_debug_callback::on_passphrase_request(bool on_device, epee::wipeable_string &passphrase) {
+
+ }
+
+ void trezor_debug_callback::on_passphrase_state_request(const std::string &state) {
+
+ }
+
+ void trezor_debug_callback::on_disconnect(){
+ if (m_debug_link) m_debug_link->close();
+ }
+#endif
+
#endif //WITH_DEVICE_TREZOR
}}
diff --git a/src/device_trezor/device_trezor_base.hpp b/src/device_trezor/device_trezor_base.hpp
index 3c35e8aca..8942df797 100644
--- a/src/device_trezor/device_trezor_base.hpp
+++ b/src/device_trezor/device_trezor_base.hpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
@@ -42,6 +42,10 @@
#include "cryptonote_config.h"
#include "trezor.hpp"
+#ifdef WITH_TREZOR_DEBUGGING
+#include "trezor/debug_link.hpp"
+#endif
+
//automatic lock one more level on device ensuring the current thread is allowed to use it
#define AUTO_LOCK_CMD() \
/* lock both mutexes without deadlock*/ \
@@ -57,6 +61,23 @@ namespace trezor {
#ifdef WITH_DEVICE_TREZOR
class device_trezor_base;
+#ifdef WITH_TREZOR_DEBUGGING
+ class trezor_debug_callback {
+ public:
+ trezor_debug_callback()=default;
+ explicit trezor_debug_callback(std::shared_ptr<Transport> & debug_transport);
+
+ void on_button_request();
+ void on_pin_request(epee::wipeable_string &pin);
+ void on_passphrase_request(bool on_device, epee::wipeable_string &passphrase);
+ void on_passphrase_state_request(const std::string &state);
+ void on_disconnect();
+ protected:
+ std::shared_ptr<DebugLink> m_debug_link;
+ };
+
+#endif
+
/**
* TREZOR device template with basic functions
*/
@@ -77,6 +98,13 @@ namespace trezor {
cryptonote::network_type network_type;
+#ifdef WITH_TREZOR_DEBUGGING
+ std::shared_ptr<trezor_debug_callback> m_debug_callback;
+ bool m_debug;
+
+ void setup_debug();
+#endif
+
//
// Internal methods
//
@@ -103,7 +131,7 @@ namespace trezor {
* @throws UnexpectedMessageException if the response message type is different than expected.
* Exception contains message type and the message itself.
*/
- template<class t_message>
+ template<class t_message=google::protobuf::Message>
std::shared_ptr<t_message>
client_exchange(const std::shared_ptr<const google::protobuf::Message> &req,
const boost::optional<messages::MessageType> & resp_type = boost::none,
@@ -229,6 +257,12 @@ namespace trezor {
return m_features;
}
+ uint64_t get_version() const {
+ CHECK_AND_ASSERT_THROW_MES(m_features, "Features not loaded");
+ CHECK_AND_ASSERT_THROW_MES(m_features->has_major_version() && m_features->has_minor_version() && m_features->has_patch_version(), "Invalid Trezor firmware version information");
+ return pack_version(m_features->major_version(), m_features->minor_version(), m_features->patch_version());
+ }
+
void set_derivation_path(const std::string &deriv_path) override;
/* ======================================================================= */
@@ -268,6 +302,23 @@ namespace trezor {
void on_pin_request(GenericMessage & resp, const messages::common::PinMatrixRequest * msg);
void on_passphrase_request(GenericMessage & resp, const messages::common::PassphraseRequest * msg);
void on_passphrase_state_request(GenericMessage & resp, const messages::common::PassphraseStateRequest * msg);
+
+#ifdef WITH_TREZOR_DEBUGGING
+ void set_debug(bool debug){
+ m_debug = debug;
+ }
+
+ void set_debug_callback(std::shared_ptr<trezor_debug_callback> & debug_callback){
+ m_debug_callback = debug_callback;
+ }
+
+ void wipe_device();
+ void init_device();
+ void load_device(const std::string & mnemonic, const std::string & pin="", bool passphrase_protection=false,
+ const std::string & label="test", const std::string & language="english",
+ bool skip_checksum=false, bool expand=false);
+
+#endif
};
#endif
diff --git a/src/device_trezor/trezor.hpp b/src/device_trezor/trezor.hpp
index 97dc0a957..396a27534 100644
--- a/src/device_trezor/trezor.hpp
+++ b/src/device_trezor/trezor.hpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/device_trezor/trezor/debug_link.cpp b/src/device_trezor/trezor/debug_link.cpp
new file mode 100644
index 000000000..c7ee59afe
--- /dev/null
+++ b/src/device_trezor/trezor/debug_link.cpp
@@ -0,0 +1,90 @@
+// Copyright (c) 2017-2018, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+
+#include "debug_link.hpp"
+
+namespace hw{
+namespace trezor{
+
+ DebugLink::DebugLink(){
+
+ }
+
+ DebugLink::~DebugLink(){
+ if (m_transport){
+ close();
+ }
+ }
+
+ void DebugLink::init(std::shared_ptr<Transport> & transport){
+ CHECK_AND_ASSERT_THROW_MES(!m_transport, "Already initialized");
+ m_transport = transport;
+ m_transport->open();
+ }
+
+ void DebugLink::close(){
+ CHECK_AND_ASSERT_THROW_MES(m_transport, "Not initialized");
+ if (m_transport) m_transport->close();
+ }
+
+ std::shared_ptr<messages::debug::DebugLinkState> DebugLink::state(){
+ return call<messages::debug::DebugLinkState>(
+ messages::debug::DebugLinkGetState(),
+ boost::make_optional(messages::MessageType_DebugLinkGetState));
+ }
+
+ void DebugLink::input_word(const std::string & word){
+ messages::debug::DebugLinkDecision decision;
+ decision.set_input(word);
+ call(decision, boost::none, true);
+ }
+
+ void DebugLink::input_button(bool button){
+ messages::debug::DebugLinkDecision decision;
+ decision.set_yes_no(button);
+ call(decision, boost::none, true);
+ }
+
+ void DebugLink::input_swipe(bool swipe){
+ messages::debug::DebugLinkDecision decision;
+ decision.set_up_down(swipe);
+ call(decision, boost::none, true);
+ }
+
+ void DebugLink::stop(){
+ messages::debug::DebugLinkStop msg;
+ call(msg, boost::none, true);
+ }
+
+
+
+
+
+}
+} \ No newline at end of file
diff --git a/src/device_trezor/trezor/debug_link.hpp b/src/device_trezor/trezor/debug_link.hpp
new file mode 100644
index 000000000..adf5f1d8f
--- /dev/null
+++ b/src/device_trezor/trezor/debug_link.hpp
@@ -0,0 +1,93 @@
+// Copyright (c) 2017-2018, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+
+#ifndef MONERO_DEBUG_LINK_H
+#define MONERO_DEBUG_LINK_H
+
+#include "transport.hpp"
+#include "messages/messages-debug.pb.h"
+
+
+namespace hw {
+namespace trezor {
+
+ class DebugLink {
+ public:
+
+ DebugLink();
+ virtual ~DebugLink();
+
+ void init(std::shared_ptr<Transport> & transport);
+ void close();
+
+ std::shared_ptr<messages::debug::DebugLinkState> state();
+ void input_word(const std::string & word);
+ void input_button(bool button);
+ void input_swipe(bool swipe);
+ void press_yes() { input_button(true); }
+ void press_no() { input_button(false); }
+ void stop();
+
+ template<class t_message=messages::debug::DebugLinkState>
+ std::shared_ptr<t_message> call(
+ const google::protobuf::Message & req,
+ const boost::optional<messages::MessageType> &resp_type = boost::none,
+ bool no_wait = false)
+ {
+ BOOST_STATIC_ASSERT(boost::is_base_of<google::protobuf::Message, t_message>::value);
+
+ m_transport->write(req);
+ if (no_wait){
+ return nullptr;
+ }
+
+ // Read the response
+ std::shared_ptr<google::protobuf::Message> msg_resp;
+ hw::trezor::messages::MessageType msg_resp_type;
+ m_transport->read(msg_resp, &msg_resp_type);
+
+ messages::MessageType required_type = resp_type ? resp_type.get() : MessageMapper::get_message_wire_number<t_message>();
+ if (msg_resp_type == required_type) {
+ return message_ptr_retype<t_message>(msg_resp);
+ } else if (msg_resp_type == messages::MessageType_Failure){
+ throw_failure_exception(dynamic_cast<messages::common::Failure*>(msg_resp.get()));
+ } else {
+ throw exc::UnexpectedMessageException(msg_resp_type, msg_resp);
+ }
+ };
+
+ private:
+ std::shared_ptr<Transport> m_transport;
+
+ };
+
+}
+}
+
+#endif //MONERO_DEBUG_LINK_H
diff --git a/src/device_trezor/trezor/exceptions.hpp b/src/device_trezor/trezor/exceptions.hpp
index 197dc43a4..41e8c2875 100644
--- a/src/device_trezor/trezor/exceptions.hpp
+++ b/src/device_trezor/trezor/exceptions.hpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/device_trezor/trezor/messages_map.cpp b/src/device_trezor/trezor/messages_map.cpp
index b0d1aa254..6956b369a 100644
--- a/src/device_trezor/trezor/messages_map.cpp
+++ b/src/device_trezor/trezor/messages_map.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
@@ -33,6 +33,10 @@
#include "messages/messages-management.pb.h"
#include "messages/messages-monero.pb.h"
+#ifdef WITH_TREZOR_DEBUGGING
+#include "messages/messages-debug.pb.h"
+#endif
+
using namespace std;
using namespace hw::trezor;
@@ -45,6 +49,9 @@ namespace trezor
"hw.trezor.messages.",
"hw.trezor.messages.common.",
"hw.trezor.messages.management.",
+#ifdef WITH_TREZOR_DEBUGGING
+ "hw.trezor.messages.debug.",
+#endif
"hw.trezor.messages.monero."
};
@@ -68,6 +75,10 @@ namespace trezor
hw::trezor::messages::management::Cancel::default_instance();
hw::trezor::messages::monero::MoneroGetAddress::default_instance();
+#ifdef WITH_TREZOR_DEBUGGING
+ hw::trezor::messages::debug::DebugLinkDecision::default_instance();
+#endif
+
google::protobuf::Descriptor const * desc = nullptr;
for(const string &text : PACKAGES){
desc = google::protobuf::DescriptorPool::generated_pool()
diff --git a/src/device_trezor/trezor/messages_map.hpp b/src/device_trezor/trezor/messages_map.hpp
index f61338f09..28fe9f4c2 100644
--- a/src/device_trezor/trezor/messages_map.hpp
+++ b/src/device_trezor/trezor/messages_map.hpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
@@ -62,14 +62,14 @@ namespace trezor {
static messages::MessageType get_message_wire_number(const google::protobuf::Message & msg);
static messages::MessageType get_message_wire_number(const std::string & msg_name);
- template<class t_message>
+ template<class t_message=google::protobuf::Message>
static messages::MessageType get_message_wire_number() {
BOOST_STATIC_ASSERT(boost::is_base_of<google::protobuf::Message, t_message>::value);
return get_message_wire_number(t_message::default_instance().GetDescriptor()->name());
}
};
- template<class t_message>
+ template<class t_message=google::protobuf::Message>
std::shared_ptr<t_message> message_ptr_retype(std::shared_ptr<google::protobuf::Message> & in){
BOOST_STATIC_ASSERT(boost::is_base_of<google::protobuf::Message, t_message>::value);
if (!in){
@@ -79,7 +79,7 @@ namespace trezor {
return std::dynamic_pointer_cast<t_message>(in);
}
- template<class t_message>
+ template<class t_message=google::protobuf::Message>
std::shared_ptr<t_message> message_ptr_retype_static(std::shared_ptr<google::protobuf::Message> & in){
BOOST_STATIC_ASSERT(boost::is_base_of<google::protobuf::Message, t_message>::value);
if (!in){
diff --git a/src/device_trezor/trezor/protocol.cpp b/src/device_trezor/trezor/protocol.cpp
index 13506a67f..79f6adac9 100644
--- a/src/device_trezor/trezor/protocol.cpp
+++ b/src/device_trezor/trezor/protocol.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/device_trezor/trezor/protocol.hpp b/src/device_trezor/trezor/protocol.hpp
index ce0361640..23f94f948 100644
--- a/src/device_trezor/trezor/protocol.hpp
+++ b/src/device_trezor/trezor/protocol.hpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/device_trezor/trezor/tools/build_protob.py b/src/device_trezor/trezor/tools/build_protob.py
index 2611f3296..eb32f6b4d 100644
--- a/src/device_trezor/trezor/tools/build_protob.py
+++ b/src/device_trezor/trezor/tools/build_protob.py
@@ -2,6 +2,12 @@
import os
import subprocess
import sys
+import argparse
+
+
+parser = argparse.ArgumentParser()
+parser.add_argument("-d", "--debug-msg", default=False, action="store_const", const=True, help="Build debug messages")
+args = parser.parse_args()
CWD = os.path.dirname(os.path.realpath(__file__))
ROOT_DIR = os.path.abspath(os.path.join(CWD, "..", "..", "..", ".."))
@@ -24,6 +30,10 @@ try:
"messages-management.proto",
"messages-monero.proto",
]
+
+ if args.debug_msg:
+ selected += ["messages-debug.proto"]
+
proto_srcs = [os.path.join(TREZOR_COMMON, "protob", x) for x in selected]
exec_args = [
sys.executable,
diff --git a/src/device_trezor/trezor/transport.cpp b/src/device_trezor/trezor/transport.cpp
index cd66e59e8..991ba3395 100644
--- a/src/device_trezor/trezor/transport.cpp
+++ b/src/device_trezor/trezor/transport.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
@@ -84,6 +84,17 @@ namespace trezor{
return std::string(in.GetString());
}
+ uint64_t pack_version(uint32_t major, uint32_t minor, uint32_t patch)
+ {
+ // packing (major, minor, patch) to 64 B: 16 B | 24 B | 24 B
+ const unsigned bits_1 = 16;
+ const unsigned bits_2 = 24;
+ const uint32_t mask_1 = (1 << bits_1) - 1;
+ const uint32_t mask_2 = (1 << bits_2) - 1;
+ CHECK_AND_ASSERT_THROW_MES(major <= mask_1 && minor <= mask_2 && patch <= mask_2, "Version numbers overflow packing scheme");
+ return patch | (((uint64_t)minor) << bits_2) | (((uint64_t)major) << (bits_1 + bits_2));
+ }
+
//
// Helpers
//
@@ -212,6 +223,40 @@ namespace trezor{
msg = msg_wrap;
}
+ Transport::Transport(): m_open_counter(0) {
+
+ }
+
+ bool Transport::pre_open(){
+ if (m_open_counter > 0){
+ MTRACE("Already opened, count: " << m_open_counter);
+ m_open_counter += 1;
+ return false;
+
+ } else if (m_open_counter < 0){
+ MTRACE("Negative open value: " << m_open_counter);
+
+ }
+
+ // Caller should set m_open_counter to 1 after open
+ m_open_counter = 0;
+ return true;
+ }
+
+ bool Transport::pre_close(){
+ m_open_counter -= 1;
+
+ if (m_open_counter < 0){
+ MDEBUG("Already closed. Counter " << m_open_counter);
+
+ } else if (m_open_counter == 0) {
+ return true;
+
+ }
+
+ return false;
+ }
+
//
// Bridge transport
//
@@ -246,6 +291,10 @@ namespace trezor{
}
void BridgeTransport::open() {
+ if (!pre_open()){
+ return;
+ }
+
if (!m_device_path){
throw exc::CommunicationException("Coud not open, empty device path");
}
@@ -259,9 +308,15 @@ namespace trezor{
}
m_session = boost::make_optional(json_get_string(bridge_res["session"]));
+ m_open_counter = 1;
}
void BridgeTransport::close() {
+ if (!pre_close()){
+ return;
+ }
+
+ MTRACE("Closing Trezor:BridgeTransport");
if (!m_device_path || !m_session){
throw exc::CommunicationException("Device not open");
}
@@ -423,6 +478,10 @@ namespace trezor{
}
void UdpTransport::open() {
+ if (!pre_open()){
+ return;
+ }
+
udp::resolver resolver(m_io_service);
udp::resolver::query query(udp::v4(), m_device_host, std::to_string(m_device_port));
m_endpoint = *resolver.resolve(query);
@@ -434,10 +493,16 @@ namespace trezor{
check_deadline();
m_proto->session_begin(*this);
+ m_open_counter = 1;
}
void UdpTransport::close() {
- if (!m_socket){
+ if (!pre_close()){
+ return;
+ }
+
+ MTRACE("Closing Trezor:UdpTransport");
+ if (!m_socket) {
throw exc::CommunicationException("Socket is already closed");
}
@@ -446,6 +511,19 @@ namespace trezor{
m_socket = nullptr;
}
+ std::shared_ptr<Transport> UdpTransport::find_debug() {
+#ifdef WITH_TREZOR_DEBUGGING
+ std::shared_ptr<UdpTransport> t = std::make_shared<UdpTransport>();
+ t->m_proto = std::make_shared<ProtocolV1>();
+ t->m_device_host = m_device_host;
+ t->m_device_port = m_device_port + 1;
+ return t;
+#else
+ MINFO("Debug link is disabled in production");
+ return nullptr;
+#endif
+ }
+
void UdpTransport::write_chunk(const void * buff, size_t size){
require_socket();
@@ -660,8 +738,7 @@ namespace trezor{
WebUsbTransport::WebUsbTransport(
boost::optional<libusb_device_descriptor*> descriptor,
boost::optional<std::shared_ptr<Protocol>> proto
- ): m_conn_count(0),
- m_usb_session(nullptr), m_usb_device(nullptr), m_usb_device_handle(nullptr),
+ ): m_usb_session(nullptr), m_usb_device(nullptr), m_usb_device_handle(nullptr),
m_bus_id(-1), m_device_addr(-1)
{
if (descriptor){
@@ -672,7 +749,7 @@ namespace trezor{
m_proto = proto ? proto.get() : std::make_shared<ProtocolV1>();
-#ifdef WITH_TREZOR_DEBUG
+#ifdef WITH_TREZOR_DEBUGGING
m_debug_mode = false;
#endif
}
@@ -757,12 +834,10 @@ namespace trezor{
};
void WebUsbTransport::open() {
- const int interface = get_interface();
- if (m_conn_count > 0){
- MTRACE("Already opened, count: " << m_conn_count);
- m_conn_count += 1;
+ if (!pre_open()){
return;
}
+ const int interface = get_interface();
#define TREZOR_DESTROY_SESSION() do { libusb_exit(m_usb_session); m_usb_session = nullptr; } while(0)
@@ -840,45 +915,55 @@ namespace trezor{
throw exc::DeviceAcquireException("Unable to claim libusb device");
}
- m_conn_count = 1;
+ m_open_counter = 1;
m_proto->session_begin(*this);
#undef TREZOR_DESTROY_SESSION
};
void WebUsbTransport::close() {
- m_conn_count -= 1;
-
- if (m_conn_count < 0){
- MERROR("Close counter is negative: " << m_conn_count);
-
- } else if (m_conn_count == 0){
- MTRACE("Closing webusb device");
+ if (!pre_close()){
+ return;
+ }
- m_proto->session_end(*this);
+ MTRACE("Closing Trezor:WebUsbTransport");
+ m_proto->session_end(*this);
- int r = libusb_release_interface(m_usb_device_handle, get_interface());
- if (r != 0){
- MERROR("Could not release libusb interface: " << r);
- }
+ int r = libusb_release_interface(m_usb_device_handle, get_interface());
+ if (r != 0){
+ MERROR("Could not release libusb interface: " << r);
+ }
- m_usb_device = nullptr;
- if (m_usb_device_handle) {
- libusb_close(m_usb_device_handle);
- m_usb_device_handle = nullptr;
- }
+ m_usb_device = nullptr;
+ if (m_usb_device_handle) {
+ libusb_close(m_usb_device_handle);
+ m_usb_device_handle = nullptr;
+ }
- if (m_usb_session) {
- libusb_exit(m_usb_session);
- m_usb_session = nullptr;
- }
+ if (m_usb_session) {
+ libusb_exit(m_usb_session);
+ m_usb_session = nullptr;
}
};
+ std::shared_ptr<Transport> WebUsbTransport::find_debug() {
+#ifdef WITH_TREZOR_DEBUGGING
+ require_device();
+ auto t = std::make_shared<WebUsbTransport>(boost::make_optional(m_usb_device_desc.get()));
+ t->m_bus_id = m_bus_id;
+ t->m_device_addr = m_device_addr;
+ t->m_port_numbers = m_port_numbers;
+ t->m_debug_mode = true;
+ return t;
+#else
+ MINFO("Debug link is disabled in production");
+ return nullptr;
+#endif
+ }
int WebUsbTransport::get_interface() const{
const int INTERFACE_NORMAL = 0;
-#ifdef WITH_TREZOR_DEBUG
+#ifdef WITH_TREZOR_DEBUGGING
const int INTERFACE_DEBUG = 1;
return m_debug_mode ? INTERFACE_DEBUG : INTERFACE_NORMAL;
#else
@@ -888,7 +973,7 @@ namespace trezor{
unsigned char WebUsbTransport::get_endpoint() const{
const unsigned char ENDPOINT_NORMAL = 1;
-#ifdef WITH_TREZOR_DEBUG
+#ifdef WITH_TREZOR_DEBUGGING
const unsigned char ENDPOINT_DEBUG = 2;
return m_debug_mode ? ENDPOINT_DEBUG : ENDPOINT_NORMAL;
#else
@@ -1047,4 +1132,3 @@ namespace trezor{
}
}
-
diff --git a/src/device_trezor/trezor/transport.hpp b/src/device_trezor/trezor/transport.hpp
index 50c31cf73..2945b3184 100644
--- a/src/device_trezor/trezor/transport.hpp
+++ b/src/device_trezor/trezor/transport.hpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
@@ -62,6 +62,8 @@ namespace trezor {
const std::string DEFAULT_BRIDGE = "127.0.0.1:21325";
+ uint64_t pack_version(uint32_t major, uint32_t minor=0, uint32_t patch=0);
+
// Base HTTP comm serialization.
bool t_serialize(const std::string & in, std::string & out);
bool t_serialize(const json_val & in, std::string & out);
@@ -134,7 +136,7 @@ namespace trezor {
class Transport {
public:
- Transport() = default;
+ Transport();
virtual ~Transport() = default;
virtual bool ping() { return false; };
@@ -144,10 +146,16 @@ namespace trezor {
virtual void close(){};
virtual void write(const google::protobuf::Message & req) =0;
virtual void read(std::shared_ptr<google::protobuf::Message> & msg, messages::MessageType * msg_type=nullptr) =0;
+ virtual std::shared_ptr<Transport> find_debug() { return nullptr; };
virtual void write_chunk(const void * buff, size_t size) { };
virtual size_t read_chunk(void * buff, size_t size) { return 0; };
virtual std::ostream& dump(std::ostream& o) const { return o << "Transport<>"; }
+ protected:
+ long m_open_counter;
+
+ virtual bool pre_open();
+ virtual bool pre_close();
};
// Bridge transport
@@ -162,7 +170,7 @@ namespace trezor {
m_session(boost::none),
m_device_info(boost::none)
{
- m_http_client.set_server(m_bridge_host, boost::none, false);
+ m_http_client.set_server(m_bridge_host, boost::none, epee::net_utils::ssl_support_t::e_ssl_support_disabled);
}
virtual ~BridgeTransport() = default;
@@ -212,6 +220,7 @@ namespace trezor {
void open() override;
void close() override;
+ std::shared_ptr<Transport> find_debug() override;
void write(const google::protobuf::Message &req) override;
void read(std::shared_ptr<google::protobuf::Message> & msg, messages::MessageType * msg_type=nullptr) override;
@@ -259,6 +268,7 @@ namespace trezor {
void open() override;
void close() override;
+ std::shared_ptr<Transport> find_debug() override;
void write(const google::protobuf::Message &req) override;
void read(std::shared_ptr<google::protobuf::Message> & msg, messages::MessageType * msg_type=nullptr) override;
@@ -274,7 +284,6 @@ namespace trezor {
int get_interface() const;
unsigned char get_endpoint() const;
- int m_conn_count;
std::shared_ptr<Protocol> m_proto;
libusb_context *m_usb_session;
@@ -285,7 +294,7 @@ namespace trezor {
int m_bus_id;
int m_device_addr;
-#ifdef WITH_TREZOR_DEBUG
+#ifdef WITH_TREZOR_DEBUGGING
bool m_debug_mode;
#endif
};
@@ -309,7 +318,7 @@ namespace trezor {
/**
* Transforms path to the particular transport
*/
- template<class t_transport>
+ template<class t_transport=Transport>
std::shared_ptr<t_transport> transport_typed(const std::string & path){
auto t = transport(path);
if (!t){
@@ -362,7 +371,7 @@ namespace trezor {
* @throws UnexpectedMessageException if the response message type is different than expected.
* Exception contains message type and the message itself.
*/
- template<class t_message>
+ template<class t_message=google::protobuf::Message>
std::shared_ptr<t_message>
exchange_message(Transport & transport, const google::protobuf::Message & req,
boost::optional<messages::MessageType> resp_type = boost::none)
diff --git a/src/device_trezor/trezor/trezor_defs.hpp b/src/device_trezor/trezor/trezor_defs.hpp
index 30e76eadc..f0697cdb5 100644
--- a/src/device_trezor/trezor/trezor_defs.hpp
+++ b/src/device_trezor/trezor/trezor_defs.hpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/gen_multisig/CMakeLists.txt b/src/gen_multisig/CMakeLists.txt
index 18a6a9efe..3a5e29273 100644
--- a/src/gen_multisig/CMakeLists.txt
+++ b/src/gen_multisig/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2017-2018, The Monero Project
+# Copyright (c) 2017-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/src/gen_multisig/gen_multisig.cpp b/src/gen_multisig/gen_multisig.cpp
index 8262e86f7..06019c50e 100644
--- a/src/gen_multisig/gen_multisig.cpp
+++ b/src/gen_multisig/gen_multisig.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/mnemonics/CMakeLists.txt b/src/mnemonics/CMakeLists.txt
index e3836bcca..acb9a4338 100644
--- a/src/mnemonics/CMakeLists.txt
+++ b/src/mnemonics/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/src/mnemonics/chinese_simplified.h b/src/mnemonics/chinese_simplified.h
index 0566b1079..ff035dde0 100644
--- a/src/mnemonics/chinese_simplified.h
+++ b/src/mnemonics/chinese_simplified.h
@@ -21,7 +21,7 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-// Code surrounding the word list is Copyright (c) 2014-2018, The Monero Project
+// Code surrounding the word list is Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/mnemonics/dutch.h b/src/mnemonics/dutch.h
index 801caf986..14ba56a7e 100644
--- a/src/mnemonics/dutch.h
+++ b/src/mnemonics/dutch.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/mnemonics/electrum-words.cpp b/src/mnemonics/electrum-words.cpp
index 68d5b84d3..48c9ab1ba 100644
--- a/src/mnemonics/electrum-words.cpp
+++ b/src/mnemonics/electrum-words.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/mnemonics/electrum-words.h b/src/mnemonics/electrum-words.h
index 60d2c5f15..9aa727e45 100644
--- a/src/mnemonics/electrum-words.h
+++ b/src/mnemonics/electrum-words.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/mnemonics/english.h b/src/mnemonics/english.h
index d5c5594ef..677b70052 100644
--- a/src/mnemonics/english.h
+++ b/src/mnemonics/english.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/mnemonics/english_old.h b/src/mnemonics/english_old.h
index e35b907df..179fc45ec 100644
--- a/src/mnemonics/english_old.h
+++ b/src/mnemonics/english_old.h
@@ -1,6 +1,6 @@
// Word list originally created as part of the Electrum project, Copyright (C) 2014 Thomas Voegtlin
//
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/mnemonics/esperanto.h b/src/mnemonics/esperanto.h
index b0be235ed..ef63a2235 100644
--- a/src/mnemonics/esperanto.h
+++ b/src/mnemonics/esperanto.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/mnemonics/french.h b/src/mnemonics/french.h
index 48ec46f78..85925aa53 100644
--- a/src/mnemonics/french.h
+++ b/src/mnemonics/french.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/mnemonics/german.h b/src/mnemonics/german.h
index 883a173a3..40116970c 100644
--- a/src/mnemonics/german.h
+++ b/src/mnemonics/german.h
@@ -1,6 +1,6 @@
// Word list created by Monero contributor Shrikez
//
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/mnemonics/italian.h b/src/mnemonics/italian.h
index 57cdfa25e..204fdcb78 100644
--- a/src/mnemonics/italian.h
+++ b/src/mnemonics/italian.h
@@ -1,6 +1,6 @@
// Word list created by Monero contributor Shrikez
//
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/mnemonics/japanese.h b/src/mnemonics/japanese.h
index 5baabedf2..6213c4976 100644
--- a/src/mnemonics/japanese.h
+++ b/src/mnemonics/japanese.h
@@ -21,7 +21,7 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-// Code surrounding the word list is Copyright (c) 2014-2018, The Monero Project
+// Code surrounding the word list is Copyright (c) 2014-2019, The Monero Project
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
diff --git a/src/mnemonics/language_base.h b/src/mnemonics/language_base.h
index a6f969604..653314b04 100644
--- a/src/mnemonics/language_base.h
+++ b/src/mnemonics/language_base.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/mnemonics/lojban.h b/src/mnemonics/lojban.h
index 5162a8ec9..b6baf46c4 100644
--- a/src/mnemonics/lojban.h
+++ b/src/mnemonics/lojban.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/mnemonics/portuguese.h b/src/mnemonics/portuguese.h
index af04f89c2..dbc51fb2a 100644
--- a/src/mnemonics/portuguese.h
+++ b/src/mnemonics/portuguese.h
@@ -21,7 +21,7 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-// Code surrounding the word list is Copyright (c) 2014-2018, The Monero Project
+// Code surrounding the word list is Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/mnemonics/russian.h b/src/mnemonics/russian.h
index f3e70ede6..d36942a9b 100644
--- a/src/mnemonics/russian.h
+++ b/src/mnemonics/russian.h
@@ -1,6 +1,6 @@
// Word list created by Monero contributor sammy007
//
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/mnemonics/singleton.h b/src/mnemonics/singleton.h
index d317a2d8d..ffe3fe4de 100644
--- a/src/mnemonics/singleton.h
+++ b/src/mnemonics/singleton.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/mnemonics/spanish.h b/src/mnemonics/spanish.h
index 4d7a896a6..a05485775 100644
--- a/src/mnemonics/spanish.h
+++ b/src/mnemonics/spanish.h
@@ -21,7 +21,7 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-// Code surrounding the word list is Copyright (c) 2014-2018, The Monero Project
+// Code surrounding the word list is Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/multisig/CMakeLists.txt b/src/multisig/CMakeLists.txt
index a770c6dc5..4631b75ef 100644
--- a/src/multisig/CMakeLists.txt
+++ b/src/multisig/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2017-2018, The Monero Project
+# Copyright (c) 2017-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/src/multisig/multisig.cpp b/src/multisig/multisig.cpp
index 33d0a312f..14df4d554 100644
--- a/src/multisig/multisig.cpp
+++ b/src/multisig/multisig.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/multisig/multisig.h b/src/multisig/multisig.h
index 93a756812..bc6edbb05 100644
--- a/src/multisig/multisig.h
+++ b/src/multisig/multisig.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/net/CMakeLists.txt b/src/net/CMakeLists.txt
index a81372125..8a3ee9e6f 100644
--- a/src/net/CMakeLists.txt
+++ b/src/net/CMakeLists.txt
@@ -26,9 +26,9 @@
# 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.
-set(net_sources error.cpp parse.cpp socks.cpp tor_address.cpp)
-set(net_headers error.h parse.h socks.h tor_address.h)
+set(net_sources error.cpp parse.cpp socks.cpp tor_address.cpp i2p_address.cpp)
+set(net_headers error.h parse.h socks.h tor_address.h i2p_address.h)
monero_add_library(net ${net_sources} ${net_headers})
-target_link_libraries(net epee ${Boost_ASIO_LIBRARY})
+target_link_libraries(net common epee ${Boost_ASIO_LIBRARY})
diff --git a/src/net/fwd.h b/src/net/fwd.h
index ee7c539b0..7cae88251 100644
--- a/src/net/fwd.h
+++ b/src/net/fwd.h
@@ -34,6 +34,7 @@ namespace net
{
enum class error : int;
class tor_address;
+ class i2p_address;
namespace socks
{
diff --git a/src/net/i2p_address.cpp b/src/net/i2p_address.cpp
new file mode 100644
index 000000000..cba829d3f
--- /dev/null
+++ b/src/net/i2p_address.cpp
@@ -0,0 +1,200 @@
+// Copyright (c) 2019, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "i2p_address.h"
+
+#include <algorithm>
+#include <boost/spirit/include/karma_generate.hpp>
+#include <boost/spirit/include/karma_uint.hpp>
+#include <cassert>
+#include <cstring>
+#include <limits>
+
+#include "net/error.h"
+#include "serialization/keyvalue_serialization.h"
+#include "storages/portable_storage.h"
+#include "string_tools.h"
+
+namespace net
+{
+ namespace
+ {
+ // !TODO only b32 addresses right now
+ constexpr const char tld[] = u8".b32.i2p";
+ constexpr const char unknown_host[] = "<unknown i2p host>";
+
+ constexpr const unsigned b32_length = 52;
+
+ constexpr const char base32_alphabet[] =
+ u8"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz234567";
+
+ expect<void> host_check(boost::string_ref host) noexcept
+ {
+ if (!host.ends_with(tld))
+ return {net::error::expected_tld};
+
+ host.remove_suffix(sizeof(tld) - 1);
+
+ if (host.size() != b32_length)
+ return {net::error::invalid_i2p_address};
+ if (host.find_first_not_of(base32_alphabet) != boost::string_ref::npos)
+ return {net::error::invalid_i2p_address};
+
+ return success();
+ }
+
+ struct i2p_serialized
+ {
+ std::string host;
+ std::uint16_t port;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(host)
+ KV_SERIALIZE(port)
+ END_KV_SERIALIZE_MAP()
+ };
+ }
+
+ i2p_address::i2p_address(const boost::string_ref host, const std::uint16_t port) noexcept
+ : port_(port)
+ {
+ // this is a private constructor, throw if moved to public
+ assert(host.size() < sizeof(host_));
+
+ const std::size_t length = std::min(sizeof(host_) - 1, host.size());
+ std::memcpy(host_, host.data(), length);
+ std::memset(host_ + length, 0, sizeof(host_) - length);
+ }
+
+ const char* i2p_address::unknown_str() noexcept
+ {
+ return unknown_host;
+ }
+
+ i2p_address::i2p_address() noexcept
+ : port_(0)
+ {
+ static_assert(sizeof(unknown_host) <= sizeof(host_), "bad buffer size");
+ std::memcpy(host_, unknown_host, sizeof(unknown_host));
+ std::memset(host_ + sizeof(unknown_host), 0, sizeof(host_) - sizeof(unknown_host));
+ }
+
+ expect<i2p_address> i2p_address::make(const boost::string_ref address, const std::uint16_t default_port)
+ {
+ boost::string_ref host = address.substr(0, address.rfind(':'));
+ const boost::string_ref port =
+ address.substr(host.size() + (host.size() == address.size() ? 0 : 1));
+
+ MONERO_CHECK(host_check(host));
+
+ std::uint16_t porti = default_port;
+ if (!port.empty() && !epee::string_tools::get_xtype_from_string(porti, std::string{port}))
+ return {net::error::invalid_port};
+
+ static_assert(b32_length + sizeof(tld) == sizeof(i2p_address::host_), "bad internal host size");
+ return i2p_address{host, porti};
+ }
+
+ bool i2p_address::_load(epee::serialization::portable_storage& src, epee::serialization::section* hparent)
+ {
+ i2p_serialized in{};
+ if (in._load(src, hparent) && in.host.size() < sizeof(host_) && (in.host == unknown_host || !host_check(in.host).has_error()))
+ {
+ std::memcpy(host_, in.host.data(), in.host.size());
+ std::memset(host_ + in.host.size(), 0, sizeof(host_) - in.host.size());
+ port_ = in.port;
+ return true;
+ }
+ static_assert(sizeof(unknown_host) <= sizeof(host_), "bad buffer size");
+ std::memcpy(host_, unknown_host, sizeof(unknown_host)); // include null terminator
+ port_ = 0;
+ return false;
+ }
+
+ bool i2p_address::store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const
+ {
+ const i2p_serialized out{std::string{host_}, port_};
+ return out.store(dest, hparent);
+ }
+
+ i2p_address::i2p_address(const i2p_address& rhs) noexcept
+ : port_(rhs.port_)
+ {
+ std::memcpy(host_, rhs.host_, sizeof(host_));
+ }
+
+ i2p_address& i2p_address::operator=(const i2p_address& rhs) noexcept
+ {
+ if (this != std::addressof(rhs))
+ {
+ port_ = rhs.port_;
+ std::memcpy(host_, rhs.host_, sizeof(host_));
+ }
+ return *this;
+ }
+
+ bool i2p_address::is_unknown() const noexcept
+ {
+ static_assert(1 <= sizeof(host_), "host size too small");
+ return host_[0] == '<'; // character is not allowed otherwise
+ }
+
+ bool i2p_address::equal(const i2p_address& rhs) const noexcept
+ {
+ return port_ == rhs.port_ && is_same_host(rhs);
+ }
+
+ bool i2p_address::less(const i2p_address& rhs) const noexcept
+ {
+ return std::strcmp(host_str(), rhs.host_str()) < 0 || port() < rhs.port();
+ }
+
+ bool i2p_address::is_same_host(const i2p_address& rhs) const noexcept
+ {
+ return std::strcmp(host_str(), rhs.host_str()) == 0;
+ }
+
+ std::string i2p_address::str() const
+ {
+ const std::size_t host_length = std::strlen(host_str());
+ const std::size_t port_length =
+ port_ == 0 ? 0 : std::numeric_limits<std::uint16_t>::digits10 + 2;
+
+ std::string out{};
+ out.reserve(host_length + port_length);
+ out.assign(host_str(), host_length);
+
+ if (port_ != 0)
+ {
+ out.push_back(':');
+ namespace karma = boost::spirit::karma;
+ karma::generate(std::back_inserter(out), karma::ushort_, port());
+ }
+ return out;
+ }
+}
diff --git a/src/net/i2p_address.h b/src/net/i2p_address.h
new file mode 100644
index 000000000..28a1118ba
--- /dev/null
+++ b/src/net/i2p_address.h
@@ -0,0 +1,140 @@
+// Copyright (c) 2019, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#pragma once
+
+#include <boost/utility/string_ref.hpp>
+#include <cstdint>
+#include <string>
+
+#include "common/expect.h"
+#include "net/enums.h"
+#include "net/error.h"
+
+namespace epee
+{
+namespace serialization
+{
+ class portable_storage;
+ struct section;
+}
+}
+
+namespace net
+{
+ //! b32 i2p address; internal format not condensed/decoded.
+ class i2p_address
+ {
+ std::uint16_t port_;
+ char host_[61]; // null-terminated
+
+ //! Keep in private, `host.size()` has no runtime check
+ i2p_address(boost::string_ref host, std::uint16_t port) noexcept;
+
+ public:
+ //! \return Size of internal buffer for host.
+ static constexpr std::size_t buffer_size() noexcept { return sizeof(host_); }
+
+ //! \return `<unknown tor host>`.
+ static const char* unknown_str() noexcept;
+
+ //! An object with `port() == 0` and `host_str() == unknown_str()`.
+ i2p_address() noexcept;
+
+ //! \return A default constructed `i2p_address` object.
+ static i2p_address unknown() noexcept { return i2p_address{}; }
+
+ /*!
+ Parse `address` in b32 i2p format (i.e. x.b32.i2p:80)
+ with `default_port` being used if port is not specified in
+ `address`.
+ */
+ static expect<i2p_address> make(boost::string_ref address, std::uint16_t default_port = 0);
+
+ //! Load from epee p2p format, and \return false if not valid tor address
+ bool _load(epee::serialization::portable_storage& src, epee::serialization::section* hparent);
+
+ //! Store in epee p2p format
+ bool store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const;
+
+ // Moves and copies are currently identical
+
+ i2p_address(const i2p_address& rhs) noexcept;
+ ~i2p_address() = default;
+ i2p_address& operator=(const i2p_address& rhs) noexcept;
+
+ //! \return True if default constructed or via `unknown()`.
+ bool is_unknown() const noexcept;
+
+ bool equal(const i2p_address& rhs) const noexcept;
+ bool less(const i2p_address& rhs) const noexcept;
+
+ //! \return True if i2p addresses are identical.
+ bool is_same_host(const i2p_address& rhs) const noexcept;
+
+ //! \return `x.b32.i2p` or `x.b32.i2p:z` if `port() != 0`.
+ std::string str() const;
+
+ //! \return Null-terminated `x.b32.i2p` value or `unknown_str()`.
+ const char* host_str() const noexcept { return host_; }
+
+ //! \return Port value or `0` if unspecified.
+ std::uint16_t port() const noexcept { return port_; }
+
+ static constexpr bool is_loopback() noexcept { return false; }
+ static constexpr bool is_local() noexcept { return false; }
+
+ static constexpr epee::net_utils::address_type get_type_id() noexcept
+ {
+ return epee::net_utils::address_type::i2p;
+ }
+
+ static constexpr epee::net_utils::zone get_zone() noexcept
+ {
+ return epee::net_utils::zone::i2p;
+ }
+
+ //! \return `!is_unknown()`.
+ bool is_blockable() const noexcept { return !is_unknown(); }
+ };
+
+ inline bool operator==(const i2p_address& lhs, const i2p_address& rhs) noexcept
+ {
+ return lhs.equal(rhs);
+ }
+
+ inline bool operator!=(const i2p_address& lhs, const i2p_address& rhs) noexcept
+ {
+ return !lhs.equal(rhs);
+ }
+
+ inline bool operator<(const i2p_address& lhs, const i2p_address& rhs) noexcept
+ {
+ return lhs.less(rhs);
+ }
+} // net
diff --git a/src/net/parse.cpp b/src/net/parse.cpp
index ebf91eeff..eaaadb67e 100644
--- a/src/net/parse.cpp
+++ b/src/net/parse.cpp
@@ -29,6 +29,7 @@
#include "parse.h"
#include "net/tor_address.h"
+#include "net/i2p_address.h"
#include "string_tools.h"
namespace net
@@ -43,7 +44,7 @@ namespace net
if (host.ends_with(".onion"))
return tor_address::make(address, default_port);
if (host.ends_with(".i2p"))
- return make_error_code(net::error::invalid_i2p_address); // not yet implemented (prevent public DNS lookup)
+ return i2p_address::make(address, default_port);
std::uint16_t port = default_port;
if (host.size() < address.size())
diff --git a/src/net/parse.h b/src/net/parse.h
index 9195ddc2b..5804c4128 100644
--- a/src/net/parse.h
+++ b/src/net/parse.h
@@ -37,11 +37,11 @@
namespace net
{
/*!
- Identifies onion and IPv4 addresses and returns them as a generic
+ Identifies onion, i2p and IPv4 addresses and returns them as a generic
`network_address`. If the type is unsupported, it might be a hostname,
and `error() == net::error::kUnsupportedAddress` is returned.
- \param address An onion address, ipv4 address or hostname. Hostname
+ \param address An onion address, i2p address, ipv4 address or hostname. Hostname
will return an error.
\param default_port If `address` does not specify a port, this value
will be used.
diff --git a/src/net/socks.cpp b/src/net/socks.cpp
index f31efc8c1..53154369b 100644
--- a/src/net/socks.cpp
+++ b/src/net/socks.cpp
@@ -40,6 +40,7 @@
#include "net/net_utils_base.h"
#include "net/tor_address.h"
+#include "net/i2p_address.h"
namespace net
{
@@ -273,6 +274,13 @@ namespace socks
return false;
}
+ bool client::set_connect_command(const net::i2p_address& address)
+ {
+ if (!address.is_unknown())
+ return set_connect_command(address.host_str(), address.port());
+ return false;
+ }
+
bool client::set_resolve_command(boost::string_ref domain)
{
if (socks_version() != version::v4a_tor)
diff --git a/src/net/socks.h b/src/net/socks.h
index d29a51ccb..825937792 100644
--- a/src/net/socks.h
+++ b/src/net/socks.h
@@ -155,6 +155,9 @@ namespace socks
//! Try to set `address` as remote Tor hidden service connection request.
bool set_connect_command(const net::tor_address& address);
+ //! Try to set `address` as remote i2p hidden service connection request.
+ bool set_connect_command(const net::i2p_address& address);
+
//! Try to set `domain` as remote DNS A record lookup request.
bool set_resolve_command(boost::string_ref domain);
diff --git a/src/p2p/CMakeLists.txt b/src/p2p/CMakeLists.txt
index 9a1730b8a..3aecc3cf9 100644
--- a/src/p2p/CMakeLists.txt
+++ b/src/p2p/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/src/p2p/net_node.cpp b/src/p2p/net_node.cpp
index 8639fdb3b..e0f1de14a 100644
--- a/src/p2p/net_node.cpp
+++ b/src/p2p/net_node.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -46,13 +46,14 @@
#include "net/socks.h"
#include "net/parse.h"
#include "net/tor_address.h"
+#include "net/i2p_address.h"
#include "p2p/p2p_protocol_defs.h"
#include "string_tools.h"
namespace
{
constexpr const boost::chrono::milliseconds future_poll_interval{500};
- constexpr const std::chrono::seconds tor_connect_timeout{P2P_DEFAULT_TOR_CONNECT_TIMEOUT};
+ constexpr const std::chrono::seconds socks_connect_timeout{P2P_DEFAULT_SOCKS_CONNECT_TIMEOUT};
std::int64_t get_max_connections(const boost::iterator_range<boost::string_ref::const_iterator> value) noexcept
{
@@ -90,6 +91,9 @@ namespace
case net::tor_address::get_type_id():
set = client->set_connect_command(remote.as<net::tor_address>());
break;
+ case net::i2p_address::get_type_id():
+ set = client->set_connect_command(remote.as<net::i2p_address>());
+ break;
default:
MERROR("Unsupported network address in socks_connect");
return false;
@@ -177,6 +181,9 @@ namespace nodetool
case epee::net_utils::zone::tor:
proxies.back().zone = epee::net_utils::zone::tor;
break;
+ case epee::net_utils::zone::i2p:
+ proxies.back().zone = epee::net_utils::zone::i2p;
+ break;
default:
MERROR("Invalid network for --" << arg_proxy.name);
return boost::none;
@@ -235,6 +242,10 @@ namespace nodetool
inbounds.back().our_address = std::move(*our_address);
inbounds.back().default_remote = net::tor_address::unknown();
break;
+ case net::i2p_address::get_type_id():
+ inbounds.back().our_address = std::move(*our_address);
+ inbounds.back().default_remote = net::i2p_address::unknown();
+ break;
default:
MERROR("Invalid inbound address (" << address << ") for --" << arg_anonymous_inbound.name << ": " << (our_address ? "invalid type" : our_address.error().message()));
return boost::none;
@@ -308,7 +319,7 @@ namespace nodetool
const auto start = std::chrono::steady_clock::now();
while (socks_result.wait_for(future_poll_interval) == boost::future_status::timeout)
{
- if (tor_connect_timeout < std::chrono::steady_clock::now() - start)
+ if (socks_connect_timeout < std::chrono::steady_clock::now() - start)
{
MERROR("Timeout on socks connect (" << proxy << " to " << remote.str() << ")");
return boost::none;
diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h
index 112f30fb6..0e7016b27 100644
--- a/src/p2p/net_node.h
+++ b/src/p2p/net_node.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -129,11 +129,11 @@ namespace nodetool
typedef epee::net_utils::boosted_tcp_server<epee::levin::async_protocol_handler<p2p_connection_context>> net_server;
struct network_zone;
- using connect_func = boost::optional<p2p_connection_context>(network_zone&, epee::net_utils::network_address const&);
+ using connect_func = boost::optional<p2p_connection_context>(network_zone&, epee::net_utils::network_address const&, epee::net_utils::ssl_support_t);
- struct config
+ struct config_t
{
- config()
+ config_t()
: m_net_config(),
m_peer_id(crypto::rand<uint64_t>()),
m_support_flags(0)
@@ -143,6 +143,7 @@ namespace nodetool
uint64_t m_peer_id;
uint32_t m_support_flags;
};
+ typedef epee::misc_utils::struct_init<config_t> config;
struct network_zone
{
@@ -437,8 +438,8 @@ namespace nodetool
//keep connections to initiate some interactions
- static boost::optional<p2p_connection_context> public_connect(network_zone&, epee::net_utils::network_address const&);
- static boost::optional<p2p_connection_context> socks_connect(network_zone&, epee::net_utils::network_address const&);
+ static boost::optional<p2p_connection_context> public_connect(network_zone&, epee::net_utils::network_address const&, epee::net_utils::ssl_support_t);
+ static boost::optional<p2p_connection_context> socks_connect(network_zone&, epee::net_utils::network_address const&, epee::net_utils::ssl_support_t);
/* A `std::map` provides constant iterators and key/value pointers even with
@@ -463,6 +464,8 @@ namespace nodetool
boost::uuids::uuid m_network_id;
cryptonote::network_type m_nettype;
+
+ epee::net_utils::ssl_support_t m_ssl_support;
};
const int64_t default_limit_up = P2P_DEFAULT_LIMIT_RATE_UP; // kB/s
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index 471fdda0d..f32b9e990 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -650,6 +650,7 @@ namespace nodetool
return res;
//try to bind
+ m_ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_disabled;
for (auto& zone : m_network_zones)
{
zone.second.m_net_server.get_config_object().set_handler(this);
@@ -659,7 +660,7 @@ namespace nodetool
{
zone.second.m_net_server.set_connection_filter(this);
MINFO("Binding on " << zone.second.m_bind_ip << ":" << zone.second.m_port);
- res = zone.second.m_net_server.init_server(zone.second.m_port, zone.second.m_bind_ip);
+ res = zone.second.m_net_server.init_server(zone.second.m_port, zone.second.m_bind_ip, epee::net_utils::ssl_support_t::e_ssl_support_disabled);
CHECK_AND_ASSERT_MES(res, false, "Failed to bind server");
}
}
@@ -1057,7 +1058,7 @@ namespace nodetool
<< (last_seen_stamp ? epee::misc_utils::get_time_interval_string(time(NULL) - last_seen_stamp):"never")
<< ")...");
- auto con = zone.m_connect(zone, na);
+ auto con = zone.m_connect(zone, na, m_ssl_support);
if(!con)
{
bool is_priority = is_priority_node(na);
@@ -1119,7 +1120,7 @@ namespace nodetool
<< (last_seen_stamp ? epee::misc_utils::get_time_interval_string(time(NULL) - last_seen_stamp):"never")
<< ")...");
- auto con = zone.m_connect(zone, na);
+ auto con = zone.m_connect(zone, na, m_ssl_support);
if (!con) {
bool is_priority = is_priority_node(na);
@@ -1397,7 +1398,15 @@ namespace nodetool
}
if(zone.second.m_net_server.is_stop_signal_sent())
return false;
- conn_count = get_outgoing_connections_count(zone.second);
+ size_t new_conn_count = get_outgoing_connections_count(zone.second);
+ if (new_conn_count <= conn_count)
+ {
+ // we did not make any connection, sleep a bit to avoid a busy loop in case we don't have
+ // any peers to try, then break so we will try seeds to get more peers
+ boost::this_thread::sleep_for(boost::chrono::seconds(1));
+ break;
+ }
+ conn_count = new_conn_count;
}
}
@@ -2456,13 +2465,13 @@ namespace nodetool
template<typename t_payload_net_handler>
boost::optional<p2p_connection_context_t<typename t_payload_net_handler::connection_context>>
- node_server<t_payload_net_handler>::socks_connect(network_zone& zone, const epee::net_utils::network_address& remote)
+ node_server<t_payload_net_handler>::socks_connect(network_zone& zone, const epee::net_utils::network_address& remote, epee::net_utils::ssl_support_t ssl_support)
{
auto result = socks_connect_internal(zone.m_net_server.get_stop_signal(), zone.m_net_server.get_io_service(), zone.m_proxy_address, remote);
if (result) // if no error
{
p2p_connection_context context{};
- if (zone.m_net_server.add_connection(context, std::move(*result), remote))
+ if (zone.m_net_server.add_connection(context, std::move(*result), remote, ssl_support))
return {std::move(context)};
}
return boost::none;
@@ -2470,7 +2479,7 @@ namespace nodetool
template<typename t_payload_net_handler>
boost::optional<p2p_connection_context_t<typename t_payload_net_handler::connection_context>>
- node_server<t_payload_net_handler>::public_connect(network_zone& zone, epee::net_utils::network_address const& na)
+ node_server<t_payload_net_handler>::public_connect(network_zone& zone, epee::net_utils::network_address const& na, epee::net_utils::ssl_support_t ssl_support)
{
CHECK_AND_ASSERT_MES(na.get_type_id() == epee::net_utils::ipv4_network_address::get_type_id(), boost::none,
"Only IPv4 addresses are supported here");
@@ -2480,7 +2489,7 @@ namespace nodetool
const bool res = zone.m_net_server.connect(epee::string_tools::get_ip_string_from_int32(ipv4.ip()),
epee::string_tools::num_to_string_fast(ipv4.port()),
zone.m_config.m_net_config.connection_timeout,
- con);
+ con, "0.0.0.0", ssl_support);
if (res)
return {std::move(con)};
diff --git a/src/p2p/net_node_common.h b/src/p2p/net_node_common.h
index 944bf48e4..26451b333 100644
--- a/src/p2p/net_node_common.h
+++ b/src/p2p/net_node_common.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/p2p/net_peerlist.h b/src/p2p/net_peerlist.h
index 46726d7d8..91d7fa2b3 100644
--- a/src/p2p/net_peerlist.h
+++ b/src/p2p/net_peerlist.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/p2p/net_peerlist_boost_serialization.h b/src/p2p/net_peerlist_boost_serialization.h
index d2e9efa3d..1d6eb7690 100644
--- a/src/p2p/net_peerlist_boost_serialization.h
+++ b/src/p2p/net_peerlist_boost_serialization.h
@@ -1,4 +1,4 @@
- // Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -35,6 +35,7 @@
#include "common/expect.h"
#include "net/net_utils_base.h"
#include "net/tor_address.h"
+#include "net/i2p_address.h"
#include "p2p/p2p_protocol_defs.h"
#ifdef CRYPTONOTE_PRUNING_DEBUG_SPOOF_SEED
@@ -76,6 +77,9 @@ namespace boost
case net::tor_address::get_type_id():
do_serialize<net::tor_address>(is_saving, a, na);
break;
+ case net::i2p_address::get_type_id():
+ do_serialize<net::i2p_address>(is_saving, a, na);
+ break;
case epee::net_utils::address_type::invalid:
default:
throw std::runtime_error("Unsupported network address type");
@@ -107,6 +111,20 @@ namespace boost
}
template <class Archive, class ver_type>
+ inline void save(Archive& a, const net::i2p_address& na, const ver_type)
+ {
+ const size_t length = std::strlen(na.host_str());
+ if (length > 255)
+ MONERO_THROW(net::error::invalid_i2p_address, "i2p address too long");
+
+ const uint16_t port{na.port()};
+ const uint8_t len = length;
+ a & port;
+ a & len;
+ a.save_binary(na.host_str(), length);
+ }
+
+ template <class Archive, class ver_type>
inline void load(Archive& a, net::tor_address& na, const ver_type)
{
uint16_t port = 0;
@@ -128,12 +146,39 @@ namespace boost
}
template <class Archive, class ver_type>
+ inline void load(Archive& a, net::i2p_address& na, const ver_type)
+ {
+ uint16_t port = 0;
+ uint8_t length = 0;
+ a & port;
+ a & length;
+
+ if (length > net::i2p_address::buffer_size())
+ MONERO_THROW(net::error::invalid_i2p_address, "i2p address too long");
+
+ char host[net::i2p_address::buffer_size()] = {0};
+ a.load_binary(host, length);
+ host[sizeof(host) - 1] = 0;
+
+ if (std::strcmp(host, net::i2p_address::unknown_str()) == 0)
+ na = net::i2p_address::unknown();
+ else
+ na = MONERO_UNWRAP(net::i2p_address::make(host, port));
+ }
+
+ template <class Archive, class ver_type>
inline void serialize(Archive &a, net::tor_address& na, const ver_type ver)
{
boost::serialization::split_free(a, na, ver);
}
template <class Archive, class ver_type>
+ inline void serialize(Archive &a, net::i2p_address& na, const ver_type ver)
+ {
+ boost::serialization::split_free(a, na, ver);
+ }
+
+ template <class Archive, class ver_type>
inline void serialize(Archive &a, nodetool::peerlist_entry& pl, const ver_type ver)
{
a & pl.adr;
diff --git a/src/p2p/p2p_protocol_defs.h b/src/p2p/p2p_protocol_defs.h
index 6e5e45008..b08fc7e83 100644
--- a/src/p2p/p2p_protocol_defs.h
+++ b/src/p2p/p2p_protocol_defs.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -35,6 +35,7 @@
#include "serialization/keyvalue_serialization.h"
#include "net/net_utils_base.h"
#include "net/tor_address.h" // needed for serialization
+#include "net/i2p_address.h" // needed for serialization
#include "misc_language.h"
#include "string_tools.h"
#include "time_helper.h"
@@ -178,7 +179,7 @@ namespace nodetool
{
const static int ID = P2P_COMMANDS_POOL_BASE + 1;
- struct request
+ struct request_t
{
basic_node_data node_data;
t_playload_type payload_data;
@@ -188,8 +189,9 @@ namespace nodetool
KV_SERIALIZE(payload_data)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
basic_node_data node_data;
t_playload_type payload_data;
@@ -229,7 +231,8 @@ namespace nodetool
}
END_KV_SERIALIZE_MAP()
};
- };
+ typedef epee::misc_utils::struct_init<response_t> response;
+ };
/************************************************************************/
@@ -240,15 +243,16 @@ namespace nodetool
{
const static int ID = P2P_COMMANDS_POOL_BASE + 2;
- struct request
+ struct request_t
{
t_playload_type payload_data;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(payload_data)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
uint64_t local_time;
t_playload_type payload_data;
@@ -288,6 +292,7 @@ namespace nodetool
}
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
/************************************************************************/
@@ -305,15 +310,16 @@ namespace nodetool
#define PING_OK_RESPONSE_STATUS_TEXT "OK"
- struct request
+ struct request_t
{
/*actually we don't need to send any real data*/
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
peerid_type peer_id;
@@ -323,6 +329,7 @@ namespace nodetool
KV_SERIALIZE(peer_id)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
@@ -349,15 +356,16 @@ namespace nodetool
{
const static int ID = P2P_COMMANDS_POOL_BASE + 4;
- struct request
+ struct request_t
{
proof_of_trust tr;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(tr)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string version;
std::string os_version;
@@ -373,6 +381,7 @@ namespace nodetool
KV_SERIALIZE(payload_info)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
@@ -383,15 +392,16 @@ namespace nodetool
{
const static int ID = P2P_COMMANDS_POOL_BASE + 5;
- struct request
+ struct request_t
{
proof_of_trust tr;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(tr)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::vector<peerlist_entry> local_peerlist_white;
std::vector<peerlist_entry> local_peerlist_gray;
@@ -406,6 +416,7 @@ namespace nodetool
KV_SERIALIZE(local_time)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
/************************************************************************/
@@ -415,13 +426,14 @@ namespace nodetool
{
const static int ID = P2P_COMMANDS_POOL_BASE + 6;
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
peerid_type my_id;
@@ -429,6 +441,7 @@ namespace nodetool
KV_SERIALIZE(my_id)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
/************************************************************************/
@@ -438,13 +451,14 @@ namespace nodetool
{
const static int ID = P2P_COMMANDS_POOL_BASE + 7;
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
uint32_t support_flags;
@@ -452,6 +466,7 @@ namespace nodetool
KV_SERIALIZE(support_flags)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
#endif
diff --git a/src/p2p/stdafx.h b/src/p2p/stdafx.h
index b6ff37811..12a371702 100644
--- a/src/p2p/stdafx.h
+++ b/src/p2p/stdafx.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/platform/mingw/alloca.h b/src/platform/mingw/alloca.h
index 71934b19a..e4722af2a 100644
--- a/src/platform/mingw/alloca.h
+++ b/src/platform/mingw/alloca.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/platform/msc/alloca.h b/src/platform/msc/alloca.h
index 89743e12b..fcf1731b0 100644
--- a/src/platform/msc/alloca.h
+++ b/src/platform/msc/alloca.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/platform/msc/inline_c.h b/src/platform/msc/inline_c.h
index b274f3ec2..23c11bd06 100644
--- a/src/platform/msc/inline_c.h
+++ b/src/platform/msc/inline_c.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/platform/msc/stdbool.h b/src/platform/msc/stdbool.h
index 63e4200b2..4d24995bd 100644
--- a/src/platform/msc/stdbool.h
+++ b/src/platform/msc/stdbool.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/platform/msc/sys/param.h b/src/platform/msc/sys/param.h
index ca9c9282d..e3cfb7e86 100644
--- a/src/platform/msc/sys/param.h
+++ b/src/platform/msc/sys/param.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/ringct/CMakeLists.txt b/src/ringct/CMakeLists.txt
index 29f166a3b..0192aa931 100644
--- a/src/ringct/CMakeLists.txt
+++ b/src/ringct/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2016-2018, The Monero Project
+# Copyright (c) 2016-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/src/ringct/bulletproofs.cc b/src/ringct/bulletproofs.cc
index d485fb748..e394ef088 100644
--- a/src/ringct/bulletproofs.cc
+++ b/src/ringct/bulletproofs.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
@@ -202,20 +202,36 @@ static rct::keyV vector_powers(const rct::key &x, size_t n)
}
/* Given a scalar, return the sum of its powers from 0 to n-1 */
-static rct::key vector_power_sum(const rct::key &x, size_t n)
+static rct::key vector_power_sum(rct::key x, size_t n)
{
if (n == 0)
return rct::zero();
rct::key res = rct::identity();
if (n == 1)
return res;
- rct::key prev = x;
- for (size_t i = 1; i < n; ++i)
+
+ const bool is_power_of_2 = (n & (n - 1)) == 0;
+ if (is_power_of_2)
{
- if (i > 1)
- sc_mul(prev.bytes, prev.bytes, x.bytes);
- sc_add(res.bytes, res.bytes, prev.bytes);
+ sc_add(res.bytes, res.bytes, x.bytes);
+ while (n > 2)
+ {
+ sc_mul(x.bytes, x.bytes, x.bytes);
+ sc_muladd(res.bytes, x.bytes, res.bytes, res.bytes);
+ n /= 2;
+ }
+ }
+ else
+ {
+ rct::key prev = x;
+ for (size_t i = 1; i < n; ++i)
+ {
+ if (i > 1)
+ sc_mul(prev.bytes, prev.bytes, x.bytes);
+ sc_add(res.bytes, res.bytes, prev.bytes);
+ }
}
+
return res;
}
diff --git a/src/ringct/bulletproofs.h b/src/ringct/bulletproofs.h
index b86202ccc..21d494834 100644
--- a/src/ringct/bulletproofs.h
+++ b/src/ringct/bulletproofs.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/ringct/rctCryptoOps.c b/src/ringct/rctCryptoOps.c
index 6fdd17f6b..fbbf6f9bd 100644
--- a/src/ringct/rctCryptoOps.c
+++ b/src/ringct/rctCryptoOps.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/ringct/rctCryptoOps.h b/src/ringct/rctCryptoOps.h
index e5c1c987a..2a25d13a7 100644
--- a/src/ringct/rctCryptoOps.h
+++ b/src/ringct/rctCryptoOps.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/ringct/rctSigs.cpp b/src/ringct/rctSigs.cpp
index 81bec487c..25571238e 100644
--- a/src/ringct/rctSigs.cpp
+++ b/src/ringct/rctSigs.cpp
@@ -469,7 +469,6 @@ namespace rct {
//Ver:
// verifies the above sig is created corretly
mgSig proveRctMG(const key &message, const ctkeyM & pubs, const ctkeyV & inSk, const ctkeyV &outSk, const ctkeyV & outPk, const multisig_kLRki *kLRki, key *mscout, unsigned int index, const key &txnFeeKey, hw::device &hwdev) {
- mgSig mg;
//setup vars
size_t cols = pubs.size();
CHECK_AND_ASSERT_THROW_MES(cols >= 1, "Empty pubs");
@@ -527,7 +526,6 @@ namespace rct {
// a_out, Cout is for the output commitment
// index is the signing index..
mgSig proveRctMGSimple(const key &message, const ctkeyV & pubs, const ctkey & inSk, const key &a , const key &Cout, const multisig_kLRki *kLRki, key *mscout, unsigned int index, hw::device &hwdev) {
- mgSig mg;
//setup vars
size_t rows = 1;
size_t cols = pubs.size();
@@ -793,7 +791,6 @@ namespace rct {
rv.p.bulletproofs.clear();
if (bulletproof)
{
- std::vector<uint64_t> proof_amounts;
size_t n_amounts = outamounts.size();
size_t amounts_proved = 0;
if (rct_config.range_proof_type == RangeProofPaddedBulletproof)
diff --git a/src/rpc/CMakeLists.txt b/src/rpc/CMakeLists.txt
index 60cae036c..cffe8e1eb 100644
--- a/src/rpc/CMakeLists.txt
+++ b/src/rpc/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index bb9768168..6357f84b1 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -65,6 +65,11 @@ namespace
reasons += ", ";
reasons += reason;
}
+
+ uint64_t round_up(uint64_t value, uint64_t quantum)
+ {
+ return (value + quantum - 1) / quantum * quantum;
+ }
}
namespace cryptonote
@@ -76,6 +81,12 @@ namespace cryptonote
command_line::add_arg(desc, arg_rpc_bind_port);
command_line::add_arg(desc, arg_rpc_restricted_bind_port);
command_line::add_arg(desc, arg_restricted_rpc);
+ command_line::add_arg(desc, arg_rpc_ssl);
+ command_line::add_arg(desc, arg_rpc_ssl_private_key);
+ command_line::add_arg(desc, arg_rpc_ssl_certificate);
+ command_line::add_arg(desc, arg_rpc_ssl_allowed_certificates);
+ command_line::add_arg(desc, arg_rpc_ssl_allowed_fingerprints);
+ command_line::add_arg(desc, arg_rpc_ssl_allow_any_cert);
command_line::add_arg(desc, arg_bootstrap_daemon_address);
command_line::add_arg(desc, arg_bootstrap_daemon_login);
cryptonote::rpc_args::init_options(desc);
@@ -112,11 +123,11 @@ namespace cryptonote
epee::net_utils::http::login login;
login.username = bootstrap_daemon_login.substr(0, loc);
login.password = bootstrap_daemon_login.substr(loc + 1);
- m_http_client.set_server(m_bootstrap_daemon_address, login, false);
+ m_http_client.set_server(m_bootstrap_daemon_address, login, epee::net_utils::ssl_support_t::e_ssl_support_autodetect);
}
else
{
- m_http_client.set_server(m_bootstrap_daemon_address, boost::none, false);
+ m_http_client.set_server(m_bootstrap_daemon_address, boost::none, epee::net_utils::ssl_support_t::e_ssl_support_autodetect);
}
m_should_use_bootstrap_daemon = true;
}
@@ -131,9 +142,36 @@ namespace cryptonote
if (rpc_config->login)
http_login.emplace(std::move(rpc_config->login->username), std::move(rpc_config->login->password).password());
+ epee::net_utils::ssl_support_t ssl_support;
+ const std::string ssl = command_line::get_arg(vm, arg_rpc_ssl);
+ if (!epee::net_utils::ssl_support_from_string(ssl_support, ssl))
+ {
+ MFATAL("Invalid RPC SSL support: " << ssl);
+ return false;
+ }
+ const std::string ssl_private_key = command_line::get_arg(vm, arg_rpc_ssl_private_key);
+ const std::string ssl_certificate = command_line::get_arg(vm, arg_rpc_ssl_certificate);
+ const std::vector<std::string> ssl_allowed_certificate_paths = command_line::get_arg(vm, arg_rpc_ssl_allowed_certificates);
+ std::list<std::string> ssl_allowed_certificates;
+ for (const std::string &path: ssl_allowed_certificate_paths)
+ {
+ ssl_allowed_certificates.push_back({});
+ if (!epee::file_io_utils::load_file_to_string(path, ssl_allowed_certificates.back()))
+ {
+ MERROR("Failed to load certificate: " << path);
+ ssl_allowed_certificates.back() = std::string();
+ }
+ }
+
+ const std::vector<std::string> ssl_allowed_fingerprint_strings = command_line::get_arg(vm, arg_rpc_ssl_allowed_fingerprints);
+ std::vector<std::vector<uint8_t>> ssl_allowed_fingerprints{ ssl_allowed_fingerprint_strings.size() };
+ std::transform(ssl_allowed_fingerprint_strings.begin(), ssl_allowed_fingerprint_strings.end(), ssl_allowed_fingerprints.begin(), epee::from_hex::vector);
+ const bool ssl_allow_any_cert = command_line::get_arg(vm, arg_rpc_ssl_allow_any_cert);
+
auto rng = [](size_t len, uint8_t *ptr){ return crypto::rand(len, ptr); };
return epee::http_server_impl_base<core_rpc_server, connection_context>::init(
- rng, std::move(port), std::move(rpc_config->bind_ip), std::move(rpc_config->access_control_origins), std::move(http_login)
+ rng, std::move(port), std::move(rpc_config->bind_ip), std::move(rpc_config->access_control_origins), std::move(http_login),
+ ssl_support, std::make_pair(ssl_private_key, ssl_certificate), std::move(ssl_allowed_certificates), std::move(ssl_allowed_fingerprints), ssl_allow_any_cert
);
}
//------------------------------------------------------------------------------------------------------------------------------
@@ -214,7 +252,9 @@ namespace cryptonote
boost::shared_lock<boost::shared_mutex> lock(m_bootstrap_daemon_mutex);
res.was_bootstrap_ever_used = m_was_bootstrap_ever_used;
}
- res.database_size = restricted ? 0 : m_core.get_blockchain_storage().get_db().get_database_size();
+ res.database_size = m_core.get_blockchain_storage().get_db().get_database_size();
+ if (restricted)
+ res.database_size = round_up(res.database_size, 5ull* 1024 * 1024 * 1024);
res.update_available = restricted ? false : m_core.is_update_available();
res.version = restricted ? "" : MONERO_VERSION;
return true;
@@ -1341,6 +1381,7 @@ namespace cryptonote
response.block_size = response.block_weight = m_core.get_blockchain_storage().get_db().get_block_weight(height);
response.num_txes = blk.tx_hashes.size();
response.pow_hash = fill_pow_hash ? string_tools::pod_to_hex(get_block_longhash(blk, height)) : "";
+ response.long_term_weight = m_core.get_blockchain_storage().get_db().get_block_long_term_weight(height);
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
@@ -2336,6 +2377,40 @@ namespace cryptonote
, false
};
+ const command_line::arg_descriptor<std::string> core_rpc_server::arg_rpc_ssl = {
+ "rpc-ssl"
+ , "Enable SSL on RPC connections: enabled|disabled|autodetect"
+ , "autodetect"
+ };
+
+ const command_line::arg_descriptor<std::string> core_rpc_server::arg_rpc_ssl_private_key = {
+ "rpc-ssl-private-key"
+ , "Path to a PEM format private key"
+ , ""
+ };
+
+ const command_line::arg_descriptor<std::string> core_rpc_server::arg_rpc_ssl_certificate = {
+ "rpc-ssl-certificate"
+ , "Path to a PEM format certificate"
+ , ""
+ };
+
+ const command_line::arg_descriptor<std::vector<std::string>> core_rpc_server::arg_rpc_ssl_allowed_certificates = {
+ "rpc-ssl-allowed-certificates"
+ , "List of paths to PEM format certificates of allowed peers (all allowed if empty)"
+ };
+
+ const command_line::arg_descriptor<std::vector<std::string>> core_rpc_server::arg_rpc_ssl_allowed_fingerprints = {
+ "rpc-ssl-allowed-fingerprints"
+ , "List of certificate fingerprints to allow"
+ };
+
+ const command_line::arg_descriptor<bool> core_rpc_server::arg_rpc_ssl_allow_any_cert = {
+ "rpc-ssl-allow-any-cert"
+ , "Allow any peer certificate, rather than just those on the allowed list"
+ , false
+ };
+
const command_line::arg_descriptor<std::string> core_rpc_server::arg_bootstrap_daemon_address = {
"bootstrap-daemon-address"
, "URL of a 'bootstrap' remote daemon that the connected wallets can use while this daemon is still not fully synced"
diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h
index 62a377841..bcc5f1470 100644
--- a/src/rpc/core_rpc_server.h
+++ b/src/rpc/core_rpc_server.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -56,6 +56,12 @@ namespace cryptonote
static const command_line::arg_descriptor<std::string, false, true, 2> arg_rpc_bind_port;
static const command_line::arg_descriptor<std::string> arg_rpc_restricted_bind_port;
static const command_line::arg_descriptor<bool> arg_restricted_rpc;
+ static const command_line::arg_descriptor<std::string> arg_rpc_ssl;
+ static const command_line::arg_descriptor<std::string> arg_rpc_ssl_private_key;
+ static const command_line::arg_descriptor<std::string> arg_rpc_ssl_certificate;
+ static const command_line::arg_descriptor<std::vector<std::string>> arg_rpc_ssl_allowed_certificates;
+ static const command_line::arg_descriptor<std::vector<std::string>> arg_rpc_ssl_allowed_fingerprints;
+ static const command_line::arg_descriptor<bool> arg_rpc_ssl_allow_any_cert;
static const command_line::arg_descriptor<std::string> arg_bootstrap_daemon_address;
static const command_line::arg_descriptor<std::string> arg_bootstrap_daemon_login;
diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h
index 59caa1b9e..7ee25ca85 100644
--- a/src/rpc/core_rpc_server_commands_defs.h
+++ b/src/rpc/core_rpc_server_commands_defs.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -90,13 +90,14 @@ namespace cryptonote
struct COMMAND_RPC_GET_HEIGHT
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
uint64_t height;
std::string status;
@@ -108,12 +109,13 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_BLOCKS_FAST
{
- struct request
+ struct request_t
{
std::list<crypto::hash> block_ids; //*first 10 blocks id goes sequential, next goes in pow(2,n) offset, like 2, 4, 8, 16, 32, 64 and so on, and the last one is always genesis block */
uint64_t start_height;
@@ -126,6 +128,7 @@ namespace cryptonote
KV_SERIALIZE_OPT(no_miner_tx, false)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
struct tx_output_indices
{
@@ -145,7 +148,7 @@ namespace cryptonote
END_KV_SERIALIZE_MAP()
};
- struct response
+ struct response_t
{
std::vector<block_complete_entry> blocks;
uint64_t start_height;
@@ -163,19 +166,21 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_BLOCKS_BY_HEIGHT
{
- struct request
+ struct request_t
{
std::vector<uint64_t> heights;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(heights)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::vector<block_complete_entry> blocks;
std::string status;
@@ -187,17 +192,19 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_ALT_BLOCKS_HASHES
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::vector<std::string> blks_hashes;
std::string status;
@@ -209,11 +216,12 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_HASHES_FAST
{
- struct request
+ struct request_t
{
std::list<crypto::hash> block_ids; //*first 10 blocks id goes sequential, next goes in pow(2,n) offset, like 2, 4, 8, 16, 32, 64 and so on, and the last one is always genesis block */
uint64_t start_height;
@@ -222,8 +230,9 @@ namespace cryptonote
KV_SERIALIZE(start_height)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::vector<crypto::hash> m_block_ids;
uint64_t start_height;
@@ -239,12 +248,13 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
struct COMMAND_RPC_GET_ADDRESS_TXS
{
- struct request
+ struct request_t
{
std::string address;
std::string view_key;
@@ -254,6 +264,7 @@ namespace cryptonote
KV_SERIALIZE(view_key)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
struct spent_output {
uint64_t amount;
@@ -304,7 +315,7 @@ namespace cryptonote
};
- struct response
+ struct response_t
{
//std::list<std::string> txs_as_json;
uint64_t total_received;
@@ -324,12 +335,13 @@ namespace cryptonote
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
struct COMMAND_RPC_GET_ADDRESS_INFO
{
- struct request
+ struct request_t
{
std::string address;
std::string view_key;
@@ -339,6 +351,7 @@ namespace cryptonote
KV_SERIALIZE(view_key)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
struct spent_output
{
@@ -356,10 +369,8 @@ namespace cryptonote
KV_SERIALIZE(mixin)
END_KV_SERIALIZE_MAP()
};
-
-
-
- struct response
+
+ struct response_t
{
uint64_t locked_funds;
uint64_t total_received;
@@ -382,12 +393,13 @@ namespace cryptonote
KV_SERIALIZE(spent_outputs)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
struct COMMAND_RPC_GET_UNSPENT_OUTS
{
- struct request
+ struct request_t
{
std::string amount;
std::string address;
@@ -406,6 +418,7 @@ namespace cryptonote
KV_SERIALIZE(dust_threshold)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
struct output {
@@ -437,7 +450,7 @@ namespace cryptonote
END_KV_SERIALIZE_MAP()
};
- struct response
+ struct response_t
{
uint64_t amount;
std::list<output> outputs;
@@ -452,12 +465,13 @@ namespace cryptonote
KV_SERIALIZE(reason)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
struct COMMAND_RPC_GET_RANDOM_OUTS
{
- struct request
+ struct request_t
{
std::vector<std::string> amounts;
uint32_t count;
@@ -467,6 +481,7 @@ namespace cryptonote
KV_SERIALIZE(count)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
struct output {
@@ -491,7 +506,7 @@ namespace cryptonote
};
- struct response
+ struct response_t
{
std::vector<amount_out> amount_outs;
std::string Error;
@@ -500,11 +515,12 @@ namespace cryptonote
KV_SERIALIZE(Error)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
struct COMMAND_RPC_SUBMIT_RAW_TX
{
- struct request
+ struct request_t
{
std::string address;
std::string view_key;
@@ -516,9 +532,10 @@ namespace cryptonote
KV_SERIALIZE(tx)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
std::string error;
@@ -528,11 +545,12 @@ namespace cryptonote
KV_SERIALIZE(error)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
struct COMMAND_RPC_LOGIN
{
- struct request
+ struct request_t
{
std::string address;
std::string view_key;
@@ -544,9 +562,9 @@ namespace cryptonote
KV_SERIALIZE(create_account)
END_KV_SERIALIZE_MAP()
};
-
-
- struct response
+ typedef epee::misc_utils::struct_init<request_t> request;
+
+ struct response_t
{
std::string status;
std::string reason;
@@ -558,11 +576,12 @@ namespace cryptonote
KV_SERIALIZE(new_address)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
struct COMMAND_RPC_IMPORT_WALLET_REQUEST
{
- struct request
+ struct request_t
{
std::string address;
std::string view_key;
@@ -572,9 +591,9 @@ namespace cryptonote
KV_SERIALIZE(view_key)
END_KV_SERIALIZE_MAP()
};
-
-
- struct response
+ typedef epee::misc_utils::struct_init<request_t> request;
+
+ struct response_t
{
std::string payment_id;
uint64_t import_fee;
@@ -592,11 +611,12 @@ namespace cryptonote
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
struct COMMAND_RPC_GET_TRANSACTIONS
{
- struct request
+ struct request_t
{
std::vector<std::string> txs_hashes;
bool decode_as_json;
@@ -610,6 +630,7 @@ namespace cryptonote
KV_SERIALIZE_OPT(split, false)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
struct entry
{
@@ -640,7 +661,7 @@ namespace cryptonote
END_KV_SERIALIZE_MAP()
};
- struct response
+ struct response_t
{
// older compatibility stuff
std::vector<std::string> txs_as_hex; //transactions blobs as hex (old compat)
@@ -663,6 +684,7 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
@@ -674,7 +696,7 @@ namespace cryptonote
SPENT_IN_POOL = 2,
};
- struct request
+ struct request_t
{
std::vector<std::string> key_images;
@@ -682,9 +704,10 @@ namespace cryptonote
KV_SERIALIZE(key_images)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::vector<int> spent_status;
std::string status;
@@ -696,21 +719,23 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
struct COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES
{
- struct request
+ struct request_t
{
crypto::hash txid;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_VAL_POD_AS_BLOB(txid)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::vector<uint64_t> o_indexes;
std::string status;
@@ -721,6 +746,7 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
struct get_outputs_out
@@ -736,7 +762,7 @@ namespace cryptonote
struct COMMAND_RPC_GET_OUTPUTS_BIN
{
- struct request
+ struct request_t
{
std::vector<get_outputs_out> outputs;
bool get_txid;
@@ -746,6 +772,7 @@ namespace cryptonote
KV_SERIALIZE_OPT(get_txid, true)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
struct outkey
{
@@ -764,7 +791,7 @@ namespace cryptonote
END_KV_SERIALIZE_MAP()
};
- struct response
+ struct response_t
{
std::vector<outkey> outs;
std::string status;
@@ -776,11 +803,12 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
struct COMMAND_RPC_GET_OUTPUTS
{
- struct request
+ struct request_t
{
std::vector<get_outputs_out> outputs;
@@ -788,6 +816,7 @@ namespace cryptonote
KV_SERIALIZE(outputs)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
struct outkey
{
@@ -806,7 +835,7 @@ namespace cryptonote
END_KV_SERIALIZE_MAP()
};
- struct response
+ struct response_t
{
std::vector<outkey> outs;
std::string status;
@@ -818,11 +847,12 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
struct COMMAND_RPC_SEND_RAW_TX
{
- struct request
+ struct request_t
{
std::string tx_as_hex;
bool do_not_relay;
@@ -832,9 +862,10 @@ namespace cryptonote
KV_SERIALIZE_OPT(do_not_relay, false)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
std::string reason;
@@ -864,11 +895,12 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
struct COMMAND_RPC_START_MINING
{
- struct request
+ struct request_t
{
std::string miner_address;
uint64_t threads_count;
@@ -882,8 +914,9 @@ namespace cryptonote
KV_SERIALIZE(ignore_battery)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
@@ -891,18 +924,20 @@ namespace cryptonote
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
struct COMMAND_RPC_GET_INFO
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
uint64_t height;
@@ -974,21 +1009,23 @@ namespace cryptonote
KV_SERIALIZE(version)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
struct COMMAND_RPC_STOP_MINING
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
@@ -996,20 +1033,22 @@ namespace cryptonote
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
struct COMMAND_RPC_MINING_STATUS
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
bool active;
@@ -1041,20 +1080,22 @@ namespace cryptonote
KV_SERIALIZE(block_reward)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
//-----------------------------------------------
struct COMMAND_RPC_SAVE_BC
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
@@ -1062,6 +1103,7 @@ namespace cryptonote
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
//
@@ -1069,7 +1111,7 @@ namespace cryptonote
{
typedef std::list<std::string> request;
- struct response
+ struct response_t
{
uint64_t count;
std::string status;
@@ -1079,7 +1121,7 @@ namespace cryptonote
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
-
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GETBLOCKHASH
@@ -1092,7 +1134,7 @@ namespace cryptonote
struct COMMAND_RPC_GETBLOCKTEMPLATE
{
- struct request
+ struct request_t
{
uint64_t reserve_size; //max 255 bytes
std::string wallet_address;
@@ -1102,8 +1144,9 @@ namespace cryptonote
KV_SERIALIZE(wallet_address)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
uint64_t difficulty;
uint64_t height;
@@ -1127,13 +1170,14 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_SUBMITBLOCK
{
typedef std::vector<std::string> request;
- struct response
+ struct response_t
{
std::string status;
@@ -1141,11 +1185,12 @@ namespace cryptonote
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GENERATEBLOCKS
{
- struct request
+ struct request_t
{
uint64_t amount_of_blocks;
std::string wallet_address;
@@ -1155,8 +1200,9 @@ namespace cryptonote
KV_SERIALIZE(wallet_address)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
uint64_t height;
std::string status;
@@ -1166,6 +1212,7 @@ namespace cryptonote
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct block_header_response
@@ -1186,6 +1233,7 @@ namespace cryptonote
uint64_t block_weight;
uint64_t num_txes;
std::string pow_hash;
+ uint64_t long_term_weight;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(major_version)
@@ -1204,12 +1252,13 @@ namespace cryptonote
KV_SERIALIZE_OPT(block_weight, (uint64_t)0)
KV_SERIALIZE(num_txes)
KV_SERIALIZE(pow_hash)
+ KV_SERIALIZE_OPT(long_term_weight, (uint64_t)0)
END_KV_SERIALIZE_MAP()
};
struct COMMAND_RPC_GET_LAST_BLOCK_HEADER
{
- struct request
+ struct request_t
{
bool fill_pow_hash;
@@ -1217,8 +1266,9 @@ namespace cryptonote
KV_SERIALIZE_OPT(fill_pow_hash, false);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
block_header_response block_header;
@@ -1230,12 +1280,13 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_BLOCK_HEADER_BY_HASH
{
- struct request
+ struct request_t
{
std::string hash;
bool fill_pow_hash;
@@ -1245,8 +1296,9 @@ namespace cryptonote
KV_SERIALIZE_OPT(fill_pow_hash, false);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
block_header_response block_header;
@@ -1258,12 +1310,12 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
-
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_BLOCK_HEADER_BY_HEIGHT
{
- struct request
+ struct request_t
{
uint64_t height;
bool fill_pow_hash;
@@ -1273,8 +1325,9 @@ namespace cryptonote
KV_SERIALIZE_OPT(fill_pow_hash, false);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
block_header_response block_header;
@@ -1286,12 +1339,12 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
-
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_BLOCK
{
- struct request
+ struct request_t
{
std::string hash;
uint64_t height;
@@ -1303,8 +1356,9 @@ namespace cryptonote
KV_SERIALIZE_OPT(fill_pow_hash, false);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
block_header_response block_header;
@@ -1324,7 +1378,7 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
-
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct peer {
@@ -1356,13 +1410,14 @@ namespace cryptonote
struct COMMAND_RPC_GET_PEER_LIST
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
std::vector<peer> white_list;
@@ -1374,11 +1429,12 @@ namespace cryptonote
KV_SERIALIZE(gray_list)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_SET_LOG_HASH_RATE
{
- struct request
+ struct request_t
{
bool visible;
@@ -1386,19 +1442,21 @@ namespace cryptonote
KV_SERIALIZE(visible)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_SET_LOG_LEVEL
{
- struct request
+ struct request_t
{
int8_t level;
@@ -1406,19 +1464,21 @@ namespace cryptonote
KV_SERIALIZE(level)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_SET_LOG_CATEGORIES
{
- struct request
+ struct request_t
{
std::string categories;
@@ -1426,8 +1486,9 @@ namespace cryptonote
KV_SERIALIZE(categories)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
std::string categories;
@@ -1437,6 +1498,7 @@ namespace cryptonote
KV_SERIALIZE(categories)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct tx_info
@@ -1491,13 +1553,14 @@ namespace cryptonote
struct COMMAND_RPC_GET_TRANSACTION_POOL
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
std::vector<tx_info> transactions;
@@ -1511,17 +1574,19 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_TRANSACTION_POOL_HASHES_BIN
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
std::vector<crypto::hash> tx_hashes;
@@ -1533,17 +1598,19 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_TRANSACTION_POOL_HASHES
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
std::vector<std::string> tx_hashes;
@@ -1555,6 +1622,7 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct tx_backlog_entry
@@ -1566,13 +1634,14 @@ namespace cryptonote
struct COMMAND_RPC_GET_TRANSACTION_POOL_BACKLOG
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
std::vector<tx_backlog_entry> backlog;
@@ -1584,6 +1653,7 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct txpool_histo
@@ -1634,13 +1704,14 @@ namespace cryptonote
struct COMMAND_RPC_GET_TRANSACTION_POOL_STATS
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
txpool_stats pool_stats;
@@ -1652,17 +1723,19 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_CONNECTIONS
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
std::list<connection_info> connections;
@@ -1672,12 +1745,12 @@ namespace cryptonote
KV_SERIALIZE(connections)
END_KV_SERIALIZE_MAP()
};
-
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_BLOCK_HEADERS_RANGE
{
- struct request
+ struct request_t
{
uint64_t start_height;
uint64_t end_height;
@@ -1689,8 +1762,9 @@ namespace cryptonote
KV_SERIALIZE_OPT(fill_pow_hash, false);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
std::vector<block_header_response> headers;
@@ -1702,17 +1776,19 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_STOP_DAEMON
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
@@ -1720,17 +1796,19 @@ namespace cryptonote
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_FAST_EXIT
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
@@ -1738,17 +1816,19 @@ namespace cryptonote
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_LIMIT
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
uint64_t limit_up;
@@ -1762,11 +1842,12 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_SET_LIMIT
{
- struct request
+ struct request_t
{
int64_t limit_down; // all limits (for get and set) are kB/s
int64_t limit_up;
@@ -1776,8 +1857,9 @@ namespace cryptonote
KV_SERIALIZE(limit_up)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
int64_t limit_up;
@@ -1789,19 +1871,21 @@ namespace cryptonote
KV_SERIALIZE(limit_down)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_OUT_PEERS
{
- struct request
+ struct request_t
{
uint64_t out_peers;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(out_peers)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
@@ -1809,19 +1893,21 @@ namespace cryptonote
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_IN_PEERS
{
- struct request
+ struct request_t
{
uint64_t in_peers;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(in_peers)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
@@ -1829,17 +1915,19 @@ namespace cryptonote
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_START_SAVE_GRAPH
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
@@ -1847,17 +1935,19 @@ namespace cryptonote
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_STOP_SAVE_GRAPH
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
@@ -1865,11 +1955,12 @@ namespace cryptonote
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_HARD_FORK_INFO
{
- struct request
+ struct request_t
{
uint8_t version;
@@ -1877,8 +1968,9 @@ namespace cryptonote
KV_SERIALIZE(version)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
uint8_t version;
bool enabled;
@@ -1904,6 +1996,7 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GETBANS
@@ -1921,13 +2014,14 @@ namespace cryptonote
END_KV_SERIALIZE_MAP()
};
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
std::vector<ban> bans;
@@ -1937,6 +2031,7 @@ namespace cryptonote
KV_SERIALIZE(bans)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_SETBANS
@@ -1956,7 +2051,7 @@ namespace cryptonote
END_KV_SERIALIZE_MAP()
};
- struct request
+ struct request_t
{
std::vector<ban> bans;
@@ -1964,8 +2059,9 @@ namespace cryptonote
KV_SERIALIZE(bans)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
@@ -1973,11 +2069,12 @@ namespace cryptonote
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_FLUSH_TRANSACTION_POOL
{
- struct request
+ struct request_t
{
std::vector<std::string> txids;
@@ -1985,8 +2082,9 @@ namespace cryptonote
KV_SERIALIZE(txids)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
@@ -1994,11 +2092,12 @@ namespace cryptonote
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_OUTPUT_HISTOGRAM
{
- struct request
+ struct request_t
{
std::vector<uint64_t> amounts;
uint64_t min_count;
@@ -2014,6 +2113,7 @@ namespace cryptonote
KV_SERIALIZE(recent_cutoff);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
struct entry
{
@@ -2034,7 +2134,7 @@ namespace cryptonote
entry() {}
};
- struct response
+ struct response_t
{
std::string status;
std::vector<entry> histogram;
@@ -2046,17 +2146,19 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_VERSION
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
uint32_t version;
@@ -2068,11 +2170,12 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_COINBASE_TX_SUM
{
- struct request
+ struct request_t
{
uint64_t height;
uint64_t count;
@@ -2082,8 +2185,9 @@ namespace cryptonote
KV_SERIALIZE(count);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
uint64_t emission_amount;
@@ -2095,11 +2199,12 @@ namespace cryptonote
KV_SERIALIZE(fee_amount)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_BASE_FEE_ESTIMATE
{
- struct request
+ struct request_t
{
uint64_t grace_blocks;
@@ -2107,8 +2212,9 @@ namespace cryptonote
KV_SERIALIZE(grace_blocks)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
uint64_t fee;
@@ -2122,15 +2228,17 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_ALTERNATE_CHAINS
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
struct chain_info
{
@@ -2151,7 +2259,7 @@ namespace cryptonote
END_KV_SERIALIZE_MAP()
};
- struct response
+ struct response_t
{
std::string status;
std::list<chain_info> chains;
@@ -2161,11 +2269,12 @@ namespace cryptonote
KV_SERIALIZE(chains)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_UPDATE
{
- struct request
+ struct request_t
{
std::string command;
std::string path;
@@ -2175,8 +2284,9 @@ namespace cryptonote
KV_SERIALIZE(path);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
bool update;
@@ -2196,11 +2306,12 @@ namespace cryptonote
KV_SERIALIZE(path)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_RELAY_TX
{
- struct request
+ struct request_t
{
std::vector<std::string> txids;
@@ -2208,8 +2319,9 @@ namespace cryptonote
KV_SERIALIZE(txids)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
@@ -2217,15 +2329,17 @@ namespace cryptonote
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_SYNC_INFO
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
struct peer
{
@@ -2257,7 +2371,7 @@ namespace cryptonote
END_KV_SERIALIZE_MAP()
};
- struct response
+ struct response_t
{
std::string status;
uint64_t height;
@@ -2277,11 +2391,12 @@ namespace cryptonote
KV_SERIALIZE(overview)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_OUTPUT_DISTRIBUTION
{
- struct request
+ struct request_t
{
std::vector<uint64_t> amounts;
uint64_t from_height;
@@ -2299,6 +2414,7 @@ namespace cryptonote
KV_SERIALIZE_OPT(compress, false)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
struct distribution
{
@@ -2342,7 +2458,7 @@ namespace cryptonote
END_KV_SERIALIZE_MAP()
};
- struct response
+ struct response_t
{
std::string status;
std::vector<distribution> distributions;
@@ -2354,11 +2470,12 @@ namespace cryptonote
KV_SERIALIZE(untrusted)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_POP_BLOCKS
{
- struct request
+ struct request_t
{
uint64_t nblocks;
@@ -2366,8 +2483,9 @@ namespace cryptonote
KV_SERIALIZE(nblocks);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string status;
uint64_t height;
@@ -2377,11 +2495,12 @@ namespace cryptonote
KV_SERIALIZE(height)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_PRUNE_BLOCKCHAIN
{
- struct request
+ struct request_t
{
bool check;
@@ -2389,8 +2508,9 @@ namespace cryptonote
KV_SERIALIZE_OPT(check, false)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
uint32_t pruning_seed;
std::string status;
@@ -2400,6 +2520,7 @@ namespace cryptonote
KV_SERIALIZE(pruning_seed)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
}
diff --git a/src/rpc/core_rpc_server_error_codes.h b/src/rpc/core_rpc_server_error_codes.h
index 5a754749f..b13049e61 100644
--- a/src/rpc/core_rpc_server_error_codes.h
+++ b/src/rpc/core_rpc_server_error_codes.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/rpc/daemon_handler.cpp b/src/rpc/daemon_handler.cpp
index 871f7d368..14b492786 100644
--- a/src/rpc/daemon_handler.cpp
+++ b/src/rpc/daemon_handler.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/rpc/daemon_handler.h b/src/rpc/daemon_handler.h
index 2c8ac3867..87161784e 100644
--- a/src/rpc/daemon_handler.h
+++ b/src/rpc/daemon_handler.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/rpc/daemon_messages.cpp b/src/rpc/daemon_messages.cpp
index 7c7442014..ecd3683e5 100644
--- a/src/rpc/daemon_messages.cpp
+++ b/src/rpc/daemon_messages.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018, The Monero Project
+// Copyright (c) 2016-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/rpc/daemon_messages.h b/src/rpc/daemon_messages.h
index d2014247c..8ce56b6af 100644
--- a/src/rpc/daemon_messages.h
+++ b/src/rpc/daemon_messages.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018, The Monero Project
+// Copyright (c) 2016-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/rpc/daemon_rpc_version.h b/src/rpc/daemon_rpc_version.h
index e20af5b21..b3eb9699b 100644
--- a/src/rpc/daemon_rpc_version.h
+++ b/src/rpc/daemon_rpc_version.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018, The Monero Project
+// Copyright (c) 2016-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/rpc/instanciations.cpp b/src/rpc/instanciations.cpp
index ec8882982..94fdb5f18 100644
--- a/src/rpc/instanciations.cpp
+++ b/src/rpc/instanciations.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/rpc/message.cpp b/src/rpc/message.cpp
index 0ebe34efe..158b58005 100644
--- a/src/rpc/message.cpp
+++ b/src/rpc/message.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018, The Monero Project
+// Copyright (c) 2016-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/rpc/message.h b/src/rpc/message.h
index 56087b998..2b7b61ab3 100644
--- a/src/rpc/message.h
+++ b/src/rpc/message.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018, The Monero Project
+// Copyright (c) 2016-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/rpc/message_data_structs.h b/src/rpc/message_data_structs.h
index 73cf28cec..8b5e02417 100644
--- a/src/rpc/message_data_structs.h
+++ b/src/rpc/message_data_structs.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018, The Monero Project
+// Copyright (c) 2016-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/rpc/rpc_args.cpp b/src/rpc/rpc_args.cpp
index 60c78480a..f2be94f51 100644
--- a/src/rpc/rpc_args.cpp
+++ b/src/rpc/rpc_args.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/rpc/rpc_args.h b/src/rpc/rpc_args.h
index 8e375385b..216ba3712 100644
--- a/src/rpc/rpc_args.h
+++ b/src/rpc/rpc_args.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/rpc/rpc_handler.h b/src/rpc/rpc_handler.h
index e0d520408..2439eaa58 100644
--- a/src/rpc/rpc_handler.h
+++ b/src/rpc/rpc_handler.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018, The Monero Project
+// Copyright (c) 2016-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/rpc/zmq_server.cpp b/src/rpc/zmq_server.cpp
index a2ff76668..ae748e052 100644
--- a/src/rpc/zmq_server.cpp
+++ b/src/rpc/zmq_server.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018, The Monero Project
+// Copyright (c) 2016-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/rpc/zmq_server.h b/src/rpc/zmq_server.h
index 0cd906a3f..1b1e4c7cf 100644
--- a/src/rpc/zmq_server.h
+++ b/src/rpc/zmq_server.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018, The Monero Project
+// Copyright (c) 2016-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/serialization/CMakeLists.txt b/src/serialization/CMakeLists.txt
index 5a6bebf09..28b775a37 100644
--- a/src/serialization/CMakeLists.txt
+++ b/src/serialization/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2016-2018, The Monero Project
+# Copyright (c) 2016-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/src/serialization/binary_archive.h b/src/serialization/binary_archive.h
index f47a4494d..a0e4eff9d 100644
--- a/src/serialization/binary_archive.h
+++ b/src/serialization/binary_archive.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -99,7 +99,7 @@ struct binary_archive<false> : public binary_archive_base<std::istream, false>
{
explicit binary_archive(stream_type &s) : base_type(s) {
- stream_type::streampos pos = stream_.tellg();
+ stream_type::pos_type pos = stream_.tellg();
stream_.seekg(0, std::ios_base::end);
eof_pos_ = stream_.tellg();
stream_.seekg(pos);
diff --git a/src/serialization/binary_utils.h b/src/serialization/binary_utils.h
index 79b30b337..790661e49 100644
--- a/src/serialization/binary_utils.h
+++ b/src/serialization/binary_utils.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/serialization/container.h b/src/serialization/container.h
index 978a59d2a..dfe0f9691 100644
--- a/src/serialization/container.h
+++ b/src/serialization/container.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2017, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/serialization/crypto.h b/src/serialization/crypto.h
index 87172834f..d2537146e 100644
--- a/src/serialization/crypto.h
+++ b/src/serialization/crypto.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/serialization/debug_archive.h b/src/serialization/debug_archive.h
index c6033a399..093ca41eb 100644
--- a/src/serialization/debug_archive.h
+++ b/src/serialization/debug_archive.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/serialization/deque.h b/src/serialization/deque.h
index 994d3f195..97f16d0a5 100644
--- a/src/serialization/deque.h
+++ b/src/serialization/deque.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2017, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/serialization/json_archive.h b/src/serialization/json_archive.h
index 04436c21c..c9f4e175e 100644
--- a/src/serialization/json_archive.h
+++ b/src/serialization/json_archive.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/serialization/json_object.cpp b/src/serialization/json_object.cpp
index ee4fa4a19..cd3585529 100644
--- a/src/serialization/json_object.cpp
+++ b/src/serialization/json_object.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018, The Monero Project
+// Copyright (c) 2016-2019, The Monero Project
//
// All rights reserved.
//
@@ -563,7 +563,6 @@ void toJsonValue(rapidjson::Document& doc, const cryptonote::connection_info& in
{
val.SetObject();
- auto& al = doc.GetAllocator();
INSERT_INTO_JSON_OBJECT(val, doc, incoming, info.incoming);
INSERT_INTO_JSON_OBJECT(val, doc, localhost, info.localhost);
INSERT_INTO_JSON_OBJECT(val, doc, local_ip, info.local_ip);
diff --git a/src/serialization/json_object.h b/src/serialization/json_object.h
index b6384ca0d..c804d148b 100644
--- a/src/serialization/json_object.h
+++ b/src/serialization/json_object.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018, The Monero Project
+// Copyright (c) 2016-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/serialization/json_utils.h b/src/serialization/json_utils.h
index 16f32cf66..05122f3bd 100644
--- a/src/serialization/json_utils.h
+++ b/src/serialization/json_utils.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/serialization/list.h b/src/serialization/list.h
index ef0063a98..b7b65e184 100644
--- a/src/serialization/list.h
+++ b/src/serialization/list.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/serialization/pair.h b/src/serialization/pair.h
index 67105d530..aed0c4699 100644
--- a/src/serialization/pair.h
+++ b/src/serialization/pair.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/serialization/serialization.h b/src/serialization/serialization.h
index 2050e88e2..007bf265f 100644
--- a/src/serialization/serialization.h
+++ b/src/serialization/serialization.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/serialization/set.h b/src/serialization/set.h
index edf170852..ae602a2f1 100644
--- a/src/serialization/set.h
+++ b/src/serialization/set.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/serialization/string.h b/src/serialization/string.h
index 97268d454..fd8450f7b 100644
--- a/src/serialization/string.h
+++ b/src/serialization/string.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/serialization/unordered_set.h b/src/serialization/unordered_set.h
index b277f0c4a..6dd01fd93 100644
--- a/src/serialization/unordered_set.h
+++ b/src/serialization/unordered_set.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2017, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/serialization/variant.h b/src/serialization/variant.h
index 1d00ab461..5a179ca87 100644
--- a/src/serialization/variant.h
+++ b/src/serialization/variant.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/serialization/vector.h b/src/serialization/vector.h
index f180b5353..ad96582a5 100644
--- a/src/serialization/vector.h
+++ b/src/serialization/vector.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/simplewallet/CMakeLists.txt b/src/simplewallet/CMakeLists.txt
index e292f85dd..030867dc0 100644
--- a/src/simplewallet/CMakeLists.txt
+++ b/src/simplewallet/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 3cbfb760b..8952a43dd 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -116,7 +116,7 @@ typedef cryptonote::simple_wallet sw;
#define LONG_PAYMENT_ID_SUPPORT_CHECK() \
do { \
if (!m_long_payment_id_support) { \
- fail_msg_writer() << tr("Long payment IDs are obsolete. Use --long-payment-id-support if you really must use one."); \
+ fail_msg_writer() << tr("Long payment IDs are obsolete. Use --long-payment-id-support if you really must use one, and warn the recipient they are using an obsolete feature that will disappear in the future."); \
return true; \
} \
} while(0)
@@ -2705,8 +2705,10 @@ simple_wallet::simple_wallet()
" Set the wallet's refresh behaviour.\n "
"priority [0|1|2|3|4]\n "
" Set the fee to default/unimportant/normal/elevated/priority.\n "
- "confirm-missing-payment-id <1|0>\n "
+ "confirm-missing-payment-id <1|0> (obsolete)\n "
"ask-password <0|1|2 (or never|action|decrypt)>\n "
+ " action: ask the password before many actions such as transfer, etc\n "
+ " decrypt: same as action, but keeps the spend key encrypted in memory when not needed\n "
"unit <monero|millinero|micronero|nanonero|piconero>\n "
" Set the default monero (sub-)unit.\n "
"min-outputs-count [n]\n "
@@ -8402,7 +8404,8 @@ bool simple_wallet::status(const std::vector<std::string> &args)
{
uint64_t local_height = m_wallet->get_blockchain_current_height();
uint32_t version = 0;
- if (!m_wallet->check_connection(&version))
+ bool ssl = false;
+ if (!m_wallet->check_connection(&version, &ssl))
{
success_msg_writer() << "Refreshed " << local_height << "/?, no daemon connected";
return true;
@@ -8414,7 +8417,7 @@ bool simple_wallet::status(const std::vector<std::string> &args)
{
bool synced = local_height == bc_height;
success_msg_writer() << "Refreshed " << local_height << "/" << bc_height << ", " << (synced ? "synced" : "syncing")
- << ", daemon RPC v" << get_version_string(version);
+ << ", daemon RPC v" << get_version_string(version) << ", " << (ssl ? "SSL" : "no SSL");
}
else
{
diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h
index c3dc16d96..6655fda27 100644
--- a/src/simplewallet/simplewallet.h
+++ b/src/simplewallet/simplewallet.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/version.cpp.in b/src/version.cpp.in
index ff2405811..8aaa41b19 100644
--- a/src/version.cpp.in
+++ b/src/version.cpp.in
@@ -1,6 +1,6 @@
#define DEF_MONERO_VERSION_TAG "@VERSIONTAG@"
-#define DEF_MONERO_VERSION "0.13.0.0-master"
-#define DEF_MONERO_RELEASE_NAME "Beryllium Bullet"
+#define DEF_MONERO_VERSION "0.14.1.0"
+#define DEF_MONERO_RELEASE_NAME "Boron Butterfly"
#define DEF_MONERO_VERSION_FULL DEF_MONERO_VERSION "-" DEF_MONERO_VERSION_TAG
#include "version.h"
diff --git a/src/wallet/CMakeLists.txt b/src/wallet/CMakeLists.txt
index 2991f75c5..efd61cb5a 100644
--- a/src/wallet/CMakeLists.txt
+++ b/src/wallet/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/src/wallet/api/CMakeLists.txt b/src/wallet/api/CMakeLists.txt
index d6f2bf6b7..3376ec70e 100644
--- a/src/wallet/api/CMakeLists.txt
+++ b/src/wallet/api/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/src/wallet/api/address_book.cpp b/src/wallet/api/address_book.cpp
index 7ef011e06..7be78bba7 100644
--- a/src/wallet/api/address_book.cpp
+++ b/src/wallet/api/address_book.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/wallet/api/address_book.h b/src/wallet/api/address_book.h
index f4ca68efd..92e6eaa17 100644
--- a/src/wallet/api/address_book.h
+++ b/src/wallet/api/address_book.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/wallet/api/pending_transaction.cpp b/src/wallet/api/pending_transaction.cpp
index 913e3156f..e649f1f3a 100644
--- a/src/wallet/api/pending_transaction.cpp
+++ b/src/wallet/api/pending_transaction.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/wallet/api/pending_transaction.h b/src/wallet/api/pending_transaction.h
index 50b9f07ef..4ec7c656a 100644
--- a/src/wallet/api/pending_transaction.h
+++ b/src/wallet/api/pending_transaction.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/wallet/api/subaddress.cpp b/src/wallet/api/subaddress.cpp
index 61dbbf4b0..8a1d34864 100644
--- a/src/wallet/api/subaddress.cpp
+++ b/src/wallet/api/subaddress.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/wallet/api/subaddress.h b/src/wallet/api/subaddress.h
index f3db7d97b..87585ec16 100644
--- a/src/wallet/api/subaddress.h
+++ b/src/wallet/api/subaddress.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/wallet/api/subaddress_account.cpp b/src/wallet/api/subaddress_account.cpp
index 4765465c3..9bc9d1d91 100644
--- a/src/wallet/api/subaddress_account.cpp
+++ b/src/wallet/api/subaddress_account.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/wallet/api/subaddress_account.h b/src/wallet/api/subaddress_account.h
index b052182f8..358e446d4 100644
--- a/src/wallet/api/subaddress_account.h
+++ b/src/wallet/api/subaddress_account.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/wallet/api/transaction_history.cpp b/src/wallet/api/transaction_history.cpp
index ba46a6904..f4ad8b1f6 100644
--- a/src/wallet/api/transaction_history.cpp
+++ b/src/wallet/api/transaction_history.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/wallet/api/transaction_history.h b/src/wallet/api/transaction_history.h
index 7bdce97e2..67fe1989d 100644
--- a/src/wallet/api/transaction_history.h
+++ b/src/wallet/api/transaction_history.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/wallet/api/transaction_info.cpp b/src/wallet/api/transaction_info.cpp
index cc3209609..21573c6f6 100644
--- a/src/wallet/api/transaction_info.cpp
+++ b/src/wallet/api/transaction_info.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/wallet/api/transaction_info.h b/src/wallet/api/transaction_info.h
index 37e0445d9..d5c8f31cf 100644
--- a/src/wallet/api/transaction_info.h
+++ b/src/wallet/api/transaction_info.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/wallet/api/unsigned_transaction.cpp b/src/wallet/api/unsigned_transaction.cpp
index 29910a3b6..c2c04cbc3 100644
--- a/src/wallet/api/unsigned_transaction.cpp
+++ b/src/wallet/api/unsigned_transaction.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/wallet/api/unsigned_transaction.h b/src/wallet/api/unsigned_transaction.h
index 8a3330014..f1af80fa1 100644
--- a/src/wallet/api/unsigned_transaction.h
+++ b/src/wallet/api/unsigned_transaction.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/wallet/api/utils.cpp b/src/wallet/api/utils.cpp
index 86fe56564..24252868a 100644
--- a/src/wallet/api/utils.cpp
+++ b/src/wallet/api/utils.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp
index 935a8d51c..da6ddc8a3 100644
--- a/src/wallet/api/wallet.cpp
+++ b/src/wallet/api/wallet.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -1504,7 +1504,6 @@ PendingTransaction *WalletImpl::createSweepUnmixableTransaction()
{
clearStatus();
- vector<cryptonote::tx_destination_entry> dsts;
cryptonote::tx_destination_entry de;
PendingTransactionImpl * transaction = new PendingTransactionImpl(*this);
@@ -1924,7 +1923,7 @@ bool WalletImpl::verifyMessageWithPublicKey(const std::string &message, const st
bool WalletImpl::connectToDaemon()
{
- bool result = m_wallet->check_connection(NULL, DEFAULT_CONNECTION_TIMEOUT_MILLIS);
+ bool result = m_wallet->check_connection(NULL, NULL, DEFAULT_CONNECTION_TIMEOUT_MILLIS);
if (!result) {
setStatusError("Error connecting to daemon at " + m_wallet->get_daemon_address());
} else {
@@ -1937,7 +1936,7 @@ bool WalletImpl::connectToDaemon()
Wallet::ConnectionStatus WalletImpl::connected() const
{
uint32_t version = 0;
- m_is_connected = m_wallet->check_connection(&version, DEFAULT_CONNECTION_TIMEOUT_MILLIS);
+ m_is_connected = m_wallet->check_connection(&version, NULL, DEFAULT_CONNECTION_TIMEOUT_MILLIS);
if (!m_is_connected)
return Wallet::ConnectionStatus_Disconnected;
// Version check is not implemented in light wallets nodes/wallets
diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h
index 55240d64f..bd33b773c 100644
--- a/src/wallet/api/wallet.h
+++ b/src/wallet/api/wallet.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h
index 5c301974f..c549c260b 100644
--- a/src/wallet/api/wallet2_api.h
+++ b/src/wallet/api/wallet2_api.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/wallet/api/wallet_manager.cpp b/src/wallet/api/wallet_manager.cpp
index 89fe01c0d..f584e88ac 100644
--- a/src/wallet/api/wallet_manager.cpp
+++ b/src/wallet/api/wallet_manager.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/wallet/api/wallet_manager.h b/src/wallet/api/wallet_manager.h
index b3c0d6c00..0c83d794f 100644
--- a/src/wallet/api/wallet_manager.h
+++ b/src/wallet/api/wallet_manager.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/wallet/message_transporter.cpp b/src/wallet/message_transporter.cpp
index eafd13d3b..2f8188a3c 100644
--- a/src/wallet/message_transporter.cpp
+++ b/src/wallet/message_transporter.cpp
@@ -44,7 +44,7 @@ namespace mms
namespace bitmessage_rpc
{
- struct message_info
+ struct message_info_t
{
uint32_t encodingType;
std::string toAddress;
@@ -66,8 +66,9 @@ namespace bitmessage_rpc
KV_SERIALIZE(subject)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<message_info_t> message_info;
- struct inbox_messages_response
+ struct inbox_messages_response_t
{
std::vector<message_info> inboxMessages;
@@ -75,6 +76,7 @@ namespace bitmessage_rpc
KV_SERIALIZE(inboxMessages)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<inbox_messages_response_t> inbox_messages_response;
}
@@ -116,7 +118,11 @@ bool message_transporter::receive_messages(const std::vector<std::string> &desti
std::string json = get_str_between_tags(answer, "<string>", "</string>");
bitmessage_rpc::inbox_messages_response bitmessage_res;
- epee::serialization::load_t_from_json(bitmessage_res, json);
+ if (!epee::serialization::load_t_from_json(bitmessage_res, json))
+ {
+ MERROR("Failed to deserialize messages");
+ return true;
+ }
size_t size = bitmessage_res.inboxMessages.size();
messages.clear();
@@ -138,8 +144,10 @@ bool message_transporter::receive_messages(const std::vector<std::string> &desti
std::string message_body = epee::string_encoding::base64_decode(message_info.message);
// Second Base64-decoding: The MMS uses Base64 to hide non-textual data in its JSON from Bitmessage
json = epee::string_encoding::base64_decode(message_body);
- epee::serialization::load_t_from_json(message, json);
- is_mms_message = true;
+ if (!epee::serialization::load_t_from_json(message, json))
+ MERROR("Failed to deserialize message");
+ else
+ is_mms_message = true;
}
catch(const std::exception& e)
{
diff --git a/src/wallet/message_transporter.h b/src/wallet/message_transporter.h
index 8291311ce..736fc9b63 100644
--- a/src/wallet/message_transporter.h
+++ b/src/wallet/message_transporter.h
@@ -42,7 +42,7 @@
namespace mms
{
-struct transport_message
+struct transport_message_t
{
cryptonote::account_public_address source_monero_address;
std::string source_transport_address;
@@ -78,6 +78,7 @@ struct transport_message
KV_SERIALIZE(transport_id)
END_KV_SERIALIZE_MAP()
};
+typedef epee::misc_utils::struct_init<transport_message_t> transport_message;
class message_transporter
{
diff --git a/src/wallet/node_rpc_proxy.cpp b/src/wallet/node_rpc_proxy.cpp
index 605531e59..f5f3c0e1b 100644
--- a/src/wallet/node_rpc_proxy.cpp
+++ b/src/wallet/node_rpc_proxy.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/wallet/node_rpc_proxy.h b/src/wallet/node_rpc_proxy.h
index 65f13eaaa..3630aec08 100644
--- a/src/wallet/node_rpc_proxy.h
+++ b/src/wallet/node_rpc_proxy.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index c02d10ab4..8bb886c6d 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -237,6 +237,12 @@ struct options {
const command_line::arg_descriptor<std::string> password_file = {"password-file", tools::wallet2::tr("Wallet password file"), "", true};
const command_line::arg_descriptor<int> daemon_port = {"daemon-port", tools::wallet2::tr("Use daemon instance at port <arg> instead of 18081"), 0};
const command_line::arg_descriptor<std::string> daemon_login = {"daemon-login", tools::wallet2::tr("Specify username[:password] for daemon RPC client"), "", true};
+ const command_line::arg_descriptor<std::string> daemon_ssl = {"daemon-ssl", tools::wallet2::tr("Enable SSL on daemon RPC connections: enabled|disabled|autodetect"), "autodetect"};
+ const command_line::arg_descriptor<std::string> daemon_ssl_private_key = {"daemon-ssl-private-key", tools::wallet2::tr("Path to a PEM format private key"), ""};
+ const command_line::arg_descriptor<std::string> daemon_ssl_certificate = {"daemon-ssl-certificate", tools::wallet2::tr("Path to a PEM format certificate"), ""};
+ const command_line::arg_descriptor<std::vector<std::string>> daemon_ssl_allowed_certificates = {"daemon-ssl-allowed-certificates", tools::wallet2::tr("List of paths to PEM format certificates of allowed RPC servers")};
+ const command_line::arg_descriptor<std::vector<std::string>> daemon_ssl_allowed_fingerprints = {"daemon-ssl-allowed-fingerprints", tools::wallet2::tr("List of valid fingerprints of allowed RPC servers")};
+ const command_line::arg_descriptor<bool> daemon_ssl_allow_any_cert = {"daemon-ssl-allow-any-cert", tools::wallet2::tr("Allow any SSL certificate from the daemon"), false};
const command_line::arg_descriptor<bool> testnet = {"testnet", tools::wallet2::tr("For testnet. Daemon must also be launched with --testnet flag"), false};
const command_line::arg_descriptor<bool> stagenet = {"stagenet", tools::wallet2::tr("For stagenet. Daemon must also be launched with --stagenet flag"), false};
const command_line::arg_descriptor<std::string, false, true, 2> shared_ringdb_dir = {
@@ -308,6 +314,15 @@ std::unique_ptr<tools::wallet2> make_basic(const boost::program_options::variabl
auto daemon_port = command_line::get_arg(vm, opts.daemon_port);
auto device_name = command_line::get_arg(vm, opts.hw_device);
auto device_derivation_path = command_line::get_arg(vm, opts.hw_device_derivation_path);
+ auto daemon_ssl_private_key = command_line::get_arg(vm, opts.daemon_ssl_private_key);
+ auto daemon_ssl_certificate = command_line::get_arg(vm, opts.daemon_ssl_certificate);
+ auto daemon_ssl_allowed_certificates = command_line::get_arg(vm, opts.daemon_ssl_allowed_certificates);
+ auto daemon_ssl_allowed_fingerprints = command_line::get_arg(vm, opts.daemon_ssl_allowed_fingerprints);
+ auto daemon_ssl_allow_any_cert = command_line::get_arg(vm, opts.daemon_ssl_allow_any_cert);
+ auto daemon_ssl = command_line::get_arg(vm, opts.daemon_ssl);
+ epee::net_utils::ssl_support_t ssl_support;
+ THROW_WALLET_EXCEPTION_IF(!epee::net_utils::ssl_support_from_string(ssl_support, daemon_ssl), tools::error::wallet_internal_error,
+ tools::wallet2::tr("Invalid argument for ") + std::string(opts.daemon_ssl.name));
THROW_WALLET_EXCEPTION_IF(!daemon_address.empty() && !daemon_host.empty() && 0 != daemon_port,
tools::error::wallet_internal_error, tools::wallet2::tr("can't specify daemon host or port more than once"));
@@ -358,8 +373,23 @@ std::unique_ptr<tools::wallet2> make_basic(const boost::program_options::variabl
catch (const std::exception &e) { }
}
+ std::list<std::string> ssl_allowed_certificates;
+ for (const std::string &path: daemon_ssl_allowed_certificates)
+ {
+ ssl_allowed_certificates.push_back({});
+ if (!epee::file_io_utils::load_file_to_string(path, ssl_allowed_certificates.back()))
+ {
+ MERROR("Failed to load certificate: " << path);
+ ssl_allowed_certificates.back() = std::string();
+ }
+ }
+
+ std::vector<std::vector<uint8_t>> ssl_allowed_fingerprints{ daemon_ssl_allowed_fingerprints.size() };
+ std::transform(daemon_ssl_allowed_fingerprints.begin(), daemon_ssl_allowed_fingerprints.end(), ssl_allowed_fingerprints.begin(), epee::from_hex::vector);
+
std::unique_ptr<tools::wallet2> wallet(new tools::wallet2(nettype, kdf_rounds, unattended));
- wallet->init(std::move(daemon_address), std::move(login), 0, false, *trusted_daemon);
+ wallet->init(std::move(daemon_address), std::move(login), 0, *trusted_daemon, ssl_support, std::make_pair(daemon_ssl_private_key, daemon_ssl_certificate), ssl_allowed_certificates, ssl_allowed_fingerprints, daemon_ssl_allow_any_cert);
+
boost::filesystem::path ringdb_path = command_line::get_arg(vm, opts.shared_ringdb_dir);
wallet->set_ring_database(ringdb_path.string());
wallet->get_message_store().set_options(vm);
@@ -373,7 +403,7 @@ std::unique_ptr<tools::wallet2> make_basic(const boost::program_options::variabl
}
catch (const std::exception &e)
{
- MERROR("Failed to parse tx notify spec");
+ MERROR("Failed to parse tx notify spec: " << e.what());
}
return wallet;
@@ -763,9 +793,8 @@ uint64_t calculate_fee(bool use_per_byte_fee, const cryptonote::transaction &tx,
return calculate_fee(base_fee, blob_size, fee_multiplier);
}
-crypto::hash8 get_short_payment_id(const tools::wallet2::pending_tx &ptx, hw::device &hwdev)
+bool get_short_payment_id(crypto::hash8 &payment_id8, const tools::wallet2::pending_tx &ptx, hw::device &hwdev)
{
- crypto::hash8 payment_id8 = null_hash8;
std::vector<tx_extra_field> tx_extra_fields;
parse_tx_extra(ptx.tx.extra, tx_extra_fields); // ok if partially parsed
cryptonote::tx_extra_nonce extra_nonce;
@@ -776,19 +805,19 @@ crypto::hash8 get_short_payment_id(const tools::wallet2::pending_tx &ptx, hw::de
if (ptx.dests.empty())
{
MWARNING("Encrypted payment id found, but no destinations public key, cannot decrypt");
- return crypto::null_hash8;
+ return false;
}
- hwdev.decrypt_payment_id(payment_id8, ptx.dests[0].addr.m_view_public_key, ptx.tx_key);
+ return hwdev.decrypt_payment_id(payment_id8, ptx.dests[0].addr.m_view_public_key, ptx.tx_key);
}
}
- return payment_id8;
+ return false;
}
tools::wallet2::tx_construction_data get_construction_data_with_decrypted_short_payment_id(const tools::wallet2::pending_tx &ptx, hw::device &hwdev)
{
tools::wallet2::tx_construction_data construction_data = ptx.construction_data;
- crypto::hash8 payment_id = get_short_payment_id(ptx,hwdev);
- if (payment_id != null_hash8)
+ crypto::hash8 payment_id = null_hash8;
+ if (get_short_payment_id(payment_id, ptx, hwdev))
{
// Remove encrypted
remove_field_from_tx_extra(construction_data.extra, typeid(cryptonote::tx_extra_nonce));
@@ -867,7 +896,7 @@ wallet_keys_unlocker::wallet_keys_unlocker(wallet2 &w, const boost::optional<too
w(w),
locked(password != boost::none)
{
- if (!locked || w.is_unattended() || w.ask_password() != tools::wallet2::AskPasswordToDecrypt)
+ if (!locked || w.is_unattended() || w.ask_password() != tools::wallet2::AskPasswordToDecrypt || w.watch_only())
{
locked = false;
return;
@@ -1015,6 +1044,12 @@ void wallet2::init_options(boost::program_options::options_description& desc_par
command_line::add_arg(desc_params, opts.password_file);
command_line::add_arg(desc_params, opts.daemon_port);
command_line::add_arg(desc_params, opts.daemon_login);
+ command_line::add_arg(desc_params, opts.daemon_ssl);
+ command_line::add_arg(desc_params, opts.daemon_ssl_private_key);
+ command_line::add_arg(desc_params, opts.daemon_ssl_certificate);
+ command_line::add_arg(desc_params, opts.daemon_ssl_allowed_certificates);
+ command_line::add_arg(desc_params, opts.daemon_ssl_allowed_fingerprints);
+ command_line::add_arg(desc_params, opts.daemon_ssl_allow_any_cert);
command_line::add_arg(desc_params, opts.testnet);
command_line::add_arg(desc_params, opts.stagenet);
command_line::add_arg(desc_params, opts.shared_ringdb_dir);
@@ -1066,7 +1101,7 @@ std::unique_ptr<wallet2> wallet2::make_dummy(const boost::program_options::varia
}
//----------------------------------------------------------------------------------------------------
-bool wallet2::init(std::string daemon_address, boost::optional<epee::net_utils::http::login> daemon_login, uint64_t upper_transaction_weight_limit, bool ssl, bool trusted_daemon)
+bool wallet2::init(std::string daemon_address, boost::optional<epee::net_utils::http::login> daemon_login, uint64_t upper_transaction_weight_limit, bool trusted_daemon, epee::net_utils::ssl_support_t ssl_support, const std::pair<std::string, std::string> &private_key_and_certificate_path, const std::list<std::string> &allowed_certificates, const std::vector<std::vector<uint8_t>> &allowed_fingerprints, bool allow_any_cert)
{
m_checkpoints.init_default_checkpoints(m_nettype);
if(m_http_client.is_connected())
@@ -1076,8 +1111,7 @@ bool wallet2::init(std::string daemon_address, boost::optional<epee::net_utils::
m_daemon_address = std::move(daemon_address);
m_daemon_login = std::move(daemon_login);
m_trusted_daemon = trusted_daemon;
- // When switching from light wallet to full wallet, we need to reset the height we got from lw node.
- return m_http_client.set_server(get_daemon_address(), get_daemon_login(), ssl);
+ return m_http_client.set_server(get_daemon_address(), get_daemon_login(), ssl_support, private_key_and_certificate_path, allowed_certificates, allowed_fingerprints, allow_any_cert);
}
//----------------------------------------------------------------------------------------------------
bool wallet2::is_deterministic() const
@@ -1426,7 +1460,7 @@ static uint64_t decodeRct(const rct::rctSig & rv, const crypto::key_derivation &
}
}
//----------------------------------------------------------------------------------------------------
-void wallet2::scan_output(const cryptonote::transaction &tx, const crypto::public_key &tx_pub_key, size_t i, tx_scan_info_t &tx_scan_info, int &num_vouts_received, std::unordered_map<cryptonote::subaddress_index, uint64_t> &tx_money_got_in_outs, std::vector<size_t> &outs, bool pool)
+void wallet2::scan_output(const cryptonote::transaction &tx, bool miner_tx, const crypto::public_key &tx_pub_key, size_t i, tx_scan_info_t &tx_scan_info, int &num_vouts_received, std::unordered_map<cryptonote::subaddress_index, uint64_t> &tx_money_got_in_outs, std::vector<size_t> &outs, bool pool)
{
THROW_WALLET_EXCEPTION_IF(i >= tx.vout.size(), error::wallet_internal_error, "Invalid vout index");
@@ -1459,11 +1493,20 @@ void wallet2::scan_output(const cryptonote::transaction &tx, const crypto::publi
error::wallet_internal_error, "key_image generated ephemeral public key not matched with output_key");
}
- outs.push_back(i);
- if (tx_scan_info.money_transfered == 0)
+ THROW_WALLET_EXCEPTION_IF(std::find(outs.begin(), outs.end(), i) != outs.end(), error::wallet_internal_error, "Same output cannot be added twice");
+ if (tx_scan_info.money_transfered == 0 && !miner_tx)
{
tx_scan_info.money_transfered = tools::decodeRct(tx.rct_signatures, tx_scan_info.received->derivation, i, tx_scan_info.mask, m_account.get_device());
}
+ if (tx_scan_info.money_transfered == 0)
+ {
+ MERROR("Invalid output amount, skipping");
+ tx_scan_info.error = true;
+ return;
+ }
+ outs.push_back(i);
+ THROW_WALLET_EXCEPTION_IF(tx_money_got_in_outs[tx_scan_info.received->index] >= std::numeric_limits<uint64_t>::max() - tx_scan_info.money_transfered,
+ error::wallet_internal_error, "Overflow in received amounts");
tx_money_got_in_outs[tx_scan_info.received->index] += tx_scan_info.money_transfered;
tx_scan_info.amount = tx_scan_info.money_transfered;
++num_vouts_received;
@@ -1496,7 +1539,6 @@ void wallet2::cache_tx_data(const cryptonote::transaction& tx, const crypto::has
// additional tx pubkeys and derivations for multi-destination transfers involving one or more subaddresses
tx_extra_additional_pub_keys additional_tx_pub_keys;
- std::vector<crypto::key_derivation> additional_derivations;
if (find_tx_extra_field_by_type(tx_cache_data.tx_extra_fields, additional_tx_pub_keys))
{
for (size_t i = 0; i < additional_tx_pub_keys.data.size(); ++i)
@@ -1641,7 +1683,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
if (tx_scan_info[i].received)
{
hwdev.conceal_derivation(tx_scan_info[i].received->derivation, tx_pub_key, additional_tx_pub_keys.data, derivation, additional_derivations);
- scan_output(tx, tx_pub_key, i, tx_scan_info[i], num_vouts_received, tx_money_got_in_outs, outs, pool);
+ scan_output(tx, miner_tx, tx_pub_key, i, tx_scan_info[i], num_vouts_received, tx_money_got_in_outs, outs, pool);
}
}
}
@@ -1664,7 +1706,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
if (tx_scan_info[i].received)
{
hwdev.conceal_derivation(tx_scan_info[i].received->derivation, tx_pub_key, additional_tx_pub_keys.data, derivation, additional_derivations);
- scan_output(tx, tx_pub_key, i, tx_scan_info[i], num_vouts_received, tx_money_got_in_outs, outs, pool);
+ scan_output(tx, miner_tx, tx_pub_key, i, tx_scan_info[i], num_vouts_received, tx_money_got_in_outs, outs, pool);
}
}
}
@@ -1680,7 +1722,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
boost::unique_lock<hw::device> hwdev_lock (hwdev);
hwdev.set_mode(hw::device::NONE);
hwdev.conceal_derivation(tx_scan_info[i].received->derivation, tx_pub_key, additional_tx_pub_keys.data, derivation, additional_derivations);
- scan_output(tx, tx_pub_key, i, tx_scan_info[i], num_vouts_received, tx_money_got_in_outs, outs, pool);
+ scan_output(tx, miner_tx, tx_pub_key, i, tx_scan_info[i], num_vouts_received, tx_money_got_in_outs, outs, pool);
}
}
}
@@ -2969,6 +3011,11 @@ void wallet2::refresh(bool trusted_daemon, uint64_t start_height, uint64_t & blo
{
LOG_PRINT_L1("Another try pull_blocks (try_count=" << try_count << ")...");
first = true;
+ start_height = 0;
+ blocks.clear();
+ parsed_blocks.clear();
+ short_chain_history.clear();
+ get_short_chain_history(short_chain_history, 1);
++try_count;
}
else
@@ -4848,7 +4895,7 @@ bool wallet2::prepare_file_names(const std::string& file_path)
return true;
}
//----------------------------------------------------------------------------------------------------
-bool wallet2::check_connection(uint32_t *version, uint32_t timeout)
+bool wallet2::check_connection(uint32_t *version, bool *ssl, uint32_t timeout)
{
THROW_WALLET_EXCEPTION_IF(!m_is_initialized, error::wallet_not_initialized);
@@ -4856,15 +4903,20 @@ bool wallet2::check_connection(uint32_t *version, uint32_t timeout)
// TODO: Add light wallet version check.
if(m_light_wallet) {
- version = 0;
+ if (version)
+ *version = 0;
+ if (ssl)
+ *ssl = m_light_wallet_connected; // light wallet is always SSL
return m_light_wallet_connected;
}
- if(!m_http_client.is_connected())
+ if(!m_http_client.is_connected(ssl))
{
m_node_rpc_proxy.invalidate();
if (!m_http_client.connect(std::chrono::milliseconds(timeout)))
return false;
+ if(!m_http_client.is_connected(ssl))
+ return false;
}
if (version)
@@ -9096,6 +9148,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
{
const size_t estimated_rct_tx_weight = estimate_tx_weight(use_rct, tx.selected_transfers.size(), fake_outs_count, tx.dsts.size()+1, extra.size(), bulletproof);
try_tx = dsts.empty() || (estimated_rct_tx_weight >= TX_WEIGHT_TARGET(upper_transaction_weight_limit));
+ THROW_WALLET_EXCEPTION_IF(try_tx && tx.dsts.empty(), error::tx_too_big, estimated_rct_tx_weight, upper_transaction_weight_limit);
}
}
@@ -10134,11 +10187,11 @@ void wallet2::check_tx_key_helper(const crypto::hash &txid, const crypto::key_de
else
{
cryptonote::blobdata tx_data;
- crypto::hash tx_prefix_hash;
ok = string_tools::parse_hexstr_to_binbuff(res.txs_as_hex.front(), tx_data);
THROW_WALLET_EXCEPTION_IF(!ok, error::wallet_internal_error, "Failed to parse transaction from daemon");
- THROW_WALLET_EXCEPTION_IF(!cryptonote::parse_and_validate_tx_from_blob(tx_data, tx, tx_hash, tx_prefix_hash),
+ THROW_WALLET_EXCEPTION_IF(!cryptonote::parse_and_validate_tx_from_blob(tx_data, tx),
error::wallet_internal_error, "Failed to validate transaction from daemon");
+ tx_hash = cryptonote::get_transaction_hash(tx);
}
THROW_WALLET_EXCEPTION_IF(tx_hash != txid, error::wallet_internal_error,
@@ -10280,11 +10333,11 @@ std::string wallet2::get_tx_proof(const crypto::hash &txid, const cryptonote::ac
else
{
cryptonote::blobdata tx_data;
- crypto::hash tx_prefix_hash;
ok = string_tools::parse_hexstr_to_binbuff(res.txs_as_hex.front(), tx_data);
THROW_WALLET_EXCEPTION_IF(!ok, error::wallet_internal_error, "Failed to parse transaction from daemon");
- THROW_WALLET_EXCEPTION_IF(!cryptonote::parse_and_validate_tx_from_blob(tx_data, tx, tx_hash, tx_prefix_hash),
+ THROW_WALLET_EXCEPTION_IF(!cryptonote::parse_and_validate_tx_from_blob(tx_data, tx),
error::wallet_internal_error, "Failed to validate transaction from daemon");
+ tx_hash = cryptonote::get_transaction_hash(tx);
}
THROW_WALLET_EXCEPTION_IF(tx_hash != txid, error::wallet_internal_error, "Failed to get the right transaction from daemon");
@@ -10398,11 +10451,11 @@ bool wallet2::check_tx_proof(const crypto::hash &txid, const cryptonote::account
else
{
cryptonote::blobdata tx_data;
- crypto::hash tx_prefix_hash;
ok = string_tools::parse_hexstr_to_binbuff(res.txs_as_hex.front(), tx_data);
THROW_WALLET_EXCEPTION_IF(!ok, error::wallet_internal_error, "Failed to parse transaction from daemon");
- THROW_WALLET_EXCEPTION_IF(!cryptonote::parse_and_validate_tx_from_blob(tx_data, tx, tx_hash, tx_prefix_hash),
+ THROW_WALLET_EXCEPTION_IF(!cryptonote::parse_and_validate_tx_from_blob(tx_data, tx),
error::wallet_internal_error, "Failed to validate transaction from daemon");
+ tx_hash = cryptonote::get_transaction_hash(tx);
}
THROW_WALLET_EXCEPTION_IF(tx_hash != txid, error::wallet_internal_error, "Failed to get the right transaction from daemon");
@@ -11308,6 +11361,7 @@ uint64_t wallet2::import_key_images(const std::vector<std::pair<crypto::key_imag
THROW_WALLET_EXCEPTION_IF(!r, error::wallet_internal_error, "Failed to generate key derivation");
}
size_t output_index = 0;
+ bool miner_tx = cryptonote::is_coinbase(spent_tx);
for (const cryptonote::tx_out& out : spent_tx.vout)
{
tx_scan_info_t tx_scan_info;
@@ -11315,11 +11369,13 @@ uint64_t wallet2::import_key_images(const std::vector<std::pair<crypto::key_imag
THROW_WALLET_EXCEPTION_IF(tx_scan_info.error, error::wallet_internal_error, "check_acc_out_precomp failed");
if (tx_scan_info.received)
{
- if (tx_scan_info.money_transfered == 0)
+ if (tx_scan_info.money_transfered == 0 && !miner_tx)
{
rct::key mask;
tx_scan_info.money_transfered = tools::decodeRct(spent_tx.rct_signatures, tx_scan_info.received->derivation, output_index, mask, hwdev);
}
+ THROW_WALLET_EXCEPTION_IF(tx_money_got_in_outs >= std::numeric_limits<uint64_t>::max() - tx_scan_info.money_transfered,
+ error::wallet_internal_error, "Overflow in received amounts");
tx_money_got_in_outs += tx_scan_info.money_transfered;
}
++output_index;
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index 3b2dd6076..36271c82a 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -67,6 +67,7 @@
#define MONERO_DEFAULT_LOG_CATEGORY "wallet.wallet2"
class Serialization_portability_wallet_Test;
+class wallet_accessor_test;
namespace tools
{
@@ -171,6 +172,7 @@ namespace tools
class wallet2
{
friend class ::Serialization_portability_wallet_Test;
+ friend class ::wallet_accessor_test;
friend class wallet_keys_unlocker;
friend class wallet_device_callback;
public:
@@ -676,7 +678,12 @@ namespace tools
bool deinit();
bool init(std::string daemon_address = "http://localhost:8080",
- boost::optional<epee::net_utils::http::login> daemon_login = boost::none, uint64_t upper_transaction_weight_limit = 0, bool ssl = false, bool trusted_daemon = false);
+ boost::optional<epee::net_utils::http::login> daemon_login = boost::none, uint64_t upper_transaction_weight_limit = 0,
+ bool trusted_daemon = true,
+ epee::net_utils::ssl_support_t ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_autodetect,
+ const std::pair<std::string, std::string> &private_key_and_certificate_path = {},
+ const std::list<std::string> &allowed_certificates = {}, const std::vector<std::vector<uint8_t>> &allowed_fingerprints = {},
+ bool allow_any_cert = false);
void stop() { m_run.store(false, std::memory_order_relaxed); m_message_store.stop(); }
@@ -800,7 +807,7 @@ namespace tools
bool sign_multisig_tx_to_file(multisig_tx_set &exported_txs, const std::string &filename, std::vector<crypto::hash> &txids);
std::vector<pending_tx> create_unmixable_sweep_transactions();
void discard_unmixable_outputs();
- bool check_connection(uint32_t *version = NULL, uint32_t timeout = 200000);
+ bool check_connection(uint32_t *version = NULL, bool *ssl = NULL, uint32_t timeout = 200000);
void get_transfers(wallet2::transfer_container& incoming_transfers) const;
void get_payments(const crypto::hash& payment_id, std::list<wallet2::payment_details>& payments, uint64_t min_height = 0, const boost::optional<uint32_t>& subaddr_account = boost::none, const std::set<uint32_t>& subaddr_indices = {}) const;
void get_payments(std::list<std::pair<crypto::hash,wallet2::payment_details>>& payments, uint64_t min_height, uint64_t max_height = (uint64_t)-1, const boost::optional<uint32_t>& subaddr_account = boost::none, const std::set<uint32_t>& subaddr_indices = {}) const;
@@ -1292,7 +1299,7 @@ namespace tools
bool tx_add_fake_output(std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs, uint64_t global_index, const crypto::public_key& tx_public_key, const rct::key& mask, uint64_t real_index, bool unlocked) const;
bool should_pick_a_second_output(bool use_rct, size_t n_transfers, const std::vector<size_t> &unused_transfers_indices, const std::vector<size_t> &unused_dust_indices) const;
std::vector<size_t> get_only_rct(const std::vector<size_t> &unused_dust_indices, const std::vector<size_t> &unused_transfers_indices) const;
- void scan_output(const cryptonote::transaction &tx, const crypto::public_key &tx_pub_key, size_t i, tx_scan_info_t &tx_scan_info, int &num_vouts_received, std::unordered_map<cryptonote::subaddress_index, uint64_t> &tx_money_got_in_outs, std::vector<size_t> &outs, bool pool);
+ void scan_output(const cryptonote::transaction &tx, bool miner_tx, const crypto::public_key &tx_pub_key, size_t i, tx_scan_info_t &tx_scan_info, int &num_vouts_received, std::unordered_map<cryptonote::subaddress_index, uint64_t> &tx_money_got_in_outs, std::vector<size_t> &outs, bool pool);
void trim_hashchain();
crypto::key_image get_multisig_composite_key_image(size_t n) const;
rct::multisig_kLRki get_multisig_composite_kLRki(size_t n, const std::unordered_set<crypto::public_key> &ignore_set, std::unordered_set<rct::key> &used_L, std::unordered_set<rct::key> &new_used_L) const;
diff --git a/src/wallet/wallet_args.cpp b/src/wallet/wallet_args.cpp
index b9d0a6a75..a4bb342ca 100644
--- a/src/wallet/wallet_args.cpp
+++ b/src/wallet/wallet_args.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/wallet/wallet_args.h b/src/wallet/wallet_args.h
index a1f251144..c861dca11 100644
--- a/src/wallet/wallet_args.h
+++ b/src/wallet/wallet_args.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/src/wallet/wallet_errors.h b/src/wallet/wallet_errors.h
index 35862bda1..6ebaaa395 100644
--- a/src/wallet/wallet_errors.h
+++ b/src/wallet/wallet_errors.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -699,26 +699,43 @@ namespace tools
explicit tx_too_big(std::string&& loc, const cryptonote::transaction& tx, uint64_t tx_weight_limit)
: transfer_error(std::move(loc), "transaction is too big")
, m_tx(tx)
+ , m_tx_valid(true)
+ , m_tx_weight(cryptonote::get_transaction_weight(tx))
, m_tx_weight_limit(tx_weight_limit)
{
}
+ explicit tx_too_big(std::string&& loc, uint64_t tx_weight, uint64_t tx_weight_limit)
+ : transfer_error(std::move(loc), "transaction would be too big")
+ , m_tx_valid(false)
+ , m_tx_weight(tx_weight)
+ , m_tx_weight_limit(tx_weight_limit)
+ {
+ }
+
+ bool tx_valid() const { return m_tx_valid; }
const cryptonote::transaction& tx() const { return m_tx; }
+ uint64_t tx_weight() const { return m_tx_weight; }
uint64_t tx_weight_limit() const { return m_tx_weight_limit; }
std::string to_string() const
{
std::ostringstream ss;
- cryptonote::transaction tx = m_tx;
ss << transfer_error::to_string() <<
", tx_weight_limit = " << m_tx_weight_limit <<
- ", tx weight = " << get_transaction_weight(m_tx) <<
- ", tx:\n" << cryptonote::obj_to_json_str(tx);
+ ", tx weight = " << m_tx_weight;
+ if (m_tx_valid)
+ {
+ cryptonote::transaction tx = m_tx;
+ ss << ", tx:\n" << cryptonote::obj_to_json_str(tx);
+ }
return ss.str();
}
private:
cryptonote::transaction m_tx;
+ bool m_tx_valid;
+ uint64_t m_tx_weight;
uint64_t m_tx_weight_limit;
};
//----------------------------------------------------------------------------------------------------
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index c87c2fca6..5b7cf90d0 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -63,6 +63,11 @@ namespace
const command_line::arg_descriptor<bool> arg_restricted = {"restricted-rpc", "Restricts to view-only commands", false};
const command_line::arg_descriptor<std::string> arg_wallet_dir = {"wallet-dir", "Directory for newly created wallets"};
const command_line::arg_descriptor<bool> arg_prompt_for_password = {"prompt-for-password", "Prompts for password when not provided", false};
+ const command_line::arg_descriptor<std::string> arg_rpc_ssl = {"rpc-ssl", tools::wallet2::tr("Enable SSL on wallet RPC connections: enabled|disabled|autodetect"), "autodetect"};
+ const command_line::arg_descriptor<std::string> arg_rpc_ssl_private_key = {"rpc-ssl-private-key", tools::wallet2::tr("Path to a PEM format private key"), ""};
+ const command_line::arg_descriptor<std::string> arg_rpc_ssl_certificate = {"rpc-ssl-certificate", tools::wallet2::tr("Path to a PEM format certificate"), ""};
+ const command_line::arg_descriptor<std::vector<std::string>> arg_rpc_ssl_allowed_certificates = {"rpc-ssl-allowed-certificates", tools::wallet2::tr("List of paths to PEM format certificates of allowed RPC servers (all allowed if empty)")};
+ const command_line::arg_descriptor<std::vector<std::string>> arg_rpc_ssl_allowed_fingerprints = {"rpc-ssl-allowed-fingerprints", tools::wallet2::tr("List of certificate fingerprints to allow")};
constexpr const char default_rpc_username[] = "monero";
@@ -233,10 +238,36 @@ namespace tools
assert(bool(http_login));
} // end auth enabled
+ auto rpc_ssl_private_key = command_line::get_arg(vm, arg_rpc_ssl_private_key);
+ auto rpc_ssl_certificate = command_line::get_arg(vm, arg_rpc_ssl_certificate);
+ auto rpc_ssl_allowed_certificates = command_line::get_arg(vm, arg_rpc_ssl_allowed_certificates);
+ auto rpc_ssl_allowed_fingerprints = command_line::get_arg(vm, arg_rpc_ssl_allowed_fingerprints);
+ auto rpc_ssl = command_line::get_arg(vm, arg_rpc_ssl);
+ epee::net_utils::ssl_support_t rpc_ssl_support;
+ if (!epee::net_utils::ssl_support_from_string(rpc_ssl_support, rpc_ssl))
+ {
+ MERROR("Invalid argument for " << std::string(arg_rpc_ssl.name));
+ return false;
+ }
+ std::list<std::string> allowed_certificates;
+ for (const std::string &path: rpc_ssl_allowed_certificates)
+ {
+ allowed_certificates.push_back({});
+ if (!epee::file_io_utils::load_file_to_string(path, allowed_certificates.back()))
+ {
+ MERROR("Failed to load certificate: " << path);
+ allowed_certificates.back() = std::string();
+ }
+ }
+
+ std::vector<std::vector<uint8_t>> allowed_fingerprints{ rpc_ssl_allowed_fingerprints.size() };
+ std::transform(rpc_ssl_allowed_fingerprints.begin(), rpc_ssl_allowed_fingerprints.end(), allowed_fingerprints.begin(), epee::from_hex::vector);
+
m_net_server.set_threads_prefix("RPC");
auto rng = [](size_t len, uint8_t *ptr) { return crypto::rand(len, ptr); };
return epee::http_server_impl_base<wallet_rpc_server, connection_context>::init(
- rng, std::move(bind_port), std::move(rpc_config->bind_ip), std::move(rpc_config->access_control_origins), std::move(http_login)
+ rng, std::move(bind_port), std::move(rpc_config->bind_ip), std::move(rpc_config->access_control_origins), std::move(http_login),
+ rpc_ssl_support, std::make_pair(rpc_ssl_private_key, rpc_ssl_certificate), std::move(allowed_certificates), std::move(allowed_fingerprints)
);
}
//------------------------------------------------------------------------------------------------------------------------------
@@ -337,30 +368,54 @@ namespace tools
if (!m_wallet) return not_open(er);
try
{
- res.balance = m_wallet->balance(req.account_index);
- res.unlocked_balance = m_wallet->unlocked_balance(req.account_index);
+ res.balance = req.all_accounts ? m_wallet->balance_all() : m_wallet->balance(req.account_index);
+ res.unlocked_balance = req.all_accounts ? m_wallet->unlocked_balance_all() : m_wallet->unlocked_balance(req.account_index);
res.multisig_import_needed = m_wallet->multisig() && m_wallet->has_multisig_partial_key_images();
- std::map<uint32_t, uint64_t> balance_per_subaddress = m_wallet->balance_per_subaddress(req.account_index);
- std::map<uint32_t, uint64_t> unlocked_balance_per_subaddress = m_wallet->unlocked_balance_per_subaddress(req.account_index);
- std::vector<tools::wallet2::transfer_details> transfers;
- m_wallet->get_transfers(transfers);
- std::set<uint32_t> address_indices = req.address_indices;
- if (address_indices.empty())
+ std::map<uint32_t, std::map<uint32_t, uint64_t>> balance_per_subaddress_per_account;
+ std::map<uint32_t, std::map<uint32_t, uint64_t>> unlocked_balance_per_subaddress_per_account;
+ if (req.all_accounts)
{
- for (const auto& i : balance_per_subaddress)
- address_indices.insert(i.first);
+ for (uint32_t account_index = 0; account_index < m_wallet->get_num_subaddress_accounts(); ++account_index)
+ {
+ balance_per_subaddress_per_account[account_index] = m_wallet->balance_per_subaddress(account_index);
+ unlocked_balance_per_subaddress_per_account[account_index] = m_wallet->unlocked_balance_per_subaddress(account_index);
+ }
}
- for (uint32_t i : address_indices)
+ else
{
- wallet_rpc::COMMAND_RPC_GET_BALANCE::per_subaddress_info info;
- info.address_index = i;
- cryptonote::subaddress_index index = {req.account_index, info.address_index};
- info.address = m_wallet->get_subaddress_as_str(index);
- info.balance = balance_per_subaddress[i];
- info.unlocked_balance = unlocked_balance_per_subaddress[i];
- info.label = m_wallet->get_subaddress_label(index);
- info.num_unspent_outputs = std::count_if(transfers.begin(), transfers.end(), [&](const tools::wallet2::transfer_details& td) { return !td.m_spent && td.m_subaddr_index == index; });
- res.per_subaddress.push_back(info);
+ balance_per_subaddress_per_account[req.account_index] = m_wallet->balance_per_subaddress(req.account_index);
+ unlocked_balance_per_subaddress_per_account[req.account_index] = m_wallet->unlocked_balance_per_subaddress(req.account_index);
+ }
+ std::vector<tools::wallet2::transfer_details> transfers;
+ m_wallet->get_transfers(transfers);
+ for (const auto& p : balance_per_subaddress_per_account)
+ {
+ uint32_t account_index = p.first;
+ std::map<uint32_t, uint64_t> balance_per_subaddress = p.second;
+ std::map<uint32_t, uint64_t> unlocked_balance_per_subaddress = unlocked_balance_per_subaddress_per_account[account_index];
+ std::set<uint32_t> address_indices;
+ if (!req.all_accounts && !req.address_indices.empty())
+ {
+ address_indices = req.address_indices;
+ }
+ else
+ {
+ for (const auto& i : balance_per_subaddress)
+ address_indices.insert(i.first);
+ }
+ for (uint32_t i : address_indices)
+ {
+ wallet_rpc::COMMAND_RPC_GET_BALANCE::per_subaddress_info info;
+ info.account_index = account_index;
+ info.address_index = i;
+ cryptonote::subaddress_index index = {info.account_index, info.address_index};
+ info.address = m_wallet->get_subaddress_as_str(index);
+ info.balance = balance_per_subaddress[i];
+ info.unlocked_balance = unlocked_balance_per_subaddress[i];
+ info.label = m_wallet->get_subaddress_label(index);
+ info.num_unspent_outputs = std::count_if(transfers.begin(), transfers.end(), [&](const tools::wallet2::transfer_details& td) { return !td.m_spent && td.m_subaddr_index == index; });
+ res.per_subaddress.emplace_back(std::move(info));
+ }
}
}
catch (const std::exception& e)
@@ -691,13 +746,9 @@ namespace tools
if (wallet2::parse_long_payment_id(payment_id_str, long_payment_id)) {
cryptonote::set_payment_id_to_tx_extra_nonce(extra_nonce, long_payment_id);
}
- /* or short payment ID */
- else if (wallet2::parse_short_payment_id(payment_id_str, short_payment_id)) {
- cryptonote::set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, short_payment_id);
- }
else {
er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID;
- er.message = "Payment id has invalid format: \"" + payment_id_str + "\", expected 16 or 64 character string";
+ er.message = "Payment id has invalid format: \"" + payment_id_str + "\", expected 64 character string";
return false;
}
@@ -1638,23 +1689,14 @@ namespace tools
cryptonote::blobdata payment_id_blob;
// TODO - should the whole thing fail because of one bad id?
-
- if(!epee::string_tools::parse_hexstr_to_binbuff(payment_id_str, payment_id_blob))
- {
- er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID;
- er.message = "Payment ID has invalid format: " + payment_id_str;
- return false;
- }
-
- if(sizeof(payment_id) == payment_id_blob.size())
+ bool r;
+ if (payment_id_str.size() == 2 * sizeof(payment_id))
{
- payment_id = *reinterpret_cast<const crypto::hash*>(payment_id_blob.data());
+ r = epee::string_tools::hex_to_pod(payment_id_str, payment_id);
}
- else if(sizeof(payment_id8) == payment_id_blob.size())
+ else if (payment_id_str.size() == 2 * sizeof(payment_id8))
{
- payment_id8 = *reinterpret_cast<const crypto::hash8*>(payment_id_blob.data());
- memcpy(payment_id.data, payment_id8.data, 8);
- memset(payment_id.data + 8, 0, 24);
+ r = epee::string_tools::hex_to_pod(payment_id_str, payment_id8);
}
else
{
@@ -1663,6 +1705,13 @@ namespace tools
return false;
}
+ if(!r)
+ {
+ er.code = WALLET_RPC_ERROR_CODE_WRONG_PAYMENT_ID;
+ er.message = "Payment ID has invalid format: " + payment_id_str;
+ return false;
+ }
+
std::list<wallet2::payment_details> payment_list;
m_wallet->get_payments(payment_id, payment_list, req.min_block_height);
@@ -2146,9 +2195,6 @@ namespace tools
try
{
- uint64_t received;
- bool in_pool;
- uint64_t confirmations;
res.good = m_wallet->check_tx_proof(txid, info.address, info.is_subaddress, req.message, req.signature, res.received, res.in_pool, res.confirmations);
}
catch (const std::exception &e)
@@ -2287,10 +2333,18 @@ namespace tools
max_height = req.max_height <= max_height ? req.max_height : max_height;
}
+ boost::optional<uint32_t> account_index = req.account_index;
+ std::set<uint32_t> subaddr_indices = req.subaddr_indices;
+ if (req.all_accounts)
+ {
+ account_index = boost::none;
+ subaddr_indices.clear();
+ }
+
if (req.in)
{
std::list<std::pair<crypto::hash, tools::wallet2::payment_details>> payments;
- m_wallet->get_payments(payments, min_height, max_height, req.account_index, req.subaddr_indices);
+ m_wallet->get_payments(payments, min_height, max_height, account_index, subaddr_indices);
for (std::list<std::pair<crypto::hash, tools::wallet2::payment_details>>::const_iterator i = payments.begin(); i != payments.end(); ++i) {
res.in.push_back(wallet_rpc::transfer_entry());
fill_transfer_entry(res.in.back(), i->second.m_tx_hash, i->first, i->second);
@@ -2300,7 +2354,7 @@ namespace tools
if (req.out)
{
std::list<std::pair<crypto::hash, tools::wallet2::confirmed_transfer_details>> payments;
- m_wallet->get_payments_out(payments, min_height, max_height, req.account_index, req.subaddr_indices);
+ m_wallet->get_payments_out(payments, min_height, max_height, account_index, subaddr_indices);
for (std::list<std::pair<crypto::hash, tools::wallet2::confirmed_transfer_details>>::const_iterator i = payments.begin(); i != payments.end(); ++i) {
res.out.push_back(wallet_rpc::transfer_entry());
fill_transfer_entry(res.out.back(), i->first, i->second);
@@ -2309,7 +2363,7 @@ namespace tools
if (req.pending || req.failed) {
std::list<std::pair<crypto::hash, tools::wallet2::unconfirmed_transfer_details>> upayments;
- m_wallet->get_unconfirmed_payments_out(upayments, req.account_index, req.subaddr_indices);
+ m_wallet->get_unconfirmed_payments_out(upayments, account_index, subaddr_indices);
for (std::list<std::pair<crypto::hash, tools::wallet2::unconfirmed_transfer_details>>::const_iterator i = upayments.begin(); i != upayments.end(); ++i) {
const tools::wallet2::unconfirmed_transfer_details &pd = i->second;
bool is_failed = pd.m_state == tools::wallet2::unconfirmed_transfer_details::failed;
@@ -2326,7 +2380,7 @@ namespace tools
m_wallet->update_pool_state();
std::list<std::pair<crypto::hash, tools::wallet2::pool_payment_details>> payments;
- m_wallet->get_unconfirmed_payments(payments, req.account_index, req.subaddr_indices);
+ m_wallet->get_unconfirmed_payments(payments, account_index, subaddr_indices);
for (std::list<std::pair<crypto::hash, tools::wallet2::pool_payment_details>>::const_iterator i = payments.begin(); i != payments.end(); ++i) {
res.pool.push_back(wallet_rpc::transfer_entry());
fill_transfer_entry(res.pool.back(), i->first, i->second);
@@ -2537,23 +2591,19 @@ namespace tools
ski.resize(req.signed_key_images.size());
for (size_t n = 0; n < ski.size(); ++n)
{
- cryptonote::blobdata bd;
-
- if(!epee::string_tools::parse_hexstr_to_binbuff(req.signed_key_images[n].key_image, bd) || bd.size() != sizeof(crypto::key_image))
+ if (!epee::string_tools::hex_to_pod(req.signed_key_images[n].key_image, ski[n].first))
{
er.code = WALLET_RPC_ERROR_CODE_WRONG_KEY_IMAGE;
er.message = "failed to parse key image";
return false;
}
- ski[n].first = *reinterpret_cast<const crypto::key_image*>(bd.data());
- if(!epee::string_tools::parse_hexstr_to_binbuff(req.signed_key_images[n].signature, bd) || bd.size() != sizeof(crypto::signature))
+ if (!epee::string_tools::hex_to_pod(req.signed_key_images[n].signature, ski[n].second))
{
er.code = WALLET_RPC_ERROR_CODE_WRONG_SIGNATURE;
er.message = "failed to parse signature";
return false;
}
- ski[n].second = *reinterpret_cast<const crypto::signature*>(bd.data());
}
uint64_t spent = 0, unspent = 0;
uint64_t height = m_wallet->import_key_images(ski, req.offset, spent, unspent);
@@ -2857,8 +2907,6 @@ namespace tools
std::vector<std::string> languages;
crypto::ElectrumWords::get_language_list(languages);
std::vector<std::string>::iterator it;
- std::string wallet_file;
- char *ptr;
it = std::find(languages.begin(), languages.end(), req.language);
if (it == languages.end())
@@ -3129,6 +3177,174 @@ namespace tools
}
}
//------------------------------------------------------------------------------------------------------------------------------
+ bool wallet_rpc_server::on_generate_from_keys(const wallet_rpc::COMMAND_RPC_GENERATE_FROM_KEYS::request &req, wallet_rpc::COMMAND_RPC_GENERATE_FROM_KEYS::response &res, epee::json_rpc::error &er, const connection_context *ctx)
+ {
+ if (m_wallet_dir.empty())
+ {
+ er.code = WALLET_RPC_ERROR_CODE_NO_WALLET_DIR;
+ er.message = "No wallet dir configured";
+ return false;
+ }
+
+ // early check for mandatory fields
+ if (req.filename.empty())
+ {
+ er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
+ er.message = "field 'filename' is mandatory. Please provide a filename to save the restored wallet to.";
+ return false;
+ }
+ if (req.viewkey.empty())
+ {
+ er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
+ er.message = "field 'viewkey' is mandatory. Please provide a view key you want to restore from.";
+ return false;
+ }
+ if (req.address.empty())
+ {
+ er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
+ er.message = "field 'address' is mandatory. Please provide a public address.";
+ return false;
+ }
+
+ namespace po = boost::program_options;
+ po::variables_map vm2;
+ const char *ptr = strchr(req.filename.c_str(), '/');
+ #ifdef _WIN32
+ if (!ptr)
+ ptr = strchr(req.filename.c_str(), '\\');
+ if (!ptr)
+ ptr = strchr(req.filename.c_str(), ':');
+ #endif
+ if (ptr)
+ {
+ er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
+ er.message = "Invalid filename";
+ return false;
+ }
+ std::string wallet_file = m_wallet_dir + "/" + req.filename;
+ // check if wallet file already exists
+ if (!wallet_file.empty())
+ {
+ try
+ {
+ boost::system::error_code ignored_ec;
+ THROW_WALLET_EXCEPTION_IF(boost::filesystem::exists(wallet_file, ignored_ec), error::file_exists, wallet_file);
+ }
+ catch (const std::exception &e)
+ {
+ er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
+ er.message = "Wallet already exists.";
+ return false;
+ }
+ }
+
+ {
+ po::options_description desc("dummy");
+ const command_line::arg_descriptor<std::string, true> arg_password = {"password", "password"};
+ const char *argv[4];
+ int argc = 3;
+ argv[0] = "wallet-rpc";
+ argv[1] = "--password";
+ argv[2] = req.password.c_str();
+ argv[3] = NULL;
+ vm2 = *m_vm;
+ command_line::add_arg(desc, arg_password);
+ po::store(po::parse_command_line(argc, argv, desc), vm2);
+ }
+
+ auto rc = tools::wallet2::make_new(vm2, true, nullptr);
+ std::unique_ptr<wallet2> wal;
+ wal = std::move(rc.first);
+ if (!wal)
+ {
+ er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
+ er.message = "Failed to create wallet";
+ return false;
+ }
+
+ cryptonote::address_parse_info info;
+ if(!get_account_address_from_str(info, wal->nettype(), req.address))
+ {
+ er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
+ er.message = "Failed to parse public address";
+ return false;
+ }
+
+ epee::wipeable_string password = rc.second.password();
+ epee::wipeable_string viewkey_string = req.viewkey;
+ crypto::secret_key viewkey;
+ if (!viewkey_string.hex_to_pod(unwrap(unwrap(viewkey))))
+ {
+ er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
+ er.message = "Failed to parse view key secret key";
+ return false;
+ }
+
+ try
+ {
+ if (!req.spendkey.empty())
+ {
+ epee::wipeable_string spendkey_string = req.spendkey;
+ crypto::secret_key spendkey;
+ if (!spendkey_string.hex_to_pod(unwrap(unwrap(spendkey))))
+ {
+ er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
+ er.message = "Failed to parse spend key secret key";
+ return false;
+ }
+ wal->generate(wallet_file, std::move(rc.second).password(), info.address, spendkey, viewkey, false);
+ res.info = "Wallet has been generated successfully.";
+ }
+ else
+ {
+ wal->generate(wallet_file, std::move(rc.second).password(), info.address, viewkey, false);
+ res.info = "Watch-only wallet has been generated successfully.";
+ }
+ MINFO("Wallet has been generated.\n");
+ }
+ catch (const std::exception &e)
+ {
+ handle_rpc_exception(std::current_exception(), er, WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR);
+ return false;
+ }
+
+ if (!wal)
+ {
+ er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR;
+ er.message = "Failed to generate wallet";
+ return false;
+ }
+
+ // set blockheight if given
+ try
+ {
+ wal->set_refresh_from_block_height(req.restore_height);
+ wal->rewrite(wallet_file, password);
+ }
+ catch (const std::exception &e)
+ {
+ handle_rpc_exception(std::current_exception(), er, WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR);
+ return false;
+ }
+
+ if (m_wallet)
+ {
+ try
+ {
+ m_wallet->store();
+ }
+ catch (const std::exception &e)
+ {
+ handle_rpc_exception(std::current_exception(), er, WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR);
+ return false;
+ }
+ delete m_wallet;
+ }
+ m_wallet = wal.release();
+ res.address = m_wallet->get_account().get_public_address_str(m_wallet->nettype());
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::on_restore_deterministic_wallet(const wallet_rpc::COMMAND_RPC_RESTORE_DETERMINISTIC_WALLET::request &req, wallet_rpc::COMMAND_RPC_RESTORE_DETERMINISTIC_WALLET::response &res, epee::json_rpc::error &er, const connection_context *ctx)
{
if (m_wallet_dir.empty())
@@ -3741,6 +3957,57 @@ namespace tools
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
+ bool wallet_rpc_server::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)
+ {
+ cryptonote::address_parse_info info;
+ static const struct { cryptonote::network_type type; const char *stype; } net_types[] = {
+ { cryptonote::MAINNET, "mainnet" },
+ { cryptonote::TESTNET, "testnet" },
+ { cryptonote::STAGENET, "stagenet" },
+ };
+ for (const auto &net_type: net_types)
+ {
+ if (!req.any_net_type && net_type.type != m_wallet->nettype())
+ continue;
+ if (req.allow_openalias)
+ {
+ std::string address;
+ res.valid = get_account_address_from_str_or_url(info, net_type.type, req.address,
+ [&er, &address](const std::string &url, const std::vector<std::string> &addresses, bool dnssec_valid)->std::string {
+ if (!dnssec_valid)
+ {
+ er.message = std::string("Invalid DNSSEC for ") + url;
+ return {};
+ }
+ if (addresses.empty())
+ {
+ er.message = std::string("No Monero address found at ") + url;
+ return {};
+ }
+ address = addresses[0];
+ return address;
+ });
+ if (res.valid)
+ res.openalias_address = address;
+ }
+ else
+ {
+ res.valid = cryptonote::get_account_address_from_str(info, net_type.type, req.address);
+ }
+ if (res.valid)
+ {
+ res.integrated = info.has_payment_id;
+ res.subaddress = info.is_subaddress;
+ res.nettype = net_type.stype;
+ return true;
+ }
+ }
+
+ er.code = WALLET_RPC_ERROR_CODE_WRONG_ADDRESS;
+ er.message = std::string("Invalid address");
+ return false;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
bool wallet_rpc_server::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)
{
res.version = WALLET_RPC_VERSION;
@@ -3937,6 +4204,11 @@ int main(int argc, char** argv) {
command_line::add_arg(desc_params, arg_from_json);
command_line::add_arg(desc_params, arg_wallet_dir);
command_line::add_arg(desc_params, arg_prompt_for_password);
+ command_line::add_arg(desc_params, arg_rpc_ssl);
+ command_line::add_arg(desc_params, arg_rpc_ssl_private_key);
+ command_line::add_arg(desc_params, arg_rpc_ssl_certificate);
+ command_line::add_arg(desc_params, arg_rpc_ssl_allowed_certificates);
+ command_line::add_arg(desc_params, arg_rpc_ssl_allowed_fingerprints);
daemonizer::init_options(hidden_options, desc_params);
desc_params.add(hidden_options);
diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h
index 1a54e4c79..affaf10f7 100644
--- a/src/wallet/wallet_rpc_server.h
+++ b/src/wallet/wallet_rpc_server.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -137,6 +137,7 @@ namespace tools
MAP_JON_RPC_WE("open_wallet", on_open_wallet, wallet_rpc::COMMAND_RPC_OPEN_WALLET)
MAP_JON_RPC_WE("close_wallet", on_close_wallet, wallet_rpc::COMMAND_RPC_CLOSE_WALLET)
MAP_JON_RPC_WE("change_wallet_password", on_change_wallet_password, wallet_rpc::COMMAND_RPC_CHANGE_WALLET_PASSWORD)
+ MAP_JON_RPC_WE("generate_from_keys", on_generate_from_keys, wallet_rpc::COMMAND_RPC_GENERATE_FROM_KEYS)
MAP_JON_RPC_WE("restore_deterministic_wallet", on_restore_deterministic_wallet, wallet_rpc::COMMAND_RPC_RESTORE_DETERMINISTIC_WALLET)
MAP_JON_RPC_WE("is_multisig", on_is_multisig, wallet_rpc::COMMAND_RPC_IS_MULTISIG)
MAP_JON_RPC_WE("prepare_multisig", on_prepare_multisig, wallet_rpc::COMMAND_RPC_PREPARE_MULTISIG)
@@ -147,6 +148,7 @@ namespace tools
MAP_JON_RPC_WE("exchange_multisig_keys", on_exchange_multisig_keys, wallet_rpc::COMMAND_RPC_EXCHANGE_MULTISIG_KEYS)
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)
MAP_JON_RPC_WE("get_version", on_get_version, wallet_rpc::COMMAND_RPC_GET_VERSION)
END_JSON_RPC_MAP()
END_URI_MAP2()
@@ -216,6 +218,7 @@ namespace tools
bool on_open_wallet(const wallet_rpc::COMMAND_RPC_OPEN_WALLET::request& req, wallet_rpc::COMMAND_RPC_OPEN_WALLET::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
bool on_close_wallet(const wallet_rpc::COMMAND_RPC_CLOSE_WALLET::request& req, wallet_rpc::COMMAND_RPC_CLOSE_WALLET::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
bool on_change_wallet_password(const wallet_rpc::COMMAND_RPC_CHANGE_WALLET_PASSWORD::request& req, wallet_rpc::COMMAND_RPC_CHANGE_WALLET_PASSWORD::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
+ bool on_generate_from_keys(const wallet_rpc::COMMAND_RPC_GENERATE_FROM_KEYS::request& req, wallet_rpc::COMMAND_RPC_GENERATE_FROM_KEYS::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
bool on_restore_deterministic_wallet(const wallet_rpc::COMMAND_RPC_RESTORE_DETERMINISTIC_WALLET::request& req, wallet_rpc::COMMAND_RPC_RESTORE_DETERMINISTIC_WALLET::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
bool 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 = NULL);
bool on_prepare_multisig(const wallet_rpc::COMMAND_RPC_PREPARE_MULTISIG::request& req, wallet_rpc::COMMAND_RPC_PREPARE_MULTISIG::response& res, epee::json_rpc::error& er, const connection_context *ctx = NULL);
@@ -226,6 +229,7 @@ namespace tools
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_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);
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);
//json rpc v2
diff --git a/src/wallet/wallet_rpc_server_commands_defs.h b/src/wallet/wallet_rpc_server_commands_defs.h
index f0c1a4e9d..0879502b9 100644
--- a/src/wallet/wallet_rpc_server_commands_defs.h
+++ b/src/wallet/wallet_rpc_server_commands_defs.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -47,7 +47,7 @@
// advance which version they will stop working with
// Don't go over 32767 for any of these
#define WALLET_RPC_VERSION_MAJOR 1
-#define WALLET_RPC_VERSION_MINOR 7
+#define WALLET_RPC_VERSION_MINOR 8
#define MAKE_WALLET_RPC_VERSION(major,minor) (((major)<<16)|(minor))
#define WALLET_RPC_VERSION MAKE_WALLET_RPC_VERSION(WALLET_RPC_VERSION_MAJOR, WALLET_RPC_VERSION_MINOR)
namespace tools
@@ -59,18 +59,22 @@ namespace wallet_rpc
struct COMMAND_RPC_GET_BALANCE
{
- struct request
+ struct request_t
{
uint32_t account_index;
std::set<uint32_t> address_indices;
+ bool all_accounts;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(account_index)
KV_SERIALIZE(address_indices)
+ KV_SERIALIZE_OPT(all_accounts, false);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
struct per_subaddress_info
{
+ uint32_t account_index;
uint32_t address_index;
std::string address;
uint64_t balance;
@@ -79,6 +83,7 @@ namespace wallet_rpc
uint64_t num_unspent_outputs;
BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(account_index)
KV_SERIALIZE(address_index)
KV_SERIALIZE(address)
KV_SERIALIZE(balance)
@@ -88,7 +93,7 @@ namespace wallet_rpc
END_KV_SERIALIZE_MAP()
};
- struct response
+ struct response_t
{
uint64_t balance;
uint64_t unlocked_balance;
@@ -102,11 +107,12 @@ namespace wallet_rpc
KV_SERIALIZE(per_subaddress)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_ADDRESS
{
- struct request
+ struct request_t
{
uint32_t account_index;
std::vector<uint32_t> address_index;
@@ -115,6 +121,7 @@ namespace wallet_rpc
KV_SERIALIZE(address_index)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
struct address_info
{
@@ -131,7 +138,7 @@ namespace wallet_rpc
END_KV_SERIALIZE_MAP()
};
- struct response
+ struct response_t
{
std::string address; // to remain compatible with older RPC format
std::vector<address_info> addresses;
@@ -141,30 +148,33 @@ namespace wallet_rpc
KV_SERIALIZE(addresses)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_ADDRESS_INDEX
{
- struct request
+ struct request_t
{
std::string address;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(address)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
cryptonote::subaddress_index index;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(index)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_CREATE_ADDRESS
{
- struct request
+ struct request_t
{
uint32_t account_index;
std::string label;
@@ -174,8 +184,9 @@ namespace wallet_rpc
KV_SERIALIZE(label)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string address;
uint32_t address_index;
@@ -185,11 +196,12 @@ namespace wallet_rpc
KV_SERIALIZE(address_index)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_LABEL_ADDRESS
{
- struct request
+ struct request_t
{
cryptonote::subaddress_index index;
std::string label;
@@ -199,17 +211,19 @@ namespace wallet_rpc
KV_SERIALIZE(label)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_ACCOUNTS
{
- struct request
+ struct request_t
{
std::string tag; // all accounts if empty, otherwise those accounts with this tag
@@ -217,6 +231,7 @@ namespace wallet_rpc
KV_SERIALIZE(tag)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
struct subaddress_account_info
{
@@ -237,7 +252,7 @@ namespace wallet_rpc
END_KV_SERIALIZE_MAP()
};
- struct response
+ struct response_t
{
uint64_t total_balance;
uint64_t total_unlocked_balance;
@@ -249,19 +264,21 @@ namespace wallet_rpc
KV_SERIALIZE(subaddress_accounts)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_CREATE_ACCOUNT
{
- struct request
+ struct request_t
{
std::string label;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(label)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
uint32_t account_index;
std::string address; // the 0-th address for convenience
@@ -270,11 +287,12 @@ namespace wallet_rpc
KV_SERIALIZE(address)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_LABEL_ACCOUNT
{
- struct request
+ struct request_t
{
uint32_t account_index;
std::string label;
@@ -284,21 +302,24 @@ namespace wallet_rpc
KV_SERIALIZE(label)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_ACCOUNT_TAGS
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
struct account_tag_info
{
@@ -313,7 +334,7 @@ namespace wallet_rpc
END_KV_SERIALIZE_MAP()
};
- struct response
+ struct response_t
{
std::vector<account_tag_info> account_tags;
@@ -321,11 +342,12 @@ namespace wallet_rpc
KV_SERIALIZE(account_tags)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_TAG_ACCOUNTS
{
- struct request
+ struct request_t
{
std::string tag;
std::set<uint32_t> accounts;
@@ -335,17 +357,19 @@ namespace wallet_rpc
KV_SERIALIZE(accounts)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_UNTAG_ACCOUNTS
{
- struct request
+ struct request_t
{
std::set<uint32_t> accounts;
@@ -353,17 +377,19 @@ namespace wallet_rpc
KV_SERIALIZE(accounts)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_SET_ACCOUNT_TAG_DESCRIPTION
{
- struct request
+ struct request_t
{
std::string tag;
std::string description;
@@ -373,29 +399,33 @@ namespace wallet_rpc
KV_SERIALIZE(description)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_HEIGHT
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
uint64_t height;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(height)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct transfer_destination
@@ -410,7 +440,7 @@ namespace wallet_rpc
struct COMMAND_RPC_TRANSFER
{
- struct request
+ struct request_t
{
std::list<transfer_destination> destinations;
uint32_t account_index;
@@ -440,8 +470,9 @@ namespace wallet_rpc
KV_SERIALIZE_OPT(get_tx_metadata, false)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string tx_hash;
std::string tx_key;
@@ -463,11 +494,12 @@ namespace wallet_rpc
KV_SERIALIZE(unsigned_txset)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_TRANSFER_SPLIT
{
- struct request
+ struct request_t
{
std::list<transfer_destination> destinations;
uint32_t account_index;
@@ -497,6 +529,7 @@ namespace wallet_rpc
KV_SERIALIZE_OPT(get_tx_metadata, false)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
struct key_list
{
@@ -507,7 +540,7 @@ namespace wallet_rpc
END_KV_SERIALIZE_MAP()
};
- struct response
+ struct response_t
{
std::list<std::string> tx_hash_list;
std::list<std::string> tx_key_list;
@@ -529,6 +562,7 @@ namespace wallet_rpc
KV_SERIALIZE(unsigned_txset)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_DESCRIBE_TRANSFER
@@ -573,7 +607,7 @@ namespace wallet_rpc
END_KV_SERIALIZE_MAP()
};
- struct request
+ struct request_t
{
std::string unsigned_txset;
@@ -581,8 +615,9 @@ namespace wallet_rpc
KV_SERIALIZE(unsigned_txset)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::list<transfer_description> desc;
@@ -590,11 +625,12 @@ namespace wallet_rpc
KV_SERIALIZE(desc)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_SIGN_TRANSFER
{
- struct request
+ struct request_t
{
std::string unsigned_txset;
bool export_raw;
@@ -606,8 +642,9 @@ namespace wallet_rpc
KV_SERIALIZE_OPT(get_tx_keys, false)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string signed_txset;
std::list<std::string> tx_hash_list;
@@ -621,11 +658,12 @@ namespace wallet_rpc
KV_SERIALIZE(tx_key_list)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_SUBMIT_TRANSFER
{
- struct request
+ struct request_t
{
std::string tx_data_hex;
@@ -633,8 +671,9 @@ namespace wallet_rpc
KV_SERIALIZE(tx_data_hex)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::list<std::string> tx_hash_list;
@@ -642,11 +681,12 @@ namespace wallet_rpc
KV_SERIALIZE(tx_hash_list)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_SWEEP_DUST
{
- struct request
+ struct request_t
{
bool get_tx_keys;
bool do_not_relay;
@@ -660,6 +700,7 @@ namespace wallet_rpc
KV_SERIALIZE_OPT(get_tx_metadata, false)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
struct key_list
{
@@ -670,7 +711,7 @@ namespace wallet_rpc
END_KV_SERIALIZE_MAP()
};
- struct response
+ struct response_t
{
std::list<std::string> tx_hash_list;
std::list<std::string> tx_key_list;
@@ -692,11 +733,12 @@ namespace wallet_rpc
KV_SERIALIZE(unsigned_txset)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_SWEEP_ALL
{
- struct request
+ struct request_t
{
std::string address;
uint32_t account_index;
@@ -730,6 +772,7 @@ namespace wallet_rpc
KV_SERIALIZE_OPT(get_tx_metadata, false)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
struct key_list
{
@@ -740,7 +783,7 @@ namespace wallet_rpc
END_KV_SERIALIZE_MAP()
};
- struct response
+ struct response_t
{
std::list<std::string> tx_hash_list;
std::list<std::string> tx_key_list;
@@ -762,11 +805,12 @@ namespace wallet_rpc
KV_SERIALIZE(unsigned_txset)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_SWEEP_SINGLE
{
- struct request
+ struct request_t
{
std::string address;
uint32_t priority;
@@ -796,8 +840,9 @@ namespace wallet_rpc
KV_SERIALIZE_OPT(get_tx_metadata, false)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string tx_hash;
std::string tx_key;
@@ -819,11 +864,12 @@ namespace wallet_rpc
KV_SERIALIZE(unsigned_txset)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_RELAY_TX
{
- struct request
+ struct request_t
{
std::string hex;
@@ -831,8 +877,9 @@ namespace wallet_rpc
KV_SERIALIZE(hex)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string tx_hash;
@@ -840,21 +887,24 @@ namespace wallet_rpc
KV_SERIALIZE(tx_hash)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_STORE
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct payment_details
@@ -880,7 +930,7 @@ namespace wallet_rpc
struct COMMAND_RPC_GET_PAYMENTS
{
- struct request
+ struct request_t
{
std::string payment_id;
@@ -888,8 +938,9 @@ namespace wallet_rpc
KV_SERIALIZE(payment_id)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::list<payment_details> payments;
@@ -897,11 +948,12 @@ namespace wallet_rpc
KV_SERIALIZE(payments)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_BULK_PAYMENTS
{
- struct request
+ struct request_t
{
std::vector<std::string> payment_ids;
uint64_t min_block_height;
@@ -911,8 +963,9 @@ namespace wallet_rpc
KV_SERIALIZE(min_block_height)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::list<payment_details> payments;
@@ -920,6 +973,7 @@ namespace wallet_rpc
KV_SERIALIZE(payments)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct transfer_details
@@ -943,7 +997,7 @@ namespace wallet_rpc
struct COMMAND_RPC_INCOMING_TRANSFERS
{
- struct request
+ struct request_t
{
std::string transfer_type;
uint32_t account_index;
@@ -955,8 +1009,9 @@ namespace wallet_rpc
KV_SERIALIZE(subaddr_indices)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::list<transfer_details> transfers;
@@ -964,12 +1019,13 @@ namespace wallet_rpc
KV_SERIALIZE(transfers)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
//JSON RPC V2
struct COMMAND_RPC_QUERY_KEY
{
- struct request
+ struct request_t
{
std::string key_type;
@@ -977,8 +1033,9 @@ namespace wallet_rpc
KV_SERIALIZE(key_type)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string key;
@@ -986,11 +1043,12 @@ namespace wallet_rpc
KV_SERIALIZE(key)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_MAKE_INTEGRATED_ADDRESS
{
- struct request
+ struct request_t
{
std::string standard_address;
std::string payment_id;
@@ -1000,8 +1058,9 @@ namespace wallet_rpc
KV_SERIALIZE(payment_id)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string integrated_address;
std::string payment_id;
@@ -1011,11 +1070,12 @@ namespace wallet_rpc
KV_SERIALIZE(payment_id)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_SPLIT_INTEGRATED_ADDRESS
{
- struct request
+ struct request_t
{
std::string integrated_address;
@@ -1023,8 +1083,9 @@ namespace wallet_rpc
KV_SERIALIZE(integrated_address)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string standard_address;
std::string payment_id;
@@ -1036,26 +1097,29 @@ namespace wallet_rpc
KV_SERIALIZE(is_subaddress)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_STOP_WALLET
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_RESCAN_BLOCKCHAIN
{
- struct request
+ struct request_t
{
bool hard;
@@ -1063,17 +1127,19 @@ namespace wallet_rpc
KV_SERIALIZE_OPT(hard, false);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_SET_TX_NOTES
{
- struct request
+ struct request_t
{
std::list<std::string> txids;
std::list<std::string> notes;
@@ -1083,17 +1149,19 @@ namespace wallet_rpc
KV_SERIALIZE(notes)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_TX_NOTES
{
- struct request
+ struct request_t
{
std::list<std::string> txids;
@@ -1101,8 +1169,9 @@ namespace wallet_rpc
KV_SERIALIZE(txids)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::list<std::string> notes;
@@ -1110,11 +1179,12 @@ namespace wallet_rpc
KV_SERIALIZE(notes)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_SET_ATTRIBUTE
{
- struct request
+ struct request_t
{
std::string key;
std::string value;
@@ -1124,17 +1194,19 @@ namespace wallet_rpc
KV_SERIALIZE(value)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_ATTRIBUTE
{
- struct request
+ struct request_t
{
std::string key;
@@ -1143,8 +1215,9 @@ namespace wallet_rpc
KV_SERIALIZE(key)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string value;
@@ -1152,11 +1225,12 @@ namespace wallet_rpc
KV_SERIALIZE(value)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_TX_KEY
{
- struct request
+ struct request_t
{
std::string txid;
@@ -1164,8 +1238,9 @@ namespace wallet_rpc
KV_SERIALIZE(txid)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string tx_key;
@@ -1173,11 +1248,12 @@ namespace wallet_rpc
KV_SERIALIZE(tx_key)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_CHECK_TX_KEY
{
- struct request
+ struct request_t
{
std::string txid;
std::string tx_key;
@@ -1189,8 +1265,9 @@ namespace wallet_rpc
KV_SERIALIZE(address)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
uint64_t received;
bool in_pool;
@@ -1202,11 +1279,12 @@ namespace wallet_rpc
KV_SERIALIZE(confirmations)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_TX_PROOF
{
- struct request
+ struct request_t
{
std::string txid;
std::string address;
@@ -1218,8 +1296,9 @@ namespace wallet_rpc
KV_SERIALIZE(message)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string signature;
@@ -1227,11 +1306,12 @@ namespace wallet_rpc
KV_SERIALIZE(signature)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_CHECK_TX_PROOF
{
- struct request
+ struct request_t
{
std::string txid;
std::string address;
@@ -1245,8 +1325,9 @@ namespace wallet_rpc
KV_SERIALIZE(signature)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
bool good;
uint64_t received;
@@ -1260,6 +1341,7 @@ namespace wallet_rpc
KV_SERIALIZE(confirmations)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct transfer_entry
@@ -1301,7 +1383,7 @@ namespace wallet_rpc
struct COMMAND_RPC_GET_SPEND_PROOF
{
- struct request
+ struct request_t
{
std::string txid;
std::string message;
@@ -1311,8 +1393,9 @@ namespace wallet_rpc
KV_SERIALIZE(message)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string signature;
@@ -1320,11 +1403,12 @@ namespace wallet_rpc
KV_SERIALIZE(signature)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_CHECK_SPEND_PROOF
{
- struct request
+ struct request_t
{
std::string txid;
std::string message;
@@ -1336,8 +1420,9 @@ namespace wallet_rpc
KV_SERIALIZE(signature)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
bool good;
@@ -1345,11 +1430,12 @@ namespace wallet_rpc
KV_SERIALIZE(good)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_RESERVE_PROOF
{
- struct request
+ struct request_t
{
bool all;
uint32_t account_index; // ignored when `all` is true
@@ -1363,8 +1449,9 @@ namespace wallet_rpc
KV_SERIALIZE(message)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string signature;
@@ -1372,11 +1459,12 @@ namespace wallet_rpc
KV_SERIALIZE(signature)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_CHECK_RESERVE_PROOF
{
- struct request
+ struct request_t
{
std::string address;
std::string message;
@@ -1388,8 +1476,9 @@ namespace wallet_rpc
KV_SERIALIZE(signature)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
bool good;
uint64_t total;
@@ -1401,11 +1490,12 @@ namespace wallet_rpc
KV_SERIALIZE(spent)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_TRANSFERS
{
- struct request
+ struct request_t
{
bool in;
bool out;
@@ -1418,6 +1508,7 @@ namespace wallet_rpc
uint64_t max_height;
uint32_t account_index;
std::set<uint32_t> subaddr_indices;
+ bool all_accounts;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(in);
@@ -1430,10 +1521,12 @@ namespace wallet_rpc
KV_SERIALIZE_OPT(max_height, (uint64_t)CRYPTONOTE_MAX_BLOCK_NUMBER);
KV_SERIALIZE(account_index);
KV_SERIALIZE(subaddr_indices);
+ KV_SERIALIZE_OPT(all_accounts, false);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::list<transfer_entry> in;
std::list<transfer_entry> out;
@@ -1449,11 +1542,12 @@ namespace wallet_rpc
KV_SERIALIZE(pool);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_TRANSFER_BY_TXID
{
- struct request
+ struct request_t
{
std::string txid;
uint32_t account_index;
@@ -1463,8 +1557,9 @@ namespace wallet_rpc
KV_SERIALIZE_OPT(account_index, (uint32_t)0)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
transfer_entry transfer;
std::list<transfer_entry> transfers;
@@ -1474,11 +1569,12 @@ namespace wallet_rpc
KV_SERIALIZE(transfers);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_SIGN
{
- struct request
+ struct request_t
{
std::string data;
@@ -1486,8 +1582,9 @@ namespace wallet_rpc
KV_SERIALIZE(data);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string signature;
@@ -1495,11 +1592,12 @@ namespace wallet_rpc
KV_SERIALIZE(signature);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_VERIFY
{
- struct request
+ struct request_t
{
std::string data;
std::string address;
@@ -1511,8 +1609,9 @@ namespace wallet_rpc
KV_SERIALIZE(signature);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
bool good;
@@ -1520,17 +1619,19 @@ namespace wallet_rpc
KV_SERIALIZE(good);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_EXPORT_OUTPUTS
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string outputs_data_hex;
@@ -1538,11 +1639,12 @@ namespace wallet_rpc
KV_SERIALIZE(outputs_data_hex);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_IMPORT_OUTPUTS
{
- struct request
+ struct request_t
{
std::string outputs_data_hex;
@@ -1550,8 +1652,9 @@ namespace wallet_rpc
KV_SERIALIZE(outputs_data_hex);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
uint64_t num_imported;
@@ -1559,11 +1662,12 @@ namespace wallet_rpc
KV_SERIALIZE(num_imported);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_EXPORT_KEY_IMAGES
{
- struct request
+ struct request_t
{
bool all;
@@ -1571,6 +1675,7 @@ namespace wallet_rpc
KV_SERIALIZE_OPT(all, false);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
struct signed_key_image
{
@@ -1583,7 +1688,7 @@ namespace wallet_rpc
END_KV_SERIALIZE_MAP()
};
- struct response
+ struct response_t
{
uint32_t offset;
std::vector<signed_key_image> signed_key_images;
@@ -1593,6 +1698,7 @@ namespace wallet_rpc
KV_SERIALIZE(signed_key_images);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_IMPORT_KEY_IMAGES
@@ -1608,7 +1714,7 @@ namespace wallet_rpc
END_KV_SERIALIZE_MAP()
};
- struct request
+ struct request_t
{
uint32_t offset;
std::vector<signed_key_image> signed_key_images;
@@ -1618,8 +1724,9 @@ namespace wallet_rpc
KV_SERIALIZE(signed_key_images);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
uint64_t height;
uint64_t spent;
@@ -1631,6 +1738,7 @@ namespace wallet_rpc
KV_SERIALIZE(unspent)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct uri_spec
@@ -1652,11 +1760,12 @@ namespace wallet_rpc
struct COMMAND_RPC_MAKE_URI
{
- struct request: public uri_spec
+ struct request_t: public uri_spec
{
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string uri;
@@ -1664,11 +1773,12 @@ namespace wallet_rpc
KV_SERIALIZE(uri)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_PARSE_URI
{
- struct request
+ struct request_t
{
std::string uri;
@@ -1676,8 +1786,9 @@ namespace wallet_rpc
KV_SERIALIZE(uri)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
uri_spec uri;
std::vector<std::string> unknown_parameters;
@@ -1687,11 +1798,12 @@ namespace wallet_rpc
KV_SERIALIZE(unknown_parameters);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_ADD_ADDRESS_BOOK_ENTRY
{
- struct request
+ struct request_t
{
std::string address;
std::string payment_id;
@@ -1703,8 +1815,9 @@ namespace wallet_rpc
KV_SERIALIZE(description)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
uint64_t index;
@@ -1712,11 +1825,12 @@ namespace wallet_rpc
KV_SERIALIZE(index);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_ADDRESS_BOOK_ENTRY
{
- struct request
+ struct request_t
{
std::list<uint64_t> entries;
@@ -1724,6 +1838,7 @@ namespace wallet_rpc
KV_SERIALIZE(entries)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
struct entry
{
@@ -1740,7 +1855,7 @@ namespace wallet_rpc
END_KV_SERIALIZE_MAP()
};
- struct response
+ struct response_t
{
std::vector<entry> entries;
@@ -1748,11 +1863,12 @@ namespace wallet_rpc
KV_SERIALIZE(entries)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_DELETE_ADDRESS_BOOK_ENTRY
{
- struct request
+ struct request_t
{
uint64_t index;
@@ -1760,32 +1876,36 @@ namespace wallet_rpc
KV_SERIALIZE(index);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_RESCAN_SPENT
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_REFRESH
{
- struct request
+ struct request_t
{
uint64_t start_height;
@@ -1793,8 +1913,9 @@ namespace wallet_rpc
KV_SERIALIZE_OPT(start_height, (uint64_t) 0)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
uint64_t blocks_fetched;
bool received_money;
@@ -1804,11 +1925,12 @@ namespace wallet_rpc
KV_SERIALIZE(received_money);
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_START_MINING
{
- struct request
+ struct request_t
{
uint64_t threads_count;
bool do_background_mining;
@@ -1820,37 +1942,43 @@ namespace wallet_rpc
KV_SERIALIZE(ignore_battery)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_STOP_MINING
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_LANGUAGES
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
- struct response
+ typedef epee::misc_utils::struct_init<request_t> request;
+
+ struct response_t
{
std::vector<std::string> languages;
@@ -1858,11 +1986,12 @@ namespace wallet_rpc
KV_SERIALIZE(languages)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_CREATE_WALLET
{
- struct request
+ struct request_t
{
std::string filename;
std::string password;
@@ -1874,16 +2003,19 @@ namespace wallet_rpc
KV_SERIALIZE(language)
END_KV_SERIALIZE_MAP()
};
- struct response
+ 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_OPEN_WALLET
{
- struct request
+ struct request_t
{
std::string filename;
std::string password;
@@ -1893,31 +2025,36 @@ namespace wallet_rpc
KV_SERIALIZE(password)
END_KV_SERIALIZE_MAP()
};
- struct response
+ 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_CLOSE_WALLET
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_CHANGE_WALLET_PASSWORD
{
- struct request
+ struct request_t
{
std::string old_password;
std::string new_password;
@@ -1927,16 +2064,52 @@ namespace wallet_rpc
KV_SERIALIZE(new_password)
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_GENERATE_FROM_KEYS
+ {
+ struct request
+ {
+ uint64_t restore_height;
+ std::string filename;
+ std::string address;
+ std::string spendkey;
+ std::string viewkey;
+ std::string password;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE_OPT(restore_height, (uint64_t)0)
+ KV_SERIALIZE(filename)
+ KV_SERIALIZE(address)
+ KV_SERIALIZE(spendkey)
+ KV_SERIALIZE(viewkey)
+ KV_SERIALIZE(password)
+ END_KV_SERIALIZE_MAP()
+ };
+
struct response
{
+ std::string address;
+ std::string info;
+
BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(address)
+ KV_SERIALIZE(info)
END_KV_SERIALIZE_MAP()
};
};
struct COMMAND_RPC_RESTORE_DETERMINISTIC_WALLET
{
- struct request
+ struct request_t
{
uint64_t restore_height;
std::string filename;
@@ -1954,8 +2127,9 @@ namespace wallet_rpc
KV_SERIALIZE(language)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string address;
std::string seed;
@@ -1969,17 +2143,19 @@ namespace wallet_rpc
KV_SERIALIZE(was_deprecated)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_IS_MULTISIG
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
bool multisig;
bool ready;
@@ -1993,17 +2169,19 @@ namespace wallet_rpc
KV_SERIALIZE(total)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_PREPARE_MULTISIG
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string multisig_info;
@@ -2011,11 +2189,12 @@ namespace wallet_rpc
KV_SERIALIZE(multisig_info)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_MAKE_MULTISIG
{
- struct request
+ struct request_t
{
std::vector<std::string> multisig_info;
uint32_t threshold;
@@ -2027,8 +2206,9 @@ namespace wallet_rpc
KV_SERIALIZE(password)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string address;
std::string multisig_info;
@@ -2038,17 +2218,19 @@ namespace wallet_rpc
KV_SERIALIZE(multisig_info)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_EXPORT_MULTISIG
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string info;
@@ -2056,11 +2238,12 @@ namespace wallet_rpc
KV_SERIALIZE(info)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_IMPORT_MULTISIG
{
- struct request
+ struct request_t
{
std::vector<std::string> info;
@@ -2068,8 +2251,9 @@ namespace wallet_rpc
KV_SERIALIZE(info)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
uint64_t n_outputs;
@@ -2077,11 +2261,12 @@ namespace wallet_rpc
KV_SERIALIZE(n_outputs)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_FINALIZE_MULTISIG
{
- struct request
+ struct request_t
{
std::string password;
std::vector<std::string> multisig_info;
@@ -2091,8 +2276,9 @@ namespace wallet_rpc
KV_SERIALIZE(multisig_info)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string address;
@@ -2100,11 +2286,12 @@ namespace wallet_rpc
KV_SERIALIZE(address)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_EXCHANGE_MULTISIG_KEYS
{
- struct request
+ struct request_t
{
std::string password;
std::vector<std::string> multisig_info;
@@ -2114,8 +2301,9 @@ namespace wallet_rpc
KV_SERIALIZE(multisig_info)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string address;
std::string multisig_info;
@@ -2125,11 +2313,12 @@ namespace wallet_rpc
KV_SERIALIZE(multisig_info)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_SIGN_MULTISIG
{
- struct request
+ struct request_t
{
std::string tx_data_hex;
@@ -2137,8 +2326,9 @@ namespace wallet_rpc
KV_SERIALIZE(tx_data_hex)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::string tx_data_hex;
std::list<std::string> tx_hash_list;
@@ -2148,11 +2338,12 @@ namespace wallet_rpc
KV_SERIALIZE(tx_hash_list)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_SUBMIT_MULTISIG
{
- struct request
+ struct request_t
{
std::string tx_data_hex;
@@ -2160,8 +2351,9 @@ namespace wallet_rpc
KV_SERIALIZE(tx_data_hex)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
std::list<std::string> tx_hash_list;
@@ -2169,17 +2361,19 @@ namespace wallet_rpc
KV_SERIALIZE(tx_hash_list)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
};
struct COMMAND_RPC_GET_VERSION
{
- struct request
+ struct request_t
{
BEGIN_KV_SERIALIZE_MAP()
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<request_t> request;
- struct response
+ struct response_t
{
uint32_t version;
@@ -2187,6 +2381,42 @@ namespace wallet_rpc
KV_SERIALIZE(version)
END_KV_SERIALIZE_MAP()
};
+ typedef epee::misc_utils::struct_init<response_t> response;
+ };
+
+ struct COMMAND_RPC_VALIDATE_ADDRESS
+ {
+ struct request_t
+ {
+ std::string address;
+ bool any_net_type;
+ bool allow_openalias;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(address)
+ KV_SERIALIZE_OPT(any_net_type, false)
+ KV_SERIALIZE_OPT(allow_openalias, false)
+ END_KV_SERIALIZE_MAP()
+ };
+ typedef epee::misc_utils::struct_init<request_t> request;
+
+ struct response_t
+ {
+ bool valid;
+ bool integrated;
+ bool subaddress;
+ std::string nettype;
+ std::string openalias_address;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(valid)
+ KV_SERIALIZE(integrated)
+ KV_SERIALIZE(subaddress)
+ KV_SERIALIZE(nettype)
+ KV_SERIALIZE(openalias_address)
+ 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 9b3a2847d..440a58a47 100644
--- a/src/wallet/wallet_rpc_server_error_codes.h
+++ b/src/wallet/wallet_rpc_server_error_codes.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 20afd4203..bbb0bc051 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
@@ -85,12 +85,17 @@ add_subdirectory(performance_tests)
add_subdirectory(core_proxy)
add_subdirectory(unit_tests)
add_subdirectory(difficulty)
+add_subdirectory(block_weight)
add_subdirectory(hash)
add_subdirectory(net_load_tests)
if (BUILD_GUI_DEPS)
add_subdirectory(libwallet_api_tests)
endif()
+if (TREZOR_DEBUG)
+ add_subdirectory(trezor)
+endif()
+
# add_subdirectory(daemon_tests)
set(hash_targets_sources
@@ -115,6 +120,7 @@ add_test(
set(enabled_tests
core_tests
difficulty
+ block_weight
hash
performance_tests
core_proxy
diff --git a/tests/block_weight/CMakeLists.txt b/tests/block_weight/CMakeLists.txt
new file mode 100644
index 000000000..b0d716ea0
--- /dev/null
+++ b/tests/block_weight/CMakeLists.txt
@@ -0,0 +1,45 @@
+# Copyright (c) 2014-2018, The Monero Project
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without modification, are
+# permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice, this list of
+# conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice, this list
+# of conditions and the following disclaimer in the documentation and/or other
+# materials provided with the distribution.
+#
+# 3. Neither the name of the copyright holder nor the names of its contributors may be
+# used to endorse or promote products derived from this software without specific
+# prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+set(block_weight_sources
+ block_weight.cpp)
+
+set(block_weight_headers)
+
+add_executable(block_weight
+ ${block_weight_sources}
+ ${block_weight_headers})
+target_link_libraries(block_weight
+ PRIVATE
+ cryptonote_core
+ blockchain_db
+ ${EXTRA_LIBRARIES})
+
+add_test(
+ NAME block_weight
+ COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/compare.py ${CMAKE_CURRENT_SOURCE_DIR}/block_weight.py ${CMAKE_CURRENT_BINARY_DIR}/block_weight)
diff --git a/tests/block_weight/block_weight.cpp b/tests/block_weight/block_weight.cpp
new file mode 100644
index 000000000..57fcb497e
--- /dev/null
+++ b/tests/block_weight/block_weight.cpp
@@ -0,0 +1,185 @@
+// Copyright (c) 2019, 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.
+
+#define IN_UNIT_TESTS
+
+#include <stdio.h>
+#include <math.h>
+#include "cryptonote_core/blockchain.h"
+#include "cryptonote_core/tx_pool.h"
+#include "cryptonote_core/cryptonote_core.h"
+#include "blockchain_db/testdb.h"
+
+#define LONG_TERM_BLOCK_WEIGHT_WINDOW 5000
+
+enum test_t
+{
+ test_max = 0,
+ test_lcg = 1,
+ test_min = 2,
+};
+
+namespace
+{
+
+class TestDB: public cryptonote::BaseTestDB
+{
+private:
+ struct block_t
+ {
+ size_t weight;
+ uint64_t long_term_weight;
+ };
+
+public:
+ TestDB() { m_open = true; }
+
+ virtual void add_block( const cryptonote::block& blk
+ , size_t block_weight
+ , uint64_t long_term_block_weight
+ , const cryptonote::difficulty_type& cumulative_difficulty
+ , const uint64_t& coins_generated
+ , uint64_t num_rct_outs
+ , const crypto::hash& blk_hash
+ ) override {
+ blocks.push_back({block_weight, long_term_block_weight});
+ }
+ virtual uint64_t height() const override { return blocks.size(); }
+ virtual size_t get_block_weight(const uint64_t &h) const override { return blocks[h].weight; }
+ virtual uint64_t get_block_long_term_weight(const uint64_t &h) const override { return blocks[h].long_term_weight; }
+ virtual crypto::hash top_block_hash(uint64_t *block_height = NULL) const override {
+ uint64_t h = height();
+ crypto::hash top = crypto::null_hash;
+ if (h)
+ *(uint64_t*)&top = h - 1;
+ if (block_height)
+ *block_height = h - 1;
+ return top;
+ }
+ virtual void pop_block(cryptonote::block &blk, std::vector<cryptonote::transaction> &txs) override { blocks.pop_back(); }
+ virtual void set_hard_fork_version(uint64_t height, uint8_t version) override { if (height >= hf.size()) hf.resize(height + 1); hf[height] = version; }
+ virtual uint8_t get_hard_fork_version(uint64_t height) const override { if (height >= hf.size()) return 255; return hf[height]; }
+
+private:
+ std::vector<block_t> blocks;
+ std::vector<uint8_t> hf;
+};
+
+}
+
+#define PREFIX_WINDOW(hf_version,window) \
+ std::unique_ptr<cryptonote::Blockchain> bc; \
+ cryptonote::tx_memory_pool txpool(*bc); \
+ bc.reset(new cryptonote::Blockchain(txpool)); \
+ 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)LONG_TERM_BLOCK_WEIGHT_WINDOW), std::make_pair((uint8_t)0, (uint64_t)0)} {} \
+ } opts; \
+ cryptonote::Blockchain *blockchain = bc.get(); \
+ bool r = blockchain->init(new TestDB(), cryptonote::FAKECHAIN, true, &opts.test_options, 0, NULL); \
+ if (!r) \
+ { \
+ fprintf(stderr, "Failed to init blockchain\n"); \
+ exit(1); \
+ }
+
+#define PREFIX(hf_version) PREFIX_WINDOW(hf_version, LONG_TERM_BLOCK_WEIGHT_WINDOW)
+
+static uint32_t lcg_seed = 0;
+
+static uint32_t lcg()
+{
+ lcg_seed = (lcg_seed * 0x100000001b3 + 0xcbf29ce484222325) & 0xffffffff;
+ return lcg_seed;
+}
+
+static void test(test_t t, uint64_t blocks)
+{
+ PREFIX(10);
+
+ for (uint64_t h = 0; h < LONG_TERM_BLOCK_WEIGHT_WINDOW; ++h)
+ {
+ cryptonote::block b;
+ b.major_version = 1;
+ b.minor_version = 1;
+ bc->get_db().add_block(std::make_pair(b, ""), 300000, 300000, bc->get_db().height(), bc->get_db().height(), {});
+ if (!bc->update_next_cumulative_weight_limit())
+ {
+ fprintf(stderr, "Failed to update cumulative weight limit 1\n");
+ exit(1);
+ }
+ }
+
+ for (uint64_t h = 0; h < blocks; ++h)
+ {
+ uint64_t w;
+ uint64_t effective_block_weight_median = bc->get_current_cumulative_block_weight_median();
+ switch (t)
+ {
+ case test_lcg:
+ {
+ uint32_t r = lcg();
+ int64_t wi = 90 + r % 500000 + 250000 + sin(h / 200.) * 350000;
+ w = wi < 90 ? 90 : wi;
+ break;
+ }
+ case test_max:
+ w = bc->get_current_cumulative_block_weight_limit();
+ break;
+ case test_min:
+ w = 90;
+ break;
+ default:
+ exit(1);
+ }
+ uint64_t ltw = bc->get_next_long_term_block_weight(w);
+ cryptonote::block b;
+ b.major_version = 10;
+ b.minor_version = 10;
+ 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())
+ {
+ fprintf(stderr, "Failed to update cumulative weight limit\n");
+ exit(1);
+ }
+ std::cout << "H " << h << ", BW " << w << ", EMBW " << effective_block_weight_median << ", LTBW " << ltw << std::endl;
+ }
+}
+
+int main()
+{
+ test(test_max, 2 * LONG_TERM_BLOCK_WEIGHT_WINDOW);
+ test(test_lcg, 9 * LONG_TERM_BLOCK_WEIGHT_WINDOW);
+ test(test_min, 1 * LONG_TERM_BLOCK_WEIGHT_WINDOW);
+ return 0;
+}
diff --git a/tests/block_weight/block_weight.py b/tests/block_weight/block_weight.py
new file mode 100755
index 000000000..06aaabb02
--- /dev/null
+++ b/tests/block_weight/block_weight.py
@@ -0,0 +1,74 @@
+#!/usr/bin/python
+# Simulate a maximal block attack on the Monero network
+# This uses the scheme proposed by ArticMine
+# Written by Sarang Nother
+# Copyright (c) 2019 The Monero Project
+import sys
+import math
+
+MEDIAN_WINDOW_SMALL = 100 # number of recent blocks for median computation
+MEDIAN_WINDOW_BIG = 5000
+MULTIPLIER_SMALL = 1.4 # multipliers for determining weights
+MULTIPLIER_BIG = 50.0
+MEDIAN_THRESHOLD = 300*1000 # initial value for median (scaled kB -> B)
+lcg_seed = 0
+embw = MEDIAN_THRESHOLD
+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
+
+# Compute the median of a list
+def get_median(vec):
+ #temp = vec
+ temp = sorted(vec)
+ if len(temp) % 2 == 1:
+ return temp[len(temp)/2]
+ else:
+ return int((temp[len(temp)/2]+temp[len(temp)/2-1])/2)
+
+def LCG():
+ global lcg_seed
+ lcg_seed = (lcg_seed * 0x100000001b3 + 0xcbf29ce484222325) & 0xffffffff
+ return lcg_seed
+
+def run(t, blocks):
+ global embw
+ global ltembw
+
+ 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
+
+ for block in range(blocks):
+ # determine the long-term effective weight
+ ltmedian = get_median(lt_weights[-MEDIAN_WINDOW_BIG:])
+ ltembw = max(MEDIAN_THRESHOLD,ltmedian)
+
+ # determine the effective weight
+ stmedian = get_median(weights[-MEDIAN_WINDOW_SMALL:])
+ embw = min(max(MEDIAN_THRESHOLD,stmedian),int(MULTIPLIER_BIG*ltembw))
+
+ # drop the lowest values
+ weights = weights[1:]
+ lt_weights = lt_weights[1:]
+
+ # add a block of max weight
+ if t == 0:
+ max_weight = 2 * embw
+ elif t == 1:
+ r = LCG()
+ max_weight = int(90 + r % 500000 + 250000 + math.sin(block / 200.) * 350000)
+ if max_weight < 90: max_weight = 90
+ elif t == 2:
+ max_weight = 90
+ else:
+ sys.exit(1)
+ weights.append(max_weight)
+ lt_weights.append(min(max_weight,int(ltembw + int(ltembw * 2 / 5))))
+
+ #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])
+
+run(0, 2 * MEDIAN_WINDOW_BIG)
+run(1, 9 * MEDIAN_WINDOW_BIG)
+run(2, 1 * MEDIAN_WINDOW_BIG)
diff --git a/tests/block_weight/compare.py b/tests/block_weight/compare.py
new file mode 100755
index 000000000..c6be05206
--- /dev/null
+++ b/tests/block_weight/compare.py
@@ -0,0 +1,13 @@
+#!/usr/bin/python
+
+import sys
+import subprocess
+
+print 'running: ', sys.argv[1]
+S0 = subprocess.check_output(sys.argv[1], stderr=subprocess.STDOUT)
+print 'running: ', sys.argv[2]
+S1 = subprocess.check_output(sys.argv[2], stderr=subprocess.STDOUT)
+print 'comparing'
+if S0 != S1:
+ sys.exit(1)
+sys.exit(0)
diff --git a/tests/core_proxy/CMakeLists.txt b/tests/core_proxy/CMakeLists.txt
index 105c20d22..9818d35d7 100644
--- a/tests/core_proxy/CMakeLists.txt
+++ b/tests/core_proxy/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/tests/core_proxy/core_proxy.cpp b/tests/core_proxy/core_proxy.cpp
index 17e552714..388808269 100644
--- a/tests/core_proxy/core_proxy.cpp
+++ b/tests/core_proxy/core_proxy.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -197,7 +197,7 @@ bool tests::proxy_core::handle_incoming_txs(const std::vector<blobdata>& tx_blob
return true;
}
-bool tests::proxy_core::handle_incoming_block(const cryptonote::blobdata& block_blob, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate) {
+bool tests::proxy_core::handle_incoming_block(const cryptonote::blobdata& block_blob, const cryptonote::block *block_, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate) {
block b = AUTO_VAL_INIT(b);
if(!parse_and_validate_block_from_blob(block_blob, b)) {
diff --git a/tests/core_proxy/core_proxy.h b/tests/core_proxy/core_proxy.h
index 7888540cc..6c8b3ccb6 100644
--- a/tests/core_proxy/core_proxy.h
+++ b/tests/core_proxy/core_proxy.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -77,7 +77,7 @@ namespace tests
void get_blockchain_top(uint64_t& height, crypto::hash& top_id);
bool handle_incoming_tx(const cryptonote::blobdata& tx_blob, cryptonote::tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay);
bool handle_incoming_txs(const std::vector<cryptonote::blobdata>& tx_blobs, std::vector<cryptonote::tx_verification_context>& tvc, bool keeped_by_block, bool relayed, bool do_not_relay);
- bool handle_incoming_block(const cryptonote::blobdata& block_blob, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate = true);
+ bool handle_incoming_block(const cryptonote::blobdata& block_blob, const cryptonote::block *block, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate = true);
void pause_mine(){}
void resume_mine(){}
bool on_idle(){return true;}
@@ -86,7 +86,7 @@ namespace tests
cryptonote::Blockchain &get_blockchain_storage() { throw std::runtime_error("Called invalid member function: please never call get_blockchain_storage on the TESTING class proxy_core."); }
bool get_test_drop_download() {return true;}
bool get_test_drop_download_height() {return true;}
- bool prepare_handle_incoming_blocks(const std::vector<cryptonote::block_complete_entry> &blocks) { return true; }
+ bool prepare_handle_incoming_blocks(const std::vector<cryptonote::block_complete_entry> &blocks_entry, std::vector<cryptonote::block> &blocks) { return true; }
bool cleanup_handle_incoming_blocks(bool force_sync = false) { return true; }
uint64_t get_target_blockchain_height() const { return 1; }
size_t get_block_sync_size(uint64_t height) const { return BLOCKS_SYNCHRONIZING_DEFAULT_COUNT; }
diff --git a/tests/core_tests/CMakeLists.txt b/tests/core_tests/CMakeLists.txt
index 1ac0e7864..f93cbf3ad 100644
--- a/tests/core_tests/CMakeLists.txt
+++ b/tests/core_tests/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
@@ -42,7 +42,8 @@ set(core_tests_sources
tx_validation.cpp
v2_tests.cpp
rct.cpp
- bulletproofs.cpp)
+ bulletproofs.cpp
+ wallet_tools.cpp)
set(core_tests_headers
block_reward.h
@@ -60,7 +61,8 @@ set(core_tests_headers
tx_validation.h
v2_tests.h
rct.h
- bulletproofs.h)
+ bulletproofs.h
+ wallet_tools.h)
add_executable(core_tests
${core_tests_sources}
@@ -73,6 +75,7 @@ target_link_libraries(core_tests
version
epee
device
+ wallet
${CMAKE_THREAD_LIBS_INIT}
${EXTRA_LIBRARIES})
enable_stack_trace(core_tests)
diff --git a/tests/core_tests/block_reward.cpp b/tests/core_tests/block_reward.cpp
index e55378439..17fc762ec 100644
--- a/tests/core_tests/block_reward.cpp
+++ b/tests/core_tests/block_reward.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/block_reward.h b/tests/core_tests/block_reward.h
index b7eb7c98e..6234bb9c5 100644
--- a/tests/core_tests/block_reward.h
+++ b/tests/core_tests/block_reward.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/block_validation.cpp b/tests/core_tests/block_validation.cpp
index 760cc4328..566ec1440 100644
--- a/tests/core_tests/block_validation.cpp
+++ b/tests/core_tests/block_validation.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/block_validation.h b/tests/core_tests/block_validation.h
index d229e4530..4a65b029e 100644
--- a/tests/core_tests/block_validation.h
+++ b/tests/core_tests/block_validation.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/bulletproofs.cpp b/tests/core_tests/bulletproofs.cpp
index 3e2db2e29..fd3f5114b 100644
--- a/tests/core_tests/bulletproofs.cpp
+++ b/tests/core_tests/bulletproofs.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/bulletproofs.h b/tests/core_tests/bulletproofs.h
index b0289f355..efc751df7 100644
--- a/tests/core_tests/bulletproofs.h
+++ b/tests/core_tests/bulletproofs.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/chain_split_1.cpp b/tests/core_tests/chain_split_1.cpp
index d78e793bb..c51accb67 100644
--- a/tests/core_tests/chain_split_1.cpp
+++ b/tests/core_tests/chain_split_1.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/chain_split_1.h b/tests/core_tests/chain_split_1.h
index 75602d1b0..503c3da19 100644
--- a/tests/core_tests/chain_split_1.h
+++ b/tests/core_tests/chain_split_1.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/chain_switch_1.cpp b/tests/core_tests/chain_switch_1.cpp
index 18a813b19..0554fd676 100644
--- a/tests/core_tests/chain_switch_1.cpp
+++ b/tests/core_tests/chain_switch_1.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/chain_switch_1.h b/tests/core_tests/chain_switch_1.h
index 989b6df11..c084de262 100644
--- a/tests/core_tests/chain_switch_1.h
+++ b/tests/core_tests/chain_switch_1.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp
index d3cb52246..09bc10ea8 100644
--- a/tests/core_tests/chaingen.cpp
+++ b/tests/core_tests/chaingen.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -31,6 +31,11 @@
#include <vector>
#include <iostream>
#include <sstream>
+#include <algorithm>
+#include <array>
+#include <random>
+#include <sstream>
+#include <fstream>
#include "include_base_utils.h"
@@ -105,10 +110,11 @@ void test_generator::add_block(const cryptonote::block& blk, size_t txs_weight,
bool test_generator::construct_block(cryptonote::block& blk, uint64_t height, const crypto::hash& prev_id,
const cryptonote::account_base& miner_acc, uint64_t timestamp, uint64_t already_generated_coins,
- std::vector<size_t>& block_weights, const std::list<cryptonote::transaction>& tx_list)
+ std::vector<size_t>& block_weights, const std::list<cryptonote::transaction>& tx_list,
+ const boost::optional<uint8_t>& hf_ver)
{
- blk.major_version = CURRENT_BLOCK_MAJOR_VERSION;
- blk.minor_version = CURRENT_BLOCK_MINOR_VERSION;
+ blk.major_version = hf_ver ? hf_ver.get() : CURRENT_BLOCK_MAJOR_VERSION;
+ blk.minor_version = hf_ver ? hf_ver.get() : CURRENT_BLOCK_MINOR_VERSION;
blk.timestamp = timestamp;
blk.prev_id = prev_id;
@@ -135,7 +141,7 @@ bool test_generator::construct_block(cryptonote::block& blk, uint64_t height, co
size_t target_block_weight = txs_weight + get_transaction_weight(blk.miner_tx);
while (true)
{
- if (!construct_miner_tx(height, misc_utils::median(block_weights), already_generated_coins, target_block_weight, total_fee, miner_acc.get_keys().m_account_address, blk.miner_tx, blobdata(), 10))
+ if (!construct_miner_tx(height, misc_utils::median(block_weights), already_generated_coins, target_block_weight, total_fee, miner_acc.get_keys().m_account_address, blk.miner_tx, blobdata(), 10, hf_ver ? hf_ver.get() : 1))
return false;
size_t actual_block_weight = txs_weight + get_transaction_weight(blk.miner_tx);
@@ -180,10 +186,10 @@ bool test_generator::construct_block(cryptonote::block& blk, uint64_t height, co
// Nonce search...
blk.nonce = 0;
- while (!miner::find_nonce_for_given_block(blk, get_test_difficulty(), height))
+ while (!miner::find_nonce_for_given_block(blk, get_test_difficulty(hf_ver), height))
blk.timestamp++;
- add_block(blk, txs_weight, block_weights, already_generated_coins);
+ add_block(blk, txs_weight, block_weights, already_generated_coins, hf_ver ? hf_ver.get() : 1);
return true;
}
@@ -197,17 +203,18 @@ bool test_generator::construct_block(cryptonote::block& blk, const cryptonote::a
bool test_generator::construct_block(cryptonote::block& blk, const cryptonote::block& blk_prev,
const cryptonote::account_base& miner_acc,
- const std::list<cryptonote::transaction>& tx_list/* = std::list<cryptonote::transaction>()*/)
+ const std::list<cryptonote::transaction>& tx_list/* = std::list<cryptonote::transaction>()*/,
+ const boost::optional<uint8_t>& hf_ver)
{
uint64_t height = boost::get<txin_gen>(blk_prev.miner_tx.vin.front()).height + 1;
crypto::hash prev_id = get_block_hash(blk_prev);
// Keep difficulty unchanged
- uint64_t timestamp = blk_prev.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN;
+ uint64_t timestamp = blk_prev.timestamp + current_difficulty_window(hf_ver); // DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN;
uint64_t already_generated_coins = get_already_generated_coins(prev_id);
std::vector<size_t> block_weights;
get_last_n_block_weights(block_weights, prev_id, CRYPTONOTE_REWARD_BLOCKS_WINDOW);
- return construct_block(blk, height, prev_id, miner_acc, timestamp, already_generated_coins, block_weights, tx_list);
+ return construct_block(blk, height, prev_id, miner_acc, timestamp, already_generated_coins, block_weights, tx_list, hf_ver);
}
bool test_generator::construct_block_manually(block& blk, const block& prev_block, const account_base& miner_acc,
@@ -244,7 +251,7 @@ bool test_generator::construct_block_manually(block& blk, const block& prev_bloc
//blk.tree_root_hash = get_tx_tree_hash(blk);
- difficulty_type a_diffic = actual_params & bf_diffic ? diffic : get_test_difficulty();
+ difficulty_type a_diffic = actual_params & bf_diffic ? diffic : get_test_difficulty(hf_version);
fill_nonce(blk, a_diffic, height);
add_block(blk, txs_weight, block_weights, already_generated_coins, hf_version);
@@ -259,49 +266,6 @@ bool test_generator::construct_block_manually_tx(cryptonote::block& blk, const c
return construct_block_manually(blk, prev_block, miner_acc, bf_tx_hashes, 0, 0, 0, crypto::hash(), 0, transaction(), tx_hashes, txs_weight);
}
-
-struct output_index {
- const cryptonote::txout_target_v out;
- uint64_t amount;
- size_t blk_height; // block height
- size_t tx_no; // index of transaction in block
- size_t out_no; // index of out in transaction
- size_t idx;
- bool spent;
- const cryptonote::block *p_blk;
- const cryptonote::transaction *p_tx;
-
- output_index(const cryptonote::txout_target_v &_out, uint64_t _a, size_t _h, size_t tno, size_t ono, const cryptonote::block *_pb, const cryptonote::transaction *_pt)
- : out(_out), amount(_a), blk_height(_h), tx_no(tno), out_no(ono), idx(0), spent(false), p_blk(_pb), p_tx(_pt) { }
-
- output_index(const output_index &other)
- : out(other.out), amount(other.amount), blk_height(other.blk_height), tx_no(other.tx_no), out_no(other.out_no), idx(other.idx), spent(other.spent), p_blk(other.p_blk), p_tx(other.p_tx) { }
-
- const std::string toString() const {
- std::stringstream ss;
-
- ss << "output_index{blk_height=" << blk_height
- << " tx_no=" << tx_no
- << " out_no=" << out_no
- << " amount=" << amount
- << " idx=" << idx
- << " spent=" << spent
- << "}";
-
- return ss.str();
- }
-
- output_index& operator=(const output_index& other)
- {
- new(this) output_index(other);
- return *this;
- }
-};
-
-typedef std::map<uint64_t, std::vector<size_t> > map_output_t;
-typedef std::map<uint64_t, std::vector<output_index> > map_output_idx_t;
-typedef pair<uint64_t, size_t> outloc_t;
-
namespace
{
uint64_t get_inputs_amount(const vector<tx_source_entry> &s)
@@ -339,6 +303,9 @@ bool init_output_indices(map_output_idx_t& outs, std::map<uint64_t, std::vector<
const tx_out &out = tx.vout[j];
output_index oi(out.target, out.amount, boost::get<txin_gen>(*blk.miner_tx.vin.begin()).height, i, j, &blk, vtx[i]);
+ oi.set_rct(tx.version == 2);
+ oi.unlock_time = tx.unlock_time;
+ oi.is_coin_base = i == 0;
if (2 == out.target.which()) { // out_to_key
outs[out.amount].push_back(oi);
@@ -416,8 +383,9 @@ bool fill_output_entries(std::vector<output_index>& out_indices, size_t sender_o
if (append)
{
+ rct::key comm = oi.commitment();
const txout_to_key& otk = boost::get<txout_to_key>(oi.out);
- output_entries.push_back(tx_source_entry::output_entry(oi.idx, rct::ctkey({rct::pk2rct(otk.key), rct::identity()})));
+ output_entries.push_back(tx_source_entry::output_entry(oi.idx, rct::ctkey({rct::pk2rct(otk.key), comm})));
}
}
@@ -452,6 +420,8 @@ bool fill_tx_sources(std::vector<tx_source_entry>& sources, const std::vector<te
const output_index& oi = outs[o.first][sender_out];
if (oi.spent)
continue;
+ if (oi.rct)
+ continue;
cryptonote::tx_source_entry ts;
ts.amount = oi.amount;
@@ -463,6 +433,11 @@ bool fill_tx_sources(std::vector<tx_source_entry>& sources, const std::vector<te
ts.real_output = realOutput;
ts.rct = false;
+ ts.mask = rct::identity(); // non-rct has identity mask by definition
+
+ rct::key comm = rct::zeroCommit(ts.amount);
+ for(auto & ot : ts.outputs)
+ ot.second.mask = comm;
sources.push_back(ts);
@@ -477,38 +452,347 @@ bool fill_tx_sources(std::vector<tx_source_entry>& sources, const std::vector<te
return sources_found;
}
-bool fill_tx_destination(tx_destination_entry &de, const cryptonote::account_base &to, uint64_t amount) {
- de.addr = to.get_keys().m_account_address;
+bool fill_tx_destination(tx_destination_entry &de, const cryptonote::account_public_address &to, uint64_t amount) {
+ de.addr = to;
de.amount = amount;
return true;
}
-void fill_tx_sources_and_destinations(const std::vector<test_event_entry>& events, const block& blk_head,
- const cryptonote::account_base& from, const cryptonote::account_base& to,
- uint64_t amount, uint64_t fee, size_t nmix, std::vector<tx_source_entry>& sources,
- std::vector<tx_destination_entry>& destinations)
+map_txid_output_t::iterator block_tracker::find_out(const crypto::hash &txid, size_t out)
+{
+ return find_out(std::make_pair(txid, out));
+}
+
+map_txid_output_t::iterator block_tracker::find_out(const output_hasher &id)
+{
+ return m_map_outs.find(id);
+}
+
+void block_tracker::process(const std::vector<cryptonote::block>& blockchain, const map_hash2tx_t& mtx)
+{
+ std::vector<const cryptonote::block*> blks;
+ blks.reserve(blockchain.size());
+
+ BOOST_FOREACH (const block& blk, blockchain) {
+ auto hsh = get_block_hash(blk);
+ auto it = m_blocks.find(hsh);
+ if (it == m_blocks.end()){
+ m_blocks[hsh] = blk;
+ }
+
+ blks.push_back(&m_blocks[hsh]);
+ }
+
+ process(blks, mtx);
+}
+
+void block_tracker::process(const std::vector<const cryptonote::block*>& blockchain, const map_hash2tx_t& mtx)
+{
+ BOOST_FOREACH (const block* blk, blockchain) {
+ vector<const transaction*> vtx;
+ vtx.push_back(&(blk->miner_tx));
+
+ BOOST_FOREACH(const crypto::hash &h, blk->tx_hashes) {
+ const map_hash2tx_t::const_iterator cit = mtx.find(h);
+ CHECK_AND_ASSERT_THROW_MES(mtx.end() != cit, "block contains an unknown tx hash");
+ vtx.push_back(cit->second);
+ }
+
+ for (size_t i = 0; i < vtx.size(); i++) {
+ process(blk, vtx[i], i);
+ }
+ }
+}
+
+void block_tracker::process(const block* blk, const transaction * tx, size_t i)
+{
+ for (size_t j = 0; j < tx->vout.size(); ++j) {
+ const tx_out &out = tx->vout[j];
+
+ if (typeid(cryptonote::txout_to_key) != out.target.type()) { // out_to_key
+ continue;
+ }
+
+ const uint64_t rct_amount = tx->version == 2 ? 0 : out.amount;
+ const output_hasher hid = std::make_pair(tx->hash, j);
+ auto it = find_out(hid);
+ if (it != m_map_outs.end()){
+ continue;
+ }
+
+ output_index oi(out.target, out.amount, boost::get<txin_gen>(blk->miner_tx.vin.front()).height, i, j, blk, tx);
+ oi.set_rct(tx->version == 2);
+ oi.idx = m_outs[rct_amount].size();
+ oi.unlock_time = tx->unlock_time;
+ oi.is_coin_base = tx->vin.size() == 1 && tx->vin.back().type() == typeid(cryptonote::txin_gen);
+
+ m_outs[rct_amount].push_back(oi);
+ m_map_outs.insert({hid, oi});
+ }
+}
+
+void block_tracker::global_indices(const cryptonote::transaction *tx, std::vector<uint64_t> &indices)
+{
+ indices.clear();
+
+ for(size_t j=0; j < tx->vout.size(); ++j){
+ auto it = find_out(tx->hash, j);
+ if (it != m_map_outs.end()){
+ indices.push_back(it->second.idx);
+ }
+ }
+}
+
+void block_tracker::get_fake_outs(size_t num_outs, uint64_t amount, uint64_t global_index, uint64_t cur_height, std::vector<get_outs_entry> &outs){
+ auto & vct = m_outs[amount];
+ const size_t n_outs = vct.size();
+
+ std::set<size_t> used;
+ std::vector<size_t> choices;
+ choices.resize(n_outs);
+ for(size_t i=0; i < n_outs; ++i) choices[i] = i;
+ shuffle(choices.begin(), choices.end(), std::default_random_engine(crypto::rand<unsigned>()));
+
+ size_t n_iters = 0;
+ ssize_t idx = -1;
+ outs.reserve(num_outs);
+ while(outs.size() < num_outs){
+ n_iters += 1;
+ idx = (idx + 1) % n_outs;
+ size_t oi_idx = choices[(size_t)idx];
+ CHECK_AND_ASSERT_THROW_MES((n_iters / n_outs) <= outs.size(), "Fake out pick selection problem");
+
+ auto & oi = vct[oi_idx];
+ if (oi.idx == global_index)
+ continue;
+ if (oi.out.type() != typeid(cryptonote::txout_to_key))
+ continue;
+ if (oi.unlock_time > cur_height)
+ continue;
+ if (used.find(oi_idx) != used.end())
+ continue;
+
+ rct::key comm = oi.commitment();
+ auto out = boost::get<txout_to_key>(oi.out);
+ auto item = std::make_tuple(oi.idx, out.key, comm);
+ outs.push_back(item);
+ used.insert(oi_idx);
+ }
+}
+
+std::string block_tracker::dump_data()
+{
+ ostringstream ss;
+ for (auto &m_out : m_outs)
+ {
+ auto & vct = m_out.second;
+ ss << m_out.first << " => |vector| = " << vct.size() << '\n';
+
+ for (const auto & oi : vct)
+ {
+ auto out = boost::get<txout_to_key>(oi.out);
+
+ ss << " idx: " << oi.idx
+ << ", rct: " << oi.rct
+ << ", xmr: " << oi.amount
+ << ", key: " << dump_keys(out.key.data)
+ << ", msk: " << dump_keys(oi.comm.bytes)
+ << ", txid: " << dump_keys(oi.p_tx->hash.data)
+ << '\n';
+ }
+ }
+
+ return ss.str();
+}
+
+void block_tracker::dump_data(const std::string & fname)
+{
+ ofstream myfile;
+ myfile.open (fname);
+ myfile << dump_data();
+ myfile.close();
+}
+
+std::string dump_data(const cryptonote::transaction &tx)
+{
+ ostringstream ss;
+ ss << "msg: " << dump_keys(tx.rct_signatures.message.bytes)
+ << ", vin: ";
+
+ for(auto & in : tx.vin){
+ if (typeid(txin_to_key) == in.type()){
+ auto tk = boost::get<txin_to_key>(in);
+ std::vector<uint64_t> full_off;
+ int64_t last = -1;
+
+ ss << " i: " << tk.amount << " [";
+ for(auto ix : tk.key_offsets){
+ ss << ix << ", ";
+ if (last == -1){
+ last = ix;
+ full_off.push_back(ix);
+ } else {
+ last += ix;
+ full_off.push_back((uint64_t)last);
+ }
+ }
+
+ ss << "], full: [";
+ for(auto ix : full_off){
+ ss << ix << ", ";
+ }
+ ss << "]; ";
+
+ } else if (typeid(txin_gen) == in.type()){
+ ss << " h: " << boost::get<txin_gen>(in).height << ", ";
+ } else {
+ ss << " ?, ";
+ }
+ }
+
+ ss << ", mixring: \n";
+ for (const auto & row : tx.rct_signatures.mixRing){
+ for(auto cur : row){
+ ss << " (" << dump_keys(cur.dest.bytes) << ", " << dump_keys(cur.mask.bytes) << ")\n ";
+ }
+ ss << "; ";
+ }
+
+ return ss.str();
+}
+
+cryptonote::account_public_address get_address(const var_addr_t& inp)
+{
+ if (typeid(cryptonote::account_public_address) == inp.type()){
+ return boost::get<cryptonote::account_public_address>(inp);
+ } else if(typeid(cryptonote::account_keys) == inp.type()){
+ return boost::get<cryptonote::account_keys>(inp).m_account_address;
+ } else if (typeid(cryptonote::account_base) == inp.type()){
+ return boost::get<cryptonote::account_base>(inp).get_keys().m_account_address;
+ } else if (typeid(cryptonote::tx_destination_entry) == inp.type()){
+ return boost::get<cryptonote::tx_destination_entry>(inp).addr;
+ } else {
+ throw std::runtime_error("Unexpected type");
+ }
+}
+
+cryptonote::account_public_address get_address(const cryptonote::account_public_address& inp)
+{
+ return inp;
+}
+
+cryptonote::account_public_address get_address(const cryptonote::account_keys& inp)
+{
+ return inp.m_account_address;
+}
+
+cryptonote::account_public_address get_address(const cryptonote::account_base& inp)
+{
+ return inp.get_keys().m_account_address;
+}
+
+cryptonote::account_public_address get_address(const cryptonote::tx_destination_entry& inp)
+{
+ return inp.addr;
+}
+
+uint64_t sum_amount(const std::vector<tx_destination_entry>& destinations)
+{
+ uint64_t amount = 0;
+ for(auto & cur : destinations){
+ amount += cur.amount;
+ }
+
+ return amount;
+}
+
+uint64_t sum_amount(const std::vector<cryptonote::tx_source_entry>& sources)
+{
+ uint64_t amount = 0;
+ for(auto & cur : sources){
+ amount += cur.amount;
+ }
+
+ return amount;
+}
+
+void fill_tx_destinations(const var_addr_t& from, const std::vector<tx_destination_entry>& dests,
+ uint64_t fee,
+ const std::vector<tx_source_entry> &sources,
+ std::vector<tx_destination_entry>& destinations,
+ bool always_change)
+
{
- sources.clear();
destinations.clear();
+ uint64_t amount = sum_amount(dests);
+ std::copy(dests.begin(), dests.end(), std::back_inserter(destinations));
- if (!fill_tx_sources(sources, events, blk_head, from, amount + fee, nmix))
- throw std::runtime_error("couldn't fill transaction sources");
+ tx_destination_entry de_change;
+ uint64_t cache_back = get_inputs_amount(sources) - (amount + fee);
+
+ if (cache_back > 0 || always_change) {
+ if (!fill_tx_destination(de_change, get_address(from), cache_back <= 0 ? 0 : cache_back))
+ throw std::runtime_error("couldn't fill transaction cache back destination");
+ destinations.push_back(de_change);
+ }
+}
+
+void fill_tx_destinations(const var_addr_t& from, const cryptonote::account_public_address& to,
+ uint64_t amount, uint64_t fee,
+ const std::vector<tx_source_entry> &sources,
+ std::vector<tx_destination_entry>& destinations,
+ std::vector<tx_destination_entry>& destinations_pure,
+ bool always_change)
+{
+ destinations.clear();
tx_destination_entry de;
if (!fill_tx_destination(de, to, amount))
throw std::runtime_error("couldn't fill transaction destination");
destinations.push_back(de);
+ destinations_pure.push_back(de);
tx_destination_entry de_change;
uint64_t cache_back = get_inputs_amount(sources) - (amount + fee);
- if (0 < cache_back)
- {
- if (!fill_tx_destination(de_change, from, cache_back))
+
+ if (cache_back > 0 || always_change) {
+ if (!fill_tx_destination(de_change, get_address(from), cache_back <= 0 ? 0 : cache_back))
throw std::runtime_error("couldn't fill transaction cache back destination");
destinations.push_back(de_change);
}
}
+void fill_tx_destinations(const var_addr_t& from, const cryptonote::account_public_address& to,
+ uint64_t amount, uint64_t fee,
+ const std::vector<tx_source_entry> &sources,
+ std::vector<tx_destination_entry>& destinations, bool always_change)
+{
+ std::vector<tx_destination_entry> destinations_pure;
+ fill_tx_destinations(from, to, amount, fee, sources, destinations, destinations_pure, always_change);
+}
+
+void fill_tx_sources_and_destinations(const std::vector<test_event_entry>& events, const block& blk_head,
+ const cryptonote::account_base& from, const cryptonote::account_public_address& to,
+ uint64_t amount, uint64_t fee, size_t nmix, std::vector<tx_source_entry>& sources,
+ std::vector<tx_destination_entry>& destinations)
+{
+ sources.clear();
+ destinations.clear();
+
+ if (!fill_tx_sources(sources, events, blk_head, from, amount + fee, nmix))
+ throw std::runtime_error("couldn't fill transaction sources");
+
+ fill_tx_destinations(from, to, amount, fee, sources, destinations, false);
+}
+
+void fill_tx_sources_and_destinations(const std::vector<test_event_entry>& events, const block& blk_head,
+ const cryptonote::account_base& from, const cryptonote::account_base& to,
+ uint64_t amount, uint64_t fee, size_t nmix, std::vector<tx_source_entry>& sources,
+ std::vector<tx_destination_entry>& destinations)
+{
+ fill_tx_sources_and_destinations(events, blk_head, from, to.get_keys().m_account_address, amount, fee, nmix, sources, destinations);
+}
+
void fill_nonce(cryptonote::block& blk, const difficulty_type& diffic, uint64_t height)
{
blk.nonce = 0;
@@ -516,6 +800,32 @@ void fill_nonce(cryptonote::block& blk, const difficulty_type& diffic, uint64_t
blk.timestamp++;
}
+cryptonote::tx_destination_entry build_dst(const var_addr_t& to, bool is_subaddr, uint64_t amount)
+{
+ tx_destination_entry de;
+ de.amount = amount;
+ de.addr = get_address(to);
+ de.is_subaddress = is_subaddr;
+ return de;
+}
+
+std::vector<cryptonote::tx_destination_entry> build_dsts(const var_addr_t& to1, bool sub1, uint64_t am1)
+{
+ std::vector<cryptonote::tx_destination_entry> res;
+ res.push_back(build_dst(to1, sub1, am1));
+ return res;
+}
+
+std::vector<cryptonote::tx_destination_entry> build_dsts(std::initializer_list<dest_wrapper_t> inps)
+{
+ std::vector<cryptonote::tx_destination_entry> res;
+ res.reserve(inps.size());
+ for(auto & c : inps){
+ res.push_back(build_dst(c.addr, c.is_subaddr, c.amount));
+ }
+ return res;
+}
+
bool construct_miner_tx_manually(size_t height, uint64_t already_generated_coins,
const account_public_address& miner_address, transaction& tx, uint64_t fee,
keypair* p_txkey/* = 0*/)
@@ -556,22 +866,70 @@ bool construct_miner_tx_manually(size_t height, uint64_t already_generated_coins
return true;
}
-bool construct_tx_to_key(const std::vector<test_event_entry>& events, cryptonote::transaction& tx, const block& blk_head,
- const cryptonote::account_base& from, const cryptonote::account_base& to, uint64_t amount,
- uint64_t fee, size_t nmix)
+bool construct_tx_to_key(const std::vector<test_event_entry>& events, cryptonote::transaction& tx, const cryptonote::block& blk_head,
+ const cryptonote::account_base& from, const var_addr_t& to, uint64_t amount,
+ uint64_t fee, size_t nmix, bool rct, rct::RangeProofType range_proof_type, int bp_version)
+{
+ vector<tx_source_entry> sources;
+ vector<tx_destination_entry> destinations;
+ fill_tx_sources_and_destinations(events, blk_head, from, get_address(to), amount, fee, nmix, sources, destinations);
+
+ 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);
+}
+
+bool construct_tx_to_key(const std::vector<test_event_entry>& events, cryptonote::transaction& tx, const cryptonote::block& blk_head,
+ const cryptonote::account_base& from, std::vector<cryptonote::tx_destination_entry> destinations,
+ uint64_t fee, size_t nmix, bool rct, rct::RangeProofType range_proof_type, int bp_version)
{
vector<tx_source_entry> sources;
+ vector<tx_destination_entry> destinations_all;
+ uint64_t amount = sum_amount(destinations);
+
+ if (!fill_tx_sources(sources, events, blk_head, from, amount + fee, nmix))
+ throw std::runtime_error("couldn't fill transaction sources");
+
+ 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);
+}
+
+bool construct_tx_to_key(cryptonote::transaction& tx,
+ const cryptonote::account_base& from, const var_addr_t& to, uint64_t amount,
+ std::vector<cryptonote::tx_source_entry> &sources,
+ uint64_t fee, bool rct, rct::RangeProofType range_proof_type, int bp_version)
+{
vector<tx_destination_entry> destinations;
- fill_tx_sources_and_destinations(events, blk_head, from, to, amount, fee, nmix, sources, 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);
+}
+
+bool construct_tx_to_key(cryptonote::transaction& tx,
+ const cryptonote::account_base& from,
+ const std::vector<cryptonote::tx_destination_entry>& destinations,
+ std::vector<cryptonote::tx_source_entry> &sources,
+ uint64_t fee, bool rct, rct::RangeProofType range_proof_type, int bp_version)
+{
+ 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(from.get_keys(), sources, destinations, from.get_keys().m_account_address, std::vector<uint8_t>(), tx, 0);
+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)
+{
+ 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;
+ 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, nullptr);
}
transaction construct_tx_with_fee(std::vector<test_event_entry>& events, const block& blk_head,
- const account_base& acc_from, const account_base& acc_to, uint64_t amount, uint64_t fee)
+ const account_base& acc_from, const var_addr_t& to, uint64_t amount, uint64_t fee)
{
transaction tx;
- construct_tx_to_key(events, tx, blk_head, acc_from, acc_to, amount, fee, 0);
+ construct_tx_to_key(events, tx, blk_head, acc_from, to, amount, fee, 0);
events.push_back(tx);
return tx;
}
@@ -602,6 +960,24 @@ uint64_t get_balance(const cryptonote::account_base& addr, const std::vector<cry
return res;
}
+bool extract_hard_forks(const std::vector<test_event_entry>& events, v_hardforks_t& hard_forks)
+{
+ for(auto & ev : events)
+ {
+ if (typeid(event_replay_settings) == ev.type())
+ {
+ const auto & rep_settings = boost::get<event_replay_settings>(ev);
+ if (rep_settings.hard_forks)
+ {
+ const auto & hf = rep_settings.hard_forks.get();
+ std::copy(hf.begin(), hf.end(), std::back_inserter(hard_forks));
+ }
+ }
+ }
+
+ return !hard_forks.empty();
+}
+
void get_confirmed_txs(const std::vector<cryptonote::block>& blockchain, const map_hash2tx_t& mtx, map_hash2tx_t& confirmed_txs)
{
std::unordered_set<crypto::hash> confirmed_hashes;
@@ -622,6 +998,74 @@ void get_confirmed_txs(const std::vector<cryptonote::block>& blockchain, const m
}
}
+bool trim_block_chain(std::vector<cryptonote::block>& blockchain, const crypto::hash& tail){
+ size_t cut = 0;
+ bool found = true;
+
+ for(size_t i = 0; i < blockchain.size(); ++i){
+ crypto::hash chash = get_block_hash(blockchain[i]);
+ if (chash == tail){
+ cut = i;
+ found = true;
+ break;
+ }
+ }
+
+ if (found && cut > 0){
+ blockchain.erase(blockchain.begin(), blockchain.begin() + cut);
+ }
+
+ return found;
+}
+
+bool trim_block_chain(std::vector<const cryptonote::block*>& blockchain, const crypto::hash& tail){
+ size_t cut = 0;
+ bool found = true;
+
+ for(size_t i = 0; i < blockchain.size(); ++i){
+ crypto::hash chash = get_block_hash(*blockchain[i]);
+ if (chash == tail){
+ cut = i;
+ found = true;
+ break;
+ }
+ }
+
+ if (found && cut > 0){
+ blockchain.erase(blockchain.begin(), blockchain.begin() + cut);
+ }
+
+ return found;
+}
+
+uint64_t num_blocks(const std::vector<test_event_entry>& events)
+{
+ uint64_t res = 0;
+ BOOST_FOREACH(const test_event_entry& ev, events)
+ {
+ if (typeid(block) == ev.type())
+ {
+ res += 1;
+ }
+ }
+
+ return res;
+}
+
+cryptonote::block get_head_block(const std::vector<test_event_entry>& events)
+{
+ for(auto it = events.rbegin(); it != events.rend(); ++it)
+ {
+ auto &ev = *it;
+ if (typeid(block) == ev.type())
+ {
+ return boost::get<block>(ev);
+ }
+ }
+
+ throw std::runtime_error("No block event");
+}
+
bool find_block_chain(const std::vector<test_event_entry>& events, std::vector<cryptonote::block>& blockchain, map_hash2tx_t& mtx, const crypto::hash& head) {
std::unordered_map<crypto::hash, const block*> block_index;
BOOST_FOREACH(const test_event_entry& ev, events)
@@ -655,6 +1099,38 @@ bool find_block_chain(const std::vector<test_event_entry>& events, std::vector<c
return b_success;
}
+bool find_block_chain(const std::vector<test_event_entry>& events, std::vector<const cryptonote::block*>& blockchain, map_hash2tx_t& mtx, const crypto::hash& head) {
+ std::unordered_map<crypto::hash, const block*> block_index;
+ BOOST_FOREACH(const test_event_entry& ev, events)
+ {
+ if (typeid(block) == ev.type())
+ {
+ const block* blk = &boost::get<block>(ev);
+ block_index[get_block_hash(*blk)] = blk;
+ }
+ else if (typeid(transaction) == ev.type())
+ {
+ const transaction& tx = boost::get<transaction>(ev);
+ mtx[get_transaction_hash(tx)] = &tx;
+ }
+ }
+
+ bool b_success = false;
+ crypto::hash id = head;
+ for (auto it = block_index.find(id); block_index.end() != it; it = block_index.find(id))
+ {
+ blockchain.push_back(it->second);
+ id = it->second->prev_id;
+ if (null_hash == id)
+ {
+ b_success = true;
+ break;
+ }
+ }
+ reverse(blockchain.begin(), blockchain.end());
+ return b_success;
+}
+
void test_chain_unit_base::register_callback(const std::string& cb_name, verify_callback cb)
{
diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h
index 907b32bcd..8bf5a9b08 100644
--- a/tests/core_tests/chaingen.h
+++ b/tests/core_tests/chaingen.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -37,8 +37,12 @@
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/program_options.hpp>
+#include <boost/optional.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/variant.hpp>
+#include <boost/serialization/optional.hpp>
+#include <boost/serialization/unordered_map.hpp>
+#include <boost/functional/hash.hpp>
#include "include_base_utils.h"
#include "common/boost_serialization_helper.h"
@@ -129,13 +133,32 @@ private:
}
};
+typedef std::vector<std::pair<uint8_t, uint64_t>> v_hardforks_t;
+struct event_replay_settings
+{
+ boost::optional<v_hardforks_t> hard_forks;
+
+ event_replay_settings() = default;
+
+private:
+ friend class boost::serialization::access;
+
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int /*version*/)
+ {
+ ar & hard_forks;
+ }
+};
+
+
VARIANT_TAG(binary_archive, callback_entry, 0xcb);
VARIANT_TAG(binary_archive, cryptonote::account_base, 0xcc);
VARIANT_TAG(binary_archive, serialized_block, 0xcd);
VARIANT_TAG(binary_archive, serialized_transaction, 0xce);
VARIANT_TAG(binary_archive, event_visitor_settings, 0xcf);
+VARIANT_TAG(binary_archive, event_replay_settings, 0xda);
-typedef boost::variant<cryptonote::block, cryptonote::transaction, std::vector<cryptonote::transaction>, cryptonote::account_base, callback_entry, serialized_block, serialized_transaction, event_visitor_settings> test_event_entry;
+typedef boost::variant<cryptonote::block, cryptonote::transaction, std::vector<cryptonote::transaction>, cryptonote::account_base, callback_entry, serialized_block, serialized_transaction, event_visitor_settings, event_replay_settings> test_event_entry;
typedef std::unordered_map<crypto::hash, const cryptonote::transaction*> map_hash2tx_t;
class test_chain_unit_base
@@ -173,6 +196,17 @@ public:
crypto::hash prev_id;
uint64_t already_generated_coins;
size_t block_weight;
+
+ private:
+ friend class boost::serialization::access;
+
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int /*version*/)
+ {
+ ar & prev_id;
+ ar & already_generated_coins;
+ ar & block_weight;
+ }
};
enum block_fields
@@ -189,6 +223,8 @@ public:
bf_hf_version= 1 << 8
};
+ test_generator() {}
+ test_generator(const test_generator &other): m_blocks_info(other.m_blocks_info) {}
void get_block_chain(std::vector<block_info>& blockchain, const crypto::hash& head, size_t n) const;
void get_last_n_block_weights(std::vector<size_t>& block_weights, const crypto::hash& head, size_t n) const;
uint64_t get_already_generated_coins(const crypto::hash& blk_id) const;
@@ -198,10 +234,12 @@ public:
uint8_t hf_version = 1);
bool construct_block(cryptonote::block& blk, uint64_t height, const crypto::hash& prev_id,
const cryptonote::account_base& miner_acc, uint64_t timestamp, uint64_t already_generated_coins,
- std::vector<size_t>& block_weights, const std::list<cryptonote::transaction>& tx_list);
+ std::vector<size_t>& block_weights, const std::list<cryptonote::transaction>& tx_list,
+ const boost::optional<uint8_t>& hf_ver = boost::none);
bool construct_block(cryptonote::block& blk, const cryptonote::account_base& miner_acc, uint64_t timestamp);
bool construct_block(cryptonote::block& blk, const cryptonote::block& blk_prev, const cryptonote::account_base& miner_acc,
- const std::list<cryptonote::transaction>& tx_list = std::list<cryptonote::transaction>());
+ const std::list<cryptonote::transaction>& tx_list = std::list<cryptonote::transaction>(),
+ const boost::optional<uint8_t>& hf_ver = boost::none);
bool construct_block_manually(cryptonote::block& blk, const cryptonote::block& prev_block,
const cryptonote::account_base& miner_acc, int actual_params = bf_none, uint8_t major_ver = 0,
@@ -214,30 +252,241 @@ public:
private:
std::unordered_map<crypto::hash, block_info> m_blocks_info;
+
+ friend class boost::serialization::access;
+
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int /*version*/)
+ {
+ ar & m_blocks_info;
+ }
};
-inline cryptonote::difficulty_type get_test_difficulty() {return 1;}
+template<typename T>
+std::string dump_keys(T * buff32)
+{
+ std::ostringstream ss;
+ char buff[10];
+
+ ss << "[";
+ for(int i = 0; i < 32; i++)
+ {
+ snprintf(buff, 10, "0x%02x", ((uint8_t)buff32[i] & 0xff));
+ ss << buff;
+ if (i < 31)
+ ss << ",";
+ }
+ ss << "]";
+ return ss.str();
+}
+
+struct output_index {
+ const cryptonote::txout_target_v out;
+ uint64_t amount;
+ size_t blk_height; // block height
+ size_t tx_no; // index of transaction in block
+ size_t out_no; // index of out in transaction
+ size_t idx;
+ uint64_t unlock_time;
+ bool is_coin_base;
+ bool spent;
+ bool rct;
+ rct::key comm;
+ const cryptonote::block *p_blk;
+ const cryptonote::transaction *p_tx;
+
+ output_index(const cryptonote::txout_target_v &_out, uint64_t _a, size_t _h, size_t tno, size_t ono, const cryptonote::block *_pb, const cryptonote::transaction *_pt)
+ : out(_out), amount(_a), blk_height(_h), tx_no(tno), out_no(ono), idx(0), unlock_time(0),
+ is_coin_base(false), spent(false), rct(false), p_blk(_pb), p_tx(_pt)
+ {
+
+ }
+
+ output_index(const output_index &other)
+ : out(other.out), amount(other.amount), blk_height(other.blk_height), tx_no(other.tx_no), rct(other.rct),
+ out_no(other.out_no), idx(other.idx), unlock_time(other.unlock_time), is_coin_base(other.is_coin_base),
+ spent(other.spent), comm(other.comm), p_blk(other.p_blk), p_tx(other.p_tx) { }
+
+ void set_rct(bool arct) {
+ rct = arct;
+ if (rct && p_tx->rct_signatures.outPk.size() > out_no)
+ comm = p_tx->rct_signatures.outPk[out_no].mask;
+ else
+ comm = rct::commit(amount, rct::identity());
+ }
+
+ rct::key commitment() const {
+ return comm;
+ }
+
+ const std::string toString() const {
+ std::stringstream ss;
+
+ ss << "output_index{blk_height=" << blk_height
+ << " tx_no=" << tx_no
+ << " out_no=" << out_no
+ << " amount=" << amount
+ << " idx=" << idx
+ << " unlock_time=" << unlock_time
+ << " spent=" << spent
+ << " is_coin_base=" << is_coin_base
+ << " rct=" << rct
+ << " comm=" << dump_keys(comm.bytes)
+ << "}";
+
+ return ss.str();
+ }
+
+ output_index& operator=(const output_index& other)
+ {
+ new(this) output_index(other);
+ return *this;
+ }
+};
+
+typedef std::tuple<uint64_t, crypto::public_key, rct::key> get_outs_entry;
+typedef std::pair<crypto::hash, size_t> output_hasher;
+typedef boost::hash<output_hasher> output_hasher_hasher;
+typedef std::map<uint64_t, std::vector<size_t> > map_output_t;
+typedef std::map<uint64_t, std::vector<output_index> > map_output_idx_t;
+typedef std::unordered_map<crypto::hash, cryptonote::block> map_block_t;
+typedef std::unordered_map<output_hasher, output_index, output_hasher_hasher> map_txid_output_t;
+typedef std::unordered_map<crypto::public_key, cryptonote::subaddress_index> subaddresses_t;
+typedef std::pair<uint64_t, size_t> outloc_t;
+
+typedef boost::variant<cryptonote::account_public_address, cryptonote::account_keys, cryptonote::account_base, cryptonote::tx_destination_entry> var_addr_t;
+typedef struct {
+ const var_addr_t addr;
+ bool is_subaddr;
+ uint64_t amount;
+} dest_wrapper_t;
+
+// Daemon functionality
+class block_tracker
+{
+public:
+ map_output_idx_t m_outs;
+ map_txid_output_t m_map_outs; // mapping (txid, out) -> output_index
+ map_block_t m_blocks;
+
+ block_tracker() = default;
+ block_tracker(const block_tracker &bt): m_outs(bt.m_outs), m_map_outs(bt.m_map_outs), m_blocks(bt.m_blocks) {};
+ map_txid_output_t::iterator find_out(const crypto::hash &txid, size_t out);
+ map_txid_output_t::iterator find_out(const output_hasher &id);
+ void process(const std::vector<cryptonote::block>& blockchain, const map_hash2tx_t& mtx);
+ void process(const std::vector<const cryptonote::block*>& blockchain, const map_hash2tx_t& mtx);
+ void process(const cryptonote::block* blk, const cryptonote::transaction * tx, size_t i);
+ void global_indices(const cryptonote::transaction *tx, std::vector<uint64_t> &indices);
+ void get_fake_outs(size_t num_outs, uint64_t amount, uint64_t global_index, uint64_t cur_height, std::vector<get_outs_entry> &outs);
+
+ std::string dump_data();
+ void dump_data(const std::string & fname);
+
+private:
+ friend class boost::serialization::access;
+
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int /*version*/)
+ {
+ ar & m_outs;
+ ar & m_map_outs;
+ ar & m_blocks;
+ }
+};
+
+std::string dump_data(const cryptonote::transaction &tx);
+cryptonote::account_public_address get_address(const var_addr_t& inp);
+cryptonote::account_public_address get_address(const cryptonote::account_public_address& inp);
+cryptonote::account_public_address get_address(const cryptonote::account_keys& inp);
+cryptonote::account_public_address get_address(const cryptonote::account_base& inp);
+cryptonote::account_public_address get_address(const cryptonote::tx_destination_entry& inp);
+
+inline cryptonote::difficulty_type get_test_difficulty(const boost::optional<uint8_t>& hf_ver=boost::none) {return !hf_ver || hf_ver.get() <= 1 ? 1 : 2;}
+inline uint64_t current_difficulty_window(const boost::optional<uint8_t>& hf_ver=boost::none){ return !hf_ver || hf_ver.get() <= 1 ? DIFFICULTY_TARGET_V1 : DIFFICULTY_TARGET_V2; }
void fill_nonce(cryptonote::block& blk, const cryptonote::difficulty_type& diffic, uint64_t height);
+cryptonote::tx_destination_entry build_dst(const var_addr_t& to, bool is_subaddr=false, uint64_t amount=0);
+std::vector<cryptonote::tx_destination_entry> build_dsts(const var_addr_t& to1, bool sub1=false, uint64_t am1=0);
+std::vector<cryptonote::tx_destination_entry> build_dsts(std::initializer_list<dest_wrapper_t> inps);
+uint64_t sum_amount(const std::vector<cryptonote::tx_destination_entry>& destinations);
+uint64_t sum_amount(const std::vector<cryptonote::tx_source_entry>& sources);
+
bool construct_miner_tx_manually(size_t height, uint64_t already_generated_coins,
const cryptonote::account_public_address& miner_address, cryptonote::transaction& tx,
- uint64_t fee, cryptonote::keypair* p_txkey = 0);
+ uint64_t fee, cryptonote::keypair* p_txkey = nullptr);
+
bool construct_tx_to_key(const std::vector<test_event_entry>& events, cryptonote::transaction& tx,
- const cryptonote::block& blk_head, const cryptonote::account_base& from, const cryptonote::account_base& to,
- uint64_t amount, uint64_t fee, size_t nmix);
+ const cryptonote::block& blk_head, const cryptonote::account_base& from, const var_addr_t& to, uint64_t amount,
+ uint64_t fee, size_t nmix, bool rct=false, rct::RangeProofType range_proof_type=rct::RangeProofBorromean, int bp_version = 0);
+
+bool construct_tx_to_key(const std::vector<test_event_entry>& events, cryptonote::transaction& tx, const cryptonote::block& blk_head,
+ const cryptonote::account_base& from, std::vector<cryptonote::tx_destination_entry> destinations,
+ uint64_t fee, size_t nmix, bool rct=false, rct::RangeProofType range_proof_type=rct::RangeProofBorromean, int bp_version = 0);
+
+bool construct_tx_to_key(cryptonote::transaction& tx, const cryptonote::account_base& from, const var_addr_t& to, uint64_t amount,
+ std::vector<cryptonote::tx_source_entry> &sources,
+ uint64_t fee, bool rct=false, rct::RangeProofType range_proof_type=rct::RangeProofBorromean, int bp_version = 0);
+
+bool construct_tx_to_key(cryptonote::transaction& tx, const cryptonote::account_base& from, const std::vector<cryptonote::tx_destination_entry>& destinations,
+ std::vector<cryptonote::tx_source_entry> &sources,
+ uint64_t fee, bool rct, rct::RangeProofType range_proof_type, int bp_version = 0);
+
cryptonote::transaction construct_tx_with_fee(std::vector<test_event_entry>& events, const cryptonote::block& blk_head,
- const cryptonote::account_base& acc_from, const cryptonote::account_base& acc_to,
+ const cryptonote::account_base& acc_from, const var_addr_t& to,
uint64_t amount, uint64_t fee);
+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=false, rct::RangeProofType range_proof_type=rct::RangeProofBorromean, int bp_version = 0);
+
+
+uint64_t num_blocks(const std::vector<test_event_entry>& events);
+cryptonote::block get_head_block(const std::vector<test_event_entry>& events);
+
void get_confirmed_txs(const std::vector<cryptonote::block>& blockchain, const map_hash2tx_t& mtx, map_hash2tx_t& confirmed_txs);
+bool trim_block_chain(std::vector<cryptonote::block>& blockchain, const crypto::hash& tail);
+bool trim_block_chain(std::vector<const cryptonote::block*>& blockchain, const crypto::hash& tail);
bool find_block_chain(const std::vector<test_event_entry>& events, std::vector<cryptonote::block>& blockchain, map_hash2tx_t& mtx, const crypto::hash& head);
+bool find_block_chain(const std::vector<test_event_entry>& events, std::vector<const cryptonote::block*>& blockchain, map_hash2tx_t& mtx, const crypto::hash& head);
+
+void fill_tx_destinations(const var_addr_t& from, const cryptonote::account_public_address& to,
+ uint64_t amount, uint64_t fee,
+ const std::vector<cryptonote::tx_source_entry> &sources,
+ std::vector<cryptonote::tx_destination_entry>& destinations, bool always_change=false);
+
+void fill_tx_destinations(const var_addr_t& from, const std::vector<cryptonote::tx_destination_entry>& dests,
+ uint64_t fee,
+ const std::vector<cryptonote::tx_source_entry> &sources,
+ std::vector<cryptonote::tx_destination_entry>& destinations,
+ bool always_change);
+
+void fill_tx_destinations(const var_addr_t& from, const cryptonote::account_public_address& to,
+ uint64_t amount, uint64_t fee,
+ const std::vector<cryptonote::tx_source_entry> &sources,
+ std::vector<cryptonote::tx_destination_entry>& destinations,
+ std::vector<cryptonote::tx_destination_entry>& destinations_pure,
+ bool always_change=false);
+
+
+void fill_tx_sources_and_destinations(const std::vector<test_event_entry>& events, const cryptonote::block& blk_head,
+ const cryptonote::account_base& from, const cryptonote::account_public_address& to,
+ uint64_t amount, uint64_t fee, size_t nmix,
+ std::vector<cryptonote::tx_source_entry>& sources,
+ std::vector<cryptonote::tx_destination_entry>& destinations);
+
void fill_tx_sources_and_destinations(const std::vector<test_event_entry>& events, const cryptonote::block& blk_head,
const cryptonote::account_base& from, const cryptonote::account_base& to,
uint64_t amount, uint64_t fee, size_t nmix,
std::vector<cryptonote::tx_source_entry>& sources,
std::vector<cryptonote::tx_destination_entry>& destinations);
+
uint64_t get_balance(const cryptonote::account_base& addr, const std::vector<cryptonote::block>& blockchain, const map_hash2tx_t& mtx);
+bool extract_hard_forks(const std::vector<test_event_entry>& events, v_hardforks_t& hard_forks);
+
//--------------------------------------------------------------------------
template<class t_test_class>
auto do_check_tx_verification_context(const cryptonote::tx_verification_context& tvc, bool tx_added, size_t event_index, const cryptonote::transaction& tx, t_test_class& validator, int)
@@ -338,6 +587,12 @@ public:
m_ev_index = ev_index;
}
+ bool operator()(const event_replay_settings& settings)
+ {
+ log_event("event_replay_settings");
+ return true;
+ }
+
bool operator()(const event_visitor_settings& settings)
{
log_event("event_visitor_settings");
@@ -388,7 +643,7 @@ public:
log_event("cryptonote::block");
cryptonote::block_verification_context bvc = AUTO_VAL_INIT(bvc);
- m_c.handle_incoming_block(t_serializable_object_to_blob(b), bvc);
+ m_c.handle_incoming_block(t_serializable_object_to_blob(b), &b, bvc);
bool r = check_block_verification_context(bvc, m_ev_index, b, m_validator);
CHECK_AND_NO_ASSERT_MES(r, false, "block verification context check failed");
return r;
@@ -411,7 +666,7 @@ public:
log_event("serialized_block");
cryptonote::block_verification_context bvc = AUTO_VAL_INIT(bvc);
- m_c.handle_incoming_block(sr_block.data, bvc);
+ m_c.handle_incoming_block(sr_block.data, NULL, bvc);
cryptonote::block blk;
std::stringstream ss;
@@ -461,12 +716,20 @@ private:
template<class t_test_class>
inline bool replay_events_through_core(cryptonote::core& cr, const std::vector<test_event_entry>& events, t_test_class& validator)
{
+ return replay_events_through_core_plain(cr, events, validator, true);
+}
+//--------------------------------------------------------------------------
+template<class t_test_class>
+inline bool replay_events_through_core_plain(cryptonote::core& cr, const std::vector<test_event_entry>& events, t_test_class& validator, bool reinit=true)
+{
TRY_ENTRY();
//init core here
-
- CHECK_AND_ASSERT_MES(typeid(cryptonote::block) == events[0].type(), false, "First event must be genesis block creation");
- cr.set_genesis_block(boost::get<cryptonote::block>(events[0]));
+ if (reinit) {
+ CHECK_AND_ASSERT_MES(typeid(cryptonote::block) == events[0].type(), false,
+ "First event must be genesis block creation");
+ cr.set_genesis_block(boost::get<cryptonote::block>(events[0]));
+ }
bool r = true;
push_core_event_visitor<t_test_class> visitor(cr, events, validator);
@@ -489,10 +752,9 @@ struct get_test_options {
};
get_test_options():hard_forks{std::make_pair((uint8_t)1, (uint64_t)0), std::make_pair((uint8_t)0, (uint64_t)0)}{}
};
-
//--------------------------------------------------------------------------
template<class t_test_class>
-inline bool do_replay_events(std::vector<test_event_entry>& events)
+inline bool do_replay_events_get_core(std::vector<test_event_entry>& events, cryptonote::core **core)
{
boost::program_options::options_description desc("Allowed options");
cryptonote::core::init_options(desc);
@@ -506,12 +768,24 @@ inline bool do_replay_events(std::vector<test_event_entry>& events)
if (!r)
return false;
- cryptonote::cryptonote_protocol_stub pr; //TODO: stub only for this kind of test, make real validation of relayed objects
- cryptonote::core c(&pr);
+ *core = new cryptonote::core(nullptr);
+ auto & c = **core;
+
// FIXME: make sure that vm has arg_testnet_on set to true or false if
// this test needs for it to be so.
get_test_options<t_test_class> gto;
- if (!c.init(vm, &gto.test_options))
+
+ // Hardforks can be specified in events.
+ v_hardforks_t hardforks;
+ cryptonote::test_options test_options_tmp{};
+ const cryptonote::test_options * test_options_ = &gto.test_options;
+ if (extract_hard_forks(events, hardforks)){
+ hardforks.push_back(std::make_pair((uint8_t)0, (uint64_t)0)); // terminator
+ test_options_tmp.hard_forks = hardforks.data();
+ test_options_ = &test_options_tmp;
+ }
+
+ if (!c.init(vm, test_options_))
{
MERROR("Failed to init core");
return false;
@@ -529,7 +803,31 @@ inline bool do_replay_events(std::vector<test_event_entry>& events)
t_test_class validator;
bool ret = replay_events_through_core<t_test_class>(c, events, validator);
- c.deinit();
+// c.deinit();
+ return ret;
+}
+//--------------------------------------------------------------------------
+template<class t_test_class>
+inline bool replay_events_through_core_validate(std::vector<test_event_entry>& events, cryptonote::core & c)
+{
+ std::vector<crypto::hash> pool_txs;
+ if (!c.get_pool_transaction_hashes(pool_txs))
+ {
+ MERROR("Failed to flush txpool");
+ return false;
+ }
+ c.get_blockchain_storage().flush_txes_from_pool(pool_txs);
+
+ t_test_class validator;
+ return replay_events_through_core_plain<t_test_class>(c, events, validator, false);
+}
+//--------------------------------------------------------------------------
+template<class t_test_class>
+inline bool do_replay_events(std::vector<test_event_entry>& events)
+{
+ cryptonote::core * core;
+ bool ret = do_replay_events_get_core<t_test_class>(events, &core);
+ core->deinit();
return ret;
}
//--------------------------------------------------------------------------
@@ -546,6 +844,12 @@ inline bool do_replay_file(const std::string& filename)
}
//--------------------------------------------------------------------------
+#define DEFAULT_HARDFORKS(HARDFORKS) do { \
+ HARDFORKS.push_back(std::make_pair((uint8_t)1, (uint64_t)0)); \
+} while(0)
+
+#define ADD_HARDFORK(HARDFORKS, FORK, HEIGHT) HARDFORKS.push_back(std::make_pair((uint8_t)FORK, (uint64_t)HEIGHT))
+
#define GENERATE_ACCOUNT(account) \
cryptonote::account_base account; \
account.generate();
@@ -589,6 +893,11 @@ inline bool do_replay_file(const std::string& filename)
generator.construct_block(BLK_NAME, PREV_BLOCK, MINER_ACC); \
VEC_EVENTS.push_back(BLK_NAME);
+#define MAKE_NEXT_BLOCK_HF(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, HF) \
+ cryptonote::block BLK_NAME; \
+ generator.construct_block(BLK_NAME, PREV_BLOCK, MINER_ACC, std::list<cryptonote::transaction>(), HF); \
+ VEC_EVENTS.push_back(BLK_NAME);
+
#define MAKE_NEXT_BLOCK_TX1(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, TX1) \
cryptonote::block BLK_NAME; \
{ \
@@ -598,46 +907,91 @@ inline bool do_replay_file(const std::string& filename)
} \
VEC_EVENTS.push_back(BLK_NAME);
+#define MAKE_NEXT_BLOCK_TX1_HF(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, TX1, HF) \
+ cryptonote::block BLK_NAME; \
+ { \
+ std::list<cryptonote::transaction> tx_list; \
+ tx_list.push_back(TX1); \
+ generator.construct_block(BLK_NAME, PREV_BLOCK, MINER_ACC, tx_list, HF); \
+ } \
+ VEC_EVENTS.push_back(BLK_NAME);
+
#define MAKE_NEXT_BLOCK_TX_LIST(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, TXLIST) \
cryptonote::block BLK_NAME; \
generator.construct_block(BLK_NAME, PREV_BLOCK, MINER_ACC, TXLIST); \
VEC_EVENTS.push_back(BLK_NAME);
-#define REWIND_BLOCKS_N(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, COUNT) \
+#define MAKE_NEXT_BLOCK_TX_LIST_HF(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, TXLIST, HF) \
cryptonote::block BLK_NAME; \
+ generator.construct_block(BLK_NAME, PREV_BLOCK, MINER_ACC, TXLIST, HF); \
+ VEC_EVENTS.push_back(BLK_NAME);
+
+#define REWIND_BLOCKS_N_HF(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, COUNT, HF) \
+ cryptonote::block BLK_NAME; \
{ \
- cryptonote::block blk_last = PREV_BLOCK; \
+ cryptonote::block blk_last = PREV_BLOCK; \
for (size_t i = 0; i < COUNT; ++i) \
{ \
- MAKE_NEXT_BLOCK(VEC_EVENTS, blk, blk_last, MINER_ACC); \
+ MAKE_NEXT_BLOCK_HF(VEC_EVENTS, blk, blk_last, MINER_ACC, HF); \
blk_last = blk; \
} \
BLK_NAME = blk_last; \
}
+#define REWIND_BLOCKS_N(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, COUNT) REWIND_BLOCKS_N_HF(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, COUNT, boost::none)
#define REWIND_BLOCKS(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC) REWIND_BLOCKS_N(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW)
+#define REWIND_BLOCKS_HF(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, HF) REWIND_BLOCKS_N_HF(VEC_EVENTS, BLK_NAME, PREV_BLOCK, MINER_ACC, CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW, HF)
#define MAKE_TX_MIX(VEC_EVENTS, TX_NAME, FROM, TO, AMOUNT, NMIX, HEAD) \
cryptonote::transaction TX_NAME; \
construct_tx_to_key(VEC_EVENTS, TX_NAME, HEAD, FROM, TO, AMOUNT, TESTS_DEFAULT_FEE, NMIX); \
VEC_EVENTS.push_back(TX_NAME);
+#define MAKE_TX_MIX_RCT(VEC_EVENTS, TX_NAME, FROM, TO, AMOUNT, NMIX, HEAD) \
+ cryptonote::transaction TX_NAME; \
+ construct_tx_to_key(VEC_EVENTS, TX_NAME, HEAD, FROM, TO, AMOUNT, TESTS_DEFAULT_FEE, NMIX, true, rct::RangeProofPaddedBulletproof); \
+ VEC_EVENTS.push_back(TX_NAME);
+
#define MAKE_TX(VEC_EVENTS, TX_NAME, FROM, TO, AMOUNT, HEAD) MAKE_TX_MIX(VEC_EVENTS, TX_NAME, FROM, TO, AMOUNT, 0, HEAD)
#define MAKE_TX_MIX_LIST(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, NMIX, HEAD) \
{ \
- cryptonote::transaction t; \
+ cryptonote::transaction t; \
construct_tx_to_key(VEC_EVENTS, t, HEAD, FROM, TO, AMOUNT, TESTS_DEFAULT_FEE, NMIX); \
SET_NAME.push_back(t); \
VEC_EVENTS.push_back(t); \
}
+#define MAKE_TX_MIX_LIST_RCT(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, NMIX, HEAD) \
+ MAKE_TX_MIX_LIST_RCT_EX(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, NMIX, HEAD, rct::RangeProofPaddedBulletproof, 1)
+#define MAKE_TX_MIX_LIST_RCT_EX(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, NMIX, HEAD, RCT_TYPE, BP_VER) \
+ { \
+ cryptonote::transaction t; \
+ construct_tx_to_key(VEC_EVENTS, t, HEAD, FROM, TO, AMOUNT, TESTS_DEFAULT_FEE, NMIX, true, RCT_TYPE, BP_VER); \
+ SET_NAME.push_back(t); \
+ VEC_EVENTS.push_back(t); \
+ }
+
+#define MAKE_TX_MIX_DEST_LIST_RCT(VEC_EVENTS, SET_NAME, FROM, TO, NMIX, HEAD) \
+ MAKE_TX_MIX_DEST_LIST_RCT_EX(VEC_EVENTS, SET_NAME, FROM, TO, NMIX, HEAD, rct::RangeProofPaddedBulletproof, 1)
+#define MAKE_TX_MIX_DEST_LIST_RCT_EX(VEC_EVENTS, SET_NAME, FROM, TO, NMIX, HEAD, RCT_TYPE, BP_VER) \
+ { \
+ cryptonote::transaction t; \
+ construct_tx_to_key(VEC_EVENTS, t, HEAD, FROM, TO, TESTS_DEFAULT_FEE, NMIX, true, RCT_TYPE, BP_VER); \
+ SET_NAME.push_back(t); \
+ VEC_EVENTS.push_back(t); \
+ }
+
#define MAKE_TX_LIST(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, HEAD) MAKE_TX_MIX_LIST(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, 0, HEAD)
#define MAKE_TX_LIST_START(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, HEAD) \
std::list<cryptonote::transaction> SET_NAME; \
MAKE_TX_LIST(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, HEAD);
+#define MAKE_TX_LIST_START_RCT(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, NMIX, HEAD) \
+ std::list<cryptonote::transaction> SET_NAME; \
+ MAKE_TX_MIX_LIST_RCT(VEC_EVENTS, SET_NAME, FROM, TO, AMOUNT, NMIX, HEAD);
+
#define MAKE_MINER_TX_AND_KEY_MANUALLY(TX, BLK, KEY) \
transaction TX; \
if (!construct_miner_tx_manually(get_block_height(BLK) + 1, generator.get_already_generated_coins(BLK), \
@@ -668,19 +1022,7 @@ inline bool do_replay_file(const std::string& filename)
return 1; \
}
-#define GENERATE_AND_PLAY(genclass) \
- if (list_tests) \
- std::cout << #genclass << std::endl; \
- else if (filter.empty() || boost::regex_match(std::string(#genclass), match, boost::regex(filter))) \
- { \
- std::vector<test_event_entry> events; \
- ++tests_count; \
- bool generated = false; \
- try \
- { \
- genclass g; \
- generated = g.generate(events);; \
- } \
+#define CATCH_REPLAY(genclass) \
catch (const std::exception& ex) \
{ \
MERROR(#genclass << " generation failed: what=" << ex.what()); \
@@ -688,7 +1030,9 @@ inline bool do_replay_file(const std::string& filename)
catch (...) \
{ \
MERROR(#genclass << " generation failed: generic exception"); \
- } \
+ }
+
+#define REPLAY_CORE(genclass) \
if (generated && do_replay_events< genclass >(events)) \
{ \
MGINFO_GREEN("#TEST# Succeeded " << #genclass); \
@@ -697,7 +1041,54 @@ inline bool do_replay_file(const std::string& filename)
{ \
MERROR("#TEST# Failed " << #genclass); \
failed_tests.push_back(#genclass); \
+ }
+
+#define REPLAY_WITH_CORE(genclass, CORE) \
+ if (generated && replay_events_through_core_validate< genclass >(events, CORE)) \
+ { \
+ MGINFO_GREEN("#TEST# Succeeded " << #genclass); \
+ } \
+ else \
+ { \
+ MERROR("#TEST# Failed " << #genclass); \
+ failed_tests.push_back(#genclass); \
+ }
+
+#define CATCH_GENERATE_REPLAY(genclass) \
+ CATCH_REPLAY(genclass); \
+ REPLAY_CORE(genclass);
+
+#define CATCH_GENERATE_REPLAY_CORE(genclass, CORE) \
+ CATCH_REPLAY(genclass); \
+ REPLAY_WITH_CORE(genclass, CORE);
+
+#define GENERATE_AND_PLAY(genclass) \
+ if (list_tests) \
+ std::cout << #genclass << std::endl; \
+ else if (filter.empty() || boost::regex_match(std::string(#genclass), match, boost::regex(filter))) \
+ { \
+ std::vector<test_event_entry> events; \
+ ++tests_count; \
+ bool generated = false; \
+ try \
+ { \
+ genclass g; \
+ generated = g.generate(events); \
+ } \
+ CATCH_GENERATE_REPLAY(genclass); \
+ }
+
+#define GENERATE_AND_PLAY_INSTANCE(genclass, ins, CORE) \
+ if (filter.empty() || boost::regex_match(std::string(#genclass), match, boost::regex(filter))) \
+ { \
+ std::vector<test_event_entry> events; \
+ ++tests_count; \
+ bool generated = false; \
+ try \
+ { \
+ generated = ins.generate(events); \
} \
+ CATCH_GENERATE_REPLAY_CORE(genclass, CORE); \
}
#define CALL_TEST(test_name, function) \
diff --git a/tests/core_tests/chaingen001.cpp b/tests/core_tests/chaingen001.cpp
index a76cf1592..b313f4821 100644
--- a/tests/core_tests/chaingen001.cpp
+++ b/tests/core_tests/chaingen001.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp
index 71b8c4463..cb35cfde2 100644
--- a/tests/core_tests/chaingen_main.cpp
+++ b/tests/core_tests/chaingen_main.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/chaingen_tests_list.h b/tests/core_tests/chaingen_tests_list.h
index c12e97f95..cf20c725c 100644
--- a/tests/core_tests/chaingen_tests_list.h
+++ b/tests/core_tests/chaingen_tests_list.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/double_spend.cpp b/tests/core_tests/double_spend.cpp
index c60ea885e..afd212b27 100644
--- a/tests/core_tests/double_spend.cpp
+++ b/tests/core_tests/double_spend.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/double_spend.h b/tests/core_tests/double_spend.h
index 276e74853..70d9f84b9 100644
--- a/tests/core_tests/double_spend.h
+++ b/tests/core_tests/double_spend.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/double_spend.inl b/tests/core_tests/double_spend.inl
index d02147065..600899b6f 100644
--- a/tests/core_tests/double_spend.inl
+++ b/tests/core_tests/double_spend.inl
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/integer_overflow.cpp b/tests/core_tests/integer_overflow.cpp
index e7e1ac9ca..42df4aa3b 100644
--- a/tests/core_tests/integer_overflow.cpp
+++ b/tests/core_tests/integer_overflow.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/integer_overflow.h b/tests/core_tests/integer_overflow.h
index eaca268e4..75a60eb15 100644
--- a/tests/core_tests/integer_overflow.h
+++ b/tests/core_tests/integer_overflow.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/multisig.cpp b/tests/core_tests/multisig.cpp
index 37fda6643..e0c90423d 100644
--- a/tests/core_tests/multisig.cpp
+++ b/tests/core_tests/multisig.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/multisig.h b/tests/core_tests/multisig.h
index e0d227840..1e8226d26 100644
--- a/tests/core_tests/multisig.h
+++ b/tests/core_tests/multisig.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/rct.cpp b/tests/core_tests/rct.cpp
index bb7dd013b..248354177 100644
--- a/tests/core_tests/rct.cpp
+++ b/tests/core_tests/rct.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/rct.h b/tests/core_tests/rct.h
index 641f3dd5e..72460d98e 100644
--- a/tests/core_tests/rct.h
+++ b/tests/core_tests/rct.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/ring_signature_1.cpp b/tests/core_tests/ring_signature_1.cpp
index 8b2b943cc..eb5ee48ec 100644
--- a/tests/core_tests/ring_signature_1.cpp
+++ b/tests/core_tests/ring_signature_1.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/ring_signature_1.h b/tests/core_tests/ring_signature_1.h
index 7ff6cfd96..256f5732b 100644
--- a/tests/core_tests/ring_signature_1.h
+++ b/tests/core_tests/ring_signature_1.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/transaction_tests.cpp b/tests/core_tests/transaction_tests.cpp
index 810dec6fc..14028b5be 100644
--- a/tests/core_tests/transaction_tests.cpp
+++ b/tests/core_tests/transaction_tests.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/transaction_tests.h b/tests/core_tests/transaction_tests.h
index 9500c66f6..eac2c3479 100644
--- a/tests/core_tests/transaction_tests.h
+++ b/tests/core_tests/transaction_tests.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/tx_validation.cpp b/tests/core_tests/tx_validation.cpp
index f0a385ee5..232c86482 100644
--- a/tests/core_tests/tx_validation.cpp
+++ b/tests/core_tests/tx_validation.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/tx_validation.h b/tests/core_tests/tx_validation.h
index 01a258a20..8d457cdb5 100644
--- a/tests/core_tests/tx_validation.h
+++ b/tests/core_tests/tx_validation.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/v2_tests.cpp b/tests/core_tests/v2_tests.cpp
index b96c744b3..8c2b51acf 100644
--- a/tests/core_tests/v2_tests.cpp
+++ b/tests/core_tests/v2_tests.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/core_tests/v2_tests.h b/tests/core_tests/v2_tests.h
index ecb23818c..71b0f0e83 100644
--- a/tests/core_tests/v2_tests.h
+++ b/tests/core_tests/v2_tests.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -81,7 +81,7 @@ template<>
struct get_test_options<gen_v2_tx_validation_base> {
const std::pair<uint8_t, uint64_t> hard_forks[3] = {std::make_pair(1, 0), std::make_pair(2, 1), std::make_pair(0, 0)};
const cryptonote::test_options test_options = {
- hard_forks
+ hard_forks, 0
};
};
diff --git a/tests/core_tests/wallet_tools.cpp b/tests/core_tests/wallet_tools.cpp
new file mode 100644
index 000000000..ff7ce3a34
--- /dev/null
+++ b/tests/core_tests/wallet_tools.cpp
@@ -0,0 +1,287 @@
+//
+// Created by Dusan Klinec on 2019-02-28.
+//
+
+#include "wallet_tools.h"
+#include <random>
+
+using namespace std;
+using namespace epee;
+using namespace crypto;
+using namespace cryptonote;
+
+// Shared random generator
+static std::default_random_engine RND(crypto::rand<unsigned>());
+
+void wallet_accessor_test::set_account(tools::wallet2 * wallet, cryptonote::account_base& account)
+{
+ wallet->clear();
+ wallet->m_account = account;
+ wallet->m_nettype = MAINNET;
+
+ wallet->m_key_device_type = account.get_device().get_type();
+ wallet->m_account_public_address = account.get_keys().m_account_address;
+ wallet->m_watch_only = false;
+ wallet->m_multisig = false;
+ wallet->m_multisig_threshold = 0;
+ wallet->m_multisig_signers.clear();
+ wallet->m_device_name = account.get_device().get_name();
+
+ wallet->m_subaddress_lookahead_major = 5;
+ wallet->m_subaddress_lookahead_minor = 20;
+
+ wallet->setup_new_blockchain(); // generates also subadress register
+}
+
+void wallet_accessor_test::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)
+{
+ wallet->process_parsed_blocks(start_height, blocks, parsed_blocks, blocks_added);
+}
+
+void wallet_tools::process_transactions(tools::wallet2 * wallet, const std::vector<test_event_entry>& events, const cryptonote::block& blk_head, block_tracker &bt, const boost::optional<crypto::hash>& blk_tail)
+{
+ map_hash2tx_t mtx;
+ std::vector<const cryptonote::block*> blockchain;
+ find_block_chain(events, blockchain, mtx, get_block_hash(blk_head));
+
+ if (blk_tail){
+ trim_block_chain(blockchain, blk_tail.get());
+ }
+
+ process_transactions(wallet, blockchain, mtx, bt);
+}
+
+void wallet_tools::process_transactions(tools::wallet2 * wallet, const std::vector<const cryptonote::block*>& blockchain, const map_hash2tx_t & mtx, block_tracker &bt)
+{
+ uint64_t start_height=0, blocks_added=0;
+ std::vector<cryptonote::block_complete_entry> v_bche;
+ std::vector<tools::wallet2::parsed_block> v_parsed_block;
+
+ v_bche.reserve(blockchain.size());
+ v_parsed_block.reserve(blockchain.size());
+
+ size_t idx = 0;
+ for(auto bl : blockchain)
+ {
+ idx += 1;
+ uint64_t height;
+ v_bche.emplace_back();
+ v_parsed_block.emplace_back();
+
+ wallet_tools::gen_block_data(bt, bl, mtx, v_bche.back(), v_parsed_block.back(), idx == 1 ? start_height : height);
+ }
+
+ if (wallet)
+ wallet_accessor_test::process_parsed_blocks(wallet, start_height, v_bche, v_parsed_block, blocks_added);
+}
+
+bool wallet_tools::fill_tx_sources(tools::wallet2 * wallet, std::vector<cryptonote::tx_source_entry>& sources, size_t mixin, const boost::optional<size_t>& num_utxo, const boost::optional<uint64_t>& min_amount, block_tracker &bt, std::vector<size_t> &selected, uint64_t cur_height, ssize_t offset, int step, const boost::optional<fnc_accept_tx_source_t>& fnc_accept)
+{
+ CHECK_AND_ASSERT_THROW_MES(step != 0, "Step is zero");
+ sources.clear();
+
+ auto & transfers = wallet_accessor_test::get_transfers(wallet);
+ std::unordered_set<size_t> selected_idx;
+ std::unordered_set<crypto::key_image> selected_kis;
+ const size_t ntrans = wallet->get_num_transfer_details();
+ size_t roffset = offset >= 0 ? offset : ntrans - offset - 1;
+ size_t iters = 0;
+ uint64_t sum = 0;
+ size_t cur_utxo = 0;
+ bool abort = false;
+ unsigned brk_cond = 0;
+ unsigned brk_thresh = num_utxo && min_amount ? 2 : (num_utxo || min_amount ? 1 : 0);
+
+#define EVAL_BRK_COND() do { \
+ brk_cond = 0; \
+ if (num_utxo && num_utxo.get() <= cur_utxo) \
+ brk_cond += 1; \
+ if (min_amount && min_amount.get() <= sum) \
+ brk_cond += 1; \
+ } while(0)
+
+ for(ssize_t i = roffset; iters < ntrans && !abort; i += step, ++iters)
+ {
+ EVAL_BRK_COND();
+ if (brk_cond >= brk_thresh)
+ break;
+
+ i = i < 0 ? (i + ntrans) : i % ntrans;
+ auto & td = transfers[i];
+ if (td.m_spent)
+ continue;
+ if (td.m_block_height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW > cur_height)
+ continue;
+ if (selected_idx.find((size_t)i) != selected_idx.end()){
+ MERROR("Should not happen (selected_idx not found): " << i);
+ continue;
+ }
+ if (selected_kis.find(td.m_key_image) != selected_kis.end()){
+ MERROR("Should not happen (selected KI): " << i << "ki: " << dump_keys(td.m_key_image.data));
+ continue;
+ }
+
+ try {
+ cryptonote::tx_source_entry src;
+ wallet_tools::gen_tx_src(mixin, cur_height, td, src, bt);
+
+ // Acceptor function
+ if (fnc_accept){
+ tx_source_info_crate_t c_info{.td=&td, .src=&src, .selected_idx=&selected_idx, .selected_kis=&selected_kis,
+ .ntrans=ntrans, .iters=iters, .sum=sum, .cur_utxo=cur_utxo};
+
+ bool take_it = (fnc_accept.get())(c_info, abort);
+ if (!take_it){
+ continue;
+ }
+ }
+
+ MINFO("Selected " << i << " from tx: " << dump_keys(td.m_txid.data)
+ << " ki: " << dump_keys(td.m_key_image.data)
+ << " amnt: " << td.amount()
+ << " rct: " << td.is_rct()
+ << " glob: " << td.m_global_output_index);
+
+ sum += td.amount();
+ cur_utxo += 1;
+
+ sources.emplace_back(src);
+ selected.push_back((size_t)i);
+ selected_idx.insert((size_t)i);
+ selected_kis.insert(td.m_key_image);
+
+ } catch(const std::exception &e){
+ MTRACE("Output " << i << ", from: " << dump_keys(td.m_txid.data)
+ << ", amnt: " << td.amount() << ", rct: " << td.is_rct()
+ << ", glob: " << td.m_global_output_index << " is not applicable: " << e.what());
+ }
+ }
+
+ EVAL_BRK_COND();
+ return brk_cond >= brk_thresh;
+#undef EVAL_BRK_COND
+}
+
+void wallet_tools::gen_tx_src(size_t mixin, uint64_t cur_height, const tools::wallet2::transfer_details & td, cryptonote::tx_source_entry & src, block_tracker &bt)
+{
+ src.amount = td.amount();
+ src.rct = td.is_rct();
+
+ std::vector<tools::wallet2::get_outs_entry> outs;
+ bt.get_fake_outs(mixin, td.is_rct() ? 0 : td.amount(), td.m_global_output_index, cur_height, outs);
+
+ for (size_t n = 0; n < mixin; ++n)
+ {
+ cryptonote::tx_source_entry::output_entry oe;
+ oe.first = std::get<0>(outs[n]);
+ oe.second.dest = rct::pk2rct(std::get<1>(outs[n]));
+ oe.second.mask = std::get<2>(outs[n]);
+ src.outputs.push_back(oe);
+ }
+
+ size_t real_idx = crypto::rand<size_t>() % mixin;
+
+ cryptonote::tx_source_entry::output_entry &real_oe = src.outputs[real_idx];
+ real_oe.first = td.m_global_output_index;
+ real_oe.second.dest = rct::pk2rct(boost::get<txout_to_key>(td.m_tx.vout[td.m_internal_output_index].target).key);
+ real_oe.second.mask = rct::commit(td.amount(), td.m_mask);
+
+ std::sort(src.outputs.begin(), src.outputs.end(), [&](const cryptonote::tx_source_entry::output_entry i0, const cryptonote::tx_source_entry::output_entry i1) {
+ return i0.first < i1.first;
+ });
+
+ for (size_t i = 0; i < src.outputs.size(); ++i){
+ if (src.outputs[i].first == td.m_global_output_index){
+ src.real_output = i;
+ break;
+ }
+ }
+
+ src.mask = td.m_mask;
+ src.real_out_tx_key = get_tx_pub_key_from_extra(td.m_tx, td.m_pk_index);
+ src.real_out_additional_tx_keys = get_additional_tx_pub_keys_from_extra(td.m_tx);
+ src.real_output_in_tx_index = td.m_internal_output_index;
+ src.multisig_kLRki = rct::multisig_kLRki({rct::zero(), rct::zero(), rct::zero(), rct::zero()});
+}
+
+void wallet_tools::gen_block_data(block_tracker &bt, const cryptonote::block *bl, const map_hash2tx_t &mtx, cryptonote::block_complete_entry &bche, tools::wallet2::parsed_block &parsed_block, uint64_t &height)
+{
+ vector<const transaction*> vtx;
+ vtx.push_back(&(bl->miner_tx));
+ height = boost::get<txin_gen>(*bl->miner_tx.vin.begin()).height;
+
+ BOOST_FOREACH(const crypto::hash &h, bl->tx_hashes) {
+ const map_hash2tx_t::const_iterator cit = mtx.find(h);
+ CHECK_AND_ASSERT_THROW_MES(mtx.end() != cit, "block contains an unknown tx hash @ " << height << ", " << h);
+ vtx.push_back(cit->second);
+ }
+
+ bche.block = "NA";
+ bche.txs.resize(bl->tx_hashes.size());
+
+ parsed_block.error = false;
+ parsed_block.hash = get_block_hash(*bl);
+ parsed_block.block = *bl;
+ parsed_block.txes.reserve(bl->tx_hashes.size());
+
+ auto & o_indices = parsed_block.o_indices.indices;
+ o_indices.reserve(bl->tx_hashes.size() + 1);
+
+ size_t cur = 0;
+ BOOST_FOREACH(const transaction *tx, vtx){
+ cur += 1;
+ o_indices.emplace_back();
+ bt.process(bl, tx, cur - 1);
+ bt.global_indices(tx, o_indices.back().indices);
+
+ if (cur > 1) // miner not included
+ parsed_block.txes.push_back(*tx);
+ }
+}
+
+void wallet_tools::compute_subaddresses(std::unordered_map<crypto::public_key, cryptonote::subaddress_index> &subaddresses, cryptonote::account_base & creds, size_t account, size_t minors)
+{
+ auto &hwdev = hw::get_device("default");
+ const std::vector<crypto::public_key> pkeys = hwdev.get_subaddress_spend_public_keys(creds.get_keys(), account, 0, minors);
+
+ for(uint32_t c = 0; c < pkeys.size(); ++c){
+ cryptonote::subaddress_index sidx{(uint32_t)account, c};
+ subaddresses[pkeys[c]] = sidx;
+ }
+}
+
+cryptonote::account_public_address get_address(const tools::wallet2* inp)
+{
+ return (inp)->get_account().get_keys().m_account_address;
+}
+
+bool construct_tx_to_key(cryptonote::transaction& tx,
+ tools::wallet2 * sender_wallet, const var_addr_t& to, uint64_t amount,
+ std::vector<cryptonote::tx_source_entry> &sources,
+ uint64_t fee, bool rct, rct::RangeProofType range_proof_type, int bp_version)
+{
+ 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);
+}
+
+bool construct_tx_to_key(cryptonote::transaction& tx,
+ tools::wallet2 * sender_wallet,
+ const std::vector<cryptonote::tx_destination_entry>& destinations,
+ std::vector<cryptonote::tx_source_entry> &sources,
+ uint64_t fee, bool rct, rct::RangeProofType range_proof_type, int bp_version)
+{
+ 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);
+}
+
+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)
+{
+ 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, nullptr);
+}
diff --git a/tests/core_tests/wallet_tools.h b/tests/core_tests/wallet_tools.h
new file mode 100644
index 000000000..03db04c99
--- /dev/null
+++ b/tests/core_tests/wallet_tools.h
@@ -0,0 +1,86 @@
+// Copyright (c) 2014-2018, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
+
+#pragma once
+
+#include "chaingen.h"
+#include "wallet/wallet2.h"
+
+typedef struct {
+ tools::wallet2::transfer_details * td;
+ cryptonote::tx_source_entry * src;
+
+ std::unordered_set<size_t> * selected_idx;
+ std::unordered_set<crypto::key_image> * selected_kis;
+ size_t ntrans;
+ size_t iters;
+ uint64_t sum;
+ size_t cur_utxo;
+} tx_source_info_crate_t;
+
+typedef std::function<bool(const tx_source_info_crate_t &info, bool &abort)> fnc_accept_tx_source_t;
+
+// Wallet friend, direct access to required fields and private methods
+class wallet_accessor_test
+{
+public:
+ static void set_account(tools::wallet2 * wallet, cryptonote::account_base& account);
+ 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);
+};
+
+class wallet_tools
+{
+public:
+ static void gen_tx_src(size_t mixin, uint64_t cur_height, const tools::wallet2::transfer_details & td, cryptonote::tx_source_entry & src, block_tracker &bt);
+ static void gen_block_data(block_tracker &bt, const cryptonote::block *bl, const map_hash2tx_t & mtx, cryptonote::block_complete_entry &bche, tools::wallet2::parsed_block &parsed_block, uint64_t &height);
+ static void compute_subaddresses(std::unordered_map<crypto::public_key, cryptonote::subaddress_index> &subaddresses, cryptonote::account_base & creds, size_t account, size_t minors);
+ static void process_transactions(tools::wallet2 * wallet, const std::vector<test_event_entry>& events, const cryptonote::block& blk_head, block_tracker &bt, const boost::optional<crypto::hash>& blk_tail=boost::none);
+ static void process_transactions(tools::wallet2 * wallet, const std::vector<const cryptonote::block*>& blockchain, const map_hash2tx_t & mtx, block_tracker &bt);
+ static bool fill_tx_sources(tools::wallet2 * wallet, std::vector<cryptonote::tx_source_entry>& sources, size_t mixin, const boost::optional<size_t>& num_utxo, const boost::optional<uint64_t>& min_amount, block_tracker &bt, std::vector<size_t> &selected, uint64_t cur_height, ssize_t offset=0, int step=1, const boost::optional<fnc_accept_tx_source_t>& fnc_accept=boost::none);
+};
+
+cryptonote::account_public_address get_address(const tools::wallet2*);
+
+bool construct_tx_to_key(cryptonote::transaction& tx, tools::wallet2 * from_wallet, const var_addr_t& to, uint64_t amount,
+ std::vector<cryptonote::tx_source_entry> &sources,
+ uint64_t fee, bool rct=false, rct::RangeProofType range_proof_type=rct::RangeProofBorromean, int bp_version = 0);
+
+bool construct_tx_to_key(cryptonote::transaction& tx, tools::wallet2 * sender_wallet, const std::vector<cryptonote::tx_destination_entry>& destinations,
+ std::vector<cryptonote::tx_source_entry> &sources,
+ uint64_t fee, bool rct, rct::RangeProofType range_proof_type, int bp_version = 0);
+
+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=false, rct::RangeProofType range_proof_type=rct::RangeProofBorromean, int bp_version = 0);
diff --git a/tests/crypto/CMakeLists.txt b/tests/crypto/CMakeLists.txt
index df96c57cc..fd260ad59 100644
--- a/tests/crypto/CMakeLists.txt
+++ b/tests/crypto/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
@@ -52,3 +52,17 @@ set_property(TARGET cncrypto-tests
add_test(
NAME cncrypto
COMMAND cncrypto-tests "${CMAKE_CURRENT_SOURCE_DIR}/tests.txt")
+
+add_executable(cnv4-jit-tests cnv4-jit.c)
+target_link_libraries(cnv4-jit-tests
+ PRIVATE
+ crypto
+ common
+ ${EXTRA_LIBRARIES})
+set_property(TARGET cnv4-jit-tests
+ PROPERTY
+ FOLDER "tests")
+
+add_test(
+ NAME cnv4-jit
+ COMMAND cnv4-jit-tests 1788000 1789000)
diff --git a/tests/crypto/cnv4-jit.c b/tests/crypto/cnv4-jit.c
new file mode 100644
index 000000000..0f11e4393
--- /dev/null
+++ b/tests/crypto/cnv4-jit.c
@@ -0,0 +1,119 @@
+// Copyright (c) 2019, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include <stdint.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include "crypto/hash-ops.h"
+
+extern volatile int use_v4_jit_flag;
+
+static int test(const uint8_t *data, size_t len, uint64_t height)
+{
+ char hash0[32], hash1[32];
+ use_v4_jit_flag = 0;
+ cn_slow_hash(data, len, hash0, 4, 0, height);
+ use_v4_jit_flag = 1;
+ cn_slow_hash(data, len, hash1, 4, 0, height);
+ return memcmp(hash0, hash1, 32);
+}
+
+int main(int argc, char **argv)
+{
+ uint8_t data[64];
+ uint64_t start_height = 1788000;
+ uint64_t end_height = 1788001;
+
+ if (argc != 1 && argc != 2 && argc != 3)
+ {
+ fprintf(stderr, "usage: %s [<start_height> [<end_height>]]\n", argv[0]);
+ return 1;
+ }
+ if (argc > 1)
+ {
+ errno = 0;
+ start_height = strtoull(argv[1], NULL, 10);
+ if ((start_height == 0 && errno) || start_height == ULLONG_MAX)
+ {
+ fprintf(stderr, "invalid start_height\n");
+ return 1;
+ }
+ end_height = start_height;
+ if (argc > 2)
+ {
+ errno = 0;
+ end_height = strtoull(argv[2], NULL, 10);
+ if ((end_height == 0 && errno) || end_height == ULLONG_MAX)
+ {
+ fprintf(stderr, "invalid end_height\n");
+ return 1;
+ }
+ }
+ }
+
+ if (start_height == end_height)
+ {
+ uint64_t counter = 0;
+ while (1)
+ {
+ printf("\r%llu", (unsigned long long)counter);
+ fflush(stdout);
+ size_t offset = 0;
+ while (offset + 8 < sizeof(data))
+ {
+ memcpy(data + offset, &counter, sizeof(counter));
+ offset += 8;
+ }
+ if (test(data, sizeof(data), start_height))
+ {
+ fprintf(stderr, "\nFailure at height %llu, counter %llu\n", (unsigned long long)start_height, (unsigned long long)counter);
+ return 0;
+ }
+ ++counter;
+ }
+ }
+
+ memset(data, 0x42, sizeof(data));
+ for (uint64_t h = start_height; h < end_height; ++h)
+ {
+ printf("\r%llu/%llu", (unsigned long long)(h-start_height), (unsigned long long)(end_height-start_height));
+ fflush(stdout);
+ if (test(data, sizeof(data), h))
+ {
+ fprintf(stderr, "\nFailure at height %llu\n", (unsigned long long)h);
+ return 0;
+ }
+ }
+
+ printf("\r");
+
+ return 0;
+}
diff --git a/tests/crypto/crypto-ops-data.c b/tests/crypto/crypto-ops-data.c
index 9bdd6b88f..63fedff07 100644
--- a/tests/crypto/crypto-ops-data.c
+++ b/tests/crypto/crypto-ops-data.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/crypto/crypto-ops.c b/tests/crypto/crypto-ops.c
index 476de786a..9b1ccfcee 100644
--- a/tests/crypto/crypto-ops.c
+++ b/tests/crypto/crypto-ops.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/crypto/crypto-tests.h b/tests/crypto/crypto-tests.h
index d910a845c..be8d5a2e1 100644
--- a/tests/crypto/crypto-tests.h
+++ b/tests/crypto/crypto-tests.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/crypto/crypto.cpp b/tests/crypto/crypto.cpp
index 6a1dd1b29..160e0a23f 100644
--- a/tests/crypto/crypto.cpp
+++ b/tests/crypto/crypto.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/crypto/hash.c b/tests/crypto/hash.c
index 6b865abd9..d65f13f11 100644
--- a/tests/crypto/hash.c
+++ b/tests/crypto/hash.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/crypto/main.cpp b/tests/crypto/main.cpp
index cc3b53b83..3cdef4ce7 100644
--- a/tests/crypto/main.cpp
+++ b/tests/crypto/main.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/crypto/random.c b/tests/crypto/random.c
index e9464d457..7a17cbccc 100644
--- a/tests/crypto/random.c
+++ b/tests/crypto/random.c
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/cryptolib.pl b/tests/cryptolib.pl
index 3d4cb638b..d26ce601c 100644
--- a/tests/cryptolib.pl
+++ b/tests/cryptolib.pl
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/tests/cryptotest.pl b/tests/cryptotest.pl
index 13f8db09e..57f6e2c5a 100644
--- a/tests/cryptotest.pl
+++ b/tests/cryptotest.pl
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/tests/daemon_tests/CMakeLists.txt b/tests/daemon_tests/CMakeLists.txt
index bc1dce2cc..a32f26584 100644
--- a/tests/daemon_tests/CMakeLists.txt
+++ b/tests/daemon_tests/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/tests/daemon_tests/transfers.cpp b/tests/daemon_tests/transfers.cpp
index 726f11dfb..e20e6b280 100644
--- a/tests/daemon_tests/transfers.cpp
+++ b/tests/daemon_tests/transfers.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/difficulty/CMakeLists.txt b/tests/difficulty/CMakeLists.txt
index 3cb8af8d5..2ed495806 100644
--- a/tests/difficulty/CMakeLists.txt
+++ b/tests/difficulty/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/tests/difficulty/difficulty.cpp b/tests/difficulty/difficulty.cpp
index 996913a19..ee20e27e4 100644
--- a/tests/difficulty/difficulty.cpp
+++ b/tests/difficulty/difficulty.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/difficulty/generate-data b/tests/difficulty/generate-data
index c41ce025d..3a9976e05 100755
--- a/tests/difficulty/generate-data
+++ b/tests/difficulty/generate-data
@@ -1,6 +1,6 @@
#!/usr/bin/python3
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/tests/functional_tests/CMakeLists.txt b/tests/functional_tests/CMakeLists.txt
index 7a2a7fbd1..2e3519994 100644
--- a/tests/functional_tests/CMakeLists.txt
+++ b/tests/functional_tests/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/tests/functional_tests/main.cpp b/tests/functional_tests/main.cpp
index b9a686dbc..c6869f755 100644
--- a/tests/functional_tests/main.cpp
+++ b/tests/functional_tests/main.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/functional_tests/transactions_flow_test.cpp b/tests/functional_tests/transactions_flow_test.cpp
index 7e5b73415..32b601d7a 100644
--- a/tests/functional_tests/transactions_flow_test.cpp
+++ b/tests/functional_tests/transactions_flow_test.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/functional_tests/transactions_flow_test.h b/tests/functional_tests/transactions_flow_test.h
index 78135b9c0..530400df8 100644
--- a/tests/functional_tests/transactions_flow_test.h
+++ b/tests/functional_tests/transactions_flow_test.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/functional_tests/transactions_generation_from_blockchain.cpp b/tests/functional_tests/transactions_generation_from_blockchain.cpp
index 92dc00f2d..b9c43e0e9 100644
--- a/tests/functional_tests/transactions_generation_from_blockchain.cpp
+++ b/tests/functional_tests/transactions_generation_from_blockchain.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/functional_tests/transactions_generation_from_blockchain.h b/tests/functional_tests/transactions_generation_from_blockchain.h
index b684f7c7a..cb5f94f80 100644
--- a/tests/functional_tests/transactions_generation_from_blockchain.h
+++ b/tests/functional_tests/transactions_generation_from_blockchain.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/CMakeLists.txt b/tests/fuzz/CMakeLists.txt
index fdb745699..a6ef139f5 100644
--- a/tests/fuzz/CMakeLists.txt
+++ b/tests/fuzz/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/tests/fuzz/base58.cpp b/tests/fuzz/base58.cpp
index a4857bdd1..5f909a5d9 100644
--- a/tests/fuzz/base58.cpp
+++ b/tests/fuzz/base58.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/block.cpp b/tests/fuzz/block.cpp
index eed3b94b2..850c58890 100644
--- a/tests/fuzz/block.cpp
+++ b/tests/fuzz/block.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/bulletproof.cpp b/tests/fuzz/bulletproof.cpp
index 2f3a2f8d1..e9a6ded7d 100644
--- a/tests/fuzz/bulletproof.cpp
+++ b/tests/fuzz/bulletproof.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/cold-outputs.cpp b/tests/fuzz/cold-outputs.cpp
index 29b3ed267..f3f35e140 100644
--- a/tests/fuzz/cold-outputs.cpp
+++ b/tests/fuzz/cold-outputs.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/cold-transaction.cpp b/tests/fuzz/cold-transaction.cpp
index fa3041ba3..83493f8a0 100644
--- a/tests/fuzz/cold-transaction.cpp
+++ b/tests/fuzz/cold-transaction.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/fuzzer.cpp b/tests/fuzz/fuzzer.cpp
index ab14e2b79..24db5ee05 100644
--- a/tests/fuzz/fuzzer.cpp
+++ b/tests/fuzz/fuzzer.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/fuzzer.h b/tests/fuzz/fuzzer.h
index 2bf01914a..5cbd1abc2 100644
--- a/tests/fuzz/fuzzer.h
+++ b/tests/fuzz/fuzzer.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/http-client.cpp b/tests/fuzz/http-client.cpp
index 909325832..1750838ae 100644
--- a/tests/fuzz/http-client.cpp
+++ b/tests/fuzz/http-client.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/levin.cpp b/tests/fuzz/levin.cpp
index 573abd1d3..fe9ef418e 100644
--- a/tests/fuzz/levin.cpp
+++ b/tests/fuzz/levin.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/load_from_binary.cpp b/tests/fuzz/load_from_binary.cpp
index 89f122902..85b7361e5 100644
--- a/tests/fuzz/load_from_binary.cpp
+++ b/tests/fuzz/load_from_binary.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/load_from_json.cpp b/tests/fuzz/load_from_json.cpp
index 083555f7e..3ba98050b 100644
--- a/tests/fuzz/load_from_json.cpp
+++ b/tests/fuzz/load_from_json.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/parse_url.cpp b/tests/fuzz/parse_url.cpp
index fb5754a70..3db78f9d9 100644
--- a/tests/fuzz/parse_url.cpp
+++ b/tests/fuzz/parse_url.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/signature.cpp b/tests/fuzz/signature.cpp
index f82ada8b4..ab8faa29f 100644
--- a/tests/fuzz/signature.cpp
+++ b/tests/fuzz/signature.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/fuzz/transaction.cpp b/tests/fuzz/transaction.cpp
index 934bd4685..0f62888a1 100644
--- a/tests/fuzz/transaction.cpp
+++ b/tests/fuzz/transaction.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/hash-target.cpp b/tests/hash-target.cpp
index 2737ae30e..70368ce24 100644
--- a/tests/hash-target.cpp
+++ b/tests/hash-target.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/hash/CMakeLists.txt b/tests/hash/CMakeLists.txt
index 433cf94e9..a0c78bfdc 100644
--- a/tests/hash/CMakeLists.txt
+++ b/tests/hash/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
@@ -43,7 +43,7 @@ set_property(TARGET hash-tests
PROPERTY
FOLDER "tests")
-foreach (hash IN ITEMS fast slow slow-1 slow-2 tree extra-blake extra-groestl extra-jh extra-skein)
+foreach (hash IN ITEMS fast slow slow-1 slow-2 slow-4 tree extra-blake extra-groestl extra-jh extra-skein)
add_test(
NAME "hash-${hash}"
COMMAND hash-tests "${hash}" "${CMAKE_CURRENT_SOURCE_DIR}/tests-${hash}.txt")
diff --git a/tests/hash/main.cpp b/tests/hash/main.cpp
index 7767d0d3b..adf1bd9c4 100644
--- a/tests/hash/main.cpp
+++ b/tests/hash/main.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -44,6 +44,13 @@ using namespace std;
using namespace crypto;
typedef crypto::hash chash;
+struct V4_Data
+{
+ const void* data;
+ size_t length;
+ uint64_t height;
+};
+
PUSH_WARNINGS
DISABLE_VS_WARNINGS(4297)
extern "C" {
@@ -54,13 +61,17 @@ extern "C" {
tree_hash((const char (*)[crypto::HASH_SIZE]) data, length >> 5, hash);
}
static void cn_slow_hash_0(const void *data, size_t length, char *hash) {
- return cn_slow_hash(data, length, hash, 0/*variant*/, 0/*prehashed*/);
+ return cn_slow_hash(data, length, hash, 0/*variant*/, 0/*prehashed*/, 0/*height*/);
}
static void cn_slow_hash_1(const void *data, size_t length, char *hash) {
- return cn_slow_hash(data, length, hash, 1/*variant*/, 0/*prehashed*/);
+ return cn_slow_hash(data, length, hash, 1/*variant*/, 0/*prehashed*/, 0/*height*/);
}
static void cn_slow_hash_2(const void *data, size_t length, char *hash) {
- return cn_slow_hash(data, length, hash, 2/*variant*/, 0/*prehashed*/);
+ return cn_slow_hash(data, length, hash, 2/*variant*/, 0/*prehashed*/, 0/*height*/);
+ }
+ static void cn_slow_hash_4(const void *data, size_t, char *hash) {
+ const V4_Data* p = reinterpret_cast<const V4_Data*>(data);
+ return cn_slow_hash(p->data, p->length, hash, 4/*variant*/, 0/*prehashed*/, p->height);
}
}
POP_WARNINGS
@@ -72,7 +83,7 @@ struct hash_func {
} hashes[] = {{"fast", cn_fast_hash}, {"slow", cn_slow_hash_0}, {"tree", hash_tree},
{"extra-blake", hash_extra_blake}, {"extra-groestl", hash_extra_groestl},
{"extra-jh", hash_extra_jh}, {"extra-skein", hash_extra_skein},
- {"slow-1", cn_slow_hash_1}, {"slow-2", cn_slow_hash_2}};
+ {"slow-1", cn_slow_hash_1}, {"slow-2", cn_slow_hash_2}, {"slow-4", cn_slow_hash_4}};
int test_variant2_int_sqrt();
int test_variant2_int_sqrt_ref();
@@ -140,7 +151,15 @@ int main(int argc, char *argv[]) {
input.exceptions(ios_base::badbit | ios_base::failbit | ios_base::eofbit);
input.clear(input.rdstate());
get(input, data);
- f(data.data(), data.size(), (char *) &actual);
+ if (f == cn_slow_hash_4) {
+ V4_Data d;
+ d.data = data.data();
+ d.length = data.size();
+ get(input, d.height);
+ f(&d, 0, (char *) &actual);
+ } else {
+ f(data.data(), data.size(), (char *) &actual);
+ }
if (expected != actual) {
size_t i;
cerr << "Hash mismatch on test " << test << endl << "Input: ";
diff --git a/tests/hash/tests-slow-4.txt b/tests/hash/tests-slow-4.txt
new file mode 100644
index 000000000..06ab52cff
--- /dev/null
+++ b/tests/hash/tests-slow-4.txt
@@ -0,0 +1,10 @@
+f759588ad57e758467295443a9bd71490abff8e9dad1b95b6bf2f5d0d78387bc 5468697320697320612074657374205468697320697320612074657374205468697320697320612074657374 1806260
+5bb833deca2bdd7252a9ccd7b4ce0b6a4854515794b56c207262f7a5b9bdb566 4c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e67 1806261
+1ee6728da60fbd8d7d55b2b1ade487a3cf52a2c3ac6f520db12c27d8921f6cab 656c69742c2073656420646f20656975736d6f642074656d706f7220696e6369646964756e74207574206c61626f7265 1806262
+6969fe2ddfb758438d48049f302fc2108a4fcc93e37669170e6db4b0b9b4c4cb 657420646f6c6f7265206d61676e6120616c697175612e20557420656e696d206164206d696e696d2076656e69616d2c 1806263
+7f3048b4e90d0cbe7a57c0394f37338a01fae3adfdc0e5126d863a895eb04e02 71756973206e6f737472756420657865726369746174696f6e20756c6c616d636f206c61626f726973206e697369 1806264
+1d290443a4b542af04a82f6b2494a6ee7f20f2754c58e0849032483a56e8e2ef 757420616c697175697020657820656120636f6d6d6f646f20636f6e7365717561742e20447569732061757465 1806265
+c43cc6567436a86afbd6aa9eaa7c276e9806830334b614b2bee23cc76634f6fd 697275726520646f6c6f7220696e20726570726568656e646572697420696e20766f6c7570746174652076656c6974 1806266
+87be2479c0c4e8edfdfaa5603e93f4265b3f8224c1c5946feb424819d18990a4 657373652063696c6c756d20646f6c6f726520657520667567696174206e756c6c612070617269617475722e 1806267
+dd9d6a6d8e47465cceac0877ef889b93e7eba979557e3935d7f86dce11b070f3 4578636570746575722073696e74206f6363616563617420637570696461746174206e6f6e2070726f6964656e742c 1806268
+75c6f2ae49a20521de97285b431e717125847fb8935ed84a61e7f8d36a2c3d8e 73756e7420696e2063756c706120717569206f666669636961206465736572756e74206d6f6c6c697420616e696d20696420657374206c61626f72756d2e 1806269
diff --git a/tests/io.h b/tests/io.h
index ec5a9ee60..0f65ed297 100644
--- a/tests/io.h
+++ b/tests/io.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/libwallet_api_tests/CMakeLists.txt b/tests/libwallet_api_tests/CMakeLists.txt
index 1a9cbc5a6..cb1d563b0 100644
--- a/tests/libwallet_api_tests/CMakeLists.txt
+++ b/tests/libwallet_api_tests/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/tests/libwallet_api_tests/main.cpp b/tests/libwallet_api_tests/main.cpp
index fe31541df..02faae50d 100644
--- a/tests/libwallet_api_tests/main.cpp
+++ b/tests/libwallet_api_tests/main.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/net_load_tests/CMakeLists.txt b/tests/net_load_tests/CMakeLists.txt
index 1407bbf70..40b5561a7 100644
--- a/tests/net_load_tests/CMakeLists.txt
+++ b/tests/net_load_tests/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/tests/net_load_tests/clt.cpp b/tests/net_load_tests/clt.cpp
index 77cce2be7..fc2280f23 100644
--- a/tests/net_load_tests/clt.cpp
+++ b/tests/net_load_tests/clt.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/net_load_tests/net_load_tests.h b/tests/net_load_tests/net_load_tests.h
index 6c4f7cb76..cdc2d267a 100644
--- a/tests/net_load_tests/net_load_tests.h
+++ b/tests/net_load_tests/net_load_tests.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/net_load_tests/srv.cpp b/tests/net_load_tests/srv.cpp
index 092c6955c..fe32ec5cb 100644
--- a/tests/net_load_tests/srv.cpp
+++ b/tests/net_load_tests/srv.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/CMakeLists.txt b/tests/performance_tests/CMakeLists.txt
index 5cd054d86..aa424da80 100644
--- a/tests/performance_tests/CMakeLists.txt
+++ b/tests/performance_tests/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/tests/performance_tests/bulletproof.h b/tests/performance_tests/bulletproof.h
index 7bb702c3d..7136fbbfe 100644
--- a/tests/performance_tests/bulletproof.h
+++ b/tests/performance_tests/bulletproof.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2017, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/check_tx_signature.h b/tests/performance_tests/check_tx_signature.h
index 755d8f941..329714c56 100644
--- a/tests/performance_tests/check_tx_signature.h
+++ b/tests/performance_tests/check_tx_signature.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/cn_fast_hash.h b/tests/performance_tests/cn_fast_hash.h
index 2ddaef269..63b2c5bee 100644
--- a/tests/performance_tests/cn_fast_hash.h
+++ b/tests/performance_tests/cn_fast_hash.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/cn_slow_hash.h b/tests/performance_tests/cn_slow_hash.h
index b484afa41..4f410d62d 100644
--- a/tests/performance_tests/cn_slow_hash.h
+++ b/tests/performance_tests/cn_slow_hash.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -34,6 +34,7 @@
#include "crypto/crypto.h"
#include "cryptonote_basic/cryptonote_basic.h"
+template<unsigned int variant>
class test_cn_slow_hash
{
public:
@@ -42,18 +43,15 @@ public:
#pragma pack(push, 1)
struct data_t
{
- char data[13];
+ char data[43];
};
#pragma pack(pop)
- static_assert(13 == sizeof(data_t), "Invalid structure size");
+ static_assert(43 == sizeof(data_t), "Invalid structure size");
bool init()
{
- if (!epee::string_tools::hex_to_pod("63617665617420656d70746f72", m_data))
- return false;
-
- if (!epee::string_tools::hex_to_pod("bbec2cacf69866a8e740380fe7b818fc78f8571221742d729d9d02d7f8989b87", m_expected_hash))
+ if (!epee::string_tools::hex_to_pod("63617665617420656d70746f763617665617420656d70746f72263617665617420656d70746f7201020304", m_data))
return false;
return true;
@@ -62,11 +60,10 @@ public:
bool test()
{
crypto::hash hash;
- crypto::cn_slow_hash(&m_data, sizeof(m_data), hash);
- return hash == m_expected_hash;
+ crypto::cn_slow_hash(&m_data, sizeof(m_data), hash, variant);
+ return true;
}
private:
data_t m_data;
- crypto::hash m_expected_hash;
};
diff --git a/tests/performance_tests/construct_tx.h b/tests/performance_tests/construct_tx.h
index 71d42073d..ebfe46edf 100644
--- a/tests/performance_tests/construct_tx.h
+++ b/tests/performance_tests/construct_tx.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/crypto_ops.h b/tests/performance_tests/crypto_ops.h
index 3ebb6f470..5b215cef4 100644
--- a/tests/performance_tests/crypto_ops.h
+++ b/tests/performance_tests/crypto_ops.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2017, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/derive_public_key.h b/tests/performance_tests/derive_public_key.h
index 35c4ff062..ad0b3b55f 100644
--- a/tests/performance_tests/derive_public_key.h
+++ b/tests/performance_tests/derive_public_key.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/derive_secret_key.h b/tests/performance_tests/derive_secret_key.h
index c478a2a99..ba01b57c0 100644
--- a/tests/performance_tests/derive_secret_key.h
+++ b/tests/performance_tests/derive_secret_key.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/equality.h b/tests/performance_tests/equality.h
index 8d24d7da7..5788ebec8 100644
--- a/tests/performance_tests/equality.h
+++ b/tests/performance_tests/equality.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/ge_frombytes_vartime.h b/tests/performance_tests/ge_frombytes_vartime.h
index 3f7d55182..1a0601c74 100644
--- a/tests/performance_tests/ge_frombytes_vartime.h
+++ b/tests/performance_tests/ge_frombytes_vartime.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/ge_tobytes.h b/tests/performance_tests/ge_tobytes.h
index 3d46f4838..66e6fce38 100644
--- a/tests/performance_tests/ge_tobytes.h
+++ b/tests/performance_tests/ge_tobytes.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/generate_key_derivation.h b/tests/performance_tests/generate_key_derivation.h
index 3f6238265..1f0066589 100644
--- a/tests/performance_tests/generate_key_derivation.h
+++ b/tests/performance_tests/generate_key_derivation.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/generate_key_image.h b/tests/performance_tests/generate_key_image.h
index 5155e64a5..df39d7088 100644
--- a/tests/performance_tests/generate_key_image.h
+++ b/tests/performance_tests/generate_key_image.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/generate_key_image_helper.h b/tests/performance_tests/generate_key_image_helper.h
index ede48b6ca..d4d83c07d 100644
--- a/tests/performance_tests/generate_key_image_helper.h
+++ b/tests/performance_tests/generate_key_image_helper.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/generate_keypair.h b/tests/performance_tests/generate_keypair.h
index 91c830166..cf28f7f58 100644
--- a/tests/performance_tests/generate_keypair.h
+++ b/tests/performance_tests/generate_keypair.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/is_out_to_acc.h b/tests/performance_tests/is_out_to_acc.h
index 9f81995ac..8b4516843 100644
--- a/tests/performance_tests/is_out_to_acc.h
+++ b/tests/performance_tests/is_out_to_acc.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp
index bfe6de895..e6558a364 100644
--- a/tests/performance_tests/main.cpp
+++ b/tests/performance_tests/main.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -77,10 +77,12 @@ int main(int argc, char** argv)
const command_line::arg_descriptor<bool> arg_verbose = { "verbose", "Verbose output", false };
const command_line::arg_descriptor<bool> arg_stats = { "stats", "Including statistics (min/median)", false };
const command_line::arg_descriptor<unsigned> arg_loop_multiplier = { "loop-multiplier", "Run for that many times more loops", 1 };
+ const command_line::arg_descriptor<std::string> arg_timings_database = { "timings-database", "Keep timings history in a file" };
command_line::add_arg(desc_options, arg_filter);
command_line::add_arg(desc_options, arg_verbose);
command_line::add_arg(desc_options, arg_stats);
command_line::add_arg(desc_options, arg_loop_multiplier);
+ command_line::add_arg(desc_options, arg_timings_database);
po::variables_map vm;
bool r = command_line::handle_error_helper(desc_options, [&]()
@@ -93,7 +95,10 @@ int main(int argc, char** argv)
return 1;
const std::string filter = tools::glob_to_regex(command_line::get_arg(vm, arg_filter));
+ const std::string timings_database = command_line::get_arg(vm, arg_timings_database);
Params p;
+ if (!timings_database.empty())
+ p.td = TimingsDatabase(timings_database);
p.verbose = command_line::get_arg(vm, arg_verbose);
p.stats = command_line::get_arg(vm, arg_stats);
p.loop_multiplier = command_line::get_arg(vm, arg_loop_multiplier);
@@ -193,7 +198,10 @@ int main(int argc, char** argv)
TEST_PERFORMANCE2(filter, p, test_wallet2_expand_subaddresses, 50, 200);
- TEST_PERFORMANCE0(filter, p, test_cn_slow_hash);
+ TEST_PERFORMANCE1(filter, p, test_cn_slow_hash, 0);
+ TEST_PERFORMANCE1(filter, p, test_cn_slow_hash, 1);
+ TEST_PERFORMANCE1(filter, p, test_cn_slow_hash, 2);
+ TEST_PERFORMANCE1(filter, p, test_cn_slow_hash, 4);
TEST_PERFORMANCE1(filter, p, test_cn_fast_hash, 32);
TEST_PERFORMANCE1(filter, p, test_cn_fast_hash, 16384);
diff --git a/tests/performance_tests/multi_tx_test_base.h b/tests/performance_tests/multi_tx_test_base.h
index ae9d6ea7a..bdbbee37d 100644
--- a/tests/performance_tests/multi_tx_test_base.h
+++ b/tests/performance_tests/multi_tx_test_base.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/performance_tests.h b/tests/performance_tests/performance_tests.h
index d37dda729..606c5980f 100644
--- a/tests/performance_tests/performance_tests.h
+++ b/tests/performance_tests/performance_tests.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -37,7 +37,9 @@
#include <boost/regex.hpp>
#include "misc_language.h"
+#include "stats.h"
#include "common/perf_timer.h"
+#include "common/timings.h"
class performance_timer
{
@@ -67,6 +69,7 @@ private:
struct Params
{
+ TimingsDatabase td;
bool verbose;
bool stats;
unsigned loop_multiplier;
@@ -85,6 +88,8 @@ public:
bool run()
{
+ static_assert(0 < T::loop_count, "T::loop_count must be greater than 0");
+
T test;
if (!test.init())
return false;
@@ -106,11 +111,13 @@ public:
m_per_call_timers[i].pause();
}
m_elapsed = timer.elapsed_ms();
+ m_stats.reset(new Stats<tools::PerformanceTimer, uint64_t>(m_per_call_timers));
return true;
}
int elapsed_time() const { return m_elapsed; }
+ size_t get_size() const { return m_stats->get_size(); }
int time_per_call(int scale = 1) const
{
@@ -118,59 +125,19 @@ public:
return m_elapsed * scale / (T::loop_count * m_params.loop_multiplier);
}
- uint64_t per_call_min() const
- {
- uint64_t v = std::numeric_limits<uint64_t>::max();
- for (const auto &pt: m_per_call_timers)
- v = std::min(v, pt.value());
- return v;
- }
-
- uint64_t per_call_max() const
- {
- uint64_t v = std::numeric_limits<uint64_t>::min();
- for (const auto &pt: m_per_call_timers)
- v = std::max(v, pt.value());
- return v;
- }
-
- uint64_t per_call_mean() const
- {
- uint64_t v = 0;
- for (const auto &pt: m_per_call_timers)
- v += pt.value();
- return v / m_per_call_timers.size();
- }
-
- uint64_t per_call_median() const
- {
- std::vector<uint64_t> values;
- values.reserve(m_per_call_timers.size());
- for (const auto &pt: m_per_call_timers)
- values.push_back(pt.value());
- return epee::misc_utils::median(values);
- }
+ uint64_t get_min() const { return m_stats->get_min(); }
+ uint64_t get_max() const { return m_stats->get_max(); }
+ double get_mean() const { return m_stats->get_mean(); }
+ uint64_t get_median() const { return m_stats->get_median(); }
+ double get_stddev() const { return m_stats->get_standard_deviation(); }
+ double get_non_parametric_skew() const { return m_stats->get_non_parametric_skew(); }
+ std::vector<uint64_t> get_quantiles(size_t n) const { return m_stats->get_quantiles(n); }
- uint64_t per_call_stddev() const
+ bool is_same_distribution(size_t npoints, double mean, double stddev) const
{
- if (m_per_call_timers.size() <= 1)
- return 0;
- const uint64_t mean = per_call_mean();
- uint64_t acc = 0;
- for (const auto &pt: m_per_call_timers)
- {
- int64_t dv = pt.value() - mean;
- acc += dv * dv;
- }
- acc /= m_per_call_timers.size () - 1;
- return sqrt(acc);
+ return m_stats->is_same_distribution_99(npoints, mean, stddev);
}
- uint64_t min_time_ns() const { return tools::ticks_to_ns(per_call_min()); }
- uint64_t max_time_ns() const { return tools::ticks_to_ns(per_call_max()); }
- uint64_t median_time_ns() const { return tools::ticks_to_ns(per_call_median()); }
- uint64_t standard_deviation_time_ns() const { return tools::ticks_to_ns(per_call_stddev()); }
-
private:
/**
* Warm up processor core, enabling turbo boost, etc.
@@ -191,10 +158,11 @@ private:
int m_elapsed;
Params m_params;
std::vector<tools::PerformanceTimer> m_per_call_timers;
+ std::unique_ptr<Stats<tools::PerformanceTimer, uint64_t>> m_stats;
};
template <typename T>
-void run_test(const std::string &filter, const Params &params, const char* test_name)
+void run_test(const std::string &filter, Params &params, const char* test_name)
{
boost::smatch match;
if (!filter.empty() && !boost::regex_match(std::string(test_name), match, boost::regex(filter)))
@@ -210,10 +178,10 @@ void run_test(const std::string &filter, const Params &params, const char* test_
std::cout << " elapsed: " << runner.elapsed_time() << " ms\n";
if (params.stats)
{
- std::cout << " min: " << runner.min_time_ns() << " ns\n";
- std::cout << " max: " << runner.max_time_ns() << " ns\n";
- std::cout << " median: " << runner.median_time_ns() << " ns\n";
- std::cout << " std dev: " << runner.standard_deviation_time_ns() << " ns\n";
+ std::cout << " min: " << runner.get_min() << " ns\n";
+ std::cout << " max: " << runner.get_max() << " ns\n";
+ std::cout << " median: " << runner.get_median() << " ns\n";
+ std::cout << " std dev: " << runner.get_stddev() << " ns\n";
}
}
else
@@ -221,24 +189,48 @@ void run_test(const std::string &filter, const Params &params, const char* test_
std::cout << test_name << " (" << T::loop_count * params.loop_multiplier << " calls) - OK:";
}
const char *unit = "ms";
- uint64_t scale = 1000000;
- int time_per_call = runner.time_per_call();
- if (time_per_call < 30000) {
+ double scale = 1000000;
+ uint64_t time_per_call = runner.time_per_call();
+ if (time_per_call < 100) {
+ scale = 1000;
time_per_call = runner.time_per_call(1000);
#ifdef _WIN32
unit = "\xb5s";
#else
unit = "µs";
#endif
- scale = 1000;
}
+ const auto quantiles = runner.get_quantiles(10);
+ double min = runner.get_min();
+ double max = runner.get_max();
+ double med = runner.get_median();
+ double mean = runner.get_mean();
+ double stddev = runner.get_stddev();
+ double npskew = runner.get_non_parametric_skew();
+
+ std::vector<TimingsDatabase::instance> prev_instances = params.td.get(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" : "");
if (params.stats)
{
- uint64_t min_ns = runner.min_time_ns() / scale;
- uint64_t med_ns = runner.median_time_ns() / scale;
- uint64_t stddev_ns = runner.standard_deviation_time_ns() / scale;
- std::cout << " (min " << min_ns << " " << unit << ", median " << med_ns << " " << unit << ", std dev " << stddev_ns << " " << unit << ")";
+ uint64_t mins = min / scale;
+ uint64_t maxs = max / scale;
+ uint64_t meds = med / scale;
+ uint64_t p95s = quantiles[9] / scale;
+ uint64_t stddevs = stddev / scale;
+ std::string cmp;
+ if (!prev_instances.empty())
+ {
+ const TimingsDatabase::instance &prev_instance = prev_instances.back();
+ 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");
+ }
+cmp += " -- " + std::to_string(prev_instance.mean);
+ }
+ std::cout << " (min " << mins << " " << unit << ", 90th " << p95s << " " << unit << ", median " << meds << " " << unit << ", std dev " << stddevs << " " << unit << ")" << cmp;
}
std::cout << std::endl;
}
diff --git a/tests/performance_tests/performance_utils.h b/tests/performance_tests/performance_utils.h
index e46a7bce4..0eb9a720e 100644
--- a/tests/performance_tests/performance_utils.h
+++ b/tests/performance_tests/performance_utils.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/range_proof.h b/tests/performance_tests/range_proof.h
index 0ce962cd9..548237814 100644
--- a/tests/performance_tests/range_proof.h
+++ b/tests/performance_tests/range_proof.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2017, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/rct_mlsag.h b/tests/performance_tests/rct_mlsag.h
index 888f4b260..0141710f7 100644
--- a/tests/performance_tests/rct_mlsag.h
+++ b/tests/performance_tests/rct_mlsag.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2017, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/sc_reduce32.h b/tests/performance_tests/sc_reduce32.h
index fc5606414..8db1ca70a 100644
--- a/tests/performance_tests/sc_reduce32.h
+++ b/tests/performance_tests/sc_reduce32.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/signature.h b/tests/performance_tests/signature.h
index 21110b525..63c63ea46 100644
--- a/tests/performance_tests/signature.h
+++ b/tests/performance_tests/signature.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/single_tx_test_base.h b/tests/performance_tests/single_tx_test_base.h
index 365d25444..52fbf5f80 100644
--- a/tests/performance_tests/single_tx_test_base.h
+++ b/tests/performance_tests/single_tx_test_base.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/performance_tests/subaddress_expand.h b/tests/performance_tests/subaddress_expand.h
index 2a13ff5c2..61fcb41f3 100644
--- a/tests/performance_tests/subaddress_expand.h
+++ b/tests/performance_tests/subaddress_expand.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/trezor/CMakeLists.txt b/tests/trezor/CMakeLists.txt
new file mode 100644
index 000000000..67c2f8438
--- /dev/null
+++ b/tests/trezor/CMakeLists.txt
@@ -0,0 +1,63 @@
+# Copyright (c) 2014-2018, The Monero Project
+#
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without modification, are
+# permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice, this list of
+# conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice, this list
+# of conditions and the following disclaimer in the documentation and/or other
+# materials provided with the distribution.
+#
+# 3. Neither the name of the copyright holder nor the names of its contributors may be
+# used to endorse or promote products derived from this software without specific
+# prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+set(trezor_tests_sources
+ trezor_tests.cpp
+ ../core_tests/chaingen.cpp
+ ../core_tests/wallet_tools.cpp)
+
+set(trezor_tests_headers
+ trezor_tests.h
+ ../core_tests/chaingen.h
+ ../core_tests/wallet_tools.h)
+
+add_executable(trezor_tests
+ ${trezor_tests_sources}
+ ${trezor_tests_headers})
+
+target_link_libraries(trezor_tests
+ PRIVATE
+ multisig
+ cryptonote_core
+ p2p
+ version
+ epee
+ device
+ device_trezor
+ wallet
+ ${CMAKE_THREAD_LIBS_INIT}
+ ${EXTRA_LIBRARIES})
+
+enable_stack_trace(trezor_tests)
+set_property(TARGET trezor_tests
+ PROPERTY
+ FOLDER "tests")
+
+add_test(
+ NAME trezor_tests
+ COMMAND trezor_tests)
diff --git a/tests/trezor/trezor_tests.cpp b/tests/trezor/trezor_tests.cpp
new file mode 100644
index 000000000..c2b46f698
--- /dev/null
+++ b/tests/trezor/trezor_tests.cpp
@@ -0,0 +1,1409 @@
+// Copyright (c) 2014-2018, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
+
+#include "include_base_utils.h"
+#include "cryptonote_basic/cryptonote_basic_impl.h"
+#include "cryptonote_basic/account.h"
+#include "cryptonote_core/cryptonote_tx_utils.h"
+#include "misc_language.h"
+#include "string_tools.h"
+
+using namespace cryptonote;
+
+#include <boost/regex.hpp>
+#include "common/util.h"
+#include "common/command_line.h"
+#include "trezor_tests.h"
+#include "device/device_cold.hpp"
+#include "device_trezor/device_trezor.hpp"
+
+
+namespace po = boost::program_options;
+
+namespace
+{
+ const command_line::arg_descriptor<std::string> arg_filter = { "filter", "Regular expression filter for which tests to run" };
+ const command_line::arg_descriptor<bool> arg_generate_and_play_test_data = {"generate_and_play_test_data", ""};
+ const command_line::arg_descriptor<std::string> arg_trezor_path = {"trezor_path", "Path to the trezor device to use, has to support debug link", ""};
+ const command_line::arg_descriptor<bool> arg_heavy_tests = {"heavy_tests", "Runs expensive tests (volume tests with real device)", false};
+ const command_line::arg_descriptor<std::string> arg_chain_path = {"chain_path", "Path to the serialized blockchain, speeds up testing", ""};
+ const command_line::arg_descriptor<bool> arg_fix_chain = {"fix_chain", "If chain_patch is given and file cannot be used, it is ignored and overwriten", false};
+}
+
+
+#define TREZOR_ACCOUNT_ORDERING &m_miner_account, &m_alice_account, &m_bob_account, &m_eve_account
+#define TREZOR_COMMON_TEST_CASE(genclass, CORE, BASE) \
+ rollback_chain(CORE, BASE.head_block()); \
+ { \
+ genclass ctest; \
+ BASE.fork(ctest); \
+ GENERATE_AND_PLAY_INSTANCE(genclass, ctest, *(CORE)); \
+ }
+
+#define TREZOR_SETUP_CHAIN(NAME) do { \
+ ++tests_count; \
+ try { \
+ setup_chain(&core, trezor_base, chain_path, fix_chain); \
+ } catch (const std::exception& ex) { \
+ failed_tests.emplace_back("gen_trezor_base " #NAME); \
+ } \
+} while(0)
+
+static void rollback_chain(cryptonote::core * core, const cryptonote::block & head);
+static void setup_chain(cryptonote::core ** core, gen_trezor_base & trezor_base, std::string chain_path, bool fix_chain);
+
+int main(int argc, char* argv[])
+{
+ TRY_ENTRY();
+ tools::on_startup();
+ epee::string_tools::set_module_name_and_folder(argv[0]);
+
+ //set up logging options
+ mlog_configure(mlog_get_default_log_path("trezor_tests.log"), true);
+ mlog_set_log_level(2);
+
+ po::options_description desc_options("Allowed options");
+ command_line::add_arg(desc_options, command_line::arg_help);
+ command_line::add_arg(desc_options, arg_filter);
+ command_line::add_arg(desc_options, arg_trezor_path);
+ command_line::add_arg(desc_options, arg_heavy_tests);
+ command_line::add_arg(desc_options, arg_chain_path);
+ command_line::add_arg(desc_options, arg_fix_chain);
+
+ po::variables_map vm;
+ bool r = command_line::handle_error_helper(desc_options, [&]()
+ {
+ po::store(po::parse_command_line(argc, argv, desc_options), vm);
+ po::notify(vm);
+ return true;
+ });
+ if (!r)
+ return 1;
+
+ if (command_line::get_arg(vm, command_line::arg_help))
+ {
+ std::cout << desc_options << std::endl;
+ return 0;
+ }
+
+ const std::string filter = tools::glob_to_regex(command_line::get_arg(vm, arg_filter));
+ boost::smatch match;
+
+ size_t tests_count = 0;
+ std::vector<std::string> failed_tests;
+ std::string trezor_path = command_line::get_arg(vm, arg_trezor_path);
+ std::string chain_path = command_line::get_arg(vm, arg_chain_path);
+ const bool heavy_tests = command_line::get_arg(vm, arg_heavy_tests);
+ const bool fix_chain = command_line::get_arg(vm, arg_fix_chain);
+
+ hw::trezor::register_all();
+
+ // Bootstrapping common chain & accounts
+ cryptonote::core * core = nullptr;
+
+ gen_trezor_base trezor_base;
+ trezor_base.setup_args(trezor_path, heavy_tests);
+ trezor_base.rct_config({rct::RangeProofPaddedBulletproof, 1}); // HF9 tests
+
+ TREZOR_SETUP_CHAIN("HF9");
+
+ // Individual test cases using shared pre-generated blockchain.
+ TREZOR_COMMON_TEST_CASE(gen_trezor_ki_sync, core, trezor_base);
+
+ // Transaction tests
+ TREZOR_COMMON_TEST_CASE(gen_trezor_1utxo, core, trezor_base);
+ TREZOR_COMMON_TEST_CASE(gen_trezor_1utxo_paymentid_short, core, trezor_base);
+ TREZOR_COMMON_TEST_CASE(gen_trezor_1utxo_paymentid_short_integrated, core, trezor_base);
+ TREZOR_COMMON_TEST_CASE(gen_trezor_1utxo_paymentid_long, core, trezor_base);
+ TREZOR_COMMON_TEST_CASE(gen_trezor_4utxo, core, trezor_base);
+ TREZOR_COMMON_TEST_CASE(gen_trezor_4utxo_acc1, core, trezor_base);
+ TREZOR_COMMON_TEST_CASE(gen_trezor_4utxo_to_sub, core, trezor_base);
+ TREZOR_COMMON_TEST_CASE(gen_trezor_4utxo_to_2sub, core, trezor_base);
+ TREZOR_COMMON_TEST_CASE(gen_trezor_4utxo_to_1norm_2sub, core, trezor_base);
+ TREZOR_COMMON_TEST_CASE(gen_trezor_2utxo_sub_acc_to_1norm_2sub, core, trezor_base);
+ TREZOR_COMMON_TEST_CASE(gen_trezor_4utxo_to_7outs, core, trezor_base);
+
+ if (trezor_base.heavy_tests())
+ {
+ TREZOR_COMMON_TEST_CASE(gen_trezor_many_utxo, core, trezor_base);
+ }
+
+ core->deinit();
+ el::Level level = (failed_tests.empty() ? el::Level::Info : el::Level::Error);
+ MLOG(level, "\nREPORT:");
+ MLOG(level, " Test run: " << tests_count);
+ MLOG(level, " Failures: " << failed_tests.size());
+ if (!failed_tests.empty())
+ {
+ MLOG(level, "FAILED TESTS:");
+ BOOST_FOREACH(auto test_name, failed_tests)
+ {
+ MLOG(level, " " << test_name);
+ }
+ }
+
+ return failed_tests.empty() ? 0 : 1;
+
+ CATCH_ENTRY_L0("main", 1);
+}
+
+static void rollback_chain(cryptonote::core * core, const cryptonote::block & head)
+{
+ CHECK_AND_ASSERT_THROW_MES(core, "Core is null");
+
+ block popped_block;
+ std::vector<transaction> popped_txs;
+
+ crypto::hash head_hash = get_block_hash(head), cur_hash{};
+ uint64_t height = get_block_height(head), cur_height=0;
+
+ do {
+ core->get_blockchain_top(cur_height, cur_hash);
+
+ if (cur_height <= height && head_hash == cur_hash)
+ return;
+
+ CHECK_AND_ASSERT_THROW_MES(cur_height > height, "Height differs");
+ core->get_blockchain_storage().get_db().pop_block(popped_block, popped_txs);
+ } while(true);
+}
+
+static bool unserialize_chain_from_file(std::vector<test_event_entry>& events, gen_trezor_base &test_base, const std::string& file_path)
+{
+ TRY_ENTRY();
+ std::ifstream data_file;
+ data_file.open( file_path, std::ios_base::binary | std::ios_base::in);
+ if(data_file.fail())
+ return false;
+ try
+ {
+ boost::archive::portable_binary_iarchive a(data_file);
+ test_base.clear();
+
+ a >> events;
+ a >> test_base;
+ return true;
+ }
+ catch(...)
+ {
+ MWARNING("Chain deserialization failed");
+ return false;
+ }
+ CATCH_ENTRY_L0("unserialize_chain_from_file", false);
+}
+
+static bool serialize_chain_to_file(std::vector<test_event_entry>& events, gen_trezor_base &test_base, const std::string& file_path)
+{
+ TRY_ENTRY();
+ std::ofstream data_file;
+ data_file.open( file_path, std::ios_base::binary | std::ios_base::out | std::ios::trunc);
+ if(data_file.fail())
+ return false;
+ try
+ {
+
+ boost::archive::portable_binary_oarchive a(data_file);
+ a << events;
+ a << test_base;
+ return !data_file.fail();
+ }
+ catch(...)
+ {
+ MWARNING("Chain deserialization failed");
+ return false;
+ }
+ return false;
+ CATCH_ENTRY_L0("serialize_chain_to_file", false);
+}
+
+static void setup_chain(cryptonote::core ** core, gen_trezor_base & trezor_base, std::string chain_path, bool fix_chain)
+{
+ std::vector<test_event_entry> events;
+ const bool do_serialize = !chain_path.empty();
+ const bool chain_file_exists = do_serialize && boost::filesystem::exists(chain_path);
+ bool loaded = false;
+ bool generated = false;
+
+ if (chain_file_exists)
+ {
+ if (!unserialize_chain_from_file(events, trezor_base, chain_path))
+ {
+ MERROR("Failed to deserialize data from file: " << chain_path);
+ if (!fix_chain)
+ {
+ throw std::runtime_error("Chain load error");
+ }
+ } else
+ {
+ trezor_base.load(events);
+ generated = true;
+ loaded = true;
+ }
+ }
+
+ if (!generated)
+ {
+ try
+ {
+ generated = trezor_base.generate(events);
+
+ if (generated && !loaded && do_serialize)
+ {
+ trezor_base.update_trackers(events);
+ if (!serialize_chain_to_file(events, trezor_base, chain_path))
+ {
+ MERROR("Failed to serialize data to file: " << chain_path);
+ }
+ }
+ }
+ CATCH_REPLAY(gen_trezor_base);
+ }
+
+ trezor_base.fix_hf(events);
+ if (generated && do_replay_events_get_core<gen_trezor_base>(events, core))
+ {
+ MGINFO_GREEN("#TEST-chain-init# Succeeded ");
+ }
+ else
+ {
+ MERROR("#TEST-chain-init# Failed ");
+ throw std::runtime_error("Chain init error");
+ }
+}
+
+static void add_hforks(std::vector<test_event_entry>& events, const v_hardforks_t& hard_forks)
+{
+ event_replay_settings repl_set;
+ repl_set.hard_forks = boost::make_optional(hard_forks);
+ events.push_back(repl_set);
+}
+
+static void add_top_hfork(std::vector<test_event_entry>& events, const v_hardforks_t& hard_forks)
+{
+ event_replay_settings repl_set;
+ v_hardforks_t top_fork;
+ top_fork.push_back(hard_forks.back());
+ repl_set.hard_forks = boost::make_optional(top_fork);
+ events.push_back(repl_set);
+}
+
+static crypto::public_key get_tx_pub_key_from_received_outs(const tools::wallet2::transfer_details &td)
+{
+ std::vector<tx_extra_field> tx_extra_fields;
+ parse_tx_extra(td.m_tx.extra, tx_extra_fields);
+
+ tx_extra_pub_key pub_key_field;
+ THROW_WALLET_EXCEPTION_IF(!find_tx_extra_field_by_type(tx_extra_fields, pub_key_field, 0), tools::error::wallet_internal_error,
+ "Public key wasn't found in the transaction extra");
+ const crypto::public_key tx_pub_key = pub_key_field.pub_key;
+ bool two_found = find_tx_extra_field_by_type(tx_extra_fields, pub_key_field, 1);
+ if (!two_found) {
+ return tx_pub_key;
+ } else {
+ throw std::runtime_error("Unsupported tx pub resolution");
+ }
+}
+
+static void setup_shim(hw::wallet_shim * shim)
+{
+ shim->get_tx_pub_key_from_received_outs = &get_tx_pub_key_from_received_outs;
+}
+
+bool get_short_payment_id(crypto::hash8 &payment_id8, const tools::wallet2::pending_tx &ptx, hw::device &hwdev)
+{
+ std::vector<tx_extra_field> tx_extra_fields;
+ parse_tx_extra(ptx.tx.extra, tx_extra_fields); // ok if partially parsed
+ cryptonote::tx_extra_nonce extra_nonce;
+ if (find_tx_extra_field_by_type(tx_extra_fields, extra_nonce))
+ {
+ if(get_encrypted_payment_id_from_tx_extra_nonce(extra_nonce.nonce, payment_id8))
+ {
+ if (ptx.dests.empty())
+ {
+ MWARNING("Encrypted payment id found, but no destinations public key, cannot decrypt");
+ return false;
+ }
+ return hwdev.decrypt_payment_id(payment_id8, ptx.dests[0].addr.m_view_public_key, ptx.tx_key);
+ }
+ }
+ return false;
+}
+
+static tools::wallet2::tx_construction_data get_construction_data_with_decrypted_short_payment_id(const tools::wallet2::pending_tx &ptx, hw::device &hwdev)
+{
+ tools::wallet2::tx_construction_data construction_data = ptx.construction_data;
+ crypto::hash8 payment_id = crypto::null_hash8;
+ if (get_short_payment_id(payment_id, ptx, hwdev))
+ {
+ // Remove encrypted
+ remove_field_from_tx_extra(construction_data.extra, typeid(cryptonote::tx_extra_nonce));
+ // Add decrypted
+ std::string extra_nonce;
+ set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, payment_id);
+ THROW_WALLET_EXCEPTION_IF(!add_extra_nonce_to_tx_extra(construction_data.extra, extra_nonce),
+ tools::error::wallet_internal_error, "Failed to add decrypted payment id to tx extra");
+ MDEBUG("Decrypted payment ID: " << payment_id);
+ }
+ return construction_data;
+}
+
+static std::string get_payment_id(const std::vector<uint8_t> &tx_extra)
+{
+ std::vector<cryptonote::tx_extra_field> tx_extra_fields;
+ cryptonote::parse_tx_extra(tx_extra, tx_extra_fields); // ok if partially parsed
+ cryptonote::tx_extra_nonce extra_nonce;
+
+ ::crypto::hash payment_id{};
+ if (find_tx_extra_field_by_type(tx_extra_fields, extra_nonce))
+ {
+ ::crypto::hash8 payment_id8{};
+ if(cryptonote::get_encrypted_payment_id_from_tx_extra_nonce(extra_nonce.nonce, payment_id8))
+ {
+ return std::string(payment_id8.data, 8);
+ }
+ else if (cryptonote::get_payment_id_from_tx_extra_nonce(extra_nonce.nonce, payment_id))
+ {
+ return std::string(payment_id.data, 32);
+ }
+ }
+ return std::string();
+}
+
+static crypto::hash8 to_short_payment_id(const std::string & payment_id)
+{
+ crypto::hash8 payment_id_short;
+ CHECK_AND_ASSERT_THROW_MES(payment_id.size() == 8, "Invalid argument");
+ memcpy(payment_id_short.data, payment_id.data(), 8);
+ return payment_id_short;
+}
+
+static crypto::hash to_long_payment_id(const std::string & payment_id)
+{
+ crypto::hash payment_id_long;
+ CHECK_AND_ASSERT_THROW_MES(payment_id.size() == 32, "Invalid argument");
+ memcpy(payment_id_long.data, payment_id.data(), 32);
+ return payment_id_long;
+}
+
+static std::vector<uint8_t> build_payment_id_extra(const std::string & payment_id)
+{
+ std::vector<uint8_t> res;
+
+ if (payment_id.size() == 8) {
+ std::string extra_nonce;
+ set_encrypted_payment_id_to_tx_extra_nonce(extra_nonce, to_short_payment_id(payment_id));
+ THROW_WALLET_EXCEPTION_IF(!add_extra_nonce_to_tx_extra(res, extra_nonce),
+ tools::error::wallet_internal_error, "Failed to add decrypted payment id to tx extra");
+
+ } else if (payment_id.size() == 32){
+ std::string extra_nonce;
+ set_payment_id_to_tx_extra_nonce(extra_nonce, to_long_payment_id(payment_id));
+ THROW_WALLET_EXCEPTION_IF(!add_extra_nonce_to_tx_extra(res, extra_nonce),
+ tools::error::wallet_internal_error, "Failed to add decrypted payment id to tx extra");
+ }
+
+ return res;
+}
+
+static cryptonote::address_parse_info init_addr_parse_info(cryptonote::account_public_address &addr, bool is_sub=false, boost::optional<crypto::hash8> payment_id = boost::none)
+{
+ cryptonote::address_parse_info res;
+ res.address = addr;
+ res.is_subaddress = is_sub;
+ if (payment_id){
+ res.has_payment_id = true;
+ res.payment_id = payment_id.get();
+ } else {
+ res.has_payment_id = false;
+ }
+ return res;
+}
+
+static void expand_tsx(cryptonote::transaction &tx)
+{
+ auto & rv = tx.rct_signatures;
+ if (rv.type == rct::RCTTypeFull)
+ {
+ rv.p.MGs.resize(1);
+ rv.p.MGs[0].II.resize(tx.vin.size());
+ for (size_t n = 0; n < tx.vin.size(); ++n)
+ rv.p.MGs[0].II[n] = rct::ki2rct(boost::get<txin_to_key>(tx.vin[n]).k_image);
+ }
+ else if (rv.type == rct::RCTTypeSimple || rv.type == rct::RCTTypeBulletproof || rv.type == rct::RCTTypeBulletproof2)
+ {
+ CHECK_AND_ASSERT_THROW_MES(rv.p.MGs.size() == tx.vin.size(), "Bad MGs size");
+ for (size_t n = 0; n < tx.vin.size(); ++n)
+ {
+ rv.p.MGs[n].II.resize(1);
+ rv.p.MGs[n].II[0] = rct::ki2rct(boost::get<txin_to_key>(tx.vin[n]).k_image);
+ }
+ }
+}
+
+static std::vector<tools::wallet2*> vct_wallets(tools::wallet2* w1=nullptr, tools::wallet2* w2=nullptr, tools::wallet2* w3=nullptr, tools::wallet2* w4=nullptr, tools::wallet2* w5=nullptr)
+{
+ std::vector<tools::wallet2*> res;
+ if (w1)
+ res.push_back(w1);
+ if (w2)
+ res.push_back(w2);
+ if (w3)
+ res.push_back(w3);
+ if (w4)
+ res.push_back(w4);
+ if (w5)
+ res.push_back(w5);
+ return res;
+}
+
+// gen_trezor_base
+const uint64_t gen_trezor_base::m_ts_start = 1338224400;
+const uint64_t gen_trezor_base::m_wallet_ts = m_ts_start - 60*60*24*4;
+const std::string gen_trezor_base::m_device_name = "Trezor:udp";
+const std::string gen_trezor_base::m_master_seed_str = "14821d0bc5659b24cafbc889dc4fc60785ee08b65d71c525f81eeaba4f3a570f";
+const std::string gen_trezor_base::m_device_seed = "permit universe parent weapon amused modify essay borrow tobacco budget walnut lunch consider gallery ride amazing frog forget treat market chapter velvet useless topple";
+const std::string gen_trezor_base::m_alice_spend_private = m_master_seed_str;
+const std::string gen_trezor_base::m_alice_view_private = "a6ccd4ac344a295d1387f8d18c81bdd394f1845de84188e204514ef9370fd403";
+
+gen_trezor_base::gen_trezor_base(){
+ m_rct_config = {rct::RangeProofPaddedBulletproof, 1};
+}
+
+gen_trezor_base::gen_trezor_base(const gen_trezor_base &other):
+ m_generator(other.m_generator), m_bt(other.m_bt), m_miner_account(other.m_miner_account),
+ m_bob_account(other.m_bob_account), m_alice_account(other.m_alice_account), m_eve_account(other.m_eve_account),
+ m_hard_forks(other.m_hard_forks), m_trezor(other.m_trezor), m_rct_config(other.m_rct_config)
+{
+
+}
+
+void gen_trezor_base::setup_args(const std::string & trezor_path, bool heavy_tests)
+{
+ m_trezor_path = trezor_path.empty() ? m_device_name : std::string("Trezor:") + trezor_path;
+ m_heavy_tests = heavy_tests;
+}
+
+void gen_trezor_base::setup_trezor()
+{
+ hw::device &hwdev = hw::get_device(m_trezor_path);
+ m_trezor = dynamic_cast<hw::trezor::device_trezor *>(&hwdev);
+ CHECK_AND_ASSERT_THROW_MES(m_trezor, "Dynamic cast failed");
+
+ m_trezor->set_debug(true); // debugging commands on Trezor (auto-confirm transactions)
+
+ CHECK_AND_ASSERT_THROW_MES(m_trezor->set_name(m_trezor_path), "Could not set device name " << m_trezor_path);
+ m_trezor->set_network_type(MAINNET);
+ m_trezor->set_derivation_path(""); // empty derivation path
+
+ CHECK_AND_ASSERT_THROW_MES(m_trezor->init(), "Could not initialize the device " << m_trezor_path);
+ CHECK_AND_ASSERT_THROW_MES(m_trezor->connect(), "Could not connect to the device " << m_trezor_path);
+ m_trezor->wipe_device();
+ m_trezor->load_device(m_device_seed);
+ m_trezor->release();
+ m_trezor->disconnect();
+}
+
+void gen_trezor_base::fork(gen_trezor_base & other)
+{
+ other.m_generator = m_generator;
+ other.m_bt = m_bt;
+ other.m_events = m_events;
+ other.m_head = m_head;
+ other.m_hard_forks = m_hard_forks;
+ other.m_trezor_path = m_trezor_path;
+ other.m_heavy_tests = m_heavy_tests;
+ other.m_rct_config = m_rct_config;
+
+ other.m_miner_account = m_miner_account;
+ other.m_bob_account = m_bob_account;
+ other.m_alice_account = m_alice_account;
+ other.m_eve_account = m_eve_account;
+ other.m_trezor = m_trezor;
+}
+
+void gen_trezor_base::clear()
+{
+ m_generator = test_generator();
+ m_bt = block_tracker();
+ m_events.clear();
+ m_hard_forks.clear();
+ m_trezor = nullptr;
+}
+
+void gen_trezor_base::add_shared_events(std::vector<test_event_entry>& events)
+{
+ events.reserve(m_events.size());
+ for(const test_event_entry & c : m_events){
+ events.push_back(c);
+ }
+}
+
+void gen_trezor_base::init_fields()
+{
+ m_miner_account.generate();
+ DEFAULT_HARDFORKS(m_hard_forks);
+
+ crypto::secret_key master_seed{};
+ CHECK_AND_ASSERT_THROW_MES(epee::string_tools::hex_to_pod(m_master_seed_str, master_seed), "Hexdecode fails");
+
+ m_alice_account.generate(master_seed, true);
+ m_alice_account.set_createtime(m_wallet_ts);
+}
+
+bool gen_trezor_base::generate(std::vector<test_event_entry>& events)
+{
+ init_fields();
+ setup_trezor();
+ m_alice_account.create_from_device(*m_trezor);
+ m_alice_account.set_createtime(m_wallet_ts);
+
+ // Events, custom genesis so it matches wallet genesis
+ auto & generator = m_generator; // macro shortcut
+
+ cryptonote::block blk_gen;
+ std::vector<size_t> block_weights;
+ generate_genesis_block(blk_gen, get_config(MAINNET).GENESIS_TX, get_config(MAINNET).GENESIS_NONCE);
+ events.push_back(blk_gen);
+ generator.add_block(blk_gen, 0, block_weights, 0);
+
+ // First event has to be the genesis block
+ m_bob_account.generate();
+ m_eve_account.generate();
+ m_bob_account.set_createtime(m_wallet_ts);
+ m_eve_account.set_createtime(m_wallet_ts);
+ cryptonote::account_base * accounts[] = {TREZOR_ACCOUNT_ORDERING};
+ for(cryptonote::account_base * ac : accounts){
+ events.push_back(*ac);
+ }
+
+ // Another block with predefined timestamp.
+ // Carefully set reward and already generated coins so it passes miner_tx check.
+ cryptonote::block blk_0;
+ {
+ std::list<cryptonote::transaction> tx_list;
+ const crypto::hash prev_id = get_block_hash(blk_gen);
+ const uint64_t already_generated_coins = generator.get_already_generated_coins(prev_id);
+ block_weights.clear();
+ generator.get_last_n_block_weights(block_weights, prev_id, CRYPTONOTE_REWARD_BLOCKS_WINDOW);
+ generator.construct_block(blk_0, 1, prev_id, m_miner_account, m_ts_start, already_generated_coins, block_weights, tx_list);
+ }
+
+ events.push_back(blk_0);
+ MDEBUG("Gen+1 block has time: " << blk_0.timestamp << " blid: " << get_block_hash(blk_0));
+
+ // Generate some spendable funds on the Miner account
+ REWIND_BLOCKS_N(events, blk_3, blk_0, m_miner_account, 40);
+
+ // Rewind so the miners funds are unlocked for initial transactions.
+ REWIND_BLOCKS(events, blk_3r, blk_3, m_miner_account);
+
+ // Non-rct transactions Miner -> Bob
+ MAKE_TX_LIST_START(events, txs_blk_4, m_miner_account, m_alice_account, MK_COINS(10), blk_3);
+ MAKE_TX_LIST(events, txs_blk_4, m_miner_account, m_alice_account, MK_COINS(7), blk_3);
+ MAKE_TX_LIST(events, txs_blk_4, m_miner_account, m_alice_account, MK_COINS(7), blk_3);
+ MAKE_TX_LIST(events, txs_blk_4, m_miner_account, m_alice_account, MK_COINS(14), blk_3);
+ MAKE_TX_LIST(events, txs_blk_4, m_miner_account, m_alice_account, MK_COINS(20), blk_3);
+ MAKE_TX_LIST(events, txs_blk_4, m_miner_account, m_alice_account, MK_COINS(2), blk_3);
+ MAKE_TX_LIST(events, txs_blk_4, m_miner_account, m_alice_account, MK_COINS(2), blk_3);
+ MAKE_TX_LIST(events, txs_blk_4, m_miner_account, m_alice_account, MK_COINS(5), blk_3);
+ MAKE_NEXT_BLOCK_TX_LIST(events, blk_4, blk_3r, m_miner_account, txs_blk_4);
+ REWIND_BLOCKS(events, blk_4r, blk_4, m_miner_account); // rewind to unlock
+
+ // Hard fork to bulletproofs version, v9.
+ const uint8_t CUR_HF = 9;
+ auto hardfork_height = num_blocks(events); // next block is v9
+ ADD_HARDFORK(m_hard_forks, CUR_HF, hardfork_height);
+ add_hforks(events, m_hard_forks);
+ MDEBUG("Hardfork height: " << hardfork_height << " at block: " << get_block_hash(blk_4r));
+
+ // RCT transactions, wallets have to be used, wallet init
+ m_wl_alice.reset(new tools::wallet2(MAINNET, 1, true));
+ m_wl_bob.reset(new tools::wallet2(MAINNET, 1, true));
+ wallet_accessor_test::set_account(m_wl_alice.get(), m_alice_account);
+ wallet_accessor_test::set_account(m_wl_bob.get(), m_bob_account);
+
+ auto addr_alice_sub_0_1 = m_wl_alice->get_subaddress({0, 1});
+ auto addr_alice_sub_0_2 = m_wl_alice->get_subaddress({0, 2});
+ auto addr_alice_sub_0_3 = m_wl_alice->get_subaddress({0, 3});
+ auto addr_alice_sub_0_4 = m_wl_alice->get_subaddress({0, 4});
+ auto addr_alice_sub_0_5 = m_wl_alice->get_subaddress({0, 5});
+ auto addr_alice_sub_1_0 = m_wl_alice->get_subaddress({1, 0});
+ auto addr_alice_sub_1_1 = m_wl_alice->get_subaddress({1, 1});
+ auto addr_alice_sub_1_2 = m_wl_alice->get_subaddress({1, 2});
+
+ // Miner -> Bob, RCT funds
+ MAKE_TX_LIST_START_RCT(events, txs_blk_5, m_miner_account, m_alice_account, MK_COINS(5), 10, blk_4);
+
+ const size_t target_rct = m_heavy_tests ? 105 : 15;
+ for(size_t i = 0; i < target_rct; ++i)
+ {
+ MAKE_TX_MIX_LIST_RCT(events, txs_blk_5, m_miner_account, m_alice_account, MK_COINS(1) >> 2, 10, blk_4);
+ }
+
+ // Sub-address destinations
+ MAKE_TX_MIX_DEST_LIST_RCT(events, txs_blk_5, m_miner_account, build_dsts(addr_alice_sub_0_1, true, MK_COINS(1) >> 1), 10, blk_4);
+ MAKE_TX_MIX_DEST_LIST_RCT(events, txs_blk_5, m_miner_account, build_dsts(addr_alice_sub_0_2, true, MK_COINS(1) >> 1), 10, blk_4);
+ MAKE_TX_MIX_DEST_LIST_RCT(events, txs_blk_5, m_miner_account, build_dsts(addr_alice_sub_0_3, true, MK_COINS(1) >> 1), 10, blk_4);
+ MAKE_TX_MIX_DEST_LIST_RCT(events, txs_blk_5, m_miner_account, build_dsts(addr_alice_sub_0_4, true, MK_COINS(1) >> 1), 10, blk_4);
+
+ // Sub-address destinations + multi out to force use of additional keys
+ MAKE_TX_MIX_DEST_LIST_RCT(events, txs_blk_5, m_miner_account, build_dsts({{addr_alice_sub_0_1, true, MK_COINS(1) >> 1}, {addr_alice_sub_0_2, true, MK_COINS(1) >> 1}}), 10, blk_4);
+ MAKE_TX_MIX_DEST_LIST_RCT(events, txs_blk_5, m_miner_account, build_dsts({{addr_alice_sub_0_1, true, MK_COINS(1) >> 1}, {addr_alice_sub_0_2, true, MK_COINS(1) >> 1}, {addr_alice_sub_0_3, true, MK_COINS(1) >> 1}}), 10, blk_4);
+ MAKE_TX_MIX_DEST_LIST_RCT(events, txs_blk_5, m_miner_account, build_dsts({{m_miner_account, false, MK_COINS(1) >> 1}, {addr_alice_sub_0_2, true, MK_COINS(1) >> 1}, {addr_alice_sub_0_3, true, MK_COINS(1) >> 1}}), 10, blk_4);
+ MAKE_TX_MIX_DEST_LIST_RCT(events, txs_blk_5, m_miner_account, build_dsts({{m_miner_account, false, MK_COINS(1) >> 1}, {addr_alice_sub_0_2, true, MK_COINS(1) >> 1}, {addr_alice_sub_0_3, true, MK_COINS(1) >> 1}}), 10, blk_4);
+
+ // Transfer to other accounts
+ MAKE_TX_MIX_DEST_LIST_RCT(events, txs_blk_5, m_miner_account, build_dsts(addr_alice_sub_1_0, true, MK_COINS(1) >> 1), 10, blk_4);
+ MAKE_TX_MIX_DEST_LIST_RCT(events, txs_blk_5, m_miner_account, build_dsts(addr_alice_sub_1_1, true, MK_COINS(1) >> 1), 10, blk_4);
+ MAKE_TX_MIX_DEST_LIST_RCT(events, txs_blk_5, m_miner_account, build_dsts({{addr_alice_sub_1_0, true, MK_COINS(1) >> 1}, {addr_alice_sub_1_1, true, MK_COINS(1) >> 1}, {addr_alice_sub_0_3, true, MK_COINS(1) >> 1}}), 10, blk_4);
+ MAKE_TX_MIX_DEST_LIST_RCT(events, txs_blk_5, m_miner_account, build_dsts({{addr_alice_sub_1_1, true, MK_COINS(1) >> 1}, {addr_alice_sub_1_1, true, MK_COINS(1) >> 1}, {addr_alice_sub_0_2, true, MK_COINS(1) >> 1}}), 10, blk_4);
+ MAKE_TX_MIX_DEST_LIST_RCT(events, txs_blk_5, m_miner_account, build_dsts({{addr_alice_sub_1_2, true, MK_COINS(1) >> 1}, {addr_alice_sub_1_1, true, MK_COINS(1) >> 1}, {addr_alice_sub_0_5, true, MK_COINS(1) >> 1}}), 10, blk_4);
+
+ // Simple RCT transactions
+ MAKE_TX_MIX_LIST_RCT(events, txs_blk_5, m_miner_account, m_alice_account, MK_COINS(7), 10, blk_4);
+ MAKE_TX_MIX_LIST_RCT(events, txs_blk_5, m_miner_account, m_alice_account, MK_COINS(1), 10, blk_4);
+ MAKE_TX_MIX_LIST_RCT(events, txs_blk_5, m_miner_account, m_alice_account, MK_COINS(3), 10, blk_4);
+ MAKE_TX_MIX_LIST_RCT(events, txs_blk_5, m_miner_account, m_alice_account, MK_COINS(4), 10, blk_4);
+ MAKE_NEXT_BLOCK_TX_LIST_HF(events, blk_5, blk_4r, m_miner_account, txs_blk_5, CUR_HF);
+
+ // Simple transaction check
+ bool resx = rct::verRctSemanticsSimple(txs_blk_5.begin()->rct_signatures);
+ bool resy = rct::verRctNonSemanticsSimple(txs_blk_5.begin()->rct_signatures);
+ CHECK_AND_ASSERT_THROW_MES(resx, "Tsx5[0] semantics failed");
+ CHECK_AND_ASSERT_THROW_MES(resy, "Tsx5[0] non-semantics failed");
+
+ REWIND_BLOCKS_HF(events, blk_5r, blk_5, m_miner_account, CUR_HF); // rewind to unlock
+
+ // RCT transactions, wallets have to be used
+ wallet_tools::process_transactions(m_wl_alice.get(), events, blk_5r, m_bt);
+ wallet_tools::process_transactions(m_wl_bob.get(), events, blk_5r, m_bt);
+
+ // Send Alice -> Bob, manually constructed. Simple TX test, precondition.
+ cryptonote::transaction tx_1;
+ std::vector<size_t> selected_transfers;
+ std::vector<tx_source_entry> sources;
+ bool res = wallet_tools::fill_tx_sources(m_wl_alice.get(), sources, TREZOR_TEST_MIXIN, boost::none, MK_COINS(2), m_bt, selected_transfers, num_blocks(events) - 1, 0, 1);
+ CHECK_AND_ASSERT_THROW_MES(res, "TX Fill sources failed");
+
+ construct_tx_to_key(tx_1, m_wl_alice.get(), m_bob_account, MK_COINS(1), sources, TREZOR_TEST_FEE, true, rct::RangeProofPaddedBulletproof, 1);
+ events.push_back(tx_1);
+ MAKE_NEXT_BLOCK_TX1_HF(events, blk_6, blk_5r, m_miner_account, tx_1, CUR_HF);
+ MDEBUG("Post 1st tsx: " << (num_blocks(events) - 1) << " at block: " << get_block_hash(blk_6));
+
+ // Simple transaction check
+ resx = rct::verRctSemanticsSimple(tx_1.rct_signatures);
+ resy = rct::verRctNonSemanticsSimple(tx_1.rct_signatures);
+ CHECK_AND_ASSERT_THROW_MES(resx, "tx_1 semantics failed");
+ CHECK_AND_ASSERT_THROW_MES(resy, "tx_1 non-semantics failed");
+
+ REWIND_BLOCKS_HF(events, blk_6r, blk_6, m_miner_account, CUR_HF);
+ m_head = blk_6r;
+ m_events = events;
+ return true;
+}
+
+void gen_trezor_base::load(std::vector<test_event_entry>& events)
+{
+ init_fields();
+ m_events = events;
+
+ unsigned acc_idx = 0;
+ cryptonote::account_base * accounts[] = {TREZOR_ACCOUNT_ORDERING};
+ unsigned accounts_num = (sizeof(accounts) / sizeof(accounts[0]));
+
+ for(auto & ev : events)
+ {
+ if (typeid(cryptonote::block) == ev.type())
+ {
+ m_head = boost::get<cryptonote::block>(ev);
+ }
+ else if (typeid(cryptonote::account_base) == ev.type()) // accounts
+ {
+ const auto & acc = boost::get<cryptonote::account_base>(ev);
+ if (acc_idx < accounts_num)
+ {
+ *accounts[acc_idx++] = acc;
+ }
+ }
+ else if (typeid(event_replay_settings) == ev.type()) // hard forks
+ {
+ const auto & rep_settings = boost::get<event_replay_settings>(ev);
+ if (rep_settings.hard_forks)
+ {
+ const auto & hf = rep_settings.hard_forks.get();
+ std::copy(hf.begin(), hf.end(), std::back_inserter(m_hard_forks));
+ }
+ }
+ }
+
+ // Setup wallets, synchronize blocks
+ m_bob_account.set_createtime(m_wallet_ts);
+ m_eve_account.set_createtime(m_wallet_ts);
+
+ setup_trezor();
+ m_alice_account.create_from_device(*m_trezor);
+ m_alice_account.set_createtime(m_wallet_ts);
+
+ m_wl_alice.reset(new tools::wallet2(MAINNET, 1, true));
+ m_wl_bob.reset(new tools::wallet2(MAINNET, 1, true));
+ m_wl_eve.reset(new tools::wallet2(MAINNET, 1, true));
+ wallet_accessor_test::set_account(m_wl_alice.get(), m_alice_account);
+ wallet_accessor_test::set_account(m_wl_bob.get(), m_bob_account);
+ wallet_accessor_test::set_account(m_wl_eve.get(), m_eve_account);
+
+ wallet_tools::process_transactions(m_wl_alice.get(), events, m_head, m_bt);
+ wallet_tools::process_transactions(m_wl_bob.get(), events, m_head, m_bt);
+}
+
+void gen_trezor_base::fix_hf(std::vector<test_event_entry>& events)
+{
+ // If current test requires higher hard-fork, move it up
+ const auto current_hf = m_hard_forks.back().first;
+ if (m_rct_config.bp_version == 2 && current_hf < 10){
+ auto hardfork_height = num_blocks(events);
+ ADD_HARDFORK(m_hard_forks, 10, hardfork_height);
+ add_top_hfork(events, m_hard_forks);
+ MDEBUG("Hardfork height: " << hardfork_height);
+ }
+}
+
+void gen_trezor_base::update_trackers(std::vector<test_event_entry>& events)
+{
+ wallet_tools::process_transactions(nullptr, events, m_head, m_bt);
+}
+
+void gen_trezor_base::test_setup(std::vector<test_event_entry>& events)
+{
+ add_shared_events(events);
+
+ setup_trezor();
+ m_alice_account.create_from_device(*m_trezor);
+ m_alice_account.set_createtime(m_wallet_ts);
+
+ m_wl_alice.reset(new tools::wallet2(MAINNET, 1, true));
+ m_wl_bob.reset(new tools::wallet2(MAINNET, 1, true));
+ m_wl_eve.reset(new tools::wallet2(MAINNET, 1, true));
+ wallet_accessor_test::set_account(m_wl_alice.get(), m_alice_account);
+ wallet_accessor_test::set_account(m_wl_bob.get(), m_bob_account);
+ wallet_accessor_test::set_account(m_wl_eve.get(), m_eve_account);
+ wallet_tools::process_transactions(m_wl_alice.get(), events, m_head, m_bt);
+ wallet_tools::process_transactions(m_wl_bob.get(), events, m_head, m_bt);
+ wallet_tools::process_transactions(m_wl_eve.get(), events, m_head, m_bt);
+}
+
+void gen_trezor_base::test_trezor_tx(std::vector<test_event_entry>& events, std::vector<tools::wallet2::pending_tx>& ptxs, std::vector<cryptonote::address_parse_info>& dsts_info, test_generator &generator, std::vector<tools::wallet2*> wallets, bool is_sweep)
+{
+ // Construct pending transaction for signature in the Trezor.
+ const uint64_t height_pre = num_blocks(events) - 1;
+ cryptonote::block head_block = get_head_block(events);
+ const crypto::hash head_hash = get_block_hash(head_block);
+
+ // If current test requires higher hard-fork, move it up
+ const auto current_hf = m_hard_forks.back().first;
+ const uint8_t tx_hf = m_rct_config.bp_version == 2 ? 10 : 9;
+ if (tx_hf > current_hf){
+ throw std::runtime_error("Too late for HF change");
+ }
+
+ tools::wallet2::unsigned_tx_set txs;
+ std::list<cryptonote::transaction> tx_list;
+
+ for(auto &ptx : ptxs) {
+ txs.txes.push_back(get_construction_data_with_decrypted_short_payment_id(ptx, *m_trezor));
+ }
+ txs.transfers = std::make_pair(0, wallet_accessor_test::get_transfers(m_wl_alice.get()));
+
+ auto dev_cold = dynamic_cast<::hw::device_cold*>(m_trezor);
+ CHECK_AND_ASSERT_THROW_MES(dev_cold, "Device does not implement cold signing interface");
+
+ tools::wallet2::signed_tx_set exported_txs;
+ hw::tx_aux_data aux_data;
+ hw::wallet_shim wallet_shim;
+ setup_shim(&wallet_shim);
+ aux_data.tx_recipients = dsts_info;
+ dev_cold->tx_sign(&wallet_shim, txs, exported_txs, aux_data);
+
+ MDEBUG("Signed tx data from hw: " << exported_txs.ptx.size() << " transactions");
+ CHECK_AND_ASSERT_THROW_MES(exported_txs.ptx.size() == ptxs.size(), "Invalid transaction sizes");
+
+ for (size_t i = 0; i < exported_txs.ptx.size(); ++i){
+ auto &c_ptx = exported_txs.ptx[i];
+ c_ptx.tx.rct_signatures.mixRing = ptxs[i].tx.rct_signatures.mixRing;
+ expand_tsx(c_ptx.tx);
+
+ // Simple TX tests, more complex are performed in the core.
+ MTRACE(cryptonote::obj_to_json_str(c_ptx.tx));
+ bool resx = rct::verRctSemanticsSimple(c_ptx.tx.rct_signatures);
+ bool resy = rct::verRctNonSemanticsSimple(c_ptx.tx.rct_signatures);
+ CHECK_AND_ASSERT_THROW_MES(resx, "Trezor tx_1 semantics failed");
+ CHECK_AND_ASSERT_THROW_MES(resy, "Trezor tx_1 Nonsemantics failed");
+
+ events.push_back(c_ptx.tx);
+ tx_list.push_back(c_ptx.tx);
+ MDEBUG("Transaction: " << dump_data(c_ptx.tx));
+ }
+
+ MAKE_NEXT_BLOCK_TX_LIST_HF(events, blk_7, m_head, m_miner_account, tx_list, tx_hf);
+ MDEBUG("Trezor tsx: " << (num_blocks(events) - 1) << " at block: " << get_block_hash(blk_7));
+
+ // TX receive test
+ uint64_t sum_in = 0;
+ uint64_t sum_out = 0;
+
+ for(size_t txid = 0; txid < exported_txs.ptx.size(); ++txid) {
+ auto &c_ptx = exported_txs.ptx[txid];
+ auto &c_tx = c_ptx.tx;
+ const crypto::hash txhash = cryptonote::get_transaction_hash(c_tx);
+ const size_t num_outs = c_tx.vout.size();
+ size_t num_received = 0;
+ uint64_t cur_sum_in = 0;
+ uint64_t cur_sum_out = 0;
+ uint64_t cur_sum_out_recv = 0;
+ std::unordered_set<size_t> recv_out_idx;
+ std::string exp_payment_id = get_payment_id(c_ptx.construction_data.extra);
+ std::string enc_payment_id = get_payment_id(c_tx.extra);
+ size_t num_payment_id_checks_done = 0;
+
+ CHECK_AND_ASSERT_THROW_MES(exp_payment_id.empty() || exp_payment_id.size() == 8 || exp_payment_id.size() == 32, "Required payment ID invalid");
+ CHECK_AND_ASSERT_THROW_MES((exp_payment_id.size() == 32) == (enc_payment_id.size() == 32), "Required and built payment ID size mismatch");
+ CHECK_AND_ASSERT_THROW_MES(exp_payment_id.size() <= enc_payment_id.size(), "Required and built payment ID size mismatch");
+
+ for(auto &src : c_ptx.construction_data.sources){
+ cur_sum_in += src.amount;
+ }
+
+ for(auto &dst : c_ptx.construction_data.splitted_dsts){
+ cur_sum_out += dst.amount;
+ }
+
+ CHECK_AND_ASSERT_THROW_MES(c_tx.rct_signatures.txnFee + cur_sum_out == cur_sum_in, "Tx Input Output amount mismatch");
+
+ for (size_t widx = 0; widx < wallets.size(); ++widx) {
+ const bool sender = widx == 0;
+ tools::wallet2 *wl = wallets[widx];
+
+ wallet_tools::process_transactions(wl, events, blk_7, m_bt, boost::make_optional(head_hash));
+
+ tools::wallet2::transfer_container m_trans;
+ tools::wallet2::transfer_container m_trans_txid;
+ wl->get_transfers(m_trans);
+
+ std::copy_if(m_trans.begin(), m_trans.end(), std::back_inserter(m_trans_txid), [&txhash](const tools::wallet2::transfer_details& item) {
+ return item.m_txid == txhash;
+ });
+
+ // Testing if the transaction output has been received
+ num_received += m_trans_txid.size();
+ for (auto & ctran : m_trans_txid){
+ cur_sum_out_recv += ctran.amount();
+ recv_out_idx.insert(ctran.m_internal_output_index);
+ CHECK_AND_ASSERT_THROW_MES(!ctran.m_spent, "Txout is spent");
+ CHECK_AND_ASSERT_THROW_MES(!sender || ctran.m_key_image_known, "Key Image unknown for recipient"); // sender is Trezor, does not need to have KI
+ }
+
+ // Sender output payment (contains change and stuff)
+ if (sender) {
+ std::list<std::pair<crypto::hash, tools::wallet2::confirmed_transfer_details>> confirmed_transfers; // txid -> tdetail
+ std::list<std::pair<crypto::hash, tools::wallet2::confirmed_transfer_details>> confirmed_transfers_txid; // txid -> tdetail
+ wl->get_payments_out(confirmed_transfers, height_pre);
+
+ std::copy_if(confirmed_transfers.begin(), confirmed_transfers.end(), std::back_inserter(confirmed_transfers_txid), [&txhash](const std::pair<crypto::hash, tools::wallet2::confirmed_transfer_details>& item) {
+ return item.first == txhash;
+ });
+
+ CHECK_AND_ASSERT_THROW_MES(confirmed_transfers_txid.size() == 1, "Sender does not have outgoing transfer for the transaction");
+ }
+
+ // Received payment from the block
+ std::list<std::pair<crypto::hash, tools::wallet2::payment_details>> payments; // payment id -> [payment details] multimap
+ std::list<std::pair<crypto::hash, tools::wallet2::payment_details>> payments_txid; // payment id -> [payment details] multimap
+ wl->get_payments(payments, height_pre);
+
+ std::copy_if(payments.begin(), payments.end(), std::back_inserter(payments_txid), [&txhash](const std::pair<crypto::hash, tools::wallet2::payment_details>& item) {
+ return item.second.m_tx_hash == txhash;
+ });
+
+ for(auto &paydet : payments_txid){
+ CHECK_AND_ASSERT_THROW_MES(exp_payment_id.empty() || (memcmp(exp_payment_id.data(), paydet.first.data, exp_payment_id.size()) == 0), "Payment ID mismatch");
+ num_payment_id_checks_done += 1;
+ }
+ }
+
+ CHECK_AND_ASSERT_THROW_MES(c_tx.rct_signatures.txnFee + cur_sum_out_recv == cur_sum_in, "Tx Input Output amount mismatch");
+ CHECK_AND_ASSERT_THROW_MES(exp_payment_id.empty() || num_payment_id_checks_done > 0, "No Payment ID checks");
+
+ if(!is_sweep){
+ CHECK_AND_ASSERT_THROW_MES(num_received == num_outs, "Number of received outputs do not match number of outgoing");
+ CHECK_AND_ASSERT_THROW_MES(recv_out_idx.size() == num_outs, "Num of outs received do not match");
+ } else {
+ CHECK_AND_ASSERT_THROW_MES(num_received + 1 >= num_outs, "Number of received outputs do not match number of outgoing");
+ CHECK_AND_ASSERT_THROW_MES(recv_out_idx.size() + 1 >= num_outs, "Num of outs received do not match"); // can have dummy out
+ }
+
+ sum_in += cur_sum_in;
+ sum_out += cur_sum_out + c_tx.rct_signatures.txnFee;
+ }
+
+ CHECK_AND_ASSERT_THROW_MES(sum_in == sum_out, "Tx amount mismatch");
+}
+
+#define TREZOR_TEST_PREFIX() \
+ test_generator generator(m_generator); \
+ test_setup(events); \
+ tsx_builder t_builder_o(this); \
+ tsx_builder * t_builder = &t_builder_o
+
+#define TREZOR_TEST_SUFFIX() \
+ auto _dsts = t_builder->build(); \
+ auto _dsts_info = t_builder->dest_info(); \
+ test_trezor_tx(events, _dsts, _dsts_info, generator, vct_wallets(m_wl_alice.get(), m_wl_bob.get(), m_wl_eve.get())); \
+ return true
+
+#define TREZOR_SKIP_IF_VERSION_LEQ(x) if (m_trezor->get_version() <= x) { MDEBUG("Test skipped"); return true; }
+#define TREZOR_TEST_PAYMENT_ID "\xde\xad\xc0\xde\xde\xad\xc0\xde"
+#define TREZOR_TEST_PAYMENT_ID_LONG "\xde\xad\xc0\xde\xde\xad\xc0\xde\xde\xad\xc0\xde\xde\xad\xc0\xde\xde\xad\xc0\xde\xde\xad\xc0\xde\xde\xad\xc0\xde\xde\xad\xc0\xde"
+
+tsx_builder * tsx_builder::sources(std::vector<cryptonote::tx_source_entry> & sources, std::vector<size_t> & selected_transfers)
+{
+ m_sources = sources;
+ m_selected_transfers = selected_transfers;
+ return this;
+}
+
+tsx_builder * tsx_builder::compute_sources(boost::optional<size_t> num_utxo, boost::optional<uint64_t> min_amount, ssize_t offset, int step, boost::optional<fnc_accept_tx_source_t> fnc_accept)
+{
+ CHECK_AND_ASSERT_THROW_MES(m_tester, "m_tester wallet empty");
+ CHECK_AND_ASSERT_THROW_MES(m_from, "m_from wallet empty");
+
+ // typedef std::function<bool(const tx_source_info_crate_t &info, bool &abort)> fnc_accept_tx_source_t;
+ boost::optional<fnc_accept_tx_source_t> fnc_accept_to_use = boost::none;
+
+ auto c_account = m_account;
+ fnc_accept_tx_source_t fnc_acc = [c_account, &fnc_accept] (const tx_source_info_crate_t &info, bool &abort) -> bool {
+ if (info.td->m_subaddr_index.major != c_account){
+ return false;
+ }
+ if (fnc_accept){
+ return (fnc_accept.get())(info, abort);
+ }
+ return true;
+ };
+
+ fnc_accept_to_use = fnc_acc;
+ bool res = wallet_tools::fill_tx_sources(m_from, m_sources, m_mixin, num_utxo, min_amount, m_tester->m_bt, m_selected_transfers, m_cur_height, offset, step, fnc_accept_to_use);
+ CHECK_AND_ASSERT_THROW_MES(res, "Tx source fill error");
+ return this;
+}
+
+tsx_builder * tsx_builder::compute_sources_to_sub(boost::optional<size_t> num_utxo, boost::optional<uint64_t> min_amount, ssize_t offset, int step, boost::optional<fnc_accept_tx_source_t> fnc_accept)
+{
+ fnc_accept_tx_source_t fnc = [&fnc_accept] (const tx_source_info_crate_t &info, bool &abort) -> bool {
+ if (info.td->m_subaddr_index.minor == 0){
+ return false;
+ }
+ if (fnc_accept){
+ return (fnc_accept.get())(info, abort);
+ }
+ return true;
+ };
+
+ return compute_sources(num_utxo, min_amount, offset, step, fnc);
+}
+
+tsx_builder * tsx_builder::compute_sources_to_sub_acc(boost::optional<size_t> num_utxo, boost::optional<uint64_t> min_amount, ssize_t offset, int step, boost::optional<fnc_accept_tx_source_t> fnc_accept)
+{
+ fnc_accept_tx_source_t fnc = [&fnc_accept] (const tx_source_info_crate_t &info, bool &abort) -> bool {
+ if (info.td->m_subaddr_index.minor == 0 || info.src->real_out_additional_tx_keys.size() == 0){
+ return false;
+ }
+ if (fnc_accept){
+ return (fnc_accept.get())(info, abort);
+ }
+ return true;
+ };
+
+ return compute_sources(num_utxo, min_amount, offset, step, fnc);
+}
+
+tsx_builder * tsx_builder::destinations(std::vector<cryptonote::tx_destination_entry> &dsts)
+{
+ m_destinations_orig = dsts;
+ return this;
+}
+
+tsx_builder * tsx_builder::add_destination(const cryptonote::tx_destination_entry &dst)
+{
+ m_destinations_orig.push_back(dst);
+ return this;
+}
+
+tsx_builder * tsx_builder::add_destination(const var_addr_t addr, bool is_subaddr, uint64_t amount)
+{
+ m_destinations_orig.push_back(build_dst(addr, is_subaddr, amount));
+ return this;
+}
+
+tsx_builder * tsx_builder::add_destination(const tools::wallet2 * wallet, bool is_subaddr, uint64_t amount)
+{
+ m_destinations_orig.push_back(build_dst(get_address(wallet), is_subaddr, amount));
+ return this;
+}
+
+tsx_builder * tsx_builder::set_integrated(size_t idx)
+{
+ m_integrated.insert(idx);
+ return this;
+}
+
+tsx_builder * tsx_builder::clear_current()
+{
+ m_account = 0;
+ m_selected_transfers.clear();
+ m_sources.clear();
+ m_destinations.clear();
+ m_destinations_orig.clear();
+ m_dsts_info.clear();
+ m_integrated.clear();
+ m_payment_id.clear();
+ return this;
+}
+
+tsx_builder * tsx_builder::build_tx()
+{
+ CHECK_AND_ASSERT_THROW_MES(m_tester, "m_tester wallet empty");
+ CHECK_AND_ASSERT_THROW_MES(m_from, "m_from wallet empty");
+
+ // Amount sanity check input >= fee + outputs
+ const uint64_t out_amount = sum_amount(m_destinations_orig);
+ const uint64_t in_amount = sum_amount(m_sources);
+ CHECK_AND_ASSERT_THROW_MES(in_amount >= out_amount + m_fee, "Not enough input credits for outputs and fees");
+
+ // Create new pending transaction, init with sources and destinations
+ m_ptxs.emplace_back();
+ auto & ptx = m_ptxs.back();
+
+ std::vector<uint8_t> extra = build_payment_id_extra(m_payment_id);
+ fill_tx_destinations(m_from->get_subaddress({m_account, 0}), m_destinations_orig, m_fee, m_sources, m_destinations, true);
+ construct_pending_tx(ptx, extra);
+
+ ptx.construction_data.subaddr_account = m_account;
+
+ // Build destinations parse info
+ for(size_t i = 0; i < m_destinations_orig.size(); ++i){
+ auto & cdest = m_destinations_orig[i];
+ cryptonote::address_parse_info info = init_addr_parse_info(cdest.addr, cdest.is_subaddress);
+ if (m_integrated.find(i) != m_integrated.end()){
+ CHECK_AND_ASSERT_THROW_MES(m_payment_id.size() == 8, "Integrated set but payment_id.size() != 8");
+ info.has_payment_id = true;
+ info.payment_id = to_short_payment_id(m_payment_id);
+ }
+
+ m_dsts_info.push_back(info);
+ }
+
+ return this;
+}
+
+tsx_builder * tsx_builder::construct_pending_tx(tools::wallet2::pending_tx &ptx, boost::optional<std::vector<uint8_t>> extra)
+{
+ CHECK_AND_ASSERT_THROW_MES(m_from, "Wallet not provided");
+
+ cryptonote::transaction tx;
+ subaddresses_t & subaddresses = wallet_accessor_test::get_subaddresses(m_from);
+ crypto::secret_key tx_key;
+ std::vector<crypto::secret_key> additional_tx_keys;
+ std::vector<tx_destination_entry> destinations_copy = m_destinations;
+
+ auto change_addr = m_from->get_account().get_keys().m_account_address;
+ bool r = construct_tx_and_get_tx_key(m_from->get_account().get_keys(), subaddresses, m_sources, destinations_copy,
+ change_addr, extra ? extra.get() : std::vector<uint8_t>(), tx, 0, tx_key,
+ additional_tx_keys, true, m_rct_config, nullptr);
+
+ CHECK_AND_ASSERT_THROW_MES(r, "Transaction construction failed");
+
+ ptx.key_images = "";
+ ptx.fee = TESTS_DEFAULT_FEE;
+ ptx.dust = 0;
+ ptx.dust_added_to_fee = false;
+ ptx.tx = tx;
+ ptx.change_dts = m_destinations.back();
+ ptx.selected_transfers = m_selected_transfers;
+ ptx.tx_key = tx_key;
+ ptx.additional_tx_keys = additional_tx_keys;
+ ptx.dests = m_destinations;
+ ptx.multisig_sigs.clear();
+ ptx.construction_data.sources = m_sources;
+ ptx.construction_data.change_dts = m_destinations.back();
+ ptx.construction_data.splitted_dsts = m_destinations;
+ ptx.construction_data.selected_transfers = ptx.selected_transfers;
+ ptx.construction_data.extra = tx.extra;
+ ptx.construction_data.unlock_time = 0;
+ ptx.construction_data.use_rct = true;
+ ptx.construction_data.use_bulletproofs = true;
+ ptx.construction_data.dests = m_destinations_orig;
+
+ ptx.construction_data.subaddr_account = 0;
+ ptx.construction_data.subaddr_indices.clear();
+ for(uint32_t i = 0; i < 20; ++i)
+ ptx.construction_data.subaddr_indices.insert(i);
+
+ return this;
+}
+
+std::vector<tools::wallet2::pending_tx> tsx_builder::build()
+{
+ return m_ptxs;
+}
+
+bool gen_trezor_ki_sync::generate(std::vector<test_event_entry>& events)
+{
+ test_generator generator(m_generator);
+ test_setup(events);
+
+ auto dev_cold = dynamic_cast<::hw::device_cold*>(m_trezor);
+ CHECK_AND_ASSERT_THROW_MES(dev_cold, "Device does not implement cold signing interface");
+
+ std::vector<std::pair<crypto::key_image, crypto::signature>> ski;
+ tools::wallet2::transfer_container transfers;
+ hw::wallet_shim wallet_shim;
+ setup_shim(&wallet_shim);
+ m_wl_alice->get_transfers(transfers);
+
+ dev_cold->ki_sync(&wallet_shim, transfers, ski);
+ CHECK_AND_ASSERT_THROW_MES(ski.size() == transfers.size(), "Size mismatch");
+ for(size_t i = 0; i < transfers.size(); ++i)
+ {
+ auto & td = transfers[i];
+ auto & kip = ski[i];
+ CHECK_AND_ASSERT_THROW_MES(!td.m_key_image_known || td.m_key_image == kip.first, "Key Image invalid: " << i);
+ }
+
+ uint64_t spent = 0, unspent = 0;
+ m_wl_alice->import_key_images(ski, 0, spent, unspent, false);
+ return true;
+}
+
+bool gen_trezor_1utxo::generate(std::vector<test_event_entry>& events)
+{
+ TREZOR_TEST_PREFIX();
+ t_builder->cur_height(num_blocks(events) - 1)
+ ->mixin(TREZOR_TEST_MIXIN)
+ ->fee(TREZOR_TEST_FEE)
+ ->from(m_wl_alice.get(), 0)
+ ->compute_sources(boost::none, MK_COINS(1), -1, -1)
+ ->add_destination(m_eve_account, false, 1000)
+ ->rct_config(m_rct_config)
+ ->build_tx();
+
+ TREZOR_TEST_SUFFIX();
+}
+
+bool gen_trezor_1utxo_paymentid_short::generate(std::vector<test_event_entry>& events)
+{
+ TREZOR_TEST_PREFIX();
+ TREZOR_SKIP_IF_VERSION_LEQ(hw::trezor::pack_version(2, 0, 9));
+ t_builder->cur_height(num_blocks(events) - 1)
+ ->mixin(TREZOR_TEST_MIXIN)
+ ->fee(TREZOR_TEST_FEE)
+ ->from(m_wl_alice.get(), 0)
+ ->compute_sources(boost::none, MK_COINS(1), -1, -1)
+ ->add_destination(m_eve_account, false, 1000)
+ ->payment_id(TREZOR_TEST_PAYMENT_ID)
+ ->rct_config(m_rct_config)
+ ->build_tx();
+
+ TREZOR_TEST_SUFFIX();
+}
+
+bool gen_trezor_1utxo_paymentid_short_integrated::generate(std::vector<test_event_entry>& events)
+{
+ TREZOR_TEST_PREFIX();
+ TREZOR_SKIP_IF_VERSION_LEQ(hw::trezor::pack_version(2, 0, 9));
+ t_builder->cur_height(num_blocks(events) - 1)
+ ->mixin(TREZOR_TEST_MIXIN)
+ ->fee(TREZOR_TEST_FEE)
+ ->from(m_wl_alice.get(), 0)
+ ->compute_sources(boost::none, MK_COINS(1), -1, -1)
+ ->add_destination(m_eve_account, false, 1000)
+ ->payment_id(TREZOR_TEST_PAYMENT_ID)
+ ->set_integrated(0)
+ ->rct_config(m_rct_config)
+ ->build_tx();
+
+ TREZOR_TEST_SUFFIX();
+}
+
+bool gen_trezor_1utxo_paymentid_long::generate(std::vector<test_event_entry>& events)
+{
+ TREZOR_TEST_PREFIX();
+ t_builder->cur_height(num_blocks(events) - 1)
+ ->mixin(TREZOR_TEST_MIXIN)
+ ->fee(TREZOR_TEST_FEE)
+ ->from(m_wl_alice.get(), 0)
+ ->compute_sources(boost::none, MK_COINS(1), -1, -1)
+ ->add_destination(m_eve_account, false, 1000)
+ ->payment_id(TREZOR_TEST_PAYMENT_ID_LONG)
+ ->rct_config(m_rct_config)
+ ->build_tx();
+
+ TREZOR_TEST_SUFFIX();
+}
+
+bool gen_trezor_4utxo::generate(std::vector<test_event_entry>& events)
+{
+ TREZOR_TEST_PREFIX();
+ t_builder->cur_height(num_blocks(events) - 1)
+ ->mixin(TREZOR_TEST_MIXIN)
+ ->fee(TREZOR_TEST_FEE)
+ ->from(m_wl_alice.get(), 0)
+ ->compute_sources(4, MK_COINS(1), -1, -1)
+ ->add_destination(m_eve_account, false, 1000)
+ ->rct_config(m_rct_config)
+ ->build_tx();
+
+ TREZOR_TEST_SUFFIX();
+}
+
+bool gen_trezor_4utxo_acc1::generate(std::vector<test_event_entry>& events)
+{
+ TREZOR_TEST_PREFIX();
+ t_builder->cur_height(num_blocks(events) - 1)
+ ->mixin(TREZOR_TEST_MIXIN)
+ ->fee(TREZOR_TEST_FEE)
+ ->from(m_wl_alice.get(), 1)
+ ->compute_sources(4, MK_COINS(1), -1, -1)
+ ->add_destination(m_wl_eve->get_subaddress({0, 1}), true, 1000)
+ ->rct_config(m_rct_config)
+ ->build_tx();
+
+ TREZOR_TEST_SUFFIX();
+}
+
+bool gen_trezor_4utxo_to_sub::generate(std::vector<test_event_entry>& events)
+{
+ TREZOR_TEST_PREFIX();
+ t_builder->cur_height(num_blocks(events) - 1)
+ ->mixin(TREZOR_TEST_MIXIN)
+ ->fee(TREZOR_TEST_FEE)
+ ->from(m_wl_alice.get(), 0)
+ ->compute_sources(4, MK_COINS(1), -1, -1)
+ ->add_destination(m_wl_eve->get_subaddress({0, 1}), true, 1000)
+ ->rct_config(m_rct_config)
+ ->build_tx();
+
+ TREZOR_TEST_SUFFIX();
+}
+
+bool gen_trezor_4utxo_to_2sub::generate(std::vector<test_event_entry>& events)
+{
+ TREZOR_TEST_PREFIX();
+ t_builder->cur_height(num_blocks(events) - 1)
+ ->mixin(TREZOR_TEST_MIXIN)
+ ->fee(TREZOR_TEST_FEE)
+ ->from(m_wl_alice.get(), 0)
+ ->compute_sources(4, MK_COINS(1), -1, -1)
+ ->add_destination(m_wl_eve->get_subaddress({0, 1}), true, 1000)
+ ->add_destination(m_wl_eve->get_subaddress({1, 3}), true, 1000)
+ ->rct_config(m_rct_config)
+ ->build_tx();
+
+ TREZOR_TEST_SUFFIX();
+}
+
+bool gen_trezor_4utxo_to_1norm_2sub::generate(std::vector<test_event_entry>& events)
+{
+ TREZOR_TEST_PREFIX();
+ t_builder->cur_height(num_blocks(events) - 1)
+ ->mixin(TREZOR_TEST_MIXIN)
+ ->fee(TREZOR_TEST_FEE)
+ ->from(m_wl_alice.get(), 0)
+ ->compute_sources(4, MK_COINS(1), -1, -1)
+ ->add_destination(m_wl_eve->get_subaddress({1, 1}), true, 1000)
+ ->add_destination(m_wl_eve->get_subaddress({2, 1}), true, 1000)
+ ->add_destination(m_wl_eve.get(), false, 1000)
+ ->rct_config(m_rct_config)
+ ->build_tx();
+
+ TREZOR_TEST_SUFFIX();
+}
+
+bool gen_trezor_2utxo_sub_acc_to_1norm_2sub::generate(std::vector<test_event_entry>& events)
+{
+ TREZOR_TEST_PREFIX();
+ t_builder->cur_height(num_blocks(events) - 1)
+ ->mixin(TREZOR_TEST_MIXIN)
+ ->fee(TREZOR_TEST_FEE)
+ ->from(m_wl_alice.get(), 0)
+ ->compute_sources_to_sub_acc(2, MK_COINS(1) >> 2, -1, -1)
+ ->add_destination(m_wl_eve->get_subaddress({1, 1}), true, 1000)
+ ->add_destination(m_wl_eve->get_subaddress({2, 1}), true, 1000)
+ ->add_destination(m_wl_eve.get(), false, 1000)
+ ->rct_config(m_rct_config)
+ ->build_tx();
+
+ TREZOR_TEST_SUFFIX();
+}
+
+bool gen_trezor_4utxo_to_7outs::generate(std::vector<test_event_entry>& events)
+{
+ TREZOR_TEST_PREFIX();
+ t_builder->cur_height(num_blocks(events) - 1)
+ ->mixin(TREZOR_TEST_MIXIN)
+ ->fee(TREZOR_TEST_FEE)
+ ->from(m_wl_alice.get(), 0)
+ ->compute_sources(4, MK_COINS(1), -1, -1)
+ ->add_destination(m_wl_eve->get_subaddress({1, 1}), true, 1000)
+ ->add_destination(m_wl_eve->get_subaddress({2, 1}), true, 1000)
+ ->add_destination(m_wl_eve->get_subaddress({0, 1}), true, 1000)
+ ->add_destination(m_wl_eve->get_subaddress({0, 2}), true, 1000)
+ ->add_destination(m_wl_eve->get_subaddress({0, 3}), true, 1000)
+ ->add_destination(m_wl_eve->get_subaddress({0, 4}), true, 1000)
+ ->add_destination(m_wl_eve.get(), false, 1000)
+ ->rct_config(m_rct_config)
+ ->build_tx();
+
+ TREZOR_TEST_SUFFIX();
+}
+
+bool gen_trezor_many_utxo::generate(std::vector<test_event_entry>& events)
+{
+ TREZOR_TEST_PREFIX();
+ t_builder->cur_height(num_blocks(events) - 1)
+ ->mixin(TREZOR_TEST_MIXIN)
+ ->fee(TREZOR_TEST_FEE)
+ ->from(m_wl_alice.get(), 0)
+ ->compute_sources(110, MK_COINS(1), -1, -1)
+ ->add_destination(m_eve_account, false, 1000)
+ ->rct_config(m_rct_config)
+ ->build_tx();
+
+ TREZOR_TEST_SUFFIX();
+}
+
diff --git a/tests/trezor/trezor_tests.h b/tests/trezor/trezor_tests.h
new file mode 100644
index 000000000..41db1cce5
--- /dev/null
+++ b/tests/trezor/trezor_tests.h
@@ -0,0 +1,248 @@
+// Copyright (c) 2014-2018, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
+
+#pragma once
+
+#include <device_trezor/device_trezor.hpp>
+#include "../core_tests/chaingen.h"
+#include "../core_tests/wallet_tools.h"
+
+#define TREZOR_TEST_FEE 90000000000
+#define TREZOR_TEST_MIXIN 11
+
+/************************************************************************/
+/* */
+/************************************************************************/
+class tsx_builder;
+class gen_trezor_base : public test_chain_unit_base
+{
+public:
+ friend class tsx_builder;
+
+ gen_trezor_base();
+ gen_trezor_base(const gen_trezor_base &other);
+ virtual ~gen_trezor_base() {};
+
+ void setup_args(const std::string & trezor_path, bool heavy_tests=false);
+ virtual bool generate(std::vector<test_event_entry>& events);
+ virtual void load(std::vector<test_event_entry>& events); // load events, init test obj
+ void fix_hf(std::vector<test_event_entry>& events);
+ void update_trackers(std::vector<test_event_entry>& events);
+
+ void fork(gen_trezor_base & other); // fork generated chain to another test
+ void clear(); // clears m_events, bt, generator, hforks
+ void add_shared_events(std::vector<test_event_entry>& events); // m_events -> events
+ void test_setup(std::vector<test_event_entry>& events); // init setup env, wallets
+
+ void test_trezor_tx(std::vector<test_event_entry>& events,
+ std::vector<tools::wallet2::pending_tx>& ptxs,
+ std::vector<cryptonote::address_parse_info>& dsts_info,
+ test_generator &generator,
+ std::vector<tools::wallet2*> wallets,
+ bool is_sweep=false);
+
+ crypto::hash head_hash() { return get_block_hash(m_head); }
+ cryptonote::block head_block() { return m_head; }
+ bool heavy_tests() { return m_heavy_tests; }
+ void rct_config(rct::RCTConfig rct_config) { m_rct_config = rct_config; }
+ uint8_t cur_hf(){ return m_hard_forks.size() > 0 ? m_hard_forks.back().first : 0; }
+
+ // Static configuration
+ static const uint64_t m_ts_start;
+ static const uint64_t m_wallet_ts;
+ static const std::string m_device_name;
+ static const std::string m_master_seed_str;
+ static const std::string m_device_seed;
+ static const std::string m_alice_spend_private;
+ static const std::string m_alice_view_private;
+
+protected:
+ void setup_trezor();
+ void init_fields();
+
+ test_generator m_generator;
+ block_tracker m_bt;
+
+ v_hardforks_t m_hard_forks;
+ cryptonote::block m_head;
+ std::vector<test_event_entry> m_events;
+
+ std::string m_trezor_path;
+ bool m_heavy_tests;
+ rct::RCTConfig m_rct_config;
+
+ cryptonote::account_base m_miner_account;
+ cryptonote::account_base m_bob_account;
+ cryptonote::account_base m_alice_account;
+ cryptonote::account_base m_eve_account;
+ hw::trezor::device_trezor * m_trezor;
+ std::unique_ptr<tools::wallet2> m_wl_alice;
+ std::unique_ptr<tools::wallet2> m_wl_bob;
+ std::unique_ptr<tools::wallet2> m_wl_eve;
+
+ friend class boost::serialization::access;
+
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int /*version*/)
+ {
+ ar & m_generator;
+ }
+};
+
+class tsx_builder {
+public:
+ tsx_builder(): m_tester(nullptr), m_from(nullptr), m_account(0), m_mixin(TREZOR_TEST_MIXIN), m_fee(TREZOR_TEST_FEE),
+ m_rct_config({rct::RangeProofPaddedBulletproof, 1 }){}
+
+ tsx_builder(gen_trezor_base * tester): m_tester(tester), m_from(nullptr), m_account(0),
+ m_mixin(TREZOR_TEST_MIXIN), m_fee(TREZOR_TEST_FEE),
+ m_rct_config({rct::RangeProofPaddedBulletproof, 1 }){}
+
+ tsx_builder * cur_height(uint64_t cur_height) { m_cur_height = cur_height; return this; }
+ tsx_builder * mixin(size_t mixin=TREZOR_TEST_MIXIN) { m_mixin = mixin; return this; }
+ tsx_builder * fee(uint64_t fee=TREZOR_TEST_FEE) { m_fee = fee; return this; }
+ tsx_builder * payment_id(const std::string & payment_id) { m_payment_id = payment_id; return this; }
+ tsx_builder * from(tools::wallet2 *from, uint32_t account=0) { m_from = from; m_account=account; return this; }
+ tsx_builder * sources(std::vector<cryptonote::tx_source_entry> & sources, std::vector<size_t> & selected_transfers);
+ tsx_builder * compute_sources(boost::optional<size_t> num_utxo=boost::none, boost::optional<uint64_t> min_amount=boost::none, ssize_t offset=-1, int step=1, boost::optional<fnc_accept_tx_source_t> fnc_accept=boost::none);
+ tsx_builder * compute_sources_to_sub(boost::optional<size_t> num_utxo=boost::none, boost::optional<uint64_t> min_amount=boost::none, ssize_t offset=-1, int step=1, boost::optional<fnc_accept_tx_source_t> fnc_accept=boost::none);
+ tsx_builder * compute_sources_to_sub_acc(boost::optional<size_t> num_utxo=boost::none, boost::optional<uint64_t> min_amount=boost::none, ssize_t offset=-1, int step=1, boost::optional<fnc_accept_tx_source_t> fnc_accept=boost::none);
+
+ tsx_builder * destinations(std::vector<cryptonote::tx_destination_entry> &dsts);
+ tsx_builder * add_destination(const cryptonote::tx_destination_entry &dst);
+ tsx_builder * add_destination(const tools::wallet2 * wallet, bool is_subaddr=false, uint64_t amount=1000);
+ tsx_builder * add_destination(const var_addr_t addr, bool is_subaddr=false, uint64_t amount=1000);
+ tsx_builder * set_integrated(size_t idx);
+ tsx_builder * rct_config(const rct::RCTConfig & rct_config) {m_rct_config = rct_config; return this; };
+
+ tsx_builder * build_tx();
+ tsx_builder * construct_pending_tx(tools::wallet2::pending_tx &ptx, boost::optional<std::vector<uint8_t>> extra = boost::none);
+ tsx_builder * clear_current();
+ std::vector<tools::wallet2::pending_tx> build();
+ std::vector<cryptonote::address_parse_info> dest_info(){ return m_dsts_info; }
+
+protected:
+ gen_trezor_base * m_tester;
+ uint64_t m_cur_height;
+ std::vector<tools::wallet2::pending_tx> m_ptxs; // all transactions
+
+ // current transaction
+ size_t m_mixin;
+ uint64_t m_fee;
+ tools::wallet2 * m_from;
+ uint32_t m_account;
+ cryptonote::transaction m_tx;
+ std::vector<size_t> m_selected_transfers;
+ std::vector<cryptonote::tx_source_entry> m_sources;
+ std::vector<cryptonote::tx_destination_entry> m_destinations;
+ std::vector<cryptonote::tx_destination_entry> m_destinations_orig;
+ std::vector<cryptonote::address_parse_info> m_dsts_info;
+ std::unordered_set<size_t> m_integrated;
+ std::string m_payment_id;
+ rct::RCTConfig m_rct_config;
+};
+
+class gen_trezor_ki_sync : public gen_trezor_base
+{
+public:
+ bool generate(std::vector<test_event_entry>& events) override;
+};
+
+class gen_trezor_1utxo : public gen_trezor_base
+{
+public:
+ bool generate(std::vector<test_event_entry>& events) override;
+};
+
+class gen_trezor_1utxo_paymentid_short : public gen_trezor_base
+{
+public:
+ bool generate(std::vector<test_event_entry>& events) override;
+};
+
+class gen_trezor_1utxo_paymentid_short_integrated : public gen_trezor_base
+{
+public:
+ bool generate(std::vector<test_event_entry>& events) override;
+};
+
+class gen_trezor_1utxo_paymentid_long : public gen_trezor_base
+{
+public:
+ bool generate(std::vector<test_event_entry>& events) override;
+};
+
+class gen_trezor_4utxo : public gen_trezor_base
+{
+public:
+ bool generate(std::vector<test_event_entry>& events) override;
+};
+
+class gen_trezor_4utxo_acc1 : public gen_trezor_base
+{
+public:
+ bool generate(std::vector<test_event_entry>& events) override;
+};
+
+class gen_trezor_4utxo_to_sub : public gen_trezor_base
+{
+public:
+ bool generate(std::vector<test_event_entry>& events) override;
+};
+
+class gen_trezor_4utxo_to_2sub : public gen_trezor_base
+{
+public:
+ bool generate(std::vector<test_event_entry>& events) override;
+};
+
+class gen_trezor_4utxo_to_1norm_2sub : public gen_trezor_base
+{
+public:
+ bool generate(std::vector<test_event_entry>& events) override;
+};
+
+class gen_trezor_2utxo_sub_acc_to_1norm_2sub : public gen_trezor_base
+{
+public:
+ bool generate(std::vector<test_event_entry>& events) override;
+};
+
+class gen_trezor_4utxo_to_7outs : public gen_trezor_base
+{
+public:
+ bool generate(std::vector<test_event_entry>& events) override;
+};
+
+class gen_trezor_many_utxo : public gen_trezor_base
+{
+public:
+ bool generate(std::vector<test_event_entry>& events) override;
+};
diff --git a/tests/unit_tests/CMakeLists.txt b/tests/unit_tests/CMakeLists.txt
index cb421c847..b355d566d 100644
--- a/tests/unit_tests/CMakeLists.txt
+++ b/tests/unit_tests/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
@@ -55,6 +55,7 @@ set(unit_tests_sources
http.cpp
keccak.cpp
logging.cpp
+ long_term_block_weight.cpp
main.cpp
memwipe.cpp
mlocker.cpp
diff --git a/tests/unit_tests/account.cpp b/tests/unit_tests/account.cpp
index 113622b5e..7073ab3e8 100644
--- a/tests/unit_tests/account.cpp
+++ b/tests/unit_tests/account.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/address_from_url.cpp b/tests/unit_tests/address_from_url.cpp
index f6c0ad105..4b06c6487 100644
--- a/tests/unit_tests/address_from_url.cpp
+++ b/tests/unit_tests/address_from_url.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/apply_permutation.cpp b/tests/unit_tests/apply_permutation.cpp
index e2420eb45..76d10c8ff 100644
--- a/tests/unit_tests/apply_permutation.cpp
+++ b/tests/unit_tests/apply_permutation.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/ban.cpp b/tests/unit_tests/ban.cpp
index 1e764c83e..eb1ee8932 100644
--- a/tests/unit_tests/ban.cpp
+++ b/tests/unit_tests/ban.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -56,7 +56,7 @@ public:
void get_blockchain_top(uint64_t& height, crypto::hash& top_id)const{height=0;top_id=crypto::null_hash;}
bool handle_incoming_tx(const cryptonote::blobdata& tx_blob, cryptonote::tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay) { return true; }
bool handle_incoming_txs(const std::vector<cryptonote::blobdata>& tx_blob, std::vector<cryptonote::tx_verification_context>& tvc, bool keeped_by_block, bool relayed, bool do_not_relay) { return true; }
- bool handle_incoming_block(const cryptonote::blobdata& block_blob, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate = true) { return true; }
+ bool handle_incoming_block(const cryptonote::blobdata& block_blob, const cryptonote::block *block, cryptonote::block_verification_context& bvc, bool update_miner_blocktemplate = true) { return true; }
void pause_mine(){}
void resume_mine(){}
bool on_idle(){return true;}
@@ -65,7 +65,7 @@ public:
cryptonote::blockchain_storage &get_blockchain_storage() { throw std::runtime_error("Called invalid member function: please never call get_blockchain_storage on the TESTING class test_core."); }
bool get_test_drop_download() const {return true;}
bool get_test_drop_download_height() const {return true;}
- bool prepare_handle_incoming_blocks(const std::vector<cryptonote::block_complete_entry> &blocks) { return true; }
+ bool prepare_handle_incoming_blocks(const std::vector<cryptonote::block_complete_entry> &blocks_entry, std::vector<cryptonote::block> &blocks) { return true; }
bool cleanup_handle_incoming_blocks(bool force_sync = false) { return true; }
uint64_t get_target_blockchain_height() const { return 1; }
size_t get_block_sync_size(uint64_t height) const { return BLOCKS_SYNCHRONIZING_DEFAULT_COUNT; }
diff --git a/tests/unit_tests/base58.cpp b/tests/unit_tests/base58.cpp
index 7edb28e62..1996afd04 100644
--- a/tests/unit_tests/base58.cpp
+++ b/tests/unit_tests/base58.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/block_queue.cpp b/tests/unit_tests/block_queue.cpp
index f7b7c63fd..0cba7c443 100644
--- a/tests/unit_tests/block_queue.cpp
+++ b/tests/unit_tests/block_queue.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/block_reward.cpp b/tests/unit_tests/block_reward.cpp
index a897e4140..1dd9072b9 100644
--- a/tests/unit_tests/block_reward.cpp
+++ b/tests/unit_tests/block_reward.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/blockchain_db.cpp b/tests/unit_tests/blockchain_db.cpp
index 7e7ce9bf7..4fbc21ddc 100644
--- a/tests/unit_tests/blockchain_db.cpp
+++ b/tests/unit_tests/blockchain_db.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -163,17 +163,17 @@ protected:
block bl;
blobdata bd = h2b(i);
parse_and_validate_block_from_blob(bd, bl);
- m_blocks.push_back(bl);
+ m_blocks.push_back(std::make_pair(bl, bd));
}
for (auto& i : t_transactions)
{
- std::vector<transaction> txs;
+ std::vector<std::pair<transaction, blobdata>> txs;
for (auto& j : i)
{
transaction tx;
blobdata bd = h2b(j);
parse_and_validate_tx_from_blob(bd, tx);
- txs.push_back(tx);
+ txs.push_back(std::make_pair(tx, bd));
}
m_txs.push_back(txs);
}
@@ -187,8 +187,8 @@ protected:
BlockchainDB* m_db;
HardFork m_hardfork;
std::string m_prefix;
- std::vector<block> m_blocks;
- std::vector<std::vector<transaction> > m_txs;
+ std::vector<std::pair<block, blobdata>> m_blocks;
+ std::vector<std::vector<std::pair<transaction, blobdata>>> m_txs;
std::vector<std::string> m_filenames;
void init_hard_fork()
@@ -277,25 +277,25 @@ TYPED_TEST(BlockchainDBTest, AddBlock)
// TODO: need at least one more block to make this reasonable, as the
// BlockchainDB implementation should not check for parent if
// no blocks have been added yet (because genesis has no parent).
- //ASSERT_THROW(this->m_db->add_block(this->m_blocks[1], t_sizes[1], t_diffs[1], t_coins[1], this->m_txs[1]), BLOCK_PARENT_DNE);
+ //ASSERT_THROW(this->m_db->add_block(this->m_blocks[1], t_sizes[1], t_sizes[1], t_diffs[1], t_coins[1], this->m_txs[1]), BLOCK_PARENT_DNE);
- ASSERT_NO_THROW(this->m_db->add_block(this->m_blocks[0], t_sizes[0], t_diffs[0], t_coins[0], this->m_txs[0]));
- ASSERT_NO_THROW(this->m_db->add_block(this->m_blocks[1], t_sizes[1], t_diffs[1], t_coins[1], this->m_txs[1]));
+ ASSERT_NO_THROW(this->m_db->add_block(this->m_blocks[0], t_sizes[0], t_sizes[0], t_diffs[0], t_coins[0], this->m_txs[0]));
+ ASSERT_NO_THROW(this->m_db->add_block(this->m_blocks[1], t_sizes[1], t_sizes[1], t_diffs[1], t_coins[1], this->m_txs[1]));
block b;
- ASSERT_TRUE(this->m_db->block_exists(get_block_hash(this->m_blocks[0])));
- ASSERT_NO_THROW(b = this->m_db->get_block(get_block_hash(this->m_blocks[0])));
+ ASSERT_TRUE(this->m_db->block_exists(get_block_hash(this->m_blocks[0].first)));
+ ASSERT_NO_THROW(b = this->m_db->get_block(get_block_hash(this->m_blocks[0].first)));
- ASSERT_TRUE(compare_blocks(this->m_blocks[0], b));
+ ASSERT_TRUE(compare_blocks(this->m_blocks[0].first, b));
ASSERT_NO_THROW(b = this->m_db->get_block_from_height(0));
- ASSERT_TRUE(compare_blocks(this->m_blocks[0], b));
+ ASSERT_TRUE(compare_blocks(this->m_blocks[0].first, b));
// assert that we can't add the same block twice
- ASSERT_THROW(this->m_db->add_block(this->m_blocks[0], t_sizes[0], t_diffs[0], t_coins[0], this->m_txs[0]), TX_EXISTS);
+ ASSERT_THROW(this->m_db->add_block(this->m_blocks[0], t_sizes[0], t_sizes[0], t_diffs[0], t_coins[0], this->m_txs[0]), TX_EXISTS);
- for (auto& h : this->m_blocks[0].tx_hashes)
+ for (auto& h : this->m_blocks[0].first.tx_hashes)
{
transaction tx;
ASSERT_TRUE(this->m_db->tx_exists(h));
@@ -317,31 +317,31 @@ TYPED_TEST(BlockchainDBTest, RetrieveBlockData)
this->get_filenames();
this->init_hard_fork();
- ASSERT_NO_THROW(this->m_db->add_block(this->m_blocks[0], t_sizes[0], t_diffs[0], t_coins[0], this->m_txs[0]));
+ ASSERT_NO_THROW(this->m_db->add_block(this->m_blocks[0], t_sizes[0], t_sizes[0], t_diffs[0], t_coins[0], this->m_txs[0]));
ASSERT_EQ(t_sizes[0], this->m_db->get_block_weight(0));
ASSERT_EQ(t_diffs[0], this->m_db->get_block_cumulative_difficulty(0));
ASSERT_EQ(t_diffs[0], this->m_db->get_block_difficulty(0));
ASSERT_EQ(t_coins[0], this->m_db->get_block_already_generated_coins(0));
- ASSERT_NO_THROW(this->m_db->add_block(this->m_blocks[1], t_sizes[1], t_diffs[1], t_coins[1], this->m_txs[1]));
+ ASSERT_NO_THROW(this->m_db->add_block(this->m_blocks[1], t_sizes[1], t_sizes[1], t_diffs[1], t_coins[1], this->m_txs[1]));
ASSERT_EQ(t_diffs[1] - t_diffs[0], this->m_db->get_block_difficulty(1));
- ASSERT_HASH_EQ(get_block_hash(this->m_blocks[0]), this->m_db->get_block_hash_from_height(0));
+ ASSERT_HASH_EQ(get_block_hash(this->m_blocks[0].first), this->m_db->get_block_hash_from_height(0));
std::vector<block> blks;
ASSERT_NO_THROW(blks = this->m_db->get_blocks_range(0, 1));
ASSERT_EQ(2, blks.size());
- ASSERT_HASH_EQ(get_block_hash(this->m_blocks[0]), get_block_hash(blks[0]));
- ASSERT_HASH_EQ(get_block_hash(this->m_blocks[1]), get_block_hash(blks[1]));
+ ASSERT_HASH_EQ(get_block_hash(this->m_blocks[0].first), get_block_hash(blks[0]));
+ ASSERT_HASH_EQ(get_block_hash(this->m_blocks[1].first), get_block_hash(blks[1]));
std::vector<crypto::hash> hashes;
ASSERT_NO_THROW(hashes = this->m_db->get_hashes_range(0, 1));
ASSERT_EQ(2, hashes.size());
- ASSERT_HASH_EQ(get_block_hash(this->m_blocks[0]), hashes[0]);
- ASSERT_HASH_EQ(get_block_hash(this->m_blocks[1]), hashes[1]);
+ ASSERT_HASH_EQ(get_block_hash(this->m_blocks[0].first), hashes[0]);
+ ASSERT_HASH_EQ(get_block_hash(this->m_blocks[1].first), hashes[1]);
}
} // anonymous namespace
diff --git a/tests/unit_tests/bulletproofs.cpp b/tests/unit_tests/bulletproofs.cpp
index 4f07415b0..9ac0df45b 100644
--- a/tests/unit_tests/bulletproofs.cpp
+++ b/tests/unit_tests/bulletproofs.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/canonical_amounts.cpp b/tests/unit_tests/canonical_amounts.cpp
index 227a64a7f..74fcc9548 100644
--- a/tests/unit_tests/canonical_amounts.cpp
+++ b/tests/unit_tests/canonical_amounts.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/chacha.cpp b/tests/unit_tests/chacha.cpp
index 699890522..e06081f8f 100644
--- a/tests/unit_tests/chacha.cpp
+++ b/tests/unit_tests/chacha.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/checkpoints.cpp b/tests/unit_tests/checkpoints.cpp
index ec09c596b..90229a0b8 100644
--- a/tests/unit_tests/checkpoints.cpp
+++ b/tests/unit_tests/checkpoints.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/command_line.cpp b/tests/unit_tests/command_line.cpp
index 327fceefe..6d5afb708 100644
--- a/tests/unit_tests/command_line.cpp
+++ b/tests/unit_tests/command_line.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/crypto.cpp b/tests/unit_tests/crypto.cpp
index e09ec7f7a..7100c8013 100644
--- a/tests/unit_tests/crypto.cpp
+++ b/tests/unit_tests/crypto.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/decompose_amount_into_digits.cpp b/tests/unit_tests/decompose_amount_into_digits.cpp
index 11c6189e5..5049dd83d 100644
--- a/tests/unit_tests/decompose_amount_into_digits.cpp
+++ b/tests/unit_tests/decompose_amount_into_digits.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/dns_resolver.cpp b/tests/unit_tests/dns_resolver.cpp
index 2b3627f02..6bffc01d8 100644
--- a/tests/unit_tests/dns_resolver.cpp
+++ b/tests/unit_tests/dns_resolver.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/epee_boosted_tcp_server.cpp b/tests/unit_tests/epee_boosted_tcp_server.cpp
index 41554f948..32989f545 100644
--- a/tests/unit_tests/epee_boosted_tcp_server.cpp
+++ b/tests/unit_tests/epee_boosted_tcp_server.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/epee_levin_protocol_handler_async.cpp b/tests/unit_tests/epee_levin_protocol_handler_async.cpp
index 9ea71875b..697845f60 100644
--- a/tests/unit_tests/epee_levin_protocol_handler_async.cpp
+++ b/tests/unit_tests/epee_levin_protocol_handler_async.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp
index 18fb262c2..946731826 100644
--- a/tests/unit_tests/epee_utils.cpp
+++ b/tests/unit_tests/epee_utils.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -389,6 +389,25 @@ TEST(ToHex, String)
}
+TEST(FromHex, String)
+{
+ // the source data to encode and decode
+ std::vector<uint8_t> source{{ 0x00, 0xFF, 0x0F, 0xF0 }};
+
+ // encode and decode the data
+ auto hex = epee::to_hex::string({ source.data(), source.size() });
+ auto decoded = epee::from_hex::vector(hex);
+
+ // encoded should be twice the size and should decode to the exact same data
+ EXPECT_EQ(source.size() * 2, hex.size());
+ EXPECT_EQ(source, decoded);
+
+ // we will now create a padded hex string, we want to explicitly allow
+ // decoding it this way also, ignoring spaces and colons between the numbers
+ hex.assign("00:ff 0f:f0");
+ EXPECT_EQ(source, epee::from_hex::vector(hex));
+}
+
TEST(ToHex, Array)
{
EXPECT_EQ(
diff --git a/tests/unit_tests/fee.cpp b/tests/unit_tests/fee.cpp
index 8ccb38fc9..3b0bc1f09 100644
--- a/tests/unit_tests/fee.cpp
+++ b/tests/unit_tests/fee.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/get_xtype_from_string.cpp b/tests/unit_tests/get_xtype_from_string.cpp
index 54ba473a6..75452894a 100644
--- a/tests/unit_tests/get_xtype_from_string.cpp
+++ b/tests/unit_tests/get_xtype_from_string.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/hardfork.cpp b/tests/unit_tests/hardfork.cpp
index ec8d1d202..bb26b5533 100644
--- a/tests/unit_tests/hardfork.cpp
+++ b/tests/unit_tests/hardfork.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
@@ -34,7 +34,7 @@
#include "blockchain_db/blockchain_db.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "cryptonote_basic/hardfork.h"
-#include "testdb.h"
+#include "blockchain_db/testdb.h"
using namespace cryptonote;
@@ -44,11 +44,12 @@ using namespace cryptonote;
namespace
{
-class TestDB: public BaseTestDB {
+class TestDB: public cryptonote::BaseTestDB {
public:
virtual uint64_t height() const { return blocks.size(); }
virtual void add_block( const block& blk
, size_t block_weight
+ , uint64_t long_term_block_weight
, const difficulty_type& cumulative_difficulty
, const uint64_t& coins_generated
, uint64_t num_rct_outs
@@ -106,20 +107,20 @@ TEST(major, Only)
ASSERT_FALSE(hf.add(mkblock(0, 2), 0));
ASSERT_FALSE(hf.add(mkblock(2, 2), 0));
ASSERT_TRUE(hf.add(mkblock(1, 2), 0));
- db.add_block(mkblock(1, 1), 0, 0, 0, 0, crypto::hash());
+ db.add_block(mkblock(1, 1), 0, 0, 0, 0, 0, crypto::hash());
// block height 1, only version 1 is accepted
ASSERT_FALSE(hf.add(mkblock(0, 2), 1));
ASSERT_FALSE(hf.add(mkblock(2, 2), 1));
ASSERT_TRUE(hf.add(mkblock(1, 2), 1));
- db.add_block(mkblock(1, 1), 0, 0, 0, 0, crypto::hash());
+ db.add_block(mkblock(1, 1), 0, 0, 0, 0, 0, crypto::hash());
// block height 2, only version 2 is accepted
ASSERT_FALSE(hf.add(mkblock(0, 2), 2));
ASSERT_FALSE(hf.add(mkblock(1, 2), 2));
ASSERT_FALSE(hf.add(mkblock(3, 2), 2));
ASSERT_TRUE(hf.add(mkblock(2, 2), 2));
- db.add_block(mkblock(2, 1), 0, 0, 0, 0, crypto::hash());
+ db.add_block(mkblock(2, 1), 0, 0, 0, 0, 0, crypto::hash());
}
TEST(empty_hardforks, Success)
@@ -133,7 +134,7 @@ TEST(empty_hardforks, Success)
ASSERT_TRUE(hf.get_state(time(NULL) + 3600*24*400) == HardFork::Ready);
for (uint64_t h = 0; h <= 10; ++h) {
- db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, crypto::hash());
+ db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, crypto::hash());
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
ASSERT_EQ(hf.get(0), 1);
@@ -167,14 +168,14 @@ TEST(check_for_height, Success)
for (uint64_t h = 0; h <= 4; ++h) {
ASSERT_TRUE(hf.check_for_height(mkblock(1, 1), h));
ASSERT_FALSE(hf.check_for_height(mkblock(2, 2), h)); // block version is too high
- db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, crypto::hash());
+ db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, crypto::hash());
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
for (uint64_t h = 5; h <= 10; ++h) {
ASSERT_FALSE(hf.check_for_height(mkblock(1, 1), h)); // block version is too low
ASSERT_TRUE(hf.check_for_height(mkblock(2, 2), h));
- db.add_block(mkblock(hf, h, 2), 0, 0, 0, 0, crypto::hash());
+ db.add_block(mkblock(hf, h, 2), 0, 0, 0, 0, 0, crypto::hash());
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
}
@@ -191,19 +192,19 @@ TEST(get, next_version)
for (uint64_t h = 0; h <= 4; ++h) {
ASSERT_EQ(2, hf.get_next_version());
- db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, crypto::hash());
+ db.add_block(mkblock(hf, h, 1), 0, 0, 0, 0, 0, crypto::hash());
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
for (uint64_t h = 5; h <= 9; ++h) {
ASSERT_EQ(4, hf.get_next_version());
- db.add_block(mkblock(hf, h, 2), 0, 0, 0, 0, crypto::hash());
+ db.add_block(mkblock(hf, h, 2), 0, 0, 0, 0, 0, crypto::hash());
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
for (uint64_t h = 10; h <= 15; ++h) {
ASSERT_EQ(4, hf.get_next_version());
- db.add_block(mkblock(hf, h, 4), 0, 0, 0, 0, crypto::hash());
+ db.add_block(mkblock(hf, h, 4), 0, 0, 0, 0, 0, crypto::hash());
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
}
@@ -244,7 +245,7 @@ TEST(steps_asap, Success)
hf.init();
for (uint64_t h = 0; h < 10; ++h) {
- db.add_block(mkblock(hf, h, 9), 0, 0, 0, 0, crypto::hash());
+ db.add_block(mkblock(hf, h, 9), 0, 0, 0, 0, 0, crypto::hash());
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
@@ -271,7 +272,7 @@ TEST(steps_1, Success)
hf.init();
for (uint64_t h = 0 ; h < 10; ++h) {
- db.add_block(mkblock(hf, h, h+1), 0, 0, 0, 0, crypto::hash());
+ db.add_block(mkblock(hf, h, h+1), 0, 0, 0, 0, 0, crypto::hash());
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
@@ -296,7 +297,7 @@ TEST(reorganize, Same)
// index 0 1 2 3 4 5 6 7 8 9
static const uint8_t block_versions[] = { 1, 1, 4, 4, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 };
for (uint64_t h = 0; h < 20; ++h) {
- db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, crypto::hash());
+ db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, crypto::hash());
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
@@ -327,7 +328,7 @@ TEST(reorganize, Changed)
static const uint8_t block_versions[] = { 1, 1, 4, 4, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 };
static const uint8_t expected_versions[] = { 1, 1, 1, 1, 1, 1, 4, 4, 7, 7, 9, 9, 9, 9, 9, 9 };
for (uint64_t h = 0; h < 16; ++h) {
- db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, crypto::hash());
+ db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, crypto::hash());
ASSERT_TRUE (hf.add(db.get_block_from_height(h), h));
}
@@ -347,7 +348,7 @@ TEST(reorganize, Changed)
ASSERT_EQ(db.height(), 3);
hf.reorganize_from_block_height(2);
for (uint64_t h = 3; h < 16; ++h) {
- db.add_block(mkblock(hf, h, block_versions_new[h]), 0, 0, 0, 0, crypto::hash());
+ db.add_block(mkblock(hf, h, block_versions_new[h]), 0, 0, 0, 0, 0, crypto::hash());
bool ret = hf.add(db.get_block_from_height(h), h);
ASSERT_EQ (ret, h < 15);
}
@@ -371,7 +372,7 @@ TEST(voting, threshold)
for (uint64_t h = 0; h <= 8; ++h) {
uint8_t v = 1 + !!(h % 8);
- db.add_block(mkblock(hf, h, v), 0, 0, 0, 0, crypto::hash());
+ db.add_block(mkblock(hf, h, v), 0, 0, 0, 0, 0, crypto::hash());
bool ret = hf.add(db.get_block_from_height(h), h);
if (h >= 8 && threshold == 87) {
// for threshold 87, we reach the treshold at height 7, so from height 8, hard fork to version 2, but 8 tries to add 1
@@ -405,7 +406,7 @@ TEST(voting, different_thresholds)
static const uint8_t expected_versions[] = { 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4 };
for (uint64_t h = 0; h < sizeof(block_versions) / sizeof(block_versions[0]); ++h) {
- db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, crypto::hash());
+ db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, crypto::hash());
bool ret = hf.add(db.get_block_from_height(h), h);
ASSERT_EQ(ret, true);
}
@@ -459,7 +460,7 @@ TEST(voting, info)
ASSERT_EQ(expected_thresholds[h], threshold);
ASSERT_EQ(4, voting);
- db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, crypto::hash());
+ db.add_block(mkblock(hf, h, block_versions[h]), 0, 0, 0, 0, 0, crypto::hash());
ASSERT_TRUE(hf.add(db.get_block_from_height(h), h));
}
}
@@ -522,7 +523,7 @@ TEST(reorganize, changed)
#define ADD(v, h, a) \
do { \
cryptonote::block b = mkblock(hf, h, v); \
- db.add_block(b, 0, 0, 0, 0, crypto::hash()); \
+ db.add_block(b, 0, 0, 0, 0, 0, crypto::hash()); \
ASSERT_##a(hf.add(b, h)); \
} while(0)
#define ADD_TRUE(v, h) ADD(v, h, TRUE)
diff --git a/tests/unit_tests/hashchain.cpp b/tests/unit_tests/hashchain.cpp
index df87f5df2..d07dfdb7a 100644
--- a/tests/unit_tests/hashchain.cpp
+++ b/tests/unit_tests/hashchain.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/http.cpp b/tests/unit_tests/http.cpp
index 372448764..938f444d7 100644
--- a/tests/unit_tests/http.cpp
+++ b/tests/unit_tests/http.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/logging.cpp b/tests/unit_tests/logging.cpp
index 476e92bef..12d49e2fb 100644
--- a/tests/unit_tests/logging.cpp
+++ b/tests/unit_tests/logging.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018, The Monero Project
+// Copyright (c) 2016-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/long_term_block_weight.cpp b/tests/unit_tests/long_term_block_weight.cpp
new file mode 100644
index 000000000..f37b608b6
--- /dev/null
+++ b/tests/unit_tests/long_term_block_weight.cpp
@@ -0,0 +1,386 @@
+// Copyright (c) 2019, 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.
+
+#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"
+
+#define TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW 5000
+
+namespace
+{
+
+class TestDB: public cryptonote::BaseTestDB
+{
+private:
+ struct block_t
+ {
+ size_t weight;
+ uint64_t long_term_weight;
+ };
+
+public:
+ TestDB() { m_open = true; }
+
+ virtual void add_block( const cryptonote::block& blk
+ , size_t block_weight
+ , uint64_t long_term_block_weight
+ , const cryptonote::difficulty_type& cumulative_difficulty
+ , const uint64_t& coins_generated
+ , uint64_t num_rct_outs
+ , const crypto::hash& blk_hash
+ ) override {
+ blocks.push_back({block_weight, long_term_block_weight});
+ }
+ virtual uint64_t height() const override { return blocks.size(); }
+ virtual size_t get_block_weight(const uint64_t &h) const override { return blocks[h].weight; }
+ virtual uint64_t get_block_long_term_weight(const uint64_t &h) const override { return blocks[h].long_term_weight; }
+ virtual crypto::hash top_block_hash(uint64_t *block_height = NULL) const override {
+ uint64_t h = height();
+ crypto::hash top = crypto::null_hash;
+ if (h)
+ *(uint64_t*)&top = h - 1;
+ if (block_height)
+ *block_height = h - 1;
+ return top;
+ }
+ virtual void pop_block(cryptonote::block &blk, std::vector<cryptonote::transaction> &txs) override { blocks.pop_back(); }
+
+private:
+ std::vector<block_t> blocks;
+};
+
+static uint32_t lcg_seed = 0;
+
+static uint32_t lcg()
+{
+ lcg_seed = (lcg_seed * 0x100000001b3 + 0xcbf29ce484222325) & 0xffffffff;
+ return lcg_seed;
+}
+
+}
+
+#define PREFIX_WINDOW(hf_version,window) \
+ std::unique_ptr<cryptonote::Blockchain> bc; \
+ cryptonote::tx_memory_pool txpool(*bc); \
+ bc.reset(new cryptonote::Blockchain(txpool)); \
+ 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::Blockchain *blockchain = bc.get(); \
+ 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(long_term_block_weight, empty_short)
+{
+ PREFIX(9);
+
+ ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
+
+ ASSERT_EQ(bc->get_current_cumulative_block_weight_median(), CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5);
+ ASSERT_EQ(bc->get_current_cumulative_block_weight_limit(), CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 * 2);
+}
+
+TEST(long_term_block_weight, identical_before_fork)
+{
+ PREFIX(9);
+
+ for (uint64_t h = 1; h < 10 * TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW; ++h)
+ {
+ size_t w = h < CRYPTONOTE_REWARD_BLOCKS_WINDOW ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : bc->get_current_cumulative_block_weight_limit();
+ uint64_t ltw = bc->get_next_long_term_block_weight(w);
+ bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
+ ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
+ }
+ for (uint64_t h = 0; h < 10 * TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW; ++h)
+ {
+ ASSERT_EQ(bc->get_db().get_block_long_term_weight(h), bc->get_db().get_block_weight(h));
+ }
+}
+
+TEST(long_term_block_weight, identical_after_fork_before_long_term_window)
+{
+ PREFIX(10);
+
+ for (uint64_t h = 1; h <= TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW; ++h)
+ {
+ size_t w = h < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : bc->get_current_cumulative_block_weight_limit();
+ uint64_t ltw = bc->get_next_long_term_block_weight(w);
+ bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
+ ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
+ }
+ for (uint64_t h = 0; h < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW; ++h)
+ {
+ ASSERT_EQ(bc->get_db().get_block_long_term_weight(h), bc->get_db().get_block_weight(h));
+ }
+}
+
+TEST(long_term_block_weight, ceiling_at_30000000)
+{
+ PREFIX(10);
+
+ for (uint64_t h = 0; h < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW + TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW / 2 - 1; ++h)
+ {
+ size_t w = h < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : bc->get_current_cumulative_block_weight_limit();
+ uint64_t ltw = bc->get_next_long_term_block_weight(w);
+ bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
+ ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
+ }
+ ASSERT_EQ(bc->get_current_cumulative_block_weight_median(), 15000000);
+ ASSERT_EQ(bc->get_current_cumulative_block_weight_limit(), 30000000);
+}
+
+TEST(long_term_block_weight, multi_pop)
+{
+ PREFIX(10);
+
+ for (uint64_t h = 1; h <= TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW + 20; ++h)
+ {
+ size_t w = h < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : bc->get_current_cumulative_block_weight_limit();
+ uint64_t ltw = bc->get_next_long_term_block_weight(w);
+ bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
+ ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
+ }
+
+ const uint64_t effective_median = bc->get_current_cumulative_block_weight_median();
+ const uint64_t effective_limit = bc->get_current_cumulative_block_weight_limit();
+
+ for (uint64_t h = 0; h < 4; ++h)
+ {
+ size_t w = h < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : bc->get_current_cumulative_block_weight_limit();
+ uint64_t ltw = bc->get_next_long_term_block_weight(w);
+ bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
+ ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
+ }
+
+ cryptonote::block b;
+ std::vector<cryptonote::transaction> txs;
+ bc->get_db().pop_block(b, txs);
+ bc->get_db().pop_block(b, txs);
+ bc->get_db().pop_block(b, txs);
+ bc->get_db().pop_block(b, txs);
+ ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
+
+ ASSERT_EQ(effective_median, bc->get_current_cumulative_block_weight_median());
+ ASSERT_EQ(effective_limit, bc->get_current_cumulative_block_weight_limit());
+}
+
+TEST(long_term_block_weight, multiple_updates)
+{
+ PREFIX(10);
+
+ for (uint64_t h = 1; h <= 3 * TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW; ++h)
+ {
+ size_t w = h < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : bc->get_current_cumulative_block_weight_limit();
+ uint64_t ltw = bc->get_next_long_term_block_weight(w);
+ bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
+ ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
+ const uint64_t effective_median = bc->get_current_cumulative_block_weight_median();
+ const uint64_t effective_limit = bc->get_current_cumulative_block_weight_limit();
+ ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
+ ASSERT_EQ(effective_median, bc->get_current_cumulative_block_weight_median());
+ ASSERT_EQ(effective_limit, bc->get_current_cumulative_block_weight_limit());
+ ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
+ ASSERT_EQ(effective_median, bc->get_current_cumulative_block_weight_median());
+ ASSERT_EQ(effective_limit, bc->get_current_cumulative_block_weight_limit());
+ ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
+ ASSERT_EQ(effective_median, bc->get_current_cumulative_block_weight_median());
+ ASSERT_EQ(effective_limit, bc->get_current_cumulative_block_weight_limit());
+ }
+}
+
+TEST(long_term_block_weight, pop_invariant_max)
+{
+ PREFIX(10);
+
+ for (uint64_t h = 1; h < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW - 10; ++h)
+ {
+ size_t w = bc->get_db().height() < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : bc->get_current_cumulative_block_weight_limit();
+ uint64_t ltw = bc->get_next_long_term_block_weight(w);
+ bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
+ ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
+ }
+
+ for (int n = 0; n < 1000; ++n)
+ {
+ // pop some blocks, then add some more
+ int remove = 1 + (n * 17) % 8;
+ int add = (n * 23) % 12;
+
+ // save long term block weights we're about to remove
+ uint64_t old_ltbw[16], h0 = bc->get_db().height() - remove - 1;
+ for (int i = -2; i < remove; ++i)
+ {
+ old_ltbw[i + 2] = bc->get_db().get_block_long_term_weight(h0 + i);
+ }
+
+ for (int i = 0; i < remove; ++i)
+ {
+ cryptonote::block b;
+ std::vector<cryptonote::transaction> txs;
+ bc->get_db().pop_block(b, txs);
+ ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
+ }
+ for (int i = 0; i < add; ++i)
+ {
+ size_t w = bc->get_db().height() < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : bc->get_current_cumulative_block_weight_limit();
+ uint64_t ltw = bc->get_next_long_term_block_weight(w);
+ bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, bc->get_db().height(), bc->get_db().height(), {});
+ ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
+ }
+
+ // check the new values are the same as the old ones
+ for (int i = -2; i < std::min(add, remove); ++i)
+ {
+ ASSERT_EQ(bc->get_db().get_block_long_term_weight(h0 + i), old_ltbw[i + 2]);
+ }
+ }
+}
+
+TEST(long_term_block_weight, pop_invariant_random)
+{
+ PREFIX(10);
+
+ for (uint64_t h = 1; h < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW - 10; ++h)
+ {
+ size_t w = bc->get_db().height() < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : bc->get_current_cumulative_block_weight_limit();
+ uint64_t ltw = bc->get_next_long_term_block_weight(w);
+ bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
+ ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
+ }
+
+ for (int n = 0; n < 1000; ++n)
+ {
+ // pop some blocks, then add some more
+ int remove = 1 + (n * 17) % 8;
+ int add = (n * 23) % 123;
+
+ // save long term block weights we're about to remove
+ uint64_t old_ltbw[16], h0 = bc->get_db().height() - remove - 1;
+ for (int i = -2; i < remove; ++i)
+ {
+ old_ltbw[i + 2] = bc->get_db().get_block_long_term_weight(h0 + i);
+ }
+
+ for (int i = 0; i < remove; ++i)
+ {
+ cryptonote::block b;
+ std::vector<cryptonote::transaction> txs;
+ bc->get_db().pop_block(b, txs);
+ ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
+ const uint64_t effective_median = bc->get_current_cumulative_block_weight_median();
+ const uint64_t effective_limit = bc->get_current_cumulative_block_weight_limit();
+ ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
+ ASSERT_EQ(effective_median, bc->get_current_cumulative_block_weight_median());
+ ASSERT_EQ(effective_limit, bc->get_current_cumulative_block_weight_limit());
+ }
+ for (int i = 0; i < add; ++i)
+ {
+ lcg_seed = bc->get_db().height();
+ uint32_t r = lcg();
+ size_t w = bc->get_db().height() < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW ? CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5 : (r % bc->get_current_cumulative_block_weight_limit());
+ uint64_t ltw = bc->get_next_long_term_block_weight(w);
+ bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, bc->get_db().height(), bc->get_db().height(), {});
+ ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
+ const uint64_t effective_median = bc->get_current_cumulative_block_weight_median();
+ const uint64_t effective_limit = bc->get_current_cumulative_block_weight_limit();
+ ASSERT_TRUE(bc->update_next_cumulative_weight_limit());
+ ASSERT_EQ(effective_median, bc->get_current_cumulative_block_weight_median());
+ ASSERT_EQ(effective_limit, bc->get_current_cumulative_block_weight_limit());
+ }
+
+ // check the new values are the same as the old ones
+ for (int i = -2; i < std::min(add, remove); ++i)
+ {
+ ASSERT_EQ(bc->get_db().get_block_long_term_weight(h0 + i), old_ltbw[i + 2]);
+ }
+ }
+}
+
+TEST(long_term_block_weight, long_growth_spike_and_drop)
+{
+ PREFIX(10);
+
+ uint64_t long_term_effective_median_block_weight;
+
+ // constant init
+ for (uint64_t h = 0; h < TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW; ++h)
+ {
+ size_t w = CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V5;
+ uint64_t ltw = bc->get_next_long_term_block_weight(w);
+ bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
+ ASSERT_TRUE(bc->update_next_cumulative_weight_limit(&long_term_effective_median_block_weight));
+ }
+ ASSERT_EQ(long_term_effective_median_block_weight, 300000);
+
+ // slow 10% yearly for a year (scaled down by 100000 / TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW) -> 8% change
+ for (uint64_t h = 0; h < 365 * 720 * TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW / 100000; ++h)
+ {
+ //size_t w = bc->get_current_cumulative_block_weight_median() * rate;
+ float t = h / float(365 * 720 * TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW / 100000);
+ size_t w = 300000 + t * 30000;
+ uint64_t ltw = bc->get_next_long_term_block_weight(w);
+ bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
+ ASSERT_TRUE(bc->update_next_cumulative_weight_limit(&long_term_effective_median_block_weight));
+ }
+ ASSERT_GT(long_term_effective_median_block_weight, 300000 * 1.07);
+ ASSERT_LT(long_term_effective_median_block_weight, 300000 * 1.09);
+
+ // spike over three weeks - does not move much
+ for (uint64_t h = 0; h < 21 * 720 * TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW / 100000; ++h)
+ {
+ size_t w = bc->get_current_cumulative_block_weight_limit();
+ uint64_t ltw = bc->get_next_long_term_block_weight(w);
+ bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
+ ASSERT_TRUE(bc->update_next_cumulative_weight_limit(&long_term_effective_median_block_weight));
+ }
+ ASSERT_GT(long_term_effective_median_block_weight, 300000 * 1.07);
+ ASSERT_LT(long_term_effective_median_block_weight, 300000 * 1.09);
+
+ // drop - does not move much
+ for (uint64_t h = 0; h < 21 * 720 * TEST_LONG_TERM_BLOCK_WEIGHT_WINDOW / 100000; ++h)
+ {
+ size_t w = bc->get_current_cumulative_block_weight_median() * .25;
+ uint64_t ltw = bc->get_next_long_term_block_weight(w);
+ bc->get_db().add_block(std::make_pair(cryptonote::block(), ""), w, ltw, h, h, {});
+ ASSERT_TRUE(bc->update_next_cumulative_weight_limit(&long_term_effective_median_block_weight));
+ }
+ ASSERT_GT(long_term_effective_median_block_weight, 300000 * 1.07);
+ ASSERT_LT(long_term_effective_median_block_weight, 300000 * 1.09);
+}
diff --git a/tests/unit_tests/main.cpp b/tests/unit_tests/main.cpp
index f7251a09e..76d17f2ad 100644
--- a/tests/unit_tests/main.cpp
+++ b/tests/unit_tests/main.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/memwipe.cpp b/tests/unit_tests/memwipe.cpp
index dd98b8142..e0f5ada20 100644
--- a/tests/unit_tests/memwipe.cpp
+++ b/tests/unit_tests/memwipe.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/mnemonics.cpp b/tests/unit_tests/mnemonics.cpp
index 59642828d..16634e7a1 100644
--- a/tests/unit_tests/mnemonics.cpp
+++ b/tests/unit_tests/mnemonics.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/mul_div.cpp b/tests/unit_tests/mul_div.cpp
index 768b95d4b..b11f715cd 100644
--- a/tests/unit_tests/mul_div.cpp
+++ b/tests/unit_tests/mul_div.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/multisig.cpp b/tests/unit_tests/multisig.cpp
index eb3196863..9a74b3dce 100644
--- a/tests/unit_tests/multisig.cpp
+++ b/tests/unit_tests/multisig.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/notify.cpp b/tests/unit_tests/notify.cpp
index ceeba8649..4de4a8d0a 100644
--- a/tests/unit_tests/notify.cpp
+++ b/tests/unit_tests/notify.cpp
@@ -82,7 +82,6 @@ TEST(notify, works)
ok = true;
break;
}
- std::cout << "got: [" << s << "]" << std::endl;
}
}
boost::filesystem::remove(name_template);
diff --git a/tests/unit_tests/output_distribution.cpp b/tests/unit_tests/output_distribution.cpp
index 649752ac7..45f2c135b 100644
--- a/tests/unit_tests/output_distribution.cpp
+++ b/tests/unit_tests/output_distribution.cpp
@@ -33,7 +33,7 @@
#include "cryptonote_core/cryptonote_core.h"
#include "cryptonote_core/tx_pool.h"
#include "cryptonote_core/blockchain.h"
-#include "testdb.h"
+#include "blockchain_db/testdb.h"
static const uint64_t test_distribution[32] = {
0, 0, 0, 0, 0, 1, 5, 1, 4, 0, 0, 1, 0, 1, 2, 3, 1, 0, 2, 0, 1, 3, 8, 1, 3, 5, 7, 1, 5, 0, 2, 3
@@ -43,7 +43,7 @@ static const size_t test_distribution_size = sizeof(test_distribution) / sizeof(
namespace
{
-class TestDB: public BaseTestDB
+class TestDB: public cryptonote::BaseTestDB
{
public:
TestDB(size_t bc_height = test_distribution_size): blockchain_height(bc_height) { m_open = true; }
diff --git a/tests/unit_tests/output_selection.cpp b/tests/unit_tests/output_selection.cpp
index fecd547f7..a528679e4 100644
--- a/tests/unit_tests/output_selection.cpp
+++ b/tests/unit_tests/output_selection.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/parse_amount.cpp b/tests/unit_tests/parse_amount.cpp
index eb8c925b1..f4f57f90f 100644
--- a/tests/unit_tests/parse_amount.cpp
+++ b/tests/unit_tests/parse_amount.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/ringct.cpp b/tests/unit_tests/ringct.cpp
index 3f302cb83..e239154cf 100644
--- a/tests/unit_tests/ringct.cpp
+++ b/tests/unit_tests/ringct.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/serialization.cpp b/tests/unit_tests/serialization.cpp
index 343a11c37..eb70caefc 100644
--- a/tests/unit_tests/serialization.cpp
+++ b/tests/unit_tests/serialization.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/sha256.cpp b/tests/unit_tests/sha256.cpp
index 0d1788f3e..898c9e4b3 100644
--- a/tests/unit_tests/sha256.cpp
+++ b/tests/unit_tests/sha256.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/slow_memmem.cpp b/tests/unit_tests/slow_memmem.cpp
index 436259bee..4f13e00e6 100644
--- a/tests/unit_tests/slow_memmem.cpp
+++ b/tests/unit_tests/slow_memmem.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/subaddress.cpp b/tests/unit_tests/subaddress.cpp
index 67802d736..385a2a8ab 100644
--- a/tests/unit_tests/subaddress.cpp
+++ b/tests/unit_tests/subaddress.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/test_peerlist.cpp b/tests/unit_tests/test_peerlist.cpp
index 03aa48ea0..dbb3aaf96 100644
--- a/tests/unit_tests/test_peerlist.cpp
+++ b/tests/unit_tests/test_peerlist.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/test_protocol_pack.cpp b/tests/unit_tests/test_protocol_pack.cpp
index d385bbc42..7329c0d23 100644
--- a/tests/unit_tests/test_protocol_pack.cpp
+++ b/tests/unit_tests/test_protocol_pack.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/test_tx_utils.cpp b/tests/unit_tests/test_tx_utils.cpp
index 55c76c3b6..d8d760b07 100644
--- a/tests/unit_tests/test_tx_utils.cpp
+++ b/tests/unit_tests/test_tx_utils.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/unbound.cpp b/tests/unit_tests/unbound.cpp
index 3676e88f0..d122b2ad2 100644
--- a/tests/unit_tests/unbound.cpp
+++ b/tests/unit_tests/unbound.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018, The Monero Project
+// Copyright (c) 2016-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/unit_tests_utils.h b/tests/unit_tests/unit_tests_utils.h
index ecd97e3d5..5944bd55a 100644
--- a/tests/unit_tests/unit_tests_utils.h
+++ b/tests/unit_tests/unit_tests_utils.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/uri.cpp b/tests/unit_tests/uri.cpp
index 999c117c2..df1dbc130 100644
--- a/tests/unit_tests/uri.cpp
+++ b/tests/unit_tests/uri.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2016-2018, The Monero Project
+// Copyright (c) 2016-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/varint.cpp b/tests/unit_tests/varint.cpp
index db675c888..ca0900682 100644
--- a/tests/unit_tests/varint.cpp
+++ b/tests/unit_tests/varint.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2014-2018, The Monero Project
+// Copyright (c) 2014-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/tests/unit_tests/vercmp.cpp b/tests/unit_tests/vercmp.cpp
index 43045979e..77399fa89 100644
--- a/tests/unit_tests/vercmp.cpp
+++ b/tests/unit_tests/vercmp.cpp
@@ -1,4 +1,4 @@
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
//
// All rights reserved.
//
diff --git a/translations/CMakeLists.txt b/translations/CMakeLists.txt
index dc7772c1d..589005a42 100644
--- a/translations/CMakeLists.txt
+++ b/translations/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2017-2018, The Monero Project
+# Copyright (c) 2017-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/translations/generate_translations_header.c b/translations/generate_translations_header.c
index 008a1b75e..4c80eec31 100644
--- a/translations/generate_translations_header.c
+++ b/translations/generate_translations_header.c
@@ -1,5 +1,5 @@
// Copyright (c) 2013, Sergey Lyubka
-// Copyright (c) 2017-2018, The Monero Project
+// Copyright (c) 2017-2019, The Monero Project
// All rights reserved.
// Released under the MIT license.
diff --git a/utils/build_scripts/windows.bat b/utils/build_scripts/windows.bat
index 717324fab..76d4f86bb 100644
--- a/utils/build_scripts/windows.bat
+++ b/utils/build_scripts/windows.bat
@@ -1,4 +1,4 @@
-:: Copyright (c) 2014-2018, The Monero Project
+:: Copyright (c) 2014-2019, The Monero Project
::
:: All rights reserved.
::
diff --git a/utils/munin_plugins/alt_blocks_count b/utils/munin_plugins/alt_blocks_count
index 5f9e43671..2510b7bc3 100644
--- a/utils/munin_plugins/alt_blocks_count
+++ b/utils/munin_plugins/alt_blocks_count
@@ -1,6 +1,6 @@
#!/bin/bash
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/utils/munin_plugins/difficulty b/utils/munin_plugins/difficulty
index f9a72b0ca..a7d90c15f 100644
--- a/utils/munin_plugins/difficulty
+++ b/utils/munin_plugins/difficulty
@@ -1,6 +1,6 @@
#!/bin/bash
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/utils/munin_plugins/grey_peerlist_size b/utils/munin_plugins/grey_peerlist_size
index 52f5b99cb..b1cf66f14 100644
--- a/utils/munin_plugins/grey_peerlist_size
+++ b/utils/munin_plugins/grey_peerlist_size
@@ -1,6 +1,6 @@
#!/bin/bash
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/utils/munin_plugins/height b/utils/munin_plugins/height
index 470798b8f..20b3e65ef 100644
--- a/utils/munin_plugins/height
+++ b/utils/munin_plugins/height
@@ -1,6 +1,6 @@
#!/bin/bash
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/utils/munin_plugins/incoming_connections_count b/utils/munin_plugins/incoming_connections_count
index 3fea27fa2..1dcc1f4d0 100644
--- a/utils/munin_plugins/incoming_connections_count
+++ b/utils/munin_plugins/incoming_connections_count
@@ -1,6 +1,6 @@
#!/bin/bash
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/utils/munin_plugins/outgoing_connections_count b/utils/munin_plugins/outgoing_connections_count
index 49d8f4fc4..45a0500dd 100644
--- a/utils/munin_plugins/outgoing_connections_count
+++ b/utils/munin_plugins/outgoing_connections_count
@@ -1,6 +1,6 @@
#!/bin/bash
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/utils/munin_plugins/tx_count b/utils/munin_plugins/tx_count
index d63c8a9d1..e81e5f321 100644
--- a/utils/munin_plugins/tx_count
+++ b/utils/munin_plugins/tx_count
@@ -1,6 +1,6 @@
#!/bin/bash
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/utils/munin_plugins/tx_pool_size b/utils/munin_plugins/tx_pool_size
index f01685a41..245733578 100644
--- a/utils/munin_plugins/tx_pool_size
+++ b/utils/munin_plugins/tx_pool_size
@@ -1,6 +1,6 @@
#!/bin/bash
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#
diff --git a/utils/munin_plugins/white_peerlist_size b/utils/munin_plugins/white_peerlist_size
index bd7d7a3c5..8d87a9f0a 100644
--- a/utils/munin_plugins/white_peerlist_size
+++ b/utils/munin_plugins/white_peerlist_size
@@ -1,6 +1,6 @@
#!/bin/bash
-# Copyright (c) 2014-2018, The Monero Project
+# Copyright (c) 2014-2019, The Monero Project
#
# All rights reserved.
#