aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core/blockchain.cpp
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2018-03-16 18:07:33 +0200
committerRiccardo Spagni <ric@spagni.net>2018-03-16 18:07:33 +0200
commit7d928be240ecaade41bbe823497086ce04372eeb (patch)
tree0ab820cc329d2cf61fbe257df9ee62a254e85d9d /src/cryptonote_core/blockchain.cpp
parentMerge pull request #3410 (diff)
parentwallet: more user friendly print_ring (diff)
downloadmonero-7d928be240ecaade41bbe823497086ce04372eeb.tar.xz
Merge pull request #3322
eac3a11e wallet: more user friendly print_ring (moneromooo-monero) 79853514 wallet2_api: add key reuse mitigations API (moneromooo-monero) b057a21d wallet2_api: add ring api (moneromooo-monero) d32ef7b0 ringdb: factor ring addition code (moneromooo-monero) a7da8208 wallet2_api: add blackball api (moneromooo-monero) 2ab66ff1 liblmdb: install lmdb library for wallet2_api usage (stoffu) 504428ab ringdb: use the genesis block as a db name (moneromooo-monero) b09e5181 wallet: add a set_ring command (moneromooo-monero) 0590f62a new blockchain_usage tool, reports on output usage (moneromooo-monero) db10dd6d wallet: make ringdb an object with database state (moneromooo-monero) df6fad4c blockchain_utilities: new blockchain_blackball tool (moneromooo-monero) d29ea045 wallet: add an output blackball list to avoid using those in rings (moneromooo-monero) 18eaf194 wallet: key reuse mitigation options (moneromooo-monero) 5f146873 wallet: add shared ring database (moneromooo-monero) 41f727ce add RPC to get a histogram of outputs of a given amount (moneromooo-monero)
Diffstat (limited to 'src/cryptonote_core/blockchain.cpp')
-rw-r--r--src/cryptonote_core/blockchain.cpp46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index a0031559b..0a6f1cdcd 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -1903,6 +1903,45 @@ void Blockchain::get_output_key_mask_unlocked(const uint64_t& amount, const uint
unlocked = is_tx_spendtime_unlocked(m_db->get_tx_unlock_time(toi.first));
}
//------------------------------------------------------------------
+bool Blockchain::get_output_distribution(uint64_t amount, uint64_t from_height, uint64_t &start_height, std::vector<uint64_t> &distribution, uint64_t &base) const
+{
+ // rct outputs don't exist before v3
+ if (amount == 0)
+ {
+ switch (m_nettype)
+ {
+ case STAGENET: start_height = stagenet_hard_forks[2].height; break;
+ case TESTNET: start_height = testnet_hard_forks[2].height; break;
+ case MAINNET: start_height = mainnet_hard_forks[2].height; break;
+ default: return false;
+ }
+ }
+ else
+ start_height = 0;
+ base = 0;
+
+ const uint64_t real_start_height = start_height;
+ if (from_height > start_height)
+ start_height = from_height;
+
+ distribution.clear();
+ uint64_t db_height = m_db->height();
+ if (start_height >= db_height)
+ return false;
+ distribution.resize(db_height - start_height, 0);
+ bool r = for_all_outputs(amount, [&](uint64_t height) {
+ CHECK_AND_ASSERT_MES(height >= real_start_height && height <= db_height, false, "Height not in expected range");
+ if (height >= start_height)
+ distribution[height - start_height]++;
+ else
+ base++;
+ return true;
+ });
+ if (!r)
+ return false;
+ return true;
+}
+//------------------------------------------------------------------
// This function takes a list of block hashes from another node
// on the network to find where the split point is between us and them.
// This is used to see what to send another node that needs to sync.
@@ -4441,11 +4480,16 @@ bool Blockchain::for_all_transactions(std::function<bool(const crypto::hash&, co
return m_db->for_all_transactions(f);
}
-bool Blockchain::for_all_outputs(std::function<bool(uint64_t amount, const crypto::hash &tx_hash, size_t tx_idx)> f) const
+bool Blockchain::for_all_outputs(std::function<bool(uint64_t amount, const crypto::hash &tx_hash, uint64_t height, size_t tx_idx)> f) const
{
return m_db->for_all_outputs(f);;
}
+bool Blockchain::for_all_outputs(uint64_t amount, std::function<bool(uint64_t height)> f) const
+{
+ return m_db->for_all_outputs(amount, f);;
+}
+
namespace cryptonote {
template bool Blockchain::get_transactions(const std::vector<crypto::hash>&, std::list<transaction>&, std::list<crypto::hash>&) const;
}