aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2017-06-18 17:36:12 +0200
committerRiccardo Spagni <ric@spagni.net>2017-06-18 17:36:12 +0200
commit78f965a9e23145f0e1f3abb422cbd4ea24654cd8 (patch)
tree81ff2d7b170da4620138fdea89ccae17632c2aea
parentMerge pull request #2081 (diff)
parentblockchain_db: add a txpool tx getter which returns existence (diff)
downloadmonero-78f965a9e23145f0e1f3abb422cbd4ea24654cd8.tar.xz
Merge pull request #2082
235df7f4 blockchain_db: add a txpool tx getter which returns existence (moneromooo-monero)
-rw-r--r--src/blockchain_db/blockchain_db.h10
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp15
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.h1
-rw-r--r--src/cryptonote_core/blockchain.cpp5
-rw-r--r--src/cryptonote_core/blockchain.h1
-rw-r--r--src/cryptonote_core/tx_pool.cpp3
-rw-r--r--tests/unit_tests/hardfork.cpp1
7 files changed, 31 insertions, 5 deletions
diff --git a/src/blockchain_db/blockchain_db.h b/src/blockchain_db/blockchain_db.h
index b0a3d84e1..27e63801d 100644
--- a/src/blockchain_db/blockchain_db.h
+++ b/src/blockchain_db/blockchain_db.h
@@ -1317,6 +1317,16 @@ public:
* @brief get a txpool transaction's blob
*
* @param txid the transaction id of the transation to lookup
+ * @param bd the blob to return
+ *
+ * @return true if the txid was in the txpool, false otherwise
+ */
+ virtual bool get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const = 0;
+
+ /**
+ * @brief get a txpool transaction's blob
+ *
+ * @param txid the transaction id of the transation to lookup
*
* @return the blob for that transaction
*/
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index d7947c8d0..6bb96d1db 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -1576,7 +1576,7 @@ txpool_tx_meta_t BlockchainLMDB::get_txpool_tx_meta(const crypto::hash& txid) co
return meta;
}
-cryptonote::blobdata BlockchainLMDB::get_txpool_tx_blob(const crypto::hash& txid) const
+bool BlockchainLMDB::get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
@@ -1587,12 +1587,21 @@ cryptonote::blobdata BlockchainLMDB::get_txpool_tx_blob(const crypto::hash& txid
MDB_val k = {sizeof(txid), (void *)&txid};
MDB_val v;
auto result = mdb_cursor_get(m_cur_txpool_blob, &k, &v, MDB_SET);
+ if (result == MDB_NOTFOUND)
+ return false;
if (result != 0)
- throw1(DB_ERROR(lmdb_error("Error finding txpool tx meta: ", result).c_str()));
+ throw1(DB_ERROR(lmdb_error("Error finding txpool tx blob: ", result).c_str()));
- blobdata bd;
bd.assign(reinterpret_cast<const char*>(v.mv_data), v.mv_size);
TXN_POSTFIX_RDONLY();
+ return true;
+}
+
+cryptonote::blobdata BlockchainLMDB::get_txpool_tx_blob(const crypto::hash& txid) const
+{
+ cryptonote::blobdata bd;
+ if (!get_txpool_tx_blob(txid, bd))
+ throw1(DB_ERROR("Tx not found in txpool: "));
return bd;
}
diff --git a/src/blockchain_db/lmdb/db_lmdb.h b/src/blockchain_db/lmdb/db_lmdb.h
index 540fababb..14e5d34e2 100644
--- a/src/blockchain_db/lmdb/db_lmdb.h
+++ b/src/blockchain_db/lmdb/db_lmdb.h
@@ -245,6 +245,7 @@ public:
virtual bool txpool_has_tx(const crypto::hash &txid) const;
virtual void remove_txpool_tx(const crypto::hash& txid);
virtual txpool_tx_meta_t get_txpool_tx_meta(const crypto::hash& txid) const;
+ virtual bool get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const;
virtual cryptonote::blobdata get_txpool_tx_blob(const crypto::hash& txid) const;
virtual bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const txpool_tx_meta_t&, const cryptonote::blobdata*)> f, bool include_blob = false) const;
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 6f2977c5b..745608b9f 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -4005,6 +4005,11 @@ txpool_tx_meta_t Blockchain::get_txpool_tx_meta(const crypto::hash& txid) const
return m_db->get_txpool_tx_meta(txid);
}
+bool Blockchain::get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const
+{
+ return m_db->get_txpool_tx_blob(txid, bd);
+}
+
cryptonote::blobdata Blockchain::get_txpool_tx_blob(const crypto::hash& txid) const
{
return m_db->get_txpool_tx_blob(txid);
diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h
index 52172012c..56373adf9 100644
--- a/src/cryptonote_core/blockchain.h
+++ b/src/cryptonote_core/blockchain.h
@@ -862,6 +862,7 @@ namespace cryptonote
void remove_txpool_tx(const crypto::hash &txid);
uint64_t get_txpool_tx_count() const;
txpool_tx_meta_t get_txpool_tx_meta(const crypto::hash& txid) const;
+ bool get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const;
cryptonote::blobdata get_txpool_tx_blob(const crypto::hash& txid) const;
bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const txpool_tx_meta_t&, const cryptonote::blobdata*)>, bool include_blob = false) const;
diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp
index 589162a3e..ffb5b478b 100644
--- a/src/cryptonote_core/tx_pool.cpp
+++ b/src/cryptonote_core/tx_pool.cpp
@@ -673,8 +673,7 @@ namespace cryptonote
CRITICAL_REGION_LOCAL1(m_blockchain);
try
{
- txblob = m_blockchain.get_txpool_tx_blob(id);
- return true;
+ return m_blockchain.get_txpool_tx_blob(id, txblob);
}
catch (const std::exception &e)
{
diff --git a/tests/unit_tests/hardfork.cpp b/tests/unit_tests/hardfork.cpp
index 4bfe90733..febf8b2f7 100644
--- a/tests/unit_tests/hardfork.cpp
+++ b/tests/unit_tests/hardfork.cpp
@@ -118,6 +118,7 @@ public:
virtual bool txpool_has_tx(const crypto::hash &txid) const { return false; }
virtual void remove_txpool_tx(const crypto::hash& txid) {}
virtual txpool_tx_meta_t get_txpool_tx_meta(const crypto::hash& txid) const { return txpool_tx_meta_t(); }
+ virtual bool get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const { return false; }
virtual cryptonote::blobdata get_txpool_tx_blob(const crypto::hash& txid) const { return ""; }
virtual bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const txpool_tx_meta_t&, const cryptonote::blobdata*)>, bool include_blob = false) const { return false; }