diff options
author | luigi1111 <luigi1111w@gmail.com> | 2018-06-08 14:29:38 -0500 |
---|---|---|
committer | luigi1111 <luigi1111w@gmail.com> | 2018-06-08 14:29:38 -0500 |
commit | 5321769b65f3dcfc8c5e893d2c3f031ea37b956c (patch) | |
tree | 0ecbb7fec1f4f55e270f1d116489e8cf3af7a214 /src | |
parent | Merge pull request #3428 (diff) | |
parent | unit_tests/hardfork: add tests for get_voting_info() (diff) | |
download | monero-5321769b65f3dcfc8c5e893d2c3f031ea37b956c.tar.xz |
Merge pull request #3444
a79fc21 hardfork: fix get_earliest_ideal_height_for_version() to support non-existent versions (stoffu)
7e30ead unit_tests/hardfork: add tests for check_for_height() (stoffu)
98cf62c hardfork: fix get_next_version() (stoffu)
0321d1a unit_tests/hardfork: add tests for get_voting_info() (stoffu)
Diffstat (limited to 'src')
-rw-r--r-- | src/cryptonote_basic/hardfork.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/cryptonote_basic/hardfork.cpp b/src/cryptonote_basic/hardfork.cpp index 95f1ecab9..f05b25901 100644 --- a/src/cryptonote_basic/hardfork.cpp +++ b/src/cryptonote_basic/hardfork.cpp @@ -379,20 +379,24 @@ uint8_t HardFork::get_ideal_version(uint64_t height) const uint64_t HardFork::get_earliest_ideal_height_for_version(uint8_t version) const { - for (unsigned int n = heights.size() - 1; n > 0; --n) { - if (heights[n].version <= version) - return heights[n].height; + uint64_t height = std::numeric_limits<uint64_t>::max(); + for (auto i = heights.rbegin(); i != heights.rend(); ++i) { + if (i->version >= version) { + height = i->height; + } else { + break; + } } - return 0; + return height; } uint8_t HardFork::get_next_version() const { CRITICAL_REGION_LOCAL(lock); uint64_t height = db.height(); - for (unsigned int n = heights.size() - 1; n > 0; --n) { - if (height >= heights[n].height) { - return heights[n < heights.size() - 1 ? n + 1 : n].version; + for (auto i = heights.rbegin(); i != heights.rend(); ++i) { + if (height >= i->height) { + return (i == heights.rbegin() ? i : (i - 1))->version; } } return original_version; |