aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cryptonote_core/BlockchainDB_impl/db_lmdb.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/cryptonote_core/BlockchainDB_impl/db_lmdb.cpp b/src/cryptonote_core/BlockchainDB_impl/db_lmdb.cpp
index 25c25f399..4e9f6cb28 100644
--- a/src/cryptonote_core/BlockchainDB_impl/db_lmdb.cpp
+++ b/src/cryptonote_core/BlockchainDB_impl/db_lmdb.cpp
@@ -1132,20 +1132,23 @@ bool BlockchainLMDB::tx_exists(const crypto::hash& h) const
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
+ txn_safe txn;
+ txn_safe* txn_ptr = &txn;
if (m_batch_active)
+ txn_ptr = m_write_txn;
+ else
{
- LOG_PRINT_L0("WARNING: active batch transaction while creating a read-only txn in tx_exists()");
+ if (mdb_txn_begin(m_env, NULL, MDB_RDONLY, txn))
+ throw0(DB_ERROR("Failed to create a transaction for the db"));
}
- txn_safe txn;
- if (mdb_txn_begin(m_env, NULL, MDB_RDONLY, txn))
- throw0(DB_ERROR("Failed to create a transaction for the db"));
MDB_val_copy<crypto::hash> key(h);
MDB_val result;
- auto get_result = mdb_get(txn, m_txs, &key, &result);
+ auto get_result = mdb_get(*txn_ptr, m_txs, &key, &result);
if (get_result == MDB_NOTFOUND)
{
- txn.commit();
+ if (! m_batch_active)
+ txn.commit();
LOG_PRINT_L1("transaction with hash " << epee::string_tools::pod_to_hex(h) << " not found in db");
return false;
}