Generate the coinbase for generation of stratum based 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
diff --git a/cgminer.c b/cgminer.c
index e880c48..56d7dca 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -4265,6 +4265,28 @@ static struct work *clone_work(struct work *work)
return work;
}
+static void gen_stratum_work(struct pool *pool, struct work *work)
+{
+ char *coinbase, *nonce2;
+ int len;
+
+ mutex_lock(&pool->pool_lock);
+ len = strlen(pool->swork.coinbase1) +
+ strlen(pool->nonce1) +
+ pool->n2size +
+ strlen(pool->swork.coinbase2);
+ coinbase = alloca(len + 1);
+ sprintf(coinbase, "%s", pool->swork.coinbase1);
+ strcat(coinbase, pool->nonce1);
+ nonce2 = bin2hex((const unsigned char *)&pool->nonce2, pool->n2size);
+ pool->nonce2++;
+ strcat(coinbase, nonce2);
+ free(nonce2);
+ strcat(coinbase, pool->swork.coinbase2);
+ mutex_unlock(&pool->pool_lock);
+ applog(LOG_DEBUG, "Generated stratum coinbase %s", coinbase);
+}
+
static void get_work(struct work *work, struct thr_info *thr, const int thr_id)
{
struct timespec abstime = {0, 0};
@@ -4284,6 +4306,11 @@ static void get_work(struct work *work, struct thr_info *thr, const int thr_id)
retry:
pool = current_pool();
+ if (pool->has_stratum) {
+ gen_stratum_work(pool, work);
+ goto out;
+ }
+
if (reuse_work(work))
goto out;
diff --git a/miner.h b/miner.h
index 9efbedc..28d102a 100644
--- a/miner.h
+++ b/miner.h
@@ -837,6 +837,7 @@ struct pool {
struct sockaddr_in *server, client;
char *subscription;
char *nonce1;
+ uint32_t nonce2;
int n2size;
bool has_stratum;
bool stratum_active;
diff --git a/util.c b/util.c
index 75f8e6b..0c75bb5 100644
--- a/util.c
+++ b/util.c
@@ -1014,6 +1014,8 @@ static bool parse_notify(struct pool *pool, json_t *val)
pool->swork.merkle[i] = json_array_string(arr, i);
}
pool->swork.merkles = merkles;
+ if (clean)
+ pool->nonce2 = 0;
mutex_unlock(&pool->pool_lock);
if (opt_protocol) {