From f141869cac2c099da0e121c4723951d4ac7c36f6 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Wed, 9 Dec 2015 17:30:30 +0000 Subject: [PATCH 01/13] tests: remove data-dir argument registration It is already registered in cryptonote::core::init_options, which we now call --- tests/core_tests/chaingen.h | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index 0c33b942..7c989b94 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -474,7 +474,6 @@ inline bool do_replay_events(std::vector& events) { boost::program_options::options_description desc("Allowed options"); cryptonote::core::init_options(desc); - command_line::add_arg(desc, command_line::arg_data_dir); boost::program_options::variables_map vm; bool r = command_line::handle_error_helper(desc, [&]() { From 015b68a2bea655f957ee3279b76a62604d6096f7 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 13 Dec 2015 11:08:59 +0000 Subject: [PATCH 02/13] db_bdb: create all needed directories, not just the leaf one --- src/blockchain_db/berkeleydb/db_bdb.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp index ce355ccd..f30e156c 100644 --- a/src/blockchain_db/berkeleydb/db_bdb.cpp +++ b/src/blockchain_db/berkeleydb/db_bdb.cpp @@ -759,7 +759,7 @@ void BlockchainBDB::open(const std::string& filename, const int db_flags) } else { - if (!boost::filesystem::create_directory(direc)) + if (!boost::filesystem::create_directories(direc)) throw0(DB_OPEN_FAILURE(std::string("Failed to create directory ").append(filename).c_str())); } From 14945576335a3e5aa292a4af61d37e9ef88e7858 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 13 Dec 2015 11:09:43 +0000 Subject: [PATCH 03/13] db_lmdb: create all needed directories, not just the leaf one --- src/blockchain_db/lmdb/db_lmdb.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index de806612..2bddcc6f 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -943,7 +943,7 @@ void BlockchainLMDB::open(const std::string& filename, const int mdb_flags) } else { - if (!boost::filesystem::create_directory(direc)) + if (!boost::filesystem::create_directories(direc)) throw0(DB_OPEN_FAILURE(std::string("Failed to create directory ").append(filename).c_str())); } From 44f1267a39db7db57d99612516bdc080145ebb37 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 13 Dec 2015 11:10:33 +0000 Subject: [PATCH 04/13] tests: fix a typo in test name --- tests/unit_tests/checkpoints.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/checkpoints.cpp b/tests/unit_tests/checkpoints.cpp index 2f70791c..85a8c9a9 100644 --- a/tests/unit_tests/checkpoints.cpp +++ b/tests/unit_tests/checkpoints.cpp @@ -35,7 +35,7 @@ using namespace cryptonote; -TEST(checkpoints_is_alternative_block_allowed, handles_empty_checkpoins) +TEST(checkpoints_is_alternative_block_allowed, handles_empty_checkpoints) { checkpoints cp; From 18bf06e4a587b49c37451ba3d327a336db9bfe67 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 13 Dec 2015 11:11:00 +0000 Subject: [PATCH 05/13] tx_pool: fix "minumim" typo in message --- src/cryptonote_core/tx_pool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index defbeb3b..e2dcd35f 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -113,7 +113,7 @@ namespace cryptonote needed_fee *= FEE_PER_KB; if (!kept_by_block && fee < needed_fee /*&& fee < MINING_ALLOWED_LEGACY_FEE*/) { - LOG_PRINT_L1("transaction fee is not enough: " << print_money(fee) << ", minumim fee: " << print_money(needed_fee)); + LOG_PRINT_L1("transaction fee is not enough: " << print_money(fee) << ", minimum fee: " << print_money(needed_fee)); tvc.m_verifivation_failed = true; return false; } From 4833f4f96f4aa97cc01c672a71e76a32caf9efa0 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 13 Dec 2015 11:12:00 +0000 Subject: [PATCH 06/13] db_bdb: implement BlockchainBDB::reset It is needed by the core tests --- src/blockchain_db/berkeleydb/db_bdb.cpp | 41 ++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp index f30e156c..07cb622a 100644 --- a/src/blockchain_db/berkeleydb/db_bdb.cpp +++ b/src/blockchain_db/berkeleydb/db_bdb.cpp @@ -1042,7 +1042,46 @@ void BlockchainBDB::sync() void BlockchainBDB::reset() { LOG_PRINT_L3("BlockchainBDB::" << __func__); - // TODO: this + check_open(); + + bdb_txn_safe txn; + if (m_env->txn_begin(NULL, txn, 0)) + throw0(DB_ERROR("Failed to create a transaction for the db")); + m_write_txn = &txn; + try + { + uint32_t count; + + m_blocks->truncate(*m_write_txn, &count, 0); + m_block_heights->truncate(*m_write_txn, &count, 0); + m_block_hashes->truncate(*m_write_txn, &count, 0); + m_block_timestamps->truncate(*m_write_txn, &count, 0); + m_block_sizes->truncate(*m_write_txn, &count, 0); + m_block_diffs->truncate(*m_write_txn, &count, 0); + m_block_coins->truncate(*m_write_txn, &count, 0); + + m_txs->truncate(*m_write_txn, &count, 0); + m_tx_unlocks->truncate(*m_write_txn, &count, 0); + m_tx_heights->truncate(*m_write_txn, &count, 0); + m_tx_outputs->truncate(*m_write_txn, &count, 0); + + m_output_txs->truncate(*m_write_txn, &count, 0); + m_output_indices->truncate(*m_write_txn, &count, 0); + m_output_amounts->truncate(*m_write_txn, &count, 0); + m_output_keys->truncate(*m_write_txn, &count, 0); + + m_spent_keys->truncate(*m_write_txn, &count, 0); + + m_hf_starting_heights->truncate(*m_write_txn, &count, 0); + m_hf_versions->truncate(*m_write_txn, &count, 0); + + m_properties->truncate(*m_write_txn, &count, 0); + } + catch (const std::exception& e) + { + throw0(DB_ERROR(std::string("Failed to reset database: ").append(e.what()).c_str())); + } + m_write_txn = NULL; } std::vector BlockchainBDB::get_filenames() const From 8af913a3d183b9f30106caaedba007c055ad945e Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 13 Dec 2015 11:12:34 +0000 Subject: [PATCH 07/13] db_lmdb: implement BlockchainLMDB::reset It is needed by the core tests --- src/blockchain_db/lmdb/db_lmdb.cpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index 2bddcc6f..62f1b39f 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -1159,7 +1159,33 @@ void BlockchainLMDB::sync() void BlockchainLMDB::reset() { LOG_PRINT_L3("BlockchainLMDB::" << __func__); - // TODO: this + check_open(); + + mdb_txn_safe txn; + if (mdb_txn_begin(m_env, NULL, 0, txn)) + throw0(DB_ERROR("Failed to create a transaction for the db")); + mdb_drop(txn, m_blocks, 0); + mdb_drop(txn, m_block_timestamps, 0); + mdb_drop(txn, m_block_heights, 0); + mdb_drop(txn, m_block_hashes, 0); + mdb_drop(txn, m_block_sizes, 0); + mdb_drop(txn, m_block_diffs, 0); + mdb_drop(txn, m_block_coins, 0); + mdb_drop(txn, m_txs, 0); + mdb_drop(txn, m_tx_unlocks, 0); + mdb_drop(txn, m_tx_heights, 0); + mdb_drop(txn, m_tx_outputs, 0); + mdb_drop(txn, m_output_txs, 0); + mdb_drop(txn, m_output_indices, 0); + mdb_drop(txn, m_output_amounts, 0); + mdb_drop(txn, m_output_keys, 0); + mdb_drop(txn, m_spent_keys, 0); + mdb_drop(txn, m_hf_starting_heights, 0); + mdb_drop(txn, m_hf_versions, 0); + mdb_drop(txn, m_properties, 0); + txn.commit(); + m_height = 0; + m_num_outputs = 0; } std::vector BlockchainLMDB::get_filenames() const From 2369968dc3bf592b350c6d7852aa2fa73537bc81 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 13 Dec 2015 11:16:07 +0000 Subject: [PATCH 08/13] blockchain: fix off by one in get_blocks --- src/cryptonote_core/blockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 2d71b61a..41fb71c6 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -1361,7 +1361,7 @@ bool Blockchain::get_blocks(uint64_t start_offset, size_t count, std::list m_db->height()) return false; - for(size_t i = start_offset; i < start_offset + count && i <= m_db->height();i++) + for(size_t i = start_offset; i < start_offset + count && i < m_db->height();i++) { blocks.push_back(m_db->get_block_from_height(i)); } From 595893fcbab8a370d98066e5c08378a10841fc4c Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 13 Dec 2015 11:16:37 +0000 Subject: [PATCH 09/13] blockchain: log block (not chain) height in "BLOCK SUCCESFULLY ADDED" This makes it log the same height as the original code, which is less confusing when comparing behaviors. --- src/cryptonote_core/blockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 41fb71c6..195b5662 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -2631,7 +2631,7 @@ bool Blockchain::handle_block_to_main_chain(const block& bl, const crypto::hash& // do this after updating the hard fork state since the size limit may change due to fork update_next_cumulative_size_limit(); - LOG_PRINT_L1("+++++ BLOCK SUCCESSFULLY ADDED" << std::endl << "id:\t" << id << std::endl << "PoW:\t" << proof_of_work << std::endl << "HEIGHT " << new_height << ", difficulty:\t" << current_diffic << std::endl << "block reward: " << print_money(fee_summary + base_reward) << "(" << print_money(base_reward) << " + " << print_money(fee_summary) << "), coinbase_blob_size: " << coinbase_blob_size << ", cumulative size: " << cumulative_block_size << ", " << block_processing_time << "(" << target_calculating_time << "/" << longhash_calculating_time << ")ms"); + LOG_PRINT_L1("+++++ BLOCK SUCCESSFULLY ADDED" << std::endl << "id:\t" << id << std::endl << "PoW:\t" << proof_of_work << std::endl << "HEIGHT " << new_height-1 << ", difficulty:\t" << current_diffic << std::endl << "block reward: " << print_money(fee_summary + base_reward) << "(" << print_money(base_reward) << " + " << print_money(fee_summary) << "), coinbase_blob_size: " << coinbase_blob_size << ", cumulative size: " << cumulative_block_size << ", " << block_processing_time << "(" << target_calculating_time << "/" << longhash_calculating_time << ")ms"); if(m_show_time_stats) { LOG_PRINT_L0("Height: " << new_height << " blob: " << coinbase_blob_size << " cumm: " From eee44e62bc924f82bb4371bc28ff8992450e04c5 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 13 Dec 2015 11:18:59 +0000 Subject: [PATCH 10/13] unit_tests: fix block reward test using post hard fork settings This would fail, as the post hard fork settings would yield different data, and the test expects pre hard fork data. --- tests/unit_tests/block_reward.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/unit_tests/block_reward.cpp b/tests/unit_tests/block_reward.cpp index 308ef299..125cad82 100644 --- a/tests/unit_tests/block_reward.cpp +++ b/tests/unit_tests/block_reward.cpp @@ -40,7 +40,7 @@ namespace class block_reward_and_already_generated_coins : public ::testing::Test { protected: - static const size_t current_block_size = CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE / 2; + static const size_t current_block_size = CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 / 2; bool m_block_not_too_big; uint64_t m_block_reward; @@ -81,7 +81,7 @@ namespace { m_block_not_too_big = get_block_reward(0, 0, already_generated_coins, m_standard_block_reward, 1); ASSERT_TRUE(m_block_not_too_big); - ASSERT_LT(CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE, m_standard_block_reward); + ASSERT_LT(CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1, m_standard_block_reward); } void do_test(size_t median_block_size, size_t current_block_size) @@ -98,28 +98,28 @@ namespace TEST_F(block_reward_and_current_block_size, handles_block_size_less_relevance_level) { - do_test(0, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE - 1); + do_test(0, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 - 1); ASSERT_TRUE(m_block_not_too_big); ASSERT_EQ(m_block_reward, m_standard_block_reward); } TEST_F(block_reward_and_current_block_size, handles_block_size_eq_relevance_level) { - do_test(0, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE); + do_test(0, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1); ASSERT_TRUE(m_block_not_too_big); ASSERT_EQ(m_block_reward, m_standard_block_reward); } TEST_F(block_reward_and_current_block_size, handles_block_size_gt_relevance_level) { - do_test(0, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE + 1); + do_test(0, CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 + 1); ASSERT_TRUE(m_block_not_too_big); ASSERT_LT(m_block_reward, m_standard_block_reward); } TEST_F(block_reward_and_current_block_size, handles_block_size_less_2_relevance_level) { - do_test(0, 2 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE - 1); + do_test(0, 2 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 - 1); ASSERT_TRUE(m_block_not_too_big); ASSERT_LT(m_block_reward, m_standard_block_reward); ASSERT_LT(0, m_block_reward); @@ -127,14 +127,14 @@ namespace TEST_F(block_reward_and_current_block_size, handles_block_size_eq_2_relevance_level) { - do_test(0, 2 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE); + do_test(0, 2 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1); ASSERT_TRUE(m_block_not_too_big); ASSERT_EQ(0, m_block_reward); } TEST_F(block_reward_and_current_block_size, handles_block_size_gt_2_relevance_level) { - do_test(0, 2 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE + 1); + do_test(0, 2 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1 + 1); ASSERT_FALSE(m_block_not_too_big); } @@ -160,17 +160,17 @@ namespace protected: virtual void SetUp() { - m_last_block_sizes.push_back(3 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE); - m_last_block_sizes.push_back(5 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE); - m_last_block_sizes.push_back(7 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE); - m_last_block_sizes.push_back(11 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE); - m_last_block_sizes.push_back(13 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE); + m_last_block_sizes.push_back(3 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1); + m_last_block_sizes.push_back(5 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1); + m_last_block_sizes.push_back(7 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1); + m_last_block_sizes.push_back(11 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1); + m_last_block_sizes.push_back(13 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1); - m_last_block_sizes_median = 7 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE; + m_last_block_sizes_median = 7 * CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1; m_block_not_too_big = get_block_reward(epee::misc_utils::median(m_last_block_sizes), 0, already_generated_coins, m_standard_block_reward, 1); ASSERT_TRUE(m_block_not_too_big); - ASSERT_LT(CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE, m_standard_block_reward); + ASSERT_LT(CRYPTONOTE_BLOCK_GRANTED_FULL_REWARD_ZONE_V1, m_standard_block_reward); } void do_test(size_t current_block_size) From 10da0a0b7cc70fad0ffde60bdd04926484fb043a Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 13 Dec 2015 11:38:37 +0000 Subject: [PATCH 11/13] 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. --- src/common/command_line.cpp | 5 +++++ src/common/command_line.h | 1 + src/cryptonote_core/blockchain.cpp | 11 +++++++---- src/cryptonote_core/blockchain.h | 2 +- src/cryptonote_core/cryptonote_core.cpp | 11 ++++++++--- src/cryptonote_core/cryptonote_core.h | 1 + tests/core_tests/chaingen.h | 4 ++++ 7 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/common/command_line.cpp b/src/common/command_line.cpp index 925b62a5..5e5a9ff4 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 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 ffac7170..8955b826 100644 --- a/src/common/command_line.h +++ b/src/common/command_line.h @@ -215,4 +215,5 @@ namespace command_line extern const arg_descriptor arg_prep_blocks_threads; extern const arg_descriptor arg_db_auto_remove_logs; extern const arg_descriptor arg_show_time_stats; + extern const arg_descriptor arg_fakechain; } diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 195b5662..5823c86f 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 c8331463..f0b03ab0 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 2f21bd4f..960c8eff 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 e7a6c415..5d665cb9 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; diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index 7c989b94..fdcb6239 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -484,6 +484,10 @@ inline bool do_replay_events(std::vector& events) if (!r) return false; + // hardcode a --fakechain option for tests + static const char * const fakechain[] = {"", "--fakechain"}; + boost::program_options::store(boost::program_options::parse_command_line(2, fakechain, desc), vm); + cryptonote::cryptonote_protocol_stub pr; //TODO: stub only for this kind of test, make real validation of relayed objects cryptonote::core c(&pr); // FIXME: make sure that vm has arg_testnet_on set to true or false if From c3d208fcbe7d32d2764a3cb8fae5653ae5de0f49 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 13 Dec 2015 13:56:15 +0000 Subject: [PATCH 12/13] core_tests: bump default test fee to 0.02 monero The current monero consensus uses 0.01 per kB fees, so use enough for 2 kB transactions for now. It'll probably have to be either bumped further or changed to calculate the proper fee. --- tests/core_tests/chaingen.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/core_tests/chaingen.h b/tests/core_tests/chaingen.h index fdcb6239..822ccfb1 100644 --- a/tests/core_tests/chaingen.h +++ b/tests/core_tests/chaingen.h @@ -674,4 +674,4 @@ inline bool do_replay_file(const std::string& filename) #define CHECK_EQ(v1, v2) CHECK_AND_ASSERT_MES(v1 == v2, false, "[" << perr_context << "] failed: \"" << QUOTEME(v1) << " == " << QUOTEME(v2) << "\", " << v1 << " != " << v2) #define CHECK_NOT_EQ(v1, v2) CHECK_AND_ASSERT_MES(!(v1 == v2), false, "[" << perr_context << "] failed: \"" << QUOTEME(v1) << " != " << QUOTEME(v2) << "\", " << v1 << " == " << v2) #define MK_COINS(amount) (UINT64_C(amount) * COIN) -#define TESTS_DEFAULT_FEE ((uint64_t)1000000) // pow(10, 6) +#define TESTS_DEFAULT_FEE ((uint64_t)20000000000) // 2 * pow(10, 10) From cbded439f45c5867e76758825f70284daca2eb47 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Sun, 13 Dec 2015 13:58:13 +0000 Subject: [PATCH 13/13] core_tests: fix ring_signature_1 tests They were trying to send too much monero, and thus failing. The parameters were set in such a way that the (simple) output gathering code could fulfill them for 4 block rewards for the original Bytecoin emission, but that does not work with monero so we need to use smaller values. --- tests/core_tests/ring_signature_1.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/core_tests/ring_signature_1.cpp b/tests/core_tests/ring_signature_1.cpp index 15b6531c..b37b55cc 100644 --- a/tests/core_tests/ring_signature_1.cpp +++ b/tests/core_tests/ring_signature_1.cpp @@ -144,7 +144,7 @@ gen_ring_signature_2::gen_ring_signature_2() } /** - * Bob has 4 inputs by 61 coins. He sends 4 * 61 coins to Alice, using ring signature with nmix = 3. Each Bob's input + * Bob has 4 inputs by 13 coins. He sends 4 * 13 coins to Alice, using ring signature with nmix = 3. Each Bob's input * is used as mix for 3 others. */ bool gen_ring_signature_2::generate(std::vector& events) const @@ -161,14 +161,14 @@ bool gen_ring_signature_2::generate(std::vector& events) const MAKE_NEXT_BLOCK(events, blk_2, blk_1, miner_account); // 4 MAKE_NEXT_BLOCK(events, blk_3, blk_2, miner_account); // 5 REWIND_BLOCKS(events, blk_3r, blk_3, miner_account); // - MAKE_TX_LIST_START(events, txs_blk_4, miner_account, bob_account, MK_COINS(61), blk_3); // 6 + N - MAKE_TX_LIST(events, txs_blk_4, miner_account, bob_account, MK_COINS(61), blk_3); // 7 + N - MAKE_TX_LIST(events, txs_blk_4, miner_account, bob_account, MK_COINS(61), blk_3); // 8 + N - MAKE_TX_LIST(events, txs_blk_4, miner_account, bob_account, MK_COINS(61), blk_3); // 9 + N + MAKE_TX_LIST_START(events, txs_blk_4, miner_account, bob_account, MK_COINS(13), blk_3); // 6 + N + MAKE_TX_LIST(events, txs_blk_4, miner_account, bob_account, MK_COINS(13), blk_3); // 7 + N + MAKE_TX_LIST(events, txs_blk_4, miner_account, bob_account, MK_COINS(13), blk_3); // 8 + N + MAKE_TX_LIST(events, txs_blk_4, miner_account, bob_account, MK_COINS(13), blk_3); // 9 + N MAKE_NEXT_BLOCK_TX_LIST(events, blk_4, blk_3r, miner_account, txs_blk_4); // 10 + N DO_CALLBACK(events, "check_balances_1"); // 11 + N REWIND_BLOCKS(events, blk_4r, blk_4, miner_account); // - MAKE_TX_MIX(events, tx_0, bob_account, alice_account, MK_COINS(244) - TESTS_DEFAULT_FEE, 3, blk_4); // 12 + 2N + MAKE_TX_MIX(events, tx_0, bob_account, alice_account, MK_COINS(52) - TESTS_DEFAULT_FEE, 3, blk_4); // 12 + 2N MAKE_NEXT_BLOCK_TX1(events, blk_5, blk_4r, miner_account, tx_0); // 13 + 2N DO_CALLBACK(events, "check_balances_2"); // 14 + 2N @@ -190,7 +190,7 @@ bool gen_ring_signature_2::check_balances_1(cryptonote::core& c, size_t ev_index map_hash2tx_t mtx; r = find_block_chain(events, chain, mtx, get_block_hash(blocks.back())); CHECK_TEST_CONDITION(r); - CHECK_EQ(MK_COINS(244), get_balance(m_bob_account, chain, mtx)); + CHECK_EQ(MK_COINS(52), get_balance(m_bob_account, chain, mtx)); CHECK_EQ(0, get_balance(m_alice_account, chain, mtx)); return true; @@ -209,7 +209,7 @@ bool gen_ring_signature_2::check_balances_2(cryptonote::core& c, size_t ev_index r = find_block_chain(events, chain, mtx, get_block_hash(blocks.back())); CHECK_TEST_CONDITION(r); CHECK_EQ(0, get_balance(m_bob_account, chain, mtx)); - CHECK_EQ(MK_COINS(244) - TESTS_DEFAULT_FEE, get_balance(m_alice_account, chain, mtx)); + CHECK_EQ(MK_COINS(52) - TESTS_DEFAULT_FEE, get_balance(m_alice_account, chain, mtx)); return true; }