stratum: debuglog on/off without code recompile

+ drop log CFLAGS comments in Makefile and old defines comments
This commit is contained in:
protopool.net 2018-03-06 14:58:37 +06:00 committed by Tanguy Pruvot
parent 010fd14493
commit 8c85b95220
10 changed files with 135 additions and 119 deletions

View file

@ -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`

View file

@ -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_
if (g_debuglog_client) {
debuglog("reconnecting client locked to %x\n", client->jobid_next);
#endif
}
}
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_
if (g_debuglog_client) {
debuglog("reconnecting2 client\n");
#endif
}
}
}
}
@ -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_
if (g_debuglog_client) {
debuglog("new client with nonce %s\n", client->extranonce1);
#endif
}
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_
if (g_debuglog_client) {
debuglog("new client %s, %s, %s\n", client->username, client->password, client->version);
#endif
}
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_
if (g_debuglog_client) {
debuglog("notify: new %s block %s\n", coind->symbol, hash);
#endif
}
coind->newblock = true;
coind->notreportingcounter = 0;
@ -578,9 +576,9 @@ void *client_thread(void *p)
break;
}
#ifdef CLIENT_DEBUGLOG_
if (g_debuglog_client) {
debuglog("client %s %d %s\n", method, client->id_int, client->id_str? client->id_str: "null");
#endif
}
bool b = false;
if(!strcmp(method, "mining.subscribe"))
@ -634,9 +632,9 @@ void *client_thread(void *p)
// source_close(client->source);
#ifdef CLIENT_DEBUGLOG_
if (g_debuglog_client) {
debuglog("client terminate\n");
#endif
}
if(!client || client->deleted) {
pthread_exit(NULL);
}

View file

@ -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_
if (g_debuglog_hash) {
debuglog("--------------------------------------------------------------\n");
debuglog("hash1 %s\n", hash1);
debuglog("hash2 %s\n", submitvalues->hash_be);
#endif
}
}
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_
if (g_debuglog_hash) {
//debuglog("block %s\n", block_hex);
debuglog("--------------------------------------------------------------\n");
#endif
}
}
}
@ -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_
if (g_debuglog_hash) {
dump_submit_debug(message, client, job, extranonce2, ntime, nonce);
#endif
}
}
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_
if (g_debuglog_hash) {
debuglog("submit %s (uid %d) %d, %s, %s, %s\n", client->sock->ip, client->userid, jobid, extranonce2, ntime, nonce);
#endif
}
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_
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]);
#endif
}
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_
if (g_debuglog_hash) {
debuglog("%016llx actual\n", hash_int);
debuglog("%016llx target\n", user_target);
debuglog("%016llx coin\n", coin_target);
#endif
}
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_
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);
#endif
}
share_add(client, job, true, extranonce2, ntime, nonce, share_diff, 0);
object_unlock(job);

View file

@ -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

View file

@ -5,7 +5,7 @@
void CommonLock(pthread_mutex_t *mutex)
{
#ifdef _LIST_DEBUG_
if (g_debuglog_list) {
int i=0;
for(; i<10; i++)
{
@ -17,9 +17,9 @@ void CommonLock(pthread_mutex_t *mutex)
if(i == 10)
debuglog("failed mutex2 %x <<----------------\n", mutex);
#else
} else {
pthread_mutex_lock(mutex);
#endif
}
}
void CommonUnlock(pthread_mutex_t *mutex)
@ -43,7 +43,7 @@ CommonList::~CommonList()
void CommonList::Enter()
{
#ifdef _LIST_DEBUG_
if (g_debuglog_list) {
int i=0;
for(; i<10; i++)
{
@ -55,9 +55,9 @@ void CommonList::Enter()
if(i == 10)
debuglog("failed mutex1 %x <<----------------\n", &mutex);
#else
} else {
pthread_mutex_lock(&mutex);
#endif
}
}
void CommonList::Leave()

View file

@ -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_
if (g_debuglog_remote) {
debuglog("remote_close JOB%d\n", remote->id);
#endif
}
remote->difficulty_actual = 0;
@ -65,9 +63,9 @@ bool remote_connect(YAAMP_REMOTE *remote)
if(remote_connected(remote))
remote_close(remote);
#ifdef REMOTE_DEBUGLOG_
if (g_debuglog_remote) {
debuglog("connecting to %s:%d JOB%d\n", remote->host, remote->port, remote->id);
#endif
}
int sock = socket(AF_INET, SOCK_STREAM, 0);
if(sock <= 0) return false;
@ -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_
if (g_debuglog_remote) {
debuglog("cant connect to %s:%d JOB%d\n", remote->host, remote->port, remote->id);
#endif
}
return false;
}

View file

@ -37,9 +37,9 @@ bool rpc_connect(YAAMP_RPC *rpc)
rpc->id = 0;
rpc->bufpos = 0;
#ifdef RPC_DEBUGLOG_
if (g_debuglog_rpc) {
debuglog("connected to %s:%d\n", rpc->host, rpc->port);
#endif
}
return true;
}
@ -52,9 +52,9 @@ void rpc_close(YAAMP_RPC *rpc)
close(rpc->sock);
rpc->sock = 0;
#ifdef RPC_DEBUGLOG_
if (g_debuglog_rpc) {
debuglog("disconnected from %s:%d\n", rpc->host, rpc->port);
#endif
}
}
///////////////////////////////////////////////////////////////////
@ -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_
if (g_debuglog_rpc) {
debuglog("sending >%s<\n", buffer);
#endif
}
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_
if (g_debuglog_rpc) {
debuglog("got %s\n", buffer+bufpos);
#endif
}
if(bytes <= 0)
{
debuglog("ERROR: recv1, %d, %d, %s, %s\n", bytes, errno, data, buffer);

View file

@ -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_
if (g_debuglog_socket) {
debuglog("socket_close\n");
#endif
}
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_
if (g_debuglog_socket) {
debuglog("socket send: %s", buffer);
#endif
}
int res = send(s->sock, buffer, size, MSG_NOSIGNAL);
return res;

View file

@ -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);

View file

@ -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;