Electroneum
Loading...
Searching...
No Matches
difficulty.cpp File Reference
#include <cstddef>
#include <cstdint>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdexcept>
#include "misc_log_ex.h"
#include "cryptonote_config.h"
#include "cryptonote_basic/difficulty.h"
Include dependency graph for difficulty.cpp:

Go to the source code of this file.

Macros

#define DEFAULT_TEST_DIFFICULTY_TARGET   120
#define DEFAULT_TEST_DIFFICULTY_WINDOW   720

Functions

int main (int argc, char *argv[])

Macro Definition Documentation

◆ DEFAULT_TEST_DIFFICULTY_TARGET

#define DEFAULT_TEST_DIFFICULTY_TARGET   120

Definition at line 46 of file difficulty.cpp.

◆ DEFAULT_TEST_DIFFICULTY_WINDOW

#define DEFAULT_TEST_DIFFICULTY_WINDOW   720

Definition at line 47 of file difficulty.cpp.

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 87 of file difficulty.cpp.

87 {
88 TRY_ENTRY();
89
90 if (argc < 2) {
91 cerr << "Wrong arguments" << endl;
92 return 1;
93 }
94 if (argc == 3 && strcmp(argv[1], "--wide") == 0)
95 {
96 return test_wide_difficulty(argv[2]);
97 }
98
99 vector<uint64_t> timestamps, cumulative_difficulties;
100 std::vector<cryptonote::difficulty_type> wide_cumulative_difficulties;
101 fstream data(argv[1], fstream::in);
102 data.exceptions(fstream::badbit);
103 data.clear(data.rdstate());
104 uint64_t timestamp;
105 uint64_t difficulty, cumulative_difficulty = 0;
106 cryptonote::difficulty_type wide_cumulative_difficulty = 0;
107 size_t n = 0;
108 while (data >> timestamp >> difficulty) {
109 size_t begin, end;
111 begin = 0;
112 end = min(n, (size_t) DEFAULT_TEST_DIFFICULTY_WINDOW);
113 } else {
114 end = n - DIFFICULTY_LAG;
115 begin = end - DEFAULT_TEST_DIFFICULTY_WINDOW;
116 }
118 vector<uint64_t>(timestamps.begin() + begin, timestamps.begin() + end),
119 vector<uint64_t>(cumulative_difficulties.begin() + begin, cumulative_difficulties.begin() + end), DEFAULT_TEST_DIFFICULTY_TARGET, 7);
120 if (res != difficulty) {
121 cerr << "Wrong difficulty for block " << n << endl
122 << "Expected: " << difficulty << endl
123 << "Found: " << res << endl;
124 return 1;
125 }
127 std::vector<uint64_t>(timestamps.begin() + begin, timestamps.begin() + end),
128 std::vector<cryptonote::difficulty_type>(wide_cumulative_difficulties.begin() + begin, wide_cumulative_difficulties.begin() + end), DEFAULT_TEST_DIFFICULTY_TARGET);
129 if ((wide_res & 0xffffffffffffffff).convert_to<uint64_t>() != res) {
130 cerr << "Wrong wide difficulty for block " << n << endl
131 << "Expected: " << res << endl
132 << "Found: " << wide_res << endl;
133 return 1;
134 }
135 timestamps.push_back(timestamp);
136 cumulative_difficulties.push_back(cumulative_difficulty += difficulty);
137 wide_cumulative_difficulties.push_back(wide_cumulative_difficulty += difficulty);
138 ++n;
139 }
140 if (!data.eof()) {
141 data.clear(fstream::badbit);
142 }
143 return 0;
144
145 CATCH_ENTRY_L0("main", 1);
146}
#define DIFFICULTY_LAG
const char * res
#define CATCH_ENTRY_L0(lacation, return_val)
#define TRY_ENTRY()
boost::multiprecision::uint128_t difficulty_type
Definition difficulty.h:43
difficulty_type next_difficulty(std::vector< uint64_t > timestamps, std::vector< difficulty_type > cumulative_difficulties, size_t target_seconds, uint8_t version)
uint64_t next_difficulty_64(std::vector< std::uint64_t > timestamps, std::vector< uint64_t > cumulative_difficulties, size_t target_seconds, uint8_t version)
unsigned __int64 uint64_t
Definition stdint.h:136
#define DEFAULT_TEST_DIFFICULTY_TARGET
#define DEFAULT_TEST_DIFFICULTY_WINDOW
Here is the call graph for this function: