Hook into various places to generate GBT work where appropriate.
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
diff --git a/cgminer.c b/cgminer.c
index 04b21da..eb34cd0 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -3028,6 +3028,19 @@ retry:
}
if (pool->has_gbt) {
+#if 0
+ while (pool->idle) {
+ struct pool *altpool = select_pool(true);
+
+ sleep(5);
+ if (altpool != pool) {
+ wc->pool = altpool;
+ inc_queued(altpool);
+ dec_queued(pool);
+ goto retry;
+ }
+ }
+#endif
ret_work = make_work();
gen_gbt_work(pool, ret_work);
if (unlikely(!stage_work(ret_work))) {
@@ -4951,7 +4964,17 @@ static bool reuse_work(struct work *work, struct pool *pool)
if (!pool->stratum_active)
return false;
applog(LOG_DEBUG, "Reusing stratum work");
- gen_stratum_work(pool, work);;
+ gen_stratum_work(pool, work);
+ return true;
+ }
+
+ if (pool->has_gbt) {
+#if 0
+ if (pool->idle)
+ return false;
+#endif
+ applog(LOG_DEBUG, "Reusing GBT work");
+ gen_gbt_work(pool, work);
return true;
}
@@ -5602,7 +5625,7 @@ static struct pool *select_longpoll_pool(struct pool *cp)
{
int i;
- if (cp->hdr_path)
+ if (cp->hdr_path || cp->has_gbt)
return cp;
for (i = 0; i < total_pools; i++) {
struct pool *pool = pools[i];
@@ -5637,6 +5660,8 @@ static void *longpoll_thread(void *userdata)
struct timeval start, reply, end;
CURL *curl = NULL;
int failures = 0;
+ char lpreq[1024];
+ char *lp_url;
int rolltime;
curl = curl_easy_init();
@@ -5660,10 +5685,21 @@ retry_pool:
wait_lpcurrent(cp);
- if (cp == pool)
- applog(LOG_WARNING, "Long-polling activated for %s", pool->lp_url);
- else
- applog(LOG_WARNING, "Long-polling activated for pool %s via %s", cp->rpc_url, pool->lp_url);
+ 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 {
+ strcpy(lpreq, getwork_req);
+
+ lp_url = pool->lp_url;
+ if (cp == pool)
+ applog(LOG_WARNING, "Long-polling activated for %s", lp_url);
+ else
+ applog(LOG_WARNING, "Long-polling activated for pool %s via %s", cp->rpc_url, lp_url);
+ }
while (42) {
json_t *val, *soval;
@@ -5677,9 +5713,8 @@ retry_pool:
* so always establish a fresh connection instead of relying on
* a persistent one. */
curl_easy_setopt(curl, CURLOPT_FRESH_CONNECT, 1);
- val = json_rpc_call(curl, pool->lp_url, pool->rpc_userpass,
- pool->rpc_req, false, true, &rolltime,
- pool, false);
+ val = json_rpc_call(curl, lp_url, pool->rpc_userpass,
+ lpreq, false, true, &rolltime, pool, false);
gettimeofday(&reply, NULL);
@@ -5701,7 +5736,7 @@ retry_pool:
if (end.tv_sec - start.tv_sec > 30)
continue;
if (failures == 1)
- applog(LOG_WARNING, "longpoll failed for %s, retrying every 30s", pool->lp_url);
+ applog(LOG_WARNING, "longpoll failed for %s, retrying every 30s", lp_url);
sleep(30);
}
if (pool != cp) {