aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_basic/hardfork.cpp
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-01-01 18:26:46 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-01-01 18:28:01 +0000
commit5ee6f03742f7c14059da6139a9923c443668f4b0 (patch)
tree55d5c01dbf3632c66d447477783dc37e6d807efc /src/cryptonote_basic/hardfork.cpp
parentblockchain: use the version passed as parameter, not a new one (diff)
downloadmonero-5ee6f03742f7c14059da6139a9923c443668f4b0.tar.xz
blockchain: fix wrong hf version when popping multiple blocks
Since we keep track of the hf version in the db, we pick it up from there instead of doing the full reorg call, which is quite expensive
Diffstat (limited to 'src/cryptonote_basic/hardfork.cpp')
-rw-r--r--src/cryptonote_basic/hardfork.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/cryptonote_basic/hardfork.cpp b/src/cryptonote_basic/hardfork.cpp
index 0de09856b..447d79aee 100644
--- a/src/cryptonote_basic/hardfork.cpp
+++ b/src/cryptonote_basic/hardfork.cpp
@@ -305,6 +305,29 @@ bool HardFork::rescan_from_chain_height(uint64_t height)
return rescan_from_block_height(height - 1);
}
+void HardFork::on_block_popped(uint64_t nblocks)
+{
+ CHECK_AND_ASSERT_THROW_MES(nblocks > 0, "nblocks must be greater than 0");
+
+ CRITICAL_REGION_LOCAL(lock);
+
+ const uint64_t new_chain_height = db.height();
+ const uint64_t old_chain_height = new_chain_height + nblocks;
+ uint8_t version;
+ uint64_t height;
+ for (height = old_chain_height - 1; height >= new_chain_height; --height)
+ {
+ versions.pop_back();
+ version = db.get_hard_fork_version(height);
+ versions.push_front(version);
+ }
+
+ // does not take voting into account
+ for (current_fork_index = heights.size() - 1; current_fork_index > 0; --current_fork_index)
+ if (height >= heights[current_fork_index].height)
+ break;
+}
+
int HardFork::get_voted_fork_index(uint64_t height) const
{
CRITICAL_REGION_LOCAL(lock);