Implement progress and error callback reporting every 9999 attempts
This commit is contained in:
@@ -263,19 +263,33 @@ static void solution_found_callback(cJSON* solution, void* user_data) {
|
||||
}
|
||||
|
||||
static void progress_report_callback(int thread_id, uint64_t attempts, void* user_data) {
|
||||
// Progress callback - placeholder for future implementation
|
||||
// For now, do nothing as requested
|
||||
(void)thread_id; // Suppress unused parameter warning
|
||||
(void)attempts; // Suppress unused parameter warning
|
||||
(void)user_data; // Suppress unused parameter warning
|
||||
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) {
|
||||
// Error callback for debugging - placeholder for future implementation
|
||||
// For now, do nothing but could be used for debugging thread issues
|
||||
(void)thread_id; // Suppress unused parameter warning
|
||||
(void)error_code; // Suppress unused parameter warning
|
||||
(void)user_data; // Suppress unused parameter warning
|
||||
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
|
||||
@@ -350,7 +364,7 @@ static void* miner_thread(void* arg) {
|
||||
|
||||
int result = nostr_add_proof_of_work(local_event, ctx->private_key,
|
||||
ctx->target_difficulty, 1000000, // max_attempts
|
||||
1000, // progress_report_interval
|
||||
10000, // progress_report_interval
|
||||
30, // timestamp_update_interval (seconds)
|
||||
progress_cb, ctx);
|
||||
|
||||
@@ -364,8 +378,8 @@ static void* miner_thread(void* arg) {
|
||||
break; // Exit after reporting solution
|
||||
}
|
||||
|
||||
// Progress reporting (currently disabled but ready for future use)
|
||||
if (ctx->progress_callback && attempts % 10000 == 0) {
|
||||
// Progress reporting every 9999 attempts
|
||||
if (ctx->progress_callback && attempts % 9999 == 0) {
|
||||
ctx->progress_callback(ctx->thread_id, attempts, ctx->user_data);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user