diff options
-rw-r--r-- | src/cryptonote_core/hardfork.cpp | 11 | ||||
-rw-r--r-- | src/cryptonote_core/hardfork.h | 7 | ||||
-rw-r--r-- | tests/unit_tests/hardfork.cpp | 22 |
3 files changed, 40 insertions, 0 deletions
diff --git a/src/cryptonote_core/hardfork.cpp b/src/cryptonote_core/hardfork.cpp index 45d623ca9..edc2f33a9 100644 --- a/src/cryptonote_core/hardfork.cpp +++ b/src/cryptonote_core/hardfork.cpp @@ -337,6 +337,17 @@ uint8_t HardFork::get_ideal_version() const return heights.back().version; } +uint8_t HardFork::get_ideal_version(uint64_t height) const +{ + CRITICAL_REGION_LOCAL(lock); + for (unsigned int n = heights.size() - 1; n > 0; --n) { + if (height >= heights[n].height) { + return heights[n].version; + } + } + return original_version; +} + bool HardFork::get_voting_info(uint8_t version, uint32_t &window, uint32_t &votes, uint32_t &threshold, uint8_t &voting) const { CRITICAL_REGION_LOCAL(lock); diff --git a/src/cryptonote_core/hardfork.h b/src/cryptonote_core/hardfork.h index f44d20f8e..6800749da 100644 --- a/src/cryptonote_core/hardfork.h +++ b/src/cryptonote_core/hardfork.h @@ -168,6 +168,13 @@ namespace cryptonote uint8_t get_ideal_version() const; /** + * @brief returns the "ideal" version for a given height + * + * @param height height of the block to check + */ + uint8_t get_ideal_version(uint64_t height) const; + + /** * @brief returns the current version * * This is the latest version that's past its trigger date and had enough votes diff --git a/tests/unit_tests/hardfork.cpp b/tests/unit_tests/hardfork.cpp index e7387db1f..1f6ef5bf0 100644 --- a/tests/unit_tests/hardfork.cpp +++ b/tests/unit_tests/hardfork.cpp @@ -480,3 +480,25 @@ TEST(reorganize, changed) ASSERT_EQ(hf.get_current_version(), 2); // we did not bump to 3 this time ASSERT_EQ(hf.get_start_height(3), std::numeric_limits<uint64_t>::max()); // not yet } + +TEST(get, higher) +{ + TestDB db; + HardFork hf(db, 1, 0, 1, 1, 4, 50); + + // v h t + ASSERT_TRUE(hf.add(1, 0, 0)); + ASSERT_TRUE(hf.add(2, 2, 1)); + ASSERT_TRUE(hf.add(3, 5, 2)); + hf.init(); + + ASSERT_EQ(hf.get_ideal_version(0), 1); + ASSERT_EQ(hf.get_ideal_version(1), 1); + ASSERT_EQ(hf.get_ideal_version(2), 2); + ASSERT_EQ(hf.get_ideal_version(3), 2); + ASSERT_EQ(hf.get_ideal_version(4), 2); + ASSERT_EQ(hf.get_ideal_version(5), 3); + ASSERT_EQ(hf.get_ideal_version(6), 3); + ASSERT_EQ(hf.get_ideal_version(7), 3); +} + |