aboutsummaryrefslogtreecommitdiff
path: root/src/blockchain_db/lmdb
diff options
context:
space:
mode:
authorwarptangent <warptangent@tutanota.com>2016-03-04 11:37:41 -0800
committerHoward Chu <hyc@symas.com>2016-04-05 20:54:06 +0100
commita2f518aa014163e63e39ce5e83a4f0d4d5be5c3f (patch)
treebeb3efd371fed289047a1a8804450a61b3b9b99b /src/blockchain_db/lmdb
parentSchema update: tx_indices - improve further with less indirection (diff)
downloadmonero-a2f518aa014163e63e39ce5e83a4f0d4d5be5c3f.tar.xz
Schema update: tx_indices - yet less indirection
Diffstat (limited to 'src/blockchain_db/lmdb')
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp23
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.h4
2 files changed, 11 insertions, 16 deletions
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index a07b257a9..a1ca2e716 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -616,20 +616,21 @@ void BlockchainLMDB::remove_block()
throw1(DB_ERROR("Failed to add removal of block info to db transaction"));
}
-void BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, const transaction& tx, const crypto::hash& tx_hash)
+uint64_t BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, const transaction& tx, const crypto::hash& tx_hash)
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
mdb_txn_cursors *m_cursors = &m_wcursors;
int result = 0;
+ uint64_t tx_index = m_num_txs;
CURSOR(txs)
CURSOR(tx_indices)
CURSOR(tx_heights)
CURSOR(tx_unlocks)
- MDB_val_copy<uint64_t> val_tx_index(m_num_txs);
+ MDB_val_copy<uint64_t> val_tx_index(tx_index);
MDB_val_copy<crypto::hash> val_h(tx_hash);
MDB_val unused;
result = mdb_cursor_get(m_cur_tx_indices, &val_h, &unused, MDB_SET);
@@ -658,6 +659,7 @@ void BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, const tr
throw0(DB_ERROR(lmdb_error("Failed to add tx unlock time to db transaction: ", result).c_str()));
m_num_txs++;
+ return tx_index;
}
// TODO: compare pros and cons of looking up the tx hash's tx index once and
@@ -761,7 +763,7 @@ void BlockchainLMDB::add_output(const crypto::hash& tx_hash,
m_num_outputs++;
}
-void BlockchainLMDB::add_amount_and_global_output_indices(const crypto::hash& tx_hash,
+void BlockchainLMDB::add_amount_and_global_output_indices(const uint64_t tx_index,
const std::vector<uint64_t>& amount_output_indices,
const std::vector<uint64_t>& global_output_indices)
{
@@ -772,8 +774,6 @@ void BlockchainLMDB::add_amount_and_global_output_indices(const crypto::hash& tx
int result = 0;
- MDB_val_copy<crypto::hash> k(tx_hash);
-
int num_outputs = amount_output_indices.size();
std::unique_ptr<uint64_t[]> paired_indices(new uint64_t[2*num_outputs]);
for (int i = 0; i < num_outputs; ++i)
@@ -782,17 +782,13 @@ void BlockchainLMDB::add_amount_and_global_output_indices(const crypto::hash& tx
paired_indices[2*i+1] = global_output_indices[i];
}
+ MDB_val_copy<uint64_t> k_tx_index(tx_index);
MDB_val v;
v.mv_data = (void*)paired_indices.get();
v.mv_size = sizeof(uint64_t) * 2 * num_outputs;
// LOG_PRINT_L1("tx_outputs[tx_hash] size: " << v.mv_size);
- MDB_val val_tx_index;
- result = mdb_cursor_get(m_cur_tx_indices, &k, &val_tx_index, MDB_SET);
- if (result)
- throw0(DB_ERROR(lmdb_error(std::string("Failed to get tx index for tx hash ") + epee::string_tools::pod_to_hex(tx_hash), result).c_str()));
-
- result = mdb_cursor_put(m_cur_tx_outputs, &val_tx_index, &v, 0);
+ result = mdb_cursor_put(m_cur_tx_outputs, &k_tx_index, &v, 0);
if (result)
throw0(DB_ERROR(std::string("Failed to add <tx hash, amount output index array> to db transaction: ").append(mdb_strerror(result)).c_str()));
}
@@ -1724,7 +1720,6 @@ bool BlockchainLMDB::tx_exists(const crypto::hash& h) const
throw0(DB_ERROR(std::string("transaction with hash ").append(epee::string_tools::pod_to_hex(h)).append(" not found at index").c_str()));
else if (get_result)
throw0(DB_ERROR(lmdb_error(std::string("DB error attempting to fetch transaction ") + epee::string_tools::pod_to_hex(h) + " at index: ", get_result).c_str()));
-
return true;
}
@@ -2009,10 +2004,10 @@ void BlockchainLMDB::get_amount_and_global_output_indices(const uint64_t tx_inde
RCURSOR(tx_outputs);
int result = 0;
- MDB_val_copy<uint64_t> val_tx_index(tx_index);
+ MDB_val_copy<uint64_t> k_tx_index(tx_index);
MDB_val v;
- result = mdb_cursor_get(m_cur_tx_outputs, &val_tx_index, &v, MDB_SET);
+ result = mdb_cursor_get(m_cur_tx_outputs, &k_tx_index, &v, MDB_SET);
if (result == MDB_NOTFOUND)
LOG_PRINT_L0("WARNING: Unexpected: tx has no amount and global indices stored in "
"tx_outputs, but it should have an empty entry even if it's a tx without "
diff --git a/src/blockchain_db/lmdb/db_lmdb.h b/src/blockchain_db/lmdb/db_lmdb.h
index ef47ea5f7..e60103712 100644
--- a/src/blockchain_db/lmdb/db_lmdb.h
+++ b/src/blockchain_db/lmdb/db_lmdb.h
@@ -289,7 +289,7 @@ private:
virtual void remove_block();
- virtual void add_transaction_data(const crypto::hash& blk_hash, const transaction& tx, const crypto::hash& tx_hash);
+ virtual uint64_t add_transaction_data(const crypto::hash& blk_hash, const transaction& tx, const crypto::hash& tx_hash);
virtual void remove_transaction_data(const crypto::hash& tx_hash, const transaction& tx);
@@ -301,7 +301,7 @@ private:
uint64_t& global_output_index
);
- virtual void add_amount_and_global_output_indices(const crypto::hash& tx_hash,
+ virtual void add_amount_and_global_output_indices(const uint64_t tx_index,
const std::vector<uint64_t>& amount_output_indices,
const std::vector<uint64_t>& global_output_indices
);