From edc447eb753aa9d1ca2e4d085e47aa3de9600e38 Mon Sep 17 00:00:00 2001 From: Oscar Mira Date: Wed, 21 May 2025 00:23:35 +0200 Subject: [PATCH 1/2] checkpoints: support nearest lower checkpoint lookup --- src/checkpoints/checkpoints.cpp | 13 +++++++++++++ src/checkpoints/checkpoints.h | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/src/checkpoints/checkpoints.cpp b/src/checkpoints/checkpoints.cpp index 63ec6ede96..e17740cd75 100644 --- a/src/checkpoints/checkpoints.cpp +++ b/src/checkpoints/checkpoints.cpp @@ -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& checkpoints::get_points() const { return m_points; diff --git a/src/checkpoints/checkpoints.h b/src/checkpoints/checkpoints.h index 7a93213c93..5189145f66 100644 --- a/src/checkpoints/checkpoints.h +++ b/src/checkpoints/checkpoints.h @@ -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 * From 69345dbe29bd60096d19897fc1724383e4a65a7a Mon Sep 17 00:00:00 2001 From: Oscar Mira Date: Wed, 21 May 2025 00:40:57 +0200 Subject: [PATCH 2/2] wallet2: use nearest checkpoint to allow fast_refresh on old accounts --- src/wallet/wallet2.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 9b09d0920a..20fadc2f69 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3790,11 +3790,11 @@ void wallet2::fast_refresh(uint64_t stop_height, uint64_t &blocks_start_height, { std::vector 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));