From 066da4d8e1f0b633afcd1b37f78374539731af9e Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 20 Jun 2017 07:53:27 +0200 Subject: [PATCH] stratum: log rejected blocks in a special file --- stratum/client_submit.cpp | 1 + stratum/stratum.cpp | 2 ++ stratum/util.cpp | 46 +++++++++++++++++++++++++++++++++++++++ stratum/util.h | 2 ++ 4 files changed, 51 insertions(+) diff --git a/stratum/client_submit.cpp b/stratum/client_submit.cpp index 80a3ed6..5e3c5fa 100644 --- a/stratum/client_submit.cpp +++ b/stratum/client_submit.cpp @@ -288,6 +288,7 @@ static void client_do_submit(YAAMP_CLIENT *client, YAAMP_JOB *job, YAAMP_JOB_VAL else { debuglog("*** REJECTED :( %s block %d %d txs\n", coind->name, templ->height, templ->txcount); + rejectlog("REJECTED %s block %d %s\n", coind->symbol, templ->height, block_hex); #ifdef HASH_DEBUGLOG_ //debuglog("block %s\n", block_hex); debuglog("--------------------------------------------------------------\n"); diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index 12a7875..5a9f393 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -316,6 +316,8 @@ int main(int argc, char **argv) pthread_join(thread2, NULL); db_close(g_db); // client threads (called by stratum one) + closelogs(); + return 0; } diff --git a/stratum/util.cpp b/stratum/util.cpp index 2ac2d43..de4ef6f 100644 --- a/stratum/util.cpp +++ b/stratum/util.cpp @@ -88,6 +88,7 @@ json_value *json_get_object(json_value *json, const char *name) FILE *g_debuglog = NULL; FILE *g_stratumlog = NULL; FILE *g_clientlog = NULL; +FILE *g_rejectlog = NULL; void initlog(const char *algo) { @@ -98,6 +99,23 @@ void initlog(const char *algo) g_stratumlog = fopen("stratum.log", "a"); g_clientlog = fopen("client.log", "a"); + g_rejectlog = fopen("reject.log", "a"); +} + +void closelogs() +{ + if (g_debuglog) { + fflush(g_debuglog); fclose(g_debuglog); + } + if (g_stratumlog) { + fflush(g_stratumlog); fclose(g_stratumlog); + } + if (g_clientlog) { + fflush(g_clientlog); fclose(g_clientlog); + } + if (g_rejectlog) { + fflush(g_rejectlog); fclose(g_rejectlog); + } } void clientlog(YAAMP_CLIENT *client, const char *format, ...) @@ -224,9 +242,37 @@ void stratumlogdate(const char *format, ...) stratumlog("%s %s", date, buffer); } +void rejectlog(const char *format, ...) +{ + char buffer[YAAMP_SMALLBUFSIZE]; + va_list args; + + va_start(args, format); + vsnprintf(buffer, YAAMP_SMALLBUFSIZE-1, format, args); + va_end(args); + + time_t rawtime; + struct tm * timeinfo; + char buffer2[80]; + + time(&rawtime); + timeinfo = localtime(&rawtime); + + strftime(buffer2, 80, "%H:%M:%S", timeinfo); + printf("%s: %s", buffer2, buffer); + + if(g_rejectlog) + { + fprintf(g_rejectlog, "%s: %s", buffer2, buffer); + fflush(g_rejectlog); + } +} + + bool yaamp_error(char const *message) { debuglog("ERROR: %d %s\n", errno, message); + closelogs(); exit(1); } diff --git a/stratum/util.h b/stratum/util.h index 046e0ad..1a39be2 100644 --- a/stratum/util.h +++ b/stratum/util.h @@ -58,11 +58,13 @@ bool yaamp_error(char const *message); const char *header_value(const char *data, const char *search, char *value); void initlog(const char *algo); +void closelogs(); void debuglog(const char *format, ...); void stratumlog(const char *format, ...); void stratumlogdate(const char *format, ...); void clientlog(YAAMP_CLIENT *client, const char *format, ...); +void rejectlog(const char *format, ...); //////////////////////////////////////////////////////////////////////////