aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core/hardfork.cpp
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2015-09-26 16:22:57 +0100
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2015-09-27 22:46:41 +0100
commit0a7421b60716051359f821b2540073ad27c141d3 (patch)
treec4ba509b1849ca571f0516b08670a49c0cf68ce0 /src/cryptonote_core/hardfork.cpp
parenthardfork: remove use of GNU extension for initializing object (diff)
downloadmonero-0a7421b60716051359f821b2540073ad27c141d3.tar.xz
hardfork: rescan speedup
Add a block height before which version 1 is assumed Use DB transactions
Diffstat (limited to 'src/cryptonote_core/hardfork.cpp')
-rw-r--r--src/cryptonote_core/hardfork.cpp41
1 files changed, 30 insertions, 11 deletions
diff --git a/src/cryptonote_core/hardfork.cpp b/src/cryptonote_core/hardfork.cpp
index 30c5d94c9..4b40a4cf3 100644
--- a/src/cryptonote_core/hardfork.cpp
+++ b/src/cryptonote_core/hardfork.cpp
@@ -35,9 +35,10 @@
using namespace cryptonote;
-HardFork::HardFork(cryptonote::BlockchainDB &db, uint8_t original_version, time_t forked_time, time_t update_time, uint64_t window_size, int threshold_percent):
+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, int threshold_percent):
db(db),
original_version(original_version),
+ original_version_till_height(original_version_till_height),
forked_time(forked_time),
update_time(update_time),
window_size(window_size),
@@ -68,9 +69,8 @@ bool HardFork::add(uint8_t version, uint64_t height, time_t time)
return true;
}
-uint8_t HardFork::get_effective_version(const cryptonote::block &block) const
+uint8_t HardFork::get_effective_version(uint8_t version) const
{
- uint8_t version = block.major_version;
if (!heights.empty()) {
uint8_t max_version = heights.back().version;
if (version > max_version)
@@ -79,27 +79,27 @@ uint8_t HardFork::get_effective_version(const cryptonote::block &block) const
return version;
}
-bool HardFork::do_check(const cryptonote::block &block) const
+bool HardFork::do_check(uint8_t version) const
{
- return block.major_version >= heights[current_fork_index].version;
+ return version >= heights[current_fork_index].version;
}
bool HardFork::check(const cryptonote::block &block) const
{
CRITICAL_REGION_LOCAL(lock);
- return do_check(block);
+ return do_check(block.major_version);
}
-bool HardFork::add(const cryptonote::block &block, uint64_t height)
+bool HardFork::add(uint8_t block_version, uint64_t height)
{
CRITICAL_REGION_LOCAL(lock);
- if (!do_check(block))
+ if (!do_check(block_version))
return false;
db.set_hard_fork_version(height, heights[current_fork_index].version);
- const uint8_t version = get_effective_version(block);
+ const uint8_t version = get_effective_version(block_version);
while (versions.size() >= window_size) {
const uint8_t old_version = versions.front();
@@ -123,6 +123,11 @@ bool HardFork::add(const cryptonote::block &block, uint64_t height)
return true;
}
+bool HardFork::add(const cryptonote::block &block, uint64_t height)
+{
+ return add(block.major_version, height);
+}
+
void HardFork::init()
{
CRITICAL_REGION_LOCAL(lock);
@@ -154,12 +159,24 @@ void HardFork::init()
LOG_PRINT_L1("reorganization done");
}
+uint8_t HardFork::get_block_version(uint64_t height) const
+{
+ if (height <= original_version_till_height)
+ return original_version;
+
+ const cryptonote::block &block = db.get_block_from_height(height);
+ return block.major_version;
+}
+
bool HardFork::reorganize_from_block_height(uint64_t height)
{
CRITICAL_REGION_LOCAL(lock);
if (height >= db.height())
return false;
+ //db.set_batch_transactions(true);
+ //db.batch_start();
+
versions.clear();
for (size_t n = 0; n < 256; ++n)
@@ -172,7 +189,7 @@ bool HardFork::reorganize_from_block_height(uint64_t height)
}
for (uint64_t h = rescan_height; h <= height; ++h) {
cryptonote::block b = db.get_block_from_height(h);
- const uint8_t v = get_effective_version(b);
+ const uint8_t v = get_effective_version(b.major_version);
last_versions[v]++;
versions.push_back(v);
}
@@ -188,9 +205,11 @@ 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(db.get_block_from_height(h), h);
+ add(get_block_version(h), h);
}
+ //db.batch_stop();
+
return true;
}