43 #undef ELECTRONEUM_DEFAULT_LOG_CATEGORY 44 #define ELECTRONEUM_DEFAULT_LOG_CATEGORY "difficulty" 52 #if defined(__x86_64__) 54 low = mul128(
a, b, &high);
72 res = aHigh * bLow + carry;
80 res = aHigh * bHigh + carry;
88 low = (r << 32) | lowRes1;
89 r = highResHigh1 + highResLow2 + carry;
92 r = highResHigh2 + carry;
93 high = d3 | (r << 32);
115 bool carry = cadd(cur, low);
118 carry = cadc(cur, low, carry);
119 carry = cadc(high, top, carry);
127 if(timestamps.size() > difficultyWindow)
129 timestamps.resize(difficultyWindow);
130 cumulative_difficulties.resize(difficultyWindow);
133 size_t length = timestamps.size();
134 assert(length == cumulative_difficulties.size());
141 assert(length <= difficultyWindow);
142 sort(timestamps.begin(), timestamps.end());
143 size_t cut_begin, cut_end;
152 cut_begin = (length - (difficultyWindow - 2 *
DIFFICULTY_CUT) + 1) / 2;
155 assert( cut_begin + 2 <= cut_end && cut_end <= length);
156 uint64_t time_span = timestamps[cut_end - 1] - timestamps[cut_begin];
157 if (time_span == 0) {
160 uint64_t total_work = cumulative_difficulties[cut_end - 1] - cumulative_difficulties[cut_begin];
161 assert(total_work > 0);
163 mul(total_work, target_seconds, low, high);
166 if (high != 0 || low + time_span - 1 < low) {
169 return (low + time_span - 1) / time_span;
172 #if defined(_MSC_VER) 179 const boost::multiprecision::uint256_t
max128bit(std::numeric_limits<boost::multiprecision::uint128_t>::max());
180 const boost::multiprecision::uint512_t
max256bit(std::numeric_limits<boost::multiprecision::uint256_t>::max());
182 #define FORCE_FULL_128_BITS 185 #ifndef FORCE_FULL_128_BITS 191 boost::multiprecision::uint512_t hashVal = 0;
192 #ifdef FORCE_FULL_128_BITS 193 for(
int i = 0; i < 4; i++) {
195 for(
int i = 1; i < 4; i++) {
200 return hashVal * difficulty <=
max256bit;
215 if(timestamps.size() > difficultyWindow)
217 timestamps.resize(difficultyWindow);
218 cumulative_difficulties.resize(difficultyWindow);
222 size_t length = timestamps.size();
223 assert(length == cumulative_difficulties.size());
229 assert(length <= difficultyWindow);
230 sort(timestamps.begin(), timestamps.end());
231 size_t cut_begin, cut_end;
238 cut_begin = (length - (difficultyWindow - 2 *
DIFFICULTY_CUT) + 1) / 2;
241 assert( cut_begin + 2 <= cut_end && cut_end <= length);
242 uint64_t time_span = timestamps[cut_end - 1] - timestamps[cut_begin];
243 if (time_span == 0) {
246 difficulty_type total_work = cumulative_difficulties[cut_end - 1] - cumulative_difficulties[cut_begin];
247 assert(total_work > 0);
248 boost::multiprecision::uint256_t
res = (boost::multiprecision::uint256_t(total_work) * target_seconds + time_span - 1) / time_span;
256 static const char chars[] =
"0123456789abcdef";
260 s.push_back(chars[(v & 0xf).convert_to<unsigned>()]);
265 std::reverse(s.begin(), s.end());
const boost::multiprecision::uint256_t max128bit(std::numeric_limits< boost::multiprecision::uint128_t >::max())
difficulty_type next_difficulty(std::vector< uint64_t > timestamps, std::vector< difficulty_type > cumulative_difficulties, size_t target_seconds, uint8_t version)
const difficulty_type max64bit(std::numeric_limits< std::uint64_t >::max())
#define DIFFICULTY_WINDOW
Holds cryptonote related classes and helpers.
const boost::multiprecision::uint512_t max256bit(std::numeric_limits< boost::multiprecision::uint256_t >::max())
bool check_hash(const crypto::hash &hash, difficulty_type difficulty)
unsigned __int64 uint64_t
#define DIFFICULTY_WINDOW_V6
version
Supported socks variants.
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
bool check_hash_64(const crypto::hash &hash, uint64_t difficulty)
checks if a hash fits the given difficulty
boost::multiprecision::uint128_t difficulty_type
std::string hex(difficulty_type v)
bool check_hash_128(const crypto::hash &hash, difficulty_type difficulty)
uint64_t next_difficulty_64(std::vector< std::uint64_t > timestamps, std::vector< uint64_t > cumulative_difficulties, size_t target_seconds, uint8_t version)