Browse Source

Convert work decode function to prepare for decoding block templates.

nfactor-troky
Con Kolivas 12 years ago
parent
commit
8afc1f6512
  1. 35
      cgminer.c
  2. 2
      miner.h

35
cgminer.c

@ -1358,37 +1358,46 @@ static void calc_midstate(struct work *work)
#endif #endif
} }
static bool work_decode(const json_t *val, struct work *work) static bool work_decode(struct pool *pool, struct work *work, json_t *val)
{ {
if (unlikely(!jobj_binary(val, "data", work->data, sizeof(work->data), true))) { bool ret = false;
json_t *res_val;
if (pool->has_gbt) {
work->gbt = true;
goto out;
}
res_val = json_object_get(val, "result");
if (unlikely(!jobj_binary(res_val, "data", work->data, sizeof(work->data), true))) {
applog(LOG_ERR, "JSON inval data"); applog(LOG_ERR, "JSON inval data");
goto err_out; goto out;
} }
if (!jobj_binary(val, "midstate", work->midstate, sizeof(work->midstate), false)) { if (!jobj_binary(res_val, "midstate", work->midstate, sizeof(work->midstate), false)) {
// Calculate it ourselves // Calculate it ourselves
applog(LOG_DEBUG, "Calculating midstate locally"); applog(LOG_DEBUG, "Calculating midstate locally");
calc_midstate(work); calc_midstate(work);
} }
if (!jobj_binary(val, "hash1", work->hash1, sizeof(work->hash1), false)) { if (!jobj_binary(res_val, "hash1", work->hash1, sizeof(work->hash1), false)) {
// Always the same anyway // Always the same anyway
memcpy(work->hash1, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x80\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0", 64); memcpy(work->hash1, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x80\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\0\0", 64);
} }
if (unlikely(!jobj_binary(val, "target", work->target, sizeof(work->target), true))) { if (unlikely(!jobj_binary(res_val, "target", work->target, sizeof(work->target), true))) {
applog(LOG_ERR, "JSON inval target"); applog(LOG_ERR, "JSON inval target");
goto err_out; goto out;
} }
memset(work->hash, 0, sizeof(work->hash)); memset(work->hash, 0, sizeof(work->hash));
gettimeofday(&work->tv_staged, NULL); gettimeofday(&work->tv_staged, NULL);
return true; ret = true;
err_out: out:
return false; return ret;
} }
int dev_from_id(int thr_id) int dev_from_id(int thr_id)
@ -2303,7 +2312,7 @@ static bool get_upstream_work(struct work *work, CURL *curl)
pool_stats->getwork_attempts++; pool_stats->getwork_attempts++;
if (likely(val)) { if (likely(val)) {
rc = work_decode(json_object_get(val, "result"), work); rc = work_decode(pool, work, val);
if (unlikely(!rc)) if (unlikely(!rc))
applog(LOG_DEBUG, "Failed to decode work in get_upstream_work"); applog(LOG_DEBUG, "Failed to decode work in get_upstream_work");
} else } else
@ -4477,7 +4486,7 @@ retry_stratum:
struct work *work = make_work(); struct work *work = make_work();
bool rc; bool rc;
rc = work_decode(json_object_get(val, "result"), work); rc = work_decode(pool, work, val);
if (rc) { if (rc) {
applog(LOG_DEBUG, "Successfully retrieved and deciphered work from pool %u %s", applog(LOG_DEBUG, "Successfully retrieved and deciphered work from pool %u %s",
pool->pool_no, pool->rpc_url); pool->pool_no, pool->rpc_url);
@ -5254,7 +5263,7 @@ static void convert_to_work(json_t *val, int rolltime, struct pool *pool, struct
work = make_work(); work = make_work();
rc = work_decode(json_object_get(val, "result"), work); rc = work_decode(pool, work, val);
if (unlikely(!rc)) { if (unlikely(!rc)) {
applog(LOG_ERR, "Could not convert longpoll data to work"); applog(LOG_ERR, "Could not convert longpoll data to work");
free_work(work); free_work(work);

2
miner.h

@ -930,6 +930,8 @@ struct work {
char ntime[16]; char ntime[16];
int sdiff; int sdiff;
bool gbt;
unsigned int work_block; unsigned int work_block;
int id; int id;
UT_hash_handle hh; UT_hash_handle hh;

Loading…
Cancel
Save