Share more fields between stratum and 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 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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
diff --git a/cgminer.c b/cgminer.c
index 351476c..d6e0ea7 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -6770,7 +6770,7 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
/* Generate merkle root */
gen_hash(pool->coinbase, merkle_root, pool->coinbase_len);
memcpy(merkle_sha, merkle_root, 32);
- for (i = 0; i < pool->swork.merkles; i++) {
+ for (i = 0; i < pool->merkles; i++) {
memcpy(merkle_sha + 32, pool->swork.merkle_bin[i], 32);
gen_hash(merkle_sha, merkle_root, 64);
memcpy(merkle_sha, merkle_root, 32);
@@ -6790,7 +6790,7 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
/* Copy parameters required for share submission */
work->job_id = strdup(pool->swork.job_id);
work->nonce1 = strdup(pool->nonce1);
- work->ntime = strdup(pool->swork.ntime);
+ work->ntime = strdup(pool->ntime);
cg_runlock(&pool->data_lock);
if (opt_debug) {
diff --git a/miner.h b/miner.h
index fb9c238..de6fdb3 100644
--- a/miner.h
+++ b/miner.h
@@ -1125,15 +1125,10 @@ enum pool_enable {
struct stratum_work {
char *job_id;
- char *prev_hash;
unsigned char **merkle_bin;
- char *bbversion;
- char *nbit;
- char *ntime;
bool clean;
size_t header_len;
- int merkles;
double diff;
};
@@ -1255,7 +1250,6 @@ struct pool {
int gbt_txns;
bool gbt_solo;
- int merkles;
unsigned char merklebin[16 * 32];
int transactions;
unsigned char **txn_data;
@@ -1268,7 +1262,12 @@ struct pool {
int coinbase_len;
int nonce2_offset;
unsigned char header_bin[128];
+ int merkles;
int merkle_offset;
+ char *prev_hash;
+ char *bbversion;
+ char *nbit;
+ char *ntime;
struct timeval tv_lastwork;
};
diff --git a/util.c b/util.c
index 1e36123..cb4c8dd 100644
--- a/util.c
+++ b/util.c
@@ -1595,7 +1595,7 @@ static char *json_array_string(json_t *val, unsigned int entry)
return NULL;
}
-static char *blank_merkel = "0000000000000000000000000000000000000000000000000000000000000000";
+static char *blank_merkle = "0000000000000000000000000000000000000000000000000000000000000000";
static bool parse_notify(struct pool *pool, json_t *val)
{
@@ -1643,22 +1643,22 @@ static bool parse_notify(struct pool *pool, json_t *val)
cg_wlock(&pool->data_lock);
free(pool->swork.job_id);
- free(pool->swork.prev_hash);
- free(pool->swork.bbversion);
- free(pool->swork.nbit);
- free(pool->swork.ntime);
+ free(pool->prev_hash);
+ free(pool->bbversion);
+ free(pool->nbit);
+ free(pool->ntime);
pool->swork.job_id = job_id;
- pool->swork.prev_hash = prev_hash;
+ pool->prev_hash = prev_hash;
cb1_len = strlen(coinbase1) / 2;
cb2_len = strlen(coinbase2) / 2;
- pool->swork.bbversion = bbversion;
- pool->swork.nbit = nbit;
- pool->swork.ntime = ntime;
+ pool->bbversion = bbversion;
+ pool->nbit = nbit;
+ pool->ntime = ntime;
pool->swork.clean = clean;
alloc_len = pool->coinbase_len = cb1_len + pool->n1_len + pool->n2size + cb2_len;
pool->nonce2_offset = cb1_len + pool->n1_len;
- for (i = 0; i < pool->swork.merkles; i++)
+ for (i = 0; i < pool->merkles; i++)
free(pool->swork.merkle_bin[i]);
if (merkles) {
pool->swork.merkle_bin = realloc(pool->swork.merkle_bin,
@@ -1679,15 +1679,15 @@ static bool parse_notify(struct pool *pool, json_t *val)
}
}
}
- pool->swork.merkles = merkles;
+ pool->merkles = merkles;
if (clean)
pool->nonce2 = 0;
- pool->merkle_offset = strlen(pool->swork.bbversion) +
- strlen(pool->swork.prev_hash);
+ pool->merkle_offset = strlen(pool->bbversion) +
+ strlen(pool->prev_hash);
pool->swork.header_len = pool->merkle_offset +
/* merkle_hash */ 32 +
- strlen(pool->swork.ntime) +
- strlen(pool->swork.nbit) +
+ strlen(pool->ntime) +
+ strlen(pool->nbit) +
/* nonce */ 8 +
/* workpadding */ 96;
pool->merkle_offset /= 2;
@@ -1696,11 +1696,11 @@ static bool parse_notify(struct pool *pool, json_t *val)
header = alloca(pool->swork.header_len);
snprintf(header, pool->swork.header_len,
"%s%s%s%s%s%s%s",
- pool->swork.bbversion,
- pool->swork.prev_hash,
- blank_merkel,
- pool->swork.ntime,
- pool->swork.nbit,
+ pool->bbversion,
+ pool->prev_hash,
+ blank_merkle,
+ pool->ntime,
+ pool->nbit,
"00000000", /* nonce */
workpadding);
ret = hex2bin(pool->header_bin, header, 128);