Merge pull request #9935

69345db wallet2: use nearest checkpoint to allow fast_refresh on old accounts (Oscar Mira)
edc447e checkpoints: support nearest lower checkpoint lookup (Oscar Mira)
This commit is contained in:
tobtoht 2025-06-14 18:58:52 +00:00
commit bc33cdfe29
No known key found for this signature in database
GPG key ID: E45B10DD027D2472
3 changed files with 23 additions and 2 deletions

View file

@ -158,6 +158,19 @@ namespace cryptonote
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
{
return m_points;

View file

@ -129,6 +129,14 @@ namespace cryptonote
*/
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
*

View file

@ -3888,11 +3888,11 @@ void wallet2::fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height,
{
std::vector<crypto::hash> hashes;
const uint64_t checkpoint_height = m_checkpoints.get_max_height();
const uint64_t checkpoint_height = m_checkpoints.get_nearest_checkpoint_height(stop_height);
if ((stop_height > checkpoint_height && m_blockchain.size()-1 < checkpoint_height) && !force)
{
// we will drop all these, so don't bother getting them
uint64_t missing_blocks = m_checkpoints.get_max_height() - m_blockchain.size();
uint64_t missing_blocks = checkpoint_height - m_blockchain.size();
while (missing_blocks-- > 0)
m_blockchain.push_back(crypto::null_hash); // maybe a bit suboptimal, but deque won't do huge reallocs like vector
m_blockchain.push_back(m_checkpoints.get_points().at(checkpoint_height));