aboutsummaryrefslogtreecommitdiff
path: root/src/blockchain_db/lmdb
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-11-11 13:39:00 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-03-05 10:28:52 +0000
commite69477bf25630c94a5aff666433f3da9ab29298c (patch)
tree49ae5707c4ee4850e546fd7ae2da020489bc3795 /src/blockchain_db/lmdb
parentMerge pull request #5101 (diff)
downloadmonero-e69477bf25630c94a5aff666433f3da9ab29298c.tar.xz
db: speedup block addition
by avoiding repeated (de)serialization
Diffstat (limited to 'src/blockchain_db/lmdb')
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index 9d2f7821e..376170a6b 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -865,21 +865,26 @@ uint64_t BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, cons
cryptonote::blobdata blob = tx_to_blob(tx);
MDB_val_sized(blobval, blob);
- std::stringstream ss;
- binary_archive<true> ba(ss);
- bool r = const_cast<cryptonote::transaction&>(tx).serialize_base(ba);
- if (!r)
- throw0(DB_ERROR("Failed to serialize pruned tx"));
- std::string pruned = ss.str();
- MDB_val_sized(pruned_blob, pruned);
+ unsigned int unprunable_size = tx.unprunable_size;
+ if (unprunable_size == 0)
+ {
+ std::stringstream ss;
+ binary_archive<true> ba(ss);
+ bool r = const_cast<cryptonote::transaction&>(tx).serialize_base(ba);
+ if (!r)
+ throw0(DB_ERROR("Failed to serialize pruned tx"));
+ unprunable_size = ss.str().size();
+ }
+
+ if (unprunable_size > blob.size())
+ throw0(DB_ERROR("pruned tx size is larger than tx size"));
+
+ MDB_val pruned_blob = {unprunable_size, (void*)blob.data()};
result = mdb_cursor_put(m_cur_txs_pruned, &val_tx_id, &pruned_blob, MDB_APPEND);
if (result)
throw0(DB_ERROR(lmdb_error("Failed to add pruned tx blob to db transaction: ", result).c_str()));
- if (pruned.size() > blob.size())
- throw0(DB_ERROR("pruned tx size is larger than tx size"));
- cryptonote::blobdata prunable(blob.data() + pruned.size(), blob.size() - pruned.size());
- MDB_val_sized(prunable_blob, prunable);
+ MDB_val prunable_blob = {blob.size() - unprunable_size, (void*)(blob.data() + unprunable_size)};
result = mdb_cursor_put(m_cur_txs_prunable, &val_tx_id, &prunable_blob, MDB_APPEND);
if (result)
throw0(DB_ERROR(lmdb_error("Failed to add prunable tx blob to db transaction: ", result).c_str()));