Browse Source

Update GBT longpollid every time we request a new longpoll.

nfactor-troky
Con Kolivas 12 years ago
parent
commit
fc94e00fd1
  1. 23
      cgminer.c

23
cgminer.c

@ -1562,7 +1562,7 @@ static bool gbt_decode(struct pool *pool, json_t *res_val)
mutex_lock(&pool->gbt_lock); mutex_lock(&pool->gbt_lock);
free(pool->coinbasetxn); free(pool->coinbasetxn);
pool->coinbasetxn = strdup(coinbasetxn); pool->coinbasetxn = strdup(coinbasetxn);
if (!pool->longpollid) free(pool->longpollid);
pool->longpollid = strdup(longpollid); pool->longpollid = strdup(longpollid);
hex2bin(hash_swap, previousblockhash, 32); hex2bin(hash_swap, previousblockhash, 32);
@ -3575,8 +3575,8 @@ static bool test_work_current(struct work *work)
if (!work->stratum) { if (!work->stratum) {
if (work->longpoll) { if (work->longpoll) {
applog(LOG_NOTICE, "LONGPOLL from pool %d detected new block", applog(LOG_NOTICE, "%sLONGPOLL from pool %d detected new block",
work->pool->pool_no); work->gbt ? "GBT " : "", work->pool->pool_no);
work->longpoll = false; work->longpoll = false;
} else if (have_longpoll) } else if (have_longpoll)
applog(LOG_NOTICE, "New block detected on network before longpoll"); applog(LOG_NOTICE, "New block detected on network before longpoll");
@ -3587,8 +3587,8 @@ static bool test_work_current(struct work *work)
} else if (work->longpoll) { } else if (work->longpoll) {
work->longpoll = false; work->longpoll = false;
if (work->pool == current_pool()) { if (work->pool == current_pool()) {
applog(LOG_NOTICE, "LONGPOLL from pool %d requested work restart", applog(LOG_NOTICE, "%sLONGPOLL from pool %d requested work restart",
work->pool->pool_no); work->gbt ? "GBT " : "", work->pool->pool_no);
work_block++; work_block++;
restart_threads(); restart_threads();
} }
@ -5696,9 +5696,6 @@ retry_pool:
wait_lpcurrent(cp); wait_lpcurrent(cp);
if (pool->has_gbt) { if (pool->has_gbt) {
sprintf(lpreq, "{\"id\": 0, \"method\": \"getblocktemplate\", \"params\": "
"[{\"capabilities\": [\"coinbasetxn\", \"workid\", \"coinbase/append\"], "
"\"longpollid\": \"%s\"}]}\n", pool->longpollid);
lp_url = pool->rpc_url; lp_url = pool->rpc_url;
applog(LOG_WARNING, "GBT longpoll ID activated for %s", lp_url); applog(LOG_WARNING, "GBT longpoll ID activated for %s", lp_url);
} else { } else {
@ -5718,6 +5715,16 @@ retry_pool:
gettimeofday(&start, NULL); gettimeofday(&start, NULL);
/* Update the longpollid every time, but do it under lock to
* avoid races */
if (pool->has_gbt) {
mutex_lock(&pool->gbt_lock);
sprintf(lpreq, "{\"id\": 0, \"method\": \"getblocktemplate\", \"params\": "
"[{\"capabilities\": [\"coinbasetxn\", \"workid\", \"coinbase/append\"], "
"\"longpollid\": \"%s\"}]}\n", pool->longpollid);
mutex_unlock(&pool->gbt_lock);
}
/* Longpoll connections can be persistent for a very long time /* Longpoll connections can be persistent for a very long time
* and any number of issues could have come up in the meantime * and any number of issues could have come up in the meantime
* so always establish a fresh connection instead of relying on * so always establish a fresh connection instead of relying on

Loading…
Cancel
Save