checkpoints: support nearest lower checkpoint lookup

This commit is contained in:
Oscar Mira 2025-05-21 00:23:35 +02:00
parent cc73fe7116
commit edc447eb75
No known key found for this signature in database
GPG key ID: B371B98C5DC32237
2 changed files with 21 additions and 0 deletions

View file

@ -158,6 +158,19 @@ namespace cryptonote
return m_points.rbegin()->first; return m_points.rbegin()->first;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
uint64_t checkpoints::get_nearest_checkpoint_height(uint64_t block_height) const
{
if (m_points.empty())
return 0;
auto it = m_points.upper_bound(block_height);
if (it == m_points.begin())
return 0;
--it;
return it->first;
}
//---------------------------------------------------------------------------
const std::map<uint64_t, crypto::hash>& checkpoints::get_points() const const std::map<uint64_t, crypto::hash>& checkpoints::get_points() const
{ {
return m_points; return m_points;

View file

@ -129,6 +129,14 @@ namespace cryptonote
*/ */
uint64_t get_max_height() const; uint64_t get_max_height() const;
/**
* @brief gets the highest checkpoint height less than the given block height
*
* @param block_height the reference block height
* @return the nearest checkpoint height below block_height, or 0 if none
*/
uint64_t get_nearest_checkpoint_height(uint64_t block_height) const;
/** /**
* @brief gets the checkpoints container * @brief gets the checkpoints container
* *