aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core/hardfork.cpp
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2015-10-20 20:55:39 +0200
committerRiccardo Spagni <ric@spagni.net>2015-10-20 20:55:53 +0200
commit14dd279fe123d7b48baed82d9109c585839b678f (patch)
treea79e281f205a0578312aa3b7cfc9a488036b9078 /src/cryptonote_core/hardfork.cpp
parentMerge pull request #432 (diff)
parentblockchain_export can now export to a blocks.dat format (diff)
downloadmonero-14dd279fe123d7b48baed82d9109c585839b678f.tar.xz
Merge pull request #437
b13e7f2 blockchain_export can now export to a blocks.dat format (moneromooo-monero) 11db442 bootstrap_file: do not try to create a directory with an empty name (moneromooo-monero) 03bc610 hardfork: use DB transactions when reorganizing (moneromooo-monero) 439c455 hardfork: simplify work done on reload (moneromooo-monero)
Diffstat (limited to 'src/cryptonote_core/hardfork.cpp')
-rw-r--r--src/cryptonote_core/hardfork.cpp44
1 files changed, 40 insertions, 4 deletions
diff --git a/src/cryptonote_core/hardfork.cpp b/src/cryptonote_core/hardfork.cpp
index 3a8584b7f..77839678c 100644
--- a/src/cryptonote_core/hardfork.cpp
+++ b/src/cryptonote_core/hardfork.cpp
@@ -150,12 +150,15 @@ void HardFork::init()
height = 1;
}
LOG_PRINT_L1("reorganizing from " << height);
- reorganize_from_chain_height(height);
if (populate) {
+ reorganize_from_chain_height(height);
// reorg will not touch the genesis block, use this as a flag for populating done
db.set_hard_fork_version(0, original_version);
db.set_hard_fork_starting_height(original_version, 0);
}
+ else {
+ rescan_from_chain_height(height);
+ }
LOG_PRINT_L1("reorganization done");
}
@@ -174,8 +177,8 @@ bool HardFork::reorganize_from_block_height(uint64_t height)
if (height >= db.height())
return false;
- //db.set_batch_transactions(true);
- //db.batch_start();
+ db.set_batch_transactions(true);
+ db.batch_start();
versions.clear();
@@ -208,7 +211,7 @@ bool HardFork::reorganize_from_block_height(uint64_t height)
add(get_block_version(h), h);
}
- //db.batch_stop();
+ db.batch_stop();
return true;
}
@@ -220,6 +223,39 @@ bool HardFork::reorganize_from_chain_height(uint64_t height)
return reorganize_from_block_height(height - 1);
}
+bool HardFork::rescan_from_block_height(uint64_t height)
+{
+ CRITICAL_REGION_LOCAL(lock);
+ if (height >= db.height())
+ return false;
+
+ versions.clear();
+
+ for (size_t n = 0; n < 256; ++n)
+ last_versions[n] = 0;
+ const uint64_t rescan_height = height >= (window_size - 1) ? height - (window_size -1) : 0;
+ 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.major_version);
+ last_versions[v]++;
+ versions.push_back(v);
+ }
+
+ uint8_t lastv = db.get_hard_fork_version(height);
+ current_fork_index = 0;
+ while (current_fork_index + 1 < heights.size() && heights[current_fork_index].version != lastv)
+ ++current_fork_index;
+
+ return true;
+}
+
+bool HardFork::rescan_from_chain_height(uint64_t height)
+{
+ if (height == 0)
+ return false;
+ return rescan_from_block_height(height - 1);
+}
+
int HardFork::get_voted_fork_index(uint64_t height) const
{
CRITICAL_REGION_LOCAL(lock);