mirror of
https://github.com/monero-project/monero.git
synced 2025-07-27 22:05:27 -04:00
Merge pull request #3981
45e419b
db: store cumulative rct output distribution in the db for speed (moneromooo-monero)
This commit is contained in:
commit
21afa71ba6
9 changed files with 314 additions and 176 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue