From 558cfc31caeb88398fe5bab9292246739586374d Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Wed, 22 Mar 2017 18:03:23 +0000 Subject: core, wallet: faster tx pool scanning Includes a new RPC to get tx pool hashes fast. --- src/cryptonote_core/tx_pool.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/cryptonote_core/tx_pool.cpp') diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index ea19b6b48..b2a7120cb 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -423,6 +423,13 @@ namespace cryptonote txs.push_back(tx_vt.second.tx); } //------------------------------------------------------------------ + void tx_memory_pool::get_transaction_hashes(std::vector& txs) const + { + CRITICAL_REGION_LOCAL(m_transactions_lock); + for(const auto& tx_vt: m_transactions) + txs.push_back(get_transaction_hash(tx_vt.second.tx)); + } + //------------------------------------------------------------------ //TODO: investigate whether boolean return is appropriate bool tx_memory_pool::get_transactions_and_spent_keys_info(std::vector& tx_infos, std::vector& key_image_infos) const { -- cgit v1.2.3 From aaeb164cf6fa5ff4c8631dd77e434c3259d6b14e Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Wed, 22 Mar 2017 20:21:54 +0000 Subject: tx_pool: remove transactions if they're in the blockchain When starting up, if the pool state was not saved, the pool might contain transactions which made it into the blockchain, so these need removing --- src/cryptonote_core/tx_pool.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/cryptonote_core/tx_pool.cpp') diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index b2a7120cb..93fe57232 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -717,8 +717,16 @@ namespace cryptonote size_t n_removed = 0; size_t tx_size_limit = get_transaction_size_limit(version); for (auto it = m_transactions.begin(); it != m_transactions.end(); ) { + bool remove = false; if (it->second.blob_size >= tx_size_limit) { - LOG_PRINT_L1("Transaction " << get_transaction_hash(it->second.tx) << " is too big (" << it->second.blob_size << " bytes), removing it from pool"); + LOG_PRINT_L1("Transaction " << it->first << " is too big (" << it->second.blob_size << " bytes), removing it from pool"); + remove = true; + } + else if (m_blockchain.have_tx(it->first)) { + LOG_PRINT_L1("Transaction " << it->first << " is in the blockchain, removing it from pool"); + remove = true; + } + if (remove) { remove_transaction_keyimages(it->second.tx); auto sorted_it = find_tx_in_sorted_container(it->first); if (sorted_it == m_txs_by_fee_and_receive_time.end()) -- cgit v1.2.3 From 91d410902399befd81589fd0153e5b7994bcdaa2 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Wed, 22 Mar 2017 20:26:56 +0000 Subject: tx_pool: ensure txes loaded from poolstate.bin have their txid cached The txid is not saved, and we want to make sure the transactions have their txid cached while in the pool, since get_transactions copies the transaction object, so any txid calculation on those copies would not benefit any later caller, since the original tx would be left without a cached txid. --- src/cryptonote_core/tx_pool.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/cryptonote_core/tx_pool.cpp') diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index 93fe57232..cde97b52f 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -718,20 +718,21 @@ namespace cryptonote size_t tx_size_limit = get_transaction_size_limit(version); for (auto it = m_transactions.begin(); it != m_transactions.end(); ) { bool remove = false; + const crypto::hash &txid = get_transaction_hash(it->second.tx); if (it->second.blob_size >= tx_size_limit) { - LOG_PRINT_L1("Transaction " << it->first << " is too big (" << it->second.blob_size << " bytes), removing it from pool"); + LOG_PRINT_L1("Transaction " << txid << " is too big (" << it->second.blob_size << " bytes), removing it from pool"); remove = true; } - else if (m_blockchain.have_tx(it->first)) { - LOG_PRINT_L1("Transaction " << it->first << " is in the blockchain, removing it from pool"); + else if (m_blockchain.have_tx(txid)) { + LOG_PRINT_L1("Transaction " << txid << " is in the blockchain, removing it from pool"); remove = true; } if (remove) { remove_transaction_keyimages(it->second.tx); - auto sorted_it = find_tx_in_sorted_container(it->first); + auto sorted_it = find_tx_in_sorted_container(txid); if (sorted_it == m_txs_by_fee_and_receive_time.end()) { - LOG_PRINT_L1("Removing tx " << it->first << " from tx pool, but it was not found in the sorted txs container!"); + LOG_PRINT_L1("Removing tx " << txid << " from tx pool, but it was not found in the sorted txs container!"); } else { -- cgit v1.2.3