mirror of
https://github.com/monero-project/monero.git
synced 2026-01-15 06:13:28 -08:00
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.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user