From 0f98b6d9906a075d47915736d6f807526ea18bf5 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sat, 13 Jun 2020 21:04:21 +0200 Subject: [PATCH] fixed few bugs related to prefetch --- src/wallet/wallet2.cpp | 39 +++++++++++---------- src/wallet/wallet2.h | 5 ++- tests/core_tests/chaingen.cpp | 12 +++++-- tests/core_tests/wallet_test_core_proxy.cpp | 16 ++++++--- 4 files changed, 45 insertions(+), 27 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index ecbb04e1..ac6c256e 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -400,6 +400,9 @@ void wallet2::process_new_transaction(const currency::transaction& tx, uint64_t if(!outs.empty() /*&& tx_money_got_in_outs*/) { + //good news - got money! take care about it + //usually we have only one transfer for user in transaction + //create once instance of tx for all entries std::shared_ptr pwallet_info(new transaction_wallet_info()); pwallet_info->m_tx = tx; @@ -414,16 +417,13 @@ void wallet2::process_new_transaction(const currency::transaction& tx, uint64_t if (!pglobal_indexes) { -#ifndef MOBILE_WALLET_BUILD - //good news - got money! take care about it - //usually we have only one transfer for user in transaction - fetch_tx_global_indixes(tx, outputs_index_local); - pglobal_indexes = &outputs_index_local; -#endif + if (!m_use_deffered_global_outputs) + { + fetch_tx_global_indixes(tx, outputs_index_local); + pglobal_indexes = &outputs_index_local; + } } - - - + for (size_t i_in_outs = 0; i_in_outs != outs.size(); i_in_outs++) { size_t o = outs[i_in_outs]; @@ -501,16 +501,18 @@ void wallet2::process_new_transaction(const currency::transaction& tx, uint64_t td.m_ptx_wallet_info = pwallet_info; td.m_internal_output_index = o; td.m_key_image = ki; -#ifdef MOBILE_WALLET_BUILD - if (pglobal_indexes && pglobal_indexes->size() > o) - td.m_global_output_index = (*pglobal_indexes)[o]; + if (m_use_deffered_global_outputs) + { + if (pglobal_indexes && pglobal_indexes->size() > o) + td.m_global_output_index = (*pglobal_indexes)[o]; + else + td.m_global_output_index = WALLET_GLOBAL_OUTPUT_INDEX_UNDEFINED; + } else - td.m_global_output_index = WALLET_GLOBAL_OUTPUT_INDEX_UNDEFINED; -#else - WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(pglobal_indexes, "pglobal_indexes IS NULL in non mobile wallet"); - td.m_global_output_index = (*pglobal_indexes)[o]; -#endif - + { + WLT_THROW_IF_FALSE_WALLET_INT_ERR_EX(pglobal_indexes, "pglobal_indexes IS NULL in non mobile wallet"); + td.m_global_output_index = (*pglobal_indexes)[o]; + } if (coin_base_tx) { //last out in coinbase tx supposed to be change from coinstake @@ -3834,6 +3836,7 @@ void wallet2::prefetch_global_indicies_if_needed(std::vector& selected { transfer_details& td = m_transfers[*it_indices]; td.m_global_output_index = (*it_ooutputs)[td.m_internal_output_index]; + it_ooutputs++; it_indices++; } } //---------------------------------------------------------------------------------------------------- diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 2bd2e38b..4b0461d4 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -333,7 +333,8 @@ namespace tools m_last_pow_block_h(0), m_minimum_height(WALLET_MINIMUM_HEIGHT_UNSET_CONST), m_pos_mint_packing_size(WALLET_DEFAULT_POS_MINT_PACKING_SIZE), - m_current_wallet_file_size(0) + m_current_wallet_file_size(0), + m_use_deffered_global_outputs(false) {}; public: wallet2() : m_stop(false), @@ -824,6 +825,7 @@ namespace tools bool get_utxo_distribution(std::map& distribution); uint64_t get_sync_progress(); uint64_t get_wallet_file_size()const; + void set_use_deffered_global_outputs(bool use) { m_use_deffered_global_outputs = use;} private: @@ -1001,6 +1003,7 @@ private: std::string m_miner_text_info; mutable uint64_t m_current_wallet_file_size; + bool m_use_deffered_global_outputs; //this needed to access wallets state in coretests, for creating abnormal blocks and tranmsactions friend class test_generator; diff --git a/tests/core_tests/chaingen.cpp b/tests/core_tests/chaingen.cpp index b5921344..7270a4af 100644 --- a/tests/core_tests/chaingen.cpp +++ b/tests/core_tests/chaingen.cpp @@ -384,10 +384,16 @@ bool test_generator::build_wallets(const blockchain_vector& blocks, {} virtual bool call_COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES(const currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request& rqt, currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response& rsp) { - auto it = m_txs_outs.find(rqt.txid); - CHECK_AND_ASSERT_MES(it != m_txs_outs.end(), false, "tx " << rqt.txid << " was not found in tx global outout indexes"); + rsp.tx_global_outs.resize(rqt.txids.size()); + size_t i = 0; + for (auto& txid : rqt.txids) + { + auto it = m_txs_outs.find(txid); + CHECK_AND_ASSERT_MES(it != m_txs_outs.end(), false, "tx " << txid << " was not found in tx global outout indexes"); + rsp.tx_global_outs[i].v = it->second; + i++; + } rsp.status = API_RETURN_CODE_OK; - rsp.o_indexes = it->second; return true; } }; diff --git a/tests/core_tests/wallet_test_core_proxy.cpp b/tests/core_tests/wallet_test_core_proxy.cpp index 0ebe76fa..aeb7727d 100644 --- a/tests/core_tests/wallet_test_core_proxy.cpp +++ b/tests/core_tests/wallet_test_core_proxy.cpp @@ -45,12 +45,18 @@ bool wallet_test_core_proxy::update_blockchain(const std::vectorsecond; + res.tx_global_outs.resize(req.txids.size()); + size_t i = 0; + for (auto& txid : req.txids) + { + auto it = m_txs_outs.find(txid); + CHECK_AND_ASSERT_MES(it != m_txs_outs.end(), false, "tx " << txid << " was not found in tx global outout indexes"); + res.tx_global_outs[i].v = it->second; + i++; + } + res.status = API_RETURN_CODE_OK; return true; }