diff --git a/README.md b/README.md index e5319eb2..4ce1db38 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ +[![Coverity Scan](https://scan.coverity.com/projects/18767/badge.svg)](https://scan.coverity.com/projects/zanoproject) [![Discord](https://img.shields.io/discord/538361472691077130?label=discord&logo=discord)](https://discord.gg/wE3rmYY) -[![Coverity Scan](https://scan.coverity.com/projects/18767/badge.svg)](https://scan.coverity.com/projects/zanoproject) - -Building +Building Zano -------- ### Cloning @@ -17,39 +16,67 @@ Be sure to properly clone the repository: | llvm/clang (Linux) | UNKNOWN | 7.0.1 | 8.0.0 | | [MSVC](https://visualstudio.microsoft.com/downloads/) (Windows) | 2015 (14.0 update 1) | 2015 (14.0 update 3) | 2017 (15.5.7) | | [XCode](https://developer.apple.com/downloads/) (macOS) | 7.3.1 | 9.2 | 9.2 | -| [CMake](https://cmake.org/download/) | 2.8.6 | 3.4.1 | 3.11.0 | -| [Boost](https://www.boost.org/users/download/) | 1.56 | 1.60 | 1.66 | -| [Qt](https://download.qt.io/archive/qt/) (only for GUI) | 5.8.0 | 5.9.1 | 5.10.1 | +| [CMake](https://cmake.org/download/) | 2.8.6 | 3.15.5 | 3.15.5 | +| [Boost](https://www.boost.org/users/download/) | 1.56 | 1.68 | 1.68 | +| [Qt](https://download.qt.io/archive/qt/) (only for GUI) | 5.8.0 | 5.11.2 | 5.13.2 | ### Linux -Recommended OS version: Ubuntu 17.04 LTS. +Recommended OS version: Ubuntu 18.04 LTS. -1. For server version: \ -`$ sudo apt-get install -y build-essential g++ python-dev autotools-dev libicu-dev libbz2-dev cmake git libboost-all-dev screen`\ -For GUI version:\ -`$ sudo apt-get install -y build-essential g++ python-dev autotools-dev libicu-dev libbz2-dev cmake git libboost-all-dev screen mesa-common-dev libglu1-mesa-dev qt5-default qtwebengine5-dev` +1. Prerequisites + 1. Prerequisites for server version: + + sudo apt-get install -y build-essential g++ python-dev autotools-dev libicu-dev libbz2-dev cmake git screen + + 1. Prerequisites for GUI version: -2. Building binaries \ - 2.1. Building daemon and simplewallet: \ -   `$ cd zano/ && make -j` \ -   or \ -   `$ cd zano && mkdir build && cd build `\ -   `$ cmake .. `\ -   `$ make -j daemon simplewallet` \ - 2.2. Building GUI: \ -   `$ cd zano/ && make -j gui ` \ -   or \ -   `$ cd zano && mkdir build && cd build `\ -   `$ cmake -D BUILD_GUI=ON .. `\ -   `$ make -j Zano` \ -   `$ rsync -haP ~/zano/src/gui/qt-daemon/html ~/zano/build/src` \ -NOTICE: If you are building on machine with relatively small anount of RAM(small VPS for example, less then 16GB) and without proper setting of virtual memory, then be careful with setting `-j` option, this may cause compiller crashes. -3. Look for the binaries, including the `Zano` GUI, in the build directory + sudo apt-get install -y build-essential g++ python-dev autotools-dev libicu-dev libbz2-dev cmake git screen mesa-common-dev libglu1-mesa-dev` + +2. Download and build Boost + + wget https://dl.bintray.com/boostorg/release/1.68.0/source/boost_1_68_0.tar.bz2 + tar -xjf boost_1_68_0.tar.bz2 + cd boost_1_68_0 + ./bootstrap.sh --with-libraries=system,filesystem,thread,date_time,chrono,regex,serialization,atomic,program_options,locale,timer + ./b2 + +3. Install Qt + + wget https://download.qt.io/archive/qt/5.11/5.11.2/qt-opensource-linux-x64-5.11.2.run + chmod +x qt-opensource-linux-x64-5.11.2.run + ./qt-opensource-linux-x64-5.11.2.run + Then follow the instructions in Wizard. Don't forget to tick WebEngine module! + +4. Set `BOOST_ROOT` and `QT_PREFIX_PATH` envinorment variables\ + For instance, by adding these lines to `~/.bashrc`: + + export BOOST_ROOT=/home/user/boost_1_68_0 + export QT_PREFIX_PATH=/home/user/Qt5.11.2/5.11.2/gcc_64 + + +5. Building binaries + 1. Building daemon and simplewallet: + + cd zano/ && make -j1 + or + + cd zano && mkdir build && cd build + cmake .. + make -j1 daemon simplewallet + + **NOTICE**: If you are building on machine with relatively high anount of RAM or with proper setting of virtual memory, then you can use `-j2` or `-j` option to speed up the building process. Use with caution. + + 1. Building GUI: + + cd zano + utils/build_sript_linux.sh + +7. Look for the binaries in `build` folder ### Windows Recommended OS version: Windows 7 x64. -1. Install required prerequisites. +1. Install required prerequisites (Boost, Qt, CMake). 2. Edit paths in `utils/configure_local_paths.cmd`. 3. Run `utils/configure_win64_msvs2015_gui.cmd` or `utils/configure_win64_msvs2017_gui.cmd` according to your MSVC version. 4. Go to the build folder and open generated Zano.sln in MSVC. @@ -79,3 +106,4 @@ To build GUI application: h. Unfold the certificate in Keychain Access window and double click underlying private key "Zano". Select "Access Control" tab, then select "Allow all applications to access this item". Click "Save Changes". 2. Revise building script, comment out unwanted steps and run it: `utils/build_script_mac_osx.sh` 3. The application should be here: `/buid_mac_osx_64/release/src` + diff --git a/contrib/epee/include/storages/portable_storage_to_json.h b/contrib/epee/include/storages/portable_storage_to_json.h index 9cfd9c0a..1e2d5d97 100644 --- a/contrib/epee/include/storages/portable_storage_to_json.h +++ b/contrib/epee/include/storages/portable_storage_to_json.h @@ -157,6 +157,7 @@ namespace epee template void dump_as_json(t_stream& strm, const double& v, size_t indent, end_of_line_t eol) { + boost::io::ios_flags_saver ifs(strm); strm.precision(8); strm << std::fixed << v; } diff --git a/contrib/epee/include/sync_locked_object.h b/contrib/epee/include/sync_locked_object.h index 4bedf549..2980bbb7 100644 --- a/contrib/epee/include/sync_locked_object.h +++ b/contrib/epee/include/sync_locked_object.h @@ -54,8 +54,10 @@ namespace epee {} ~locked_object_proxy() { + TRY_ENTRY(); uint64_t lock_time = epee::misc_utils::get_tick_count() - start_lock_time; lock_time_watching_policy::watch_lock_time(lock_time); + CATCH_ALL_DO_NOTHING(); } /* diff --git a/src/common/db_backend_lmdb.cpp b/src/common/db_backend_lmdb.cpp index 69122969..95d81076 100644 --- a/src/common/db_backend_lmdb.cpp +++ b/src/common/db_backend_lmdb.cpp @@ -315,13 +315,13 @@ namespace tools PROFILE_FUNC("lmdb_db_backend::set"); int res = 0; MDB_val key = AUTO_VAL_INIT(key); - MDB_val data = AUTO_VAL_INIT(data); + MDB_val data[2] = {}; // mdb_put may access data[1] if some flags are set, this may trigger static code analizers, so here we allocate two elements to avoid it key.mv_data = (void*)k; key.mv_size = ks; - data.mv_data = (void*)v; - data.mv_size = vs; + data[0].mv_data = (void*)v; + data[0].mv_size = vs; - res = mdb_put(get_current_tx(), static_cast(h), &key, &data, 0); + res = mdb_put(get_current_tx(), static_cast(h), &key, data, 0); CHECK_AND_ASSERT_MESS_LMDB_DB(res, false, "Unable to mdb_put"); return true; } diff --git a/src/crypto/crypto-ops.c b/src/crypto/crypto-ops.c index 97e7df50..5cc3b572 100644 --- a/src/crypto/crypto-ops.c +++ b/src/crypto/crypto-ops.c @@ -1976,6 +1976,72 @@ void ge_scalarmult(ge_p2 *r, const unsigned char *a, const ge_p3 *A) { } } +/* Assumes that a[31] <= 127 */ +void ge_scalarmult_p3(ge_p3 *result, const unsigned char *a, const ge_p3 *A) { + signed char e[64]; + int carry, carry2, i; + ge_cached Ai[8]; /* 1 * A, 2 * A, ..., 8 * A */ + ge_p1p1 t; + ge_p3 u; + ge_p2 r_tmp; + ge_p2* r = &r_tmp; + + carry = 0; /* 0..1 */ + for (i = 0; i < 31; i++) { + carry += a[i]; /* 0..256 */ + carry2 = (carry + 8) >> 4; /* 0..16 */ + e[2 * i] = carry - (carry2 << 4); /* -8..7 */ + carry = (carry2 + 8) >> 4; /* 0..1 */ + e[2 * i + 1] = carry2 - (carry << 4); /* -8..7 */ + } + carry += a[31]; /* 0..128 */ + carry2 = (carry + 8) >> 4; /* 0..8 */ + e[62] = carry - (carry2 << 4); /* -8..7 */ + e[63] = carry2; /* 0..8 */ + + ge_p3_to_cached(&Ai[0], A); + for (i = 0; i < 7; i++) { + ge_add(&t, A, &Ai[i]); + ge_p1p1_to_p3(&u, &t); + ge_p3_to_cached(&Ai[i + 1], &u); + } + + ge_p2_0(r); + for (i = 63; i >= 0; i--) { + signed char b = e[i]; + unsigned char bnegative = negative(b); + unsigned char babs = b - (((-bnegative) & b) << 1); + ge_cached cur, minuscur; + ge_p2_dbl(&t, r); + ge_p1p1_to_p2(r, &t); + ge_p2_dbl(&t, r); + ge_p1p1_to_p2(r, &t); + ge_p2_dbl(&t, r); + ge_p1p1_to_p2(r, &t); + ge_p2_dbl(&t, r); + ge_p1p1_to_p3(&u, &t); + ge_cached_0(&cur); + ge_cached_cmov(&cur, &Ai[0], equal(babs, 1)); + ge_cached_cmov(&cur, &Ai[1], equal(babs, 2)); + ge_cached_cmov(&cur, &Ai[2], equal(babs, 3)); + ge_cached_cmov(&cur, &Ai[3], equal(babs, 4)); + ge_cached_cmov(&cur, &Ai[4], equal(babs, 5)); + ge_cached_cmov(&cur, &Ai[5], equal(babs, 6)); + ge_cached_cmov(&cur, &Ai[6], equal(babs, 7)); + ge_cached_cmov(&cur, &Ai[7], equal(babs, 8)); + fe_copy(minuscur.YplusX, cur.YminusX); + fe_copy(minuscur.YminusX, cur.YplusX); + fe_copy(minuscur.Z, cur.Z); + fe_neg(minuscur.T2d, cur.T2d); + ge_cached_cmov(&cur, &minuscur, bnegative); + ge_add(&t, &u, &cur); + if (i > 0) + ge_p1p1_to_p2(r, &t); + else + ge_p1p1_to_p3(result, &t); // last iteration + } +} + void ge_double_scalarmult_precomp_vartime(ge_p2 *r, const unsigned char *a, const ge_p3 *A, const unsigned char *b, const ge_dsmp Bi) { signed char aslide[256]; signed char bslide[256]; diff --git a/src/crypto/crypto-ops.h b/src/crypto/crypto-ops.h index 9d07fc8b..c29c100d 100644 --- a/src/crypto/crypto-ops.h +++ b/src/crypto/crypto-ops.h @@ -101,6 +101,7 @@ void sc_reduce(unsigned char *); /* New code */ void ge_scalarmult(ge_p2 *, const unsigned char *, const ge_p3 *); +void ge_scalarmult_p3(ge_p3 *, const unsigned char *, const ge_p3 *); void ge_double_scalarmult_precomp_vartime(ge_p2 *, const unsigned char *, const ge_p3 *, const unsigned char *, const ge_dsmp); void ge_mul8(ge_p1p1 *, const ge_p2 *); extern const fe fe_ma2; diff --git a/src/currency_core/account.cpp b/src/currency_core/account.cpp index 0f8adc36..c40a377c 100644 --- a/src/currency_core/account.cpp +++ b/src/currency_core/account.cpp @@ -158,7 +158,10 @@ namespace currency account_public_address transform_str_to_addr(const std::string& str) { account_public_address ad = AUTO_VAL_INIT(ad); - get_account_address_from_str(ad, str); + if (!get_account_address_from_str(ad, str)) + { + LOG_ERROR("cannot parse address from string: " << str); + } return ad; } } \ No newline at end of file diff --git a/src/currency_core/checkpoints_create.h b/src/currency_core/checkpoints_create.h index e404c659..d9f2e16f 100644 --- a/src/currency_core/checkpoints_create.h +++ b/src/currency_core/checkpoints_create.h @@ -9,12 +9,22 @@ #include "checkpoints.h" #include "misc_log_ex.h" -#define ADD_CHECKPOINT(h, hash) CHECK_AND_ASSERT(checkpoints.add_checkpoint(h, hash), false); +#define ADD_CHECKPOINT(h, hash) CHECK_AND_ASSERT(checkpoints.add_checkpoint(h, hash), false) + +namespace currency +{ -namespace currency { inline bool create_checkpoints(currency::checkpoints& checkpoints) { +#ifdef TESTNET + ADD_CHECKPOINT(50000, "cb05a7bdc7f78c5cdb6ef1048f85b27c569f44879233903ce5f5a4e5bd590a3d"); + ADD_CHECKPOINT(100000, "6b8b54356a9d44f6c1ebdacb8593d8f5ab2e2e2ca4493e7ae7baf4b3755c5e16"); +#else + // MAINNET + // no checkpoints +#endif return true; } -} + +} // namespace currency diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 0e403ebe..4351ef9c 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -627,7 +627,8 @@ namespace currency //put hash into extra std::stringstream ss; binary_archive oar(ss); - ::do_serialize(oar, const_cast&>(attachment)); + if (!::do_serialize(oar, const_cast&>(attachment))) + return; std::string buff = ss.str(); eai.sz = buff.size(); eai.hsh = get_blob_hash(buff); diff --git a/src/currency_core/tx_pool.cpp b/src/currency_core/tx_pool.cpp index 5e1f7640..43bde8d0 100644 --- a/src/currency_core/tx_pool.cpp +++ b/src/currency_core/tx_pool.cpp @@ -91,6 +91,16 @@ namespace currency //--------------------------------------------------------------------------------- bool tx_memory_pool::add_tx(const transaction &tx, const crypto::hash &id, uint64_t blob_size, tx_verification_context& tvc, bool kept_by_block, bool from_core) { + if (!kept_by_block && !from_core && m_blockchain.is_in_checkpoint_zone()) + { + // BCS is in CP zone, tx verification is impossible until it gets synchronized + tvc.m_added_to_pool = false; + tvc.m_should_be_relayed = false; + tvc.m_verification_failed = false; + tvc.m_verification_impossible = true; + return false; + } + TIME_MEASURE_START_PD(tx_processing_time); TIME_MEASURE_START_PD(check_inputs_types_supported_time); if(!check_inputs_types_supported(tx)) @@ -995,12 +1005,12 @@ namespace currency std::vector txs_v; txs_v.reserve(m_db_transactions.size()); - std::vector txs; + std::vector txs; // selected transactions, vector of indices of txs_v //keep getting it as a values cz db items cache will keep it as unserialised object stored by shared ptrs m_db_transactions.enumerate_keys([&](uint64_t i, crypto::hash& k){txs_v.resize(i + 1); txs_v[i].first = k; return true;}); - txs.resize(txs_v.size(), nullptr); + txs.resize(txs_v.size(), SIZE_MAX); for (uint64_t i = 0; i != txs_v.size(); i++) { @@ -1009,17 +1019,17 @@ namespace currency if (!txs_v[i].second) { LOG_ERROR("Internal tx pool db error: key " << k << " was enumerated as key but couldn't get value"); - continue; + return false; } - txs[i] = &txs_v[i]; + txs[i] = i; } - std::sort(txs.begin(), txs.end(), [](txv *a, txv *b) -> bool { + std::sort(txs.begin(), txs.end(), [&txs_v](size_t a, size_t b) -> bool { boost::multiprecision::uint128_t a_, b_; - a_ = boost::multiprecision::uint128_t(a->second->fee) * b->second->blob_size; - b_ = boost::multiprecision::uint128_t(b->second->fee) * a->second->blob_size; + a_ = boost::multiprecision::uint128_t(txs_v[a].second->fee) * txs_v[b].second->blob_size; + b_ = boost::multiprecision::uint128_t(txs_v[b].second->fee) * txs_v[a].second->blob_size; return a_ > b_; }); @@ -1039,10 +1049,10 @@ namespace currency // scan txs for alias reg requests - if there are such requests, don't process alias updates bool alias_regs_exist = false; - for (auto txp : txs) + for (auto txi : txs) { tx_extra_info ei = AUTO_VAL_INIT(ei); - bool r = parse_and_validate_tx_extra(txp->second->tx, ei); + bool r = parse_and_validate_tx_extra(txs_v[txi].second->tx, ei); CHECK_AND_ASSERT_MES(r, false, "parse_and_validate_tx_extra failed while looking up the tx pool"); if (!ei.m_alias.m_alias.empty() && !ei.m_alias.m_sign.size()) { alias_regs_exist = true; @@ -1056,12 +1066,12 @@ namespace currency for (size_t i = 0; i < txs.size(); i++) { - txv &tx(*txs[i]); + txv &tx(txs_v[txs[i]]); // expiration time check -- skip expired transactions if (is_tx_expired(tx.second->tx, tx_expiration_ts_median)) { - txs[i] = nullptr; + txs[i] = SIZE_MAX; continue; } @@ -1075,7 +1085,7 @@ namespace currency if ((alias_count >= MAX_ALIAS_PER_BLOCK) || // IF this tx registers/updates an alias AND alias per block threshold exceeded (update_an_alias && alias_regs_exist)) // OR this tx updates an alias AND there are alias reg requests... { - txs[i] = NULL; // ...skip this tx + txs[i] = SIZE_MAX; // ...skip this tx continue; } } @@ -1093,7 +1103,7 @@ namespace currency } if (!is_tx_ready_to_go_result || have_key_images(k_images, tx.second->tx)) { - txs[i] = NULL; + txs[i] = SIZE_MAX; continue; } append_key_images(k_images, tx.second->tx); @@ -1120,17 +1130,18 @@ namespace currency for (size_t i = 0; i != txs.size(); i++) { - if (txs[i]) + if (txs[i] != SIZE_MAX) { + txv &tx(txs_v[txs[i]]); if (i < best_position) { - bl.tx_hashes.push_back(txs[i]->first); + bl.tx_hashes.push_back(tx.first); } - else if (have_attachment_service_in_container(txs[i]->second->tx.attachment, BC_OFFERS_SERVICE_ID, BC_OFFERS_SERVICE_INSTRUCTION_DEL)) + else if (have_attachment_service_in_container(tx.second->tx.attachment, BC_OFFERS_SERVICE_ID, BC_OFFERS_SERVICE_INSTRUCTION_DEL)) { // BC_OFFERS_SERVICE_INSTRUCTION_DEL transactions has zero fee, so include them here regardless of reward effectiveness - bl.tx_hashes.push_back(txs[i]->first); - total_size += txs[i]->second->blob_size; + bl.tx_hashes.push_back(tx.first); + total_size += tx.second->blob_size; } } } diff --git a/src/currency_protocol/currency_protocol_handler.inl b/src/currency_protocol/currency_protocol_handler.inl index db0dc3f6..b899481d 100644 --- a/src/currency_protocol/currency_protocol_handler.inl +++ b/src/currency_protocol/currency_protocol_handler.inl @@ -179,17 +179,17 @@ namespace currency && m_core.get_blockchain_storage().get_checkpoints().get_top_checkpoint_height() < hshd.last_checkpoint_height && m_core.get_current_blockchain_size() < hshd.last_checkpoint_height ) { - LOG_PRINT_RED("Remote node have longer checkpoints zone( " << hshd.last_checkpoint_height << ") " << - "that local (" << m_core.get_blockchain_storage().get_checkpoints().get_top_checkpoint_height() << ")" << - "That means that current software is outdated, please updated it." << - "Current heigh lay under checkpoints on remote host, so it is not possible validate this transactions on local host, disconnecting.", LOG_LEVEL_0); + LOG_PRINT_RED("Remote node has longer checkpoints zone (" << hshd.last_checkpoint_height << ") " << + "than local (" << m_core.get_blockchain_storage().get_checkpoints().get_top_checkpoint_height() << "). " << + "It means that current software is outdated, please updated it! " << + "Current height lays under checkpoints zone on remote host, so it's impossible to validate remote transactions locally, disconnecting.", LOG_LEVEL_0); return false; } else if (m_core.get_blockchain_storage().get_checkpoints().get_top_checkpoint_height() < hshd.last_checkpoint_height) { - LOG_PRINT_MAGENTA("Remote node have longer checkpoints zone( " << hshd.last_checkpoint_height << ") " << - "that local (" << m_core.get_blockchain_storage().get_checkpoints().get_top_checkpoint_height() << ")" << - "That means that current software is outdated, please updated it.", LOG_LEVEL_0); + LOG_PRINT_MAGENTA("Remote node has longer checkpoints zone (" << hshd.last_checkpoint_height << ") " << + "than local (" << m_core.get_blockchain_storage().get_checkpoints().get_top_checkpoint_height() << "). " << + "It means that current software is outdated, please updated it!", LOG_LEVEL_0); } context.m_state = currency_connection_context::state_synchronizing; diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index 90bb1b96..58d83782 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -36,9 +36,8 @@ namespace plain_wallet return ""; #endif // WIN32 #ifdef IOS_BUILD - char buffer[1000] = {0}; - strcpy(buffer, getenv("HOME")); - return buffer; + char* env = getenv("HOME"); + return env ? env : ""; #elif ANDROID_BUILD /// data/data/com.zano_mobile/files return "/data/data/" ANDROID_PACKAGE_NAME; @@ -158,6 +157,7 @@ namespace plain_wallet } gwm.run_wallet(ok_response.result.wallet_id); return epee::serialization::store_t_to_json(ok_response); + return; } error_response err_result = AUTO_VAL_INIT(err_result); err_result.error.code = rsp; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index a8e52792..229181dd 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -2334,7 +2334,7 @@ bool wallet2::generate_packing_transaction_if_needed(currency::transaction& tx, //let's check if we have at least WALLET_POS_MINT_PACKING_SIZE transactions which is ready to go size_t count = 0; - for (auto it_ind = it->second.begin(); it_ind != it->second.end() && count < m_pos_mint_packing_size; it_ind++) + for (auto it_ind = it->second.begin(); it_ind != it->second.end() && count <= m_pos_mint_packing_size; it_ind++) { if (is_transfer_ready_to_go(m_transfers[*it_ind], fake_outputs_number)) ++count; @@ -2848,7 +2848,7 @@ bool wallet2::build_minted_block(const currency::COMMAND_RPC_SCAN_POS::request& if (generate_packing_transaction_if_needed(pack_tx, 0)) { tx_to_blob(pack_tx, tmpl_req.explicit_transaction); - WLT_LOG_GREEN("Pacling inputs: " << pack_tx.vin.size() << " inputs consolidated", LOG_LEVEL_0); + WLT_LOG_GREEN("Packing inputs: " << pack_tx.vin.size() << " inputs consolidated in tx " << get_transaction_hash(pack_tx), LOG_LEVEL_0); } m_core_proxy->call_COMMAND_RPC_GETBLOCKTEMPLATE(tmpl_req, tmpl_rsp); WLT_CHECK_AND_ASSERT_MES(tmpl_rsp.status == CORE_RPC_STATUS_OK, false, "Failed to create block template after kernel hash found!"); diff --git a/src/wallet/wallet_helpers.h b/src/wallet/wallet_helpers.h index 38efcc64..365890da 100644 --- a/src/wallet/wallet_helpers.h +++ b/src/wallet/wallet_helpers.h @@ -19,6 +19,6 @@ namespace tools uint64_t fake = 0; wi.balance = w.balance(wi.unlocked_balance, fake, fake, wi.mined_total); wi.path = epee::string_encoding::wstring_to_utf8(w.get_wallet_path()); - return API_RETURN_CODE_OK; + return true; } } \ No newline at end of file diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 7651e237..b6c01a50 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -76,7 +76,9 @@ void wallet_lock_time_watching_policy::watch_lock_time(uint64_t lock_time) wallets_manager::~wallets_manager() { + TRY_ENTRY(); stop(); + CATCH_ENTRY_NO_RETURN(); } void terminate_handler_func() @@ -793,7 +795,7 @@ std::string wallets_manager::generate_wallet(const std::wstring& path, const std w->generate(path, password); owr.seed = w->get_account().get_restore_braindata(); } - catch (const tools::error::file_exists/*& e*/) + catch (const tools::error::file_exists&) { return API_RETURN_CODE_ALREADY_EXISTS; } @@ -881,7 +883,7 @@ std::string wallets_manager::restore_wallet(const std::wstring& path, const std: w->restore(path, password, restore_key); owr.seed = w->get_account().get_restore_braindata(); } - catch (const tools::error::file_exists/*& e*/) + catch (const tools::error::file_exists&) { return API_RETURN_CODE_ALREADY_EXISTS; } diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index f6180f54..471af00f 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -2047,9 +2047,11 @@ test_chain_unit_enchanced::test_chain_unit_enchanced() : m_invalid_block_index(std::numeric_limits::max()) , m_orphan_block_index(std::numeric_limits::max()) , m_invalid_tx_index(std::numeric_limits::max()) + , m_unverifiable_tx_index(std::numeric_limits::max()) { REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, configure_core); REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, mark_invalid_tx); + REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, mark_unverifiable_tx); REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, mark_invalid_block); REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, mark_orphan_block); REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, check_top_block); diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index cc270d38..7c8367a1 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -258,6 +258,9 @@ public: { if (m_invalid_tx_index == event_idx) return tvc.m_verification_failed; + + if (m_unverifiable_tx_index == event_idx) + return tvc.m_verification_impossible; return !tvc.m_verification_failed && tx_added; } @@ -291,6 +294,12 @@ public: return true; } + bool mark_unverifiable_tx(currency::core& /*c*/, size_t ev_index, const std::vector& /*events*/) + { + m_unverifiable_tx_index = ev_index + 1; + return true; + } + bool configure_core(currency::core& c, size_t ev_index, const std::vector& events); bool check_top_block(currency::core& c, size_t ev_index, const std::vector& events); bool clear_tx_pool(currency::core& c, size_t ev_index, const std::vector& events); @@ -310,6 +319,7 @@ protected: }; size_t m_invalid_block_index; size_t m_invalid_tx_index; + size_t m_unverifiable_tx_index; size_t m_orphan_block_index; }; diff --git a/tests/core_tests/chaingen_main.cpp b/tests/core_tests/chaingen_main.cpp index 2785de0f..6acc5d5b 100644 --- a/tests/core_tests/chaingen_main.cpp +++ b/tests/core_tests/chaingen_main.cpp @@ -8,7 +8,7 @@ #include "chaingen_tests_list.h" #include "common/command_line.h" #include "transaction_tests.h" -#include "../../src/gui/qt-daemon/application/core_fast_rpc_proxy.h" +#include "../../src/wallet/core_fast_rpc_proxy.h" #include "test_core_proxy.h" #include "currency_core/bc_offers_service.h" #include "random_helper.h" @@ -809,6 +809,7 @@ int main(int argc, char* argv[]) GENERATE_AND_PLAY(gen_checkpoints_prun_txs_after_blockchain_load); GENERATE_AND_PLAY(gen_checkpoints_reorganize); GENERATE_AND_PLAY(gen_checkpoints_pos_validation_on_altchain); + GENERATE_AND_PLAY(gen_checkpoints_and_invalid_tx_to_pool); GENERATE_AND_PLAY(gen_no_attchments_in_coinbase); GENERATE_AND_PLAY(gen_no_attchments_in_coinbase_gentime); diff --git a/tests/core_tests/checkpoints_tests.cpp b/tests/core_tests/checkpoints_tests.cpp index 50a47140..f4767acb 100644 --- a/tests/core_tests/checkpoints_tests.cpp +++ b/tests/core_tests/checkpoints_tests.cpp @@ -81,7 +81,9 @@ bool gen_checkpoints_attachments_basic::generate(std::vector& REWIND_BLOCKS_N(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); // 0 ... N N+1 N+2 <- height (N = CURRENCY_MINED_MONEY_UNLOCK_WINDOW) + // CP checkpoint // (0 )- (0r)- (1 )- (2 ) + // tx_0 txs DO_CALLBACK_PARAMS(events, "set_checkpoint", params_checkpoint(CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 2)); @@ -94,10 +96,13 @@ bool gen_checkpoints_attachments_basic::generate(std::vector& attachments.push_back(cm); attachments.push_back(ms); - MAKE_TX_LIST_START_WITH_ATTACHS(events, txs, miner_acc, miner_acc, MK_TEST_COINS(1), blk_0r, attachments); - m_tx_hash = get_transaction_hash(txs.front()); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); // tx_0 goes with the block blk_1 + MAKE_TX_ATTACH(events, tx_0, miner_acc, miner_acc, MK_TEST_COINS(1), blk_0r, attachments); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false)); + + m_tx_hash = get_transaction_hash(tx_0); - MAKE_NEXT_BLOCK_TX_LIST(events, blk_1, blk_0r, miner_acc, txs); + MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_0); MAKE_NEXT_BLOCK(events, blk_2, blk_1, miner_acc); @@ -150,7 +155,10 @@ bool gen_checkpoints_invalid_keyimage::generate(std::vector& e // don't sign at all // tb.step5_sign(); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); // tb.m_tx goes with block blk_1 events.push_back(tb.m_tx); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false)); + MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tb.m_tx); MAKE_NEXT_BLOCK(events, blk_2, blk_1, miner_acc); @@ -376,33 +384,40 @@ bool gen_checkpoints_prun_txs_after_blockchain_load::generate(std::vectorCP1 +------->CP2 <- checkpoints - // | | <- when CP are set up - // (0 )- (0r)- (1 )- (2 )- (3 )- (4 )- (5 )- (6 ) <- main chain - // tx_0 tx_1 <- txs included in blocks + // 0 ... N N+1 N+2 N+3 N+4 N+5 N+6 N+7 <- height (N = CURRENCY_MINED_MONEY_UNLOCK_WINDOW) + // +------->CP1 +------->CP2 <- checkpoints + // | | <- when CP are set up + // (0 )- (0r)- (1 )- (2 )- (3 )- (4 )- (5 )- (6 )- (7 ) <- main chain + // tx_0 tx_1 <- txs included in blocks // // Expected: tx_0 and tx_1 are both pruned DO_CALLBACK(events, "check_not_being_in_cp_zone"); DO_CALLBACK_PARAMS(events, "set_checkpoint", params_checkpoint(CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 2)); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); // tx_0 goes with blk_1_bad MAKE_TX(events, tx_0, miner_acc, alice, MK_TEST_COINS(1), blk_0r); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false)); MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_0); DO_CALLBACK(events, "check_being_in_cp_zone"); MAKE_NEXT_BLOCK(events, blk_2, blk_1, miner_acc); - MAKE_TX(events, tx_1, miner_acc, alice, MK_TEST_COINS(1), blk_2); - MAKE_NEXT_BLOCK_TX1(events, blk_3, blk_2, miner_acc, tx_1); + MAKE_NEXT_BLOCK(events, blk_3, blk_2, miner_acc); DO_CALLBACK(events, "check_not_being_in_cp_zone"); - DO_CALLBACK_PARAMS(events, "set_checkpoint", params_checkpoint(CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 5)); - MAKE_NEXT_BLOCK(events, blk_4, blk_3, miner_acc); + MAKE_TX(events, tx_1, miner_acc, alice, MK_TEST_COINS(1), blk_3); + MAKE_NEXT_BLOCK_TX1(events, blk_4, blk_3, miner_acc, tx_1); + + DO_CALLBACK(events, "check_not_being_in_cp_zone"); + + DO_CALLBACK_PARAMS(events, "set_checkpoint", params_checkpoint(CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 6)); + MAKE_NEXT_BLOCK(events, blk_5, blk_4, miner_acc); DO_CALLBACK(events, "check_being_in_cp_zone"); MAKE_NEXT_BLOCK(events, blk_6, blk_5, miner_acc); + MAKE_NEXT_BLOCK(events, blk_7, blk_6, miner_acc); DO_CALLBACK(events, "check_not_being_in_cp_zone"); m_tx0_id = get_transaction_hash(tx_0); @@ -813,3 +828,70 @@ bool gen_no_attchments_in_coinbase_gentime::generate(std::vector& events) const +{ + // Test idea: make sure txs with invalid signatures rejected by the pool when the core is in CP zone + // Mine a block aftewards to make sure everything is okay. + + // 0 ... N N+1 N+2 <- height (N = CURRENCY_MINED_MONEY_UNLOCK_WINDOW) + // +------->CP1 <- checkpoint + // | <- when CP is set up + // (0 )- (0r)- (1 )- (2 )- <- main chain + // tx_0 CB + + bool r = false; + GENERATE_ACCOUNT(miner_acc); + MAKE_GENESIS_BLOCK(events, blk_0, miner_acc, test_core_time::get_time()); + DO_CALLBACK_PARAMS(events, "set_checkpoint", params_checkpoint(CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 1)); + + REWIND_BLOCKS_N(events, blk_0r, blk_0, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); + + std::vector sources; + std::vector destinations; + r = fill_tx_sources_and_destinations(events, blk_0r, miner_acc, miner_acc, MK_TEST_COINS(1), TESTS_DEFAULT_FEE, 0, sources, destinations); + CHECK_AND_ASSERT_MES(r, false, "fill_tx_sources_and_destinations failed"); + + transaction tx_0 = AUTO_VAL_INIT(tx_0); + r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_0, 0); + CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); + + // invalidate tx_0 signature + tx_0.signatures.clear(); + + DO_CALLBACK(events, "mark_unverifiable_tx"); + events.push_back(tx_0); + + MAKE_NEXT_BLOCK(events, blk_1, blk_0r, miner_acc); // <-- CHECKPOINT + MAKE_NEXT_BLOCK(events, blk_2, blk_1, miner_acc); + + DO_CALLBACK(events, "check_not_being_in_cp_zone"); + + DO_CALLBACK(events, "check_tx_pool_empty"); + + // try to mine a block using default blocktemplate (all txs from the pool) + DO_CALLBACK(events, "c1"); + + DO_CALLBACK(events, "check_tx_pool_empty"); + + return true; +} + +bool gen_checkpoints_and_invalid_tx_to_pool::c1(currency::core& c, size_t ev_index, const std::vector& events) +{ + account_base acc; + acc.generate(); + + bool r = mine_next_pow_block_in_playtime(acc.get_public_address(), c); + CHECK_AND_ASSERT_MES(r, false, "mine_next_pow_block_in_playtime failed"); + + return true; +} + diff --git a/tests/core_tests/checkpoints_tests.h b/tests/core_tests/checkpoints_tests.h index 64e5b69d..67f84a12 100644 --- a/tests/core_tests/checkpoints_tests.h +++ b/tests/core_tests/checkpoints_tests.h @@ -102,3 +102,10 @@ struct gen_no_attchments_in_coinbase_gentime : public checkpoints_test { bool generate(std::vector& events) const; }; + +struct gen_checkpoints_and_invalid_tx_to_pool : public checkpoints_test +{ + gen_checkpoints_and_invalid_tx_to_pool(); + bool generate(std::vector& events) const; + bool c1(currency::core& c, size_t ev_index, const std::vector& events); +}; diff --git a/tests/core_tests/hard_fork_1.cpp b/tests/core_tests/hard_fork_1.cpp index fdbe9617..ed278cba 100644 --- a/tests/core_tests/hard_fork_1.cpp +++ b/tests/core_tests/hard_fork_1.cpp @@ -340,11 +340,13 @@ bool hard_fork_1_checkpoint_basic_test::generate(std::vector& r = construct_tx(miner_acc.get_keys(), sources, destinations, extra, empty_attachment, tx_0, tx_sec_key, 0 /* unlock time 1 is zero and thus will not be set */); CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); // tx_0 should be accepted + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); // tx_0 goes with blk_1_bad events.push_back(tx_0); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false)); DO_CALLBACK(events, "mark_invalid_block"); MAKE_NEXT_BLOCK_TX1(events, blk_1_bad, blk_0r, miner_acc, tx_0); // should be rejected because of tx_0 - DO_CALLBACK_PARAMS(events, "check_tx_pool_count", static_cast(1)); + DO_CALLBACK(events, "check_tx_pool_empty"); // tx_0 won't be returned to the pool as it came with block blk_1_bad DO_CALLBACK(events, "clear_tx_pool"); MAKE_NEXT_BLOCK(events, blk_1, blk_0r, miner_acc); @@ -360,7 +362,9 @@ bool hard_fork_1_checkpoint_basic_test::generate(std::vector& // // now tx_0 is okay and can be added to the blockchain + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); // tx_0 goes with blk_5 events.push_back(tx_0); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false)); MAKE_NEXT_BLOCK_TX1(events, blk_5, blk_4, miner_acc, tx_0); REWIND_BLOCKS_N_WITH_TIME(events, blk_5r, blk_5, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW); diff --git a/tests/core_tests/multisig_wallet_tests.cpp b/tests/core_tests/multisig_wallet_tests.cpp index 7a50e2a2..c9990045 100644 --- a/tests/core_tests/multisig_wallet_tests.cpp +++ b/tests/core_tests/multisig_wallet_tests.cpp @@ -1674,7 +1674,10 @@ bool multisig_and_checkpoints::generate(std::vector& events) c transaction tx_1 = AUTO_VAL_INIT(tx_1); r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_1, 0, CURRENCY_TO_KEY_OUT_RELAXED, true); CHECK_AND_ASSERT_MES(r, false, "construct_tx"); + + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); // tx_1 goes with the block blk_1 events.push_back(tx_1); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false)); MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_1); @@ -1695,7 +1698,9 @@ bool multisig_and_checkpoints::generate(std::vector& events) c bool tx_fully_signed = false; r = sign_multisig_input_in_tx(tx_2, 0, alice_acc.get_keys(), tx_1, &tx_fully_signed); CHECK_AND_ASSERT_MES(r & tx_fully_signed, false, "sign_multisig_input_in_tx failed, tx_fully_signed: " << tx_fully_signed); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); // tx_2 goes with the block blk_2 events.push_back(tx_2); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false)); MAKE_NEXT_BLOCK_TX1(events, blk_2, blk_1, miner_acc, tx_2); ADJUST_TEST_CORE_TIME(blk_2.timestamp); @@ -1708,7 +1713,10 @@ bool multisig_and_checkpoints::generate(std::vector& events) c transaction tx_3 = AUTO_VAL_INIT(tx_3); r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_3, 0, CURRENCY_TO_KEY_OUT_RELAXED, true); CHECK_AND_ASSERT_MES(r, false, "construct_tx"); + + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); // tx_3 goes with the block blk_3 events.push_back(tx_3); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false)); MAKE_NEXT_BLOCK_TX1(events, blk_3, blk_2, miner_acc, tx_3); // <-- CP @@ -1732,7 +1740,9 @@ bool multisig_and_checkpoints::generate(std::vector& events) c CHECK_AND_ASSERT_MES(r, false, "construct_tx failed"); r = sign_multisig_input_in_tx(tx_4, 0, alice_acc.get_keys(), tx_3, &tx_fully_signed); CHECK_AND_ASSERT_MES(r & tx_fully_signed, false, "sign_multisig_input_in_tx failed, tx_fully_signed: " << tx_fully_signed); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); // tx_4 goes with the block blk_4 events.push_back(tx_4); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false)); MAKE_NEXT_BLOCK_TX1(events, blk_4, blk_3, miner_acc, tx_4); // tx_5: normal input -> multisig output @@ -1815,7 +1825,10 @@ bool multisig_and_checkpoints_bad_txs::generate(std::vector& e transaction tx_1 = AUTO_VAL_INIT(tx_1); r = construct_tx(miner_acc.get_keys(), sources, destinations, empty_attachment, tx_1, 0, CURRENCY_TO_KEY_OUT_RELAXED, true); CHECK_AND_ASSERT_MES(r, false, "construct_tx"); + + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); // tx_1 goes with the block blk_1 events.push_back(tx_1); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false)); MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_1); @@ -1829,21 +1842,24 @@ bool multisig_and_checkpoints_bad_txs::generate(std::vector& e boost::get(tx_2.vin[0]).sigs_count = 10; DO_CALLBACK(events, "mark_invalid_tx"); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); events.push_back(tx_2); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false)); MAKE_NEXT_BLOCK(events, blk_2, blk_1, miner_acc); DO_CALLBACK_PARAMS(events, "check_balance", params_check_balance(BOB_ACC_IDX, 0, 0, 0, 0, 0)); - // tx_3: no signatures, zero sigs_count in ms input (should FAIL) + // tx_3: no signatures, zero sigs_count in ms input (should pass under CP zone) transaction tx_3 = AUTO_VAL_INIT(tx_3); r = make_tx_multisig_to_key(tx_1, get_tx_out_index_by_amount(tx_1, amount), std::list({ alice_acc.get_keys() }), bob_acc.get_public_address(), tx_3); CHECK_AND_ASSERT_MES(r, false, "make_tx_multisig_to_key failed"); tx_3.signatures.clear(); boost::get(tx_3.vin[0]).sigs_count = 0; - DO_CALLBACK(events, "mark_invalid_tx"); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); events.push_back(tx_3); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false)); // tx_4: zero ms out keys (should FAIL) r = fill_tx_sources_and_destinations(events, blk_0r, miner_acc.get_keys(), to_addrs, amount, TESTS_DEFAULT_FEE, 0, sources, destinations, true, true, 1); @@ -1857,7 +1873,9 @@ bool multisig_and_checkpoints_bad_txs::generate(std::vector& e txb.step5_sign(sources); transaction tx_4 = txb.m_tx; DO_CALLBACK(events, "mark_invalid_tx"); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); events.push_back(tx_4); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false)); // tx_6: many ms out keys + no sigs (should pass due to CP zone) txb = AUTO_VAL_INIT(txb); @@ -1870,7 +1888,9 @@ bool multisig_and_checkpoints_bad_txs::generate(std::vector& e txb.step5_sign(sources); txb.m_tx.signatures.clear(); transaction tx_6 = txb.m_tx; + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); events.push_back(tx_6); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false)); MAKE_NEXT_BLOCK_TX1(events, blk_3, blk_2, miner_acc, tx_6); @@ -1880,7 +1900,9 @@ bool multisig_and_checkpoints_bad_txs::generate(std::vector& e transaction tx_7 = AUTO_VAL_INIT(tx_7); r = make_tx_multisig_to_key(tx_6, get_tx_out_index_by_amount(tx_6, amount), std::list({ alice_acc.get_keys() }), bob_acc.get_public_address(), tx_7); CHECK_AND_ASSERT_MES(r, false, "make_tx_multisig_to_key failed"); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); events.push_back(tx_7); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false)); MAKE_NEXT_BLOCK_TX1(events, blk_4, blk_3, miner_acc, tx_7); diff --git a/tests/core_tests/pos_validation.cpp b/tests/core_tests/pos_validation.cpp index 6a637cb2..d8d338c1 100644 --- a/tests/core_tests/pos_validation.cpp +++ b/tests/core_tests/pos_validation.cpp @@ -1040,6 +1040,8 @@ bool pos_minting_tx_packing::pos_minting_tx_packing::generate(std::vectorset_pos_mint_packing_size(m_pos_mint_packing_size); - // no coinbase tx outputs should packed + // no coinbase tx outputs should be packed r = alice_wlt->try_mint_pos(); CHECK_AND_ASSERT_MES(r, false, "try_mint_pos failed"); @@ -1112,12 +1114,24 @@ bool pos_minting_tx_packing::c1(currency::core& c, size_t ev_index, const std::v CHECK_AND_ASSERT_MES(r, false, "try_mint_pos failed"); CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Alice", alice_wlt, - m_alice_start_amount + CURRENCY_BLOCK_REWARD * (m_pos_mint_packing_size + 2), // total + m_alice_start_amount + CURRENCY_BLOCK_REWARD * (m_pos_mint_packing_size + 2), // total (+1 one block reward) true, UINT64_MAX, - m_alice_start_amount + CURRENCY_BLOCK_REWARD + // CURRENCY_BLOCK_REWARD * m_pos_mint_packing_size locked for stake + // CURRENCY_BLOCK_REWARD * (m_pos_mint_packing_size + 1) locked for packing tx + m_alice_start_amount + CURRENCY_BLOCK_REWARD - CURRENCY_BLOCK_REWARD * (m_pos_mint_packing_size + 1) // unlocked ), false, ""); + r = alice_wlt->try_mint_pos(); + CHECK_AND_ASSERT_MES(r, false, "try_mint_pos failed"); + + CHECK_AND_ASSERT_MES(refresh_wallet_and_check_balance("", "Alice", alice_wlt, + m_alice_start_amount + CURRENCY_BLOCK_REWARD * (m_pos_mint_packing_size + 3), // total (+1 one block reward) + true, + UINT64_MAX, + // CURRENCY_BLOCK_REWARD * m_pos_mint_packing_size locked for stake + m_alice_start_amount + CURRENCY_BLOCK_REWARD - CURRENCY_BLOCK_REWARD * (m_pos_mint_packing_size + 1) - CURRENCY_BLOCK_REWARD * m_pos_mint_packing_size // unlocked + ), false, ""); return true; } diff --git a/tests/core_tests/pruning_ring_signatures.cpp b/tests/core_tests/pruning_ring_signatures.cpp index 56fb5444..ec38eccb 100644 --- a/tests/core_tests/pruning_ring_signatures.cpp +++ b/tests/core_tests/pruning_ring_signatures.cpp @@ -56,6 +56,7 @@ bool generate_blockchain_with_pruned_rs(std::vector& events) REWIND_BLOCKS_N(events, blk_5, blk_4, miner_account, 30); REWIND_BLOCKS(events, blk_5r, blk_5, miner_account); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); MAKE_TX_LIST_START(events, txs_blk_6, miner_account, some_account_1, MK_TEST_COINS(1), blk_5r); MAKE_TX_LIST(events, txs_blk_6, miner_account, some_account_1, MK_TEST_COINS(1), blk_5r); MAKE_TX_LIST(events, txs_blk_6, miner_account, some_account_1, MK_TEST_COINS(1), blk_5r); @@ -69,13 +70,16 @@ bool generate_blockchain_with_pruned_rs(std::vector& events) MAKE_TX_LIST(events, txs_blk_6, miner_account, some_account_1, MK_TEST_COINS(1), blk_5r); MAKE_TX_LIST(events, txs_blk_6, miner_account, some_account_1, MK_TEST_COINS(1), blk_5r); MAKE_TX_LIST(events, txs_blk_6, miner_account, some_account_1, MK_TEST_COINS(1), blk_5r); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false)); MAKE_NEXT_BLOCK_TX_LIST(events, blk_6, blk_5r, miner_account, txs_blk_6); REWIND_BLOCKS_N(events, blk_6r, blk_6, miner_account, 20); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, true)); MAKE_TX_LIST_START(events, txs_blk_7, some_account_1, some_account_1, MK_TEST_COINS(1) + TESTS_DEFAULT_FEE, blk_6r); MAKE_TX_MIX_LIST(events, txs_blk_7, some_account_1, some_account_1, MK_TEST_COINS(1) + TESTS_DEFAULT_FEE, 3, blk_6r, std::vector()); MAKE_TX_MIX_LIST(events, txs_blk_7, some_account_1, some_account_1, MK_TEST_COINS(1) + TESTS_DEFAULT_FEE, 3, blk_6r, std::vector()); MAKE_TX_MIX_LIST(events, txs_blk_7, some_account_1, some_account_1, MK_TEST_COINS(1) + TESTS_DEFAULT_FEE, 3, blk_6r, std::vector()); + events.push_back(event_visitor_settings(event_visitor_settings::set_txs_kept_by_block, false)); MAKE_NEXT_BLOCK_TX_LIST(events, blk_7, blk_6r, miner_account, txs_blk_7); REWIND_BLOCKS(events, blk_7r, blk_7, miner_account); diff --git a/utils/build_script_linux.sh b/utils/build_script_linux.sh index b86876a5..2f156c02 100755 --- a/utils/build_script_linux.sh +++ b/utils/build_script_linux.sh @@ -117,6 +117,9 @@ fi echo "Build success" +if [ -z "$upload_build" ]; then + exit 0 +fi echo "Uploading..." diff --git a/utils/docker/Dockerfile b/utils/docker/Dockerfile new file mode 100644 index 00000000..9176be64 --- /dev/null +++ b/utils/docker/Dockerfile @@ -0,0 +1,96 @@ +########################################################################################### +## 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 sowle/zano-full-node +# +# 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 +# + +# +# Build Zano +# + +FROM ubuntu:18.04 as zano-build + +RUN apt update && \ + apt install -y build-essential \ + libicu-dev \ + curl \ + g++ \ + git + + +WORKDIR /root + +# CMake 3.15.5 + +RUN curl https://github.com/Kitware/CMake/releases/download/v3.15.5/cmake-3.15.5-Linux-x86_64.sh -OL &&\ + echo '62e3e7d134a257e13521e306a9d3d1181ab99af8fcae66699c8f98754fc02dda cmake-3.15.5-Linux-x86_64.sh' | sha256sum -c - &&\ + mkdir /opt/cmake &&\ + sh cmake-3.15.5-Linux-x86_64.sh --prefix=/opt/cmake --skip-license &&\ + ln -s /opt/cmake/bin/cmake /usr/local/bin/cmake &&\ + cmake --version &&\ + rm cmake-3.15.5-Linux-x86_64.sh + +# Boost 1.68 + +RUN curl https://dl.bintray.com/boostorg/release/1.68.0/source/boost_1_68_0.tar.bz2 -OL &&\ + echo '7f6130bc3cf65f56a618888ce9d5ea704fa10b462be126ad053e80e553d6d8b7 boost_1_68_0.tar.bz2' | sha256sum -c - &&\ + tar -xjf boost_1_68_0.tar.bz2 &&\ + rm boost_1_68_0.tar.bz2 &&\ + cd boost_1_68_0 &&\ + ./bootstrap.sh --with-libraries=system,filesystem,thread,date_time,chrono,regex,serialization,atomic,program_options,locale,timer &&\ + ./b2 &&\ + cd .. + +ENV BOOST_ROOT=/root/boost_1_68_0 + +# 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 https://github.com/hyle-team/zano.git &&\ + cd zano &&\ + git submodule update --init --recursive &&\ + mkdir build && cd build &&\ + cmake -D STATIC=TRUE .. &&\ + make -j $make_job_slots daemon simplewallet + + +# +# Run Zano +# + +FROM ubuntu:18.04 + +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=zano-build /root/zano/build/src/zanod . +COPY --chown=zano:zano --from=zano-build /root/zano/build/src/simplewallet . + +# blockchain loaction +VOLUME /home/zano/.Zano + +EXPOSE 11121 11211 + +ENTRYPOINT ["./zanod"] +CMD ["--disable-upnp", "--rpc-bind-ip=0.0.0.0", "--log-level=0"] diff --git a/utils/snap/snapcraft.yaml b/utils/snap/snapcraft.yaml new file mode 100644 index 00000000..344e80d1 --- /dev/null +++ b/utils/snap/snapcraft.yaml @@ -0,0 +1,61 @@ +name: zano # you probably want to 'snapcraft register ' +base: core18 # the base snap is the execution environment for this snap +version: '1.1.5' # just for humans, typically '1.2+git' or '1.3.2' +summary: "Zano coin: official wallet. Secure. Scalable. Easy to Use." +description: | + Zano is a scalable and secure coin, designed for use in e-commerce. + The technology behind our blockchain provides reliability, security, + and flexibility — a perfect option for P2P transactions. + More info: http://zano.org +grade: devel # must be 'stable' to release into candidate/stable channels +confinement: devmode # use 'strict' once you have the right plugs and slots + +parts: + libboost: + plugin: dump + source: . + + override-pull: | + curl https://dl.bintray.com/boostorg/release/1.68.0/source/boost_1_68_0.tar.bz2 -OL &&\ + echo '7f6130bc3cf65f56a618888ce9d5ea704fa10b462be126ad053e80e553d6d8b7 boost_1_68_0.tar.bz2' | sha256sum -c - &&\ + pwd && echo pulled ok + + override-build: | + tar -xjf $SNAPCRAFT_PART_SRC/boost_1_68_0.tar.bz2 + cd boost_1_68_0 + pwd + ./bootstrap.sh --with-libraries=system,filesystem,thread,date_time,chrono,regex,serialization,atomic,program_options,locale,timer + ./b2 + mkdir -p $SNAPCRAFT_PART_INSTALL/boost_1_68_0 $SNAPCRAFT_PART_INSTALL/boost_1_68_0/stage + cp -pr boost $SNAPCRAFT_PART_INSTALL/boost_1_68_0/ + cp -pr stage/lib $SNAPCRAFT_PART_INSTALL/boost_1_68_0/stage/ + + build-packages: + - curl + - build-essential + - g++ + - libicu-dev + + stage-packages: + - libicu60 + + zano-bin: + after: [ libboost ] + source: https://github.com/hyle-team/zano.git + plugin: cmake + + override-build: | + cmake -DBOOST_ROOT=$SNAPCRAFT_STAGE/boost_1_68_0 -DBOOST_LIBRARYDIR=$SNAPCRAFT_STAGE/boost_1_68_0/stage/lib -DSTATIC=True $SNAPCRAFT_PART_SRC + make -j1 daemon simplewallet + cp src/zanod $SNAPCRAFT_PART_INSTALL + cp src/simplewallet $SNAPCRAFT_PART_INSTALL + + build-packages: + - build-essential + - g++ + - libicu-dev + + +apps: + zano: + command: zanod