1
0
Fork 0
forked from lthn/blockchain

fixed few bugs related to prefetch

This commit is contained in:
cryptozoidberg 2020-06-13 21:04:21 +02:00
parent 53bdb6417e
commit 0f98b6d990
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
4 changed files with 45 additions and 27 deletions

View file

@ -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<transaction_wallet_info> 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<uint64_t>& selected
{
transfer_details& td = m_transfers[*it_indices];
td.m_global_output_index = (*it_ooutputs)[td.m_internal_output_index];
it_ooutputs++; it_indices++;
}
}
//----------------------------------------------------------------------------------------------------

View file

@ -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<uint64_t, uint64_t>& 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;

View file

@ -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;
}
};

View file

@ -45,12 +45,18 @@ bool wallet_test_core_proxy::update_blockchain(const std::vector<test_event_entr
return true;
}
bool wallet_test_core_proxy::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)
bool wallet_test_core_proxy::call_COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES(const currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request& req, currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response& res)
{
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.status = API_RETURN_CODE_OK;
rsp.o_indexes = it->second;
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;
}