stratum: configure version-rolling and parse version mask

This commit is contained in:
johnny9 2023-05-31 21:11:15 -04:00
parent 30ee3f9dbb
commit 471c53c817
3 changed files with 48 additions and 1 deletions

View File

@ -24,7 +24,8 @@ typedef struct {
typedef enum {
STRATUM_UNKNOWN,
MINING_NOTIFY,
MINING_SET_DIFFICULTY
MINING_SET_DIFFICULTY,
MINING_SET_VERSION_MASK
} stratum_method;
void initialize_stratum_buffer();
@ -39,6 +40,8 @@ mining_notify parse_mining_notify_message(const char * stratum_json);
uint32_t parse_mining_set_difficulty_message(const char * stratum_json);
uint32_t parse_mining_set_version_mask_message(const char * stratum_json);
void free_mining_notify(mining_notify params);
int parse_stratum_subscribe_result_message(const char * result_json_str,
@ -46,6 +49,9 @@ int parse_stratum_subscribe_result_message(const char * result_json_str,
int * extranonce2_len);
int auth_to_stratum(int socket, const char * username);
void configure_version_rolling(int socket);
int suggest_difficulty(int socket, uint32_t difficulty);
void submit_share(int socket, const char * username, const char * jobid,

View File

@ -105,6 +105,8 @@ stratum_method parse_stratum_method(const char * stratum_json)
result = MINING_NOTIFY;
} else if (strcmp("mining.set_difficulty", method_json->valuestring) == 0) {
result = MINING_SET_DIFFICULTY;
} else if (strcmp("mining.set_version_mask", method_json->valuestring) == 0) {
result = MINING_SET_VERSION_MASK;
}
}
@ -127,6 +129,21 @@ uint32_t parse_mining_set_difficulty_message(const char * stratum_json)
return difficulty;
}
uint32_t parse_mining_set_version_mask_message(const char * stratum_json)
{
cJSON * json = cJSON_Parse(stratum_json);
cJSON * method = cJSON_GetObjectItem(json, "method");
if (method != NULL && cJSON_IsString(method)) {
assert(strcmp("mining.set_version_mask", method->valuestring) == 0);
}
cJSON * params = cJSON_GetObjectItem(json, "params");
uint32_t version_mask = strtoul(cJSON_GetArrayItem(params, 0)->valuestring, NULL, 16);
cJSON_Delete(json);
return version_mask;
}
mining_notify parse_mining_notify_message(const char * stratum_json)
{
cJSON * json = cJSON_Parse(stratum_json);
@ -282,3 +299,19 @@ int should_abandon_work(const char * mining_notify_json_str)
cJSON_Delete(root);
return value;
}
void parse_stratum_configure_result_message(const char * line, uint32_t * version_mask)
{
return;
}
void configure_version_rolling(int socket)
{
// Configure
char configure_msg[BUFFER_SIZE * 2];
sprintf(configure_msg, "{\"id\": %d, \"method\": \"mining.configure\", \"params\": [[\"version-rolling\"], {\"version-rolling.mask\": \"ffffffff\"}]}\n", send_uid++);
ESP_LOGI(TAG, "-> %s", configure_msg);
write(socket, configure_msg, strlen(configure_msg));
return;
}

View File

@ -273,8 +273,13 @@ static void admin_task(void * pvParameters)
ESP_LOGE(TAG, "Socket unable to connect: errno %d", errno);
break;
}
uint32_t version_mask = 0;
subscribe_to_stratum(sock, &extranonce_str, &extranonce_2_len);
configure_version_rolling(sock);
auth_to_stratum(sock, STRATUM_USER);
ESP_LOGI(TAG, "Extranonce: %s", extranonce_str);
@ -309,6 +314,9 @@ static void admin_task(void * pvParameters)
} else if (method == MINING_SET_DIFFICULTY) {
stratum_difficulty = parse_mining_set_difficulty_message(line);
ESP_LOGI(TAG, "Set stratum difficulty: %d", stratum_difficulty);
} else if (method == MINING_SET_VERSION_MASK) {
version_mask = parse_mining_set_version_mask_message(line);
ESP_LOGI(TAG, "Set version mask: %08x", version_mask);
} else {
free(line);
}