diff --git a/README.md b/README.md index 655e780a..97bd8b80 100644 --- a/README.md +++ b/README.md @@ -13,14 +13,14 @@ Be sure to clone the repository properly:\ ### Dependencies | component / version | minimum
(not recommended but may work) | recommended | most recent of what we have ever tested | |--|--|--|--| -| gcc (Linux) | 5.4.0 | 9.4.0 | 12.3.0 | +| gcc (Linux) | 8.4.0 | 9.4.0 | 12.3.0 | | llvm/clang (Linux) | UNKNOWN | 7.0.1 | 8.0.0 | -| [MSVC](https://visualstudio.microsoft.com/downloads/) (Windows) | 2017 (15.9.30) | 2019 (16.11.34) | 2022 (17.11.5) | +| [MSVC](https://visualstudio.microsoft.com/downloads/) (Windows) | 2017 (15.9.30) | 2022 (17.11.5) | 2022 (17.12.3) | | [XCode](https://developer.apple.com/downloads/) (macOS) | 12.3 | 14.3 | 15.2 | | [CMake](https://cmake.org/download/) | 3.15.5 | 3.26.3 | 3.29.0 | | [Boost](https://www.boost.org/users/download/) | 1.75 | 1.84 | 1.84 | -| [OpenSSL](https://www.openssl.org/source/) [(win)](https://slproweb.com/products/Win32OpenSSL.html) | 1.1.1n | 1.1.1w | 1.1.1w | -| [Qt](https://download.qt.io/archive/qt/) (*only for GUI*) | 5.8.0 | 5.11.2 | 5.15.2 | +| [OpenSSL](https://www.openssl.org/source/) [(win)](https://slproweb.com/products/Win32OpenSSL.html) | 1.1.1n | 1.1.1w | 3.4 | +| [Qt](https://download.qt.io/archive/qt/) (*only for GUI*) | 5.8.0 | 5.15.2 | 5.15.2 | Note:\ [*server version*] denotes steps required for building command-line tools (daemon, simplewallet, etc.).\ @@ -52,7 +52,7 @@ Recommended OS versions: Ubuntu 20.04, 22.04 LTS. 3. Download and build Boost\ (Assuming you have cloned Zano into the 'zano' folder. If you used a different location for Zano, **edit line 4** accordingly.) - curl -OL https://boostorg.jfrog.io/artifactory/main/release/1.84.0/source/boost_1_84_0.tar.bz2 + curl -OL https://archives.boost.io/release/1.84.0/source/boost_1_84_0.tar.bz2 echo "cc4b893acf645c9d4b698e9a0f08ca8846aa5d6c68275c14c3e7949c24109454 boost_1_84_0.tar.bz2" | shasum -c && tar -xjf boost_1_84_0.tar.bz2 rm boost_1_84_0.tar.bz2 && cd boost_1_84_0 ./bootstrap.sh --with-libraries=system,filesystem,thread,date_time,chrono,regex,serialization,atomic,program_options,locale,timer,log diff --git a/contrib/epee/include/gzip_encoding.h b/contrib/epee/include/gzip_encoding.h index e2e1ea2c..1d354f78 100644 --- a/contrib/epee/include/gzip_encoding.h +++ b/contrib/epee/include/gzip_encoding.h @@ -182,7 +182,7 @@ namespace net_utils * */ inline - virtual void stop(std::string& OUT collect_remains) + virtual void stop(std::string& OUT collect_remains) override { } protected: @@ -260,6 +260,10 @@ namespace net_utils m_pcb.reset(new abstract_callback(cb)); return content_encoding_gzip::update_in(piece_of_transfer); } + + virtual void stop(std::string& OUT collect_remains) override + {} + template bool stop(callback_t cb) {return true;} diff --git a/contrib/epee/include/net/http_client.h b/contrib/epee/include/net/http_client.h index 9c658e43..fea2f655 100644 --- a/contrib/epee/include/net/http_client.h +++ b/contrib/epee/include/net/http_client.h @@ -200,8 +200,26 @@ namespace epee namespace http { + + + struct i_http_client + { + virtual void set_host_name(const std::string& name) = 0; + virtual boost::asio::ip::tcp::socket& get_socket() = 0; + virtual bool connect(const std::string& host, int port, unsigned int timeout) = 0; + virtual bool set_timeouts(unsigned int connection_timeout, unsigned int recv_timeout) = 0; + virtual bool connect(const std::string& host, std::string port) = 0; + virtual bool connect(const std::string& host, const std::string& port, unsigned int timeout) = 0; + virtual bool disconnect() = 0; + virtual bool is_connected() = 0; + virtual bool invoke_get(const std::string& uri, const std::string& body = std::string(), const http_response_info** ppresponse_info = NULL, const fields_list& additional_params = fields_list()) = 0; + virtual bool invoke(const std::string& uri, const std::string& method, const std::string& body, const http_response_info** ppresponse_info = NULL, const fields_list& additional_params = fields_list()) = 0; + virtual bool invoke_post(const std::string& uri, const std::string& body, const http_response_info** ppresponse_info = NULL, const fields_list& additional_params = fields_list()) = 0; + }; + template - class http_simple_client_t : public i_target_handler + class http_simple_client_t : public i_target_handler, + public i_http_client { public: @@ -893,6 +911,64 @@ namespace epee typedef http_simple_client_t https_simple_client; + //suitable for both http and https + class http_universal_client: public i_http_client + { + public: + http_universal_client(): m_pclient(new http_simple_client()) + {} + // Forward all calls to m_pclient + void set_host_name(const std::string& name) override + { + m_pclient->set_host_name(name); + } + bool connect(const std::string& host, int port, unsigned int timeout) override + { + return m_pclient->connect(host, port, timeout); + } + boost::asio::ip::tcp::socket& get_socket() override { return m_pclient->get_socket(); } + bool set_timeouts(unsigned int connection_timeout, unsigned int recv_timeout) override { return m_pclient->set_timeouts(connection_timeout, recv_timeout); } + bool connect(const std::string& host, std::string port) override { return m_pclient->connect(host, port); } + bool connect(const std::string& host, const std::string& port, unsigned int timeout) override { return m_pclient->connect(host, port, timeout); } + bool disconnect() override { return m_pclient->disconnect(); } + bool is_connected() override { return m_pclient->is_connected(); } + bool invoke_get(const std::string& uri, const std::string& body = std::string(), const http_response_info** ppresponse_info = nullptr, const fields_list& additional_params = fields_list()) override { return m_pclient->invoke_get(uri, body, ppresponse_info, additional_params); } + bool invoke(const std::string& uri, const std::string& method, const std::string& body, const http_response_info** ppresponse_info = nullptr, const fields_list& additional_params = fields_list()) override { return m_pclient->invoke(uri, method, body, ppresponse_info, additional_params); } + bool invoke_post(const std::string& uri, const std::string& body, const http_response_info** ppresponse_info = nullptr, const fields_list& additional_params = fields_list()) override { return m_pclient->invoke_post(uri, body, ppresponse_info, additional_params); } + + void set_is_ssl(bool is_ssl) + { + if (m_is_ssl != is_ssl) + { + if (is_ssl) + { + m_pclient.reset(new https_simple_client()); + } + else + { + m_pclient.reset(new http_simple_client()); + } + m_is_ssl = is_ssl; + } + } + private: + bool m_is_ssl = false; + std::shared_ptr m_pclient; + }; + + + template + void configure_transport(const std::string schema, transport& tr) + {} + inline void configure_transport(const std::string schema, http_universal_client& tr) + { + if (schema == "https") + tr.set_is_ssl(true); + else + tr.set_is_ssl(false); + } + + /************************************************************************/ /* */ /************************************************************************/ @@ -915,6 +991,7 @@ namespace epee if (!port) port = 80;//default for http + configure_transport(u_c.schema, tr); if (!tr.connect(u_c.host, port, timeout)) { LOG_PRINT_L2("invoke_request: cannot connect to " << u_c.host << ":" << port); diff --git a/contrib/epee/include/serialization/keyvalue_serialization_overloads.h b/contrib/epee/include/serialization/keyvalue_serialization_overloads.h index 1bd2db1c..0eefa26d 100644 --- a/contrib/epee/include/serialization/keyvalue_serialization_overloads.h +++ b/contrib/epee/include/serialization/keyvalue_serialization_overloads.h @@ -117,7 +117,7 @@ namespace epee static bool unserialize_stl_container_t_val(stl_container& container, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname) { container.clear(); - typename stl_container::value_type exchange_val; + typename stl_container::value_type exchange_val{}; typename t_storage::harray hval_array = stg.get_first_value(pname, exchange_val, hparent_section); if(!hval_array) return false; container.push_back(std::move(exchange_val)); diff --git a/contrib/epee/include/storages/parserse_base_utils.h b/contrib/epee/include/storages/parserse_base_utils.h index bd40c688..d27bfca7 100644 --- a/contrib/epee/include/storages/parserse_base_utils.h +++ b/contrib/epee/include/storages/parserse_base_utils.h @@ -23,10 +23,8 @@ // (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 namespace epee { diff --git a/contrib/tor-connect b/contrib/tor-connect index b589edb1..1be2073e 160000 --- a/contrib/tor-connect +++ b/contrib/tor-connect @@ -1 +1 @@ -Subproject commit b589edb1906dccb387cfeded6ed12286c5f0405f +Subproject commit 1be2073ed3da5e9e6e94e8362548df26a22b1bd2 diff --git a/src/currency_core/blockchain_storage.cpp b/src/currency_core/blockchain_storage.cpp index d06b74c2..01074e2c 100644 --- a/src/currency_core/blockchain_storage.cpp +++ b/src/currency_core/blockchain_storage.cpp @@ -30,7 +30,6 @@ #include "common/boost_serialization_helper.h" #include "warnings.h" #include "crypto/hash.h" -#include "miner_common.h" #include "storages/portable_storage_template_helper.h" #include "basic_pow_helpers.h" #include "version.h" diff --git a/src/currency_core/currency_core.cpp b/src/currency_core/currency_core.cpp index 8d29c38d..37e67e93 100644 --- a/src/currency_core/currency_core.cpp +++ b/src/currency_core/currency_core.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2018 Zano Project +// Copyright (c) 2014-2025 Zano Project // Copyright (c) 2014-2018 The Louisdor Project // Copyright (c) 2012-2013 The Cryptonote developers // Copyright (c) 2012-2013 The Boolberry developers @@ -34,8 +34,10 @@ namespace currency core::core(i_currency_protocol* pprotocol) : m_mempool(m_blockchain_storage, pprotocol) , m_blockchain_storage(m_mempool) +#ifdef CPU_MINING_ENABLED , m_miner(this, m_blockchain_storage) - , m_miner_address(boost::value_initialized()) +#endif + //, m_miner_address(boost::value_initialized()) , m_starter_message_showed(false) , m_critical_error_handler(nullptr) , m_stop_after_height(0) @@ -165,8 +167,10 @@ namespace currency m_mempool.remove_incompatible_txs(); +#ifdef CPU_MINING_ENABLED r = m_miner.init(vm); CHECK_AND_ASSERT_MES(r, false, "Failed to initialize miner"); +#endif //check if tx_pool module synchronized with blockchaine storage // if (m_blockchain_storage.get_top_block_id() != m_mempool.get_last_core_hash()) @@ -193,8 +197,10 @@ namespace currency { //m_mempool.set_last_core_hash(m_blockchain_storage.get_top_block_id()); +#ifdef CPU_MINING_ENABLED m_miner.stop(); m_miner.deinit(); +#endif m_mempool.deinit(); m_blockchain_storage.deinit(); return true; @@ -274,7 +280,9 @@ namespace currency //----------------------------------------------------------------------------------------------- bool core::get_stat_info(const core_stat_info::params& pr, core_stat_info& st_inf) { +#ifdef CPU_MINING_ENABLED st_inf.mining_speed = m_miner.get_speed(); +#endif st_inf.alternative_blocks = m_blockchain_storage.get_alternative_blocks_count(); st_inf.blockchain_height = m_blockchain_storage.get_current_blockchain_size(); st_inf.tx_pool_size = m_mempool.get_transactions_count(); @@ -405,12 +413,16 @@ namespace currency //----------------------------------------------------------------------------------------------- void core::pause_mine() { +#ifdef CPU_MINING_ENABLED m_miner.pause(); +#endif } //----------------------------------------------------------------------------------------------- void core::resume_mine() { +#ifdef CPU_MINING_ENABLED m_miner.resume(); +#endif } //----------------------------------------------------------------------------------------------- bool core::handle_block_found(const block& b, block_verification_context* p_verification_result, bool need_update_miner_block_template) @@ -422,10 +434,10 @@ namespace currency if (!p_verification_result) p_verification_result = &bvc; - m_miner.pause(); + pause_mine(); misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler([this]() { - m_miner.resume(); + resume_mine(); }); TIME_MEASURE_START_MS(time_add_new_block_ms); @@ -520,7 +532,9 @@ namespace currency //----------------------------------------------------------------------------------------------- void core::on_synchronized() { +#ifdef CPU_MINING_ENABLED m_miner.on_synchronized(); +#endif } bool core::get_backward_blocks_sizes(uint64_t from_height, std::vector& sizes, size_t count) { @@ -685,7 +699,9 @@ namespace currency bool core::update_miner_block_template() { notify_blockchain_update_listeners(); +#ifdef CPU_MINING_ENABLED m_miner.on_block_chain_update(); +#endif return true; } //----------------------------------------------------------------------------------------------- @@ -708,7 +724,9 @@ namespace currency m_prune_alt_blocks_interval.do_call([this](){return m_blockchain_storage.prune_aged_alt_blocks();}); m_check_free_space_interval.do_call([this](){ check_free_space(); return true; }); +#ifdef CPU_MINING_ENABLED m_miner.on_idle(); +#endif m_mempool.on_idle(); return true; } diff --git a/src/currency_core/currency_core.h b/src/currency_core/currency_core.h index feeca5f4..637103b1 100644 --- a/src/currency_core/currency_core.h +++ b/src/currency_core/currency_core.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2018 Zano Project +// Copyright (c) 2014-2025 Zano Project // Copyright (c) 2014-2018 The Louisdor Project // Copyright (c) 2012-2013 The Cryptonote developers // Copyright (c) 2012-2013 The Boolberry developers @@ -57,7 +57,9 @@ namespace currency virtual bool get_block_template(const create_block_template_params& params, create_block_template_response& resp); bool get_block_template(block& b, const account_public_address& adr, const account_public_address& stakeholder_address, wide_difficulty_type& diffic, uint64_t& height, const blobdata& ex_nonce, bool pos = false, const pos_entry& pe = pos_entry()); +#ifdef CPU_MINING_ENABLED miner& get_miner(){ return m_miner; } +#endif static void init_options(boost::program_options::options_description& desc); bool init(const boost::program_options::variables_map& vm); bool set_genesis_block(const block& b); @@ -66,7 +68,7 @@ namespace currency uint64_t get_current_tx_version() const; uint64_t get_top_block_height() const; std::string get_config_folder(); - bool get_blockchain_top(uint64_t& heeight, crypto::hash& top_id) const; + bool get_blockchain_top(uint64_t& height, crypto::hash& top_id) const; bool get_blocks(uint64_t start_offset, size_t count, std::list& blocks, std::list& txs); bool get_blocks(uint64_t start_offset, size_t count, std::list& blocks); template @@ -136,13 +138,15 @@ namespace currency void check_free_space(); - blockchain_storage m_blockchain_storage; tx_memory_pool m_mempool; + blockchain_storage m_blockchain_storage; i_currency_protocol* m_pprotocol; i_critical_error_handler* m_critical_error_handler; epee::critical_section m_incoming_tx_lock; +#ifdef CPU_MINING_ENABLED miner m_miner; - account_public_address m_miner_address; +#endif + //account_public_address m_miner_address; std::string m_config_folder; uint64_t m_stop_after_height; currency_protocol_stub m_protocol_stub; diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 7ec3400d..56316dd5 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -4295,7 +4295,7 @@ namespace currency { payment_id.clear(); blobdata blob; - uint64_t prefix; + uint64_t prefix{}; if (!tools::base58::decode_addr(str, prefix, blob)) { LOG_PRINT_L1("Invalid address format: base58 decoding failed for \"" << str << "\""); diff --git a/src/currency_core/genesis.cpp b/src/currency_core/genesis.cpp index a58dcb4e..5c5435a5 100644 --- a/src/currency_core/genesis.cpp +++ b/src/currency_core/genesis.cpp @@ -1,8 +1,7 @@ -// Copyright (c) 2014-2018 Zano Project +// Copyright (c) 2014-2025 Zano Project // Copyright (c) 2014-2018 The Louisdor Project // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. - #include "genesis.h" namespace currency @@ -17,4 +16,3 @@ namespace currency {0x00,0x00}}; #endif } - diff --git a/src/currency_core/genesis.h b/src/currency_core/genesis.h index 8ea77d89..1c025c90 100644 --- a/src/currency_core/genesis.h +++ b/src/currency_core/genesis.h @@ -1,11 +1,11 @@ -// Copyright (c) 2014-2018 Zano Project -// Copyright (c) 2014-2018 Zano Project +// Copyright (c) 2014-2025 Zano Project // Copyright (c) 2014-2018 The Louisdor Project // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#pragma once +#pragma once #include +#include + namespace currency { #pragma pack(push, 1) @@ -17,7 +17,7 @@ namespace currency }; #else - struct genesis_tx_raw_data + struct genesis_tx_raw_data { uint64_t const v[42]; uint8_t const r[2]; @@ -26,7 +26,3 @@ namespace currency #pragma pack(pop) extern const genesis_tx_raw_data ggenesis_tx_raw; } - - - - diff --git a/src/currency_core/miner.cpp b/src/currency_core/miner.cpp index 109d9966..dc37f3f6 100644 --- a/src/currency_core/miner.cpp +++ b/src/currency_core/miner.cpp @@ -31,6 +31,64 @@ using namespace epee; namespace currency { +#ifndef CPU_MINING_ENABLED + + // CPU mining disabled + // currency::miner stub implementation + + /* + miner::miner(i_miner_handler* phandler, blockchain_storage& bc) + {} + miner::~miner() + {} + bool miner::init(const boost::program_options::variables_map& vm) + { + return true; + } + bool miner::deinit() + { + return true; + } + void miner::init_options(boost::program_options::options_description& desc) + {} + bool miner::start(const account_public_address& adr, size_t threads_count) + { + return false; + } + bool miner::stop() + { + return false; + } + bool miner::is_mining() + { + return false; + } + void miner::do_print_hashrate(bool do_hr) + {} + void miner::pause() + {} + void miner::resume() + {} + bool miner::on_block_chain_update() + { + return false; + } + uint64_t miner::get_speed() + { + return 0; + } + void miner::on_synchronized() + {} + bool miner::on_idle() + { + return false; + } + + // end of currency::miner stub implementation + */ +#else + + namespace { const command_line::arg_descriptor arg_extra_messages ("extra-messages-file", "Specify file for extra messages to include into coinbase transactions"); @@ -379,5 +437,8 @@ namespace currency return true; } //----------------------------------------------------------------------------------------------------- -} + +#endif // #ifndef CPU_MINING_ENABLED + +} // namespace currency diff --git a/src/currency_core/miner.h b/src/currency_core/miner.h index c8a37225..674bb4d2 100644 --- a/src/currency_core/miner.h +++ b/src/currency_core/miner.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2018 Zano Project +// Copyright (c) 2014-2025 Zano Project // Copyright (c) 2014-2018 The Louisdor Project // Copyright (c) 2012-2013 The Cryptonote developers // Copyright (c) 2012-2013 The Boolberry developers @@ -7,6 +7,10 @@ #pragma once +#ifdef TESTNET +#define CPU_MINING_ENABLED // disable CPU mining capabilities in mainnet +#endif // #ifndef TESTNET + #include #include #include @@ -30,6 +34,29 @@ namespace currency ~i_miner_handler(){}; }; + inline + static bool find_nonce_for_given_block(block& bl, const wide_difficulty_type& diffic, uint64_t height) + { + bl.nonce = 0; + blobdata bd = get_block_hashing_blob(bl); + crypto::hash bd_hash = crypto::cn_fast_hash(bd.data(), bd.size()); + //uint64_t& nonce_ref = access_nonce_in_block_blob(bd); + //nonce_ref = 0; + + for(; bl.nonce != std::numeric_limits::max(); bl.nonce++) + { + crypto::hash h = get_block_longhash(height, bd_hash, bl.nonce); + if(check_hash(h, diffic)) + { + LOG_PRINT_L1("Found nonce for block: " << get_block_hash(bl) << "[" << height << "]: PoW:" << h << " (diff:" << diffic << "), ts: " << bl.timestamp); + return true; + } + } + return false; + } + +#ifdef CPU_MINING_ENABLED + /************************************************************************/ /* */ /************************************************************************/ @@ -54,27 +81,6 @@ namespace currency void resume(); void do_print_hashrate(bool do_hr); - inline - static bool find_nonce_for_given_block(block& bl, const wide_difficulty_type& diffic, uint64_t height) - { - bl.nonce = 0; - blobdata bd = get_block_hashing_blob(bl); - crypto::hash bd_hash = crypto::cn_fast_hash(bd.data(), bd.size()); - //uint64_t& nonce_ref = access_nonce_in_block_blob(bd); - //nonce_ref = 0; - - for(; bl.nonce != std::numeric_limits::max(); bl.nonce++) - { - crypto::hash h = get_block_longhash(height, bd_hash, bl.nonce); - if(check_hash(h, diffic)) - { - LOG_PRINT_L1("Found nonce for block: " << get_block_hash(bl) << "[" << height << "]: PoW:" << h << " (diff:" << diffic << "), ts: " << bl.timestamp); - return true; - } - } - return false; - } - private: bool set_block_template(const block& bl, const wide_difficulty_type& diffic, uint64_t height); bool worker_thread(); @@ -122,7 +128,7 @@ namespace currency bool m_do_mining; }; -} - +#endif // #ifdef CPU_MINING_ENABLED +} // namespace currency diff --git a/src/currency_core/miner_common.h b/src/currency_core/miner_common.h deleted file mode 100644 index 9c6db391..00000000 --- a/src/currency_core/miner_common.h +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright (c) 2014-2018 Zano Project -// Copyright (c) 2014-2018 The Louisdor Project -// Copyright (c) 2012-2013 The Boolberry developers -// Distributed under the MIT/X11 software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -#pragma once - diff --git a/src/currency_protocol/currency_protocol_handler.inl b/src/currency_protocol/currency_protocol_handler.inl index b9c7a524..94b77505 100644 --- a/src/currency_protocol/currency_protocol_handler.inl +++ b/src/currency_protocol/currency_protocol_handler.inl @@ -229,7 +229,8 @@ namespace currency template uint64_t t_currency_protocol_handler::get_max_seen_height() { - return m_max_height_seen; + uint64_t max_seen = m_max_height_seen; + return std::max(max_seen, m_core.get_blockchain_storage().get_top_block_height()); } //------------------------------------------------------------------------------------------------------------------------ template diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index f5f768fc..4e5d0de0 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -126,7 +126,6 @@ int main(int argc, char* argv[]) log_space::get_set_log_detalisation_level(true, LOG_LEVEL_0); log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL); log_space::log_singletone::enable_channels("core,currency_protocol,tx_pool,wallet", false); - LOG_PRINT_L0("Starting..."); tools::signal_handler::install_fatal([](int sig_number, void* address) { LOG_ERROR("\n\nFATAL ERROR\nsig: " << sig_number << ", address: " << address); @@ -175,7 +174,9 @@ int main(int argc, char* argv[]) currency::core_rpc_server::init_options(desc_cmd_sett); typedef nodetool::node_server > p2psrv_t; p2psrv_t::init_options(desc_cmd_sett); +#ifdef CPU_MINING_ENABLED currency::miner::init_options(desc_cmd_sett); +#endif bc_services::bc_offers_service::init_options(desc_cmd_sett); currency::stratum_server::init_options(desc_cmd_sett); tools::db::db_backend_selector::init_options(desc_cmd_sett); @@ -184,6 +185,7 @@ int main(int argc, char* argv[]) desc_options.add(desc_cmd_only).add(desc_cmd_sett); po::variables_map vm; + bool exit_requested = false; bool r = command_line::handle_error_helper(desc_options, [&]() { po::store(po::parse_command_line(argc, argv, desc_options), vm); @@ -192,7 +194,14 @@ int main(int argc, char* argv[]) { std::cout << CURRENCY_NAME << " v" << PROJECT_VERSION_LONG << ENDL << ENDL; std::cout << desc_options << std::endl; - return false; + exit_requested = true; + return true; + } + else if (command_line::get_arg(vm, command_line::arg_version)) + { + std::cout << CURRENCY_NAME << " v" << PROJECT_VERSION_LONG << ENDL << ENDL; + exit_requested = true; + return true; } std::string data_dir = command_line::get_arg(vm, command_line::arg_data_dir); @@ -214,9 +223,13 @@ int main(int argc, char* argv[]) return true; }); + if (!r) return EXIT_FAILURE; + if (exit_requested) + return EXIT_SUCCESS; + //set up logging options std::string log_dir; std::string log_file_name = log_space::log_singletone::get_default_log_file(); @@ -238,6 +251,7 @@ int main(int argc, char* argv[]) return EXIT_SUCCESS; } + LOG_PRINT_L0("Starting..."); // stratum server is enabled if any of its options present bool stratum_enabled = currency::stratum_server::should_start(vm); diff --git a/src/daemon/daemon_commands_handler.h b/src/daemon/daemon_commands_handler.h index 1b26fb73..2920c118 100644 --- a/src/daemon/daemon_commands_handler.h +++ b/src/daemon/daemon_commands_handler.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2018 Zano Project +// Copyright (c) 2014-2024 Zano Project // Copyright (c) 2014-2018 The Louisdor Project // Copyright (c) 2012-2013 The Cryptonote developers // Distributed under the MIT/X11 software license, see the accompanying @@ -49,12 +49,14 @@ public: m_cmd_binder.set_handler("print_tx", boost::bind(&daemon_commands_handler::print_tx, this, ph::_1), "Print transaction, print_tx "); m_cmd_binder.set_handler("print_asset_info", boost::bind(&daemon_commands_handler::print_asset_info, this, ph::_1), "Print information about the given asset by its id"); m_cmd_binder.set_handler("print_blocked_ips", boost::bind(&daemon_commands_handler::print_blocked_ips, this, ph::_1), "Print ip address blacklists"); +#ifdef CPU_MINING_ENABLED m_cmd_binder.set_handler("start_mining", boost::bind(&daemon_commands_handler::start_mining, this, ph::_1), "Start mining for specified address, start_mining [threads=1]"); m_cmd_binder.set_handler("stop_mining", boost::bind(&daemon_commands_handler::stop_mining, this, ph::_1), "Stop mining"); - m_cmd_binder.set_handler("print_pool", boost::bind(&daemon_commands_handler::print_pool, this, ph::_1), "Print transaction pool (long format)"); - m_cmd_binder.set_handler("print_pool_sh", boost::bind(&daemon_commands_handler::print_pool_sh, this, ph::_1), "Print transaction pool (short format)"); m_cmd_binder.set_handler("show_hr", boost::bind(&daemon_commands_handler::show_hr, this, ph::_1), "Start showing hash rate"); m_cmd_binder.set_handler("hide_hr", boost::bind(&daemon_commands_handler::hide_hr, this, ph::_1), "Stop showing hash rate"); +#endif + m_cmd_binder.set_handler("print_pool", boost::bind(&daemon_commands_handler::print_pool, this, ph::_1), "Print transaction pool (long format)"); + m_cmd_binder.set_handler("print_pool_sh", boost::bind(&daemon_commands_handler::print_pool_sh, this, ph::_1), "Print transaction pool (short format)"); m_cmd_binder.set_handler("save", boost::bind(&daemon_commands_handler::save, this, ph::_1), "Save blockchain"); m_cmd_binder.set_handler("print_daemon_stat", boost::bind(&daemon_commands_handler::print_daemon_stat, this, ph::_1), "Print daemon stat"); m_cmd_binder.set_handler("print_debug_stat", boost::bind(&daemon_commands_handler::print_debug_stat, this, ph::_1), "Print debug stat info"); @@ -184,25 +186,6 @@ private: return true; } - //-------------------------------------------------------------------------------- - bool show_hr(const std::vector& args) - { - if (!m_srv.get_payload_object().get_core().get_miner().is_mining()) - { - std::cout << "Mining is not started. You need start mining before you can see hash rate." << ENDL; - } - else - { - m_srv.get_payload_object().get_core().get_miner().do_print_hashrate(true); - } - return true; - } - //-------------------------------------------------------------------------------- - bool hide_hr(const std::vector& args) - { - m_srv.get_payload_object().get_core().get_miner().do_print_hashrate(false); - return true; - } //-------------------------------------------------------------------------------- bool print_bc_outs(const std::vector& args) { @@ -910,7 +893,9 @@ private: { LOG_PRINT_L0("Pool state: " << ENDL << m_srv.get_payload_object().get_core().print_pool(true)); return true; - } //-------------------------------------------------------------------------------- + } + //-------------------------------------------------------------------------------- +#ifdef CPU_MINING_ENABLED bool start_mining(const std::vector& args) { if (!args.size()) @@ -941,6 +926,26 @@ private: m_srv.get_payload_object().get_core().get_miner().stop(); return true; } + //-------------------------------------------------------------------------------- + bool show_hr(const std::vector& args) + { + if (!m_srv.get_payload_object().get_core().get_miner().is_mining()) + { + std::cout << "Mining is not started. You need start mining before you can see hash rate." << ENDL; + } + else + { + m_srv.get_payload_object().get_core().get_miner().do_print_hashrate(true); + } + return true; + } + //-------------------------------------------------------------------------------- + bool hide_hr(const std::vector& args) + { + m_srv.get_payload_object().get_core().get_miner().do_print_hashrate(false); + return true; + } +#endif // #ifdef CPU_MINING_ENABLED //-------------------------------------------------------------------------------- bool forecast_difficulty(const std::vector& args) { diff --git a/src/gui/qt-daemon/layout b/src/gui/qt-daemon/layout index 638f98f9..dbca6947 160000 --- a/src/gui/qt-daemon/layout +++ b/src/gui/qt-daemon/layout @@ -1 +1 @@ -Subproject commit 638f98f9e25fa3c2f88338b7efe4b1c45ea0e23c +Subproject commit dbca694737496434ef9c7da765ee6aafd7f90158 diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 2cbf9a08..46fe0a41 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2022 Zano Project +// Copyright (c) 2014-2024 Zano Project // Copyright (c) 2014-2018 The Louisdor Project // Copyright (c) 2012-2013 The Cryptonote developers // Distributed under the MIT/X11 software license, see the accompanying @@ -925,6 +925,7 @@ namespace currency return call_res; } //------------------------------------------------------------------------------------------------------------------------------ +#ifdef CPU_MINING_ENABLED bool core_rpc_server::on_start_mining(const COMMAND_RPC_START_MINING::request& req, COMMAND_RPC_START_MINING::response& res, connection_context& cntx) { CHECK_CORE_READY(); @@ -955,6 +956,7 @@ namespace currency res.status = API_RETURN_CODE_OK; return true; } +#endif // #ifdef CPU_MINING_ENABLED //------------------------------------------------------------------------------------------------------------------------------ bool core_rpc_server::on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request& req, COMMAND_RPC_GETBLOCKCOUNT::response& res, connection_context& cntx) { diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h index 0e55204b..c0a089ae 100644 --- a/src/rpc/core_rpc_server.h +++ b/src/rpc/core_rpc_server.h @@ -45,9 +45,11 @@ namespace currency bool on_get_blocks(const COMMAND_RPC_GET_BLOCKS_FAST::request& req, COMMAND_RPC_GET_BLOCKS_FAST::response& res, connection_context& cntx); bool on_get_transactions(const COMMAND_RPC_GET_TRANSACTIONS::request& req, COMMAND_RPC_GET_TRANSACTIONS::response& res, connection_context& cntx); bool on_get_indexes(const COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request& req, COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response& res, connection_context& cntx); - bool on_send_raw_tx(const COMMAND_RPC_SEND_RAW_TX::request& req, COMMAND_RPC_SEND_RAW_TX::response& res, connection_context& cntx); + bool on_send_raw_tx(const COMMAND_RPC_SEND_RAW_TX::request& req, COMMAND_RPC_SEND_RAW_TX::response& res, connection_context& cntx); +#ifdef CPU_MINING_ENABLED bool on_start_mining(const COMMAND_RPC_START_MINING::request& req, COMMAND_RPC_START_MINING::response& res, connection_context& cntx); bool on_stop_mining(const COMMAND_RPC_STOP_MINING::request& req, COMMAND_RPC_STOP_MINING::response& res, connection_context& cntx); +#endif bool on_get_random_outs(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS_LEGACY::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS_LEGACY::response& res, connection_context& cntx); bool on_get_random_outs1(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& res, connection_context& cntx); bool on_get_random_outs3(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS3::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS3::response& res, connection_context& cntx); @@ -56,7 +58,7 @@ namespace currency bool on_get_tx_pool(const COMMAND_RPC_GET_TX_POOL::request& req, COMMAND_RPC_GET_TX_POOL::response& res, connection_context& cntx); bool on_check_keyimages(const COMMAND_RPC_CHECK_KEYIMAGES::request& req, COMMAND_RPC_CHECK_KEYIMAGES::response& res, connection_context& cntx); bool on_rpc_get_blocks_details(const COMMAND_RPC_GET_BLOCKS_DETAILS::request& req, COMMAND_RPC_GET_BLOCKS_DETAILS::response& res, connection_context& cntx); - bool on_force_relaey_raw_txs(const COMMAND_RPC_FORCE_RELAY_RAW_TXS::request& req, COMMAND_RPC_FORCE_RELAY_RAW_TXS::response& res, connection_context& cntx); + bool on_force_relaey_raw_txs(const COMMAND_RPC_FORCE_RELAY_RAW_TXS::request& req, COMMAND_RPC_FORCE_RELAY_RAW_TXS::response& res, connection_context& cntx); bool on_get_offers_ex(const COMMAND_RPC_GET_OFFERS_EX::request& req, COMMAND_RPC_GET_OFFERS_EX::response& res, epee::json_rpc::error& error_resp, connection_context& cntx); @@ -107,9 +109,11 @@ namespace currency MAP_URI_AUTO_JON2("/getheight", on_get_height, COMMAND_RPC_GET_HEIGHT) MAP_URI_AUTO_JON2("/gettransactions", on_get_transactions, COMMAND_RPC_GET_TRANSACTIONS) MAP_URI_AUTO_JON2("/sendrawtransaction", on_send_raw_tx, COMMAND_RPC_SEND_RAW_TX) - MAP_URI_AUTO_JON2("/force_relay", on_force_relaey_raw_txs, COMMAND_RPC_FORCE_RELAY_RAW_TXS) + MAP_URI_AUTO_JON2("/force_relay", on_force_relaey_raw_txs, COMMAND_RPC_FORCE_RELAY_RAW_TXS) +#ifdef CPU_MINING_ENABLED MAP_URI_AUTO_JON2("/start_mining", on_start_mining, COMMAND_RPC_START_MINING) MAP_URI_AUTO_JON2("/stop_mining", on_stop_mining, COMMAND_RPC_STOP_MINING) +#endif MAP_URI_AUTO_JON2("/getinfo", on_get_info, COMMAND_RPC_GET_INFO) // binary RPCs MAP_URI_AUTO_BIN2("/getblocks.bin", on_get_blocks, COMMAND_RPC_GET_BLOCKS_FAST) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 9a5d07e2..ef5d36fa 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -288,8 +288,10 @@ simple_wallet::simple_wallet() m_refresh_progress_reporter(*this), m_offline_mode(false) { +#ifdef CPU_MINING_ENABLED m_cmd_binder.set_handler("start_mining", boost::bind(&simple_wallet::start_mining, this, ph::_1), "start_mining - Start mining in daemon"); m_cmd_binder.set_handler("stop_mining", boost::bind(&simple_wallet::stop_mining, this, ph::_1), "Stop mining in daemon"); +#endif // #ifdef CPU_MINING_ENABLED m_cmd_binder.set_handler("refresh", boost::bind(&simple_wallet::refresh, this, ph::_1), "Resynchronize transactions and balance"); m_cmd_binder.set_handler("balance", boost::bind(&simple_wallet::show_balance, this, ph::_1), "[raw] Show current wallet balance, with 'raw' param it displays all assets without filtering against whitelists"); m_cmd_binder.set_handler("show_staking_history", boost::bind(&simple_wallet::show_staking_history, this, ph::_1), "show_staking_history [2] - Show staking transfers, if option provided - number of days for history to display"); @@ -761,6 +763,7 @@ bool simple_wallet::save(const std::vector &args) return true; } //---------------------------------------------------------------------------------------------------- +#ifdef CPU_MINING_ENABLED bool simple_wallet::start_mining(const std::vector& args) { if (!try_connect_to_daemon()) @@ -815,6 +818,7 @@ bool simple_wallet::stop_mining(const std::vector& args) fail_msg_writer() << "mining has NOT been stopped: " << err; return true; } +#endif // #ifdef CPU_MINING_ENABLED //---------------------------------------------------------------------------------------------------- void simple_wallet::on_new_block(uint64_t height, const currency::block& block) { @@ -3227,20 +3231,23 @@ int main(int argc, char* argv[]) po::options_description desc_all; desc_all.add(desc_general).add(desc_params); po::variables_map vm; + bool exit_requested = false; bool r = command_line::handle_error_helper(desc_all, [&]() { po::store(command_line::parse_command_line(argc, argv, desc_general, true), vm); if (command_line::get_arg(vm, command_line::arg_help)) { - success_msg_writer() << "Usage: simplewallet [--wallet-file=|--generate-new-wallet=] [--daemon-address=:] []"; + success_msg_writer() << "Usage: simplewallet [--wallet-file=|--generate-new[-auditable]-wallet=] [--daemon-address=:] []"; success_msg_writer() << desc_all << '\n' << sw->get_commands_str(); - return false; + exit_requested = true; + return true; } else if (command_line::get_arg(vm, command_line::arg_version)) { success_msg_writer() << CURRENCY_NAME << " wallet v" << PROJECT_VERSION_LONG; - return false; + exit_requested = true; + return true; } auto parser = po::command_line_parser(argc, argv).options(desc_params).positional(positional_options); @@ -3248,8 +3255,13 @@ int main(int argc, char* argv[]) po::notify(vm); return true; }); + if (!r) return EXIT_FAILURE; + + if (exit_requested) + return EXIT_SUCCESS; + //set up logging options log_space::get_set_log_detalisation_level(true, LOG_LEVEL_0); diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index d8bbb5d8..d660e75c 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -50,8 +50,10 @@ namespace currency bool close_wallet(); bool help(const std::vector &args = std::vector()); +#ifdef CPU_MINING_ENABLED bool start_mining(const std::vector &args); bool stop_mining(const std::vector &args); +#endif // #ifdef CPU_MINING_ENABLED bool refresh(const std::vector &args); bool show_balance(const std::vector &args = std::vector()); bool list_recent_transfers(const std::vector& args); diff --git a/src/version.h.in b/src/version.h.in index 9b2e4cac..5b55abd7 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -8,6 +8,6 @@ #define PROJECT_REVISION "1" #define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION -#define PROJECT_VERSION_BUILD_NO 372 +#define PROJECT_VERSION_BUILD_NO 378 #define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO) #define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]" diff --git a/src/wallet/core_default_rpc_proxy.cpp b/src/wallet/core_default_rpc_proxy.cpp index 38907e37..5e82efa4 100644 --- a/src/wallet/core_default_rpc_proxy.cpp +++ b/src/wallet/core_default_rpc_proxy.cpp @@ -167,6 +167,15 @@ namespace tools epee::net_utils::parse_url(m_daemon_address, u); if (!u.port) u.port = 8081; + if (u.schema == "https") + { + m_http_client.set_is_ssl(true); + } + else + { + m_http_client.set_is_ssl(false); + } + bool r = m_http_client.connect(u.host, std::to_string(u.port), m_connection_timeout); if (r) { diff --git a/src/wallet/core_default_rpc_proxy.h b/src/wallet/core_default_rpc_proxy.h index 7eb94397..b693fca6 100644 --- a/src/wallet/core_default_rpc_proxy.h +++ b/src/wallet/core_default_rpc_proxy.h @@ -134,7 +134,7 @@ namespace tools } epee::critical_section m_lock; - epee::net_utils::http::http_simple_client m_http_client; + epee::net_utils::http::http_universal_client m_http_client; std::string m_daemon_address; unsigned int m_connection_timeout; diff --git a/src/wallet/plain_wallet_api.h b/src/wallet/plain_wallet_api.h index f12eba03..84fe46ae 100644 --- a/src/wallet/plain_wallet_api.h +++ b/src/wallet/plain_wallet_api.h @@ -1,11 +1,10 @@ -// Copyright (c) 2014-2020 Zano Project +// Copyright (c) 2014-2025 Zano Project // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. - - #pragma once #include +#include #include "../common/error_codes.h" namespace plain_wallet diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 6dc46bc7..e6e13d35 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2116,6 +2116,12 @@ void wallet2::handle_pulled_blocks(size_t& blocks_added, std::atomic& stop } else { + //if first synchronized block in the wallet accidently became orphaned we need to force wallet to resync + if(this->m_minimum_height == height) + { + full_reset_needed = true; + } + //this should happen ONLY after block been matched, if not then is internal error if (full_reset_needed) { diff --git a/src/wallet/wallet_chain_shortener.cpp b/src/wallet/wallet_chain_shortener.cpp index 77c5d82c..39d37c75 100644 --- a/src/wallet/wallet_chain_shortener.cpp +++ b/src/wallet/wallet_chain_shortener.cpp @@ -217,7 +217,7 @@ void wallet_chain_shortener::check_if_block_matched(uint64_t i, const crypto::ha } return; } - if (!m_last_20_blocks.empty() && i > m_last_20_blocks.begin()->first) + if (!m_last_20_blocks.empty() && i >= m_last_20_blocks.begin()->first) { //must be in short sequence (m_last_20_blocks) //self check diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index b51f929f..caa6c9ef 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -201,7 +201,9 @@ bool wallets_manager::init_command_line(int argc, char* argv[], std::string& fai currency::core::init_options(desc_cmd_sett); currency::core_rpc_server::init_options(desc_cmd_sett); nodetool::node_server >::init_options(desc_cmd_sett); +#ifdef CPU_MINING_ENABLED currency::miner::init_options(desc_cmd_sett); +#endif bc_services::bc_offers_service::init_options(desc_cmd_sett); tools::db::db_backend_selector::init_options(desc_cmd_sett); #endif diff --git a/tests/core_tests/alias_tests.cpp b/tests/core_tests/alias_tests.cpp index 1e5b1de5..266e4164 100644 --- a/tests/core_tests/alias_tests.cpp +++ b/tests/core_tests/alias_tests.cpp @@ -381,7 +381,7 @@ bool gen_alias_tests::check_too_many_aliases_registration(currency::core& c, siz CHECK_AND_ASSERT_MES(c.get_pool_transactions_count() == total_alias_to_gen, false, "Unexpected number of txs in the pool: " << c.get_pool_transactions_count() << ", expected: " << total_alias_to_gen); // complete block template and try to process it - r = miner::find_nonce_for_given_block(b, diff, height); + r = find_nonce_for_given_block(b, diff, height); CHECK_AND_ASSERT_MES(r, false, "find_nonce_for_given_block failed"); currency::block_verification_context bvc = AUTO_VAL_INIT(bvc); @@ -1320,7 +1320,7 @@ bool gen_alias_switch_and_check_block_template::add_block_from_template(currency bool r = c.get_block_template(b, acc.get_public_address(), acc.get_public_address(), diff, height, extra); CHECK_AND_ASSERT_MES(r, false, "get_block_template failed"); - r = miner::find_nonce_for_given_block(b, diff, height); + r = find_nonce_for_given_block(b, diff, height); CHECK_AND_ASSERT_MES(r, false, "find_nonce_for_given_block failed"); currency::block_verification_context bvc = AUTO_VAL_INIT(bvc); @@ -1443,7 +1443,7 @@ bool gen_alias_too_many_regs_in_block_template::add_block_from_template(currency bool r = c.get_block_template(b, acc.get_public_address(), acc.get_public_address(), diff, height, extra); CHECK_AND_ASSERT_MES(r, false, "get_block_template failed"); - r = miner::find_nonce_for_given_block(b, diff, height); + r = find_nonce_for_given_block(b, diff, height); CHECK_AND_ASSERT_MES(r, false, "find_nonce_for_given_block failed"); currency::block_verification_context bvc = AUTO_VAL_INIT(bvc); diff --git a/tests/core_tests/block_validation.cpp b/tests/core_tests/block_validation.cpp index 26045224..ed290387 100644 --- a/tests/core_tests/block_validation.cpp +++ b/tests/core_tests/block_validation.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2023 Zano Project +// Copyright (c) 2014-2025 Zano Project // Copyright (c) 2014-2018 The Louisdor Project // Copyright (c) 2012-2013 The Cryptonote developers // Distributed under the MIT/X11 software license, see the accompanying @@ -694,7 +694,7 @@ bool gen_block_wrong_version_agains_hardfork::generate(std::vector& events) const @@ -705,26 +705,500 @@ bool block_with_correct_prev_id_on_wrong_height::generate(std::vector& events) const { - currency::block_verification_context context_blk_2{}; + block blk_2{}; - CHECK_AND_ASSERT_EQ(boost::get(m_blk_2.miner_tx.vin.front()).height, 10); - CHECK_AND_ASSERT_EQ(c.get_blockchain_storage().add_new_block(m_blk_2, context_blk_2), false); + { + const auto serialized_block{boost::get(events.at(ev_index)).callback_params}; + + CHECK_AND_ASSERT_EQ(t_unserializable_object_from_blob(blk_2, serialized_block), true); + } + + { + currency::block_verification_context context_blk_2{}; + + CHECK_AND_ASSERT_EQ(boost::get(blk_2.miner_tx.vin.front()).height, 10); + // Make sure, that it's impossible to insert blk_2. + CHECK_AND_ASSERT_EQ(c.get_blockchain_storage().add_new_block(blk_2, context_blk_2), false); + } + + return true; +} + +struct block_reward_in_main_chain_basic::argument_assert +{ + uint64_t m_height{}, m_balance{}; + std::list m_rewards{}; + + argument_assert() = default; + + template + argument_assert(const test* instance, uint64_t height, const std::list& blk_tx_fees = {}, const argument_assert previous = {}) : m_height{height} + { + CHECK_AND_ASSERT_THROW(instance, std::runtime_error{"Pointer to an instance of the test equals to the nullptr."}); + CHECK_AND_ASSERT_THROW(m_height >= previous.m_height, std::runtime_error{"A height specified in the previous argument is greather than current height."}); + + if (height == 0) + { + m_rewards.push_back(PREMINE_AMOUNT); + m_balance = m_rewards.back(); + } + + else + { + m_balance = previous.m_balance; + + for (auto fee_iterator{blk_tx_fees.rbegin()}; fee_iterator != blk_tx_fees.rend(); ++fee_iterator) + { + if (height != 0) + { + m_rewards.push_back(COIN); + + if (const auto& fee{*fee_iterator}; fee <= m_rewards.back()) + { + if (instance->m_hardforks.is_hardfork_active_for_height(ZANO_HARDFORK_04_ZARCANUM, height)) + { + m_rewards.back() -= fee; + } + } + + m_balance += m_rewards.back(); + } + + else + { + m_balance += PREMINE_AMOUNT; + } + + --height; + } + } + + CHECK_AND_ASSERT_THROW(m_rewards.size() > 0, std::runtime_error{"A list of the rewards is empty."}); + } + + BEGIN_SERIALIZE() + FIELD(m_height) + FIELD(m_balance) + FIELD(m_rewards) + END_SERIALIZE() +}; + +block_reward_in_main_chain_basic::block_reward_in_main_chain_basic() +{ + REGISTER_CALLBACK_METHOD(block_reward_in_main_chain_basic, assert_balance); + REGISTER_CALLBACK_METHOD(block_reward_in_main_chain_basic, assert_reward); +} + +bool block_reward_in_main_chain_basic::generate(std::vector& events) const +{ + // The test idea: make sure that receiving rewards for block insertion is counted correctly. + + const auto assert_balance{[&events](const argument_assert& argument) -> void + { + DO_CALLBACK_PARAMS_STR(events, "assert_balance", t_serializable_object_to_blob(argument)); + } + }; + + const auto assert_reward{[&events](const argument_assert& argument) -> void + { + DO_CALLBACK_PARAMS_STR(events, "assert_reward", t_serializable_object_to_blob(argument)); + } + }; + + GENERATE_ACCOUNT(miner); + MAKE_GENESIS_BLOCK(events, blk_0, miner, test_core_time::get_time()); + argument_assert argument{this, get_block_height(blk_0)}; + + m_accounts.push_back(miner); + assert_reward(argument); + // Make sure the balance equals to the PREMINE_AMOUNT. + assert_balance(argument); + DO_CALLBACK(events, "configure_core"); + + MAKE_NEXT_BLOCK(events, blk_1, blk_0, miner); + + argument = argument_assert{this, get_block_height(blk_1), {0}, argument}; + assert_balance(argument); + assert_reward(argument); + + REWIND_BLOCKS_N(events, blk_1r, blk_1, miner, CURRENCY_MINED_MONEY_UNLOCK_WINDOW - 1); + + argument = argument_assert{this, get_block_height(blk_1r), std::list(CURRENCY_MINED_MONEY_UNLOCK_WINDOW - 1), argument}; + assert_balance(argument); + assert_reward(argument); + + MAKE_TX_FEE(events, tx_0, miner, miner, MK_TEST_COINS(1), TESTS_DEFAULT_FEE, blk_1r); + MAKE_NEXT_BLOCK_TX1(events, blk_2, blk_1r, miner, tx_0); + + argument = {this, get_block_height(blk_2), {TESTS_DEFAULT_FEE}, argument}; + assert_reward(argument); + // Make sure in the balance change in the case of a transaction with the default fee. + assert_balance(argument); + + MAKE_TX_FEE(events, tx_1, miner, miner, MK_TEST_COINS(3), 2 * TESTS_DEFAULT_FEE, blk_2); + MAKE_TX_FEE(events, tx_2, miner, miner, MK_TEST_COINS(2), 3 * TESTS_DEFAULT_FEE, blk_2); + + const std::list txs{tx_1, tx_2}; + MAKE_NEXT_BLOCK_TX_LIST(events, blk_3, blk_2, miner, txs); + + argument = argument_assert{this, get_block_height(blk_3), {(2 + 3) * TESTS_DEFAULT_FEE}, argument}; + assert_reward(argument); + // A case of one inserted block with a several transactions with a non default fees. + assert_balance(argument); + + MAKE_TX_FEE(events, tx_3, miner, miner, MK_TEST_COINS(1), COIN + TESTS_DEFAULT_FEE, blk_3); + MAKE_NEXT_BLOCK(events, blk_4, blk_3, miner); + + argument = argument_assert{this, get_block_height(blk_4), {COIN + TESTS_DEFAULT_FEE}, argument}; + assert_reward(argument); + // A transaction inside blk_4 has a fee greater than a block reward. blk_4 includes only one transaction. + assert_balance(argument); + + MAKE_TX_FEE(events, tx_4, miner, miner, MK_TEST_COINS(1), 76 * COIN + 14 * TESTS_DEFAULT_FEE, blk_4); + MAKE_NEXT_BLOCK(events, blk_5, blk_4, miner); + + argument = argument_assert{this, get_block_height(blk_5), {76 * COIN + 14 * TESTS_DEFAULT_FEE}, argument}; + assert_reward(argument); + // A transaction inside blk_5 has a fee greater than a block reward. blk_5 includes only one transaction. + assert_balance(argument); + + REWIND_BLOCKS_N(events, blk_5r, blk_5, miner, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + + argument = argument_assert{this, get_block_height(blk_5r), std::list(CURRENCY_MINED_MONEY_UNLOCK_WINDOW), argument}; + assert_reward(argument); + assert_balance(argument); + + return true; +} + +bool block_reward_in_main_chain_basic::assert_balance(currency::core& core, size_t event_index, const std::vector& events) const +{ + argument_assert argument{}; + + { + const auto serialized_argument{boost::get(events.at(event_index)).callback_params}; + + CHECK_AND_ASSERT_EQ(t_unserializable_object_from_blob(argument, serialized_argument), true); + } + + CHECK_AND_ASSERT_EQ(core.get_blockchain_storage().get_top_block_height(), argument.m_height); + + const auto wallet{init_playtime_test_wallet(events, core, m_accounts.front())}; + + CHECK_AND_ASSERT(wallet, false); + wallet->refresh(); + CHECK_AND_ASSERT_EQ(wallet->balance(), argument.m_balance); + + return true; +} + +bool block_reward_in_main_chain_basic::assert_reward(currency::core& core, size_t event_index, const std::vector& events) const +{ + argument_assert argument{}; + + { + const auto serialized_argument{boost::get(events.at(event_index)).callback_params}; + + CHECK_AND_ASSERT_EQ(t_unserializable_object_from_blob(argument, serialized_argument), true); + } + + for (const auto expected_reward : argument.m_rewards) + { + uint64_t reward{}; + + CHECK_AND_ASSERT_EQ(core.get_blockchain_storage().get_block_reward_by_main_chain_height(argument.m_height, reward), true); + CHECK_AND_ASSERT_EQ(reward, expected_reward); + --argument.m_height; + } + + return true; +} + +struct block_reward_in_alt_chain_basic::argument_assert +{ + uint64_t m_height{}, m_balance{}; + crypto::hash blk_id{}; + std::list m_rewards{}; + + argument_assert() = default; + + template + argument_assert(const test* instance, const block& block, const std::list& blk_tx_fees = {}, const argument_assert previous = {}) : blk_id{get_block_hash(block)} + { + CHECK_AND_ASSERT_THROW(instance, std::runtime_error{"Pointer to an instance of the test equals to the nullptr."}); + + auto height{get_block_height(block)}; + + m_height = height; + + if (height == 0) + { + m_rewards.push_back(PREMINE_AMOUNT); + m_balance = m_rewards.back(); + return; + } + + m_balance = previous.m_balance; + + for (auto fee_iterator{blk_tx_fees.rbegin()}; fee_iterator != blk_tx_fees.rend(); ++fee_iterator) + { + if (height != 0) + { + m_rewards.push_back(COIN); + + if (const auto& fee{*fee_iterator}; fee <= m_rewards.back()) + { + if (instance->m_hardforks.is_hardfork_active_for_height(ZANO_HARDFORK_04_ZARCANUM, height)) + { + m_rewards.back() -= fee; + } + } + + m_balance += m_rewards.back(); + } + + else + { + m_balance += PREMINE_AMOUNT; + } + + --height; + } + + CHECK_AND_ASSERT_THROW(m_rewards.size() > 0, std::runtime_error{"A list of the rewards is empty."}); + } + + BEGIN_SERIALIZE() + FIELD(m_height) + FIELD(m_balance) + FIELD(m_rewards) + FIELD(blk_id) + END_SERIALIZE() +}; + +block_reward_in_alt_chain_basic::block_reward_in_alt_chain_basic() +{ + REGISTER_CALLBACK_METHOD(block_reward_in_alt_chain_basic, assert_balance); + REGISTER_CALLBACK_METHOD(block_reward_in_alt_chain_basic, assert_reward); +} + +bool block_reward_in_alt_chain_basic::generate(std::vector& events) const +{ + // The test idea: make sure that receiving rewards for block insertion is counted correctly. + + const auto assert_balance{[&events](const argument_assert& argument) -> void + { + DO_CALLBACK_PARAMS_STR(events, "assert_balance", t_serializable_object_to_blob(argument)); + } + }; + + const auto assert_reward{[&events](const argument_assert& argument) -> void + { + DO_CALLBACK_PARAMS_STR(events, "assert_reward", t_serializable_object_to_blob(argument)); + } + }; + + GENERATE_ACCOUNT(miner); + MAKE_GENESIS_BLOCK(events, blk_0, miner, test_core_time::get_time()); + argument_assert argument{this, blk_0}, argument_alt{}; + + /* 0 + (blk_0) */ + + m_accounts.push_back(miner); + // Make sure a reward for the blk_0 equals to PREMINE_AMOUNT. + assert_reward(argument); + // Make sure the balance equals to the PREMINE_AMOUNT. + assert_balance(argument); + DO_CALLBACK(events, "configure_core"); + + REWIND_BLOCKS_N(events, blk_0r, blk_0, miner, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + + /* 0 10 + (blk_0) - ... - (blk_0r) */ + + // A case of a 10 sequentally inserted empty sblocks. + argument_alt = argument = argument_assert{this, blk_0r, std::list(CURRENCY_MINED_MONEY_UNLOCK_WINDOW), argument}; + // Miner inserted 10 empty blocks. A sum of the rewards for them equals to 10 coins. + assert_reward(argument); + // Make sure the balance equals to PREMINE_AMOUNT + 10 * COIN. + assert_balance(argument); + + MAKE_TX_FEE(events, tx_0, miner, miner, MK_TEST_COINS(1), TESTS_DEFAULT_FEE, blk_0r); + MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner, tx_0); + + /* 0 10 11 + (blk_0) - ... - (blk_0r) - (blk_1) + {tx_0} */ + + MAKE_TX_FEE(events, tx_1, miner, miner, MK_TEST_COINS(1), 33 * TESTS_DEFAULT_FEE, blk_0r); + MAKE_NEXT_BLOCK_TX1(events, blk_1a, blk_0r, miner, tx_1); + + /* 0 10 11 + (blk_0) - ... - (blk_0r) - (blk_1a) + | {tx_1} + | + \ 11 + - (blk_1) + {tx_0} + + height(blk_1a) = height(blk_1) + fee(tx_1) > fee(tx_0). */ + + CHECK_AND_ASSERT_EQ(get_block_height(blk_1), get_block_height(blk_1a)); + + // Case of an alt block on the height 11 with greater total fee than total fee of blk_1 - the top of the main chain. + argument_alt = argument_assert{this, blk_1a, {33 * TESTS_DEFAULT_FEE}, argument_alt}; + argument = argument_assert{this, blk_1, {TESTS_DEFAULT_FEE}, argument}; + + if (m_hardforks.is_hardfork_active_for_height(ZANO_HARDFORK_04_ZARCANUM, get_block_height(blk_1))) + { + // Make sure that a reward for blk_1 equals to COIN. + assert_reward(argument_alt); + // Make sure that the balance equals to PREMINE_AMOUNT + 11 * COIN - 33 * TESTS_DEFAULT_FEE. + assert_balance(argument_alt); + } + + else + { + // Make sure that a reward for blk_1a equals to COIN. + assert_reward(argument); + // Make sure that the balance equals to PREMINE_AMOUNT + 11 * COIN. + assert_balance(argument); + } + + MAKE_TX_FEE(events, tx_2, miner, miner, MK_TEST_COINS(1), 8 * TESTS_DEFAULT_FEE, blk_1); + MAKE_TX_FEE(events, tx_3, miner, miner, MK_TEST_COINS(1), 57 * TESTS_DEFAULT_FEE, blk_1); + const std::list txs_0{tx_2, tx_3}; + + MAKE_NEXT_BLOCK_TX_LIST(events, blk_2, blk_1, miner, txs_0); + + /* 0 10 11 12 + (blk_0) - ... - (blk_0r) - (blk_1) - (blk_2) + | {tx_0} {tx_2, tx_3} + | + \ 11 + - (blk_1a) + {tx_1} + + height(blk_2) > height(blk_1a). */ + + // A case of block on the height 12 in the main chain. + argument = argument_assert{this, blk_2, {(8 + 57) * TESTS_DEFAULT_FEE}, argument}; + // A reward of blk_2 equals to coin. + assert_reward(argument); + /* HF3: The balance equals to PREMINE_AMOUNT + 12 * COIN. + HF4: The balance equals to PREMINE_AMOUNT + 12 * COIN - 65 * TESTS_DEFAULT_FEE. */ + assert_balance(argument); + + const auto& head_blk_for_txs_on_height_12{m_hardforks.is_hardfork_active_for_height(ZANO_HARDFORK_04_ZARCANUM, get_block_height(blk_2)) ? blk_1a : blk_0r}; + MAKE_TX_FEE(events, tx_4, miner, miner, MK_TEST_COINS(2), 15 * TESTS_DEFAULT_FEE, head_blk_for_txs_on_height_12); + MAKE_TX_FEE(events, tx_5, miner, miner, MK_TEST_COINS(5), 29 * TESTS_DEFAULT_FEE, head_blk_for_txs_on_height_12); + MAKE_TX_FEE(events, tx_6, miner, miner, MK_TEST_COINS(7), 22 * TESTS_DEFAULT_FEE, head_blk_for_txs_on_height_12); + const std::list txs_1{tx_4, tx_5, tx_6}; + MAKE_NEXT_BLOCK_TX_LIST(events, blk_2a, blk_1a, miner, txs_1); + + CHECK_AND_ASSERT_EQ(get_block_height(blk_2a), get_block_height(blk_2)); + + /* 0 10 11 12 + (blk_0) - ... - (blk_0r) - (blk_1a) - (blk_2a) + | {tx_1} {tx_4, tx_5, tx_6} + | + \ 11 12 + - (blk_1) - (blk_2) + {tx_0} {tx_2, tx_3} + + height(blk_2a) = height(blk_2) = 12 + fee(tx_2) + fee(tx_3) = (8 + 57) * TESTS_DEFAULT_FEE = 65 * TESTS_DEFAULT_FEE + fee(tx_4) + fee(tx_5) + fee(tx_6) = (15 + 29 + 22) * TESTS_DEFAULT_FEE = 66 * TESTS_DEFAULT_FEE + 66 > 65. */ + + if (m_hardforks.is_hardfork_active_for_height(ZANO_HARDFORK_04_ZARCANUM, get_block_height(blk_2))) + { + // Case of an alt block on the height 12 with greater total fee than total fee of blk_2 - the top of the main chain. + argument_alt = argument_assert{this, blk_2a, {(15 + 29 + 22) * TESTS_DEFAULT_FEE}, argument_alt}; + // Make sure a reward for blk_2a is equals to COIN. + assert_reward(argument_alt); + // Make sure the balance equals to PREMINE_AMOUNT + 12 * COIN - 99 * TESTS_DEFAULT_FEE. + assert_balance(argument_alt); + } + + else + { + // Make sure a reward for blk_2 is equals to COIN. + assert_reward(argument); + // Make sure the balance equals to PREMINE_AMOUNT + 12 * COIN. + assert_balance(argument); + } + + return true; +} + +bool block_reward_in_alt_chain_basic::assert_balance(currency::core& core, size_t event_index, const std::vector& events) const +{ + argument_assert argument{}; + + { + const auto serialized_argument{boost::get(events.at(event_index)).callback_params}; + + CHECK_AND_ASSERT_EQ(t_unserializable_object_from_blob(argument, serialized_argument), true); + } + + CHECK_AND_ASSERT_EQ(core.get_blockchain_storage().get_top_block_height(), argument.m_height); + CHECK_AND_ASSERT_EQ(core.get_blockchain_storage().get_top_block_id(), argument.blk_id); + + const auto wallet{init_playtime_test_wallet(events, core, m_accounts.front())}; + + CHECK_AND_ASSERT(wallet, false); + wallet->refresh(); + CHECK_AND_ASSERT_EQ(wallet->balance(), argument.m_balance); + + return true; +} + +bool block_reward_in_alt_chain_basic::assert_reward(currency::core& core, size_t event_index, const std::vector& events) const +{ + argument_assert argument{}; + + { + const auto serialized_argument{boost::get(events.at(event_index)).callback_params}; + + CHECK_AND_ASSERT_EQ(t_unserializable_object_from_blob(argument, serialized_argument), true); + } + + { + auto blk_id{argument.blk_id}; + + for (const auto expected_reward : argument.m_rewards) + { + uint64_t reward{}; + block blk{}; + + CHECK_AND_ASSERT_EQ(core.get_blockchain_storage().get_block_reward_by_hash(blk_id, reward), true); + CHECK_AND_ASSERT_EQ(reward, expected_reward); + CHECK_AND_ASSERT_EQ(core.get_blockchain_storage().get_block_by_hash(blk_id, blk), true); + blk_id = blk.prev_id; + } + } return true; } diff --git a/tests/core_tests/block_validation.h b/tests/core_tests/block_validation.h index 7c56f206..59e4c149 100644 --- a/tests/core_tests/block_validation.h +++ b/tests/core_tests/block_validation.h @@ -1,4 +1,4 @@ -// Copyright (c) 2014-2023 Zano Project +// Copyright (c) 2014-2025 Zano Project // Copyright (c) 2014-2018 The Louisdor Project // Copyright (c) 2012-2013 The Cryptonote developers // Distributed under the MIT/X11 software license, see the accompanying @@ -6,6 +6,7 @@ #pragma once #include "chaingen.h" +#include "wallet_tests_basic.h" template class gen_block_verification_base : public test_chain_unit_enchanced @@ -193,7 +194,26 @@ struct block_with_correct_prev_id_on_wrong_height : public gen_block_verificatio block_with_correct_prev_id_on_wrong_height(); bool generate(std::vector& events) const; bool assert_blk_2_has_wrong_height(currency::core& c, size_t ev_index, const std::vector& events) const; +}; + +struct block_reward_in_main_chain_basic : wallet_test +{ + block_reward_in_main_chain_basic(); + bool generate(std::vector& events) const; private: - mutable currency::block m_blk_2{}; + bool assert_balance(currency::core& core, size_t event_index, const std::vector& events) const; + bool assert_reward(currency::core& core, size_t event_index, const std::vector& events) const; + struct argument_assert; +}; + +struct block_reward_in_alt_chain_basic : wallet_test +{ + block_reward_in_alt_chain_basic(); + bool generate(std::vector& events) const; + +private: + bool assert_balance(currency::core& core, size_t event_index, const std::vector& events) const; + bool assert_reward(currency::core& core, size_t event_index, const std::vector& events) const; + struct argument_assert; }; diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index 4203f616..7fb1787a 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -839,7 +839,7 @@ bool test_generator::find_nounce(currency::block& blk, std::vector& event void fill_nonce(currency::block& blk, const wide_difficulty_type& diffic, uint64_t height) { blk.nonce = 0; - while (!miner::find_nonce_for_given_block(blk, diffic, height)) + while (!find_nonce_for_given_block(blk, diffic, height)) blk.timestamp++; }*/ diff --git a/tests/core_tests/chaingen_helpers.h b/tests/core_tests/chaingen_helpers.h index 1ae461b5..15d954a7 100644 --- a/tests/core_tests/chaingen_helpers.h +++ b/tests/core_tests/chaingen_helpers.h @@ -33,7 +33,7 @@ inline bool mine_next_pow_block_in_playtime(const currency::account_public_addre test_core_time::adjust(b.timestamp); modify_block_cb(b); - r = currency::miner::find_nonce_for_given_block(b, cbtr.diffic, cbtr.height); + r = currency::find_nonce_for_given_block(b, cbtr.diffic, cbtr.height); CHECK_AND_ASSERT_MES(r, false, "find_nonce_for_given_block failed"); currency::block_verification_context bvc{}; @@ -119,7 +119,7 @@ inline bool mine_next_pow_block_in_playtime_with_given_txs(const currency::accou height = cbtr.height; } - r = currency::miner::find_nonce_for_given_block(b, cbtr.diffic, cbtr.height); + r = currency::find_nonce_for_given_block(b, cbtr.diffic, cbtr.height); CHECK_AND_ASSERT_MES(r, false, "find_nonce_for_given_block failed"); currency::block_verification_context bvc{}; diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index 920b8e66..11856db7 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -1154,7 +1154,7 @@ int main(int argc, char* argv[]) GENERATE_AND_PLAY(one_block); GENERATE_AND_PLAY(gen_ring_signature_1); GENERATE_AND_PLAY(gen_ring_signature_2); - //GENERATE_AND_PLAY(fill_tx_rpc_inputs); temporary disable, waiting for fix from @stepan-dolgorukov + GENERATE_AND_PLAY(fill_tx_rpc_inputs); //GENERATE_AND_PLAY(gen_ring_signature_big); // Takes up to XXX hours (if CURRENCY_MINED_MONEY_UNLOCK_WINDOW == 10) // tests for outputs mixing in @@ -1179,6 +1179,8 @@ int main(int argc, char* argv[]) GENERATE_AND_PLAY_HF(gen_block_height_is_low, "0,3"); GENERATE_AND_PLAY_HF(gen_block_height_is_high, "0,3"); GENERATE_AND_PLAY_HF(block_with_correct_prev_id_on_wrong_height, "3-*"); + GENERATE_AND_PLAY_HF(block_reward_in_main_chain_basic, "3-*"); + GENERATE_AND_PLAY_HF(block_reward_in_alt_chain_basic, "3-*"); GENERATE_AND_PLAY_HF(gen_block_miner_tx_has_2_tx_gen_in, "0,3"); GENERATE_AND_PLAY_HF(gen_block_miner_tx_has_2_in, "0,3"); GENERATE_AND_PLAY_HF(gen_block_miner_tx_with_txin_to_key, "0,3"); diff --git a/tests/core_tests/daemon_rpc.cpp b/tests/core_tests/daemon_rpc.cpp index ca09027e..70d38898 100644 --- a/tests/core_tests/daemon_rpc.cpp +++ b/tests/core_tests/daemon_rpc.cpp @@ -1,6 +1,7 @@ -// Copyright (c) 2024 Zano Project +// Copyright (c) 2025 Zano Project // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #include "chaingen.h" #include "daemon_rpc.h" @@ -47,7 +48,7 @@ bool fill_tx_rpc_inputs::generate(std::vector& events) const tx.vin.push_back(std::move(input)); } - DO_CALLBACK_PARAMS_STR(events, "c6", t_serializable_object_to_blob(tx)); + DO_CALLBACK_PARAMS_STR(events, "c3", t_serializable_object_to_blob(tx)); } // A transaction with several "txin_to_key" inputs those have different .amount values. @@ -77,7 +78,7 @@ bool fill_tx_rpc_inputs::generate(std::vector& events) const tx.vin.push_back(std::move(input)); } - DO_CALLBACK_PARAMS_STR(events, "c3", t_serializable_object_to_blob(tx)); + DO_CALLBACK_PARAMS_STR(events, "c4", t_serializable_object_to_blob(tx)); } // A transaction with inputs of all possible types. @@ -98,7 +99,7 @@ bool fill_tx_rpc_inputs::generate(std::vector& events) const tx.vin.push_back(std::move(currency::txin_multisig{})); - DO_CALLBACK_PARAMS_STR(events, "c4", t_serializable_object_to_blob(tx)); + DO_CALLBACK_PARAMS_STR(events, "c5", t_serializable_object_to_blob(tx)); } REWIND_BLOCKS_N_WITH_TIME(events, blk_0r, blk_0, miner, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); @@ -162,7 +163,7 @@ bool fill_tx_rpc_inputs::generate(std::vector& events) const tx.vin.push_back(std::move(input)); } - DO_CALLBACK_PARAMS_STR(events, "c5", t_serializable_object_to_blob(tx)); + DO_CALLBACK_PARAMS_STR(events, "c6", t_serializable_object_to_blob(tx)); } /* A wrong reference by an object of the type "ref_by_id": a value of the attribute ".n" representing an offset is greater than a length of a container of outputs.The function "fill_tx_rpc_inputs" @@ -278,6 +279,44 @@ bool fill_tx_rpc_inputs::c3(const currency::core& core, const size_t event_posit CHECK_AND_ASSERT_EQ(info.pub_key.empty(), true); CHECK_AND_ASSERT_EQ(info.outs.empty(), true); + { + CHECK_AND_ASSERT_EQ(info.ins.size(), 1); + + { + CHECK_AND_ASSERT_EQ(info.ins.front().amount, 0); + CHECK_AND_ASSERT_EQ(info.ins.front().multisig_count, 0); + CHECK_AND_ASSERT_EQ(info.ins.front().htlc_origin.empty(), true); + CHECK_AND_ASSERT_EQ(info.ins.front().kimage_or_ms_id, epee::string_tools::pod_to_hex(currency::null_ki)); + CHECK_AND_ASSERT_EQ(info.ins.front().global_indexes.empty(), true); + CHECK_AND_ASSERT_EQ(info.ins.front().etc_options.empty(), true); + } + } + + CHECK_AND_ASSERT_EQ(info.id.empty(), true); + CHECK_AND_ASSERT_EQ(info.extra.empty(), true); + CHECK_AND_ASSERT_EQ(info.attachments.empty(), true); + CHECK_AND_ASSERT_EQ(info.object_in_json.empty(), true); + + return true; +} + +bool fill_tx_rpc_inputs::c4(const currency::core& core, const size_t event_position, const std::vector& events) const +{ + currency::transaction tx{}; + currency::tx_rpc_extended_info info{}; + + CHECK_AND_ASSERT_EQ(t_unserializable_object_from_blob(tx, boost::get(events.at(event_position)).callback_params), true); + CHECK_AND_ASSERT_EQ(core.get_blockchain_storage().fill_tx_rpc_inputs(info, tx), true); + CHECK_AND_ASSERT_EQ(info.blob.empty(), true); + CHECK_AND_ASSERT_EQ(info.blob_size, 0); + CHECK_AND_ASSERT_EQ(info.fee, 0); + CHECK_AND_ASSERT_EQ(info.amount, 0); + CHECK_AND_ASSERT_EQ(info.timestamp, 0); + CHECK_AND_ASSERT_EQ(info.keeper_block, 0); + CHECK_AND_ASSERT_EQ(info.id.empty(), true); + CHECK_AND_ASSERT_EQ(info.pub_key.empty(), true); + CHECK_AND_ASSERT_EQ(info.outs.empty(), true); + { CHECK_AND_ASSERT_EQ(info.ins.size(), 3); @@ -317,7 +356,7 @@ bool fill_tx_rpc_inputs::c3(const currency::core& core, const size_t event_posit return true; } -bool fill_tx_rpc_inputs::c4(const currency::core& core, const size_t event_position, const std::vector& events) const +bool fill_tx_rpc_inputs::c5(const currency::core& core, const size_t event_position, const std::vector& events) const { currency::transaction tx{}; currency::tx_rpc_extended_info info{}; @@ -366,7 +405,7 @@ bool fill_tx_rpc_inputs::c4(const currency::core& core, const size_t event_posit return true; } -bool fill_tx_rpc_inputs::c5(const currency::core& core, const size_t event_position, const std::vector& events) const +bool fill_tx_rpc_inputs::c6(const currency::core& core, const size_t event_position, const std::vector& events) const { currency::transaction tx{}; currency::tx_rpc_extended_info info{}; @@ -478,44 +517,6 @@ bool fill_tx_rpc_inputs::c5(const currency::core& core, const size_t event_posit return true; } -bool fill_tx_rpc_inputs::c6(const currency::core& core, const size_t event_position, const std::vector& events) const -{ - currency::transaction tx{}; - currency::tx_rpc_extended_info info{}; - - CHECK_AND_ASSERT_EQ(t_unserializable_object_from_blob(tx, boost::get(events.at(event_position)).callback_params), true); - CHECK_AND_ASSERT_EQ(core.get_blockchain_storage().fill_tx_rpc_inputs(info, tx), true); - CHECK_AND_ASSERT_EQ(info.blob.empty(), true); - CHECK_AND_ASSERT_EQ(info.blob_size, 0); - CHECK_AND_ASSERT_EQ(info.fee, 0); - CHECK_AND_ASSERT_EQ(info.amount, 0); - CHECK_AND_ASSERT_EQ(info.timestamp, 0); - CHECK_AND_ASSERT_EQ(info.keeper_block, 0); - CHECK_AND_ASSERT_EQ(info.id.empty(), true); - CHECK_AND_ASSERT_EQ(info.pub_key.empty(), true); - CHECK_AND_ASSERT_EQ(info.outs.empty(), true); - - { - CHECK_AND_ASSERT_EQ(info.ins.size(), 1); - - { - CHECK_AND_ASSERT_EQ(info.ins.front().amount, 0); - CHECK_AND_ASSERT_EQ(info.ins.front().multisig_count, 0); - CHECK_AND_ASSERT_EQ(info.ins.front().htlc_origin.empty(), true); - CHECK_AND_ASSERT_EQ(info.ins.front().kimage_or_ms_id, epee::string_tools::pod_to_hex(currency::null_ki)); - CHECK_AND_ASSERT_EQ(info.ins.front().global_indexes.empty(), true); - CHECK_AND_ASSERT_EQ(info.ins.front().etc_options.empty(), true); - } - } - - CHECK_AND_ASSERT_EQ(info.id.empty(), true); - CHECK_AND_ASSERT_EQ(info.extra.empty(), true); - CHECK_AND_ASSERT_EQ(info.attachments.empty(), true); - CHECK_AND_ASSERT_EQ(info.object_in_json.empty(), true); - - return true; -} - bool fill_tx_rpc_inputs::c7(const currency::core& core, const size_t event_position, const std::vector& events) const { currency::transaction tx{}; @@ -566,7 +567,10 @@ bool fill_tx_rpc_inputs::c8(const currency::core& core, const size_t event_posit CHECK_AND_ASSERT_EQ(reference.tx_id, currency::null_hash); CHECK_AND_ASSERT_EQ(reference.n, 0u); - CHECK_AND_ASSERT(core.get_blockchain_storage().get_tx_chain_entry(reference.tx_id), false); + + const auto pointer_entry{core.get_blockchain_storage().get_tx_chain_entry(reference.tx_id)}; + + CHECK_AND_ASSERT(pointer_entry == nullptr, false); } } diff --git a/tests/core_tests/daemon_rpc.h b/tests/core_tests/daemon_rpc.h index 3802b53f..72897ddd 100644 --- a/tests/core_tests/daemon_rpc.h +++ b/tests/core_tests/daemon_rpc.h @@ -1,6 +1,7 @@ // Copyright (c) 2024 Zano Project // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. + #pragma once #include diff --git a/tests/core_tests/emission_test.cpp b/tests/core_tests/emission_test.cpp index 3f2a1127..eb8ccb97 100644 --- a/tests/core_tests/emission_test.cpp +++ b/tests/core_tests/emission_test.cpp @@ -69,7 +69,7 @@ bool emission_test::c1(currency::core& c, size_t ev_index, const std::vector& events) const { // Test idea: make sure that the core rule prohibiting operations with assets in TX_FLAG_SIGNATURE_MODE_SEPARATE transactions works. - bool success {}; - transaction tx_2 {}; - uint64_t tx_version {}; - crypto::secret_key one_time {}; - tx_generation_context context_tx_2 {}; + bool success{}; + transaction tx_2{}; + uint64_t tx_version{}; + crypto::secret_key one_time{}; + tx_generation_context context_tx_2{}; + asset_descriptor_base adb_alice_currency{}; + asset_descriptor_operation ado_alice_currency{}; GENERATE_ACCOUNT(miner); GENERATE_ACCOUNT(alice); GENERATE_ACCOUNT(bob); @@ -1300,8 +1290,19 @@ bool asset_operation_in_consolidated_tx::generate(std::vector& m_accounts.push_back(miner); m_accounts.push_back(alice); m_accounts.push_back(bob); - m_adb_alice_currency.owner = m_accounts.at(ALICE_ACC_IDX).get_public_address().spend_public_key; - m_ado_alice_currency.opt_descriptor = m_adb_alice_currency; + + adb_alice_currency.version = ASSET_DESCRIPTOR_BASE_HF4_VER; + adb_alice_currency.total_max_supply = 1'000'000'000'000'000'000; + adb_alice_currency.current_supply = 1'000'000'000'000'000'000; + adb_alice_currency.ticker = "ALC"; + adb_alice_currency.full_name = "ALICE"; + adb_alice_currency.meta_info = "Currency created by Alice"; + adb_alice_currency.hidden_supply = false; + adb_alice_currency.owner = m_accounts.at(ALICE_ACC_IDX).get_public_address().spend_public_key; + ado_alice_currency.opt_descriptor = adb_alice_currency; + ado_alice_currency.operation_type = ASSET_DESCRIPTOR_OPERATION_REGISTER; + ado_alice_currency.opt_asset_id = currency::null_pkey; + ado_alice_currency.version = ASSET_DESCRIPTOR_OPERATION_HF4_VER; MAKE_GENESIS_BLOCK(events, blk_0, miner, test_core_time::get_time()); DO_CALLBACK(events, "configure_core"); @@ -1316,16 +1317,16 @@ bool asset_operation_in_consolidated_tx::generate(std::vector& DO_CALLBACK(events, "assert_balances"); { - std::vector sources {}; - std::vector destinations {}; + std::vector sources{}; + std::vector destinations{}; success = fill_tx_sources(sources, events, blk_2r, alice.get_keys(), MK_TEST_COINS(5), 1); CHECK_AND_ASSERT_MES(success, false, "failed to fill transaction sources on step 1"); destinations.emplace_back(MK_TEST_COINS(5), bob.get_public_address()); destinations.emplace_back(MK_TEST_COINS(/* 10 - 5 - 1 = */ 4), alice.get_public_address()); tx_version = get_tx_version(get_block_height(blk_2r), m_hardforks); - success = construct_tx(alice.get_keys(), sources, destinations, empty_extra, empty_attachment, tx_2, tx_version, one_time, 0, 0, 0, true, TX_FLAG_SIGNATURE_MODE_SEPARATE, TESTS_DEFAULT_FEE, - context_tx_2); + success = construct_tx(alice.get_keys(), sources, destinations, empty_extra, empty_attachment, tx_2, tx_version, one_time, 0, 0, 0, true, TX_FLAG_SIGNATURE_MODE_SEPARATE, TESTS_DEFAULT_FEE, + context_tx_2); CHECK_AND_ASSERT_MES(success, false, "failed to construct transaction tx_2 on step 1"); } @@ -1334,26 +1335,26 @@ bool asset_operation_in_consolidated_tx::generate(std::vector& ADD_CUSTOM_EVENT(events, tx_2); { - std::vector sources {}; - std::vector destinations {}; + std::vector sources{}; + std::vector destinations{}; success = fill_tx_sources(sources, events, blk_2r, bob.get_keys(), MK_TEST_COINS(5), 0); CHECK_AND_ASSERT_MES(success, false, "failed to fill transaction sources on step 2"); - for(tx_source_entry& source : sources) + + for (tx_source_entry& source : sources) { source.separately_signed_tx_complete = true; } + destinations.emplace_back(MK_TEST_COINS(5), alice.get_public_address()); destinations.emplace_back(MK_TEST_COINS(/* 10 - 5 - 0 = */ 5), bob.get_public_address()); - destinations.emplace_back(m_adb_alice_currency.current_supply, alice.get_public_address(), null_pkey); + destinations.emplace_back(adb_alice_currency.current_supply, alice.get_public_address(), null_pkey); tx_version = get_tx_version(get_block_height(blk_2r), m_hardforks); size_t hf_n = m_hardforks.get_the_most_recent_hardfork_id_for_height(get_block_height(blk_2r)); - fill_ado_version_based_onhardfork(m_ado_alice_currency, hf_n); - fill_adb_version_based_onhardfork(*m_ado_alice_currency.opt_descriptor, hf_n); - - - success = construct_tx(bob.get_keys(), sources, destinations, { m_ado_alice_currency }, empty_attachment, tx_2, tx_version, one_time, 0, 0, 0, true, TX_FLAG_SIGNATURE_MODE_SEPARATE, - /* fee = */ 0, context_tx_2); + fill_ado_version_based_onhardfork(ado_alice_currency, hf_n); + fill_adb_version_based_onhardfork(*ado_alice_currency.opt_descriptor, hf_n); + success = construct_tx(bob.get_keys(), sources, destinations, {ado_alice_currency}, empty_attachment, tx_2, tx_version, one_time, 0, 0, 0, true, TX_FLAG_SIGNATURE_MODE_SEPARATE, + /* fee = */ 0, context_tx_2); CHECK_AND_ASSERT_MES(success, false, "failed to construct transaction tx_2 on step 2"); } @@ -1362,15 +1363,15 @@ bool asset_operation_in_consolidated_tx::generate(std::vector& // Core rejects transaction tx_2. The balances of Alice, Bob haven't changed: Alice has 10 coins, Bob has 10 coins. DO_CALLBACK(events, "assert_balances"); // Alice's asset hasn't registered, because transaction tx_2 was rejected. - DO_CALLBACK(events, "assert_alice_currency_not_registered"); + DO_CALLBACK_PARAMS_STR(events, "assert_alice_currency_not_registered", t_serializable_object_to_blob(ado_alice_currency)); return true; } -bool asset_operation_in_consolidated_tx::assert_balances(currency::core& c, size_t ev_index, const std::vector& events) +bool asset_operation_in_consolidated_tx::assert_balances(currency::core& c, size_t ev_index, const std::vector& events) const { - std::shared_ptr alice_wallet{init_playtime_test_wallet(events, c, ALICE_ACC_IDX)}; - std::shared_ptr bob_wallet{init_playtime_test_wallet(events, c, BOB_ACC_IDX)}; + const auto alice_wallet{init_playtime_test_wallet_t(events, c, ALICE_ACC_IDX)}; + const auto bob_wallet{init_playtime_test_wallet_t(events, c, BOB_ACC_IDX)}; alice_wallet->refresh(); bob_wallet->refresh(); @@ -1381,14 +1382,28 @@ bool asset_operation_in_consolidated_tx::assert_balances(currency::core& c, size return true; } -bool asset_operation_in_consolidated_tx::assert_alice_currency_not_registered(currency::core& c, size_t ev_index, const std::vector& events) +bool asset_operation_in_consolidated_tx::assert_alice_currency_not_registered(const currency::core& c, size_t ev_index, const std::vector& events) const { - crypto::point_t asset_id_point{}; crypto::public_key asset_id{}; - currency::asset_descriptor_base stub{}; + asset_descriptor_operation ado{}; - CHECK_AND_ASSERT_MES(get_or_calculate_asset_id(m_ado_alice_currency, &asset_id_point, &asset_id), false, "fail to calculate asset id"); - CHECK_AND_ASSERT_MES(!c.get_blockchain_storage().get_asset_info(asset_id, stub), false, "unregistered asset has info"); + { + const auto serialized_ado{boost::get(events.at(ev_index)).callback_params}; + + CHECK_AND_ASSERT_MES(t_unserializable_object_from_blob(ado, serialized_ado), false, "ADO deserialization failed"); + } + + { + crypto::point_t point_asset_id{}; + + CHECK_AND_ASSERT_MES(get_or_calculate_asset_id(ado, &point_asset_id, &asset_id), false, "fail to calculate asset id"); + } + + { + currency::asset_descriptor_base adb_stub{}; + + CHECK_AND_ASSERT_MES(!c.get_blockchain_storage().get_asset_info(asset_id, adb_stub), false, "unregistered asset has info"); + } return true; } diff --git a/tests/core_tests/multiassets_test.h b/tests/core_tests/multiassets_test.h index d306a0f4..5b367533 100644 --- a/tests/core_tests/multiassets_test.h +++ b/tests/core_tests/multiassets_test.h @@ -74,12 +74,8 @@ struct asset_operation_in_consolidated_tx : public wallet_test public: asset_operation_in_consolidated_tx(); bool generate(std::vector& events) const; - bool assert_balances(currency::core& c, size_t ev_index, const std::vector& events); - bool assert_alice_currency_not_registered(currency::core& c, size_t ev_index, const std::vector& events); - -private: - mutable currency::asset_descriptor_base m_adb_alice_currency{}; - mutable currency::asset_descriptor_operation m_ado_alice_currency{}; + bool assert_balances(currency::core& c, size_t ev_index, const std::vector& events) const; + bool assert_alice_currency_not_registered(const currency::core& c, size_t ev_index, const std::vector& events) const; }; struct eth_signed_asset_basics : public wallet_test diff --git a/tests/data/account-002bee2f8e16f5de4db0d3b8ce9227c8c0b7f9688348b028e022cb43f210968b40a69cdc8531fd4a2e7c9e144eec48bb477733d70ce5f9b85338a07cb10b849ad8fb b/tests/data/account-002bee2f8e16f5de4db0d3b8ce9227c8c0b7f9688348b028e022cb43f210968b40a69cdc8531fd4a2e7c9e144eec48bb477733d70ce5f9b85338a07cb10b849ad8fb deleted file mode 100644 index 11927ecc..00000000 Binary files a/tests/data/account-002bee2f8e16f5de4db0d3b8ce9227c8c0b7f9688348b028e022cb43f210968b40a69cdc8531fd4a2e7c9e144eec48bb477733d70ce5f9b85338a07cb10b849ad8fb and /dev/null differ diff --git a/tests/data/account-007af2d7c5ffd8f69005debae820207820805e28c7d7a16714591143f56fb51e2b91ad0c1a535567e6292b321773df5e5aaace00fe767c4f09de452838575357ca9f b/tests/data/account-007af2d7c5ffd8f69005debae820207820805e28c7d7a16714591143f56fb51e2b91ad0c1a535567e6292b321773df5e5aaace00fe767c4f09de452838575357ca9f deleted file mode 100644 index 12f4a0f1..00000000 Binary files a/tests/data/account-007af2d7c5ffd8f69005debae820207820805e28c7d7a16714591143f56fb51e2b91ad0c1a535567e6292b321773df5e5aaace00fe767c4f09de452838575357ca9f and /dev/null differ diff --git a/tests/data/account-009b82d66dfaaba55a581913fa09d6c5bebe179cd73731781265c96e9e630dcd27fd5d20e7f1d0fa42619de9ca8fe4c0659f6959b2bebb15079cdaed07a442a78486 b/tests/data/account-009b82d66dfaaba55a581913fa09d6c5bebe179cd73731781265c96e9e630dcd27fd5d20e7f1d0fa42619de9ca8fe4c0659f6959b2bebb15079cdaed07a442a78486 deleted file mode 100644 index bee40fa5..00000000 Binary files a/tests/data/account-009b82d66dfaaba55a581913fa09d6c5bebe179cd73731781265c96e9e630dcd27fd5d20e7f1d0fa42619de9ca8fe4c0659f6959b2bebb15079cdaed07a442a78486 and /dev/null differ diff --git a/tests/data/account-00aff84db50d6a54dd56051379f6c336fdd330d1cb11e7523bbf71f30b1ae760fa47ace8679b6486f79429980fd2331715a631f5729db284eb1fc6f108aeb7a7f4fe b/tests/data/account-00aff84db50d6a54dd56051379f6c336fdd330d1cb11e7523bbf71f30b1ae760fa47ace8679b6486f79429980fd2331715a631f5729db284eb1fc6f108aeb7a7f4fe deleted file mode 100644 index 54122832..00000000 Binary files a/tests/data/account-00aff84db50d6a54dd56051379f6c336fdd330d1cb11e7523bbf71f30b1ae760fa47ace8679b6486f79429980fd2331715a631f5729db284eb1fc6f108aeb7a7f4fe and /dev/null differ diff --git a/tests/functional_tests/core_concurrency_test.cpp b/tests/functional_tests/core_concurrency_test.cpp index 1d791dcc..1a421168 100644 --- a/tests/functional_tests/core_concurrency_test.cpp +++ b/tests/functional_tests/core_concurrency_test.cpp @@ -156,7 +156,7 @@ bool generate_events(currency::core& c, cct_events_t& events, const cct_wallets_ test_core_time::adjust(b.timestamp); currency::wide_difficulty_type diff = 0; - r = currency::miner::find_nonce_for_given_block(b, diff, height); + r = currency::find_nonce_for_given_block(b, diff, height); CHECK_AND_ASSERT_MES(r, false, "find_nonce_for_given_block failed"); currency::block_verification_context bvc = AUTO_VAL_INIT(bvc); diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp index 9b285b68..c03eb834 100644 --- a/tests/performance_tests/main.cpp +++ b/tests/performance_tests/main.cpp @@ -56,6 +56,8 @@ void test_plain_wallet() epee::misc_utils::sleep_no_w(2000); res = plain_wallet::sync_call("reset_connection_url", 0, "195.201.107.230:33336"); + //res = plain_wallet::sync_call("reset_connection_url", 0, "https://node.zano.org:443"); + r = plain_wallet::sync_call("run_wallet", instance_id, ""); while(true) diff --git a/tests/unit_tests/get_xtype_from_string.cpp b/tests/unit_tests/get_xtype_from_string.cpp index 5bcb74df..0a520c16 100644 --- a/tests/unit_tests/get_xtype_from_string.cpp +++ b/tests/unit_tests/get_xtype_from_string.cpp @@ -151,10 +151,10 @@ TEST_neg(int16_t, "+32768"); // 2^15 TEST_neg(int16_t, "-32769"); // -2^15 - 1 TEST_neg(int16_t, ""); -TEST_pos(int32_t, 2'147'483'647, "2147483647"); // 2^31 - 1 -TEST_pos(int32_t, -2'147'483'648, "-2147483648"); // -2^31 -TEST_pos(int32_t, 0, "-0"); -TEST_pos(int32_t, 0, "+0"); +TEST_pos(int32_t, 2'147'483'647, "2147483647"); // 2^31 - 1 +TEST_pos(int32_t, -2'147'483'647 - 1, "-2147483648"); // -2^31 +TEST_pos(int32_t, 0, "-0"); +TEST_pos(int32_t, 0, "+0"); TEST_neg(int32_t, "-2147483649"); TEST_neg(int32_t, "2147483648"); diff --git a/tests/unit_tests/multiassets_test.cpp b/tests/unit_tests/multiassets_test.cpp index ad637b01..533d8826 100644 --- a/tests/unit_tests/multiassets_test.cpp +++ b/tests/unit_tests/multiassets_test.cpp @@ -245,7 +245,7 @@ static std::optional deserialize(serialization_metho return {}; } -static std::string get_string_presentation(const std::string& data) +[[maybe_unused]] static std::string get_string_presentation(const std::string& data) { std::string presentation{}; diff --git a/utils/docker/remote-node-mobile/Dockerfile b/utils/docker/remote-node-mobile/Dockerfile new file mode 100644 index 00000000..0d08e778 --- /dev/null +++ b/utils/docker/remote-node-mobile/Dockerfile @@ -0,0 +1,160 @@ +########################################################################################### +## zanod Dockerfile +########################################################################################### + +# +# Usage: +# (make sure you have correct permission for /var/data/zano-data prior to run!) +# +# docker run --restart=always -v /var/data/zano-data:/home/zano/.Zano -p 11121:11121 -p 11211:11211 --name=zanod -dit zanoproject/remote-note +# +# To get into container and interact with the daemon: +# docker attach zanod +# +# To detach from container and left it running: +# Ctrl+P, Ctrl+Q +# +# To stop container: +# docker stop zanod +# +# To build with different lib versions, pass through --build-arg's +# docker build --build-arg OPENSSL_VERSION_DOT=1.1.1n --build-arg OPENSSL_HASH=40dceb51a4f6a5275bde0e6bf20ef4b91bfc32ed57c0552e2e8e15463372b17a -f utils/docker/Dockerfile . +# +# Available Build Args +# - CMake Version: CMAKE_VERSION_DOT, CMAKE_HASH +# - Boost Version: BOOST_VERSION, BOOST_VERSION_DOT, BOOST_HASH +# - OpenSSL Version: OPENSSL_VERSION_DOT, OPENSSL_HASH + +# +# Build Zano +# + +FROM ubuntu:18.04 as build-prep + +ENV DEBIAN_FRONTEND noninteractive + +RUN apt update && \ + apt install -y build-essential \ + libicu-dev \ + libz-dev \ + curl \ + gcc-8 \ + g++-8 \ + git + +RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 700 --slave /usr/bin/g++ g++ /usr/bin/g++-7 && \ + update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 800 --slave /usr/bin/g++ g++ /usr/bin/g++-8 + +WORKDIR /root + +# Lib Settings +ARG CMAKE_VERSION_DOT=3.16.9 +ARG CMAKE_HASH=d71eda07d6ecf3964de65a0e36d0b171565e1aced56ba9f53ca3783406b5cacf + +ARG BOOST_VERSION=1_84_0 +ARG BOOST_VERSION_DOT=1.84.0 +ARG BOOST_HASH=cc4b893acf645c9d4b698e9a0f08ca8846aa5d6c68275c14c3e7949c24109454 + +ARG OPENSSL_VERSION_DOT=1.1.1w +ARG OPENSSL_HASH=cf3098950cb4d853ad95c0841f1f9c6d3dc102dccfcacd521d93925208b76ac8 + +# Environment Variables +ENV BOOST_ROOT /root/boost_${BOOST_VERSION} +ENV OPENSSL_ROOT_DIR=/root/openssl + +########################################################## +# Split download & compile to use dockers caching layers # +########################################################## + +# Download CMake +RUN set -ex \ + && curl https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION_DOT}/cmake-${CMAKE_VERSION_DOT}-Linux-x86_64.sh -OL\ + && echo "${CMAKE_HASH} cmake-${CMAKE_VERSION_DOT}-Linux-x86_64.sh" | sha256sum -c + +# Download Boost +RUN set -ex \ + && curl -L -o boost_${BOOST_VERSION}.tar.bz2 https://downloads.sourceforge.net/project/boost/boost/${BOOST_VERSION_DOT}/boost_${BOOST_VERSION}.tar.bz2 \ + && sha256sum boost_${BOOST_VERSION}.tar.bz2 \ + && echo "${BOOST_HASH} boost_${BOOST_VERSION}.tar.bz2" | sha256sum -c\ + && tar -xvf boost_${BOOST_VERSION}.tar.bz2 + + +# Download OpenSSL +RUN curl https://www.openssl.org/source/openssl-${OPENSSL_VERSION_DOT}.tar.gz -OL \ + && sha256sum openssl-${OPENSSL_VERSION_DOT}.tar.gz \ + && echo "${OPENSSL_HASH} openssl-${OPENSSL_VERSION_DOT}.tar.gz" | sha256sum -c + + +# Compile CMake +RUN set -ex \ + && mkdir /opt/cmake \ + && sh cmake-3.16.9-Linux-x86_64.sh --prefix=/opt/cmake --skip-license\ + && ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake\ + && cmake --version\ + && rm cmake-3.16.9-Linux-x86_64.sh + +# Compile Boost +RUN set -ex \ + && cd boost_${BOOST_VERSION} \ + && ./bootstrap.sh --with-libraries=system,filesystem,thread,date_time,chrono,regex,serialization,atomic,program_options,locale,timer,log \ + && ./b2 + +# Compile OpenSSL +RUN set -ex \ + && tar xaf openssl-${OPENSSL_VERSION_DOT}.tar.gz \ + && rm openssl-${OPENSSL_VERSION_DOT}.tar.gz \ + && cd openssl-${OPENSSL_VERSION_DOT} \ + && ./config --prefix=/root/openssl --openssldir=/root/openssl shared zlib \ + && make \ + && make test \ + && make install \ + && cd .. \ + && rm -rf openssl-${OPENSSL_VERSION_DOT} + +FROM build-prep as build + +# Zano + +RUN pwd && mem_avail_gb=$(( $(getconf _AVPHYS_PAGES) * $(getconf PAGE_SIZE) / (1024 * 1024 * 1024) )) &&\ + make_job_slots=$(( $mem_avail_gb < 4 ? 1 : $mem_avail_gb / 4)) &&\ + echo make_job_slots=$make_job_slots &&\ + set -x &&\ + git clone --single-branch --recursive https://github.com/hyle-team/zano.git &&\ + cd zano &&\ + mkdir build && cd build &&\ + cmake -D STATIC=TRUE .. &&\ + make -j $make_job_slots daemon simplewallet + + +# +# Run Zano +# + +FROM ubuntu:18.04 + +# Install dependencies and Nginx +RUN apt update && apt install -y \ + nginx \ + curl \ + && apt clean + +RUN useradd -ms /bin/bash zano &&\ + mkdir -p /home/zano/.Zano &&\ + chown -R zano:zano /home/zano/.Zano + +USER zano:zano + +WORKDIR /home/zano +COPY --chown=zano:zano --from=build /root/zano/build/src/zanod . +COPY --chown=zano:zano --from=build /root/zano/build/src/simplewallet . + +# Copy Nginx configuration +USER root +COPY nginx.conf /etc/nginx/nginx.conf + +# blockchain loaction +VOLUME /home/zano/.Zano + +EXPOSE 11121 11211 33340 + +CMD service nginx start && ./zanod --disable-upnp --log-level=0 diff --git a/utils/docker/remote-node-mobile/nginx.conf b/utils/docker/remote-node-mobile/nginx.conf new file mode 100644 index 00000000..245e8ed9 --- /dev/null +++ b/utils/docker/remote-node-mobile/nginx.conf @@ -0,0 +1,73 @@ +events {} + +http { + + ## + # Basic Settings + ## + + limit_conn_zone $binary_remote_addr zone=addr:10m; + limit_req_zone $binary_remote_addr zone=global_limit:10m rate=10r/s; + sendfile on; + tcp_nopush on; + tcp_nodelay on; + keepalive_timeout 65; + types_hash_max_size 2048; + # server_tokens off; + + # server_names_hash_bucket_size 64; + # server_name_in_redirect off; + + include /etc/nginx/mime.types; + default_type application/octet-stream; + + ## + # SSL Settings + ## + + ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE + ssl_prefer_server_ciphers on; + + ## + # Logging Settings + ## + + access_log /var/log/nginx/access.log; + error_log /var/log/nginx/error.log; + + ## + # Gzip Settings + ## + + gzip on; + + include /etc/nginx/conf.d/*.conf; + include /etc/nginx/sites-enabled/*; + + + #mainnet + server { + listen 33340; + listen [::]:33340; + + # Apply globally to all locations + limit_req zone=global_limit burst=20 nodelay; + limit_conn addr 30; + + access_log /var/log/nginx/reverse-access.log; + error_log /var/log/nginx/reverse-error.log; + + + location /general_info + { + root /home/mobile_app_config; + add_header Cache-Control no-cache; + # set the Expires header to 31 December 2037 23:59:59 GMT, and the Cache-Control max-age to 10 years + expires 1s; + } + + location ~ ^/(json_rpc|getheight|gettransactions|sendrawtransaction|force_relay|getinfo|getblocks\.bin|get_o_indexes\.bin|get_o_indexes\.bin|getrandom_outs\.bin|getrandom_outs1\.bin|getrandom_outs2\.bin|getrandom_outs3\.bin|set_maintainers_info\.bin|get_tx_pool\.bin|check_keyimages\.bin|get_pos_details\.bin) { + proxy_pass http://127.0.0.1:11211$uri; + } + } +}