diff options
author | Riccardo Spagni <ric@spagni.net> | 2016-02-13 19:49:09 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2016-02-13 19:49:09 +0200 |
commit | 59c1a3316e520511c1c3c03d68ae8fd99b294cd4 (patch) | |
tree | fd86c3412666858ee2a789410a5704f5a3aae01e /src | |
parent | Merge pull request #650 (diff) | |
parent | unit_tests: fix blockchain unit test after hard fork import fix (diff) | |
download | monero-59c1a3316e520511c1c3c03d68ae8fd99b294cd4.tar.xz |
Merge pull request #651
5cb03a1 unit_tests: fix blockchain unit test after hard fork import fix (moneromooo-monero)
759383c hardfork: add a default fork entry for v1 if none exist (moneromooo-monero)
c7f82ec blockchain: initialize m_hardfork to NULL (moneromooo-monero)
8649b9f blockchain_db: pass hard fork object as a simple pointer (moneromooo-monero)
a333c42 core_tests: add tests for hard fork behaviors (MRL-0004) (moneromooo-monero)
945fe90 core_tests: allow setting miner tx max_outs when creating a block (moneromooo-monero)
8e4c2e6 unit_tests: fix hard fork unit test compilation (moneromooo-monero)
9ef5794 blockchain_utilities: remove unused num_blocks variable (moneromooo-monero)
6c8e5c3 blockchain: reset hardfork object when resetting blockchain (moneromooo-monero)
Diffstat (limited to 'src')
-rw-r--r-- | src/blockchain_db/blockchain_db.cpp | 2 | ||||
-rw-r--r-- | src/blockchain_db/blockchain_db.h | 2 | ||||
-rw-r--r-- | src/blockchain_utilities/blocksdat_file.cpp | 2 | ||||
-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 | 23 | ||||
-rw-r--r-- | src/cryptonote_core/blockchain.h | 5 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_core.cpp | 7 | ||||
-rw-r--r-- | src/cryptonote_core/cryptonote_core.h | 6 | ||||
-rw-r--r-- | src/cryptonote_core/hardfork.cpp | 5 |
10 files changed, 35 insertions, 23 deletions
diff --git a/src/blockchain_db/blockchain_db.cpp b/src/blockchain_db/blockchain_db.cpp index 270b5399e..68bef3892 100644 --- a/src/blockchain_db/blockchain_db.cpp +++ b/src/blockchain_db/blockchain_db.cpp @@ -139,7 +139,7 @@ uint64_t BlockchainDB::add_block( const block& blk return prev_height; } -void BlockchainDB::set_hard_fork(HardFork*& hf) +void BlockchainDB::set_hard_fork(HardFork* hf) { m_hardfork = hf; } diff --git a/src/blockchain_db/blockchain_db.h b/src/blockchain_db/blockchain_db.h index 5926f34a5..bb4602061 100644 --- a/src/blockchain_db/blockchain_db.h +++ b/src/blockchain_db/blockchain_db.h @@ -377,7 +377,7 @@ public: virtual void block_txn_stop() = 0; virtual void block_txn_abort() = 0; - virtual void set_hard_fork(HardFork*& hf); + virtual void set_hard_fork(HardFork* hf); // adds a block with the given metadata to the top of the blockchain, returns the new height // NOTE: subclass implementations of this (or the functions it calls) need diff --git a/src/blockchain_utilities/blocksdat_file.cpp b/src/blockchain_utilities/blocksdat_file.cpp index aba618034..81b56d55e 100644 --- a/src/blockchain_utilities/blocksdat_file.cpp +++ b/src/blockchain_utilities/blocksdat_file.cpp @@ -66,8 +66,6 @@ bool BlocksdatFile::open_writer(const boost::filesystem::path& file_path, uint64 m_raw_data_file = new std::ofstream(); - uint64_t num_blocks = 0; - LOG_PRINT_L0("creating file"); m_raw_data_file->open(file_path.string(), std::ios_base::binary | std::ios_base::out | std::ios::trunc); diff --git a/src/common/command_line.cpp b/src/common/command_line.cpp index b643f5135..98ff73bc5 100644 --- a/src/common/command_line.cpp +++ b/src/common/command_line.cpp @@ -91,9 +91,4 @@ 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 2fa213a21..75dc4b9fd 100644 --- a/src/common/command_line.h +++ b/src/common/command_line.h @@ -215,5 +215,4 @@ 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 f9247ae27..a3eb21187 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -50,6 +50,7 @@ #include "warnings.h" #include "crypto/hash.h" #include "cryptonote_core/checkpoints_create.h" +#include "cryptonote_core/cryptonote_core.h" #if defined(PER_BLOCK_CHECKPOINT) #include "blocks/blocks.h" #endif @@ -99,7 +100,7 @@ static const uint64_t testnet_hard_fork_version_1_till = 624633; //------------------------------------------------------------------ Blockchain::Blockchain(tx_memory_pool& tx_pool) : - m_db(), m_tx_pool(tx_pool), m_hardfork(), m_timestamps_and_difficulties_height(0), m_current_block_cumul_sz_limit(0), m_is_in_checkpoint_zone(false), + m_db(), m_tx_pool(tx_pool), m_hardfork(NULL), m_timestamps_and_difficulties_height(0), m_current_block_cumul_sz_limit(0), m_is_in_checkpoint_zone(false), m_is_blockchain_storing(false), m_enforce_dns_checkpoints(false), m_max_prepare_blocks_threads(4), m_db_blocks_per_sync(1), m_db_sync_mode(db_async), m_fast_sync(true), m_sync_counter(0) { LOG_PRINT_L3("Blockchain::" << __func__); @@ -252,11 +253,13 @@ 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, const bool fakechain) +bool Blockchain::init(BlockchainDB* db, const bool testnet, const cryptonote::test_options *test_options) { LOG_PRINT_L3("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_blockchain_lock); + bool fakechain = test_options != NULL; + if (db == nullptr) { LOG_ERROR("Attempted to init Blockchain with null DB"); @@ -273,12 +276,19 @@ bool Blockchain::init(BlockchainDB* db, const bool testnet, const bool fakechain m_testnet = testnet; if (m_hardfork == nullptr) { - if (m_testnet) + if (fakechain) + m_hardfork = new HardFork(*db, 1, 0); + else if (m_testnet) m_hardfork = new HardFork(*db, 1, testnet_hard_fork_version_1_till); else m_hardfork = new HardFork(*db, 1, mainnet_hard_fork_version_1_till); } - if (m_testnet) + if (fakechain) + { + for (size_t n = 0; test_options->hard_forks[n].first; ++n) + m_hardfork->add_fork(test_options->hard_forks[n].first, test_options->hard_forks[n].second, 0, n + 1); + } + else if (m_testnet) { for (size_t n = 0; n < sizeof(testnet_hard_forks) / sizeof(testnet_hard_forks[0]); ++n) m_hardfork->add_fork(testnet_hard_forks[n].version, testnet_hard_forks[n].height, testnet_hard_forks[n].threshold, testnet_hard_forks[n].time); @@ -348,11 +358,11 @@ bool Blockchain::init(BlockchainDB* db, const bool testnet, const bool fakechain return true; } //------------------------------------------------------------------ -bool Blockchain::init(BlockchainDB* db, HardFork*& hf, const bool testnet, const bool fakechain) +bool Blockchain::init(BlockchainDB* db, HardFork*& hf, const bool testnet) { if (hf != nullptr) m_hardfork = hf; - bool res = init(db, testnet, fakechain); + bool res = init(db, testnet, NULL); if (hf == nullptr) hf = m_hardfork; return res; @@ -494,6 +504,7 @@ bool Blockchain::reset_and_set_genesis_block(const block& b) CRITICAL_REGION_LOCAL(m_blockchain_lock); m_alternative_chains.clear(); m_db->reset(); + m_hardfork->init(); block_verification_context bvc = boost::value_initialized<block_verification_context>(); add_new_block(b, bvc); diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h index 5299fed99..ab2c8f9e8 100644 --- a/src/cryptonote_core/blockchain.h +++ b/src/cryptonote_core/blockchain.h @@ -58,6 +58,7 @@ namespace cryptonote { class tx_memory_pool; + struct test_options; enum blockchain_db_sync_mode { @@ -91,8 +92,8 @@ namespace cryptonote Blockchain(tx_memory_pool& tx_pool); - bool init(BlockchainDB* db, const bool testnet = false, const bool fakechain = false); - bool init(BlockchainDB* db, HardFork*& hf, const bool testnet = false, const bool fakechain = false); + bool init(BlockchainDB* db, const bool testnet = false, const cryptonote::test_options *test_options = NULL); + bool init(BlockchainDB* db, HardFork*& hf, const bool testnet = 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 2479931be..2c485d791 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -145,13 +145,11 @@ 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); @@ -251,8 +249,9 @@ namespace cryptonote return true; } //----------------------------------------------------------------------------------------------- - bool core::init(const boost::program_options::variables_map& vm) + bool core::init(const boost::program_options::variables_map& vm, const cryptonote::test_options *test_options) { + m_fakechain = test_options != NULL; bool r = handle_command_line(vm); r = m_mempool.init(m_fakechain ? std::string() : m_config_folder); @@ -398,7 +397,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, m_fakechain); + r = m_blockchain_storage.init(db, m_testnet, test_options); // now that we have a valid m_blockchain_storage, we can clean out any // transactions in the pool that do not conform to the current fork diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h index 90fdfefca..3c6f56749 100644 --- a/src/cryptonote_core/cryptonote_core.h +++ b/src/cryptonote_core/cryptonote_core.h @@ -56,6 +56,10 @@ DISABLE_VS_WARNINGS(4355) namespace cryptonote { + struct test_options { + const std::pair<uint8_t, uint64_t> *hard_forks; + }; + /************************************************************************/ /* */ /************************************************************************/ @@ -81,7 +85,7 @@ namespace cryptonote miner& get_miner(){return m_miner;} const miner& get_miner()const{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, const test_options *test_options = NULL); bool set_genesis_block(const block& b); bool deinit(); static void set_fast_exit(); diff --git a/src/cryptonote_core/hardfork.cpp b/src/cryptonote_core/hardfork.cpp index 9fe731ad1..e99736ff4 100644 --- a/src/cryptonote_core/hardfork.cpp +++ b/src/cryptonote_core/hardfork.cpp @@ -155,6 +155,11 @@ bool HardFork::add(const cryptonote::block &block, uint64_t height) void HardFork::init() { CRITICAL_REGION_LOCAL(lock); + + // add a placeholder for the default version, to avoid special cases + if (heights.empty()) + heights.push_back(Params(original_version, 0, 0, 0)); + versions.clear(); for (size_t n = 0; n < 256; ++n) last_versions[n] = 0; |