Skip to content

Commit

Permalink
Fix hardfork off-by-one range
Browse files Browse the repository at this point in the history
  • Loading branch information
who-biz committed Nov 26, 2019
1 parent cef3176 commit c1f89b5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/cryptonote_basic/hardfork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void HardFork::init()
heights.push_back(Params(original_version, 0, 0));

versions.clear();
for (size_t n = 0; n < 255; ++n)
for (size_t n = 0; n <= 255; ++n)
last_versions[n] = 0;
current_fork_index = 0;

Expand Down Expand Up @@ -216,7 +216,7 @@ bool HardFork::reorganize_from_block_height(uint64_t const& height)

versions.clear();

for (size_t n = 0; n < 255; ++n)
for (size_t n = 0; n <= 255; ++n)
last_versions[n] = 0;
const uint64_t rescan_height = height >= (window_size - 1) ? height - (window_size -1) : 0;
const uint8_t start_version = height == 0 ? original_version : db.get_hard_fork_version(height);
Expand Down Expand Up @@ -264,7 +264,7 @@ bool HardFork::rescan_from_block_height(uint64_t const& height)

versions.clear();

for (size_t n = 0; n < 255; ++n)
for (size_t n = 0; n <= 255; ++n)
last_versions[n] = 0;
for (uint64_t h = height; h < db.height(); ++h) {
cryptonote::block b = db.get_block_from_height(h);
Expand Down Expand Up @@ -400,7 +400,7 @@ bool HardFork::get_voting_info(uint8_t const& version, uint32_t& window, uint32_
const bool enabled = current_version >= version;
window = versions.size();
votes = 0;
for (size_t n = version; n < 255; ++n)
for (size_t n = version; n <= 255; ++n)
votes += last_versions[n];
threshold = (window * heights[current_fork_index].threshold + 99) / 100;
//assert((votes >= threshold) == enabled);
Expand Down
2 changes: 1 addition & 1 deletion src/cryptonote_basic/hardfork.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ namespace cryptonote
std::vector<Params> heights;

std::deque<uint8_t> versions; /* rolling window of the last N blocks' versions */
unsigned int last_versions[255]; /* count of the block versions in the last N blocks */
unsigned int last_versions[256]; /* count of the block versions in the last N blocks */
uint32_t current_fork_index;

mutable epee::critical_section lock;
Expand Down

0 comments on commit c1f89b5

Please sign in to comment.