aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp77
-rw-r--r--src/version.cmake2
2 files changed, 21 insertions, 58 deletions
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index ab730d32e..8955072b5 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -65,45 +65,6 @@ inline void throw1(const T &e)
throw e;
}
-// cursor needs to be closed when it goes out of scope,
-// this helps if the function using it throws
-struct lmdb_cur
-{
- lmdb_cur(MDB_txn* txn, MDB_dbi dbi)
- {
- if (mdb_cursor_open(txn, dbi, &m_cur))
- throw0(cryptonote::DB_ERROR("Error opening db cursor"));
- done = false;
- }
-
- ~lmdb_cur()
- {
- close();
- }
-
- operator MDB_cursor*()
- {
- return m_cur;
- }
- operator MDB_cursor**()
- {
- return &m_cur;
- }
-
- void close()
- {
- if (!done)
- {
- mdb_cursor_close(m_cur);
- done = true;
- }
- }
-
-private:
- MDB_cursor* m_cur;
- bool done;
-};
-
template<typename T>
struct MDB_val_copy: public MDB_val
{
@@ -149,8 +110,14 @@ private:
int compare_uint64(const MDB_val *a, const MDB_val *b)
{
+#ifdef MISALIGNED_OK
const uint64_t va = *(const uint64_t*)a->mv_data;
const uint64_t vb = *(const uint64_t*)b->mv_data;
+#else
+ uint64_t va, vb;
+ memcpy(&va, a->mv_data, sizeof(uint64_t));
+ memcpy(&vb, b->mv_data, sizeof(uint64_t));
+#endif
if (va < vb) return -1;
else if (va == vb) return 0;
else return 1;
@@ -778,12 +745,12 @@ void BlockchainLMDB::remove_tx_outputs(const crypto::hash& tx_hash, const transa
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
- lmdb_cur cur(*m_write_txn, m_tx_outputs);
-
+ mdb_txn_cursors *m_cursors = &m_wcursors;
MDB_val_copy<crypto::hash> k(tx_hash);
MDB_val v;
+ CURSOR(tx_outputs)
- auto result = mdb_cursor_get(cur, &k, &v, MDB_SET);
+ auto result = mdb_cursor_get(m_cur_tx_outputs, &k, &v, MDB_SET);
if (result == MDB_NOTFOUND)
{
LOG_PRINT_L2("tx has no outputs, so no global output indices");
@@ -795,9 +762,9 @@ void BlockchainLMDB::remove_tx_outputs(const crypto::hash& tx_hash, const transa
else
{
mdb_size_t num_elems = 0;
- mdb_cursor_count(cur, &num_elems);
+ mdb_cursor_count(m_cur_tx_outputs, &num_elems);
- mdb_cursor_get(cur, &k, &v, MDB_LAST_DUP);
+ mdb_cursor_get(m_cur_tx_outputs, &k, &v, MDB_LAST_DUP);
for (uint64_t i = num_elems; i > 0; --i)
{
@@ -805,12 +772,10 @@ void BlockchainLMDB::remove_tx_outputs(const crypto::hash& tx_hash, const transa
remove_output(*(const uint64_t*)v.mv_data, tx_output.amount);
if (i > 1)
{
- mdb_cursor_get(cur, &k, &v, MDB_PREV_DUP);
+ mdb_cursor_get(m_cur_tx_outputs, &k, &v, MDB_PREV_DUP);
}
}
}
-
- cur.close();
}
// TODO: probably remove this function
@@ -866,29 +831,29 @@ void BlockchainLMDB::remove_amount_output_index(const uint64_t amount, const uin
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
-
- lmdb_cur cur(*m_write_txn, m_output_amounts);
+ mdb_txn_cursors *m_cursors = &m_wcursors;
+ CURSOR(output_amounts);
MDB_val_copy<uint64_t> k(amount);
MDB_val v;
- auto result = mdb_cursor_get(cur, &k, &v, MDB_SET);
+ auto result = mdb_cursor_get(m_cur_output_amounts, &k, &v, MDB_SET);
if (result == MDB_NOTFOUND)
throw1(OUTPUT_DNE("Attempting to get an output index by amount and amount index, but amount not found"));
else if (result)
throw0(DB_ERROR("DB error attempting to get an output"));
mdb_size_t num_elems = 0;
- mdb_cursor_count(cur, &num_elems);
+ mdb_cursor_count(m_cur_output_amounts, &num_elems);
- mdb_cursor_get(cur, &k, &v, MDB_LAST_DUP);
+ mdb_cursor_get(m_cur_output_amounts, &k, &v, MDB_LAST_DUP);
uint64_t amount_output_index = 0;
uint64_t goi = 0;
bool found_index = false;
for (uint64_t i = num_elems; i > 0; --i)
{
- mdb_cursor_get(cur, &k, &v, MDB_GET_CURRENT);
+ mdb_cursor_get(m_cur_output_amounts, &k, &v, MDB_GET_CURRENT);
goi = *(const uint64_t *)v.mv_data;
if (goi == global_output_index)
{
@@ -897,23 +862,21 @@ void BlockchainLMDB::remove_amount_output_index(const uint64_t amount, const uin
break;
}
if (i > 1)
- mdb_cursor_get(cur, &k, &v, MDB_PREV_DUP);
+ mdb_cursor_get(m_cur_output_amounts, &k, &v, MDB_PREV_DUP);
}
if (found_index)
{
// found the amount output index
// now delete it
- result = mdb_cursor_del(cur, 0);
+ result = mdb_cursor_del(m_cur_output_amounts, 0);
if (result)
throw0(DB_ERROR(std::string("Error deleting amount output index ").append(boost::lexical_cast<std::string>(amount_output_index)).c_str()));
}
else
{
// not found
- cur.close();
throw1(OUTPUT_DNE("Failed to find amount output index"));
}
- cur.close();
}
void BlockchainLMDB::add_spent_key(const crypto::key_image& k_image)
diff --git a/src/version.cmake b/src/version.cmake
index 4cbaa58e2..8c56b392c 100644
--- a/src/version.cmake
+++ b/src/version.cmake
@@ -72,7 +72,7 @@ else()
message(STATUS "You are building a tagged release")
set(VERSIONTAG "release")
else()
- message(STATUS "You are ahead or behind of a tagged release")
+ message(STATUS "You are ahead of or behind a tagged release")
set(VERSIONTAG "${COMMIT}")
endif()
endif()