aboutsummaryrefslogtreecommitdiff
path: root/src/blockchain_db
diff options
context:
space:
mode:
authorHoward Chu <hyc@symas.com>2017-06-01 13:29:51 +0100
committerHoward Chu <hyc@symas.com>2017-06-01 14:14:24 +0100
commitd17c0fc2d0ae52260a93ec8985b7ebb7ad3cfea7 (patch)
tree74598f10a771ee39e05778a20d1be805727169e0 /src/blockchain_db
parentMerge pull request #2053 (diff)
downloadmonero-d17c0fc2d0ae52260a93ec8985b7ebb7ad3cfea7.tar.xz
Don't copy blockchain for coinbase_tx_sum
Changed Blockchain::for_all_blocks() to for_blocks_range() Operate on blockchain in-place instead of building a copy first.
Diffstat (limited to '')
-rw-r--r--src/blockchain_db/blockchain_db.h10
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp14
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.h2
3 files changed, 19 insertions, 7 deletions
diff --git a/src/blockchain_db/blockchain_db.h b/src/blockchain_db/blockchain_db.h
index 9dd343f4b..b0a3d84e1 100644
--- a/src/blockchain_db/blockchain_db.h
+++ b/src/blockchain_db/blockchain_db.h
@@ -1353,10 +1353,10 @@ public:
virtual bool for_all_key_images(std::function<bool(const crypto::key_image&)>) const = 0;
/**
- * @brief runs a function over all blocks stored
+ * @brief runs a function over a range of blocks
*
- * The subclass should run the passed function for each block it has
- * stored, passing (block_height, block_hash, block) as its parameters.
+ * The subclass should run the passed function for each block in the
+ * specified range, passing (block_height, block_hash, block) as its parameters.
*
* If any call to the function returns false, the subclass should return
* false. Otherwise, the subclass returns true.
@@ -1364,11 +1364,13 @@ public:
* The subclass should throw DB_ERROR if any of the expected values are
* not found. Current implementations simply return false.
*
+ * @param h1 the start height
+ * @param h2 the end height
* @param std::function fn the function to run
*
* @return false if the function returns false for any block, otherwise true
*/
- virtual bool for_all_blocks(std::function<bool(uint64_t, const crypto::hash&, const cryptonote::block&)>) const = 0;
+ virtual bool for_blocks_range(const uint64_t& h1, const uint64_t& h2, std::function<bool(uint64_t, const crypto::hash&, const cryptonote::block&)>) const = 0;
/**
* @brief runs a function over all transactions stored
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index 1f0831874..d7947c8d0 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -2380,7 +2380,7 @@ bool BlockchainLMDB::for_all_key_images(std::function<bool(const crypto::key_ima
return ret;
}
-bool BlockchainLMDB::for_all_blocks(std::function<bool(uint64_t, const crypto::hash&, const cryptonote::block&)> f) const
+bool BlockchainLMDB::for_blocks_range(const uint64_t& h1, const uint64_t& h2, std::function<bool(uint64_t, const crypto::hash&, const cryptonote::block&)> f) const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
@@ -2392,7 +2392,15 @@ bool BlockchainLMDB::for_all_blocks(std::function<bool(uint64_t, const crypto::h
MDB_val v;
bool ret = true;
- MDB_cursor_op op = MDB_FIRST;
+ MDB_cursor_op op;
+ if (h1)
+ {
+ MDB_val_set(k, h1);
+ op = MDB_SET;
+ } else
+ {
+ op = MDB_FIRST;
+ }
while (1)
{
int ret = mdb_cursor_get(m_cur_blocks, &k, &v, op);
@@ -2414,6 +2422,8 @@ bool BlockchainLMDB::for_all_blocks(std::function<bool(uint64_t, const crypto::h
ret = false;
break;
}
+ if (height >= h2)
+ break;
}
TXN_POSTFIX_RDONLY();
diff --git a/src/blockchain_db/lmdb/db_lmdb.h b/src/blockchain_db/lmdb/db_lmdb.h
index 02f57ce18..540fababb 100644
--- a/src/blockchain_db/lmdb/db_lmdb.h
+++ b/src/blockchain_db/lmdb/db_lmdb.h
@@ -249,7 +249,7 @@ public:
virtual bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const txpool_tx_meta_t&, const cryptonote::blobdata*)> f, bool include_blob = false) const;
virtual bool for_all_key_images(std::function<bool(const crypto::key_image&)>) const;
- virtual bool for_all_blocks(std::function<bool(uint64_t, const crypto::hash&, const cryptonote::block&)>) const;
+ virtual bool for_blocks_range(const uint64_t& h1, const uint64_t& h2, std::function<bool(uint64_t, const crypto::hash&, const cryptonote::block&)>) const;
virtual bool for_all_transactions(std::function<bool(const crypto::hash&, const cryptonote::transaction&)>) const;
virtual bool for_all_outputs(std::function<bool(uint64_t amount, const crypto::hash &tx_hash, size_t tx_idx)> f) const;