From 6c8e5c34598b4a9c7a80630fe2bb854ad5def016 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Mon, 8 Feb 2016 18:21:42 +0000 Subject: blockchain: reset hardfork object when resetting blockchain Not doing so will prevent the new genesis block from being reset if a switch past v1 had occured already. --- src/cryptonote_core/blockchain.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/cryptonote_core/blockchain.cpp') diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index f9247ae27..70953f3e7 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -494,6 +494,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(); add_new_block(b, bvc); -- cgit v1.2.3 From a333c42cdeab4675c22df25255313752d81a2d4e Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Mon, 8 Feb 2016 18:47:56 +0000 Subject: core_tests: add tests for hard fork behaviors (MRL-0004) We also replace the --fakechain option with an optional structure containing details about configuration for the core/blockchain, for test purposes. This seems more future friendly. --- src/cryptonote_core/blockchain.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/cryptonote_core/blockchain.cpp') diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 70953f3e7..7dd0aca42 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 @@ -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; -- cgit v1.2.3 From c7f82ec7694a48f8367b22393fabf677576b9cff Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Mon, 8 Feb 2016 20:57:20 +0000 Subject: blockchain: initialize m_hardfork to NULL It can now be set by some other code, and is thus tested --- src/cryptonote_core/blockchain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/cryptonote_core/blockchain.cpp') diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 7dd0aca42..a3eb21187 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -100,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__); -- cgit v1.2.3