From 07470fd400ee30b84f6227edffb24094d03781cb Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 16 Jul 2014 13:30:15 -0400 Subject: Add testnet flag Source: cryptonotefoundation --- src/cryptonote_core/blockchain_storage.cpp | 40 +++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 6 deletions(-) (limited to 'src/cryptonote_core/blockchain_storage.cpp') diff --git a/src/cryptonote_core/blockchain_storage.cpp b/src/cryptonote_core/blockchain_storage.cpp index c80cec92c..cd20cd818 100644 --- a/src/cryptonote_core/blockchain_storage.cpp +++ b/src/cryptonote_core/blockchain_storage.cpp @@ -82,7 +82,7 @@ uint64_t blockchain_storage::get_current_blockchain_height() return m_blocks.size(); } //------------------------------------------------------------------ -bool blockchain_storage::init(const std::string& config_folder) +bool blockchain_storage::init(const std::string& config_folder, bool testnet) { CRITICAL_REGION_LOCAL(m_blockchain_lock); m_config_folder = config_folder; @@ -121,11 +121,24 @@ bool blockchain_storage::init(const std::string& config_folder) if(!m_blocks.size()) { LOG_PRINT_L0("Blockchain not loaded, generating genesis block."); - block bl = boost::value_initialized(); - block_verification_context bvc = boost::value_initialized(); - generate_genesis_block(bl); - add_new_block(bl, bvc); - CHECK_AND_ASSERT_MES(!bvc.m_verifivation_failed, false, "Failed to add genesis block to blockchain"); + + if (!store_genesis_block(testnet)) { + return false; + } + } else { + cryptonote::block b; + if (testnet) { + generate_testnet_genesis_block(b); + } else { + generate_genesis_block(b); + } + + crypto::hash genesis_hash = get_block_hash(m_blocks[0].bl); + crypto::hash testnet_genesis_hash = get_block_hash(b); + if (genesis_hash != testnet_genesis_hash) { + LOG_ERROR("Failed to init: genesis block mismatch. Probably you set --testnet flag with data dir with non-test blockchain or another network."); + return false; + } } uint64_t timestamp_diff = time(NULL) - m_blocks.back().bl.timestamp; if(!m_blocks.back().bl.timestamp) @@ -134,6 +147,21 @@ bool blockchain_storage::init(const std::string& config_folder) return true; } //------------------------------------------------------------------ +bool blockchain_storage::store_genesis_block(bool testnet) { + block bl = ::boost::value_initialized(); + block_verification_context bvc = boost::value_initialized(); + + if (testnet) { + generate_testnet_genesis_block(bl); + } else { + generate_genesis_block(bl); + } + + add_new_block(bl, bvc); + CHECK_AND_ASSERT_MES(!bvc.m_verifivation_failed, false, "Failed to add genesis block to blockchain"); + return true; +} +//------------------------------------------------------------------ bool blockchain_storage::store_blockchain() { m_is_blockchain_storing = true; -- cgit v1.2.3