diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2016-08-30 16:39:33 +0100 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2016-08-31 10:03:32 +0100 |
commit | 6cf8ca2a7f3e11ca5559018dfc9b20869c07cdce (patch) | |
tree | 5634718d7626d234510d1f9e4c714627ff4b8590 /src/blockchain_db/berkeleydb | |
parent | Merge pull request #1014 (diff) | |
download | monero-6cf8ca2a7f3e11ca5559018dfc9b20869c07cdce.tar.xz |
core: faster find_blockchain_supplement
Since this queries block heights for blocks that may or may not
exist, queries for non existing blocks would throw an exception,
and that would slow down the loop a lot. 7 seconds to go through
a 30 hash list.
Fix this by adding an optional return block height to block_exists
and using this instead. Actual errors will still throw an
exception.
This also cuts down on log exception spam.
Diffstat (limited to '')
-rw-r--r-- | src/blockchain_db/berkeleydb/db_bdb.cpp | 5 | ||||
-rw-r--r-- | src/blockchain_db/berkeleydb/db_bdb.h | 2 |
2 files changed, 5 insertions, 2 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; |