aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r--src/cryptonote_core/blockchain.cpp11
-rw-r--r--src/cryptonote_core/hardfork.cpp44
-rw-r--r--src/cryptonote_core/hardfork.h3
3 files changed, 49 insertions, 9 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index e06c3c08c..c38b58841 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -352,13 +352,14 @@ bool Blockchain::init(BlockchainDB* db, const bool testnet)
m_async_pool.create_thread(boost::bind(&boost::asio::io_service::run, &m_async_service));
#if defined(PER_BLOCK_CHECKPOINT)
- if (m_fast_sync && !testnet && get_blocks_dat_start() != nullptr)
+ if (m_fast_sync && get_blocks_dat_start(testnet) != nullptr)
{
- if (get_blocks_dat_size() > 4)
+ if (get_blocks_dat_size(testnet) > 4)
{
- const unsigned char *p = get_blocks_dat_start();
- uint32_t nblocks = *(uint32_t *) p;
- if(nblocks > 0 && nblocks > m_db->height())
+ const unsigned char *p = get_blocks_dat_start(testnet);
+ const uint32_t nblocks = *p | ((*(p+1))<<8) | ((*(p+2))<<16) | ((*(p+3))<<24);
+ const size_t size_needed = 4 + nblocks * sizeof(crypto::hash);
+ if(nblocks > 0 && nblocks > m_db->height() && get_blocks_dat_size(testnet) >= size_needed)
{
LOG_PRINT_L0("Loading precomputed blocks: " << nblocks);
p += sizeof(uint32_t);
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);
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;