aboutsummaryrefslogtreecommitdiff
path: root/src/blockchain_db/lmdb
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2016-08-01 22:16:00 +0100
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2016-08-01 22:16:00 +0100
commit1593553e03aef8d44621aaf79a33ba25f69a2bd7 (patch)
treeeb2e86a6b9c08ea92930795d620b3214062910bd /src/blockchain_db/lmdb
parentMerge pull request #937 (diff)
downloadmonero-1593553e03aef8d44621aaf79a33ba25f69a2bd7.tar.xz
new unlocked parameter to output_histogram
This constrains the number of instances of any amount to the unlocked ones (as defined by the default unlock time setting: outputs with non default unlock time are not considered, so may be counted as unlocked even if they are not actually unlocked).
Diffstat (limited to '')
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp23
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.h7
2 files changed, 24 insertions, 6 deletions
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index 2cd3943e9..4f1e84a04 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -1945,7 +1945,7 @@ tx_out_index BlockchainLMDB::get_output_tx_and_index_from_global(const uint64_t&
return ret;
}
-tx_out_index BlockchainLMDB::get_output_tx_and_index(const uint64_t& amount, const uint64_t& index)
+tx_out_index BlockchainLMDB::get_output_tx_and_index(const uint64_t& amount, const uint64_t& index) const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
std::vector < uint64_t > offsets;
@@ -2551,7 +2551,7 @@ void BlockchainLMDB::get_output_key(const uint64_t &amount, const std::vector<ui
LOG_PRINT_L3("db3: " << db3);
}
-void BlockchainLMDB::get_output_tx_and_index(const uint64_t& amount, const std::vector<uint64_t> &offsets, std::vector<tx_out_index> &indices)
+void BlockchainLMDB::get_output_tx_and_index(const uint64_t& amount, const std::vector<uint64_t> &offsets, std::vector<tx_out_index> &indices) const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
@@ -2586,7 +2586,7 @@ void BlockchainLMDB::get_output_tx_and_index(const uint64_t& amount, const std::
LOG_PRINT_L3("db3: " << db3);
}
-std::map<uint64_t, uint64_t> BlockchainLMDB::get_output_histogram(const std::vector<uint64_t> &amounts) const
+std::map<uint64_t, uint64_t> BlockchainLMDB::get_output_histogram(const std::vector<uint64_t> &amounts, bool unlocked) const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
@@ -2638,6 +2638,23 @@ std::map<uint64_t, uint64_t> BlockchainLMDB::get_output_histogram(const std::vec
}
}
+ if (unlocked) {
+ const uint64_t blockchain_height = height();
+ for (auto i: histogram) {
+ uint64_t amount = i.first;
+ uint64_t num_elems = i.second;
+ while (num_elems > 0) {
+ const tx_out_index toi = get_output_tx_and_index(amount, num_elems - 1);
+ const uint64_t height = get_tx_block_height(toi.first);
+ if (height + CRYPTONOTE_DEFAULT_TX_SPENDABLE_AGE <= blockchain_height)
+ break;
+ --num_elems;
+ }
+ // modifying second does not invalidate the iterator
+ i.second = num_elems;
+ }
+ }
+
TXN_POSTFIX_RDONLY();
return histogram;
diff --git a/src/blockchain_db/lmdb/db_lmdb.h b/src/blockchain_db/lmdb/db_lmdb.h
index d7a78617e..d60701bbe 100644
--- a/src/blockchain_db/lmdb/db_lmdb.h
+++ b/src/blockchain_db/lmdb/db_lmdb.h
@@ -224,8 +224,8 @@ public:
virtual void get_output_tx_and_index_from_global(const std::vector<uint64_t> &global_indices,
std::vector<tx_out_index> &tx_out_indices) const;
- virtual tx_out_index get_output_tx_and_index(const uint64_t& amount, const uint64_t& index);
- virtual void get_output_tx_and_index(const uint64_t& amount, const std::vector<uint64_t> &offsets, std::vector<tx_out_index> &indices);
+ virtual tx_out_index get_output_tx_and_index(const uint64_t& amount, const uint64_t& index) const;
+ virtual void get_output_tx_and_index(const uint64_t& amount, const std::vector<uint64_t> &offsets, std::vector<tx_out_index> &indices) const;
virtual std::vector<uint64_t> get_tx_amount_output_indices(const uint64_t tx_id) const;
@@ -263,10 +263,11 @@ public:
* @brief return a histogram of outputs on the blockchain
*
* @param amounts optional set of amounts to lookup
+ * @param unlocked whether to restrict count to unlocked outputs
*
* @return a set of amount/instances
*/
- std::map<uint64_t, uint64_t> get_output_histogram(const std::vector<uint64_t> &amounts) const;
+ std::map<uint64_t, uint64_t> get_output_histogram(const std::vector<uint64_t> &amounts, bool unlocked) const;
private:
void do_resize(uint64_t size_increase=0);