aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2016-09-01 11:29:22 +0200
committerRiccardo Spagni <ric@spagni.net>2016-09-01 11:29:22 +0200
commitd3994f1df0bf9a842e6fd58a87928cc73b07c91d (patch)
treef70094f1b2f1c83c45c64a4bfca90c6e8ef1e3ad /src
parentMerge pull request #1016 (diff)
parentcore: faster find_blockchain_supplement (diff)
downloadmonero-d3994f1df0bf9a842e6fd58a87928cc73b07c91d.tar.xz
Merge pull request #1018
6cf8ca2 core: faster find_blockchain_supplement (moneromooo-monero)
Diffstat (limited to 'src')
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.cpp5
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.h2
-rw-r--r--src/blockchain_db/blockchain_db.h3
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp9
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.h2
-rw-r--r--src/cryptonote_core/blockchain.cpp8
6 files changed, 18 insertions, 11 deletions
diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp
index 4ec284e38..137ed9dc6 100644
--- a/src/blockchain_db/berkeleydb/db_bdb.cpp
+++ b/src/blockchain_db/berkeleydb/db_bdb.cpp
@@ -1235,7 +1235,7 @@ void BlockchainBDB::unlock()
check_open();
}
-bool BlockchainBDB::block_exists(const crypto::hash& h) const
+bool BlockchainBDB::block_exists(const crypto::hash& h, uint64_t *height) const
{
LOG_PRINT_L3("BlockchainBDB::" << __func__);
check_open();
@@ -1251,6 +1251,9 @@ bool BlockchainBDB::block_exists(const crypto::hash& h) const
else if (get_result)
throw0(DB_ERROR("DB error attempting to fetch block index from hash"));
+ if (height)
+ *height = get_result - 1;
+
return true;
}
diff --git a/src/blockchain_db/berkeleydb/db_bdb.h b/src/blockchain_db/berkeleydb/db_bdb.h
index f8e9440bd..f320ab0e3 100644
--- a/src/blockchain_db/berkeleydb/db_bdb.h
+++ b/src/blockchain_db/berkeleydb/db_bdb.h
@@ -250,7 +250,7 @@ public:
virtual void unlock();
- virtual bool block_exists(const crypto::hash& h) const;
+ virtual bool block_exists(const crypto::hash& h, uint64_t *height = NULL) const;
virtual block get_block(const crypto::hash& h) const;
diff --git a/src/blockchain_db/blockchain_db.h b/src/blockchain_db/blockchain_db.h
index d26080a3b..5b6a793d8 100644
--- a/src/blockchain_db/blockchain_db.h
+++ b/src/blockchain_db/blockchain_db.h
@@ -736,10 +736,11 @@ public:
* @brief checks if a block exists
*
* @param h the hash of the requested block
+ * @param height if non NULL, returns the block's height if found
*
* @return true of the block exists, otherwise false
*/
- virtual bool block_exists(const crypto::hash& h) const = 0;
+ virtual bool block_exists(const crypto::hash& h, uint64_t *height = NULL) const = 0;
/**
* @brief fetches the block with the given hash
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index c0cf28dda..8ad875fc8 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -1387,7 +1387,7 @@ void BlockchainLMDB::unlock()
auto_txn.commit(); \
} while(0)
-bool BlockchainLMDB::block_exists(const crypto::hash& h) const
+bool BlockchainLMDB::block_exists(const crypto::hash& h, uint64_t *height) const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
@@ -1405,7 +1405,14 @@ bool BlockchainLMDB::block_exists(const crypto::hash& h) const
else if (get_result)
throw0(DB_ERROR(lmdb_error("DB error attempting to fetch block index from hash", get_result).c_str()));
else
+ {
+ if (height)
+ {
+ const blk_height *bhp = (const blk_height *)key.mv_data;
+ *height = bhp->bh_height;
+ }
ret = true;
+ }
TXN_POSTFIX_RDONLY();
return ret;
diff --git a/src/blockchain_db/lmdb/db_lmdb.h b/src/blockchain_db/lmdb/db_lmdb.h
index 050e9e0ae..9df4b86d1 100644
--- a/src/blockchain_db/lmdb/db_lmdb.h
+++ b/src/blockchain_db/lmdb/db_lmdb.h
@@ -168,7 +168,7 @@ public:
virtual void unlock();
- virtual bool block_exists(const crypto::hash& h) const;
+ virtual bool block_exists(const crypto::hash& h, uint64_t *height = NULL) const;
virtual block get_block(const crypto::hash& h) const;
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 07db59796..dd9c21b91 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -1801,12 +1801,8 @@ bool Blockchain::find_blockchain_supplement(const std::list<crypto::hash>& qbloc
{
try
{
- split_height = m_db->get_block_height(*bl_it);
- break;
- }
- catch (const BLOCK_DNE& e)
- {
- continue;
+ if (m_db->block_exists(*bl_it, &split_height))
+ break;
}
catch (const std::exception& e)
{