aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-05-22 14:46:30 +0100
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-07-13 11:37:04 +0100
commit45e419bd5c756337635feccec388efedf04f44ac (patch)
tree87d196cadada9f73419e353d02120122e90161d2 /src/cryptonote_core
parentMerge pull request #4094 (diff)
downloadmonero-45e419bd5c756337635feccec388efedf04f44ac.tar.xz
db: store cumulative rct output distribution in the db for speed
This gets rid of the temporary precalc cache. Also make the RPC able to send data back in binary or JSON, since there can be a lot of data This bumps the LMDB database format to v3, with migration.
Diffstat (limited to 'src/cryptonote_core')
-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 73ce98366..a7cd0947a 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -1985,14 +1985,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;
}
}
@@ -2000,11 +2000,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