Construct block for submission when using GBT.
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
diff --git a/cgminer.c b/cgminer.c
index 598cf9f..fc501fe 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -1469,6 +1469,7 @@ static void calc_diff(struct work *work, int known);
static void gen_gbt_work(struct pool *pool, struct work *work)
{
unsigned char *merkleroot;
+ char *cbhex;
mutex_lock(&pool->gbt_lock);
__build_gbt_coinbase(pool);
@@ -1477,8 +1478,10 @@ static void gen_gbt_work(struct pool *pool, struct work *work)
hex2bin(work->data + 4, pool->previousblockhash, 32);
memcpy(work->data + 4 + 32 + 32, &pool->curtime, 4);
hex2bin(work->data + 4 + 32 + 32 + 4, pool->gbt_bits, 4);
-
hex2bin(work->target, pool->gbt_target, 32);
+ cbhex = bin2hex(pool->gbt_coinbase, pool->coinbase_len);
+ sprintf(work->gbt_coinbase, "%s", cbhex);
+ free(cbhex);
mutex_unlock(&pool->gbt_lock);
memcpy(work->data + 4 + 32, merkleroot, 32);
@@ -2279,8 +2282,17 @@ static bool submit_upstream_work(struct work *work, CURL *curl, bool resubmit)
hexstr = bin2hex(work->data, sizeof(work->data));
/* build JSON-RPC request */
- sprintf(s, "{\"method\": \"getwork\", \"params\": [ \"%s\" ], \"id\":1}", hexstr);
- applog(LOG_DEBUG, "DBG: sending %s submit RPC call: %s", pool->rpc_url, s);
+ if (work->gbt) {
+ char gbt_block[512], *header;
+
+ header = bin2hex(work->data, 80);
+ sprintf(gbt_block, "%s0%s", header, work->gbt_coinbase);
+ free(header);
+
+ sprintf(s, "{\"id\": 0, \"method\": \"submitblock\", \"params\": [\"%s\"]}", gbt_block);
+ } else
+ sprintf(s, "{\"method\": \"getwork\", \"params\": [ \"%s\" ], \"id\":1}", hexstr);
+ applog(LOG_WARNING, "DBG: sending %s submit RPC call: %s", pool->rpc_url, s);
strcat(s, "\n");
gettimeofday(&tv_submit, NULL);
diff --git a/miner.h b/miner.h
index adb3ae5..1c505bc 100644
--- a/miner.h
+++ b/miner.h
@@ -946,6 +946,7 @@ struct work {
int sdiff;
bool gbt;
+ char gbt_coinbase[292];
unsigned int work_block;
int id;