diff --git a/cgminer.c b/cgminer.c index e880c486..56d7dcaa 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 9efbedc2..28d102af 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 75f8e6bd..0c75bb57 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) {