Add timing info. Remove BIGNUM PoW checks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
diff --git a/cpu-miner.c b/cpu-miner.c
index d785101..9b6e9f7 100644
--- a/cpu-miner.c
+++ b/cpu-miner.c
@@ -10,6 +10,7 @@
#include <string.h>
#include <stdbool.h>
#include <unistd.h>
+#include <time.h>
#include <jansson.h>
#include <curl/curl.h>
#include <openssl/bn.h>
@@ -22,6 +23,7 @@ enum {
static const bool opt_verbose = false;
static const bool opt_debug = false;
+static const bool opt_time = true;
struct data_buffer {
void *buf;
@@ -316,6 +318,9 @@ static uint32_t scanhash(unsigned char *midstate, unsigned char *data,
uint32_t *hash32 = (uint32_t *) hash;
uint32_t *nonce = (uint32_t *)(data + 12);
uint32_t n;
+ time_t t_start;
+
+ t_start = time(NULL);
while (1) {
n = *nonce;
@@ -339,8 +344,15 @@ static uint32_t scanhash(unsigned char *midstate, unsigned char *data,
}
if ((n & 0xffffff) == 0) {
- if (1)
- fprintf(stderr, "DBG: end of nonce range\n");
+ time_t t_end = time(NULL);
+ time_t diff = t_end - t_start;
+ long double nd = n;
+ long double sd = diff;
+ if (opt_time) {
+ fprintf(stderr,
+ "DBG: end of nonce range, %.2Lf khps\n",
+ (nd / sd) / 1000.0);
+ }
return 0;
}
}
@@ -349,54 +361,25 @@ static uint32_t scanhash(unsigned char *midstate, unsigned char *data,
static const char *url = "http://127.0.0.1:8332/";
static const char *userpass = "pretzel:smooth";
-static void submit_work(struct work *work)
+static void submit_work(struct work *work, bool byte_rev)
{
char *hexstr = NULL, *s = NULL;
json_t *val, *res;
int i;
- unsigned char hash_rev[32];
- BIGNUM *hashnum;
- char *s_hash, *s_target;
-
- printf("PROOF OF WORK FOUND? submitting...\n");
-
- for (i = 0; i < 32/4; i++)
- ((uint32_t *)hash_rev)[i] =
- swab32(((uint32_t *)work->hash)[i]);
-
- hashnum = BN_bin2bn(hash_rev, sizeof(hash_rev), NULL);
- if (!hashnum) {
- fprintf(stderr, "BN_bin2bn failed\n");
- return;
+ unsigned char data[128];
+
+ printf("PROOF OF WORK FOUND? submitting (reversed:%s)...\n",
+ byte_rev ? "yes" : "no");
+
+ if (byte_rev) {
+ /* byte reverse data */
+ for (i = 0; i < 128/4; i ++)
+ ((uint32_t *)data)[i] =
+ swab32(((uint32_t *)work->data)[i]);
+ } else {
+ memcpy(data, work->data, sizeof(data));
}
- s_hash = BN_bn2hex(hashnum);
- s_target = BN_bn2hex(work->target);
- fprintf(stderr, " hash:%s\n hashTarget:%s\n",
- s_hash, s_target);
- free(s_hash);
- free(s_target);
-
-#if 0
- i = BN_cmp(hashnum, work->target);
-#endif
-
- BN_free(hashnum);
-
-#if 0
- if (i >= 0) {
- fprintf(stderr, "---INVALID--- proof of work found.\n");
- return;
- }
-#endif
-
-#if 0
- /* byte reverse data */
- for (i = 0; i < 128/4; i ++)
- ((uint32_t *)work->data)[i] =
- swab32(((uint32_t *)work->data)[i]);
-#endif
-
/* build hex string */
hexstr = bin2hex(work->data, sizeof(work->data));
if (!hexstr)
@@ -470,7 +453,8 @@ static int main_loop(void)
/* if nonce found, submit work */
if (nonce) {
- submit_work(work);
+ submit_work(work, false);
+ submit_work(work, true);
fprintf(stderr, "sleeping, after proof-of-work...\n");
sleep(POW_SLEEP_INTERVAL);