Merge pull request #11089

1847293 checkpoints: exclude equal height in get_nearest_checkpoint_height (woodser)

ACKs: selsta, plowsof, jpk68
This commit is contained in:
tobtoht
2026-08-17 17:28:54 +00:00
2 changed files with 19 additions and 1 deletions
+1 -1
View File
@@ -163,7 +163,7 @@ namespace cryptonote
if (m_points.empty()) if (m_points.empty())
return 0; return 0;
auto it = m_points.upper_bound(block_height); auto it = m_points.lower_bound(block_height);
if (it == m_points.begin()) if (it == m_points.begin())
return 0; return 0;
+18
View File
@@ -164,3 +164,21 @@ TEST(checkpoints_is_alternative_block_allowed, handles_two_and_more_checkpoints)
ASSERT_TRUE (cp.is_alternative_block_allowed(11, 10)); ASSERT_TRUE (cp.is_alternative_block_allowed(11, 10));
ASSERT_TRUE (cp.is_alternative_block_allowed(11, 11)); ASSERT_TRUE (cp.is_alternative_block_allowed(11, 11));
} }
TEST(checkpoints_get_nearest_checkpoint_height, returns_nearest_checkpoint_below_height)
{
checkpoints cp;
ASSERT_EQ(0, cp.get_nearest_checkpoint_height(7));
ASSERT_TRUE(cp.add_checkpoint(5, "0000000000000000000000000000000000000000000000000000000000000000"));
ASSERT_TRUE(cp.add_checkpoint(9, "0000000000000000000000000000000000000000000000000000000000000000"));
ASSERT_EQ(0, cp.get_nearest_checkpoint_height(0));
ASSERT_EQ(0, cp.get_nearest_checkpoint_height(4));
ASSERT_EQ(0, cp.get_nearest_checkpoint_height(5));
ASSERT_EQ(5, cp.get_nearest_checkpoint_height(6));
ASSERT_EQ(5, cp.get_nearest_checkpoint_height(9));
ASSERT_EQ(9, cp.get_nearest_checkpoint_height(10));
ASSERT_EQ(9, cp.get_nearest_checkpoint_height(11));
}