Display proof-of-work hash when one is discovered

This commit is contained in:
Jeff Garzik 2011-02-02 18:47:04 -05:00 committed by Jeff Garzik
parent 453101d9e9
commit c68ffb30dd
6 changed files with 35 additions and 28 deletions

17
miner.h
View file

@ -27,6 +27,21 @@ static inline uint32_t swab32(uint32_t v)
return __builtin_bswap32(v);
}
static inline void swap256(void *dest_p, const void *src_p)
{
uint32_t *dest = dest_p;
const uint32_t *src = src_p;
dest[0] = src[7];
dest[1] = src[6];
dest[2] = src[5];
dest[3] = src[4];
dest[4] = src[3];
dest[5] = src[2];
dest[6] = src[1];
dest[7] = src[0];
}
extern bool opt_debug;
extern bool opt_protocol;
extern const uint32_t sha256_init_state[];
@ -55,4 +70,6 @@ extern bool scanhash_asm32(const unsigned char *midstate,unsigned char *data,
extern int
timeval_subtract (struct timeval *result, struct timeval *x, struct timeval *y);
extern void print_pow(const unsigned char *hash);
#endif /* __MINER_H__ */

View file

@ -123,6 +123,9 @@ unsigned int ScanHash_4WaySSE2(const unsigned char *pmidstate, unsigned char *pd
for (i = 0; i < 32/4; i++)
((unsigned int*)phash)[i] = thash[i][j];
print_pow(phash);
*nHashesDone = nonce;
*nNonce_p = nonce + j;
return nonce + j;

View file

@ -110,13 +110,7 @@ bool scanhash_cryptopp(const unsigned char *midstate, unsigned char *data,
stat_ctr++;
if (hash32[7] == 0) {
char *hexstr;
hexstr = bin2hex(hash, 32);
fprintf(stderr,
"DBG: found zeroes in hash:\n%s\n",
hexstr);
free(hexstr);
print_pow(hash);
*hashes_done = stat_ctr;
return true;
@ -601,13 +595,7 @@ bool scanhash_asm32(const unsigned char *midstate, unsigned char *data,
stat_ctr++;
if (hash32[7] == 0) {
char *hexstr;
hexstr = bin2hex(hash, 32);
fprintf(stderr,
"DBG: found zeroes in hash:\n%s\n",
hexstr);
free(hexstr);
print_pow(hash);
*hashes_done = stat_ctr;
return true;

View file

@ -256,13 +256,7 @@ bool scanhash_c(const unsigned char *midstate, unsigned char *data,
stat_ctr++;
if (hash32[7] == 0) {
char *hexstr;
hexstr = bin2hex(hash, 32);
fprintf(stderr,
"DBG: found zeroes in hash:\n%s\n",
hexstr);
free(hexstr);
print_pow(hash);
*hashes_done = stat_ctr;
return true;

View file

@ -57,13 +57,7 @@ bool scanhash_via(unsigned char *data_inout,
stat_ctr++;
if (hash32[7] == 0) {
char *hexstr;
hexstr = bin2hex(tmp_hash, 32);
fprintf(stderr,
"DBG: found zeroes in hash:\n%s\n",
hexstr);
free(hexstr);
print_pow(tmp_hash);
/* swap nonce'd data back into original storage area;
* TODO: only swap back the nonce, rather than all data

11
util.c
View file

@ -255,3 +255,14 @@ timeval_subtract (
return x->tv_sec < y->tv_sec;
}
void print_pow(const unsigned char *hash)
{
char *hexstr;
unsigned char hash_swap[32];
swap256(hash_swap, hash);
hexstr = bin2hex(hash_swap, 32);
fprintf(stderr, "PoW found: %s\n", hexstr);
free(hexstr);
}