Blockchain: Optionally pass in HardFork object

This commit is contained in:
warptangent 2016-02-04 23:05:11 -08:00
parent f7e337e625
commit 8f863e742d
No known key found for this signature in database
GPG key ID: 0E490BEBFBE4E92D
2 changed files with 21 additions and 4 deletions

View file

@ -99,7 +99,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_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(), 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__);
@ -271,14 +271,20 @@ bool Blockchain::init(BlockchainDB* db, const bool testnet, const bool fakechain
m_db = db;
m_testnet = testnet;
if (m_testnet) {
if (m_hardfork == nullptr)
{
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)
{
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);
}
else
{
m_hardfork = new HardFork(*db, 1, mainnet_hard_fork_version_1_till);
for (size_t n = 0; n < sizeof(mainnet_hard_forks) / sizeof(mainnet_hard_forks[0]); ++n)
m_hardfork->add_fork(mainnet_hard_forks[n].version, mainnet_hard_forks[n].height, mainnet_hard_forks[n].threshold, mainnet_hard_forks[n].time);
}
@ -340,6 +346,16 @@ 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)
{
if (hf != nullptr)
m_hardfork = hf;
bool res = init(db, testnet, fakechain);
if (hf == nullptr)
hf = m_hardfork;
return res;
}
//------------------------------------------------------------------
bool Blockchain::store_blockchain()
{
LOG_PRINT_YELLOW("Blockchain::" << __func__, LOG_LEVEL_3);

View file

@ -92,6 +92,7 @@ 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 deinit();
void set_checkpoints(checkpoints&& chk_pts) { m_checkpoints = chk_pts; }