aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core/blockchain_db.cpp
diff options
context:
space:
mode:
authorThomas Winget <tewinget@gmail.com>2015-02-23 18:24:59 -0500
committerThomas Winget <tewinget@gmail.com>2015-02-23 18:24:59 -0500
commitb5796da0fa67269ed218cdd14ef9f3b548fd6507 (patch)
treea64104230bd0d8ddfac59d119de7fd36dc4f48e6 /src/cryptonote_core/blockchain_db.cpp
parentb7d112f601b9e6901c1785e378a72e5e6f866b1b (diff)
parent6485dacc2fcaab7eb6db63c46716ffdfa0c568c4 (diff)
downloadmonzero-core-b5796da0fa67269ed218cdd14ef9f3b548fd6507.tar.gz
monzero-core-b5796da0fa67269ed218cdd14ef9f3b548fd6507.tar.xz
monzero-core-b5796da0fa67269ed218cdd14ef9f3b548fd6507.zip
Merge #32
Add support to BlockchainDB and BlockchainLMDB for batch transactions. Add profiling to block and tx processing and DB operations. Improve block and tx processing efficiency by less repeat hashing. Move LMDB storage to "lmdb" subfolder. - Upon startup, if old LMDB files are detected, abort with a message for the user to move them to subfolder or delete them. Update and fix log statements and formatting.
Diffstat (limited to 'src/cryptonote_core/blockchain_db.cpp')
-rw-r--r--src/cryptonote_core/blockchain_db.cpp68
1 files changed, 63 insertions, 5 deletions
diff --git a/src/cryptonote_core/blockchain_db.cpp b/src/cryptonote_core/blockchain_db.cpp
index 0ee10bd4d..fc8aeef4e 100644
--- a/src/cryptonote_core/blockchain_db.cpp
+++ b/src/cryptonote_core/blockchain_db.cpp
@@ -28,6 +28,7 @@
#include "cryptonote_core/blockchain_db.h"
#include "cryptonote_format_utils.h"
+#include "profile_tools.h"
using epee::string_tools::pod_to_hex;
@@ -41,11 +42,21 @@ void BlockchainDB::pop_block()
pop_block(blk, txs);
}
-void BlockchainDB::add_transaction(const crypto::hash& blk_hash, const transaction& tx)
+void BlockchainDB::add_transaction(const crypto::hash& blk_hash, const transaction& tx, const crypto::hash* tx_hash_ptr)
{
- crypto::hash tx_hash = get_transaction_hash(tx);
+ crypto::hash tx_hash;
+ if (!tx_hash_ptr)
+ {
+ // should only need to compute hash for miner transactions
+ tx_hash = get_transaction_hash(tx);
+ LOG_PRINT_L3("null tx_hash_ptr - needed to compute: " << tx_hash);
+ }
+ else
+ {
+ tx_hash = *tx_hash_ptr;
+ }
- add_transaction_data(blk_hash, tx);
+ add_transaction_data(blk_hash, tx, tx_hash);
// iterate tx.vout using indices instead of C++11 foreach syntax because
// we need the index
@@ -73,18 +84,33 @@ uint64_t BlockchainDB::add_block( const block& blk
, const std::vector<transaction>& txs
)
{
+ TIME_MEASURE_START(time1);
crypto::hash blk_hash = get_block_hash(blk);
+ TIME_MEASURE_FINISH(time1);
+ time_blk_hash += time1;
// call out to subclass implementation to add the block & metadata
- add_block(blk, block_size, cumulative_difficulty, coins_generated);
+ time1 = epee::misc_utils::get_tick_count();
+ add_block(blk, block_size, cumulative_difficulty, coins_generated, blk_hash);
+ TIME_MEASURE_FINISH(time1);
+ time_add_block1 += time1;
// call out to add the transactions
+ time1 = epee::misc_utils::get_tick_count();
add_transaction(blk_hash, blk.miner_tx);
+ int tx_i = 0;
+ crypto::hash tx_hash = null_hash;
for (const transaction& tx : txs)
{
- add_transaction(blk_hash, tx);
+ tx_hash = blk.tx_hashes[tx_i];
+ add_transaction(blk_hash, tx, &tx_hash);
+ ++tx_i;
}
+ TIME_MEASURE_FINISH(time1);
+ time_add_transaction += time1;
+
+ ++num_calls;
return height();
}
@@ -119,4 +145,36 @@ void BlockchainDB::remove_transaction(const crypto::hash& tx_hash)
remove_transaction_data(tx_hash, tx);
}
+void BlockchainDB::reset_stats()
+{
+ num_calls = 0;
+ time_blk_hash = 0;
+ time_tx_exists = 0;
+ time_add_block1 = 0;
+ time_add_transaction = 0;
+ time_commit1 = 0;
+}
+
+void BlockchainDB::show_stats()
+{
+ LOG_PRINT_L1(ENDL
+ << "*********************************"
+ << ENDL
+ << "num_calls: " << num_calls
+ << ENDL
+ << "time_blk_hash: " << time_blk_hash << "ms"
+ << ENDL
+ << "time_tx_exists: " << time_tx_exists << "ms"
+ << ENDL
+ << "time_add_block1: " << time_add_block1 << "ms"
+ << ENDL
+ << "time_add_transaction: " << time_add_transaction << "ms"
+ << ENDL
+ << "time_commit1: " << time_commit1 << "ms"
+ << ENDL
+ << "*********************************"
+ << ENDL
+ );
+}
+
} // namespace cryptonote