mirror of
https://github.com/skot/ESP-Miner.git
synced 2025-05-31 14:29:21 +02:00
stratum: fix extranonce 2 generation when length > 4
This commit is contained in:
parent
a3b0608520
commit
6b5e5b98f7
@ -62,17 +62,17 @@ bm_job construct_bm_job(mining_notify * params, const char * merkle_root) {
|
||||
new_job.ntime = params->ntime;
|
||||
|
||||
hex2bin(merkle_root, new_job.merkle_root, 32);
|
||||
hex2bin(params->prev_block_hash, new_job.prev_block_hash, 32);
|
||||
swap_endian_words(params->prev_block_hash, new_job.prev_block_hash);
|
||||
|
||||
////make the midstate hash
|
||||
uint8_t midstate_data[64];
|
||||
|
||||
//print the header
|
||||
printf("header: %08x%s%s%08x%08x00000000\n", params->version, params->prev_block_hash, merkle_root, params->ntime, params->target);
|
||||
//printf("header: %08x%s%s%08x%08x000000000000008000000000000000000000000000000000000000000000000000000000\n", params->version, params->prev_block_hash, merkle_root, params->ntime, params->target);
|
||||
|
||||
//copy 68 bytes header data into midstate (and deal with endianess)
|
||||
memcpy(midstate_data, &new_job.version, 4); //copy version
|
||||
swap_endian_words(params->prev_block_hash, midstate_data + 4); //copy prev_block_hash
|
||||
memcpy(midstate_data + 4, new_job.prev_block_hash, 32); //copy prev_block_hash
|
||||
memcpy(midstate_data + 36, new_job.merkle_root, 28); //copy merkle_root
|
||||
|
||||
printf("midstate_data: ");
|
||||
@ -88,7 +88,12 @@ bm_job construct_bm_job(mining_notify * params, const char * merkle_root) {
|
||||
char * extranonce_2_generate(uint32_t extranonce_2, uint32_t length)
|
||||
{
|
||||
char * extranonce_2_str = malloc(length * 2 + 1);
|
||||
bin2hex((uint8_t *) &extranonce_2, length, extranonce_2_str, length * 2 + 1);
|
||||
memset(extranonce_2_str, '0', length * 2);
|
||||
extranonce_2_str[length * 2] = '\0';
|
||||
bin2hex((uint8_t *) &extranonce_2, sizeof(extranonce_2), extranonce_2_str, length * 2 + 1);
|
||||
if (length > 4) {
|
||||
extranonce_2_str[8] = '0';
|
||||
}
|
||||
return extranonce_2_str;
|
||||
}
|
||||
|
||||
@ -101,13 +106,10 @@ static const double truediffone = 2695953529101130949315647634472399133601089873
|
||||
double test_nonce_value(bm_job * job, uint32_t nonce) {
|
||||
double d64, s64, ds;
|
||||
unsigned char header[80];
|
||||
uint8_t flipped_prev_block_hash[32];
|
||||
|
||||
flip32bytes(flipped_prev_block_hash, job->prev_block_hash);
|
||||
|
||||
//copy data from job to header
|
||||
memcpy(header, &job->version, 4);
|
||||
memcpy(header + 4, flipped_prev_block_hash, 32);
|
||||
memcpy(header + 4, job->prev_block_hash, 32);
|
||||
memcpy(header + 36, job->merkle_root, 32);
|
||||
memcpy(header + 68, &job->ntime, 4);
|
||||
memcpy(header + 72, &job->target, 4);
|
||||
@ -131,4 +133,4 @@ double test_nonce_value(bm_job * job, uint32_t nonce) {
|
||||
ds = d64 / s64;
|
||||
|
||||
return ds;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user