Created
December 22, 2018 16:46
-
-
Save monkins1010/5275101a593187d02606607ea8829cc7 to your computer and use it in GitHub Desktop.
miner start
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern "C" int scanhash_verus(int thr_id, struct work *work, uint32_t max_nonce, unsigned long *hashes_done) | |
{ | |
uint32_t _ALIGN(64) endiandata[35]; | |
const char *pdata = (const char*)work->data; | |
uint32_t *ptarget = work->target; | |
int dev_id = device_map[thr_id]; | |
unsigned char block_41970[] = { 0xfd, 0x40, 0x05, 0x01 }; | |
uint8_t _ALIGN(64) full_data[140 + 3 + 1344] = { 0 }; | |
uint8_t* sol_data = &full_data[140]; | |
memcpy(sol_data, block_41970, 4); | |
memcpy(full_data, pdata, 140); | |
uint32_t nonce_buf = 0; | |
uint32_t intensity = 28; | |
throughput = cuda_default_throughput(thr_id, 1U << intensity); | |
if (init[thr_id]) throughput = min(throughput, max_nonce - nonce_buf); | |
if (!init[thr_id]) | |
{ | |
cudaSetDevice(dev_id); | |
if (opt_cudaschedule == -1 && gpu_threads == 1) { | |
cudaDeviceReset(); | |
// reduce cpu usage | |
cudaSetDeviceFlags(cudaDeviceScheduleBlockingSync); | |
CUDA_LOG_ERROR(); | |
} | |
cuda_get_arch(thr_id); | |
gpulog(LOG_INFO, thr_id, "Intensity set to %g, %u cuda threads", throughput2intensity(throughput), throughput); | |
load_constants_port(); | |
CVerusHash::init(); | |
CVerusHashV2::init(); | |
verus_init(thr_id); | |
init[thr_id] = true; | |
} | |
alignas(32) uint256 curHash, curTarget = ArithToUint256(*(uint256*)work->target); | |
const uint64_t *compResult = (uint64_t *)&curHash; | |
const uint64_t *compTarget = (uint64_t *)&curTarget; | |
CVerusHashV2bWriter &vhw = CVerusHashV2bWriter(SER_GETHASH, PROTOCOL_VERSION); | |
CVerusHashV2 &vh = vhw.GetState(); | |
vh.Hash((void*)compResult, full_data,1487); | |
verusclhasher &vclh = vh.vclh; | |
u128 *hashKey = (u128 *)verusclhasher_key.get(); | |
verusclhash_descr *pdesc = (verusclhash_descr *)verusclhasher_descr.get(); | |
void *hasherrefresh = ((unsigned char *)hashKey) + pdesc->keySizeInBytes; | |
const int keyrefreshsize = vclh.keyrefreshsize(); // number of 256 bit blocks | |
//vhw.Reset(); | |
//vhw << work->data; | |
unsigned char *curBuf = vh.CurBuffer(); | |
// skip keygen if it is the current key | |
if (pdesc->seed != *((uint256 *)curBuf)) | |
{ | |
// generate a new key by chain hashing with Haraka256 from the last curbuf | |
// assume 256 bit boundary | |
int n256blks = pdesc->keySizeInBytes >> 5; | |
unsigned char *pkey = ((unsigned char *)hashKey); | |
unsigned char *psrc = curBuf; | |
for (int i = 0; i < n256blks; i++) | |
{ | |
haraka256(pkey, psrc); | |
psrc = pkey; | |
pkey += 32; | |
} | |
pdesc->seed = *((uint256 *)curBuf); | |
memcpy(hasherrefresh, hashKey, pdesc->keySizeInBytes); | |
} | |
//VerusHashHalf(blockhash_half, full_data, 1487); // full VerusHash without last iteration | |
work->valid_nonces = 0; | |
verus_setBlock((uint8_t*)curBuf, work->target, (uint8_t*)hashKey); //set data to gpu kernel | |
do { | |
*hashes_done = nonce_buf + throughput; | |
//*hashes_done = mainnonce; | |
//printf("firstnoncef= %08x, maxnonce = %08x,throughput = %08x\n",first_nonce,max_nonce, throughput); | |
verus_hash(thr_id, throughput, nonce_buf, work->nonces); | |
if (work->nonces[0] != UINT32_MAX) | |
{ | |
const uint32_t Htarg = ptarget[7]; | |
uint32_t _ALIGN(64) vhash[8]; | |
*((uint32_t *)full_data + 368) = work->nonces[0]; | |
memset(blockhash_half + 32, 0x0, 32); | |
memcpy(blockhash_half + 32, full_data + 1486 - 14, 15); | |
//haraka512_port((unsigned char*)vhash, (unsigned char*)blockhash_half); | |
if (vhash[7] <= Htarg && fulltest(vhash, ptarget)) | |
{ | |
work->valid_nonces++; | |
memcpy(work->data, endiandata, 140); | |
int nonce = work->valid_nonces - 1; | |
memcpy(work->extra, sol_data, 1347); | |
bn_store_hash_target_ratio(vhash, work->target, work, nonce); | |
work->nonces[work->valid_nonces - 1] = endiandata[NONCE_OFT]; | |
pdata[NONCE_OFT] = endiandata[NONCE_OFT] + 1; | |
goto out; | |
} | |
} | |
if ((uint64_t)throughput + (uint64_t)nonce_buf >= (uint64_t)max_nonce) { | |
break; | |
} | |
nonce_buf += throughput; | |
} while (!work_restart[thr_id].restart); | |
out: | |
// H/s | |
//*hashes_done = first_nonce; | |
pdata[NONCE_OFT] = endiandata[NONCE_OFT] + 1; | |
return work->valid_nonces; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment