aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorwarptangent <warptangent@tutanota.com>2016-02-08 08:32:36 -0800
committerwarptangent <warptangent@tutanota.com>2016-02-08 09:28:15 -0800
commitfd46c96dce043cbf9f018f59ac9cedb12f6a4286 (patch)
treea52d21a9cc54ec03c2950b1db4505ce60ad6ebc7 /src
parentBlockchainDB/LMDB/BDB: Extract DB txn functions for block add/remove (diff)
downloadmonero-fd46c96dce043cbf9f018f59ac9cedb12f6a4286.tar.xz
BlockchainDB/LMDB: Refactor block-scope DB txn handling for add block
Move block-scope txn start and stop from BlockchainLMDB to BlockchainDB.
Diffstat (limited to 'src')
-rw-r--r--src/blockchain_db/blockchain_db.cpp10
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp20
2 files changed, 10 insertions, 20 deletions
diff --git a/src/blockchain_db/blockchain_db.cpp b/src/blockchain_db/blockchain_db.cpp
index 3737dfc4f..b504f946a 100644
--- a/src/blockchain_db/blockchain_db.cpp
+++ b/src/blockchain_db/blockchain_db.cpp
@@ -99,6 +99,8 @@ uint64_t BlockchainDB::add_block( const block& blk
, const std::vector<transaction>& txs
)
{
+ block_txn_start();
+
TIME_MEASURE_START(time1);
crypto::hash blk_hash = get_block_hash(blk);
TIME_MEASURE_FINISH(time1);
@@ -125,9 +127,15 @@ uint64_t BlockchainDB::add_block( const block& blk
TIME_MEASURE_FINISH(time1);
time_add_transaction += time1;
+ // DB's new height based on this added block is only incremented after this
+ // function returns, so height() here returns the new previous height.
+ uint64_t prev_height = height();
+
+ block_txn_stop();
+
++num_calls;
- return height();
+ return prev_height;
}
void BlockchainDB::pop_block(block& blk, std::vector<transaction>& txs)
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index de82357b6..8bd64e70d 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -2244,33 +2244,15 @@ uint64_t BlockchainLMDB::add_block(const block& blk, const size_t& block_size, c
}
}
- mdb_txn_safe txn;
- if (! m_batch_active)
- {
- if (auto mdb_res = mdb_txn_begin(m_env, NULL, 0, txn))
- throw0(DB_ERROR(lmdb_error("Failed to create a transaction for the db: ", mdb_res).c_str()));
- m_write_txn = &txn;
- }
-
uint64_t num_outputs = m_num_outputs;
try
{
BlockchainDB::add_block(blk, block_size, cumulative_difficulty, coins_generated, txs);
- if (! m_batch_active)
- {
- m_write_txn = NULL;
-
- TIME_MEASURE_START(time1);
- txn.commit();
- TIME_MEASURE_FINISH(time1);
- time_commit1 += time1;
- }
}
catch (...)
{
m_num_outputs = num_outputs;
- if (! m_batch_active)
- m_write_txn = NULL;
+ block_txn_abort();
throw;
}