aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
authorwarptangent <warptangent@inbox.com>2015-02-11 15:55:53 -0800
committerwarptangent <warptangent@inbox.com>2015-02-23 00:33:37 -0800
commit8909d7d82eaf2b130b7d36fb5db7863170356b15 (patch)
treeb33f9b7f9f874e040208d2074c9797861b929281 /src/cryptonote_core
parentAdd profiling to block and tx processing (diff)
downloadmonero-8909d7d82eaf2b130b7d36fb5db7863170356b15.tar.xz
Improve block and tx processing efficiency by less repeat hashing
BlockchainLMDB::add_block() BlockchainLMDB::add_transaction_data() BlockchainDB::add_transaction()
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r--src/cryptonote_core/BlockchainDB_impl/db_lmdb.cpp7
-rw-r--r--src/cryptonote_core/BlockchainDB_impl/db_lmdb.h3
-rw-r--r--src/cryptonote_core/blockchain_db.cpp24
-rw-r--r--src/cryptonote_core/blockchain_db.h5
4 files changed, 28 insertions, 11 deletions
diff --git a/src/cryptonote_core/BlockchainDB_impl/db_lmdb.cpp b/src/cryptonote_core/BlockchainDB_impl/db_lmdb.cpp
index f7e8c5dda..849ec8f6d 100644
--- a/src/cryptonote_core/BlockchainDB_impl/db_lmdb.cpp
+++ b/src/cryptonote_core/BlockchainDB_impl/db_lmdb.cpp
@@ -152,12 +152,13 @@ void BlockchainLMDB::add_block( const block& blk
, const size_t& block_size
, const difficulty_type& cumulative_difficulty
, const uint64_t& coins_generated
+ , const crypto::hash& blk_hash
)
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
- MDB_val_copy<crypto::hash> val_h(get_block_hash(blk));
+ MDB_val_copy<crypto::hash> val_h(blk_hash);
MDB_val unused;
if (mdb_get(*m_write_txn, m_block_heights, &val_h, &unused) == 0)
throw1(BLOCK_EXISTS("Attempting to add block that's already in the db"));
@@ -243,12 +244,12 @@ void BlockchainLMDB::remove_block()
throw1(DB_ERROR("Failed to add removal of block hash to db transaction"));
}
-void BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, const transaction& tx)
+void BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, const transaction& tx, const crypto::hash& tx_hash)
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
- MDB_val_copy<crypto::hash> val_h(get_transaction_hash(tx));
+ MDB_val_copy<crypto::hash> val_h(tx_hash);
MDB_val unused;
if (mdb_get(*m_write_txn, m_txs, &val_h, &unused) == 0)
throw1(TX_EXISTS("Attempting to add transaction that's already in the db"));
diff --git a/src/cryptonote_core/BlockchainDB_impl/db_lmdb.h b/src/cryptonote_core/BlockchainDB_impl/db_lmdb.h
index 2513aa48a..29fc52fbd 100644
--- a/src/cryptonote_core/BlockchainDB_impl/db_lmdb.h
+++ b/src/cryptonote_core/BlockchainDB_impl/db_lmdb.h
@@ -184,11 +184,12 @@ private:
, const size_t& block_size
, const difficulty_type& cumulative_difficulty
, const uint64_t& coins_generated
+ , const crypto::hash& block_hash
);
virtual void remove_block();
- virtual void add_transaction_data(const crypto::hash& blk_hash, const transaction& tx);
+ virtual void add_transaction_data(const crypto::hash& blk_hash, const transaction& tx, const crypto::hash& tx_hash);
virtual void remove_transaction_data(const crypto::hash& tx_hash, const transaction& tx);
diff --git a/src/cryptonote_core/blockchain_db.cpp b/src/cryptonote_core/blockchain_db.cpp
index 615b08814..af0c9487f 100644
--- a/src/cryptonote_core/blockchain_db.cpp
+++ b/src/cryptonote_core/blockchain_db.cpp
@@ -42,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
@@ -81,7 +91,7 @@ uint64_t BlockchainDB::add_block( const block& blk
// call out to subclass implementation to add the block & metadata
time1 = epee::misc_utils::get_tick_count();
- add_block(blk, block_size, cumulative_difficulty, coins_generated);
+ add_block(blk, block_size, cumulative_difficulty, coins_generated, blk_hash);
TIME_MEASURE_FINISH(time1);
time_add_block1 += time1;
@@ -89,9 +99,13 @@ uint64_t BlockchainDB::add_block( const block& blk
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;
diff --git a/src/cryptonote_core/blockchain_db.h b/src/cryptonote_core/blockchain_db.h
index 531de04bd..02620c406 100644
--- a/src/cryptonote_core/blockchain_db.h
+++ b/src/cryptonote_core/blockchain_db.h
@@ -265,13 +265,14 @@ private:
, const size_t& block_size
, const difficulty_type& cumulative_difficulty
, const uint64_t& coins_generated
+ , const crypto::hash& blk_hash
) = 0;
// tells the subclass to remove data about the top block
virtual void remove_block() = 0;
// tells the subclass to store the transaction and its metadata
- virtual void add_transaction_data(const crypto::hash& blk_hash, const transaction& tx) = 0;
+ virtual void add_transaction_data(const crypto::hash& blk_hash, const transaction& tx, const crypto::hash& tx_hash) = 0;
// tells the subclass to remove data about a transaction
virtual void remove_transaction_data(const crypto::hash& tx_hash, const transaction& tx) = 0;
@@ -296,7 +297,7 @@ private:
void pop_block();
// helper function for add_transactions, to add each individual tx
- void add_transaction(const crypto::hash& blk_hash, const transaction& tx);
+ void add_transaction(const crypto::hash& blk_hash, const transaction& tx, const crypto::hash* tx_hash_ptr = NULL);
// helper function to remove transaction from blockchain
void remove_transaction(const crypto::hash& tx_hash);