pull/8799/merge
Jeffro 2 months ago committed by GitHub
commit ea12323ad1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -971,11 +971,13 @@ public:
*
* If the block does not exist, the subclass should throw BLOCK_DNE
*
* @param height the height requested
* @param start_height the first height to start accumulating (inclusive)
* @param end_height the last height to accumulatate (inclusive)
* @param[out] base the cumulative number of rct outputs for all blocks with height < start_height
*
* @return the cumulative number of rct outputs
*/
virtual std::vector<uint64_t> get_block_cumulative_rct_outputs(const std::vector<uint64_t> &heights) const = 0;
virtual std::vector<uint64_t> get_block_cumulative_rct_outputs(uint64_t start_height, uint64_t end_height, uint64_t& base) const = 0;
/**
* @brief fetch the top block's timestamp

@ -2490,16 +2490,20 @@ uint64_t BlockchainLMDB::get_block_timestamp(const uint64_t& height) const
return ret;
}
std::vector<uint64_t> BlockchainLMDB::get_block_cumulative_rct_outputs(const std::vector<uint64_t> &heights) const
std::vector<uint64_t> BlockchainLMDB::get_block_cumulative_rct_outputs(uint64_t start_height, uint64_t end_height, uint64_t& base) const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open();
std::vector<uint64_t> res;
int result;
if (heights.empty())
return {};
res.reserve(heights.size());
base = 0;
if (end_height < start_height)
throw0(BLOCK_DNE("Bad [start_height, end_height] range"));
const size_t num_dist_blocks = end_height - start_height + 1;
res.reserve(num_dist_blocks);
TXN_PREFIX_RDONLY();
RCURSOR(block_info);
@ -2507,15 +2511,18 @@ std::vector<uint64_t> BlockchainLMDB::get_block_cumulative_rct_outputs(const std
MDB_stat db_stats;
if ((result = mdb_stat(m_txn, m_blocks, &db_stats)))
throw0(DB_ERROR(lmdb_error("Failed to query m_blocks: ", result).c_str()));
for (size_t i = 0; i < heights.size(); ++i)
if (heights[i] >= db_stats.ms_entries)
throw0(BLOCK_DNE(std::string("Attempt to get rct distribution from height " + std::to_string(heights[i]) + " failed -- block size not in db").c_str()));
if (end_height >= db_stats.ms_entries)
throw0(BLOCK_DNE(std::string("Attempt to get rct distribution from height " + std::to_string(end_height) + " failed -- block size not in db").c_str()));
MDB_val v;
const uint64_t base_height = start_height ? start_height - 1 : 0;
MDB_val_set(v, base_height);
result = mdb_cursor_get(m_cur_block_info, (MDB_val *)&zerokval, &v, MDB_GET_BOTH);
if (result)
throw0(DB_ERROR(lmdb_error("Error attempting to retrieve rct distribution from the db: ", result).c_str()));
uint64_t range_begin = base_height;
uint64_t range_end = range_begin + 1;
uint64_t prev_height = heights[0];
uint64_t range_begin = 0, range_end = 0;
for (uint64_t height: heights)
for (uint64_t height = base_height; height <= end_height; ++height)
{
if (height >= range_begin && height < range_end)
{
@ -2523,7 +2530,6 @@ std::vector<uint64_t> BlockchainLMDB::get_block_cumulative_rct_outputs(const std
}
else
{
if (height == prev_height + 1)
{
MDB_val k2;
result = mdb_cursor_get(m_cur_block_info, &k2, &v, MDB_NEXT_MULTIPLE);
@ -2532,20 +2538,19 @@ std::vector<uint64_t> BlockchainLMDB::get_block_cumulative_rct_outputs(const std
if (height < range_begin || height >= range_end)
throw0(DB_ERROR(("Height " + std::to_string(height) + " not included in multuple record range: " + std::to_string(range_begin) + "-" + std::to_string(range_end)).c_str()));
}
else
{
v.mv_size = sizeof(uint64_t);
v.mv_data = (void*)&height;
result = mdb_cursor_get(m_cur_block_info, (MDB_val *)&zerokval, &v, MDB_GET_BOTH);
range_begin = height;
range_end = range_begin + 1;
}
if (result)
throw0(DB_ERROR(lmdb_error("Error attempting to retrieve rct distribution from the db: ", result).c_str()));
}
const mdb_block_info *bi = ((const mdb_block_info *)v.mv_data) + (height - range_begin);
res.push_back(bi->bi_cum_rct);
prev_height = height;
if (height < start_height) // doing query for base
{
base = bi->bi_cum_rct;
}
else // doing normal block query
{
res.push_back(bi->bi_cum_rct);
}
}
TXN_POSTFIX_RDONLY();

@ -216,7 +216,7 @@ public:
virtual cryptonote::blobdata get_block_blob_from_height(const uint64_t& height) const;
virtual std::vector<uint64_t> get_block_cumulative_rct_outputs(const std::vector<uint64_t> &heights) const;
virtual std::vector<uint64_t> get_block_cumulative_rct_outputs(uint64_t start_height, uint64_t end_height, uint64_t& base) const;
virtual uint64_t get_block_timestamp(const uint64_t& height) const;

@ -77,7 +77,7 @@ public:
virtual uint64_t get_block_height(const crypto::hash& h) const override { return 0; }
virtual cryptonote::block_header get_block_header(const crypto::hash& h) const override { return cryptonote::block_header(); }
virtual uint64_t get_block_timestamp(const uint64_t& height) const override { return 0; }
virtual std::vector<uint64_t> get_block_cumulative_rct_outputs(const std::vector<uint64_t> &heights) const override { return {}; }
virtual std::vector<uint64_t> get_block_cumulative_rct_outputs(uint64_t start_height, uint64_t end_height, uint64_t& base) const override { base = 0; return {}; }
virtual uint64_t get_top_block_timestamp() const override { return 0; }
virtual size_t get_block_weight(const uint64_t& height) const override { return 128; }
virtual std::vector<uint64_t> get_block_weights(uint64_t start_height, size_t count) const override { return {}; }

@ -2391,17 +2391,7 @@ bool Blockchain::get_output_distribution(uint64_t amount, uint64_t from_height,
return false;
if (amount == 0)
{
std::vector<uint64_t> heights;
heights.reserve(to_height + 1 - start_height);
const 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());
}
distribution = m_db->get_block_cumulative_rct_outputs(start_height, to_height, base);
return true;
}
else

@ -47,15 +47,20 @@ public:
TestDB(size_t bc_height = test_distribution_size): blockchain_height(bc_height) { m_open = true; }
virtual uint64_t height() const override { return blockchain_height; }
std::vector<uint64_t> get_block_cumulative_rct_outputs(const std::vector<uint64_t> &heights) const override
std::vector<uint64_t> get_block_cumulative_rct_outputs(uint64_t start_height, uint64_t end_height, uint64_t& base) const
{
base = 0;
std::vector<uint64_t> d;
for (uint64_t h: heights)
const uint64_t base_height = start_height == 0 ? 0 : start_height - 1;
for (uint64_t h = base_height; h <= end_height; ++h)
{
uint64_t c = 0;
for (uint64_t i = 0; i <= h; ++i)
c += test_distribution[i];
d.push_back(c);
if (h < start_height)
base = c;
else
d.push_back(c);
}
return d;
}

Loading…
Cancel
Save