Update GBT longpollid every time we request a new longpoll.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
diff --git a/cgminer.c b/cgminer.c
index eae7228..2571613 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -1562,8 +1562,8 @@ static bool gbt_decode(struct pool *pool, json_t *res_val)
mutex_lock(&pool->gbt_lock);
free(pool->coinbasetxn);
pool->coinbasetxn = strdup(coinbasetxn);
- if (!pool->longpollid)
- pool->longpollid = strdup(longpollid);
+ free(pool->longpollid);
+ pool->longpollid = strdup(longpollid);
hex2bin(hash_swap, previousblockhash, 32);
swap256(pool->previousblockhash, hash_swap);
@@ -3575,8 +3575,8 @@ static bool test_work_current(struct work *work)
if (!work->stratum) {
if (work->longpoll) {
- applog(LOG_NOTICE, "LONGPOLL from pool %d detected new block",
- work->pool->pool_no);
+ applog(LOG_NOTICE, "%sLONGPOLL from pool %d detected new block",
+ work->gbt ? "GBT " : "", work->pool->pool_no);
work->longpoll = false;
} else if (have_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) {
work->longpoll = false;
if (work->pool == current_pool()) {
- applog(LOG_NOTICE, "LONGPOLL from pool %d requested work restart",
- work->pool->pool_no);
+ applog(LOG_NOTICE, "%sLONGPOLL from pool %d requested work restart",
+ work->gbt ? "GBT " : "", work->pool->pool_no);
work_block++;
restart_threads();
}
@@ -5696,9 +5696,6 @@ retry_pool:
wait_lpcurrent(cp);
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;
applog(LOG_WARNING, "GBT longpoll ID activated for %s", lp_url);
} else {
@@ -5718,6 +5715,16 @@ retry_pool:
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
* and any number of issues could have come up in the meantime
* so always establish a fresh connection instead of relying on