mirror of
https://github.com/monero-project/monero.git
synced 2025-08-02 04:46:13 -04:00
Add testnet flag
Source: cryptonotefoundation
This commit is contained in:
parent
32004a756c
commit
07470fd400
15 changed files with 137 additions and 52 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue