1
0
Fork 0
forked from lthn/blockchain

an attempt to fix incorrect PoW block template creation in case when there are lots of PoS blocks

This commit is contained in:
sowle 2024-10-23 21:52:33 +02:00
parent f08d8797a0
commit c90344ea47
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC

View file

@ -1553,8 +1553,21 @@ bool blockchain_storage::create_block_template(const create_block_template_param
}
diffic = get_next_diff_conditional(pos);
CHECK_AND_ASSERT_MES(diffic, false, "get_next_diff_conditional failed");
// check PoW block timestamp against the current blockchain timestamp median -- if it's not okay, don't create a new block
// TODO (performance) both get_next_diff_conditional and get_last_n_blocks_timestamps obtains last N blocks, consider data reusing -- sowle
if (!pos)
{
std::vector<uint64_t> timestamps = get_last_n_blocks_timestamps(BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW);
uint64_t median_ts = epee::misc_utils::median(timestamps);
if(b.timestamp < median_ts)
{
LOG_PRINT_YELLOW("Block template construction failed because current core timestamp, " << b.timestamp << ", is less than median of last " << BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW << " blocks, " << median_ts, LOG_LEVEL_2);
return false;
}
}
CHECK_AND_ASSERT_MES(diffic, false, "difficulty owverhead.");