hackjealousy
Newbie
Offline
Activity: 53
Merit: 0
|
|
December 26, 2012, 08:55:58 PM |
|
Here is a small patch against cgminer-2.10.3 that shows the value of each share calculated using PPS, POT, and the latest proposed system (PPOT.) I do not include any pool fees in the calculations so the value will be high by a few percent. I also modified the target and share difficulty display in the "Accepted" log message. It now shows more accuracy. (Average target and share difficulties are kept as well.) Cut and paste the patch below into a file, cgminer.patch . Then: $ tar xvf ~/Downloads/cgminer-2.10.3.tar.bz2 $ patch -p0 < cgminer.patch Configure and build as normal. --- cgminer-2.10.3/cgminer.c 2012-12-25 14:38:50.000000000 -0800 +++ cgminer-2.10.3-share/cgminer.c 2012-12-26 12:35:49.583369271 -0800 @@ -186,6 +186,8 @@ static struct timeval total_tv_start, to pthread_mutex_t control_lock; pthread_mutex_t stats_lock; +long double g_network_difficulty = 0, g_avg_target_difficulty = 0, g_avg_share_difficulty = 0, g_total_pps = 0, g_total_pot = 0, g_total_pro_pot = 0; + int hw_errors; int total_accepted, total_rejected, total_diff1; int total_getworks, total_stale, total_discarded; @@ -1943,7 +1945,10 @@ static void curses_print_status(void) wclrtoeol(statuswin); mvwprintw(statuswin, 5, 0, " Block: %s... Diff:%s Started: %s Best share: %s ", current_hash, block_diff, blocktime, best_share); - mvwhline(statuswin, 6, 0, '-', 80); + mvwprintw(statuswin, 6, 0, " PPS: %3.8Lf BTC (Avg Target: %2.4Lf, Avg Share: %2.4Lf) ", g_total_pps, g_avg_target_difficulty, g_avg_share_difficulty); + mvwprintw(statuswin, 7, 0, " POT: %3.8Lf BTC, (%%%3.1Lf : %Lf BTC) ", g_total_pot, 100.0L * g_total_pot / g_total_pps, g_total_pot - g_total_pps); + mvwprintw(statuswin, 8, 0, " PPOT: %3.8Lf BTC, (%%%3.1Lf : %Lf BTC) ", g_total_pro_pot, 100.0L * g_total_pro_pot / g_total_pps, g_total_pro_pot - g_total_pps); + mvwhline(statuswin, 9, 0, '-', 80); mvwhline(statuswin, statusy - 1, 0, '-', 80); mvwprintw(statuswin, devcursor - 1, 1, "[P]ool management %s[S]ettings [D]isplay options [Q]uit", have_opencl ? "[G]PU management " : ""); @@ -2204,6 +2209,107 @@ static void reject_pool(struct pool *poo pool->enabled = POOL_REJECTING; } + +static void uncompress(uint32_t bits, uint32_t *target) { + + uint32_t nb = 0, v; + int s = 0; + + nb = ((bits >> 24) & 0xff) - 3; + v = bits & 0x00ffffff; + + s = (nb % 4) * 8; + if (s == 0) { + s = 32; + nb--; + } + + memset(target, 0, 32); + target[(nb >> 2) + 1] = v >> (32 - s); + target[nb >> 2] = v << s; +} + + +/* + * network difficulty, work target difficulty, share difficulty + */ +static long double diff1() { + + static long double d1 = 0.0L; + static int diff1_init = 0; + static unsigned char diff1_8[32] = { + 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + if(!diff1_init) { + int i; + + for(i = 0; i < 32; i++) { + d1 *= 256; + d1 += diff1_8[i]; + } + diff1_init = 1; + } + + return d1; +} + + +static long double network_difficulty(const struct work *work) { + + int i; + uint32_t bits; + unsigned char ntarget[32]; + long double d = 0.0L; + + bits = swab32(*((uint32_t *)(work->data + 72))); + uncompress(bits, (uint32_t *)ntarget); + for(i = 31; i >= 0; i--) { + d *= 256.0; + d += ntarget[i]; + } + if(d == 0) + return -1; + + return diff1() / d; +} + + +static long double work_target_difficulty(const struct work *work) { + + int i; + long double d = 0.0L; + + for(i = 31; i >= 0; i--) { + d *= 256.0; + d += work->target[i]; + } + if(d == 0) + return -1; + + return diff1() / d; +} + + +static long double share_difficulty(const struct work *work) { + + int i; + long double d = 0.0L; + + for(i = 31; i >= 0; i--) { + d *= 256.0; + d += work->hash[i]; + } + if(d == 0) + return -1; + + return diff1() / d; +} + + /* Theoretically threads could race when modifying accepted and * rejected values but the chance of two submits completing at the * same time is zero so there is no point adding extra locking */ @@ -2215,6 +2321,29 @@ share_result(json_t *val, json_t *res, j struct cgpu_info *cgpu = thr_info[work->thr_id].cgpu; if (json_is_true(res) || (work->gbt && json_is_null(res))) { + long double nd, td, sd, ppsv, m, potv, ppotv, pf, ppf; + + nd = network_difficulty(work); + td = work_target_difficulty(work); + sd = share_difficulty(work); + ppsv = 25.0L * td / nd; // BTC + /* + [(1-a)/(1-a*wd^(1-a)*X^(a-1))]*(wd*B/D)*(min(X,sd)/wd)^a + ((1 - a) / (1 - a(td / X)^(1 - a))) * ppsv * (min(X, sd) / td)^a + + a = 0.8 = 4/5, X = 1.5D + */ + m = (sd <= 1.5L * nd)? sd : 1.5L * nd; + pf = (1.0L / (5.0L - 4.0L * powl(1.5L * td / nd, 0.2L))) * powl(m / td, 0.8L); + potv = pf * ppsv; + + /* + a = 0.75, X = 5D + */ + m = (sd <= 5.0L * nd)? sd : 5.0L * nd; + ppf = (1.0L / (4.0L - 3.0L * powl(0.2L * td / nd, 0.25L))) * powl(m / td, 0.75L); + ppotv = ppf * ppsv; + mutex_lock(&stats_lock); cgpu->accepted++; total_accepted++; @@ -2222,6 +2351,14 @@ share_result(json_t *val, json_t *res, j cgpu->diff_accepted += work->work_difficulty; total_diff_accepted += work->work_difficulty; pool->diff_accepted += work->work_difficulty; + + g_network_difficulty = nd; + g_avg_target_difficulty = ((total_accepted - 1) * g_avg_target_difficulty + td) / ((long double)total_accepted); + g_avg_share_difficulty = ((total_accepted - 1) * g_avg_share_difficulty + sd) / ((long double)total_accepted); + g_total_pps += ppsv; + g_total_pot += potv; + g_total_pro_pot += ppotv; + mutex_unlock(&stats_lock); pool->seq_rejects = 0; @@ -2232,12 +2369,22 @@ share_result(json_t *val, json_t *res, j pool->last_share_diff = work->work_difficulty; applog(LOG_DEBUG, "PROOF OF WORK RESULT: true (yay!!!)"); if (!QUIET) { - if (total_pools > 1) - applog(LOG_NOTICE, "Accepted %s %s %d pool %d %s%s", + char logbuf[256]; + unsigned int len; + + if(total_pools > 1) + snprintf(logbuf, sizeof(logbuf), "Accepted %s %s %d pool %d %s%s", hashshow, cgpu->api->name, cgpu->device_id, work->pool->pool_no, resubmit ? "(resubmit)" : "", worktime); else - applog(LOG_NOTICE, "Accepted %s %s %d %s%s", + snprintf(logbuf, sizeof(logbuf), "Accepted %s %s %d %s%s", hashshow, cgpu->api->name, cgpu->device_id, resubmit ? "(resubmit)" : "", worktime); + for(len = strlen(logbuf); len < 65; len++) { + logbuf[len] = ' '; + logbuf[len + 1] = 0; + } + snprintf(logbuf + len, sizeof(logbuf) - len, "PPS: %4.1Lf Satoshi (POT: %4.1Lf (%%%3.3Lf) PPOT: %4.1Lf (%%%3.3Lf))", + 100000000.0L * ppsv, 100000000.0L * potv, 100.0L * pf, 100000000.0L * ppotv, 100.0L * ppf); + applog(LOG_NOTICE, "%s", logbuf); } sharelog("accept", work); if (opt_shares && total_accepted >= opt_shares) { @@ -4484,12 +4631,19 @@ static void stratum_share_result(json_t uint32_t *hash32; char diffdisp[16]; int intdiff; + long double wd, sd; + + wd = work_target_difficulty(work); + sd = share_difficulty(work); hash32 = (uint32_t *)(work->hash); intdiff = floor(work->work_difficulty); suffix_string(sharediff, diffdisp, 0); + /* sprintf(hashshow, "%08lx Diff %s/%d%s", (unsigned long)(hash32[6]), diffdisp, intdiff, work->block? " BLOCK!" : ""); + */ + sprintf(hashshow, "%08lx Diff %3.6Lf/%3.6Lf%s", (unsigned long)(hash32[6]), sd, wd, work->block? " BLOCK!" : ""); share_result(val, res_val, err_val, work, hashshow, false, ""); } @@ -6418,7 +6572,8 @@ int main(int argc, char *argv[]) #endif // defined(WIN32) #endif - devcursor = 8; + // devcursor = 8; + devcursor = 11; logstart = devcursor + 1; logcursor = logstart + 1;
|