diff --git a/algorithm.c b/algorithm.c index b9e1783f..1ef2b87b 100644 --- a/algorithm.c +++ b/algorithm.c @@ -1095,63 +1095,63 @@ static void append_equihash_compiler_options(struct _build_kernel_data *data, st static cl_int queue_cryptonight_kernel(_clState *clState, dev_blk_ctx *blk, __maybe_unused cl_uint threads) { - cl_kernel *kernel = &clState->kernel; - unsigned int num = 0; - cl_int status = 0, tgt32 = (blk->work->XMRTarget); - cl_ulong le_target = ((cl_ulong)(blk->work->XMRTarget)); - - //le_target = *(cl_ulong *)(blk->work->device_target + 24); - memcpy(clState->cldata, blk->work->data, blk->work->XMRBlobLen); - - status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, blk->work->XMRBlobLen, clState->cldata , 0, NULL, NULL); - - CL_SET_ARG(clState->CLbuffer0); - CL_SET_ARG(blk->work->XMRBlobLen); - CL_SET_ARG(clState->Scratchpads); - CL_SET_ARG(clState->States); - - num = 0; - kernel = clState->extra_kernels; - CL_SET_ARG(clState->Scratchpads); - CL_SET_ARG(clState->States); - - num = 0; - CL_NEXTKERNEL_SET_ARG(clState->Scratchpads); - CL_SET_ARG(clState->States); - CL_SET_ARG(clState->BranchBuffer[0]); - CL_SET_ARG(clState->BranchBuffer[1]); - CL_SET_ARG(clState->BranchBuffer[2]); - CL_SET_ARG(clState->BranchBuffer[3]); - - num = 0; - CL_NEXTKERNEL_SET_ARG(clState->States); - CL_SET_ARG(clState->BranchBuffer[0]); - CL_SET_ARG(clState->outputBuffer); - CL_SET_ARG(tgt32); - - // last to be set in driver-opencl.c - - num = 0; - CL_NEXTKERNEL_SET_ARG(clState->States); - CL_SET_ARG(clState->BranchBuffer[1]); - CL_SET_ARG(clState->outputBuffer); - CL_SET_ARG(tgt32); - - - num = 0; - CL_NEXTKERNEL_SET_ARG(clState->States); - CL_SET_ARG(clState->BranchBuffer[2]); - CL_SET_ARG(clState->outputBuffer); - CL_SET_ARG(tgt32); - - - num = 0; - CL_NEXTKERNEL_SET_ARG(clState->States); - CL_SET_ARG(clState->BranchBuffer[3]); - CL_SET_ARG(clState->outputBuffer); - CL_SET_ARG(tgt32); - - return(status); + cl_kernel *kernel = &clState->kernel; + unsigned int num = 0; + cl_int status = 0, tgt32 = (blk->work->XMRTarget); + cl_ulong le_target = ((cl_ulong)(blk->work->XMRTarget)); + + //le_target = *(cl_ulong *)(blk->work->device_target + 24); + memcpy(clState->cldata, blk->work->data, blk->work->XMRBlobLen); + + status = clEnqueueWriteBuffer(clState->commandQueue, clState->CLbuffer0, true, 0, blk->work->XMRBlobLen, clState->cldata , 0, NULL, NULL); + + CL_SET_ARG(clState->CLbuffer0); + CL_SET_ARG(blk->work->XMRBlobLen); + CL_SET_ARG(clState->Scratchpads); + CL_SET_ARG(clState->States); + + num = 0; + kernel = clState->extra_kernels; + CL_SET_ARG(clState->Scratchpads); + CL_SET_ARG(clState->States); + + num = 0; + CL_NEXTKERNEL_SET_ARG(clState->Scratchpads); + CL_SET_ARG(clState->States); + CL_SET_ARG(clState->BranchBuffer[0]); + CL_SET_ARG(clState->BranchBuffer[1]); + CL_SET_ARG(clState->BranchBuffer[2]); + CL_SET_ARG(clState->BranchBuffer[3]); + + num = 0; + CL_NEXTKERNEL_SET_ARG(clState->States); + CL_SET_ARG(clState->BranchBuffer[0]); + CL_SET_ARG(clState->outputBuffer); + CL_SET_ARG(tgt32); + + // last to be set in driver-opencl.c + + num = 0; + CL_NEXTKERNEL_SET_ARG(clState->States); + CL_SET_ARG(clState->BranchBuffer[1]); + CL_SET_ARG(clState->outputBuffer); + CL_SET_ARG(tgt32); + + + num = 0; + CL_NEXTKERNEL_SET_ARG(clState->States); + CL_SET_ARG(clState->BranchBuffer[2]); + CL_SET_ARG(clState->outputBuffer); + CL_SET_ARG(tgt32); + + + num = 0; + CL_NEXTKERNEL_SET_ARG(clState->States); + CL_SET_ARG(clState->BranchBuffer[3]); + CL_SET_ARG(clState->outputBuffer); + CL_SET_ARG(tgt32); + + return(status); } diff --git a/miner.h b/miner.h index c602c0d4..9c5fd532 100644 --- a/miner.h +++ b/miner.h @@ -781,12 +781,12 @@ static inline void flip128(void *dest_p, const void *src_p) static inline void flip168(void *dest_p, const void *src_p) { - uint32_t *dest = (uint32_t *)dest_p; - const uint32_t *src = (uint32_t *)src_p; - int i; + uint32_t *dest = (uint32_t *)dest_p; + const uint32_t *src = (uint32_t *)src_p; + int i; - for (i = 0; i < 42; i++) - dest[i] = swab32(src[i]); + for (i = 0; i < 42; i++) + dest[i] = swab32(src[i]); } @@ -803,7 +803,7 @@ static inline void endian_flip128(void *dest_p, const void *src_p) } static inline void endian_flip168(void *dest_p, const void *src_p) { - flip168(dest_p, src_p); + flip168(dest_p, src_p); } #else @@ -1525,7 +1525,7 @@ struct work { unsigned char device_target[32]; double device_diff; double share_diff; - double network_diff; + double network_diff; uint32_t eth_epoch; uint64_t Nonce; diff --git a/sgminer.c b/sgminer.c index 6bcf378f..1c3cc65c 100644 --- a/sgminer.c +++ b/sgminer.c @@ -2542,7 +2542,7 @@ static bool work_decode(struct pool *pool, struct work *work, json_t *val) bool parse_diff_ethash(char* Target, const char* TgtStr); -static bool work_decode_eth(struct pool *pool, struct work *work, json_t *val, json_t *ethval2) +static bool work_decode_eth(struct pool *pool, struct work *work, json_t *val) { int i; bool ret = false; @@ -2573,45 +2573,6 @@ static bool work_decode_eth(struct pool *pool, struct work *work, json_t *val, j if (!parse_diff_ethash(Target, TgtStr)) goto out; - /* - BlockHeightStr = json_string_value(json_object_get(res2_obj, "number")); - - if(!BlockHeightStr) return(false); - - for(i = 0; BlockHeightStr[i]; ++i) - { - if(i == 1) continue; - if(!isxdigit(BlockHeightStr[i])) return(false); - - } - - NetDiffStr = json_string_value(json_object_get(res2_obj, "difficulty")); - - if(!NetDiffStr) return(false); - - for(i = 0; NetDiffStr[i]; ++i) - { - if(i == 1) continue; - if(!isxdigit(NetDiffStr[i])) return(false); - - } - - if(NetDiffStr[1] == 'x') work->network_diff = strtoull(NetDiffStr + 2, NULL); - - if(strlen(NetDiffStr) != 66) - { - char NewNetDiffStr[65]; - uint32_t PadLen = 66 - strlen(NetDiffStr); - - memset(NewNetDiffStr, '0', PadLen); - memcpy(NewNetDiffStr + PadLen, NetDiffStr + 2, strlen(NetDiffStr) - 2); - NewNetDiffStr[64] = 0x00; - - if(!hex2bin(FinalNetDiffStr, NewNetDiffStr, 32UL)) return(false); - } - else if(!hex2bin(FinalNetDiffStr, NetDiffStr + 2, 32UL)) return(false); - */ - cg_ilock(&pool->data_lock); if (pool->eth_cache.current_epoch == UINT32_MAX || memcmp(pool->eth_cache.seed_hash, SeedHash, 32)) { cg_ulock(&pool->data_lock); @@ -3553,7 +3514,7 @@ static bool get_upstream_work(struct work *work, CURL *curl, char *curl_err_str) struct pool *pool = work->pool; struct sgminer_pool_stats *pool_stats = &(pool->sgminer_pool_stats); struct timeval tv_elapsed; - json_t *val = NULL, *ethval2 = NULL; + json_t *val = NULL; bool rc = false; char *url; @@ -3563,26 +3524,19 @@ static bool get_upstream_work(struct work *work, CURL *curl, char *curl_err_str) cgtime(&work->tv_getwork); - if(pool->algorithm.type == ALGO_ETHASH) - { - pool->rpc_req = eth_getwork_rpc; + if(pool->algorithm.type == ALGO_ETHASH) { + pool->rpc_req = eth_getwork_rpc; - val = json_rpc_call(curl, curl_err_str, url, pool->rpc_userpass, + val = json_rpc_call(curl, curl_err_str, url, pool->rpc_userpass, pool->rpc_req, false, false, &work->rolltime, pool, false); - - //ethval2 = json_rpc_call(curl, curl_err_str, pool->rpc_url, pool->rpc_userpass, - // eth_gethighestblock_rpc, false, false, &work->rolltime, pool, false); - } - else - { - val = json_rpc_call(curl, curl_err_str, url, pool->rpc_userpass, pool->rpc_req, false, + else { + val = json_rpc_call(curl, curl_err_str, url, pool->rpc_userpass, pool->rpc_req, false, false, &work->rolltime, pool, false); } - // WARNING: if ethval2 is NULL, it'll slip in here. if (likely(val)) { - rc = (pool->algorithm.type == ALGO_ETHASH) ? work_decode_eth(pool, work, val, ethval2) : work_decode(pool, work, val); + rc = (pool->algorithm.type == ALGO_ETHASH) ? work_decode_eth(pool, work, val) : work_decode(pool, work, val); if (unlikely(!rc)) applog(LOG_DEBUG, "Failed to decode work in get_upstream_work"); } else @@ -6062,11 +6016,11 @@ static void *stratum_sthread(void *userdata) sshare->work = work; applog(LOG_DEBUG, "stratum_sthread() algorithm = %s", pool->algorithm.name); - + char *ASCIINonce = bin2hex((uint8_t*) &work->XMRNonce, 4); ASCIIResult = bin2hex(work->hash, 32); - + mutex_lock(&sshare_lock); /* Give the stratum share a unique id */ sshare->id = swork_id++; @@ -6242,7 +6196,7 @@ static bool pool_active(struct pool *pool, bool pinging) { struct timeval tv_getwork, tv_getwork_reply; bool ret = false; - json_t *val, *ethval2; + json_t *val; CURL *curl; char curl_err_str[CURL_ERROR_SIZE]; int rolltime = 0; @@ -6341,36 +6295,30 @@ static bool pool_active(struct pool *pool, bool pinging) cgtime(&tv_getwork); - if(pool->algorithm.type == ALGO_ETHASH) - { - pool->rpc_req = eth_getwork_rpc; + if(pool->algorithm.type == ALGO_ETHASH) { + pool->rpc_req = eth_getwork_rpc; - val = json_rpc_call(curl, curl_err_str, pool->rpc_url, pool->rpc_userpass, + val = json_rpc_call(curl, curl_err_str, pool->rpc_url, pool->rpc_userpass, pool->rpc_req, true, false, &rolltime, pool, false); - cgtime(&tv_getwork_reply); - - //ethval2 = json_rpc_call(curl, curl_err_str, pool->rpc_url, pool->rpc_userpass, - // eth_gethighestblock_rpc, true, false, &rolltime, pool, false); - + cgtime(&tv_getwork_reply); } - else - { - val = json_rpc_call(curl, curl_err_str, pool->rpc_url, pool->rpc_userpass, - pool->rpc_req, true, false, &rolltime, pool, false); - cgtime(&tv_getwork_reply); - - /* Detect if a http getwork pool has an X-Stratum header at startup, - * and if so, switch to that in preference to getwork if it works */ - if (pool->stratum_url && !opt_fix_protocol && stratum_works(pool)) { - applog(LOG_NOTICE, "Switching %s to %s", get_pool_name(pool), pool->stratum_url); - if (!pool->rpc_url) - pool->rpc_url = strdup(pool->stratum_url); - pool->has_stratum = true; - curl_easy_cleanup(curl); + else { + val = json_rpc_call(curl, curl_err_str, pool->rpc_url, pool->rpc_userpass, + pool->rpc_req, true, false, &rolltime, pool, false); + cgtime(&tv_getwork_reply); + + /* Detect if a http getwork pool has an X-Stratum header at startup, + * and if so, switch to that in preference to getwork if it works */ + if (pool->stratum_url && !opt_fix_protocol && stratum_works(pool)) { + applog(LOG_NOTICE, "Switching %s to %s", get_pool_name(pool), pool->stratum_url); + if (!pool->rpc_url) + pool->rpc_url = strdup(pool->stratum_url); + pool->has_stratum = true; + curl_easy_cleanup(curl); - goto retry_stratum; - } + goto retry_stratum; + } } /* json_rpc_call() above succeeded */ @@ -6379,7 +6327,7 @@ static bool pool_active(struct pool *pool, bool pinging) bool rc; if(pool->algorithm.type == ALGO_ETHASH) - rc = work_decode_eth(pool, work, val, ethval2); + rc = work_decode_eth(pool, work, val); else rc = work_decode(pool, work, val); @@ -6676,7 +6624,7 @@ static void gen_stratum_work_cn(struct pool *pool, struct work *work) applog(LOG_DEBUG, "[THR%d] gen_stratum_work_cn() - algorithm = %s", work->thr_id, pool->algorithm.name); - cg_rlock(&pool->data_lock); + cg_rlock(&pool->data_lock); work->job_id = strdup(pool->swork.job_id); work->XMRTarget = pool->XMRTarget; //strcpy(work->XMRID, pool->XMRID); diff --git a/util.c b/util.c index 33a76356..45382396 100644 --- a/util.c +++ b/util.c @@ -2003,7 +2003,7 @@ bool parse_notify_cn(struct pool *pool, json_t *val) ret = false; goto out; } - + if (!hex2bin(XMRBlob, blobval, strlen(blobval) / 2)) { ret = false; goto out;