mirror of
https://github.com/GOSTSec/ccminer
synced 2025-01-08 22:07:56 +00:00
Show shares diff on longpoll pools too
and remove unused remains of old difficulty functions
This commit is contained in:
parent
41707760f5
commit
ec054db317
92
ccminer.cpp
92
ccminer.cpp
@ -608,60 +608,16 @@ static void calc_network_diff(struct work *work)
|
||||
uint32_t nbits = have_longpoll ? work->data[18] : swab32(work->data[18]);
|
||||
uint32_t bits = (nbits & 0xffffff);
|
||||
int16_t shift = (swab32(nbits) & 0xff); // 0x1c = 28
|
||||
#if 1
|
||||
|
||||
uint64_t diffone = 0x0000FFFF00000000ull;
|
||||
double d = (double)0x0000ffff / (double)bits;
|
||||
|
||||
for (int m=shift; m < 29; m++) d *= 256.0;
|
||||
for (int m=29; m < shift; m++) d /= 256.0;
|
||||
if (opt_debug_diff)
|
||||
applog(LOG_DEBUG, "net diff: %f -> shift %u, bits %08x", d, shift, bits);
|
||||
|
||||
net_diff = d;
|
||||
return;
|
||||
#else
|
||||
uchar rtarget[48] = { 0 };
|
||||
uint64_t *data64, d64;
|
||||
uint64_t diffone = 0xFFFF000000000000ull; //swab64(0xFFFFull);
|
||||
int shfb = 8 * (26 - (shift - 3));
|
||||
|
||||
switch (opt_algo) {
|
||||
case ALGO_QUARK:
|
||||
diffone = 0xFFFFFF0000000000ull;
|
||||
break;
|
||||
case ALGO_SCRYPT:
|
||||
case ALGO_SCRYPT_JANE:
|
||||
// cant get the right value on these 3 algos...
|
||||
diffone = 0xFFFFFFFF00000000ull;
|
||||
net_diff = 0.;
|
||||
break;
|
||||
case ALGO_NEOSCRYPT:
|
||||
// todo/check... (neoscrypt data is reversed)
|
||||
if (opt_debug)
|
||||
applog(LOG_DEBUG, "diff: %08x -> shift %u, bits %08x, shfb %d", nbits, shift, bits, shfb);
|
||||
net_diff = 0.;
|
||||
return;
|
||||
}
|
||||
|
||||
bn_nbits_to_uchar(nbits, rtarget);
|
||||
|
||||
data64 = (uint64_t*)(rtarget + 4);
|
||||
|
||||
switch (opt_algo) {
|
||||
case ALGO_HEAVY:
|
||||
data64 = (uint64_t*)(rtarget + 2);
|
||||
break;
|
||||
case ALGO_QUARK:
|
||||
data64 = (uint64_t*)(rtarget + 3);
|
||||
break;
|
||||
}
|
||||
|
||||
d64 = swab64(*data64);
|
||||
if (!d64)
|
||||
d64 = 1;
|
||||
net_diff = (double)(diffone) / d64; // 43.281
|
||||
if (opt_debug_diff)
|
||||
applog(LOG_DEBUG, "diff: %08x -> shift %u, bits %08x, shfb %d -> %.5f (pool %u)",
|
||||
nbits, shift, bits, shfb, net_diff, work->pooln);
|
||||
#endif
|
||||
}
|
||||
|
||||
static bool work_decode(const json_t *val, struct work *work)
|
||||
@ -697,6 +653,8 @@ static bool work_decode(const json_t *val, struct work *work)
|
||||
if ((opt_showdiff || opt_max_diff > 0.) && !allow_mininginfo)
|
||||
calc_network_diff(work);
|
||||
|
||||
work->targetdiff = target_to_diff(work->target);
|
||||
|
||||
work->tx_count = use_pok = 0;
|
||||
if (work->data[0] & POK_BOOL_MASK) {
|
||||
use_pok = 1;
|
||||
@ -744,40 +702,6 @@ static bool work_decode(const json_t *val, struct work *work)
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the work difficulty as double
|
||||
*/
|
||||
static void calc_target_diff(struct work *work)
|
||||
{
|
||||
// sample for diff 32.53 : 00000007de5f0000
|
||||
char rtarget[32];
|
||||
uint64_t diffone = 0xFFFF000000000000ull;
|
||||
uint64_t *data64, d64;
|
||||
|
||||
swab256(rtarget, work->target);
|
||||
|
||||
data64 = (uint64_t*)(rtarget + 3);
|
||||
|
||||
switch (opt_algo) {
|
||||
case ALGO_NEOSCRYPT: /* diffone in work->target[7] ? */
|
||||
//case ALGO_SCRYPT:
|
||||
//case ALGO_SCRYPT_JANE:
|
||||
// todo/check...
|
||||
work->difficulty = work->targetdiff;
|
||||
return;
|
||||
case ALGO_HEAVY:
|
||||
data64 = (uint64_t*)(rtarget + 2);
|
||||
break;
|
||||
}
|
||||
|
||||
d64 = swab64(*data64);
|
||||
if (unlikely(!d64))
|
||||
d64 = 1;
|
||||
work->difficulty = (double)diffone / d64;
|
||||
if (opt_difficulty > 0.)
|
||||
work->difficulty /= opt_difficulty;
|
||||
}
|
||||
|
||||
#define YES "yes!"
|
||||
#define YAY "yay!!!"
|
||||
#define BOO "booooo"
|
||||
@ -873,7 +797,6 @@ static bool submit_upstream_work(CURL *curl, struct work *work)
|
||||
applog(LOG_WARNING, "stale work detected, discarding");
|
||||
return true;
|
||||
}
|
||||
calc_target_diff(work);
|
||||
|
||||
if (pool->type & POOL_STRATUM) {
|
||||
uint32_t sent = 0;
|
||||
@ -1686,13 +1609,12 @@ static void *miner_thread(void *userdata)
|
||||
|
||||
if (!opt_benchmark && (g_work.height != work.height || memcmp(work.target, g_work.target, sizeof(work.target))))
|
||||
{
|
||||
calc_target_diff(&g_work);
|
||||
if (opt_debug) {
|
||||
uint64_t target64 = g_work.target[7] * 0x100000000ULL + g_work.target[6];
|
||||
applog(LOG_DEBUG, "job %s target change: %llx (%.1f)", g_work.job_id, target64, g_work.difficulty);
|
||||
applog(LOG_DEBUG, "job %s target change: %llx (%.1f)", g_work.job_id, target64, g_work.targetdiff);
|
||||
}
|
||||
memcpy(work.target, g_work.target, sizeof(work.target));
|
||||
work.difficulty = g_work.difficulty;
|
||||
work.targetdiff = g_work.targetdiff;
|
||||
work.height = g_work.height;
|
||||
//nonceptr[0] = (UINT32_MAX / opt_n_threads) * thr_id; // 0 if single thr
|
||||
}
|
||||
|
4
miner.h
4
miner.h
@ -485,7 +485,8 @@ extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
|
||||
extern int timeval_subtract(struct timeval *result, struct timeval *x,
|
||||
struct timeval *y);
|
||||
extern bool fulltest(const uint32_t *hash, const uint32_t *target);
|
||||
extern void diff_to_target(struct work* work, double diff);
|
||||
void diff_to_target(struct work* work, double diff);
|
||||
double target_to_diff(uint32_t* target);
|
||||
extern void get_currentalgo(char* buf, int sz);
|
||||
extern uint32_t device_intensity(int thr_id, const char *func, uint32_t defcount);
|
||||
|
||||
@ -561,7 +562,6 @@ struct work {
|
||||
} noncerange;
|
||||
|
||||
double targetdiff;
|
||||
double difficulty;
|
||||
double shareratio;
|
||||
double sharediff;
|
||||
uint32_t height;
|
||||
|
21
util.cpp
21
util.cpp
@ -790,6 +790,7 @@ bool fulltest(const uint32_t *hash, const uint32_t *target)
|
||||
return rc;
|
||||
}
|
||||
|
||||
// Only used by stratum pools
|
||||
void diff_to_target(struct work* work, double diff)
|
||||
{
|
||||
uint32_t *target = work->target;
|
||||
@ -810,6 +811,26 @@ void diff_to_target(struct work* work, double diff)
|
||||
}
|
||||
}
|
||||
|
||||
// Only used by longpoll pools
|
||||
double target_to_diff(uint32_t* target)
|
||||
{
|
||||
uchar* tgt = (uchar*) target;
|
||||
uint64_t m =
|
||||
(uint64_t)tgt[29] << 56 |
|
||||
(uint64_t)tgt[28] << 48 |
|
||||
(uint64_t)tgt[27] << 40 |
|
||||
(uint64_t)tgt[26] << 32 |
|
||||
(uint64_t)tgt[25] << 24 |
|
||||
(uint64_t)tgt[24] << 16 |
|
||||
(uint64_t)tgt[23] << 8 |
|
||||
(uint64_t)tgt[22] << 0;
|
||||
|
||||
if (!m)
|
||||
return 0.;
|
||||
else
|
||||
return (double)0x0000ffff00000000/m;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
#define socket_blocks() (WSAGetLastError() == WSAEWOULDBLOCK)
|
||||
#else
|
||||
|
Loading…
Reference in New Issue
Block a user