diff options
author | Riccardo Spagni <ric@spagni.net> | 2016-08-11 22:43:14 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2016-08-11 22:43:14 +0200 |
commit | 0faf572db890c8bed9e5e4a7a21cd7d46d6f53d2 (patch) | |
tree | db8b1e95cb6f53c452cd8a06fcf19439a7ec6a36 /src/blockchain_db | |
parent | Merge pull request #953 (diff) | |
parent | Fake outs set is now decided by the wallet (diff) | |
download | monero-0faf572db890c8bed9e5e4a7a21cd7d46d6f53d2.tar.xz |
Merge pull request #948
11dc091 Fake outs set is now decided by the wallet (moneromooo-monero)
1593553 new unlocked parameter to output_histogram (moneromooo-monero)
Diffstat (limited to 'src/blockchain_db')
-rw-r--r-- | src/blockchain_db/blockchain_db.h | 7 | ||||
-rw-r--r-- | src/blockchain_db/lmdb/db_lmdb.cpp | 23 | ||||
-rw-r--r-- | src/blockchain_db/lmdb/db_lmdb.h | 7 |
3 files changed, 28 insertions, 9 deletions
diff --git a/src/blockchain_db/blockchain_db.h b/src/blockchain_db/blockchain_db.h index ab5d2d44c..4c2157a39 100644 --- a/src/blockchain_db/blockchain_db.h +++ b/src/blockchain_db/blockchain_db.h @@ -1140,7 +1140,7 @@ public: * * @return the tx hash and output index */ - virtual tx_out_index get_output_tx_and_index(const uint64_t& amount, const uint64_t& index) = 0; + virtual tx_out_index get_output_tx_and_index(const uint64_t& amount, const uint64_t& index) const = 0; /** * @brief gets some outputs' tx hashes and indices @@ -1153,7 +1153,7 @@ public: * @param offsets a list of amount-specific output indices * @param indices return-by-reference a list of tx hashes and output indices (as pairs) */ - virtual void get_output_tx_and_index(const uint64_t& amount, const std::vector<uint64_t> &offsets, std::vector<tx_out_index> &indices) = 0; + virtual void get_output_tx_and_index(const uint64_t& amount, const std::vector<uint64_t> &offsets, std::vector<tx_out_index> &indices) const = 0; /** * @brief gets outputs' data @@ -1305,10 +1305,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 */ - virtual std::map<uint64_t, uint64_t> get_output_histogram(const std::vector<uint64_t> &amounts) const = 0; + virtual std::map<uint64_t, uint64_t> get_output_histogram(const std::vector<uint64_t> &amounts, bool unlocked) const = 0; /** * @brief is BlockchainDB in read-only mode? diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index ea97c1ab3..2bab4b2dd 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -1944,7 +1944,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; @@ -2550,7 +2550,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(); @@ -2585,7 +2585,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(); @@ -2637,6 +2637,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); |