Remove redundant internal callback system - verbose output provides better progress reporting

This commit is contained in:
Your Name
2025-08-16 15:57:14 -04:00
parent 9c428082f1
commit d4e609039e
4 changed files with 131925 additions and 48 deletions

View File

@@ -32,8 +32,6 @@ typedef struct mining_context mining_context_t;
// Callback function types
typedef void (*solution_callback_t)(cJSON* solution, void* user_data);
typedef void (*progress_callback_t)(int thread_id, uint64_t attempts, void* user_data);
typedef void (*error_callback_t)(int thread_id, int error_code, void* user_data);
// Main context for control decisions
typedef struct {
@@ -52,8 +50,6 @@ struct mining_context {
// Callbacks for reporting (no control decisions)
solution_callback_t solution_callback;
progress_callback_t progress_callback;
error_callback_t error_callback;
void* user_data;
// Control flag (only main thread modifies)
@@ -95,8 +91,6 @@ static void cleanup_context(mining_context_t* ctx);
// Callback implementations
static void solution_found_callback(cJSON* solution, void* user_data);
static void progress_report_callback(int thread_id, uint64_t attempts, void* user_data);
static void error_report_callback(int thread_id, int error_code, void* user_data);
static void verbose_pow_callback(int current_difficulty, uint64_t nonce, void* user_data);
// Usage information
@@ -262,35 +256,6 @@ static void solution_found_callback(cJSON* solution, void* user_data) {
pthread_mutex_unlock(&main_ctx->result_mutex);
}
static void progress_report_callback(int thread_id, uint64_t attempts, void* user_data) {
main_context_t* main_ctx = (main_context_t*)user_data;
// Only report if solution not yet found
if (!main_ctx->solution_found && !main_ctx->timeout_reached) {
printf("[Thread %d] Progress: %llu attempts completed\n",
thread_id, (unsigned long long)attempts);
fflush(stdout);
}
}
static void error_report_callback(int thread_id, int error_code, void* user_data) {
const char* error_msg;
switch (error_code) {
case -1:
error_msg = "JSON serialization failed";
break;
case -2:
error_msg = "Event parsing failed";
break;
default:
error_msg = "Unknown error";
break;
}
fprintf(stderr, "[Thread %d] Error %d: %s\n", thread_id, error_code, error_msg);
fflush(stderr);
}
// Verbose PoW callback - receives progress from nostr_add_proof_of_work
static void verbose_pow_callback(int current_difficulty, uint64_t nonce, void* user_data) {
@@ -339,9 +304,6 @@ static void* miner_thread(void* arg) {
// Create a copy of the event for this thread
char* event_str = cJSON_Print(ctx->event);
if (!event_str) {
if (ctx->error_callback) {
ctx->error_callback(ctx->thread_id, -1, ctx->user_data);
}
return NULL;
}
@@ -349,9 +311,6 @@ static void* miner_thread(void* arg) {
free(event_str);
if (!local_event) {
if (ctx->error_callback) {
ctx->error_callback(ctx->thread_id, -2, ctx->user_data);
}
return NULL;
}
@@ -378,10 +337,6 @@ static void* miner_thread(void* arg) {
break; // Exit after reporting solution
}
// Progress reporting every 10 attempts
if (ctx->progress_callback && attempts % 10 == 0) {
ctx->progress_callback(ctx->thread_id, attempts, ctx->user_data);
}
// Small delay to prevent CPU overuse and allow responsive stopping
usleep(100); // 0.1ms - more responsive to should_stop signal
@@ -405,8 +360,6 @@ static int mine_event(mining_context_t* ctx) {
// Set up callback system
ctx->solution_callback = solution_found_callback;
ctx->progress_callback = progress_report_callback;
ctx->error_callback = error_report_callback;
ctx->user_data = &main_ctx;
ctx->should_stop = 0;