aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2014-12-07 11:10:24 +0000
committerwarptangent <warptangent@inbox.com>2015-01-04 19:39:41 -0800
commita3157d7b697cc4313460c37a3e8740afc149b2d3 (patch)
tree6290f2656f0ab2ceaa07e97d99f2596ea1dae87d /src
parentblockchain_storage: add consts where appropriate (diff)
downloadmonero-a3157d7b697cc4313460c37a3e8740afc149b2d3.tar.xz
blockchain_storage: refactor genesis block creation
The existing assert is kept as it is stricter than the function's internal assert.
Diffstat (limited to 'src')
-rw-r--r--src/cryptonote_core/blockchain_storage.cpp20
-rw-r--r--src/cryptonote_core/blockchain_storage.h2
2 files changed, 6 insertions, 16 deletions
diff --git a/src/cryptonote_core/blockchain_storage.cpp b/src/cryptonote_core/blockchain_storage.cpp
index b3458ba47..11bd1f2ac 100644
--- a/src/cryptonote_core/blockchain_storage.cpp
+++ b/src/cryptonote_core/blockchain_storage.cpp
@@ -113,24 +113,14 @@ bool blockchain_storage::init(const std::string& config_folder, bool testnet)
else
{
LOG_PRINT_L0("Can't load blockchain storage from file, generating genesis block.");
- block bl = boost::value_initialized<block>();
- block_verification_context bvc = boost::value_initialized<block_verification_context>();
- if (testnet)
- {
- generate_genesis_block(bl, config::testnet::GENESIS_TX, config::testnet::GENESIS_NONCE);
- }
- else
- {
- generate_genesis_block(bl, config::GENESIS_TX, config::GENESIS_NONCE);
- }
- add_new_block(bl, bvc);
- CHECK_AND_ASSERT_MES(!bvc.m_verifivation_failed && bvc.m_added_to_main_chain, false, "Failed to add genesis block to blockchain");
+ if (!store_genesis_block(testnet, true))
+ return false;
}
if(!m_blocks.size())
{
LOG_PRINT_L0("Blockchain not loaded, generating genesis block.");
- if (!store_genesis_block(testnet)) {
+ if (!store_genesis_block(testnet, false)) {
return false;
}
} else {
@@ -159,7 +149,7 @@ bool blockchain_storage::init(const std::string& config_folder, bool testnet)
return true;
}
//------------------------------------------------------------------
-bool blockchain_storage::store_genesis_block(bool testnet) {
+bool blockchain_storage::store_genesis_block(bool testnet, bool check_added) {
block bl = ::boost::value_initialized<block>();
block_verification_context bvc = boost::value_initialized<block_verification_context>();
@@ -173,7 +163,7 @@ bool blockchain_storage::store_genesis_block(bool testnet) {
}
add_new_block(bl, bvc);
- CHECK_AND_ASSERT_MES(!bvc.m_verifivation_failed, false, "Failed to add genesis block to blockchain");
+ CHECK_AND_ASSERT_MES(!bvc.m_verifivation_failed && (bvc.m_added_to_main_chain || !check_added), false, "Failed to add genesis block to blockchain");
return true;
}
//------------------------------------------------------------------
diff --git a/src/cryptonote_core/blockchain_storage.h b/src/cryptonote_core/blockchain_storage.h
index 178ef38fd..e26d55b64 100644
--- a/src/cryptonote_core/blockchain_storage.h
+++ b/src/cryptonote_core/blockchain_storage.h
@@ -252,7 +252,7 @@ namespace cryptonote
uint64_t get_adjusted_time() const;
bool complete_timestamps_vector(uint64_t start_height, std::vector<uint64_t>& timestamps) const;
bool update_next_comulative_size_limit();
- bool store_genesis_block(bool testnet);
+ bool store_genesis_block(bool testnet, bool check_added = false);
};