mirror of
https://github.com/monero-project/monero.git
synced 2025-08-15 23:00:23 -04:00
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.
This commit is contained in:
parent
eed4dba880
commit
45e419bd5c
9 changed files with 315 additions and 177 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue