diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2015-12-13 11:38:37 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2015-12-13 11:38:37 +0000 |
commit | 10da0a0b7cc70fad0ffde60bdd04926484fb043a (patch) | |
tree | 01c2dc48aef06f5494c1782c76b080f0f7de9e21 /src | |
parent | unit_tests: fix block reward test using post hard fork settings (diff) | |
download | monero-10da0a0b7cc70fad0ffde60bdd04926484fb043a.tar.xz |
add a --fakechain argument for tests
The core tests use the blockchain, and reset it to be able
to add test data to it. This does not play nice with the
databases, since those will save that data without an explicit
save call.
We add a fakechain flag that the tests will set, which tells
the core and blockchain code to use a separate database, as
well as skip a few things like checkpoints and fixup, which
only make sense for real data.
Diffstat (limited to 'src')
-rw-r--r-- | src/common/command_line.cpp | 5 | ||||
-rw-r--r-- | src/common/command_line.h | 1 | ||||
-rw-r--r-- | src/cryptonote_core/blockchain.cpp | 11 | ||||
-rw-r--r-- | src/cryptonote_core/blockchain.h | 2 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_core.cpp | 11 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_core.h | 1 |
6 files changed, 23 insertions, 8 deletions
diff --git a/src/common/command_line.cpp b/src/common/command_line.cpp index 925b62a54..5e5a9ff44 100644 --- a/src/common/command_line.cpp +++ b/src/common/command_line.cpp @@ -91,4 +91,9 @@ namespace command_line , "Show time-stats when processing blocks/txs and disk synchronization." , 0 }; + const command_line::arg_descriptor<bool> arg_fakechain = { + "fakechain" + , "Use a fake chain for testing purposes." + , false + }; } diff --git a/src/common/command_line.h b/src/common/command_line.h index ffac71704..8955b826e 100644 --- a/src/common/command_line.h +++ b/src/common/command_line.h @@ -215,4 +215,5 @@ namespace command_line extern const arg_descriptor<uint64_t> arg_prep_blocks_threads; extern const arg_descriptor<uint64_t> arg_db_auto_remove_logs; extern const arg_descriptor<uint64_t> arg_show_time_stats; + extern const arg_descriptor<bool> arg_fakechain; } diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 195b5662e..5823c86f7 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -236,7 +236,7 @@ uint64_t Blockchain::get_current_blockchain_height() const //------------------------------------------------------------------ //FIXME: possibly move this into the constructor, to avoid accidentally // dereferencing a null BlockchainDB pointer -bool Blockchain::init(BlockchainDB* db, const bool testnet) +bool Blockchain::init(BlockchainDB* db, const bool testnet, const bool fakechain) { LOG_PRINT_L3("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); @@ -293,8 +293,11 @@ bool Blockchain::init(BlockchainDB* db, const bool testnet) { } - // ensure we fixup anything we found and fix in the future - m_db->fixup(); + if (!fakechain) + { + // ensure we fixup anything we found and fix in the future + m_db->fixup(); + } // check how far behind we are uint64_t top_block_timestamp = m_db->get_top_block_timestamp(); @@ -311,7 +314,7 @@ bool Blockchain::init(BlockchainDB* db, const bool testnet) m_async_pool.create_thread(boost::bind(&boost::asio::io_service::run, &m_async_service)); #if defined(PER_BLOCK_CHECKPOINT) - if (m_fast_sync && get_blocks_dat_start(testnet) != nullptr) + if (!fakechain && m_fast_sync && get_blocks_dat_start(testnet) != nullptr) { if (get_blocks_dat_size(testnet) > 4) { diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h index c83314634..f0b03ab0a 100644 --- a/src/cryptonote_core/blockchain.h +++ b/src/cryptonote_core/blockchain.h @@ -91,7 +91,7 @@ namespace cryptonote Blockchain(tx_memory_pool& tx_pool); - bool init(BlockchainDB* db, const bool testnet = false); + bool init(BlockchainDB* db, const bool testnet = false, const bool fakechain = false); bool deinit(); void set_checkpoints(checkpoints&& chk_pts) { m_checkpoints = chk_pts; } diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 2f21bd4f1..960c8eff8 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -97,7 +97,7 @@ namespace cryptonote //----------------------------------------------------------------------------------------------- bool core::update_checkpoints() { - if (m_testnet) return true; + if (m_testnet || m_fakechain) return true; if (m_checkpoints_updating.test_and_set()) return true; @@ -145,18 +145,20 @@ namespace cryptonote command_line::add_arg(desc, command_line::arg_db_sync_mode); command_line::add_arg(desc, command_line::arg_show_time_stats); command_line::add_arg(desc, command_line::arg_db_auto_remove_logs); + command_line::add_arg(desc, command_line::arg_fakechain); } //----------------------------------------------------------------------------------------------- bool core::handle_command_line(const boost::program_options::variables_map& vm) { m_testnet = command_line::get_arg(vm, command_line::arg_testnet_on); + m_fakechain = command_line::get_arg(vm, command_line::arg_fakechain); auto data_dir_arg = m_testnet ? command_line::arg_testnet_data_dir : command_line::arg_data_dir; m_config_folder = command_line::get_arg(vm, data_dir_arg); auto data_dir = boost::filesystem::path(m_config_folder); - if (!m_testnet) + if (!m_testnet && !m_fakechain) { cryptonote::checkpoints checkpoints; if (!cryptonote::create_checkpoints(checkpoints)) @@ -257,6 +259,9 @@ namespace cryptonote boost::filesystem::path folder(m_config_folder); + if (m_fakechain) + folder /= "fake"; + folder /= db->get_db_name(); LOG_PRINT_L0("Loading blockchain from folder " << folder.string() << " ..."); @@ -337,7 +342,7 @@ namespace cryptonote m_blockchain_storage.set_user_options(blocks_threads, blocks_per_sync, sync_mode, fast_sync); - r = m_blockchain_storage.init(db, m_testnet); + r = m_blockchain_storage.init(db, m_testnet, m_fakechain); bool show_time_stats = command_line::get_arg(vm, command_line::arg_show_time_stats) != 0; m_blockchain_storage.set_show_time_stats(show_time_stats); diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h index e7a6c4154..5d665cb98 100644 --- a/src/cryptonote_core/cryptonote_core.h +++ b/src/cryptonote_core/cryptonote_core.h @@ -199,6 +199,7 @@ namespace cryptonote uint64_t m_target_blockchain_height; bool m_testnet; + bool m_fakechain; std::string m_checkpoints_path; time_t m_last_dns_checkpoints_update; time_t m_last_json_checkpoints_update; |