diff --git a/src/side_chain.cpp b/src/side_chain.cpp index b78ab05..2a2a2dc 100644 --- a/src/side_chain.cpp +++ b/src/side_chain.cpp @@ -1201,7 +1201,11 @@ bool SideChain::get_difficulty(const PoolBlock* tip, std::vector std::nth_element(tmpTimestamps.begin(), tmpTimestamps.begin() + index2, tmpTimestamps.end()); const uint64_t timestamp2 = oldest_timestamp + tmpTimestamps[index2]; - const uint64_t delta_t = (timestamp2 > timestamp1) ? (timestamp2 - timestamp1) : 1; + // Make a reasonable assumption that each block has higher timestamp, so delta_t can't be less than delta_index + // Because if it is, someone is trying to mess with timestamps + // In reality, delta_t ~ delta_index*10 (sidechain block time) + const uint64_t delta_index = (index2 > index1) ? (index2 - index1) : 1U; + const uint64_t delta_t = (timestamp2 > timestamp1 + delta_index) ? (timestamp2 - timestamp1) : delta_index; difficulty_type diff1{ std::numeric_limits::max(), std::numeric_limits::max() }; difficulty_type diff2{ 0, 0 };