Fix minor bugs

Change default port to 9332 and remove default credentials
Add share summary output
This commit is contained in:
pooler 2011-12-21 04:19:44 +01:00
parent 3c3cde63f1
commit 963efb9546
2 changed files with 53 additions and 31 deletions

View file

@ -19,7 +19,9 @@
#include <unistd.h> #include <unistd.h>
#include <sys/time.h> #include <sys/time.h>
#include <time.h> #include <time.h>
#ifndef WIN32 #if defined(WIN32) || defined(WIN64)
#include <windows.h>
#else
#include <sys/resource.h> #include <sys/resource.h>
#endif #endif
#include <getopt.h> #include <getopt.h>
@ -29,10 +31,7 @@
#include "miner.h" #include "miner.h"
#define PROGRAM_NAME "minerd" #define PROGRAM_NAME "minerd"
#define DEF_RPC_URL "http://127.0.0.1:8332/" #define DEF_RPC_URL "http://127.0.0.1:9332/"
#define DEF_RPC_USERNAME "rpcuser"
#define DEF_RPC_PASSWORD "rpcpass"
#define DEF_RPC_USERPASS DEF_RPC_USERNAME ":" DEF_RPC_PASSWORD
#ifdef __linux /* Linux specific policy and affinity management */ #ifdef __linux /* Linux specific policy and affinity management */
#include <sched.h> #include <sched.h>
@ -94,7 +93,7 @@ bool want_longpoll = true;
bool have_longpoll = false; bool have_longpoll = false;
bool use_syslog = false; bool use_syslog = false;
static bool opt_quiet = false; static bool opt_quiet = false;
static int opt_retries = 10; static int opt_retries = -1;
static int opt_fail_pause = 30; static int opt_fail_pause = 30;
int opt_timeout = 180; int opt_timeout = 180;
int opt_scantime = 5; int opt_scantime = 5;
@ -111,7 +110,11 @@ static int work_thr_id;
int longpoll_thr_id; int longpoll_thr_id;
struct work_restart *work_restart = NULL; struct work_restart *work_restart = NULL;
pthread_mutex_t time_lock; pthread_mutex_t time_lock;
pthread_mutex_t stats_lock;
static unsigned long accepted_count = 0L;
static unsigned long rejected_count = 0L;
double *thr_hashrates;
struct option_help { struct option_help {
const char *name; const char *name;
@ -142,11 +145,11 @@ static struct option_help options_help[] = {
"(-P) Verbose dump of protocol-level activities (default: off)" }, "(-P) Verbose dump of protocol-level activities (default: off)" },
{ "retries N", { "retries N",
"(-r N) Number of times to retry, if JSON-RPC call fails\n" "(-r N) Number of times to retry if JSON-RPC call fails\n"
"\t(default: 10; use -1 for \"never\")" }, "\t(default: retry indefinitely)" },
{ "retry-pause N", { "retry-pause N",
"(-R N) Number of seconds to pause, between retries\n" "(-R N) Number of seconds to pause between retries\n"
"\t(default: 30)" }, "\t(default: 30)" },
{ "scantime N", { "scantime N",
@ -162,23 +165,20 @@ static struct option_help options_help[] = {
#endif #endif
{ "threads N", { "threads N",
"(-t N) Number of miner threads (default: 1)" }, "(-t N) Number of miner threads (default: number of processors)" },
{ "url URL", { "url URL",
"URL for bitcoin JSON-RPC server " "URL for JSON-RPC server "
"(default: " DEF_RPC_URL ")" }, "(default: " DEF_RPC_URL ")" },
{ "userpass USERNAME:PASSWORD", { "userpass USERNAME:PASSWORD",
"Username:Password pair for bitcoin JSON-RPC server " "Username:Password pair for JSON-RPC server" },
"(default: " DEF_RPC_USERPASS ")" },
{ "user USERNAME", { "user USERNAME",
"(-u USERNAME) Username for bitcoin JSON-RPC server " "(-u USERNAME) Username for JSON-RPC server" },
"(default: " DEF_RPC_USERNAME ")" },
{ "pass PASSWORD", { "pass PASSWORD",
"(-p PASSWORD) Password for bitcoin JSON-RPC server " "(-p PASSWORD) Password for JSON-RPC server" },
"(default: " DEF_RPC_PASSWORD ")" },
}; };
static struct option options[] = { static struct option options[] = {
@ -272,6 +272,8 @@ static bool submit_upstream_work(CURL *curl, const struct work *work)
char *hexstr = NULL; char *hexstr = NULL;
json_t *val, *res; json_t *val, *res;
char s[345]; char s[345];
double hashrate;
int i;
bool rc = false; bool rc = false;
/* build hex string */ /* build hex string */
@ -298,8 +300,20 @@ static bool submit_upstream_work(CURL *curl, const struct work *work)
res = json_object_get(val, "result"); res = json_object_get(val, "result");
applog(LOG_INFO, "PROOF OF WORK RESULT: %s", pthread_mutex_lock(&stats_lock);
json_is_true(res) ? "true (yay!!!)" : "false (booooo)"); json_is_true(res) ? accepted_count++ : rejected_count++;
pthread_mutex_unlock(&stats_lock);
hashrate = 0.;
for (i = 0; i < opt_n_threads; i++)
hashrate += thr_hashrates[i];
applog(LOG_INFO, "accepted: %lu/%lu (%.2f%%), %.2f khash/s %s",
accepted_count,
accepted_count + rejected_count,
100. * accepted_count / (accepted_count + rejected_count),
hashrate,
json_is_true(res) ? "(yay!!!)" : "(booooo)");
json_decref(val); json_decref(val);
@ -450,6 +464,8 @@ static void hashmeter(int thr_id, const struct timeval *diff,
khashes = hashes_done / 1000.0; khashes = hashes_done / 1000.0;
secs = (double)diff->tv_sec + ((double)diff->tv_usec / 1000000.0); secs = (double)diff->tv_sec + ((double)diff->tv_usec / 1000000.0);
thr_hashrates[thr_id] = khashes / secs;
if (!opt_quiet) if (!opt_quiet)
applog(LOG_INFO, "thread %d: %lu hashes, %.2f khash/s", applog(LOG_INFO, "thread %d: %lu hashes, %.2f khash/s",
thr_id, hashes_done, thr_id, hashes_done,
@ -793,14 +809,15 @@ static void parse_arg (int key, char *arg)
show_usage(); show_usage();
} }
#ifdef WIN32 #if defined(WIN32) || defined(WIN64)
if (!opt_n_threads) SYSTEM_INFO sysinfo;
opt_n_threads = 1; GetSystemInfo(&sysinfo);
num_processors = sysinfo.dwNumberOfProcessors;
#else #else
num_processors = sysconf(_SC_NPROCESSORS_ONLN); num_processors = sysconf(_SC_NPROCESSORS_ONLN);
#endif
if (!opt_n_threads) if (!opt_n_threads)
opt_n_threads = num_processors; opt_n_threads = num_processors;
#endif /* !WIN32 */
} }
static void parse_config(void) static void parse_config(void)
@ -850,7 +867,7 @@ static void parse_cmdline(int argc, char *argv[])
parse_config(); parse_config();
} }
int main (int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct thr_info *thr; struct thr_info *thr;
int i; int i;
@ -860,6 +877,9 @@ int main (int argc, char *argv[])
/* parse command line */ /* parse command line */
parse_cmdline(argc, argv); parse_cmdline(argc, argv);
pthread_mutex_init(&time_lock, NULL);
pthread_mutex_init(&stats_lock, NULL);
if (!rpc_userpass) { if (!rpc_userpass) {
if (!rpc_user || !rpc_pass) { if (!rpc_user || !rpc_pass) {
applog(LOG_ERR, "No login credentials supplied"); applog(LOG_ERR, "No login credentials supplied");
@ -871,8 +891,6 @@ int main (int argc, char *argv[])
sprintf(rpc_userpass, "%s:%s", rpc_user, rpc_pass); sprintf(rpc_userpass, "%s:%s", rpc_user, rpc_pass);
} }
pthread_mutex_init(&time_lock, NULL);
#ifdef HAVE_SYSLOG_H #ifdef HAVE_SYSLOG_H
if (use_syslog) if (use_syslog)
openlog("cpuminer", LOG_PID, LOG_USER); openlog("cpuminer", LOG_PID, LOG_USER);
@ -917,6 +935,8 @@ int main (int argc, char *argv[])
} else } else
longpoll_thr_id = -1; longpoll_thr_id = -1;
thr_hashrates = (double *) calloc(opt_n_threads, sizeof(double));
/* start mining threads */ /* start mining threads */
for (i = 0; i < opt_n_threads; i++) { for (i = 0; i < opt_n_threads; i++) {
thr = &thr_info[i]; thr = &thr_info[i];

8
util.c
View file

@ -16,9 +16,11 @@
#include <ctype.h> #include <ctype.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <unistd.h>
#include <jansson.h> #include <jansson.h>
#include <curl/curl.h> #include <curl/curl.h>
#include <time.h> #include <time.h>
#include "compat.h"
#include "miner.h" #include "miner.h"
#include "elist.h" #include "elist.h"
@ -72,13 +74,13 @@ void applog(int prio, const char *fmt, ...)
else { else {
char *f; char *f;
int len; int len;
struct timeval tv = { }; time_t now;
struct tm tm, *tm_p; struct tm tm, *tm_p;
gettimeofday(&tv, NULL); time(&now);
pthread_mutex_lock(&time_lock); pthread_mutex_lock(&time_lock);
tm_p = localtime(&tv.tv_sec); tm_p = localtime(&now);
memcpy(&tm, tm_p, sizeof(tm)); memcpy(&tm, tm_p, sizeof(tm));
pthread_mutex_unlock(&time_lock); pthread_mutex_unlock(&time_lock);