diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2015-10-16 19:38:44 +0100 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2015-10-17 00:11:06 +0100 |
commit | 439c4555e99bbd1869fc6a7a96d7a5cb4a72c028 (patch) | |
tree | 7d2e3415ef893e739c5d3373bc70f5561fdd4fa7 | |
parent | Merge pull request #432 (diff) | |
download | monero-439c4555e99bbd1869fc6a7a96d7a5cb4a72c028.tar.xz |
hardfork: simplify work done on reload
There is no need to fully recalculate and rewrite state, just
refill state from the DB.
-rw-r--r-- | src/cryptonote_core/hardfork.cpp | 38 | ||||
-rw-r--r-- | src/cryptonote_core/hardfork.h | 3 |
2 files changed, 40 insertions, 1 deletions
diff --git a/src/cryptonote_core/hardfork.cpp b/src/cryptonote_core/hardfork.cpp index 3a8584b7f..fee607bcf 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"); } @@ -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); diff --git a/src/cryptonote_core/hardfork.h b/src/cryptonote_core/hardfork.h index 6b98b9fa1..4b2c20258 100644 --- a/src/cryptonote_core/hardfork.h +++ b/src/cryptonote_core/hardfork.h @@ -189,6 +189,9 @@ namespace cryptonote uint8_t get_effective_version(uint8_t version) const; bool add(uint8_t block_version, uint64_t height); + bool rescan_from_block_height(uint64_t height); + bool rescan_from_chain_height(uint64_t height); + private: BlockchainDB &db; |