aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core/blockchain.cpp
diff options
context:
space:
mode:
authorluigi1111 <luigi1111w@gmail.com>2018-07-19 13:39:24 -0500
committerluigi1111 <luigi1111w@gmail.com>2018-07-19 13:39:24 -0500
commit21afa71ba6d2f4e5e07dd91b69b2950820493a2c (patch)
treea117fbb8c7f530b6264ddc944654f82b46c28664 /src/cryptonote_core/blockchain.cpp
parentMerge pull request #3973 (diff)
parentdb: store cumulative rct output distribution in the db for speed (diff)
downloadmonero-21afa71ba6d2f4e5e07dd91b69b2950820493a2c.tar.xz
Merge pull request #3981
45e419b db: store cumulative rct output distribution in the db for speed (moneromooo-monero)
Diffstat (limited to 'src/cryptonote_core/blockchain.cpp')
-rw-r--r--src/cryptonote_core/blockchain.cpp39
1 files changed, 34 insertions, 5 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 5d5121504..c729f5cc6 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -1996,14 +1996,14 @@ void Blockchain::get_output_key_mask_unlocked(const uint64_t& amount, const uint
//------------------------------------------------------------------
bool Blockchain::get_output_distribution(uint64_t amount, uint64_t from_height, uint64_t to_height, uint64_t &start_height, std::vector<uint64_t> &distribution, uint64_t &base) const
{
- // rct outputs don't exist before v3
+ // rct outputs don't exist before v4
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;
+ case STAGENET: start_height = stagenet_hard_forks[3].height; break;
+ case TESTNET: start_height = testnet_hard_forks[3].height; break;
+ case MAINNET: start_height = mainnet_hard_forks[3].height; break;
default: return false;
}
}
@@ -2011,11 +2011,40 @@ bool Blockchain::get_output_distribution(uint64_t amount, uint64_t from_height,
start_height = 0;
base = 0;
+ if (to_height > 0 && to_height < from_height)
+ return false;
+
const uint64_t real_start_height = start_height;
if (from_height > start_height)
start_height = from_height;
- return m_db->get_output_distribution(amount, start_height, to_height, distribution, base);
+ distribution.clear();
+ uint64_t db_height = m_db->height();
+ if (db_height == 0)
+ return false;
+ if (to_height == 0)
+ to_height = db_height - 1;
+ if (start_height >= db_height || to_height >= db_height)
+ return false;
+ if (amount == 0)
+ {
+ std::vector<uint64_t> heights;
+ heights.reserve(to_height + 1 - start_height);
+ uint64_t real_start_height = start_height > 0 ? start_height-1 : start_height;
+ for (uint64_t h = real_start_height; h <= to_height; ++h)
+ heights.push_back(h);
+ distribution = m_db->get_block_cumulative_rct_outputs(heights);
+ if (start_height > 0)
+ {
+ base = distribution[0];
+ distribution.erase(distribution.begin());
+ }
+ return true;
+ }
+ else
+ {
+ return m_db->get_output_distribution(amount, start_height, to_height, distribution, base);
+ }
}
//------------------------------------------------------------------
// This function takes a list of block hashes from another node