Skip to content

Commit f9cb2b1

Browse files
committed
Minor fixes and a last Fork change
Signed-off-by: Pttn <28868425+Pttn@users.noreply.github.com>
1 parent 5e7c148 commit f9cb2b1

File tree

5 files changed

+28
-22
lines changed

5 files changed

+28
-22
lines changed

Client.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,32 @@ std::array<uint8_t, 32> BlockHeader::powHash(const int32_t powVersion) const {
4040

4141
mpz_class BlockHeader::target(const int32_t powVersion) const {
4242
const uint32_t difficultyIntegerPart(decodeBits(bits, powVersion));
43+
uint32_t trailingZeros;
44+
const std::array<uint8_t, 32> hash(powHash(powVersion));
4345
mpz_class target;
44-
if (powVersion == -1)
46+
if (powVersion == -1) {
47+
if (difficultyIntegerPart < 265U) return 0;
4548
target = 256;
49+
for (uint64_t i(0) ; i < 256 ; i++) {
50+
target <<= 1;
51+
if ((hash[i/8] >> (i % 8)) & 1)
52+
target.get_mpz_t()->_mp_d[0]++;
53+
}
54+
trailingZeros = difficultyIntegerPart - 265U;
55+
}
4656
else if (powVersion == 1) {
57+
if (difficultyIntegerPart < 264U) return 0;
4758
const uint32_t df(bits & 255U);
4859
target = 256 + ((10U*df*df*df + 7383U*df*df + 5840720U*df + 3997440U) >> 23U);
60+
target <<= 256;
61+
mpz_class hashGmp;
62+
mpz_import(hashGmp.get_mpz_t(), 32, -1, sizeof(uint8_t), 0, 0, hash.begin());
63+
target += hashGmp;
64+
trailingZeros = difficultyIntegerPart - 264U;
4965
}
5066
else
5167
return 0;
5268

53-
const std::array<uint8_t, 32> hash(powHash(powVersion));
54-
for (uint64_t i(0) ; i < 256 ; i++) {
55-
target <<= 1;
56-
if ((hash[i/8] >> (i % 8)) & 1)
57-
target.get_mpz_t()->_mp_d[0]++;
58-
}
59-
if (difficultyIntegerPart < 265U) return 0;
60-
const uint32_t trailingZeros(difficultyIntegerPart - 265U);
6169
target <<= trailingZeros;
6270
return target;
6371
}
@@ -147,15 +155,15 @@ bool BMClient::getJob(Job& job, const bool dummy) {
147155
job.height = _height;
148156
job.difficulty = _difficulty;
149157
const uint64_t difficultyAsInteger(std::round(65536.*job.difficulty));
150-
// Target: (in binary) 1 . Leading Digits L (16 bits) . Height (32 bits) . Requests (32 bits) . (Difficulty - 81) zeros = 2^(Difficulty - 81)(2^80 + 2^64*L + 2^32*Height + Requests)
158+
// Target: (in binary) 1 . Leading Digits L (16 bits) . Height (32 bits) . Requests (32 bits) . (Difficulty - 80) zeros = 2^(Difficulty - 80)(2^80 + 2^64*L + 2^32*Height + Requests)
151159
job.target = 1;
152160
job.target <<= 16;
153161
job.target += static_cast<uint16_t>(std::round(std::pow(2., 16. + static_cast<double>(difficultyAsInteger % 65536)/65536.)) - 65536.);
154162
job.target <<= 32;
155163
job.target += job.height;
156164
job.target <<= 32;
157165
job.target += _requests;
158-
job.target <<= (difficultyAsInteger/65536ULL - 81ULL);
166+
job.target <<= (difficultyAsInteger/65536ULL - 80ULL);
159167
job.primeCountTarget = _pattern.size();
160168
job.primeCountMin = job.primeCountTarget;
161169
if (!dummy) _requests++;
@@ -165,7 +173,7 @@ bool BMClient::getJob(Job& job, const bool dummy) {
165173
bool SearchClient::getJob(Job& job, const bool) {
166174
job.height = 1;
167175
job.difficulty = _difficulty;
168-
// Target: (in binary) 1 . Leading Digits L (16 bits) . 80 Random Bits . (Difficulty - 97) zeros = 2^(Difficulty - 97)*(2^96 + 2^80*L + Random)
176+
// Target: (in binary) 1 . Leading Digits L (16 bits) . 80 Random Bits . (Difficulty - 96) zeros = 2^(Difficulty - 96)*(2^96 + 2^80*L + Random)
169177
const uint64_t difficultyAsInteger(std::round(65536.*job.difficulty));
170178
std::array<uint8_t, 10> random;
171179
for (auto &byte : random) byte = rand(0x00, 0xFF);
@@ -176,7 +184,7 @@ bool SearchClient::getJob(Job& job, const bool) {
176184
job.target <<= 16;
177185
job.target += reinterpret_cast<uint16_t*>(random.data())[4 - i];
178186
}
179-
job.target <<= (job.difficulty - 97);
187+
job.target <<= (job.difficulty - 96);
180188
job.primeCountTarget = _pattern.size();
181189
job.primeCountMin = job.primeCountTarget;
182190
return true;

GBTClient.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ void GBTClient::_submit(const Job& job) {
239239
oss << job.transactions << "\"], \"id\": 0}\n";
240240
req = oss.str();
241241

242+
DBG(std::cout << "Sending: " << req;);
242243
json_t *jsonSb(_sendRPCCall(req)); // SubmitBlock response
243-
DBG(std::cout << "Sent: " << req;);
244244
if (jsonSb == nullptr) ERRORMSG("Failure submitting block");
245245
else {
246246
json_t *jsonSb_Res(json_object_get(jsonSb, "result")),

Miner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ void Miner::init(const MinerParameters &minerParameters) {
115115
primeTableFileBytes = file.tellg();
116116
savedPrimes = primeTableFileBytes/sizeof(decltype(_primes)::value_type);
117117
if (savedPrimes > 0) {
118-
file.seekg(-sizeof(decltype(_primes)::value_type), std::ios::end);
118+
file.seekg(-static_cast<int64_t>(sizeof(decltype(_primes)::value_type)), std::ios::end);
119119
file.read(reinterpret_cast<char*>(&largestSavedPrime), sizeof(decltype(_primes)::value_type));
120120
}
121121
}
122122
std::chrono::time_point<std::chrono::steady_clock> t0(std::chrono::steady_clock::now());
123-
if (savedPrimes > 0 && _parameters.primeTableLimit >= 1048576 && _parameters.primeTableLimit < largestSavedPrime) {
123+
if (savedPrimes > 0 && _parameters.primeTableLimit >= 1048576 && _parameters.primeTableLimit <= largestSavedPrime) {
124124
std::cout << "Extracting prime numbers from " << primeTableFile << " (" << primeTableFileBytes << " bytes, " << savedPrimes << " primes, largest " << largestSavedPrime << ")..." << std::endl;
125125
uint64_t nPrimesUpperBound(std::min(1.085*static_cast<double>(_parameters.primeTableLimit)/std::log(static_cast<double>(_parameters.primeTableLimit)), static_cast<double>(savedPrimes))); // 1.085 = max(π(p)log(p)/p) for p >= 2^20
126126
try {

main.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,7 @@ void Options::loadConf() {
230230
std::vector<uint64_t> offsets;
231231
uint64_t tmp;
232232
while (offsetsSS >> tmp) offsets.push_back(tmp);
233-
if (offsets.size() < 2)
234-
std::cout << "Too short or invalid tuple offsets, ignoring." << std::endl;
235-
else _minerParameters.pattern = offsets;
233+
_minerParameters.pattern = offsets;
236234
}
237235
else if (key == "PrimorialNumber") {
238236
try {_minerParameters.primorialNumber = std::stoll(value);}
@@ -276,7 +274,7 @@ void Options::loadConf() {
276274
_minerParameters.pattern = {0, 2, 4, 2, 4, 6, 2};
277275
}
278276
else if (_mode == "Search") {
279-
const double base10Exp((_difficulty - 1.)*0.301029996);
277+
const double base10Exp(_difficulty*0.301029996);
280278
std::cout << "Search Mode at difficulty " << _difficulty << " (numbers around " << std::pow(10., base10Exp - std::floor(base10Exp)) << "*10^" << std::floor(base10Exp) << ") - Good luck!" << std::endl;
281279
if (_minerParameters.pattern.size() == 0) // Pick a default pattern if none was chosen
282280
_minerParameters.pattern = {0, 2, 4, 2, 4, 6, 2};
@@ -335,10 +333,10 @@ int main(int argc, char** argv) {
335333
#endif
336334

337335
std::cout << versionString << ", Riecoin miner by Pttn and contributors" << std::endl;
338-
std::cout << "Assembly code by Michael Bell (Rockhawk)" << std::endl;
339336
std::cout << "Project page: https://github.com/Pttn/rieMiner" << std::endl;
340337
std::cout << "Go to the project page or open README.md for usage information" << std::endl;
341338
std::cout << "-----------------------------------------------------------" << std::endl;
339+
std::cout << "Assembly code by Michael Bell (Rockhawk)" << std::endl;
342340
std::cout << "G++ " << __GNUC__ << "." << __GNUC_MINOR__ << "." << __GNUC_PATCHLEVEL__ << " - https://gcc.gnu.org/" << std::endl;
343341
std::cout << "GMP " << __GNU_MP_VERSION << "." << __GNU_MP_VERSION_MINOR << "." << __GNU_MP_VERSION_PATCHLEVEL << " - https://gmplib.org/" << std::endl;
344342
std::cout << "Curl " << LIBCURL_VERSION << " - https://curl.haxx.se/" << std::endl;

tools.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ std::vector<uint64_t> generatePrimeTable(const uint64_t limit) {
2727
std::vector<uint64_t> compositeTable((limit + 127ULL)/128ULL, 0ULL); // Booleans indicating whether an odd number is composite: 0000100100101100...
2828
for (uint64_t f(3ULL) ; f*f <= limit ; f += 2ULL) { // Eliminate f and its multiples m for odd f from 3 to square root of the limit
2929
if (compositeTable[f >> 7ULL] & (1ULL << ((f >> 1ULL) & 63ULL))) continue; // Skip if f is composite (f and its multiples were already eliminated)
30-
for (uint64_t m((f*f) >> 1ULL) ; m < (limit >> 1ULL) ; m += f) // Start eliminating at f^2 (multiples of f below were already eliminated)
30+
for (uint64_t m((f*f) >> 1ULL) ; m <= (limit >> 1ULL) ; m += f) // Start eliminating at f^2 (multiples of f below were already eliminated)
3131
compositeTable[m >> 6ULL] |= 1ULL << (m & 63ULL);
3232
}
3333
std::vector<uint64_t> primeTable(1, 2);

0 commit comments

Comments
 (0)