Extract and store the various variables GBT uses when decoding gbt work.
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
diff --git a/cgminer.c b/cgminer.c
index 8464c07..5f1fc08 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -1357,6 +1357,64 @@ static void calc_midstate(struct work *work)
#endif
}
+static bool gbt_decode(struct pool *pool, json_t *res_val)
+{
+ const char *previousblockhash;
+ const char *target;
+ const char *coinbasetxn;
+ const char *longpollid;
+ int expires;
+ int version;
+ int curtime;
+ bool submitold;
+ const char *bits;
+
+ previousblockhash = json_string_value(json_object_get(res_val, "previousblockhash"));
+ target = json_string_value(json_object_get(res_val, "target"));
+ coinbasetxn = json_string_value(json_object_get(json_object_get(res_val, "coinbasetxn"), "data"));
+ longpollid = json_string_value(json_object_get(res_val, "longpollid"));
+ expires = json_integer_value(json_object_get(res_val, "expires"));
+ version = json_integer_value(json_object_get(res_val, "version"));
+ curtime = json_integer_value(json_object_get(res_val, "curtime"));
+ submitold = json_is_true(json_object_get(res_val, "submitold"));
+ bits = json_string_value(json_object_get(res_val, "bits"));
+
+ if (!previousblockhash || !target || !coinbasetxn || !longpollid ||
+ !expires || !version || !curtime || !bits) {
+ applog(LOG_ERR, "JSON failed to decode GBT");
+ return false;
+ }
+
+ applog(LOG_DEBUG, "previousblockhash: %s", previousblockhash);
+ applog(LOG_DEBUG, "target: %s", target);
+ applog(LOG_DEBUG, "coinbasetxn: %s", coinbasetxn);
+ applog(LOG_DEBUG, "longpollid: %s", longpollid);
+ applog(LOG_DEBUG, "expires: %d", expires);
+ applog(LOG_DEBUG, "version: %d", version);
+ applog(LOG_DEBUG, "curtime: %d", curtime);
+ applog(LOG_DEBUG, "submitold: %s", submitold ? "true" : "false");
+ applog(LOG_DEBUG, "bits: %s", bits);
+
+ mutex_lock(&pool->gbt_lock);
+ free(pool->previousblockhash);
+ free(pool->gbt_target);
+ free(pool->coinbasetxn);
+ free(pool->longpollid);
+ free(pool->gbt_bits);
+ pool->previousblockhash = strdup(previousblockhash);
+ pool->gbt_target = strdup(target);
+ pool->coinbasetxn = strdup(coinbasetxn);
+ pool->longpollid = strdup(longpollid);
+ pool->gbt_expires = expires;
+ pool->gbt_version = htobe32(version);
+ pool->curtime = htobe32(curtime);
+ pool->gbt_submitold = submitold;
+ pool->gbt_bits = strdup(bits);
+ mutex_unlock(&pool->gbt_lock);
+
+ return true;
+}
+
static bool getwork_decode(json_t *res_val, struct work *work)
{
if (unlikely(!jobj_binary(res_val, "data", work->data, sizeof(work->data), true))) {
@@ -1393,11 +1451,12 @@ static bool work_decode(struct pool *pool, struct work *work, json_t *val)
}
if (pool->has_gbt) {
+ if (unlikely(!gbt_decode(pool, res_val)))
+ goto out;
work->gbt = true;
+ ret = true;
goto out;
- }
-
- if (unlikely(!getwork_decode(res_val, work)))
+ } else if (unlikely(!getwork_decode(res_val, work)))
goto out;
memset(work->hash, 0, sizeof(work->hash));
diff --git a/miner.h b/miner.h
index 278b2be..0b20984 100644
--- a/miner.h
+++ b/miner.h
@@ -887,6 +887,16 @@ struct pool {
/* GBT variables */
bool has_gbt;
pthread_mutex_t gbt_lock;
+ char *previousblockhash;
+ char *gbt_target;
+ char *coinbasetxn;
+ char *longpollid;
+ int gbt_expires;
+ uint32_t gbt_version;
+ uint32_t curtime;
+ bool gbt_submitold;
+ char *gbt_bits;
+
};
#define GETWORK_MODE_TESTPOOL 'T'