Create a function that generates a GBT coinbase from the existing pool variables.
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
diff --git a/cgminer.c b/cgminer.c
index 5f1fc08..384a9a9 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -1357,6 +1357,27 @@ static void calc_midstate(struct work *work)
#endif
}
+/* Generate a GBT coinbase from the existing GBT variables stored. Must be
+ * entered under gbt_lock */
+static void __build_gbt_coinbase(struct pool *pool)
+{
+ unsigned char *coinbase;
+ uint8_t *extra_len;
+ int cbt_len;
+
+ cbt_len = strlen(pool->coinbasetxn) / 2;
+ /* We add 4 bytes of extra data corresponding to nonce2 of stratum */
+ coinbase = calloc(cbt_len + 4, 1);
+ hex2bin(coinbase, pool->coinbasetxn, 42);
+ extra_len = (uint8_t *)(coinbase + 41);
+ *extra_len += 4;
+ hex2bin(coinbase + 42, pool->coinbasetxn + 84, cbt_len - 42);
+ pool->nonce2++;
+ memcpy(coinbase + cbt_len, &pool->nonce2, 4);
+ free(pool->gbt_coinbase);
+ pool->gbt_coinbase = coinbase;
+}
+
static bool gbt_decode(struct pool *pool, json_t *res_val)
{
const char *previousblockhash;
@@ -1394,7 +1415,7 @@ static bool gbt_decode(struct pool *pool, json_t *res_val)
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);
@@ -1410,6 +1431,7 @@ static bool gbt_decode(struct pool *pool, json_t *res_val)
pool->curtime = htobe32(curtime);
pool->gbt_submitold = submitold;
pool->gbt_bits = strdup(bits);
+ __build_gbt_coinbase(pool);
mutex_unlock(&pool->gbt_lock);
return true;
diff --git a/miner.h b/miner.h
index 0b20984..e21228a 100644
--- a/miner.h
+++ b/miner.h
@@ -896,6 +896,7 @@ struct pool {
uint32_t curtime;
bool gbt_submitold;
char *gbt_bits;
+ unsigned char *gbt_coinbase;
};