diff --git a/stratum/Makefile b/stratum/Makefile index 8bf6a9f..3bf978b 100755 --- a/stratum/Makefile +++ b/stratum/Makefile @@ -8,12 +8,6 @@ SQLFLAGS= `mysql_config --cflags --libs` # if you use the auto exchange feature... CFLAGS += -DNO_EXCHANGE -#CFLAGS += -DHASH_DEBUGLOG_ -#CFLAGS += -DRPC_DEBUGLOG_ -#CFLAGS += -DREMOTE_DEBUGLOG_ -#CFLAGS += -DSOCKET_DEBUGLOG_ -#CFLAGS += -DCLIENT_DEBUGLOG_ - #CFLAGS=-c -O2 -I /usr/include/mysql LDFLAGS=-O2 `mysql_config --libs` diff --git a/stratum/client.cpp b/stratum/client.cpp index f51f9d0..844d23d 100644 --- a/stratum/client.cpp +++ b/stratum/client.cpp @@ -1,8 +1,6 @@ #include "stratum.h" -//#define CLIENT_DEBUGLOG_ - bool client_suggest_difficulty(YAAMP_CLIENT *client, json_value *json_params) { if(json_params->u.array.length>0) @@ -88,9 +86,9 @@ bool client_subscribe(YAAMP_CLIENT *client, json_value *json_params) memcpy(client->job_history, client1->job_history, sizeof(client->job_history)); client1->lock_count = 0; -#ifdef CLIENT_DEBUGLOG_ - debuglog("reconnecting client locked to %x\n", client->jobid_next); -#endif + if (g_debuglog_client) { + debuglog("reconnecting client locked to %x\n", client->jobid_next); + } } else @@ -106,9 +104,9 @@ bool client_subscribe(YAAMP_CLIENT *client, json_value *json_params) memcpy(client->job_history, client1->job_history, sizeof(client->job_history)); client1->lock_count = 0; -#ifdef CLIENT_DEBUGLOG_ - debuglog("reconnecting2 client\n"); -#endif + if (g_debuglog_client) { + debuglog("reconnecting2 client\n"); + } } } } @@ -116,9 +114,9 @@ bool client_subscribe(YAAMP_CLIENT *client, json_value *json_params) strcpy(client->extranonce1_last, client->extranonce1); client->extranonce2size_last = client->extranonce2size; -#ifdef CLIENT_DEBUGLOG_ - debuglog("new client with nonce %s\n", client->extranonce1); -#endif + if (g_debuglog_client) { + debuglog("new client with nonce %s\n", client->extranonce1); + } client_send_result(client, "[[[\"mining.set_difficulty\",\"%.3g\"],[\"mining.notify\",\"%s\"]],\"%s\",%d]", client->difficulty_actual, client->notify_id, client->extranonce1, client->extranonce2size); @@ -236,9 +234,9 @@ bool client_authorize(YAAMP_CLIENT *client, json_value *json_params) client_initialize_difficulty(client); -#ifdef CLIENT_DEBUGLOG_ - debuglog("new client %s, %s, %s\n", client->username, client->password, client->version); -#endif + if (g_debuglog_client) { + debuglog("new client %s, %s, %s\n", client->username, client->password, client->version); + } if(!client->userid || !client->workerid) { @@ -305,9 +303,9 @@ bool client_update_block(YAAMP_CLIENT *client, json_value *json_params) const char* hash = json_params->u.array.values[2]->u.string.ptr; -#ifdef CLIENT_DEBUGLOG_ - debuglog("notify: new %s block %s\n", coind->symbol, hash); -#endif + if (g_debuglog_client) { + debuglog("notify: new %s block %s\n", coind->symbol, hash); + } coind->newblock = true; coind->notreportingcounter = 0; @@ -578,9 +576,9 @@ void *client_thread(void *p) break; } -#ifdef CLIENT_DEBUGLOG_ - debuglog("client %s %d %s\n", method, client->id_int, client->id_str? client->id_str: "null"); -#endif + if (g_debuglog_client) { + debuglog("client %s %d %s\n", method, client->id_int, client->id_str? client->id_str: "null"); + } bool b = false; if(!strcmp(method, "mining.subscribe")) @@ -634,9 +632,9 @@ void *client_thread(void *p) // source_close(client->source); -#ifdef CLIENT_DEBUGLOG_ - debuglog("client terminate\n"); -#endif + if (g_debuglog_client) { + debuglog("client terminate\n"); + } if(!client || client->deleted) { pthread_exit(NULL); } diff --git a/stratum/client_submit.cpp b/stratum/client_submit.cpp index 41cbf5b..e1021f9 100644 --- a/stratum/client_submit.cpp +++ b/stratum/client_submit.cpp @@ -4,7 +4,6 @@ uint64_t lyra2z_height = 0; //#define MERKLE_DEBUGLOG -//#define HASH_DEBUGLOG_ //#define DONTSUBMIT void build_submit_values(YAAMP_JOB_VALUES *submitvalues, YAAMP_JOB_TEMPLATE *templ, @@ -285,20 +284,20 @@ static void client_do_submit(YAAMP_CLIENT *client, YAAMP_JOB *job, YAAMP_JOB_VAL block_confirm(coind->id, submitvalues->hash_be); } -#ifdef HASH_DEBUGLOG_ - debuglog("--------------------------------------------------------------\n"); - debuglog("hash1 %s\n", hash1); - debuglog("hash2 %s\n", submitvalues->hash_be); -#endif + if (g_debuglog_hash) { + debuglog("--------------------------------------------------------------\n"); + debuglog("hash1 %s\n", hash1); + debuglog("hash2 %s\n", submitvalues->hash_be); + } } else { debuglog("*** REJECTED :( %s block %d %d txs\n", coind->name, templ->height, templ->txcount); rejectlog("REJECTED %s block %d\n", coind->symbol, templ->height); -#ifdef HASH_DEBUGLOG_ - //debuglog("block %s\n", block_hex); - debuglog("--------------------------------------------------------------\n"); -#endif + if (g_debuglog_hash) { + //debuglog("block %s\n", block_hex); + debuglog("--------------------------------------------------------------\n"); + } } } @@ -324,9 +323,9 @@ void client_submit_error(YAAMP_CLIENT *client, YAAMP_JOB *job, int id, const cha share_add(client, job, false, extranonce2, ntime, nonce, 0, id); client->submit_bad++; -#ifdef HASH_DEBUGLOG_ - dump_submit_debug(message, client, job, extranonce2, ntime, nonce); -#endif + if (g_debuglog_hash) { + dump_submit_debug(message, client, job, extranonce2, ntime, nonce); + } } object_unlock(job); @@ -377,9 +376,9 @@ bool client_submit(YAAMP_CLIENT *client, json_value *json_params) if (json_params->u.array.length == 6) strncpy(vote, json_params->u.array.values[5]->u.string.ptr, 7); -#ifdef HASH_DEBUGLOG_ - debuglog("submit %s (uid %d) %d, %s, %s, %s\n", client->sock->ip, client->userid, jobid, extranonce2, ntime, nonce); -#endif + if (g_debuglog_hash) { + debuglog("submit %s (uid %d) %d, %s, %s, %s\n", client->sock->ip, client->userid, jobid, extranonce2, ntime, nonce); + } string_lower(extranonce2); string_lower(ntime); @@ -480,11 +479,11 @@ bool client_submit(YAAMP_CLIENT *client, json_value *json_params) // minimum hash diff begins with 0000, for all... uint8_t pfx = submitvalues.hash_bin[30] | submitvalues.hash_bin[31]; if(pfx) { -#ifdef HASH_DEBUGLOG_ - debuglog("Possible %s error, hash starts with %02x%02x%02x%02x\n", g_current_algo->name, - (int) submitvalues.hash_bin[31], (int) submitvalues.hash_bin[30], - (int) submitvalues.hash_bin[29], (int) submitvalues.hash_bin[28]); -#endif + if (g_debuglog_hash) { + debuglog("Possible %s error, hash starts with %02x%02x%02x%02x\n", g_current_algo->name, + (int) submitvalues.hash_bin[31], (int) submitvalues.hash_bin[30], + (int) submitvalues.hash_bin[29], (int) submitvalues.hash_bin[28]); + } client_submit_error(client, job, 25, "Invalid share", extranonce2, ntime, nonce); return true; } @@ -494,11 +493,11 @@ bool client_submit(YAAMP_CLIENT *client, json_value *json_params) uint64_t coin_target = decode_compact(templ->nbits); if (templ->nbits && !coin_target) coin_target = 0xFFFF000000000000ULL; -#ifdef HASH_DEBUGLOG_ - debuglog("%016llx actual\n", hash_int); - debuglog("%016llx target\n", user_target); - debuglog("%016llx coin\n", coin_target); -#endif + if (g_debuglog_hash) { + debuglog("%016llx actual\n", hash_int); + debuglog("%016llx target\n", user_target); + debuglog("%016llx coin\n", coin_target); + } if(hash_int > user_target && hash_int > coin_target) { client_submit_error(client, job, 26, "Low difficulty share", extranonce2, ntime, nonce); @@ -524,12 +523,12 @@ bool client_submit(YAAMP_CLIENT *client, json_value *json_params) // share_diff = share_diff / g_current_algo->diff_multiplier; // } -#ifndef HASH_DEBUGLOG_ - // only log a few... - if (share_diff > (client->difficulty_actual * 16)) - debuglog("submit %s (uid %d) %d, %s, %s, %s, %.3f/%.3f\n", client->sock->ip, client->userid, - jobid, extranonce2, ntime, nonce, share_diff, client->difficulty_actual); -#endif + if (g_debuglog_hash) { + // only log a few... + if (share_diff > (client->difficulty_actual * 16)) + debuglog("submit %s (uid %d) %d, %s, %s, %s, %.3f/%.3f\n", client->sock->ip, client->userid, + jobid, extranonce2, ntime, nonce, share_diff, client->difficulty_actual); + } share_add(client, job, true, extranonce2, ntime, nonce, share_diff, 0); object_unlock(job); diff --git a/stratum/config.sample/skein.conf b/stratum/config.sample/skein.conf index f4957e5..b6d7536 100644 --- a/stratum/config.sample/skein.conf +++ b/stratum/config.sample/skein.conf @@ -14,3 +14,11 @@ algo = skein difficulty = 0.1 max_ttf = 200000000000000 +[DEBUGLOG] +client = 0 +hash = 0 +socket = 0 +rpc = 0 +list = 0 +remote = 0 + diff --git a/stratum/list.cpp b/stratum/list.cpp index 2942f43..ea18d7f 100644 --- a/stratum/list.cpp +++ b/stratum/list.cpp @@ -5,21 +5,21 @@ void CommonLock(pthread_mutex_t *mutex) { -#ifdef _LIST_DEBUG_ - int i=0; - for(; i<10; i++) - { - int res = pthread_mutex_trylock(mutex); - if(res == 0) break; + if (g_debuglog_list) { + int i=0; + for(; i<10; i++) + { + int res = pthread_mutex_trylock(mutex); + if(res == 0) break; - usleep(100*YAAMP_MS); + usleep(100*YAAMP_MS); + } + + if(i == 10) + debuglog("failed mutex2 %x <<----------------\n", mutex); + } else { + pthread_mutex_lock(mutex); } - - if(i == 10) - debuglog("failed mutex2 %x <<----------------\n", mutex); -#else - pthread_mutex_lock(mutex); -#endif } void CommonUnlock(pthread_mutex_t *mutex) @@ -43,21 +43,21 @@ CommonList::~CommonList() void CommonList::Enter() { -#ifdef _LIST_DEBUG_ - int i=0; - for(; i<10; i++) - { - int res = pthread_mutex_trylock(&mutex); - if(res == 0) break; + if (g_debuglog_list) { + int i=0; + for(; i<10; i++) + { + int res = pthread_mutex_trylock(&mutex); + if(res == 0) break; - usleep(100*YAAMP_MS); + usleep(100*YAAMP_MS); + } + + if(i == 10) + debuglog("failed mutex1 %x <<----------------\n", &mutex); + } else { + pthread_mutex_lock(&mutex); } - - if(i == 10) - debuglog("failed mutex1 %x <<----------------\n", &mutex); -#else - pthread_mutex_lock(&mutex); -#endif } void CommonList::Leave() diff --git a/stratum/remote.cpp b/stratum/remote.cpp index 70e8793..b3e4ef1 100644 --- a/stratum/remote.cpp +++ b/stratum/remote.cpp @@ -1,8 +1,6 @@ #include "stratum.h" -//#define REMOTE_DEBUGLOG_ - bool remote_can_mine(YAAMP_REMOTE *remote) { if(!remote) return false; @@ -40,9 +38,9 @@ bool remote_connected(YAAMP_REMOTE *remote) void remote_close(YAAMP_REMOTE *remote) { -#ifdef REMOTE_DEBUGLOG_ - debuglog("remote_close JOB%d\n", remote->id); -#endif + if (g_debuglog_remote) { + debuglog("remote_close JOB%d\n", remote->id); + } remote->difficulty_actual = 0; @@ -65,11 +63,11 @@ bool remote_connect(YAAMP_REMOTE *remote) if(remote_connected(remote)) remote_close(remote); -#ifdef REMOTE_DEBUGLOG_ - debuglog("connecting to %s:%d JOB%d\n", remote->host, remote->port, remote->id); -#endif + if (g_debuglog_remote) { + debuglog("connecting to %s:%d JOB%d\n", remote->host, remote->port, remote->id); + } - int sock = socket(AF_INET, SOCK_STREAM, 0); + int sock = socket(AF_INET, SOCK_STREAM, 0); if(sock <= 0) return false; struct hostent *ent = gethostbyname(remote->host); @@ -85,9 +83,9 @@ bool remote_connect(YAAMP_REMOTE *remote) int res = connect(sock, (struct sockaddr*)&serv, sizeof(serv)); if(res < 0) { -#ifdef REMOTE_DEBUGLOG_ - debuglog("cant connect to %s:%d JOB%d\n", remote->host, remote->port, remote->id); -#endif + if (g_debuglog_remote) { + debuglog("cant connect to %s:%d JOB%d\n", remote->host, remote->port, remote->id); + } return false; } diff --git a/stratum/rpc.cpp b/stratum/rpc.cpp index 66f857d..219b619 100644 --- a/stratum/rpc.cpp +++ b/stratum/rpc.cpp @@ -37,9 +37,9 @@ bool rpc_connect(YAAMP_RPC *rpc) rpc->id = 0; rpc->bufpos = 0; -#ifdef RPC_DEBUGLOG_ - debuglog("connected to %s:%d\n", rpc->host, rpc->port); -#endif + if (g_debuglog_rpc) { + debuglog("connected to %s:%d\n", rpc->host, rpc->port); + } return true; } @@ -52,9 +52,9 @@ void rpc_close(YAAMP_RPC *rpc) close(rpc->sock); rpc->sock = 0; -#ifdef RPC_DEBUGLOG_ - debuglog("disconnected from %s:%d\n", rpc->host, rpc->port); -#endif + if (g_debuglog_rpc) { + debuglog("disconnected from %s:%d\n", rpc->host, rpc->port); + } } /////////////////////////////////////////////////////////////////// @@ -66,9 +66,9 @@ int rpc_send_raw(YAAMP_RPC *rpc, const char *buffer, int bytes) int res = send(rpc->sock, buffer, bytes, MSG_NOSIGNAL); if(res <= 0) return res; -#ifdef RPC_DEBUGLOG_ - debuglog("sending >%s<\n", buffer); -#endif + if (g_debuglog_rpc) { + debuglog("sending >%s<\n", buffer); + } return res; } @@ -148,9 +148,9 @@ char *rpc_do_call(YAAMP_RPC *rpc, char const *data) while(!g_exiting) { int bytes = recv(rpc->sock, buffer+bufpos, YAAMP_SMALLBUFSIZE-bufpos-1, 0); -#ifdef RPC_DEBUGLOG_ - debuglog("got %s\n", buffer+bufpos); -#endif + if (g_debuglog_rpc) { + debuglog("got %s\n", buffer+bufpos); + } if(bytes <= 0) { debuglog("ERROR: recv1, %d, %d, %s, %s\n", bytes, errno, data, buffer); diff --git a/stratum/socket.cpp b/stratum/socket.cpp index c829c6a..00710db 100644 --- a/stratum/socket.cpp +++ b/stratum/socket.cpp @@ -1,8 +1,6 @@ #include "stratum.h" -//#define SOCKET_DEBUGLOG_ - bool socket_connected(YAAMP_SOCKET *s) { return s->sock > 0; @@ -68,9 +66,9 @@ YAAMP_SOCKET *socket_initialize(int sock) void socket_close(YAAMP_SOCKET *s) { -#ifdef SOCKET_DEBUGLOG_ - debuglog("socket_close\n"); -#endif + if (g_debuglog_socket) { + debuglog("socket_close\n"); + } if(!s) return; if(s->sock) close(s->sock); @@ -174,9 +172,9 @@ json_value *socket_nextjson(YAAMP_SOCKET *s, YAAMP_CLIENT *client) int socket_send_raw(YAAMP_SOCKET *s, const char *buffer, int size) { -#ifdef SOCKET_DEBUGLOG_ - debuglog("socket send: %s", buffer); -#endif + if (g_debuglog_socket) { + debuglog("socket send: %s", buffer); + } int res = send(s->sock, buffer, size, MSG_NOSIGNAL); return res; diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index 2be15b2..7d75587 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -39,6 +39,13 @@ bool g_stratum_segwit = false; int g_limit_txs_per_block = 0; +bool g_debuglog_client; +bool g_debuglog_hash; +bool g_debuglog_socket; +bool g_debuglog_rpc; +bool g_debuglog_list; +bool g_debuglog_remote; + bool g_autoexchange = true; uint64_t g_max_shares = 0; @@ -241,6 +248,13 @@ int main(int argc, char **argv) g_limit_txs_per_block = iniparser_getint(ini, "STRATUM:max_txs_per_block", 0); + g_debuglog_client = iniparser_getint(ini, "DEBUGLOG:client", false); + g_debuglog_hash = iniparser_getint(ini, "DEBUGLOG:hash", false); + g_debuglog_socket = iniparser_getint(ini, "DEBUGLOG:socket", false); + g_debuglog_rpc = iniparser_getint(ini, "DEBUGLOG:rpc", false); + g_debuglog_list = iniparser_getint(ini, "DEBUGLOG:list", false); + g_debuglog_remote = iniparser_getint(ini, "DEBUGLOG:remote", false); + iniparser_freedict(ini); g_current_algo = stratum_find_algo(g_stratum_algo); diff --git a/stratum/stratum.h b/stratum/stratum.h index 81c3d52..43356e0 100644 --- a/stratum/stratum.h +++ b/stratum/stratum.h @@ -90,6 +90,13 @@ extern bool g_stratum_renting; extern bool g_stratum_segwit; extern int g_limit_txs_per_block; +extern bool g_debuglog_client; +extern bool g_debuglog_hash; +extern bool g_debuglog_socket; +extern bool g_debuglog_rpc; +extern bool g_debuglog_list; +extern bool g_debuglog_remote; + extern uint64_t g_max_shares; extern uint64_t g_shares_counter;