Browse Source

Further consolidate the hash regeneration between sha and scrypt doing it only once and always checking the share diff for both before submission.

nfactor-troky
Con Kolivas 12 years ago
parent
commit
0b6ee62cc4
  1. 64
      cgminer.c

64
cgminer.c

@ -3220,8 +3220,6 @@ static void *submit_work_thread(void *userdata)
applog(LOG_DEBUG, "Creating extra submit work thread"); applog(LOG_DEBUG, "Creating extra submit work thread");
rebuild_hash(work);
if (stale_work(work, true)) { if (stale_work(work, true)) {
if (opt_submit_stale) if (opt_submit_stale)
applog(LOG_NOTICE, "Pool %d stale share detected, submitting as user requested", pool->pool_no); applog(LOG_NOTICE, "Pool %d stale share detected, submitting as user requested", pool->pool_no);
@ -5463,45 +5461,13 @@ void inc_hw_errors(struct thr_info *thr)
thr->cgpu->drv->hw_error(thr); thr->cgpu->drv->hw_error(thr);
} }
/* Returns 1 if meets difficulty target, 0 if not, -1 if hw error */
static int hashtest(struct thr_info *thr, struct work *work)
{
uint32_t *data32 = (uint32_t *)(work->data);
unsigned char swap[80];
uint32_t *swap32 = (uint32_t *)swap;
unsigned char hash1[32];
unsigned char hash2[32];
uint32_t *hash2_32 = (uint32_t *)hash2;
flip80(swap32, data32);
sha2(swap, 80, hash1);
sha2(hash1, 32, work->hash);
flip32(hash2_32, work->hash);
if (hash2_32[7] != 0) {
applog(LOG_WARNING, "%s%d: invalid nonce - HW error",
thr->cgpu->drv->name, thr->cgpu->device_id);
return -1;
}
if (!fulltest(hash2, work->target)) {
applog(LOG_INFO, "Share below target");
/* Check the diff of the share, even if it didn't reach the
* target, just to set the best share value if it's higher. */
regen_hash(work);
share_diff(work);
return 0;
}
return 1;
}
void submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce) void submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce)
{ {
uint32_t *work_nonce = (uint32_t *)(work->data + 64 + 12); uint32_t *work_nonce = (uint32_t *)(work->data + 64 + 12);
struct timeval tv_work_found; struct timeval tv_work_found;
int valid; unsigned char hash2[32];
uint32_t *hash2_32 = (uint32_t *)hash2;
uint32_t diff1targ;
cgtime(&tv_work_found); cgtime(&tv_work_found);
*work_nonce = htole32(nonce); *work_nonce = htole32(nonce);
@ -5513,22 +5479,28 @@ void submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce)
mutex_unlock(&stats_lock); mutex_unlock(&stats_lock);
/* Do one last check before attempting to submit the work */ /* Do one last check before attempting to submit the work */
if (opt_scrypt) rebuild_hash(work);
valid = scrypt_test(work->data, work->target, nonce); flip32(hash2_32, work->hash);
else
valid = hashtest(thr, work);
if (unlikely(valid == -1)) diff1targ = opt_scrypt ? 0x0000ffffUL : 0;
return inc_hw_errors(thr); if (be32toh(hash2_32[7]) > diff1targ) {
applog(LOG_WARNING, "%s%d: invalid nonce - HW error",
thr->cgpu->drv->name, thr->cgpu->device_id);
inc_hw_errors(thr);
return;
}
mutex_lock(&stats_lock); mutex_lock(&stats_lock);
thr->cgpu->last_device_valid_work = time(NULL); thr->cgpu->last_device_valid_work = time(NULL);
mutex_unlock(&stats_lock); mutex_unlock(&stats_lock);
if (valid == 1) if (!fulltest(hash2, work->target)) {
submit_work_async(work, &tv_work_found);
else
applog(LOG_INFO, "Share below target"); applog(LOG_INFO, "Share below target");
return;
}
submit_work_async(work, &tv_work_found);
} }
static inline bool abandon_work(struct work *work, struct timeval *wdiff, uint64_t hashes) static inline bool abandon_work(struct work *work, struct timeval *wdiff, uint64_t hashes)

Loading…
Cancel
Save