api: Display major errors from blocktemplates

This commit is contained in:
Luke Dashjr 2024-12-09 18:05:52 +00:00
parent 83edd5951f
commit 7a35e19a5d
No known key found for this signature in database
GPG Key ID: A291A2C45D0C504A
3 changed files with 17 additions and 4 deletions

View File

@ -47,6 +47,7 @@
#include <jansson.h>
#include "datum_api.h"
#include "datum_blocktemplates.h"
#include "datum_conf.h"
#include "datum_utils.h"
#include "datum_stratum.h"
@ -86,8 +87,13 @@ void datum_api_var_DATUM_SHARES_REJECTED(char *buffer, size_t buffer_size, const
}
void datum_api_var_DATUM_CONNECTION_STATUS(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) {
const char *colour = "lime";
const char *s;
if (!vardata->sjob) {
const char *s, *s2 = "";
const char * const bt_err = datum_blocktemplates_error;
if (bt_err) {
colour = "red";
s = "ERROR: ";
s2 = bt_err;
} else if (!vardata->sjob) {
colour = "silver";
s = "Initialising...";
} else if (datum_protocol_is_active()) {
@ -101,7 +107,7 @@ void datum_api_var_DATUM_CONNECTION_STATUS(char *buffer, size_t buffer_size, con
}
s = "Non-Pooled Mode";
}
snprintf(buffer, buffer_size, "<svg viewBox='0 0 100 100' role='img' style='width:1em;height:1em'><circle cx='50' cy='60' r='35' style='fill:%s' /></svg> %s", colour, s);
snprintf(buffer, buffer_size, "<svg viewBox='0 0 100 100' role='img' style='width:1em;height:1em'><circle cx='50' cy='60' r='35' style='fill:%s' /></svg> %s%s", colour, s, s2);
}
void datum_api_var_DATUM_POOL_HOST(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) {
if (datum_config.datum_pool_host[0]) {

View File

@ -74,6 +74,8 @@ T_DATUM_TEMPLATE_DATA *template_data = NULL;
int next_template_index = 0;
const char *datum_blocktemplates_error = NULL;
int datum_template_init(void) {
char *temp = NULL, *ptr = NULL;
int i,j;
@ -424,18 +426,21 @@ void *datum_gateway_template_thread(void *args) {
gbt = json_rpc_call(tcurl, datum_config.bitcoind_rpcurl, userpass, gbt_req);
if (!gbt) {
datum_blocktemplates_error = "Could not fetch new template!";
DLOG_ERROR("Could not fetch new template from %s!", datum_config.bitcoind_rpcurl);
sleep(1);
continue;
} else {
res_val = json_object_get(gbt, "result");
if (!res_val) {
DLOG_ERROR("ERROR: Could not decode GBT result!");
datum_blocktemplates_error = "Could not decode GBT result!";
DLOG_ERROR("%s", datum_blocktemplates_error);
} else {
DLOG_DEBUG("DEBUG: calling datum_gbt_parser (new=%d)", was_notified?1:0);
t = datum_gbt_parser(res_val);
if (t) {
datum_blocktemplates_error = NULL;
DLOG_DEBUG("height: %d / value: %"PRIu64,t->height, t->coinbasevalue);
DLOG_DEBUG("--- prevhash: %s", t->previousblockhash);
DLOG_DEBUG("--- txn_count: %u / sigops: %u / weight: %u / size: %u", t->txn_count, t->txn_total_sigops, t->txn_total_weight, t->txn_total_size);

View File

@ -186,6 +186,8 @@ typedef struct {
uint32_t local_data_size;
} T_DATUM_TEMPLATE_DATA;
extern const char *datum_blocktemplates_error;
int datum_template_init(void);
T_DATUM_TEMPLATE_DATA *datum_gbt_parser(json_t *gbt);
void *datum_gateway_template_thread(void *args);