@ -329,7 +329,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 network_type nettype , bool offline , const cryptonote : : test_options * test_options )
bool Blockchain : : init ( BlockchainDB * db , const network_type nettype , bool offline , const cryptonote : : test_options * test_options , difficulty_type fixed_difficulty )
{
LOG_PRINT_L3 ( " Blockchain:: " < < __func__ ) ;
CRITICAL_REGION_LOCAL ( m_tx_pool ) ;
@ -351,6 +351,7 @@ bool Blockchain::init(BlockchainDB* db, const network_type nettype, bool offline
m_nettype = test_options ! = NULL ? FAKECHAIN : nettype ;
m_offline = offline ;
m_fixed_difficulty = fixed_difficulty ;
if ( m_hardfork = = nullptr )
{
if ( m_nettype = = FAKECHAIN | | m_nettype = = STAGENET )
@ -805,6 +806,11 @@ bool Blockchain::get_block_by_hash(const crypto::hash &h, block &blk, bool *orph
// less blocks than desired if there aren't enough.
difficulty_type Blockchain : : get_difficulty_for_next_block ( )
{
if ( m_fixed_difficulty )
{
return m_db - > height ( ) ? m_fixed_difficulty : 1 ;
}
LOG_PRINT_L3 ( " Blockchain:: " < < __func__ ) ;
CRITICAL_REGION_LOCAL ( m_difficulty_lock ) ;
@ -1007,6 +1013,11 @@ bool Blockchain::switch_to_alternative_blockchain(std::list<blocks_ext_by_hash::
// an alternate chain.
difficulty_type Blockchain : : get_next_difficulty_for_alternative_chain ( const std : : list < blocks_ext_by_hash : : iterator > & alt_chain , block_extended_info & bei ) const
{
if ( m_fixed_difficulty )
{
return m_db - > height ( ) ? m_fixed_difficulty : 1 ;
}
LOG_PRINT_L3 ( " Blockchain:: " < < __func__ ) ;
std : : vector < uint64_t > timestamps ;
std : : vector < difficulty_type > cumulative_difficulties ;
@ -4374,6 +4385,39 @@ HardFork::State Blockchain::get_hard_fork_state() const
return m_hardfork - > get_state ( ) ;
}
const std : : vector < HardFork : : Params > & Blockchain : : get_hard_fork_heights ( network_type nettype )
{
static const std : : vector < HardFork : : Params > mainnet_heights = [ ] ( )
{
std : : vector < HardFork : : Params > heights ;
for ( const auto & i : mainnet_hard_forks )
heights . emplace_back ( i . version , i . height , i . threshold , i . time ) ;
return heights ;
} ( ) ;
static const std : : vector < HardFork : : Params > testnet_heights = [ ] ( )
{
std : : vector < HardFork : : Params > heights ;
for ( const auto & i : testnet_hard_forks )
heights . emplace_back ( i . version , i . height , i . threshold , i . time ) ;
return heights ;
} ( ) ;
static const std : : vector < HardFork : : Params > stagenet_heights = [ ] ( )
{
std : : vector < HardFork : : Params > heights ;
for ( const auto & i : stagenet_hard_forks )
heights . emplace_back ( i . version , i . height , i . threshold , i . time ) ;
return heights ;
} ( ) ;
static const std : : vector < HardFork : : Params > dummy ;
switch ( nettype )
{
case MAINNET : return mainnet_heights ;
case TESTNET : return testnet_heights ;
case STAGENET : return stagenet_heights ;
default : return dummy ;
}
}
bool Blockchain : : get_hard_fork_voting_info ( uint8_t version , uint32_t & window , uint32_t & votes , uint32_t & threshold , uint64_t & earliest_height , uint8_t & voting ) const
{
return m_hardfork - > get_voting_info ( version , window , votes , threshold , earliest_height , voting ) ;