2010-11-25 10:03:59 +01:00
|
|
|
|
2010-11-24 05:43:45 +01:00
|
|
|
/*
|
2010-11-25 01:50:46 +01:00
|
|
|
* Copyright 2010 Jeff Garzik
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 2 of the License, or (at your option)
|
|
|
|
* any later version. See COPYING for more details.
|
2010-11-24 05:43:45 +01:00
|
|
|
*/
|
2010-11-24 05:33:20 +01:00
|
|
|
|
2010-11-25 01:31:12 +01:00
|
|
|
#include "cpuminer-config.h"
|
|
|
|
|
2010-11-24 05:33:20 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <unistd.h>
|
2010-11-24 09:36:53 +01:00
|
|
|
#include <sys/time.h>
|
2010-11-26 22:28:12 +01:00
|
|
|
#ifndef WIN32
|
2010-11-24 09:36:53 +01:00
|
|
|
#include <sys/resource.h>
|
2010-11-26 22:28:12 +01:00
|
|
|
#endif
|
2010-11-24 09:36:53 +01:00
|
|
|
#include <pthread.h>
|
2010-11-26 21:46:11 +01:00
|
|
|
#include <getopt.h>
|
2010-11-24 05:33:20 +01:00
|
|
|
#include <jansson.h>
|
2010-11-26 21:50:36 +01:00
|
|
|
#include "compat.h"
|
2010-11-25 10:03:59 +01:00
|
|
|
#include "miner.h"
|
2010-11-24 05:33:20 +01:00
|
|
|
|
2010-11-25 07:02:53 +01:00
|
|
|
#define PROGRAM_NAME "minerd"
|
|
|
|
#define DEF_RPC_URL "http://127.0.0.1:8332/"
|
|
|
|
#define DEF_RPC_USERPASS "rpcuser:rpcpass"
|
2010-11-24 09:36:53 +01:00
|
|
|
|
2010-11-24 05:33:20 +01:00
|
|
|
#include "sha256_generic.c"
|
|
|
|
|
2010-11-24 07:19:47 +01:00
|
|
|
enum {
|
2010-11-27 05:12:24 +01:00
|
|
|
STAT_SLEEP_INTERVAL = 100,
|
2010-11-24 11:55:56 +01:00
|
|
|
STAT_CTR_INTERVAL = 10000000,
|
2010-11-24 07:19:47 +01:00
|
|
|
};
|
|
|
|
|
2010-11-27 01:04:48 +01:00
|
|
|
enum sha256_algos {
|
|
|
|
ALGO_C,
|
|
|
|
ALGO_4WAY
|
|
|
|
};
|
|
|
|
|
2010-11-24 09:36:53 +01:00
|
|
|
static bool opt_debug;
|
2010-11-25 10:03:59 +01:00
|
|
|
bool opt_protocol = false;
|
2010-11-24 09:36:53 +01:00
|
|
|
static bool program_running = true;
|
2010-11-24 08:11:59 +01:00
|
|
|
static const bool opt_time = true;
|
2010-11-27 01:04:48 +01:00
|
|
|
static enum sha256_algos opt_algo = ALGO_C;
|
2010-11-24 09:36:53 +01:00
|
|
|
static int opt_n_threads = 1;
|
2010-11-25 07:02:53 +01:00
|
|
|
static char *rpc_url = DEF_RPC_URL;
|
|
|
|
static char *userpass = DEF_RPC_USERPASS;
|
2010-11-25 06:49:39 +01:00
|
|
|
|
2010-11-24 09:36:53 +01:00
|
|
|
|
2010-11-26 21:46:11 +01:00
|
|
|
struct option_help {
|
|
|
|
const char *name;
|
|
|
|
const char *helptext;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct option_help options_help[] = {
|
|
|
|
{ "help",
|
|
|
|
"(-h) Display this help text" },
|
2010-11-25 06:49:39 +01:00
|
|
|
|
2010-11-27 02:15:07 +01:00
|
|
|
{ "algo XXX",
|
2010-11-27 01:12:22 +01:00
|
|
|
"(-a XXX) Specify sha256 implementation:\n"
|
2010-11-27 02:15:07 +01:00
|
|
|
"\tc\t\tLinux kernel sha256, implemented in C (default)"
|
2010-11-27 01:04:48 +01:00
|
|
|
#ifdef __SSE__
|
|
|
|
"\n\t4way\t\ttcatm's 4-way SSE2 implementation"
|
|
|
|
#endif
|
|
|
|
},
|
|
|
|
|
2010-11-26 21:46:11 +01:00
|
|
|
{ "debug",
|
2010-11-27 02:15:07 +01:00
|
|
|
"(-D) Enable debug output (default: off)" },
|
2010-11-25 06:49:39 +01:00
|
|
|
|
2010-11-26 21:46:11 +01:00
|
|
|
{ "protocol-dump",
|
2010-11-27 02:15:07 +01:00
|
|
|
"(-P) Verbose dump of protocol-level activities (default: off)" },
|
2010-11-25 06:49:39 +01:00
|
|
|
|
2010-11-27 02:15:07 +01:00
|
|
|
{ "threads N",
|
2010-11-26 21:46:11 +01:00
|
|
|
"(-t N) Number of miner threads (default: 1)" },
|
|
|
|
|
2010-11-27 02:15:07 +01:00
|
|
|
{ "url URL",
|
2010-11-25 06:49:39 +01:00
|
|
|
"URL for bitcoin JSON-RPC server "
|
2010-11-25 07:02:53 +01:00
|
|
|
"(default: " DEF_RPC_URL ")" },
|
2010-11-25 06:49:39 +01:00
|
|
|
|
2010-11-27 02:15:07 +01:00
|
|
|
{ "userpass USERNAME:PASSWORD",
|
2010-11-25 06:49:39 +01:00
|
|
|
"Username:Password pair for bitcoin JSON-RPC server "
|
2010-11-25 07:02:53 +01:00
|
|
|
"(default: " DEF_RPC_USERPASS ")" },
|
2010-11-24 09:36:53 +01:00
|
|
|
};
|
|
|
|
|
2010-11-26 21:46:11 +01:00
|
|
|
static struct option options[] = {
|
|
|
|
{ "help", 0, NULL, 'h' },
|
2010-11-27 01:04:48 +01:00
|
|
|
{ "algo", 1, NULL, 'a' },
|
2010-11-26 21:46:11 +01:00
|
|
|
{ "debug", 0, NULL, 'D' },
|
|
|
|
{ "protocol-dump", 0, NULL, 'P' },
|
|
|
|
{ "threads", 1, NULL, 't' },
|
|
|
|
{ "url", 1, NULL, 1001 },
|
|
|
|
{ "userpass", 1, NULL, 1002 },
|
|
|
|
{ }
|
|
|
|
};
|
2010-11-24 05:33:20 +01:00
|
|
|
|
|
|
|
struct work {
|
|
|
|
unsigned char data[128];
|
|
|
|
unsigned char hash1[64];
|
2010-11-25 07:16:34 +01:00
|
|
|
unsigned char midstate[32];
|
2010-11-25 07:02:53 +01:00
|
|
|
unsigned char target[32];
|
2010-11-25 07:16:34 +01:00
|
|
|
|
|
|
|
unsigned char hash[32];
|
2010-11-24 05:33:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool jobj_binary(const json_t *obj, const char *key,
|
|
|
|
void *buf, size_t buflen)
|
|
|
|
{
|
|
|
|
const char *hexstr;
|
|
|
|
json_t *tmp;
|
|
|
|
|
|
|
|
tmp = json_object_get(obj, key);
|
|
|
|
if (!tmp) {
|
|
|
|
fprintf(stderr, "JSON key '%s' not found\n", key);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
hexstr = json_string_value(tmp);
|
|
|
|
if (!hexstr) {
|
|
|
|
fprintf(stderr, "JSON key '%s' is not a string\n", key);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!hex2bin(buf, hexstr, buflen))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-11-25 07:16:34 +01:00
|
|
|
static bool work_decode(const json_t *val, struct work *work)
|
2010-11-24 05:33:20 +01:00
|
|
|
{
|
|
|
|
if (!jobj_binary(val, "midstate",
|
|
|
|
work->midstate, sizeof(work->midstate))) {
|
|
|
|
fprintf(stderr, "JSON inval midstate\n");
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!jobj_binary(val, "data", work->data, sizeof(work->data))) {
|
|
|
|
fprintf(stderr, "JSON inval data\n");
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!jobj_binary(val, "hash1", work->hash1, sizeof(work->hash1))) {
|
|
|
|
fprintf(stderr, "JSON inval hash1\n");
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
2010-11-25 07:02:53 +01:00
|
|
|
if (!jobj_binary(val, "target", work->target, sizeof(work->target))) {
|
2010-11-24 05:33:20 +01:00
|
|
|
fprintf(stderr, "JSON inval target\n");
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
|
2010-11-25 07:16:34 +01:00
|
|
|
memset(work->hash, 0, sizeof(work->hash));
|
|
|
|
|
|
|
|
return true;
|
2010-11-24 05:33:20 +01:00
|
|
|
|
|
|
|
err_out:
|
2010-11-25 07:16:34 +01:00
|
|
|
return false;
|
2010-11-24 05:33:20 +01:00
|
|
|
}
|
|
|
|
|
2010-11-25 10:04:30 +01:00
|
|
|
static void submit_work(struct work *work)
|
|
|
|
{
|
2010-11-26 21:20:54 +01:00
|
|
|
char *hexstr = NULL;
|
2010-11-25 10:04:30 +01:00
|
|
|
json_t *val, *res;
|
2010-11-26 21:20:54 +01:00
|
|
|
char s[256];
|
2010-11-25 10:04:30 +01:00
|
|
|
|
|
|
|
printf("PROOF OF WORK FOUND? submitting...\n");
|
|
|
|
|
|
|
|
/* build hex string */
|
|
|
|
hexstr = bin2hex(work->data, sizeof(work->data));
|
|
|
|
if (!hexstr)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* build JSON-RPC request */
|
2010-11-26 21:20:54 +01:00
|
|
|
sprintf(s,
|
|
|
|
"{\"method\": \"getwork\", \"params\": [ \"%s\" ], \"id\":1}\r\n",
|
|
|
|
hexstr);
|
2010-11-25 10:04:30 +01:00
|
|
|
|
|
|
|
if (opt_debug)
|
|
|
|
fprintf(stderr, "DBG: sending RPC call:\n%s", s);
|
|
|
|
|
|
|
|
/* issue JSON-RPC request */
|
|
|
|
val = json_rpc_call(rpc_url, userpass, s);
|
|
|
|
if (!val) {
|
|
|
|
fprintf(stderr, "submit_work json_rpc_call failed\n");
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = json_object_get(val, "result");
|
|
|
|
|
|
|
|
printf("PROOF OF WORK RESULT: %s\n",
|
|
|
|
json_is_true(res) ? "true (yay!!!)" : "false (booooo)");
|
|
|
|
|
|
|
|
json_decref(val);
|
|
|
|
|
|
|
|
out:
|
|
|
|
free(hexstr);
|
|
|
|
}
|
|
|
|
|
2010-11-27 05:12:24 +01:00
|
|
|
static void hashmeter(int thr_id, struct timeval *tv_start,
|
|
|
|
unsigned long hashes_done)
|
2010-11-24 09:36:53 +01:00
|
|
|
{
|
2010-11-27 05:12:24 +01:00
|
|
|
struct timeval tv_end, diff;
|
|
|
|
double khashes, secs;
|
2010-11-24 09:36:53 +01:00
|
|
|
|
2010-11-27 05:12:24 +01:00
|
|
|
gettimeofday(&tv_end, NULL);
|
2010-11-24 09:36:53 +01:00
|
|
|
|
2010-11-27 05:12:24 +01:00
|
|
|
timeval_subtract(&diff, &tv_end, tv_start);
|
|
|
|
|
|
|
|
khashes = hashes_done / 1000.0;
|
|
|
|
secs = (double)diff.tv_sec + ((double)diff.tv_usec / 1000000.0);
|
|
|
|
|
|
|
|
printf("HashMeter(%d): %lu hashes, %.2f khash/sec\n",
|
|
|
|
thr_id, hashes_done,
|
|
|
|
khashes / secs);
|
2010-11-24 09:36:53 +01:00
|
|
|
}
|
|
|
|
|
2010-11-24 05:33:20 +01:00
|
|
|
static void runhash(void *state, void *input, const void *init)
|
|
|
|
{
|
|
|
|
memcpy(state, init, 32);
|
|
|
|
sha256_transform(state, input);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const uint32_t init_state[8] = {
|
|
|
|
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
|
|
|
|
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
|
|
|
};
|
|
|
|
|
2010-11-24 05:54:37 +01:00
|
|
|
/* suspiciously similar to ScanHash* from bitcoin */
|
2010-11-25 07:27:19 +01:00
|
|
|
static bool scanhash(unsigned char *midstate, unsigned char *data,
|
2010-11-27 05:12:24 +01:00
|
|
|
unsigned char *hash1, unsigned char *hash,
|
|
|
|
unsigned long *hashes_done)
|
2010-11-24 05:33:20 +01:00
|
|
|
{
|
2010-11-24 07:19:47 +01:00
|
|
|
uint32_t *hash32 = (uint32_t *) hash;
|
2010-11-24 05:33:20 +01:00
|
|
|
uint32_t *nonce = (uint32_t *)(data + 12);
|
2010-11-25 07:27:19 +01:00
|
|
|
uint32_t n = 0;
|
2010-11-24 11:55:56 +01:00
|
|
|
unsigned long stat_ctr = 0;
|
2010-11-24 05:33:20 +01:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
n++;
|
|
|
|
*nonce = n;
|
|
|
|
|
|
|
|
runhash(hash1, data, midstate);
|
|
|
|
runhash(hash, hash1, init_state);
|
|
|
|
|
2010-11-27 05:12:24 +01:00
|
|
|
stat_ctr++;
|
|
|
|
|
2010-11-24 07:19:47 +01:00
|
|
|
if (hash32[7] == 0) {
|
2010-11-25 00:25:06 +01:00
|
|
|
char *hexstr;
|
|
|
|
|
|
|
|
hexstr = bin2hex(hash, 32);
|
|
|
|
fprintf(stderr,
|
|
|
|
"DBG: found zeroes in hash:\n%s\n",
|
|
|
|
hexstr);
|
|
|
|
free(hexstr);
|
|
|
|
|
2010-11-27 05:12:24 +01:00
|
|
|
*hashes_done = stat_ctr;
|
2010-11-25 07:27:19 +01:00
|
|
|
return true;
|
2010-11-24 05:33:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((n & 0xffffff) == 0) {
|
2010-11-24 09:36:53 +01:00
|
|
|
if (opt_debug)
|
|
|
|
fprintf(stderr, "DBG: end of nonce range\n");
|
2010-11-27 05:12:24 +01:00
|
|
|
*hashes_done = stat_ctr;
|
2010-11-25 07:27:19 +01:00
|
|
|
return false;
|
2010-11-24 05:33:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-27 05:12:24 +01:00
|
|
|
static void *miner_thread(void *thr_id_int)
|
2010-11-24 05:33:20 +01:00
|
|
|
{
|
2010-11-27 05:12:24 +01:00
|
|
|
int thr_id = (unsigned long) thr_id_int;
|
2010-11-24 05:33:20 +01:00
|
|
|
static const char *rpc_req =
|
|
|
|
"{\"method\": \"getwork\", \"params\": [], \"id\":0}\r\n";
|
|
|
|
|
|
|
|
while (1) {
|
2010-11-25 07:16:34 +01:00
|
|
|
struct work work __attribute__((aligned(128)));
|
2010-11-27 05:12:24 +01:00
|
|
|
unsigned long hashes_done;
|
|
|
|
struct timeval tv_start;
|
2010-11-25 07:27:19 +01:00
|
|
|
json_t *val;
|
2010-11-25 07:16:34 +01:00
|
|
|
bool rc;
|
2010-11-24 05:33:20 +01:00
|
|
|
|
2010-11-24 05:54:37 +01:00
|
|
|
/* obtain new work from bitcoin */
|
2010-11-25 10:03:59 +01:00
|
|
|
val = json_rpc_call(rpc_url, userpass, rpc_req);
|
2010-11-24 05:33:20 +01:00
|
|
|
if (!val) {
|
|
|
|
fprintf(stderr, "json_rpc_call failed\n");
|
2010-11-24 09:36:53 +01:00
|
|
|
return NULL;
|
2010-11-24 05:33:20 +01:00
|
|
|
}
|
|
|
|
|
2010-11-24 05:54:37 +01:00
|
|
|
/* decode result into work state struct */
|
2010-11-25 07:16:34 +01:00
|
|
|
rc = work_decode(json_object_get(val, "result"), &work);
|
|
|
|
if (!rc) {
|
2010-11-24 05:33:20 +01:00
|
|
|
fprintf(stderr, "work decode failed\n");
|
2010-11-24 09:36:53 +01:00
|
|
|
return NULL;
|
2010-11-24 05:33:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
json_decref(val);
|
|
|
|
|
2010-11-27 05:12:24 +01:00
|
|
|
hashes_done = 0;
|
|
|
|
gettimeofday(&tv_start, NULL);
|
|
|
|
|
2010-11-24 05:54:37 +01:00
|
|
|
/* scan nonces for a proof-of-work hash */
|
2010-11-27 01:04:48 +01:00
|
|
|
if (opt_algo == ALGO_C)
|
|
|
|
rc = scanhash(work.midstate, work.data + 64,
|
2010-11-27 05:12:24 +01:00
|
|
|
work.hash1, work.hash, &hashes_done);
|
2010-11-27 01:04:48 +01:00
|
|
|
#ifdef __SSE__
|
|
|
|
else {
|
|
|
|
unsigned int rc4 =
|
|
|
|
ScanHash_4WaySSE2(work.midstate, work.data + 64,
|
|
|
|
work.hash1, work.hash,
|
2010-11-27 05:12:24 +01:00
|
|
|
&hashes_done);
|
2010-11-27 01:04:48 +01:00
|
|
|
rc = (rc4 == -1) ? false : true;
|
|
|
|
}
|
|
|
|
#endif
|
2010-11-24 05:33:20 +01:00
|
|
|
|
2010-11-27 05:12:24 +01:00
|
|
|
hashmeter(thr_id, &tv_start, hashes_done);
|
|
|
|
|
2010-11-24 05:54:37 +01:00
|
|
|
/* if nonce found, submit work */
|
2010-11-25 07:27:19 +01:00
|
|
|
if (rc)
|
2010-11-25 07:16:34 +01:00
|
|
|
submit_work(&work);
|
2010-11-24 05:33:20 +01:00
|
|
|
}
|
|
|
|
|
2010-11-24 09:36:53 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-11-26 21:46:11 +01:00
|
|
|
static void show_usage(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2010-11-27 02:15:07 +01:00
|
|
|
printf("Usage:\tminerd [options]\n\nSupported options:\n");
|
2010-11-26 21:46:11 +01:00
|
|
|
for (i = 0; i < ARRAY_SIZE(options_help); i++) {
|
|
|
|
struct option_help *h;
|
|
|
|
|
|
|
|
h = &options_help[i];
|
|
|
|
printf("--%s\n%s\n\n", h->name, h->helptext);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void parse_arg (int key, char *arg)
|
2010-11-24 09:36:53 +01:00
|
|
|
{
|
|
|
|
int v;
|
|
|
|
|
|
|
|
switch(key) {
|
2010-11-27 01:04:48 +01:00
|
|
|
case 'a':
|
|
|
|
if (!strcmp(arg, "c"))
|
|
|
|
opt_algo = ALGO_C;
|
|
|
|
#ifdef __SSE__
|
|
|
|
else if (!strcmp(arg, "4way"))
|
|
|
|
opt_algo = ALGO_4WAY;
|
|
|
|
#endif
|
|
|
|
else
|
|
|
|
show_usage();
|
|
|
|
break;
|
2010-11-24 09:36:53 +01:00
|
|
|
case 'D':
|
|
|
|
opt_debug = true;
|
|
|
|
break;
|
2010-11-25 00:25:06 +01:00
|
|
|
case 'P':
|
|
|
|
opt_protocol = true;
|
|
|
|
break;
|
2010-11-24 09:36:53 +01:00
|
|
|
case 't':
|
|
|
|
v = atoi(arg);
|
2010-11-25 06:49:39 +01:00
|
|
|
if (v < 1 || v > 9999) /* sanity check */
|
2010-11-26 21:46:11 +01:00
|
|
|
show_usage();
|
2010-11-24 09:36:53 +01:00
|
|
|
|
|
|
|
opt_n_threads = v;
|
|
|
|
break;
|
2010-11-25 06:49:39 +01:00
|
|
|
case 1001: /* --url */
|
|
|
|
if (strncmp(arg, "http://", 7) &&
|
|
|
|
strncmp(arg, "https://", 8))
|
2010-11-26 21:46:11 +01:00
|
|
|
show_usage();
|
2010-11-25 06:49:39 +01:00
|
|
|
|
|
|
|
rpc_url = arg;
|
|
|
|
break;
|
|
|
|
case 1002: /* --userpass */
|
|
|
|
if (!strchr(arg, ':'))
|
2010-11-26 21:46:11 +01:00
|
|
|
show_usage();
|
2010-11-25 06:49:39 +01:00
|
|
|
|
|
|
|
userpass = arg;
|
|
|
|
break;
|
2010-11-24 09:36:53 +01:00
|
|
|
default:
|
2010-11-26 21:46:11 +01:00
|
|
|
show_usage();
|
2010-11-24 09:36:53 +01:00
|
|
|
}
|
2010-11-26 21:46:11 +01:00
|
|
|
}
|
2010-11-24 09:36:53 +01:00
|
|
|
|
2010-11-26 21:46:11 +01:00
|
|
|
static void parse_cmdline(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int key;
|
|
|
|
|
|
|
|
while (1) {
|
2010-11-27 01:04:48 +01:00
|
|
|
key = getopt_long(argc, argv, "a:DPt:h?", options, NULL);
|
2010-11-26 21:46:11 +01:00
|
|
|
if (key < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
parse_arg(key, optarg);
|
|
|
|
}
|
2010-11-24 05:33:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int main (int argc, char *argv[])
|
|
|
|
{
|
2010-11-24 09:36:53 +01:00
|
|
|
int i;
|
|
|
|
|
2010-11-25 06:36:40 +01:00
|
|
|
/* parse command line */
|
2010-11-26 21:46:11 +01:00
|
|
|
parse_cmdline(argc, argv);
|
2010-11-24 09:36:53 +01:00
|
|
|
|
2010-11-25 06:36:40 +01:00
|
|
|
/* set our priority to the highest (aka "nicest, least intrusive") */
|
2010-11-24 09:36:53 +01:00
|
|
|
if (setpriority(PRIO_PROCESS, 0, 19))
|
|
|
|
perror("setpriority");
|
|
|
|
|
2010-11-25 06:36:40 +01:00
|
|
|
/* start mining threads */
|
2010-11-24 09:36:53 +01:00
|
|
|
for (i = 0; i < opt_n_threads; i++) {
|
|
|
|
pthread_t t;
|
|
|
|
|
2010-11-27 05:12:24 +01:00
|
|
|
if (pthread_create(&t, NULL, miner_thread,
|
|
|
|
(void *)(unsigned long) i)) {
|
2010-11-24 09:36:53 +01:00
|
|
|
fprintf(stderr, "thread %d create failed\n", i);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-11-25 06:36:40 +01:00
|
|
|
sleep(1); /* don't pound RPC server all at once */
|
2010-11-24 09:36:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "%d miner threads started.\n", opt_n_threads);
|
|
|
|
|
2010-11-25 06:36:40 +01:00
|
|
|
/* main loop */
|
2010-11-24 09:36:53 +01:00
|
|
|
while (program_running) {
|
|
|
|
sleep(STAT_SLEEP_INTERVAL);
|
2010-11-27 05:12:24 +01:00
|
|
|
/* do nothing */
|
2010-11-24 09:36:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2010-11-24 05:33:20 +01:00
|
|
|
}
|
|
|
|
|