mirror of
https://github.com/skot/ESP-Miner.git
synced 2025-04-10 04:49:16 +02:00
Expire stratum jobs after 5 mins
This commit is contained in:
parent
685d8c1979
commit
4eac4e8cf9
@ -6,7 +6,7 @@
|
||||
#include <limits.h>
|
||||
#include "string.h"
|
||||
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
static const char *TAG = "create_jobs_task";
|
||||
|
||||
@ -23,6 +23,18 @@ void create_jobs_task(void * pvParameters)
|
||||
uint32_t extranonce_2 = 0;
|
||||
while (extranonce_2 < UINT_MAX && GLOBAL_STATE->abandon_work == 0)
|
||||
{
|
||||
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
int job_time_sec = tv.tv_sec - mining_notification->ntime;
|
||||
|
||||
// Expire jobs after 5 minutes
|
||||
// This seems to be an issue with some pools (ckpool)
|
||||
if(job_time_sec > 60 * 5){
|
||||
ESP_LOGI(TAG, "Job Expired");
|
||||
break;
|
||||
}
|
||||
|
||||
char * extranonce_2_str = extranonce_2_generate(extranonce_2, GLOBAL_STATE->extranonce_2_len);
|
||||
|
||||
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include "bm1397.h"
|
||||
#include "global_state.h"
|
||||
#include "stratum_task.h"
|
||||
#include <esp_sntp.h>
|
||||
#include <time.h>
|
||||
|
||||
#define PORT CONFIG_STRATUM_PORT
|
||||
#define STRATUM_URL CONFIG_STRATUM_URL
|
||||
@ -29,6 +31,33 @@ void dns_found_cb(const char * name, const ip_addr_t * ipaddr, void * callback_a
|
||||
bDNSFound = true;
|
||||
}
|
||||
|
||||
void obtain_time(void)
|
||||
{
|
||||
// Initialize SNTP
|
||||
sntp_setoperatingmode(SNTP_OPMODE_POLL);
|
||||
sntp_setservername(0, "pool.ntp.org"); // Set NTP server
|
||||
sntp_init();
|
||||
|
||||
// Wait for the time to be set
|
||||
time_t now = 0;
|
||||
struct tm timeinfo = {0};
|
||||
int retry = 0;
|
||||
const int retry_count = 60;
|
||||
while (timeinfo.tm_year < (2021 - 1900) && ++retry < retry_count) {
|
||||
ESP_LOGI(TAG, "Waiting for system time to be set... (%d/%d)", retry, retry_count);
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
time(&now);
|
||||
localtime_r(&now, &timeinfo);
|
||||
}
|
||||
|
||||
// Print the obtained time
|
||||
if (retry < retry_count) {
|
||||
ESP_LOGI(TAG, "System time is set.");
|
||||
ESP_LOGI(TAG, "Current time: %s", asctime(&timeinfo));
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Could not set system time.");
|
||||
}
|
||||
}
|
||||
|
||||
void stratum_task(void * pvParameters)
|
||||
{
|
||||
@ -77,6 +106,7 @@ void stratum_task(void * pvParameters)
|
||||
break;
|
||||
}
|
||||
|
||||
obtain_time();
|
||||
|
||||
STRATUM_V1_subscribe(GLOBAL_STATE->sock, &GLOBAL_STATE->extranonce_str, &GLOBAL_STATE->extranonce_2_len);
|
||||
|
||||
@ -99,7 +129,7 @@ void stratum_task(void * pvParameters)
|
||||
|
||||
if (stratum_api_v1_message.method == MINING_NOTIFY) {
|
||||
//ESP_LOGI(TAG, "Mining Notify");
|
||||
if (stratum_api_v1_message.should_abandon_work) {
|
||||
if (stratum_api_v1_message.should_abandon_work && (GLOBAL_STATE->stratum_queue.count > 0 || GLOBAL_STATE->ASIC_jobs_queue.count > 0)) {
|
||||
ESP_LOGI(TAG, "abandoning work");
|
||||
|
||||
GLOBAL_STATE->abandon_work = 1;
|
||||
@ -136,7 +166,7 @@ void stratum_task(void * pvParameters)
|
||||
ESP_LOGI(TAG, "message result accepted");
|
||||
SYSTEM_notify_accepted_share(&GLOBAL_STATE->SYSTEM_MODULE);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "message result rejected");
|
||||
ESP_LOGE(TAG, "message result rejected");
|
||||
SYSTEM_notify_rejected_share(&GLOBAL_STATE->SYSTEM_MODULE);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user