mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-23 03:13:28 +01:00
doxygen documentation for difficulty functions
This commit is contained in:
parent
540a76c5c2
commit
8ac329df02
@ -116,8 +116,8 @@ namespace cryptonote {
|
|||||||
return !carry;
|
return !carry;
|
||||||
}
|
}
|
||||||
|
|
||||||
difficulty_type next_difficulty(vector<uint64_t> timestamps, vector<difficulty_type> cumulative_difficulties, size_t target_seconds) {
|
difficulty_type next_difficulty(std::vector<std::uint64_t> timestamps, std::vector<difficulty_type> cumulative_difficulties, size_t target_seconds) {
|
||||||
//cutoff DIFFICULTY_LAG
|
|
||||||
if(timestamps.size() > DIFFICULTY_WINDOW)
|
if(timestamps.size() > DIFFICULTY_WINDOW)
|
||||||
{
|
{
|
||||||
timestamps.resize(DIFFICULTY_WINDOW);
|
timestamps.resize(DIFFICULTY_WINDOW);
|
||||||
@ -151,6 +151,8 @@ namespace cryptonote {
|
|||||||
assert(total_work > 0);
|
assert(total_work > 0);
|
||||||
uint64_t low, high;
|
uint64_t low, high;
|
||||||
mul(total_work, target_seconds, low, high);
|
mul(total_work, target_seconds, low, high);
|
||||||
|
// blockchain errors "difficulty overhead" if this function returns zero.
|
||||||
|
// TODO: consider throwing an exception instead
|
||||||
if (high != 0 || low + time_span - 1 < low) {
|
if (high != 0 || low + time_span - 1 < low) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,18 @@ namespace cryptonote
|
|||||||
{
|
{
|
||||||
typedef std::uint64_t difficulty_type;
|
typedef std::uint64_t difficulty_type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief checks if a hash fits the given difficulty
|
||||||
|
*
|
||||||
|
* The hash passes if (hash * difficulty) < 2^192.
|
||||||
|
* Phrased differently, if (hash * difficulty) fits without overflow into
|
||||||
|
* the least significant 192 bits of the 256 bit multiplication result.
|
||||||
|
*
|
||||||
|
* @param hash the hash to check
|
||||||
|
* @param difficulty the difficulty to check against
|
||||||
|
*
|
||||||
|
* @return true if valid, else false
|
||||||
|
*/
|
||||||
bool check_hash(const crypto::hash &hash, difficulty_type difficulty);
|
bool check_hash(const crypto::hash &hash, difficulty_type difficulty);
|
||||||
difficulty_type next_difficulty(std::vector<std::uint64_t> timestamps, std::vector<difficulty_type> cumulative_difficulties, size_t target_seconds);
|
difficulty_type next_difficulty(std::vector<std::uint64_t> timestamps, std::vector<difficulty_type> cumulative_difficulties, size_t target_seconds);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user