diff options
author | Zachary Michaels <mikezackles@gmail.com> | 2014-07-16 13:30:15 -0400 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2014-09-15 15:53:01 +0200 |
commit | 07470fd400ee30b84f6227edffb24094d03781cb (patch) | |
tree | 6399848a2020528971884f5f625d0a2403f92327 /src/cryptonote_core | |
parent | increase ABSTRACT_SERVER_SEND_QUE_MAX_COUNT to a more sane value (diff) | |
download | monero-07470fd400ee30b84f6227edffb24094d03781cb.tar.xz |
Add testnet flag
Source: cryptonotefoundation
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r-- | src/cryptonote_core/blockchain_storage.cpp | 40 | ||||
-rw-r--r-- | src/cryptonote_core/blockchain_storage.h | 5 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_core.cpp | 4 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_core.h | 2 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_format_utils.cpp | 10 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_format_utils.h | 1 |
6 files changed, 51 insertions, 11 deletions
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>(); - block_verification_context bvc = boost::value_initialized<block_verification_context>(); - 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>(); + block_verification_context bvc = boost::value_initialized<block_verification_context>(); + + 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; diff --git a/src/cryptonote_core/blockchain_storage.h b/src/cryptonote_core/blockchain_storage.h index 55c0cb77e..0f7295516 100644 --- a/src/cryptonote_core/blockchain_storage.h +++ b/src/cryptonote_core/blockchain_storage.h @@ -81,8 +81,8 @@ namespace cryptonote blockchain_storage(tx_memory_pool& tx_pool):m_tx_pool(tx_pool), m_current_block_cumul_sz_limit(0), m_is_in_checkpoint_zone(false), m_is_blockchain_storing(false) {}; - bool init() { return init(tools::get_default_data_dir()); } - bool init(const std::string& config_folder); + bool init() { return init(tools::get_default_data_dir(), true); } + bool init(const std::string& config_folder, bool testnet = false); bool deinit(); void set_checkpoints(checkpoints&& chk_pts) { m_checkpoints = chk_pts; } @@ -242,6 +242,7 @@ namespace cryptonote uint64_t get_adjusted_time(); bool complete_timestamps_vector(uint64_t start_height, std::vector<uint64_t>& timestamps); bool update_next_comulative_size_limit(); + bool store_genesis_block(bool testnet); }; diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 637b8fea6..3ff139c95 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -116,14 +116,14 @@ namespace cryptonote return m_blockchain_storage.get_alternative_blocks_count(); } //----------------------------------------------------------------------------------------------- - bool core::init(const boost::program_options::variables_map& vm) + bool core::init(const boost::program_options::variables_map& vm, bool testnet) { bool r = handle_command_line(vm); r = m_mempool.init(m_config_folder); CHECK_AND_ASSERT_MES(r, false, "Failed to initialize memory pool"); - r = m_blockchain_storage.init(m_config_folder); + r = m_blockchain_storage.init(m_config_folder, testnet); CHECK_AND_ASSERT_MES(r, false, "Failed to initialize blockchain storage"); r = m_miner.init(vm); diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h index 704a65cf1..f050431ef 100644 --- a/src/cryptonote_core/cryptonote_core.h +++ b/src/cryptonote_core/cryptonote_core.h @@ -70,7 +70,7 @@ namespace cryptonote miner& get_miner(){return m_miner;} static void init_options(boost::program_options::options_description& desc); - bool init(const boost::program_options::variables_map& vm); + bool init(const boost::program_options::variables_map& vm, bool testnet); bool set_genesis_block(const block& b); bool deinit(); uint64_t get_current_blockchain_height(); diff --git a/src/cryptonote_core/cryptonote_format_utils.cpp b/src/cryptonote_core/cryptonote_format_utils.cpp index d023561c3..47cd0e159 100644 --- a/src/cryptonote_core/cryptonote_format_utils.cpp +++ b/src/cryptonote_core/cryptonote_format_utils.cpp @@ -686,6 +686,16 @@ namespace cryptonote miner::find_nonce_for_given_block(bl, 1, 0); return true; } + + bool generate_testnet_genesis_block(cryptonote::block& b) { + if (!generate_genesis_block(b)) { + return false; + } + + b.nonce += 1; + return true; + } + //--------------------------------------------------------------- bool get_block_longhash(const block& b, crypto::hash& res, uint64_t height) { diff --git a/src/cryptonote_core/cryptonote_format_utils.h b/src/cryptonote_core/cryptonote_format_utils.h index 9ed6c10a4..4457f6cc6 100644 --- a/src/cryptonote_core/cryptonote_format_utils.h +++ b/src/cryptonote_core/cryptonote_format_utils.h @@ -106,6 +106,7 @@ namespace cryptonote bool get_block_longhash(const block& b, crypto::hash& res, uint64_t height); crypto::hash get_block_longhash(const block& b, uint64_t height); bool generate_genesis_block(block& bl); + bool generate_testnet_genesis_block(block& bl); bool parse_and_validate_block_from_blob(const blobdata& b_blob, block& b); bool get_inputs_money_amount(const transaction& tx, uint64_t& money); uint64_t get_outs_money_amount(const transaction& tx); |