@ -1390,7 +1390,31 @@ bool Blockchain::prevalidate_miner_transaction(const block& b, uint64_t height,
return false ;
}
MDEBUG ( " Miner tx hash: " < < get_transaction_hash ( b . miner_tx ) ) ;
CHECK_AND_ASSERT_MES ( b . miner_tx . unlock_time = = height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW , false , " coinbase transaction transaction has the wrong unlock time= " < < b . miner_tx . unlock_time < < " , expected " < < height + CRYPTONOTE_MINED_MONEY_UNLOCK_WINDOW ) ;
// Dynamic unlock time from HF 16
// To calculate unlock window, get the block hash at height-1337, convert the
// first 3 characters from hexadecimal to decimal, multiply by 2, and then add 288.
// Unlock minimum 1 day (288 blocks), maximum is ~29 days ((4095*2)+288 = 8478 blocks)
// unlock time = unlock_window + height
if ( hf_version > = HF_VERSION_DYNAMIC_UNLOCK )
{
crypto : : hash blk_id = get_block_id_by_height ( height - 1337 ) ;
std : : string hex_str = epee : : string_tools : : pod_to_hex ( blk_id ) . substr ( 0 , 3 ) ;
uint64_t blk_num = std : : stol ( hex_str , nullptr , 16 ) * 2 ;
uint64_t unlock_window = blk_num + 288 ;
if ( b . miner_tx . unlock_time ! = height + unlock_window ) {
MWARNING ( " Coinbase transaction has the wrong unlock time= " < < b . miner_tx . unlock_time < < " , expected " < < height + unlock_window ) ;
return false ;
}
LOG_PRINT_L1 ( " +++++ MINER TX UNLOCK TIME INFO " < <
" \n Height: " < < height < < " , Unlock window: " < < unlock_window < < " , Unlock time: " < < b . miner_tx . unlock_time < <
" \n blk_height: " < < height - 1337 < < " , blk_id: " < < blk_id < <
" \n hex_str: " < < hex_str < < " , blk_num: " < < blk_num ) ;
} else {
CHECK_AND_ASSERT_MES ( b . miner_tx . unlock_time = = height + 60 , false , " coinbase transaction transaction has the wrong unlock time= "
< < b . miner_tx . unlock_time < < " , expected " < < height + 60 ) ;
}
//check outs overflow
//NOTE: not entirely sure this is necessary, given that this function is
@ -1762,7 +1786,7 @@ bool Blockchain::create_block_template(block& b, const crypto::hash *from_block,
//make blocks coin-base tx looks close to real coinbase tx to get truthful blob weight
uint8_t hf_version = b . major_version ;
size_t max_outs = hf_version > = 4 ? 1 : 11 ;
bool r = construct_miner_tx ( height , median_weight , already_generated_coins , txs_weight , fee , miner_address , b . miner_tx , ex_nonce , max_outs , hf_version ) ;
bool r = construct_miner_tx ( this , height , median_weight , already_generated_coins , txs_weight , fee , miner_address , b . miner_tx , ex_nonce , max_outs , hf_version ) ;
CHECK_AND_ASSERT_MES ( r , false , " Failed to construct miner tx, first chance " ) ;
size_t cumulative_weight = txs_weight + get_transaction_weight ( b . miner_tx ) ;
# if defined(DEBUG_CREATE_BLOCK_TEMPLATE)
@ -1771,7 +1795,7 @@ bool Blockchain::create_block_template(block& b, const crypto::hash *from_block,
# endif
for ( size_t try_count = 0 ; try_count ! = 10 ; + + try_count )
{
r = construct_miner_tx ( height , median_weight , already_generated_coins , cumulative_weight , fee , miner_address , b . miner_tx , ex_nonce , max_outs , hf_version ) ;
r = construct_miner_tx ( this , height , median_weight , already_generated_coins , cumulative_weight , fee , miner_address , b . miner_tx , ex_nonce , max_outs , hf_version ) ;
CHECK_AND_ASSERT_MES ( r , false , " Failed to construct miner tx, second chance " ) ;
size_t coinbase_weight = get_transaction_weight ( b . miner_tx ) ;