Browse Source

Make longpoll do a mandatory flushing of all work even if the block hasn't changed, thus supporting longpoll initiated work change of any sort and

merged mining.
nfactor-troky
Con Kolivas 13 years ago
parent
commit
a70629a701
  1. 21
      main.c
  2. 1
      miner.h

21
main.c

@ -267,6 +267,7 @@ static int total_accepted, total_rejected;
static int total_getworks, total_stale, total_discarded; static int total_getworks, total_stale, total_discarded;
static int total_queued; static int total_queued;
static unsigned int new_blocks; static unsigned int new_blocks;
static unsigned int work_block;
static unsigned int found_blocks; static unsigned int found_blocks;
static unsigned int local_work; static unsigned int local_work;
@ -2614,7 +2615,6 @@ static bool stale_work(struct work *work, bool share)
{ {
struct timeval now; struct timeval now;
bool ret = false; bool ret = false;
char *hexstr;
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
if (share) { if (share) {
@ -2627,16 +2627,8 @@ static bool stale_work(struct work *work, bool share)
if (donor(work->pool)) if (donor(work->pool))
return ret; return ret;
hexstr = bin2hex(work->data, 18); if (work->work_block != work_block)
if (unlikely(!hexstr)) {
applog(LOG_ERR, "submit_work_thread OOM");
return ret;
}
if (strcmp(hexstr, current_block))
ret = true; ret = true;
free(hexstr);
return ret; return ret;
} }
@ -2916,9 +2908,11 @@ static void test_work_current(struct work *work, bool longpoll)
HASH_ADD_STR(blocks, hash, s); HASH_ADD_STR(blocks, hash, s);
wr_unlock(&blk_lock); wr_unlock(&blk_lock);
set_curblock(hexstr, work->data); set_curblock(hexstr, work->data);
if (++new_blocks == 1) if (unlikely(++new_blocks == 1))
goto out_free; goto out_free;
work_block++;
if (longpoll) if (longpoll)
applog(LOG_NOTICE, "LONGPOLL detected new block on network, waiting on fresh work"); applog(LOG_NOTICE, "LONGPOLL detected new block on network, waiting on fresh work");
else if (have_longpoll) else if (have_longpoll)
@ -2926,6 +2920,10 @@ static void test_work_current(struct work *work, bool longpoll)
else else
applog(LOG_NOTICE, "New block detected on network, waiting on fresh work"); applog(LOG_NOTICE, "New block detected on network, waiting on fresh work");
restart_threads(); restart_threads();
} else if (longpoll) {
applog(LOG_NOTICE, "LONGPOLL requested work restart, waiting on fresh work");
work_block++;
restart_threads();
} }
out_free: out_free:
free(hexstr); free(hexstr);
@ -2972,6 +2970,7 @@ static void *stage_thread(void *userdata)
ok = false; ok = false;
break; break;
} }
work->work_block = work_block;
test_work_current(work, false); test_work_current(work, false);

1
miner.h

@ -478,6 +478,7 @@ struct work {
bool cloned; bool cloned;
bool rolltime; bool rolltime;
unsigned int work_block;
int id; int id;
UT_hash_handle hh; UT_hash_handle hh;
}; };

Loading…
Cancel
Save