aboutsummaryrefslogtreecommitdiff
path: root/src/blockchain_db/lmdb
diff options
context:
space:
mode:
authorAlexander Blair <snipa@jagtech.io>2020-01-25 16:55:18 -0800
committerAlexander Blair <snipa@jagtech.io>2020-01-25 16:55:18 -0800
commit8eedc8a390c73112af9fff712a47c2c1814bc16a (patch)
treeab8cf897aaeb94c7ad18fd7e8336009c354640d4 /src/blockchain_db/lmdb
parentMerge pull request #6170 (diff)
parentblockchain: speedup fetching pruned contiguous tx blobs (diff)
downloadmonero-8eedc8a390c73112af9fff712a47c2c1814bc16a.tar.xz
Merge pull request #6140
08635a08 blockchain: speedup fetching pruned contiguous tx blobs (moneromooo-monero)
Diffstat (limited to 'src/blockchain_db/lmdb')
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp42
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.h1
2 files changed, 43 insertions, 0 deletions
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index 6eb5501b7..5093015f2 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -3065,6 +3065,48 @@ bool BlockchainLMDB::get_pruned_tx_blob(const crypto::hash& h, cryptonote::blobd
return true;
}
+bool BlockchainLMDB::get_pruned_tx_blobs_from(const crypto::hash& h, size_t count, std::vector<cryptonote::blobdata> &bd) const
+{
+ LOG_PRINT_L3("BlockchainLMDB::" << __func__);
+ check_open();
+
+ if (!count)
+ return true;
+
+ TXN_PREFIX_RDONLY();
+ RCURSOR(tx_indices);
+ RCURSOR(txs_pruned);
+
+ bd.reserve(bd.size() + count);
+
+ MDB_val_set(v, h);
+ MDB_val result;
+ int res = mdb_cursor_get(m_cur_tx_indices, (MDB_val *)&zerokval, &v, MDB_GET_BOTH);
+ if (res == MDB_NOTFOUND)
+ return false;
+ if (res)
+ throw0(DB_ERROR(lmdb_error("DB error attempting to fetch tx from hash", res).c_str()));
+
+ const txindex *tip = (const txindex *)v.mv_data;
+ const uint64_t id = tip->data.tx_id;
+ MDB_val_set(val_tx_id, id);
+ MDB_cursor_op op = MDB_SET;
+ while (count--)
+ {
+ res = mdb_cursor_get(m_cur_txs_pruned, &val_tx_id, &result, op);
+ op = MDB_NEXT;
+ if (res == MDB_NOTFOUND)
+ return false;
+ if (res)
+ throw0(DB_ERROR(lmdb_error("DB error attempting to fetch tx blob", res).c_str()));
+ bd.emplace_back(reinterpret_cast<char*>(result.mv_data), result.mv_size);
+ }
+
+ TXN_POSTFIX_RDONLY();
+
+ return true;
+}
+
bool BlockchainLMDB::get_prunable_tx_blob(const crypto::hash& h, cryptonote::blobdata &bd) const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
diff --git a/src/blockchain_db/lmdb/db_lmdb.h b/src/blockchain_db/lmdb/db_lmdb.h
index e56711e8f..7c0b4c72c 100644
--- a/src/blockchain_db/lmdb/db_lmdb.h
+++ b/src/blockchain_db/lmdb/db_lmdb.h
@@ -254,6 +254,7 @@ public:
virtual bool get_tx_blob(const crypto::hash& h, cryptonote::blobdata &tx) const;
virtual bool get_pruned_tx_blob(const crypto::hash& h, cryptonote::blobdata &tx) const;
+ virtual bool get_pruned_tx_blobs_from(const crypto::hash& h, size_t count, std::vector<cryptonote::blobdata> &bd) const;
virtual bool get_prunable_tx_blob(const crypto::hash& h, cryptonote::blobdata &tx) const;
virtual bool get_prunable_tx_hash(const crypto::hash& tx_hash, crypto::hash &prunable_hash) const;