From edade8dc818e2fcb7af082bb6c5f619dedd4748a Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Mon, 23 Nov 2015 14:04:33 +0000 Subject: hardfork: fix actual/voting confusion --- src/cryptonote_core/hardfork.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/cryptonote_core/hardfork.cpp') diff --git a/src/cryptonote_core/hardfork.cpp b/src/cryptonote_core/hardfork.cpp index edc2f33a9..836378050 100644 --- a/src/cryptonote_core/hardfork.cpp +++ b/src/cryptonote_core/hardfork.cpp @@ -46,6 +46,11 @@ static uint8_t get_block_vote(const cryptonote::block &b) return b.minor_version; } +static uint8_t get_block_version(const cryptonote::block &b) +{ + return b.major_version; +} + HardFork::HardFork(cryptonote::BlockchainDB &db, uint8_t original_version, uint64_t original_version_till_height, time_t forked_time, time_t update_time, uint64_t window_size, uint8_t default_threshold_percent): db(db), original_version(original_version), @@ -105,7 +110,7 @@ bool HardFork::do_check(uint8_t version) const bool HardFork::check(const cryptonote::block &block) const { CRITICAL_REGION_LOCAL(lock); - return do_check(get_block_vote(block)); + return do_check(::get_block_version(block)); } bool HardFork::add(uint8_t block_version, uint64_t height) @@ -143,7 +148,7 @@ bool HardFork::add(uint8_t block_version, uint64_t height) bool HardFork::add(const cryptonote::block &block, uint64_t height) { - return add(get_block_vote(block), height); + return add(::get_block_version(block), height); } void HardFork::init() @@ -185,7 +190,7 @@ uint8_t HardFork::get_block_version(uint64_t height) const return original_version; const cryptonote::block &block = db.get_block_from_height(height); - return get_block_vote(block); + return ::get_block_version(block); } bool HardFork::reorganize_from_block_height(uint64_t height) -- cgit v1.2.3 From 3b47ca2d7ded0e886d7fb299ebd421f3afd373c9 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Mon, 23 Nov 2015 21:12:55 +0000 Subject: hardfork: fix rescan on load --- src/cryptonote_core/hardfork.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/cryptonote_core/hardfork.cpp') diff --git a/src/cryptonote_core/hardfork.cpp b/src/cryptonote_core/hardfork.cpp index 836378050..3d1bca32d 100644 --- a/src/cryptonote_core/hardfork.cpp +++ b/src/cryptonote_core/hardfork.cpp @@ -263,7 +263,7 @@ bool HardFork::rescan_from_block_height(uint64_t height) versions.push_back(v); } - uint8_t lastv = db.get_hard_fork_version(height); + uint8_t lastv = db.get_hard_fork_version(db.height() - 1); current_fork_index = 0; while (current_fork_index + 1 < heights.size() && heights[current_fork_index].version != lastv) ++current_fork_index; -- cgit v1.2.3 From d887c18e333aefb74b168931f23edcaf21b642d9 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Tue, 24 Nov 2015 20:46:10 +0000 Subject: hardfork: fix more major/minor issues Also add some more tests, and rename some instances of "version" and "add" for clarity. NOTE: the starting height values are sometimes wrong. I suspect this is due to the hard fork reorg code being buggy, since they're good when syncing after the fact. However, they're not actually used by the consensus code, so I'm ignoring this for now, but this needs debugging. --- src/cryptonote_core/hardfork.cpp | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'src/cryptonote_core/hardfork.cpp') diff --git a/src/cryptonote_core/hardfork.cpp b/src/cryptonote_core/hardfork.cpp index 3d1bca32d..2a2e25635 100644 --- a/src/cryptonote_core/hardfork.cpp +++ b/src/cryptonote_core/hardfork.cpp @@ -66,7 +66,7 @@ HardFork::HardFork(cryptonote::BlockchainDB &db, uint8_t original_version, uint6 throw "default_threshold_percent needs to be between 0 and 100"; } -bool HardFork::add(uint8_t version, uint64_t height, uint8_t threshold, time_t time) +bool HardFork::add_fork(uint8_t version, uint64_t height, uint8_t threshold, time_t time) { CRITICAL_REGION_LOCAL(lock); @@ -87,42 +87,43 @@ bool HardFork::add(uint8_t version, uint64_t height, uint8_t threshold, time_t t return true; } -bool HardFork::add(uint8_t version, uint64_t height, time_t time) +bool HardFork::add_fork(uint8_t version, uint64_t height, time_t time) { - return add(version, height, default_threshold_percent, time); + return add_fork(version, height, default_threshold_percent, time); } -uint8_t HardFork::get_effective_version(uint8_t version) const +uint8_t HardFork::get_effective_version(uint8_t voting_version) const { if (!heights.empty()) { uint8_t max_version = heights.back().version; - if (version > max_version) - version = max_version; + if (voting_version > max_version) + voting_version = max_version; } - return version; + return voting_version; } -bool HardFork::do_check(uint8_t version) const +bool HardFork::do_check(uint8_t block_version, uint8_t voting_version) const { - return version >= heights[current_fork_index].version; + return block_version >= heights[current_fork_index].version + && voting_version >= heights[current_fork_index].version; } bool HardFork::check(const cryptonote::block &block) const { CRITICAL_REGION_LOCAL(lock); - return do_check(::get_block_version(block)); + return do_check(::get_block_version(block), ::get_block_vote(block)); } -bool HardFork::add(uint8_t block_version, uint64_t height) +bool HardFork::add(uint8_t block_version, uint8_t voting_version, uint64_t height) { CRITICAL_REGION_LOCAL(lock); - if (!do_check(block_version)) + if (!do_check(block_version, voting_version)) return false; db.set_hard_fork_version(height, heights[current_fork_index].version); - const uint8_t version = get_effective_version(block_version); + voting_version = get_effective_version(voting_version); while (versions.size() >= window_size) { const uint8_t old_version = versions.front(); @@ -131,8 +132,8 @@ bool HardFork::add(uint8_t block_version, uint64_t height) versions.pop_front(); } - last_versions[version]++; - versions.push_back(version); + last_versions[voting_version]++; + versions.push_back(voting_version); uint8_t voted = get_voted_fork_index(height + 1); if (voted > current_fork_index) { @@ -148,7 +149,7 @@ bool HardFork::add(uint8_t block_version, uint64_t height) bool HardFork::add(const cryptonote::block &block, uint64_t height) { - return add(::get_block_version(block), height); + return add(::get_block_version(block), ::get_block_vote(block), height); } void HardFork::init() @@ -230,7 +231,7 @@ bool HardFork::reorganize_from_block_height(uint64_t height) const uint64_t bc_height = db.height(); for (uint64_t h = height + 1; h < bc_height; ++h) { - add(get_block_version(h), h); + add(db.get_block_from_height(h), h); } db.batch_stop(); -- cgit v1.2.3