Browse Source

Make target on stratum scale to any size by clearing sequential bits according to diff.

nfactor-troky
Con Kolivas 12 years ago
parent
commit
fdaabf59c6
  1. 40
      cgminer.c
  2. 15
      miner.h

40
cgminer.c

@ -4477,12 +4477,13 @@ static void gen_hash(unsigned char *data, unsigned char *hash, int len)
static void gen_stratum_work(struct pool *pool, struct work *work) static void gen_stratum_work(struct pool *pool, struct work *work)
{ {
char header[257], hash1[129], *nonce2, *buf;
unsigned char *coinbase, merkle_root[33], merkle_sha[65], *merkle_hash; unsigned char *coinbase, merkle_root[33], merkle_sha[65], *merkle_hash;
int len, cb1_len, n1_len, cb2_len, i, j;
unsigned char rtarget[33], target[33];
char header[257], hash1[129], *nonce2;
uint32_t *data32, *swap32; uint32_t *data32, *swap32;
uint64_t diff, diff64; uint8_t *data8;
char target[65]; int diff;
int len, cb1_len, n1_len, cb2_len, i;
mutex_lock(&pool->pool_lock); mutex_lock(&pool->pool_lock);
@ -4551,18 +4552,25 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
if (unlikely(!hex2bin(work->hash1, hash1, 64))) if (unlikely(!hex2bin(work->hash1, hash1, 64)))
quit(1, "Failed to convert hash1 in gen_stratum_work"); quit(1, "Failed to convert hash1 in gen_stratum_work");
/* Generate target as hex where 0x00000000FFFFFFFF is diff 1 */ /* Scale to any diff by setting number of bits according to diff */
diff64 = (1Ull << (31 + diff)) - 1; hex2bin(rtarget, "00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 32);
diff64 = ~htobe64(diff64); data8 = (uint8_t *)(rtarget + 4);
sprintf(target, "ffffffffffffffffffffffffffffffffffffffffffffffff"); for (i = 1, j = 0; i < diff; i++, j++) {
buf = bin2hex((const unsigned char *)&diff64, 8); int byte = j / 8;
if (unlikely(!buf)) int bit = j % 8;
quit(1, "Failed to convert diff64 to buf in gen_stratum_work");
strcat(target, buf); data8[byte] &= ~(8 >> bit);
free(buf); }
applog(LOG_DEBUG, "Generated target %s", target); swab256(target, rtarget);
if (unlikely(!hex2bin(work->target, target, 32))) if (opt_debug) {
quit(1, "Failed to convert target to bin in gen_stratum_work"); char *htarget = bin2hex(target, 32);
if (likely(htarget)) {
applog(LOG_DEBUG, "Generated target %s", htarget);
free(htarget);
}
}
memcpy(work->target, target, 256);
work->pool = pool; work->pool = pool;
work->stratum = true; work->stratum = true;

15
miner.h

@ -511,6 +511,21 @@ static inline void swap256(void *dest_p, const void *src_p)
dest[7] = src[0]; dest[7] = src[0];
} }
static inline void swab256(void *dest_p, const void *src_p)
{
uint32_t *dest = dest_p;
const uint32_t *src = src_p;
dest[0] = swab32(src[7]);
dest[1] = swab32(src[6]);
dest[2] = swab32(src[5]);
dest[3] = swab32(src[4]);
dest[4] = swab32(src[3]);
dest[5] = swab32(src[2]);
dest[6] = swab32(src[1]);
dest[7] = swab32(src[0]);
}
extern void quit(int status, const char *format, ...); extern void quit(int status, const char *format, ...);
static inline void mutex_lock(pthread_mutex_t *lock) static inline void mutex_lock(pthread_mutex_t *lock)

Loading…
Cancel
Save