aboutsummaryrefslogtreecommitdiff
path: root/src/blockchain_db/lmdb/db_lmdb.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/blockchain_db/lmdb/db_lmdb.cpp')
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp90
1 files changed, 36 insertions, 54 deletions
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index 4bfc80863..833d6bd05 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -456,6 +456,12 @@ inline int lmdb_txn_renew(MDB_txn *txn)
return res;
}
+inline void BlockchainLMDB::check_open() const
+{
+ if (!m_open)
+ throw0(DB_ERROR("DB operation attempted on a not-open DB instance"));
+}
+
void BlockchainLMDB::do_resize(uint64_t increase_size)
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
@@ -1019,7 +1025,8 @@ void BlockchainLMDB::remove_tx_outputs(const uint64_t tx_id, const transaction&
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
- std::vector<uint64_t> amount_output_indices = get_tx_amount_output_indices(tx_id);
+ std::vector<std::vector<uint64_t>> amount_output_indices_set = get_tx_amount_output_indices(tx_id, 1);
+ const std::vector<uint64_t> &amount_output_indices = amount_output_indices_set.front();
if (amount_output_indices.empty())
{
@@ -1166,36 +1173,6 @@ void BlockchainLMDB::remove_spent_key(const crypto::key_image& k_image)
}
}
-blobdata BlockchainLMDB::output_to_blob(const tx_out& output) const
-{
- LOG_PRINT_L3("BlockchainLMDB::" << __func__);
- blobdata b;
- if (!t_serializable_object_to_blob(output, b))
- throw1(DB_ERROR("Error serializing output to blob"));
- return b;
-}
-
-tx_out BlockchainLMDB::output_from_blob(const blobdata& blob) const
-{
- LOG_PRINT_L3("BlockchainLMDB::" << __func__);
- std::stringstream ss;
- ss << blob;
- binary_archive<false> ba(ss);
- tx_out o;
-
- if (!(::serialization::serialize(ba, o)))
- throw1(DB_ERROR("Error deserializing tx output blob"));
-
- return o;
-}
-
-void BlockchainLMDB::check_open() const
-{
-// LOG_PRINT_L3("BlockchainLMDB::" << __func__);
- if (!m_open)
- throw0(DB_ERROR("DB operation attempted on a not-open DB instance"));
-}
-
BlockchainLMDB::~BlockchainLMDB()
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
@@ -2559,7 +2536,7 @@ uint64_t BlockchainLMDB::get_num_outputs(const uint64_t& amount) const
return num_elems;
}
-output_data_t BlockchainLMDB::get_output_key(const uint64_t& amount, const uint64_t& index)
+output_data_t BlockchainLMDB::get_output_key(const uint64_t& amount, const uint64_t& index) const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
@@ -2628,7 +2605,7 @@ tx_out_index BlockchainLMDB::get_output_tx_and_index(const uint64_t& amount, con
return indices[0];
}
-std::vector<uint64_t> BlockchainLMDB::get_tx_amount_output_indices(const uint64_t tx_id) const
+std::vector<std::vector<uint64_t>> BlockchainLMDB::get_tx_amount_output_indices(uint64_t tx_id, size_t n_txes) const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
@@ -2637,35 +2614,40 @@ std::vector<uint64_t> BlockchainLMDB::get_tx_amount_output_indices(const uint64_
TXN_PREFIX_RDONLY();
RCURSOR(tx_outputs);
- int result = 0;
MDB_val_set(k_tx_id, tx_id);
MDB_val v;
- std::vector<uint64_t> amount_output_indices;
+ std::vector<std::vector<uint64_t>> amount_output_indices_set;
+ amount_output_indices_set.reserve(n_txes);
- result = mdb_cursor_get(m_cur_tx_outputs, &k_tx_id, &v, MDB_SET);
- if (result == MDB_NOTFOUND)
- LOG_PRINT_L0("WARNING: Unexpected: tx has no amount indices stored in "
- "tx_outputs, but it should have an empty entry even if it's a tx without "
- "outputs");
- else if (result)
- throw0(DB_ERROR(lmdb_error("DB error attempting to get data for tx_outputs[tx_index]", result).c_str()));
+ MDB_cursor_op op = MDB_SET;
+ while (n_txes-- > 0)
+ {
+ int result = mdb_cursor_get(m_cur_tx_outputs, &k_tx_id, &v, op);
+ if (result == MDB_NOTFOUND)
+ LOG_PRINT_L0("WARNING: Unexpected: tx has no amount indices stored in "
+ "tx_outputs, but it should have an empty entry even if it's a tx without "
+ "outputs");
+ else if (result)
+ throw0(DB_ERROR(lmdb_error("DB error attempting to get data for tx_outputs[tx_index]", result).c_str()));
- const uint64_t* indices = (const uint64_t*)v.mv_data;
- int num_outputs = v.mv_size / sizeof(uint64_t);
+ op = MDB_NEXT;
- amount_output_indices.reserve(num_outputs);
- for (int i = 0; i < num_outputs; ++i)
- {
- // LOG_PRINT_L0("amount output index[" << 2*i << "]" << ": " << paired_indices[2*i] << " global output index: " << paired_indices[2*i+1]);
- amount_output_indices.push_back(indices[i]);
+ const uint64_t* indices = (const uint64_t*)v.mv_data;
+ size_t num_outputs = v.mv_size / sizeof(uint64_t);
+
+ amount_output_indices_set.resize(amount_output_indices_set.size() + 1);
+ std::vector<uint64_t> &amount_output_indices = amount_output_indices_set.back();
+ amount_output_indices.reserve(num_outputs);
+ for (size_t i = 0; i < num_outputs; ++i)
+ {
+ amount_output_indices.push_back(indices[i]);
+ }
}
- indices = nullptr;
TXN_POSTFIX_RDONLY();
- return amount_output_indices;
+ return amount_output_indices_set;
}
-
bool BlockchainLMDB::has_key_image(const crypto::key_image& img) const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
@@ -3192,7 +3174,7 @@ uint64_t BlockchainLMDB::add_block(const block& blk, size_t block_weight, const
check_open();
uint64_t m_height = height();
- if (m_height % 1000 == 0)
+ if (m_height % 1024 == 0)
{
// for batch mode, DB resize check is done at start of batch transaction
if (! m_batch_active && need_resize())
@@ -3266,7 +3248,7 @@ void BlockchainLMDB::get_output_tx_and_index_from_global(const std::vector<uint6
TXN_POSTFIX_RDONLY();
}
-void BlockchainLMDB::get_output_key(const epee::span<const uint64_t> &amounts, const std::vector<uint64_t> &offsets, std::vector<output_data_t> &outputs, bool allow_partial)
+void BlockchainLMDB::get_output_key(const epee::span<const uint64_t> &amounts, const std::vector<uint64_t> &offsets, std::vector<output_data_t> &outputs, bool allow_partial) const
{
if (amounts.size() != 1 && amounts.size() != offsets.size())
throw0(DB_ERROR("Invalid sizes of amounts and offets"));