mirror of
https://github.com/monero-project/monero.git
synced 2024-10-01 11:49:47 -04:00
Merge pull request #3749
872cb4ef
blockchain: pop top if block version disagrees with the ideal fork version (stoffu)
This commit is contained in:
commit
791da4343c
@ -441,6 +441,53 @@ bool Blockchain::init(BlockchainDB* db, const network_type nettype, bool offline
|
||||
MINFO("Blockchain initialized. last block: " << m_db->height() - 1 << ", " << epee::misc_utils::get_time_interval_string(timestamp_diff) << " time ago, current difficulty: " << get_difficulty_for_next_block());
|
||||
m_db->block_txn_stop();
|
||||
|
||||
uint64_t num_popped_blocks = 0;
|
||||
while (true)
|
||||
{
|
||||
const uint64_t top_height = m_db->height() - 1;
|
||||
const crypto::hash top_id = m_db->top_block_hash();
|
||||
const block top_block = m_db->get_top_block();
|
||||
const uint8_t ideal_hf_version = get_ideal_hard_fork_version(top_height);
|
||||
if (ideal_hf_version <= 1 || ideal_hf_version == top_block.major_version)
|
||||
{
|
||||
if (num_popped_blocks > 0)
|
||||
MGINFO("Initial popping done, top block: " << top_id << ", top height: " << top_height << ", block version: " << (uint64_t)top_block.major_version);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (num_popped_blocks == 0)
|
||||
MGINFO("Current top block " << top_id << " at height " << top_height << " has version " << (uint64_t)top_block.major_version << " which disagrees with the ideal version " << (uint64_t)ideal_hf_version);
|
||||
if (num_popped_blocks % 100 == 0)
|
||||
MGINFO("Popping blocks... " << top_height);
|
||||
++num_popped_blocks;
|
||||
block popped_block;
|
||||
std::vector<transaction> popped_txs;
|
||||
try
|
||||
{
|
||||
m_db->pop_block(popped_block, popped_txs);
|
||||
}
|
||||
// anything that could cause this to throw is likely catastrophic,
|
||||
// so we re-throw
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
MERROR("Error popping block from blockchain: " << e.what());
|
||||
throw;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
MERROR("Error popping block from blockchain, throwing!");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (num_popped_blocks > 0)
|
||||
{
|
||||
m_timestamps_and_difficulties_height = 0;
|
||||
m_hardfork->reorganize_from_chain_height(get_current_blockchain_height());
|
||||
m_tx_pool.on_blockchain_dec(m_db->height()-1, get_tail_id());
|
||||
}
|
||||
|
||||
update_next_cumulative_size_limit();
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user