From 235df7f4848fb597739c50e3a31007ae77f008f1 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 11 Jun 2017 15:10:18 +0100 Subject: blockchain_db: add a txpool tx getter which returns existence Avoids exception spam for the "nope, not found" case --- src/blockchain_db/blockchain_db.h | 10 ++++++++++ src/blockchain_db/lmdb/db_lmdb.cpp | 15 ++++++++++++--- src/blockchain_db/lmdb/db_lmdb.h | 1 + 3 files changed, 23 insertions(+), 3 deletions(-) (limited to 'src/blockchain_db') 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 @@ -1313,6 +1313,16 @@ public: */ virtual txpool_tx_meta_t get_txpool_tx_meta(const crypto::hash& txid) const = 0; + /** + * @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 * 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(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 f, bool include_blob = false) const; -- cgit v1.2.3