Skip to content

Commit

Permalink
extranonce is incremented if the miner is running out of nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
djm34 committed Dec 30, 2018
1 parent f162307 commit 8b8e689
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 23 deletions.
2 changes: 1 addition & 1 deletion RUN-ZCOIN-MTP.cmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

rem x64\Release\ccminer -a mtp -o http://127.0.0.1:8382 -u djm34 -p password --coinbase-addr aDn7MMYjVQqenT11VFDYHfFdwXmSTRUTak -d 1070 --no-getwork -i 18
rem x64\Release\ccminer -a mtp -o stratum+tcp://xzc.2miners.com:8080 -u aDn7MMYjVQqenT11VFDYHfFdwXmSTRUTak.worker -p 0 -i 16 -d 0,1 --quiet
x64\Release\ccminer -a mtp -o stratum+tcp://zcoin.mintpond.com:3000 -u aDn7MMYjVQqenT11VFDYHfFdwXmSTRUTak.worker -p 0,verbose,d=768 -d 0,1 -i 20
x64\Release\ccminer -a mtp -o stratum+tcp://zcoin.mintpond.com:3000 -u aDn7MMYjVQqenT11VFDYHfFdwXmSTRUTak.worker -p 0,verbose,d=768 -d 0,1 -i 16 --debug

pause
49 changes: 44 additions & 5 deletions ccminer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2564,6 +2564,18 @@ static bool stratum_gen_work_m7(struct stratum_ctx *sctx, struct work *work)
return true;
}

static bool increment_X2(struct work *work)
{
int i;
pthread_mutex_lock(&stratum_work_lock);
// memcpy(work->xnonce2, sctx->job.xnonce2, sctx->xnonce2_size);
for (i = 0; i < (int)work->xnonce2_len && !++work->xnonce2[i]; i++);

printf("to be transfered %llx \n", ((uint64_t*)work->xnonce2)[0]);
pthread_mutex_unlock(&stratum_work_lock);
return true;
}

static bool stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
{
uchar merkle_root[64] = { 0 };
Expand All @@ -2576,11 +2588,21 @@ static bool stratum_gen_work(struct stratum_ctx *sctx, struct work *work)

pthread_mutex_lock(&stratum_work_lock);


// printf("stratumgen \n");

// store the job ntime as high part of jobid
// free(work->job_id);
// work->job_id = strdup(sctx->job.job_id);
// for (int i=0;i<4;i++)
// work->job_iduc[i] = sctx->job.ucjob_id[i];
/* Increment extranonce2 */
if (sctx->job.IncXtra) {
printf("incrementing nonce\n");
for (i = 0; i < (int)sctx->xnonce2_size && !++sctx->job.xnonce2[i]; i++);
sctx->job.IncXtra = false;
}


snprintf(work->job_id, sizeof(work->job_id), "%07x %s",
be32dec(sctx->job.ntime) & 0xfffffff, sctx->job.job_id);
Expand All @@ -2589,6 +2611,14 @@ static bool stratum_gen_work(struct stratum_ctx *sctx, struct work *work)

// printf("thefull job id %s\n",work->job_id);
// printf("reduced job id %s\n", work->job_id+8);
unsigned char* Transfer = (unsigned char*)malloc(sctx->job.coinbase_size);

if (opt_algo == ALGO_MTP) {
memcpy(Transfer, sctx->job.coinbase, sctx->job.coinbase_size);
memcpy(Transfer + 60, work->xnonce2, 8);
}



// also store the block number
work->height = sctx->job.height;
Expand Down Expand Up @@ -2626,6 +2656,7 @@ static bool stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
}

/* Increment extranonce2 */
//printf("incrementing nonce\n");
// for (i = 0; i < (int)sctx->xnonce2_size && !++sctx->job.xnonce2[i]; i++);

/* Assemble block header */
Expand Down Expand Up @@ -2846,7 +2877,7 @@ static void *miner_thread(void *userdata)
struct work work;
uint64_t loopcnt = 0;
uint32_t max_nonce;
uint32_t end_nonce = UINT32_MAX / opt_n_threads * (thr_id + 1) - (thr_id + 1);
uint32_t end_nonce = UINT32_MAX / opt_n_threads * (thr_id + 1) ;
time_t tm_rate_log = 0;
bool work_done = false;
bool extrajob = false;
Expand Down Expand Up @@ -2969,12 +3000,17 @@ static void *miner_thread(void *userdata)
extrajob |= work_done;

regen = (nonceptr[0] >= end_nonce);



if (opt_algo == ALGO_SIA) {
regen = ((nonceptr[1] & 0xFF00) >= 0xF000);
}
regen = regen || extrajob;

if (regen || opt_algo == ALGO_MTP) {
if (regen) {


work_done = false;
extrajob = false;
if (opt_algo == ALGO_M7) {
Expand Down Expand Up @@ -3295,8 +3331,8 @@ static void *miner_thread(void *userdata)

work.scanned_from = start_nonce;

gpulog(LOG_DEBUG, thr_id, "start=%08x end=%08x range=%08x",
start_nonce, max_nonce, (max_nonce-start_nonce));
// gpulog(LOG_DEBUG, thr_id, "start=%08x end=%08x range=%08x",
// start_nonce, max_nonce, (max_nonce-start_nonce));

if (opt_led_mode == LED_MODE_MINING)
gpu_led_on(dev_id);
Expand Down Expand Up @@ -3382,7 +3418,10 @@ static void *miner_thread(void *userdata)
rc = scanhash_qubit(thr_id, &work, max_nonce, &hashes_done);
break;
case ALGO_MTP:
rc = scanhash_mtp(opt_n_threads,thr_id, &work, max_nonce, &hashes_done, mtp);
rc = scanhash_mtp(opt_n_threads,thr_id, &work, max_nonce, &hashes_done, mtp,&stratum);
// pthread_mutex_lock(&stratum_work_lock);
// stratum.job.IncXtra = true;
// pthread_mutex_unlock(&stratum_work_lock);
break;
case ALGO_LYRA2:
rc = scanhash_lyra2(thr_id, &work, max_nonce, &hashes_done);
Expand Down
6 changes: 3 additions & 3 deletions ccminer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@
<CudaCompile>
<CInterleavedPTX>false</CInterleavedPTX>
<MaxRegCount>80</MaxRegCount>
<PtxAsOptionV>true</PtxAsOptionV>
<PtxAsOptionV>false</PtxAsOptionV>
<Keep>true</Keep>
<CodeGeneration>compute_52,sm_52;compute_61,sm_61;compute_75,sm_75</CodeGeneration>
<CodeGeneration>compute_61,sm_61</CodeGeneration>
<Include>$(NVTOOLSEXT_PATH)\include;..\..\..\Common\C99</Include>
<Optimization>O3</Optimization>
<TargetMachinePlatform>64</TargetMachinePlatform>
<InterleaveSourceInPTX>true</InterleaveSourceInPTX>
<InterleaveSourceInPTX>false</InterleaveSourceInPTX>
<GenerateLineInfo>false</GenerateLineInfo>
</CudaCompile>
<CudaLink>
Expand Down
2 changes: 1 addition & 1 deletion compat/ccminer-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
#define PACKAGE_URL "http://github.com/djm34/ccminer-msvc2015"

/* Define to the version of this package. */
#define PACKAGE_VERSION "1.1.7-djm34"
#define PACKAGE_VERSION "1.1.8-djm34"

/* If using the C implementation of alloca, define if you know the
direction of stack growth for your system; otherwise it will be
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT([ccminer], [1.1.7-djm34], [], [ccminer], [http://github.com/zcoinofficial/ccminer])
AC_INIT([ccminer], [1.1.8-djm34], [], [ccminer], [http://github.com/zcoinofficial/ccminer])

AC_PREREQ([2.59c])
AC_CANONICAL_SYSTEM
Expand Down
19 changes: 10 additions & 9 deletions cuda_mtp/mtp.cu
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void get_tree(int thr_id, uint8_t* d);
static bool init[MAX_GPUS] = { 0 };
static __thread uint32_t throughput = 0;
static uint32_t JobId[MAX_GPUS] = {0};
static uint64_t XtraNonce2[MAX_GPUS] = {0};
static bool fillGpu[MAX_GPUS] = {false};
static MerkleTree::Elements TheElements;
static MerkleTree ordered_tree[MAX_GPUS];
Expand All @@ -38,7 +39,7 @@ static argon2_instance_t instance[MAX_GPUS];

static std::vector<uint8_t*> MEM[MAX_GPUS];

extern "C" int scanhash_mtp(int nthreads,int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done, struct mtp* mtp)
extern "C" int scanhash_mtp(int nthreads,int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done, struct mtp* mtp, struct stratum_ctx *sctx)
{

unsigned char mtpHashValue[32];
Expand Down Expand Up @@ -146,9 +147,9 @@ printf("memory filled \n");
pthread_mutex_unlock(&work_lock);
*/

if (JobId[thr_id] != work->data[17]) {

gpulog(LOG_WARNING, thr_id, "filling memory");
if (JobId[thr_id] != work->data[17] || XtraNonce2[thr_id] != ((uint64_t*)work->xnonce2)[0]) {
// printf("thr_id %d xnonce2 %llx\n",thr_id, ((uint64_t*)work->xnonce2)[0]);
// gpulog(LOG_WARNING, thr_id, "filling memory");
//restart_threads();
//pthread_barrier_wait(&barrier);
if (JobId[thr_id] != 0)
Expand Down Expand Up @@ -188,7 +189,7 @@ if (JobId[thr_id] != work->data[17]) {

//for(;;);
JobId[thr_id] = work->data[17];

XtraNonce2[thr_id] = ((uint64_t*)work->xnonce2)[0];
MerkleTree::Buffer root = ordered_tree[thr_id].getRoot();
//for(;;);
std::copy(root.begin(), root.end(), TheMerkleRoot[thr_id]);
Expand All @@ -197,7 +198,7 @@ if (JobId[thr_id] != work->data[17]) {
// mtp_setBlockTarget(0,endiandata,ptarget,&TheMerkleRoot);
mtp_setBlockTarget(thr_id, endiandata, ptarget, &TheMerkleRoot[thr_id]);

gpulog(LOG_WARNING, thr_id, "memory filled %d chunks", MEM[thr_id].size());
// gpulog(LOG_WARNING, thr_id, "memory filled %d chunks", MEM[thr_id].size());
}


Expand Down Expand Up @@ -284,13 +285,13 @@ fillGpu[thr_id]=false;
*/
pdata[19] += throughput;
if (pdata[19] >= real_maxnonce) {
gpulog(LOG_WARNING, thr_id, "OUT OF NONCE %x >= %x", pdata[19], real_maxnonce);
abort();
gpulog(LOG_WARNING, thr_id, "OUT OF NONCE %x >= %x incrementing extra nonce at next chance", pdata[19], real_maxnonce);
sctx->job.IncXtra = true;
}
// } while (!work_restart[thr_id].restart && pdata[19]<real_maxnonce && JobId==work->data[17] /*&& pdata[19]<(first_nonce+128*throughput)*/);

TheEnd:

// sctx->job.IncXtra = true;
*hashes_done = pdata[19] - first_nonce;


Expand Down
3 changes: 2 additions & 1 deletion miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ void sha256d(unsigned char *hash, const unsigned char *data, int len);
#define HAVE_SHA256_8WAY 0

struct work;
extern int scanhash_mtp(int nthreads, int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done, struct mtp* mtp);
extern int scanhash_mtp(int nthreads, int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done, struct mtp* mtp, struct stratum_ctx *sctx);
extern int scanhash_blake256(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done, int8_t blakerounds);
extern int scanhash_blake2s(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done);
extern int scanhash_bmw(int thr_id, struct work* work, uint32_t max_nonce, unsigned long *hashes_done);
Expand Down Expand Up @@ -636,6 +636,7 @@ struct stratum_job {
unsigned char ntime[4];
unsigned char claim[32]; // lbry
bool clean;
bool IncXtra;
unsigned char nreward[2];
uint32_t height;
double diff;
Expand Down
11 changes: 9 additions & 2 deletions util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2489,8 +2489,15 @@ static bool stratum_notify_bos(struct stratum_ctx *sctx, json_t *params)
sctx->job.xnonce2 = sctx->job.coinbase + coinb1_size + sctx->xnonce1_size;
memcpy(sctx->job.coinbase, coinb1, coinb1_size);
memcpy(sctx->job.coinbase + coinb1_size, sctx->xnonce1, sctx->xnonce1_size);
if (!sctx->job.job_id /*|| sctx->job.job_id!=job_id*/)

//
char* JobID = (char*)malloc(2 * job_idsize + 1);
JobID = abin2hex(job_id, job_idsize);

if (!sctx->job.job_id || strcmp(sctx->job.job_id,JobID) ){
memset(sctx->job.xnonce2, 0, sctx->xnonce2_size);
sctx->job.IncXtra = false;
}
// memset(sctx->job.xnonce2, 1, 1);
memcpy(sctx->job.xnonce2 + sctx->xnonce2_size, coinb2, coinb2_size);

Expand All @@ -2500,7 +2507,7 @@ static bool stratum_notify_bos(struct stratum_ctx *sctx, json_t *params)
// sctx->job.job_id = job_id;
sctx->job.job_id = (char*)malloc(2 * job_idsize + 1);
sctx->job.job_id = abin2hex(job_id, job_idsize);

free(JobID);
memcpy(sctx->job.prevhash, prevhash, 32);

/*
Expand Down

0 comments on commit 8b8e689

Please sign in to comment.