aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp8
-rw-r--r--src/cryptonote_core/cryptonote_core.h7
-rw-r--r--src/cryptonote_core/cryptonote_tx_utils.cpp6
-rw-r--r--src/cryptonote_core/tx_pool.cpp22
-rw-r--r--src/cryptonote_core/tx_pool.h7
5 files changed, 46 insertions, 4 deletions
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 1b20776a5..4d4b9d4d2 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -1036,7 +1036,13 @@ namespace cryptonote
m_mempool.get_transactions(txs);
return true;
}
- //-----------------------------------------------------------------------------------------------
+ //-----------------------------------------------------------------------------------------------
+ bool core::get_pool_transaction_hashes(std::vector<crypto::hash>& txs) const
+ {
+ m_mempool.get_transaction_hashes(txs);
+ return true;
+ }
+ //-----------------------------------------------------------------------------------------------
bool core::get_pool_transaction(const crypto::hash &id, transaction& tx) const
{
return m_mempool.get_transaction(id, tx);
diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h
index 02d58691d..24b0f0614 100644
--- a/src/cryptonote_core/cryptonote_core.h
+++ b/src/cryptonote_core/cryptonote_core.h
@@ -397,6 +397,13 @@ namespace cryptonote
bool get_pool_transactions(std::list<transaction>& txs) const;
/**
+ * @copydoc tx_memory_pool::get_transactions
+ *
+ * @note see tx_memory_pool::get_transactions
+ */
+ bool get_pool_transaction_hashes(std::vector<crypto::hash>& txs) const;
+
+ /**
* @copydoc tx_memory_pool::get_transaction
*
* @note see tx_memory_pool::get_transaction
diff --git a/src/cryptonote_core/cryptonote_tx_utils.cpp b/src/cryptonote_core/cryptonote_tx_utils.cpp
index 672a763fc..47211ff95 100644
--- a/src/cryptonote_core/cryptonote_tx_utils.cpp
+++ b/src/cryptonote_core/cryptonote_tx_utils.cpp
@@ -132,6 +132,9 @@ namespace cryptonote
//lock
tx.unlock_time = height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW;
tx.vin.push_back(in);
+
+ tx.hash_valid = tx.blob_size_valid = false;
+
//LOG_PRINT("MINER_TX generated ok, block_reward=" << print_money(block_reward) << "(" << print_money(block_reward - fee) << "+" << print_money(fee)
// << "), current_block_size=" << current_block_size << ", already_generated_coins=" << already_generated_coins << ", tx_id=" << get_transaction_hash(tx), LOG_LEVEL_2);
return true;
@@ -451,6 +454,8 @@ namespace cryptonote
MCINFO("construct_tx", "transaction_created: " << get_transaction_hash(tx) << ENDL << obj_to_json_str(tx) << ENDL);
}
+ tx.hash_valid = tx.blob_size_valid = false;
+
return true;
}
//---------------------------------------------------------------
@@ -487,6 +492,7 @@ namespace cryptonote
bl.timestamp = 0;
bl.nonce = nonce;
miner::find_nonce_for_given_block(bl, 1, 0);
+ bl.hash_valid = false;
return true;
}
//---------------------------------------------------------------
diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp
index 810d76c48..da5e6636a 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<crypto::hash>& 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_info>& tx_infos, std::vector<spent_key_image_info>& key_image_infos) const
{
@@ -710,13 +717,22 @@ 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;
+ const crypto::hash &txid = get_transaction_hash(it->second.tx);
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 " << txid << " is too big (" << it->second.blob_size << " bytes), removing it from pool");
+ remove = true;
+ }
+ 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
{
diff --git a/src/cryptonote_core/tx_pool.h b/src/cryptonote_core/tx_pool.h
index d71032943..d19f83b2e 100644
--- a/src/cryptonote_core/tx_pool.h
+++ b/src/cryptonote_core/tx_pool.h
@@ -234,6 +234,13 @@ namespace cryptonote
void get_transactions(std::list<transaction>& txs) const;
/**
+ * @brief get a list of all transaction hashes in the pool
+ *
+ * @param txs return-by-reference the list of transactions
+ */
+ void get_transaction_hashes(std::vector<crypto::hash>& txs) const;
+
+ /**
* @brief get information about all transactions and key images in the pool
*
* see documentation on tx_info and spent_key_image_info for more details