From 4e9069014644c39b298b14899e180a35968decd2 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Sat, 14 Mar 2020 14:16:50 +0800 Subject: [PATCH] Fix for Failed to get tx meta from txpool https://github.com/moneroexamples/openmonero/issues/169 --- html/js/config.js | 2 +- src/CurrentBlockchainStatus.cpp | 63 ++++++++++++++------------------- src/xmregcore | 2 +- 3 files changed, 28 insertions(+), 39 deletions(-) diff --git a/html/js/config.js b/html/js/config.js index 5070a4b..784a9c3 100755 --- a/html/js/config.js +++ b/html/js/config.js @@ -3,7 +3,7 @@ var config = { mainnetExplorerUrl: "https://xmrchain.com/", testnetExplorerUrl: "https://testnet.xmrchain.com/", stagenetExplorerUrl: "http://139.162.60.17:8082/", - nettype: 0, /* 0 - MAINNET, 1 - TESTNET, 2 - STAGENET */ + nettype: 2, /* 0 - MAINNET, 1 - TESTNET, 2 - STAGENET */ coinUnitPlaces: 12, txMinConfirms: 10, // corresponds to CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE in Monero txCoinbaseMinConfirms: 60, // corresponds to CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW in Monero diff --git a/src/CurrentBlockchainStatus.cpp b/src/CurrentBlockchainStatus.cpp index c3d3116..cede36c 100755 --- a/src/CurrentBlockchainStatus.cpp +++ b/src/CurrentBlockchainStatus.cpp @@ -590,62 +590,51 @@ bool CurrentBlockchainStatus::read_mempool() { // get txs in the mempool - std::vector mempool_tx_info; - vector key_image_infos; + + mempool_txs_t local_mempool_txs; auto future_result = thread_pool->submit( - [this](auto& mempool_tx_info, auto& key_image_infos) + [this](auto& local_mempool_txs) -> bool { - if (!this->mcore->get_mempool_txs( - mempool_tx_info, key_image_infos)) + + std::vector txs; + + if (!this->mcore->get_mempool_txs(txs)) { OMERROR << "Getting mempool failed "; return false; } - return true; - - }, std::ref(mempool_tx_info), - std::ref(key_image_infos)); - if (!future_result.get()) - return false; + for (size_t i = 0; i < txs.size(); ++i) + { + // get transaction info of the tx in the mempool + auto const& tx = txs.at(i); - // not using this info at present - (void) key_image_infos; + tx_memory_pool::tx_details txd; - std::lock_guard lck (getting_mempool_txs); + txpool_tx_meta_t meta; - // clear current mempool txs vector - // repopulate it with each execution of read_mempool() - // not very efficient but good enough for now. - mempool_txs.clear(); + if (!this->mcore->get_core().get_txpool_tx_meta(tx.hash, meta)) + { + OMERROR << "Failed to find tx in txpool"; + return false; + } - // if dont have tx_blob member, construct tx - // from json obtained from the rpc call + local_mempool_txs.emplace_back(meta.receive_time, tx); - for (size_t i = 0; i < mempool_tx_info.size(); ++i) - { - // get transaction info of the tx in the mempool - tx_info const& _tx_info = mempool_tx_info.at(i); + } // for (size_t i = 0; i < mempool_tx_info.size(); ++i) - transaction tx; - crypto::hash tx_hash; - crypto::hash tx_prefix_hash; + return true; - if (!parse_and_validate_tx_from_blob( - _tx_info.tx_blob, tx, tx_hash, tx_prefix_hash)) - { - OMERROR << "Cant make tx from _tx_info.tx_blob"; - return false; - } + }, std::ref(local_mempool_txs)); - (void) tx_hash; - (void) tx_prefix_hash; + if (!future_result.get()) + return false; - mempool_txs.emplace_back(_tx_info.receive_time, tx); + std::lock_guard lck (getting_mempool_txs); - } // for (size_t i = 0; i < mempool_tx_info.size(); ++i) + mempool_txs = std::move(local_mempool_txs); return true; } diff --git a/src/xmregcore b/src/xmregcore index 4a330c6..6e0c9e4 160000 --- a/src/xmregcore +++ b/src/xmregcore @@ -1 +1 @@ -Subproject commit 4a330c66a907df69d6bbd581684d6d05b43aeda5 +Subproject commit 6e0c9e4b9fa1d2ce1182e61290ff5190608c8b6a