diff options
Diffstat (limited to 'src/cryptonote_core/blockchain.cpp')
-rw-r--r-- | src/cryptonote_core/blockchain.cpp | 60 |
1 files changed, 54 insertions, 6 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 09f8f8d7f..65d07dcf7 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -69,6 +69,18 @@ extern "C" void slow_hash_free_state(); DISABLE_VS_WARNINGS(4267) +static const struct { + uint8_t version; + uint64_t height; + time_t time; +} hard_forks[] = { + // version 1 from the start of the blockchain + { 1, 1, 1341378000 }, + + // version 2 can start from block 1009827, setup on the 20th of september + { 2, 1009827, 1442763710 }, +}; + //------------------------------------------------------------------ Blockchain::Blockchain(tx_memory_pool& tx_pool) : m_db(), m_tx_pool(tx_pool), m_timestamps_and_difficulties_height(0), m_current_block_cumul_sz_limit(0), m_is_in_checkpoint_zone(false), @@ -118,6 +130,11 @@ void Blockchain::serialize(archive_t & ar, const unsigned int version) } } + if (version > 12) + { + ar & *m_hardfork; + } + LOG_PRINT_L3("Blockchain storage:" << std::endl << "m_blocks: " << m_db->height() << std::endl << "m_blocks_index: " << m_blocks_index.size() << std::endl << "m_transactions: " << m_transactions.size() << std::endl << "dummy_key_images_container: " << dummy_key_images_container.size() << std::endl << "m_alternative_chains: " << m_alternative_chains.size() << std::endl << "m_outputs: " << m_outputs.size() << std::endl << "m_invalid_blocks: " << m_invalid_blocks.size() << std::endl << "m_current_block_cumul_sz_limit: " << m_current_block_cumul_sz_limit); } //------------------------------------------------------------------ @@ -270,6 +287,11 @@ bool Blockchain::init(BlockchainDB* db, const bool testnet) m_db = db; + m_hardfork = new HardFork(*db); + for (size_t n = 0; n < sizeof(hard_forks) / sizeof(hard_forks[0]); ++n) + m_hardfork->add(hard_forks[n].version, hard_forks[n].height, hard_forks[n].time); + m_hardfork->init(); + // if the blockchain is new, add the genesis block // this feels kinda kludgy to do it this way, but can be looked at later. // TODO: add function to create and store genesis block, @@ -416,6 +438,7 @@ bool Blockchain::deinit() LOG_PRINT_L0("There was an issue closing/storing the blockchain, shutting down now to prevent issues!"); } + delete m_hardfork; delete m_db; return true; } @@ -706,6 +729,8 @@ bool Blockchain::rollback_blockchain_switching(std::list<block>& original_chain, CHECK_AND_ASSERT_MES(r && bvc.m_added_to_main_chain, false, "PANIC! failed to add (again) block while chain switching during the rollback!"); } + m_hardfork->reorganize_from_chain_height(rollback_height); + LOG_PRINT_L1("Rollback to height " << rollback_height << " was successful."); if (original_chain.size()) { @@ -803,6 +828,8 @@ bool Blockchain::switch_to_alternative_blockchain(std::list<blocks_ext_by_hash:: m_alternative_chains.erase(ch_ent); } + m_hardfork->reorganize_from_chain_height(split_height); + LOG_PRINT_GREEN("REORGANIZE SUCCESS! on height: " << split_height << ", new blockchain size: " << m_db->height(), LOG_LEVEL_0); return true; } @@ -972,12 +999,13 @@ bool Blockchain::create_block_template(block& b, const account_public_address& m uint64_t already_generated_coins; CRITICAL_REGION_BEGIN(m_blockchain_lock); - b.major_version = CURRENT_BLOCK_MAJOR_VERSION; - b.minor_version = CURRENT_BLOCK_MINOR_VERSION; + height = m_db->height(); + + b.major_version = m_hardfork->get_ideal_version(); + b.minor_version = 0; b.prev_id = get_tail_id(); b.timestamp = time(NULL); - height = m_db->height(); diffic = get_difficulty_for_next_block(); CHECK_AND_ASSERT_MES(diffic, false, "difficulty owverhead."); @@ -1622,7 +1650,7 @@ bool Blockchain::get_transactions(const t_ids_container& txs_ids, t_tx_container return true; } //------------------------------------------------------------------ -void Blockchain::print_blockchain(uint64_t start_index, uint64_t end_index) +void Blockchain::print_blockchain(uint64_t start_index, uint64_t end_index) const { LOG_PRINT_L3("Blockchain::" << __func__); std::stringstream ss; @@ -1642,7 +1670,7 @@ void Blockchain::print_blockchain(uint64_t start_index, uint64_t end_index) LOG_PRINT_L0("Blockchain printed with log level 1"); } //------------------------------------------------------------------ -void Blockchain::print_blockchain_index() +void Blockchain::print_blockchain_index() const { LOG_PRINT_L3("Blockchain::" << __func__); std::stringstream ss; @@ -1660,7 +1688,7 @@ void Blockchain::print_blockchain_index() } //------------------------------------------------------------------ //TODO: remove this function and references to it -void Blockchain::print_blockchain_outs(const std::string& file) +void Blockchain::print_blockchain_outs(const std::string& file) const { LOG_PRINT_L3("Blockchain::" << __func__); return; @@ -2245,6 +2273,13 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash& CRITICAL_REGION_LOCAL(m_blockchain_lock); TIME_MEASURE_START(t1); + // this is a cheap test + if (!m_hardfork->check(bl)) + { + LOG_PRINT_L1("Block with id: " << id << std::endl << "has old version: " << bl.major_version << std::endl << "current: " << m_hardfork->get_current_version()); + return false; + } + if(bl.prev_id != get_tail_id()) { LOG_PRINT_L1("Block with id: " << id << std::endl << "has wrong prev_id: " << bl.prev_id << std::endl << "expected: " << get_tail_id()); @@ -2521,6 +2556,9 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash& update_next_cumulative_size_limit(); + // this will not fail since check succeeded above + m_hardfork->add(bl, new_height - 1); + LOG_PRINT_L1("+++++ BLOCK SUCCESSFULLY ADDED" << std::endl << "id:\t" << id << std::endl << "PoW:\t" << proof_of_work << std::endl << "HEIGHT " << new_height << ", difficulty:\t" << current_diffic << std::endl << "block reward: " << print_money(fee_summary + base_reward) << "(" << print_money(base_reward) << " + " << print_money(fee_summary) << "), coinbase_blob_size: " << coinbase_blob_size << ", cumulative size: " << cumulative_block_size << ", " << block_processing_time << "(" << target_calculating_time << "/" << longhash_calculating_time << ")ms"); if(m_show_time_stats) { @@ -3054,3 +3092,13 @@ void Blockchain::set_user_options(uint64_t maxthreads, uint64_t blocks_per_sync, m_db_blocks_per_sync = blocks_per_sync; m_max_prepare_blocks_threads = maxthreads; } + +HardFork::State Blockchain::get_hard_fork_state() const +{ + return m_hardfork->get_state(); +} + +bool Blockchain::get_hard_fork_voting_info(uint8_t version, uint32_t &window, uint32_t &votes, uint32_t &threshold, uint8_t &voting) const +{ + return m_hardfork->get_voting_info(version, window, votes, threshold, voting); +} |