Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep old pool config synchronized until reboot #543

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions main/global_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ typedef struct
char * fallback_pool_url;
uint16_t pool_port;
uint16_t fallback_pool_port;
char * pool_user;
char * fallback_pool_user;
char * pool_pass;
char * fallback_pool_pass;
bool is_using_fallback;
uint16_t overheat_mode;
uint32_t lastClockSync;
Expand Down
10 changes: 9 additions & 1 deletion main/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,18 @@ void SYSTEM_init_system(GlobalState * GLOBAL_STATE)
module->pool_url = nvs_config_get_string(NVS_CONFIG_STRATUM_URL, CONFIG_STRATUM_URL);
module->fallback_pool_url = nvs_config_get_string(NVS_CONFIG_FALLBACK_STRATUM_URL, CONFIG_FALLBACK_STRATUM_URL);

//set the pool port
// set the pool port
module->pool_port = nvs_config_get_u16(NVS_CONFIG_STRATUM_PORT, CONFIG_STRATUM_PORT);
module->fallback_pool_port = nvs_config_get_u16(NVS_CONFIG_FALLBACK_STRATUM_PORT, CONFIG_FALLBACK_STRATUM_PORT);

// set the pool user
module->pool_user = nvs_config_get_string(NVS_CONFIG_STRATUM_USER, CONFIG_STRATUM_USER);
module->fallback_pool_user = nvs_config_get_string(NVS_CONFIG_FALLBACK_STRATUM_USER, CONFIG_FALLBACK_STRATUM_USER);

// set the pool password
module->pool_pass = nvs_config_get_string(NVS_CONFIG_STRATUM_PASS, CONFIG_STRATUM_PW);
module->fallback_pool_pass = nvs_config_get_string(NVS_CONFIG_FALLBACK_STRATUM_PASS, CONFIG_FALLBACK_STRATUM_PW);

// set fallback to false.
module->is_using_fallback = false;

Expand Down
5 changes: 2 additions & 3 deletions main/tasks/asic_result_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void ASIC_result_task(void *pvParameters)

if (nonce_diff > GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job_id]->pool_diff)
{
char * user = GLOBAL_STATE->SYSTEM_MODULE.is_using_fallback ? nvs_config_get_string(NVS_CONFIG_FALLBACK_STRATUM_USER, FALLBACK_STRATUM_USER) : nvs_config_get_string(NVS_CONFIG_STRATUM_USER, STRATUM_USER);
char * user = GLOBAL_STATE->SYSTEM_MODULE.is_using_fallback ? GLOBAL_STATE->SYSTEM_MODULE.fallback_pool_user : GLOBAL_STATE->SYSTEM_MODULE.pool_user;
int ret = STRATUM_V1_submit_share(
GLOBAL_STATE->sock,
user,
Expand All @@ -52,7 +52,6 @@ void ASIC_result_task(void *pvParameters)
GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job_id]->ntime,
asic_result->nonce,
asic_result->rolled_version ^ GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job_id]->version);
free(user);

if (ret < 0) {
ESP_LOGI(TAG, "Unable to write share to socket. Closing connection. Ret: %d (errno %d: %s)", ret, errno, strerror(errno));
Expand All @@ -62,4 +61,4 @@ void ASIC_result_task(void *pvParameters)

SYSTEM_notify_found_nonce(GLOBAL_STATE, nonce_diff, job_id);
}
}
}
8 changes: 3 additions & 5 deletions main/tasks/stratum_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,11 @@ void stratum_task(void * pvParameters)
// mining.subscribe - ID: 2
STRATUM_V1_subscribe(GLOBAL_STATE->sock, GLOBAL_STATE->asic_model_str);

char * username = GLOBAL_STATE->SYSTEM_MODULE.is_using_fallback ? nvs_config_get_string(NVS_CONFIG_FALLBACK_STRATUM_USER, FALLBACK_STRATUM_USER) : nvs_config_get_string(NVS_CONFIG_STRATUM_USER, STRATUM_USER);
char * password = GLOBAL_STATE->SYSTEM_MODULE.is_using_fallback ? nvs_config_get_string(NVS_CONFIG_FALLBACK_STRATUM_PASS, FALLBACK_STRATUM_PW) : nvs_config_get_string(NVS_CONFIG_STRATUM_PASS, STRATUM_PW);
char * username = GLOBAL_STATE->SYSTEM_MODULE.is_using_fallback ? GLOBAL_STATE->SYSTEM_MODULE.fallback_pool_user : GLOBAL_STATE->SYSTEM_MODULE.pool_user;
char * password = GLOBAL_STATE->SYSTEM_MODULE.is_using_fallback ? GLOBAL_STATE->SYSTEM_MODULE.fallback_pool_pass : GLOBAL_STATE->SYSTEM_MODULE.pool_pass;

//mining.authorize - ID: 3
STRATUM_V1_authenticate(GLOBAL_STATE->sock, username, password);
free(password);
free(username);

//mining.suggest_difficulty - ID: 4
STRATUM_V1_suggest_difficulty(GLOBAL_STATE->sock, STRATUM_DIFFICULTY);
Expand Down Expand Up @@ -315,4 +313,4 @@ void stratum_task(void * pvParameters)
}
}
vTaskDelete(NULL);
}
}
Loading