From c8976115d1d88e47fd2440a2ef797ed4d9c25a97 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sun, 20 Oct 2024 17:24:47 +0000 Subject: [PATCH 01/15] api: Simplify unsigned long long vars --- src/datum_api.c | 29 +++++++++++++++-------------- www/home.html | 4 ++-- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/datum_api.c b/src/datum_api.c index 646c6e3..7afaddf 100644 --- a/src/datum_api.c +++ b/src/datum_api.c @@ -76,12 +76,15 @@ static void html_leading_zeros(char * const buffer, const size_t buffer_size, co } } -void datum_api_var_DATUM_SHARES_ACCEPTED(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { - snprintf(buffer, buffer_size, "%llu (%llu diff)", (unsigned long long)datum_accepted_share_count, (unsigned long long)datum_accepted_share_diff); -} -void datum_api_var_DATUM_SHARES_REJECTED(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { - snprintf(buffer, buffer_size, "%llu (%llu diff)", (unsigned long long)datum_rejected_share_count, (unsigned long long)datum_rejected_share_diff); -} +#define MAKE_API_LLU(api_var, val) \ + static void datum_api_var_ ## api_var(char * const buffer, const size_t buffer_size, const T_DATUM_API_DASH_VARS * const vardata) { \ + snprintf(buffer, buffer_size, "%llu", (unsigned long long)(val)); \ + } \ +// end of MAKE_API_LLU +MAKE_API_LLU(DATUM_SHARES_ACCEPTED_ABSOLUTE, datum_accepted_share_count) +MAKE_API_LLU(DATUM_SHARES_ACCEPTED_WEIGHED, datum_accepted_share_diff) +MAKE_API_LLU(DATUM_SHARES_REJECTED_ABSOLUTE, datum_rejected_share_count) +MAKE_API_LLU(DATUM_SHARES_REJECTED_WEIGHED, datum_rejected_share_diff) 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; @@ -119,9 +122,7 @@ void datum_api_var_DATUM_MINER_TAG(char *buffer, size_t buffer_size, const T_DAT buffer[i+1] = '"'; buffer[i+2] = 0; } -void datum_api_var_DATUM_POOL_DIFF(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { - snprintf(buffer, buffer_size, "%llu", (unsigned long long)datum_config.override_vardiff_min); -} +MAKE_API_LLU(DATUM_POOL_DIFF, datum_config.override_vardiff_min) void datum_api_var_DATUM_POOL_PUBKEY(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { snprintf(buffer, buffer_size, "%s", datum_config.datum_pool_pubkey); } @@ -141,9 +142,7 @@ void datum_api_var_STRATUM_JOB_INFO(char *buffer, size_t buffer_size, const T_DA if (!vardata->sjob) return; snprintf(buffer, buffer_size, "%s (%d) @ %.3f", vardata->sjob->job_id, vardata->sjob->global_index, (double)vardata->sjob->tsms / 1000.0); } -void datum_api_var_STRATUM_JOB_BLOCK_HEIGHT(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { - snprintf(buffer, buffer_size, "%llu", (unsigned long long)vardata->sjob->block_template->height); -} +MAKE_API_LLU(STRATUM_JOB_BLOCK_HEIGHT, vardata->sjob->block_template->height) void datum_api_var_STRATUM_JOB_BLOCK_VALUE(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { snprintf(buffer, buffer_size, "%.8f BTC", (double)vardata->sjob->block_template->coinbasevalue / (double)100000000.0); } @@ -186,8 +185,10 @@ void datum_api_var_STRATUM_JOB_TXNCOUNT(char *buffer, size_t buffer_size, const DATUM_API_VarEntry var_entries[] = { - {"DATUM_SHARES_ACCEPTED", datum_api_var_DATUM_SHARES_ACCEPTED}, - {"DATUM_SHARES_REJECTED", datum_api_var_DATUM_SHARES_REJECTED}, + {"DATUM_SHARES_ACCEPTED_ABSOLUTE", datum_api_var_DATUM_SHARES_ACCEPTED_ABSOLUTE}, + {"DATUM_SHARES_ACCEPTED_WEIGHED", datum_api_var_DATUM_SHARES_ACCEPTED_WEIGHED}, + {"DATUM_SHARES_REJECTED_ABSOLUTE", datum_api_var_DATUM_SHARES_REJECTED_ABSOLUTE}, + {"DATUM_SHARES_REJECTED_WEIGHED", datum_api_var_DATUM_SHARES_REJECTED_WEIGHED}, {"DATUM_CONNECTION_STATUS", datum_api_var_DATUM_CONNECTION_STATUS}, {"DATUM_POOL_HOST", datum_api_var_DATUM_POOL_HOST}, {"DATUM_POOL_TAG", datum_api_var_DATUM_POOL_TAG}, diff --git a/www/home.html b/www/home.html index 93e0487..666f3b9 100644 --- a/www/home.html +++ b/www/home.html @@ -47,11 +47,11 @@

Decentralized Client Stats

- + - + From 0321773b0758ddc4ad83ad7fa09b42f6a9f52351 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sun, 20 Oct 2024 17:34:49 +0000 Subject: [PATCH 02/15] api: Simplify int, unsigned, unsigned long, and string vars --- src/datum_api.c | 51 ++++++++++++++++++++----------------------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/src/datum_api.c b/src/datum_api.c index 7afaddf..2201271 100644 --- a/src/datum_api.c +++ b/src/datum_api.c @@ -76,11 +76,22 @@ static void html_leading_zeros(char * const buffer, const size_t buffer_size, co } } +#define MAKE_API_D(api_var, val) \ + static void datum_api_var_ ## api_var(char * const buffer, const size_t buffer_size, const T_DATUM_API_DASH_VARS * const vardata) { \ + snprintf(buffer, buffer_size, "%d", (int)(val)); \ + } \ +// end of MAKE_API_D #define MAKE_API_LLU(api_var, val) \ static void datum_api_var_ ## api_var(char * const buffer, const size_t buffer_size, const T_DATUM_API_DASH_VARS * const vardata) { \ snprintf(buffer, buffer_size, "%llu", (unsigned long long)(val)); \ } \ // end of MAKE_API_LLU +#define MAKE_API_S(api_var, val) \ + static void datum_api_var_ ## api_var(char * const buffer, const size_t buffer_size, const T_DATUM_API_DASH_VARS * const vardata) { \ + snprintf(buffer, buffer_size, "%s", (val)); \ + } \ +// end of MAKE_API_S + MAKE_API_LLU(DATUM_SHARES_ACCEPTED_ABSOLUTE, datum_accepted_share_count) MAKE_API_LLU(DATUM_SHARES_ACCEPTED_WEIGHED, datum_accepted_share_diff) MAKE_API_LLU(DATUM_SHARES_REJECTED_ABSOLUTE, datum_rejected_share_count) @@ -123,18 +134,10 @@ void datum_api_var_DATUM_MINER_TAG(char *buffer, size_t buffer_size, const T_DAT buffer[i+2] = 0; } MAKE_API_LLU(DATUM_POOL_DIFF, datum_config.override_vardiff_min) -void datum_api_var_DATUM_POOL_PUBKEY(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { - snprintf(buffer, buffer_size, "%s", datum_config.datum_pool_pubkey); -} -void datum_api_var_STRATUM_ACTIVE_THREADS(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { - snprintf(buffer, buffer_size, "%d", vardata->STRATUM_ACTIVE_THREADS); -} -void datum_api_var_STRATUM_TOTAL_CONNECTIONS(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { - snprintf(buffer, buffer_size, "%d", vardata->STRATUM_TOTAL_CONNECTIONS); -} -void datum_api_var_STRATUM_TOTAL_SUBSCRIPTIONS(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { - snprintf(buffer, buffer_size, "%d", vardata->STRATUM_TOTAL_SUBSCRIPTIONS); -} +MAKE_API_S(DATUM_POOL_PUBKEY, datum_config.datum_pool_pubkey) +MAKE_API_D(STRATUM_ACTIVE_THREADS, vardata->STRATUM_ACTIVE_THREADS) +MAKE_API_D(STRATUM_TOTAL_CONNECTIONS, vardata->STRATUM_TOTAL_CONNECTIONS) +MAKE_API_D(STRATUM_TOTAL_SUBSCRIPTIONS, vardata->STRATUM_TOTAL_SUBSCRIPTIONS) void datum_api_var_STRATUM_HASHRATE_ESTIMATE(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { snprintf(buffer, buffer_size, "%.2f Th/sec", vardata->STRATUM_HASHRATE_ESTIMATE); } @@ -152,36 +155,24 @@ void datum_api_var_STRATUM_JOB_TARGET(char *buffer, size_t buffer_size, const T_ void datum_api_var_STRATUM_JOB_PREVBLOCK(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { html_leading_zeros(buffer, buffer_size, vardata->sjob->block_template->previousblockhash); } -void datum_api_var_STRATUM_JOB_WITNESS(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { - snprintf(buffer, buffer_size, "%s", vardata->sjob->block_template->default_witness_commitment); -} +MAKE_API_S(STRATUM_JOB_WITNESS, vardata->sjob->block_template->default_witness_commitment) void datum_api_var_STRATUM_JOB_DIFF(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { snprintf(buffer, buffer_size, "%.3Lf", calc_network_difficulty(vardata->sjob->nbits)); } void datum_api_var_STRATUM_JOB_VERSION(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { snprintf(buffer, buffer_size, "%s (%u)", vardata->sjob->version, (unsigned)vardata->sjob->version_uint); } -void datum_api_var_STRATUM_JOB_BITS(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { - snprintf(buffer, buffer_size, "%s", vardata->sjob->nbits); -} +MAKE_API_S(STRATUM_JOB_BITS, vardata->sjob->nbits) void datum_api_var_STRATUM_JOB_TIMEINFO(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { snprintf(buffer, buffer_size, "Current: %llu / Min: %llu", (unsigned long long)vardata->sjob->block_template->curtime, (unsigned long long)vardata->sjob->block_template->mintime); } void datum_api_var_STRATUM_JOB_LIMITINFO(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { snprintf(buffer, buffer_size, "Size: %lu, Weight: %lu, SigOps: %lu", (unsigned long)vardata->sjob->block_template->sizelimit, (unsigned long)vardata->sjob->block_template->weightlimit, (unsigned long)vardata->sjob->block_template->sigoplimit); } -void datum_api_var_STRATUM_JOB_SIZE(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { - snprintf(buffer, buffer_size, "%lu", (unsigned long)vardata->sjob->block_template->txn_total_size); -} -void datum_api_var_STRATUM_JOB_WEIGHT(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { - snprintf(buffer, buffer_size, "%lu", (unsigned long)vardata->sjob->block_template->txn_total_weight); -} -void datum_api_var_STRATUM_JOB_SIGOPS(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { - snprintf(buffer, buffer_size, "%lu", (unsigned long)vardata->sjob->block_template->txn_total_sigops); -} -void datum_api_var_STRATUM_JOB_TXNCOUNT(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { - snprintf(buffer, buffer_size, "%u", (unsigned)vardata->sjob->block_template->txn_count); -} +MAKE_API_LLU(STRATUM_JOB_SIZE, vardata->sjob->block_template->txn_total_size) +MAKE_API_LLU(STRATUM_JOB_WEIGHT, vardata->sjob->block_template->txn_total_weight) +MAKE_API_LLU(STRATUM_JOB_SIGOPS, vardata->sjob->block_template->txn_total_sigops) +MAKE_API_LLU(STRATUM_JOB_TXNCOUNT, vardata->sjob->block_template->txn_count) DATUM_API_VarEntry var_entries[] = { From fce3da5718120cb351f3ad841de63f0be9da10bc Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sun, 20 Oct 2024 17:44:37 +0000 Subject: [PATCH 03/15] api: Split DATUM_CONNECTION_STATUS into DATUM_CONNECTION_STATUS_INDICATOR_COLOUR and DATUM_CONNECTION_STATUS_DESCRIPTION --- src/datum_api.c | 23 +++++++++++++++-------- www/home.html | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/datum_api.c b/src/datum_api.c index 2201271..ee55157 100644 --- a/src/datum_api.c +++ b/src/datum_api.c @@ -96,21 +96,27 @@ MAKE_API_LLU(DATUM_SHARES_ACCEPTED_ABSOLUTE, datum_accepted_share_count) MAKE_API_LLU(DATUM_SHARES_ACCEPTED_WEIGHED, datum_accepted_share_diff) MAKE_API_LLU(DATUM_SHARES_REJECTED_ABSOLUTE, datum_rejected_share_count) MAKE_API_LLU(DATUM_SHARES_REJECTED_WEIGHED, datum_rejected_share_diff) -void datum_api_var_DATUM_CONNECTION_STATUS(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { - const char *colour = "lime"; +void datum_api_var_DATUM_CONNECTION_STATUS_INDICATOR_COLOUR(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { + const char *colour; + if (datum_protocol_is_active() || !datum_config.datum_pool_host[0]) { + colour = "lime"; + } else if (datum_config.datum_pooled_mining_only) { + colour = "red"; + } else { + colour = "yellow"; + } + snprintf(buffer, buffer_size, "%s", colour); +} +void datum_api_var_DATUM_CONNECTION_STATUS_DESCRIPTION(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { const char *s; if (datum_protocol_is_active()) { s = "Connected and Ready"; } else if (datum_config.datum_pooled_mining_only && datum_config.datum_pool_host[0]) { - colour = "red"; s = "Not Ready"; } else { - if (datum_config.datum_pool_host[0]) { - colour = "yellow"; - } s = "Non-Pooled Mode"; } - snprintf(buffer, buffer_size, " %s", colour, s); + snprintf(buffer, buffer_size, "%s", s); } 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]) { @@ -180,7 +186,8 @@ DATUM_API_VarEntry var_entries[] = { {"DATUM_SHARES_ACCEPTED_WEIGHED", datum_api_var_DATUM_SHARES_ACCEPTED_WEIGHED}, {"DATUM_SHARES_REJECTED_ABSOLUTE", datum_api_var_DATUM_SHARES_REJECTED_ABSOLUTE}, {"DATUM_SHARES_REJECTED_WEIGHED", datum_api_var_DATUM_SHARES_REJECTED_WEIGHED}, - {"DATUM_CONNECTION_STATUS", datum_api_var_DATUM_CONNECTION_STATUS}, + {"DATUM_CONNECTION_STATUS_INDICATOR_COLOUR", datum_api_var_DATUM_CONNECTION_STATUS_INDICATOR_COLOUR}, + {"DATUM_CONNECTION_STATUS_DESCRIPTION", datum_api_var_DATUM_CONNECTION_STATUS_DESCRIPTION}, {"DATUM_POOL_HOST", datum_api_var_DATUM_POOL_HOST}, {"DATUM_POOL_TAG", datum_api_var_DATUM_POOL_TAG}, {"DATUM_MINER_TAG", datum_api_var_DATUM_MINER_TAG}, diff --git a/www/home.html b/www/home.html index 666f3b9..4e94383 100644 --- a/www/home.html +++ b/www/home.html @@ -55,7 +55,7 @@

Decentralized Client Stats

- + From 031782e19412bcdfd5637c6012723ea267f08cbf Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sun, 20 Oct 2024 17:46:32 +0000 Subject: [PATCH 04/15] api: Rename DATUM_POOL_HOST to DATUM_POOL_HOST_NA and replace with null string alternative --- src/datum_api.c | 10 +++++++++- www/home.html | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/datum_api.c b/src/datum_api.c index ee55157..cb6bd9b 100644 --- a/src/datum_api.c +++ b/src/datum_api.c @@ -118,13 +118,20 @@ void datum_api_var_DATUM_CONNECTION_STATUS_DESCRIPTION(char *buffer, size_t buff } snprintf(buffer, buffer_size, "%s", s); } -void datum_api_var_DATUM_POOL_HOST(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { +void datum_api_var_DATUM_POOL_HOST_OR_NA(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { if (datum_config.datum_pool_host[0]) { snprintf(buffer, buffer_size, "%s:%u", datum_config.datum_pool_host, (unsigned)datum_config.datum_pool_port); } else { snprintf(buffer, buffer_size, "N/A"); } } +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]) { + snprintf(buffer, buffer_size, "%s:%u", datum_config.datum_pool_host, (unsigned)datum_config.datum_pool_port); + } else { + snprintf(buffer, buffer_size, ""); + } +} void datum_api_var_DATUM_POOL_TAG(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { size_t i; buffer[0] = '"'; @@ -188,6 +195,7 @@ DATUM_API_VarEntry var_entries[] = { {"DATUM_SHARES_REJECTED_WEIGHED", datum_api_var_DATUM_SHARES_REJECTED_WEIGHED}, {"DATUM_CONNECTION_STATUS_INDICATOR_COLOUR", datum_api_var_DATUM_CONNECTION_STATUS_INDICATOR_COLOUR}, {"DATUM_CONNECTION_STATUS_DESCRIPTION", datum_api_var_DATUM_CONNECTION_STATUS_DESCRIPTION}, + {"DATUM_POOL_HOST_OR_NA", datum_api_var_DATUM_POOL_HOST_OR_NA}, {"DATUM_POOL_HOST", datum_api_var_DATUM_POOL_HOST}, {"DATUM_POOL_TAG", datum_api_var_DATUM_POOL_TAG}, {"DATUM_MINER_TAG", datum_api_var_DATUM_MINER_TAG}, diff --git a/www/home.html b/www/home.html index 4e94383..0f74132 100644 --- a/www/home.html +++ b/www/home.html @@ -59,7 +59,7 @@

Decentralized Client Stats

- + From 29d0fc9a1f81a23d9b658884d9bb16f0098c415b Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sun, 20 Oct 2024 17:49:48 +0000 Subject: [PATCH 05/15] api: Rename DATUM_POOL/MINER_TAG to DATUM_POOL/MINER_TAG_FORMATTED and replace with raw alternatives --- src/datum_api.c | 8 ++++++-- www/home.html | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/datum_api.c b/src/datum_api.c index cb6bd9b..c5a32fd 100644 --- a/src/datum_api.c +++ b/src/datum_api.c @@ -132,20 +132,22 @@ void datum_api_var_DATUM_POOL_HOST(char *buffer, size_t buffer_size, const T_DAT snprintf(buffer, buffer_size, ""); } } -void datum_api_var_DATUM_POOL_TAG(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { +void datum_api_var_DATUM_POOL_TAG_FORMATTED(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { size_t i; buffer[0] = '"'; i = strncpy_html_escape(&buffer[1], datum_protocol_is_active()?datum_config.override_mining_coinbase_tag_primary:datum_config.mining_coinbase_tag_primary, buffer_size-3); buffer[i+1] = '"'; buffer[i+2] = 0; } -void datum_api_var_DATUM_MINER_TAG(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { +MAKE_API_S(DATUM_POOL_TAG, datum_protocol_is_active() ? datum_config.override_mining_coinbase_tag_primary : datum_config.mining_coinbase_tag_primary) +void datum_api_var_DATUM_MINER_TAG_FORMATTED(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { size_t i; buffer[0] = '"'; i = strncpy_html_escape(&buffer[1], datum_config.mining_coinbase_tag_secondary, buffer_size-3); buffer[i+1] = '"'; buffer[i+2] = 0; } +MAKE_API_S(DATUM_MINER_TAG, datum_config.mining_coinbase_tag_secondary) MAKE_API_LLU(DATUM_POOL_DIFF, datum_config.override_vardiff_min) MAKE_API_S(DATUM_POOL_PUBKEY, datum_config.datum_pool_pubkey) MAKE_API_D(STRATUM_ACTIVE_THREADS, vardata->STRATUM_ACTIVE_THREADS) @@ -197,7 +199,9 @@ DATUM_API_VarEntry var_entries[] = { {"DATUM_CONNECTION_STATUS_DESCRIPTION", datum_api_var_DATUM_CONNECTION_STATUS_DESCRIPTION}, {"DATUM_POOL_HOST_OR_NA", datum_api_var_DATUM_POOL_HOST_OR_NA}, {"DATUM_POOL_HOST", datum_api_var_DATUM_POOL_HOST}, + {"DATUM_POOL_TAG_FORMATTED", datum_api_var_DATUM_POOL_TAG_FORMATTED}, {"DATUM_POOL_TAG", datum_api_var_DATUM_POOL_TAG}, + {"DATUM_MINER_TAG_FORMATTED", datum_api_var_DATUM_MINER_TAG_FORMATTED}, {"DATUM_MINER_TAG", datum_api_var_DATUM_MINER_TAG}, {"DATUM_POOL_DIFF", datum_api_var_DATUM_POOL_DIFF}, {"DATUM_POOL_PUBKEY", datum_api_var_DATUM_POOL_PUBKEY}, diff --git a/www/home.html b/www/home.html index 0f74132..05b24a8 100644 --- a/www/home.html +++ b/www/home.html @@ -63,11 +63,11 @@

Decentralized Client Stats

- + - + From 61dfa72089c294cd75344bf9c69cdbb420b050e1 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sun, 20 Oct 2024 17:53:19 +0000 Subject: [PATCH 06/15] api: Rename STRATUM_HASHRATE_ESTIMATE to STRATUM_HASHRATE_ESTIMATE_FORMATTED and replace with raw alternative --- src/datum_api.c | 6 +++++- www/home.html | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/datum_api.c b/src/datum_api.c index c5a32fd..d624e86 100644 --- a/src/datum_api.c +++ b/src/datum_api.c @@ -153,9 +153,12 @@ MAKE_API_S(DATUM_POOL_PUBKEY, datum_config.datum_pool_pubkey) MAKE_API_D(STRATUM_ACTIVE_THREADS, vardata->STRATUM_ACTIVE_THREADS) MAKE_API_D(STRATUM_TOTAL_CONNECTIONS, vardata->STRATUM_TOTAL_CONNECTIONS) MAKE_API_D(STRATUM_TOTAL_SUBSCRIPTIONS, vardata->STRATUM_TOTAL_SUBSCRIPTIONS) -void datum_api_var_STRATUM_HASHRATE_ESTIMATE(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { +void datum_api_var_STRATUM_HASHRATE_ESTIMATE_FORMATTED(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { snprintf(buffer, buffer_size, "%.2f Th/sec", vardata->STRATUM_HASHRATE_ESTIMATE); } +void datum_api_var_STRATUM_HASHRATE_ESTIMATE(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { + snprintf(buffer, buffer_size, "%.0f", vardata->STRATUM_HASHRATE_ESTIMATE * 1e12); +} void datum_api_var_STRATUM_JOB_INFO(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { if (!vardata->sjob) return; snprintf(buffer, buffer_size, "%s (%d) @ %.3f", vardata->sjob->job_id, vardata->sjob->global_index, (double)vardata->sjob->tsms / 1000.0); @@ -209,6 +212,7 @@ DATUM_API_VarEntry var_entries[] = { {"STRATUM_ACTIVE_THREADS", datum_api_var_STRATUM_ACTIVE_THREADS}, {"STRATUM_TOTAL_CONNECTIONS", datum_api_var_STRATUM_TOTAL_CONNECTIONS}, {"STRATUM_TOTAL_SUBSCRIPTIONS", datum_api_var_STRATUM_TOTAL_SUBSCRIPTIONS}, + {"STRATUM_HASHRATE_ESTIMATE_FORMATTED", datum_api_var_STRATUM_HASHRATE_ESTIMATE_FORMATTED}, {"STRATUM_HASHRATE_ESTIMATE", datum_api_var_STRATUM_HASHRATE_ESTIMATE}, {"STRATUM_JOB_INFO", datum_api_var_STRATUM_JOB_INFO}, diff --git a/www/home.html b/www/home.html index 05b24a8..2a0cc9f 100644 --- a/www/home.html +++ b/www/home.html @@ -97,7 +97,7 @@

Stratum Server Info

- +
Shares Accepted:${DATUM_SHARES_ACCEPTED}${DATUM_SHARES_ACCEPTED_ABSOLUTE} (${DATUM_SHARES_ACCEPTED_WEIGHED} diff)
Shares Rejected:${DATUM_SHARES_REJECTED}${DATUM_SHARES_REJECTED_ABSOLUTE} (${DATUM_SHARES_REJECTED_WEIGHED} diff)
Status:
Status:${DATUM_CONNECTION_STATUS} ${DATUM_CONNECTION_STATUS_DESCRIPTION}
Pool Host:
Pool Host:${DATUM_POOL_HOST}${DATUM_POOL_HOST_OR_NA}
Pool Tag:
Pool Tag:${DATUM_POOL_TAG}${DATUM_POOL_TAG_FORMATTED}
Secondary/Miner Tag:${DATUM_MINER_TAG}${DATUM_MINER_TAG_FORMATTED}
Pool Current MinDiff:
Estimated Hashrate:${STRATUM_HASHRATE_ESTIMATE}${STRATUM_HASHRATE_ESTIMATE_FORMATTED}
From c9b355120fade402b0d0dfcb757fe3d641177832 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sun, 20 Oct 2024 17:59:47 +0000 Subject: [PATCH 07/15] api: Add vars for STRATUM_JOB_{ID,INDEX,TIMESTAMP} (split out of STRATUM_JOB_INFO) --- src/datum_api.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/datum_api.c b/src/datum_api.c index d624e86..f1e75f9 100644 --- a/src/datum_api.c +++ b/src/datum_api.c @@ -163,6 +163,12 @@ void datum_api_var_STRATUM_JOB_INFO(char *buffer, size_t buffer_size, const T_DA if (!vardata->sjob) return; snprintf(buffer, buffer_size, "%s (%d) @ %.3f", vardata->sjob->job_id, vardata->sjob->global_index, (double)vardata->sjob->tsms / 1000.0); } +MAKE_API_S(STRATUM_JOB_ID, vardata->sjob->job_id) +MAKE_API_D(STRATUM_JOB_INDEX, vardata->sjob->global_index) +void datum_api_var_STRATUM_JOB_TIMESTAMP(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { + if (!vardata->sjob) return; + snprintf(buffer, buffer_size, "%.3f", (double)vardata->sjob->tsms / 1000.0); +} MAKE_API_LLU(STRATUM_JOB_BLOCK_HEIGHT, vardata->sjob->block_template->height) void datum_api_var_STRATUM_JOB_BLOCK_VALUE(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { snprintf(buffer, buffer_size, "%.8f BTC", (double)vardata->sjob->block_template->coinbasevalue / (double)100000000.0); @@ -216,6 +222,9 @@ DATUM_API_VarEntry var_entries[] = { {"STRATUM_HASHRATE_ESTIMATE", datum_api_var_STRATUM_HASHRATE_ESTIMATE}, {"STRATUM_JOB_INFO", datum_api_var_STRATUM_JOB_INFO}, + {"STRATUM_JOB_ID", datum_api_var_STRATUM_JOB_ID}, + {"STRATUM_JOB_INDEX", datum_api_var_STRATUM_JOB_INDEX}, + {"STRATUM_JOB_TIMESTAMP", datum_api_var_STRATUM_JOB_TIMESTAMP}, {"STRATUM_JOB_BLOCK_HEIGHT", datum_api_var_STRATUM_JOB_BLOCK_HEIGHT}, {"STRATUM_JOB_BLOCK_VALUE", datum_api_var_STRATUM_JOB_BLOCK_VALUE}, {"STRATUM_JOB_PREVBLOCK", datum_api_var_STRATUM_JOB_PREVBLOCK}, From 59f4508d44d7489753ef7adc4e99b21ee3f06126 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sun, 20 Oct 2024 18:01:19 +0000 Subject: [PATCH 08/15] api: Rename STRATUM_JOB_BLOCK_VALUE to STRATUM_JOB_BLOCK_VALUE_FORMATTED and replace with raw alternative --- src/datum_api.c | 4 +++- www/home.html | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/datum_api.c b/src/datum_api.c index f1e75f9..c78e5ee 100644 --- a/src/datum_api.c +++ b/src/datum_api.c @@ -170,9 +170,10 @@ void datum_api_var_STRATUM_JOB_TIMESTAMP(char *buffer, size_t buffer_size, const snprintf(buffer, buffer_size, "%.3f", (double)vardata->sjob->tsms / 1000.0); } MAKE_API_LLU(STRATUM_JOB_BLOCK_HEIGHT, vardata->sjob->block_template->height) -void datum_api_var_STRATUM_JOB_BLOCK_VALUE(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { +void datum_api_var_STRATUM_JOB_BLOCK_VALUE_FORMATTED(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { snprintf(buffer, buffer_size, "%.8f BTC", (double)vardata->sjob->block_template->coinbasevalue / (double)100000000.0); } +MAKE_API_LLU(STRATUM_JOB_BLOCK_VALUE, vardata->sjob->block_template->coinbasevalue) void datum_api_var_STRATUM_JOB_TARGET(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { html_leading_zeros(buffer, buffer_size, vardata->sjob->block_template->block_target_hex); } @@ -226,6 +227,7 @@ DATUM_API_VarEntry var_entries[] = { {"STRATUM_JOB_INDEX", datum_api_var_STRATUM_JOB_INDEX}, {"STRATUM_JOB_TIMESTAMP", datum_api_var_STRATUM_JOB_TIMESTAMP}, {"STRATUM_JOB_BLOCK_HEIGHT", datum_api_var_STRATUM_JOB_BLOCK_HEIGHT}, + {"STRATUM_JOB_BLOCK_VALUE_FORMATTED", datum_api_var_STRATUM_JOB_BLOCK_VALUE_FORMATTED}, {"STRATUM_JOB_BLOCK_VALUE", datum_api_var_STRATUM_JOB_BLOCK_VALUE}, {"STRATUM_JOB_PREVBLOCK", datum_api_var_STRATUM_JOB_PREVBLOCK}, {"STRATUM_JOB_TARGET", datum_api_var_STRATUM_JOB_TARGET}, diff --git a/www/home.html b/www/home.html index 2a0cc9f..41cd701 100644 --- a/www/home.html +++ b/www/home.html @@ -116,7 +116,7 @@

Current Stratum Job

Block Value: - ${STRATUM_JOB_BLOCK_VALUE} + ${STRATUM_JOB_BLOCK_VALUE_FORMATTED} Previous Block: From 8f71bf043a04c8ba14121321d40a2026a31c470a Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sun, 20 Oct 2024 18:04:40 +0000 Subject: [PATCH 09/15] api: Rename STRATUM_JOB_PREVBLOCK/TARGET to STRATUM_JOB_PREVBLOCK/TARGET_FORMATTED and replace with raw alternatives --- src/datum_api.c | 8 ++++++-- www/home.html | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/datum_api.c b/src/datum_api.c index c78e5ee..64ddf3d 100644 --- a/src/datum_api.c +++ b/src/datum_api.c @@ -174,12 +174,14 @@ void datum_api_var_STRATUM_JOB_BLOCK_VALUE_FORMATTED(char *buffer, size_t buffer snprintf(buffer, buffer_size, "%.8f BTC", (double)vardata->sjob->block_template->coinbasevalue / (double)100000000.0); } MAKE_API_LLU(STRATUM_JOB_BLOCK_VALUE, vardata->sjob->block_template->coinbasevalue) -void datum_api_var_STRATUM_JOB_TARGET(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { +void datum_api_var_STRATUM_JOB_TARGET_FORMATTED(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { html_leading_zeros(buffer, buffer_size, vardata->sjob->block_template->block_target_hex); } -void datum_api_var_STRATUM_JOB_PREVBLOCK(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { +MAKE_API_S(STRATUM_JOB_TARGET, vardata->sjob->block_template->block_target_hex) +void datum_api_var_STRATUM_JOB_PREVBLOCK_FORMATTED(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { html_leading_zeros(buffer, buffer_size, vardata->sjob->block_template->previousblockhash); } +MAKE_API_S(STRATUM_JOB_PREVBLOCK, vardata->sjob->block_template->previousblockhash) MAKE_API_S(STRATUM_JOB_WITNESS, vardata->sjob->block_template->default_witness_commitment) void datum_api_var_STRATUM_JOB_DIFF(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { snprintf(buffer, buffer_size, "%.3Lf", calc_network_difficulty(vardata->sjob->nbits)); @@ -229,7 +231,9 @@ DATUM_API_VarEntry var_entries[] = { {"STRATUM_JOB_BLOCK_HEIGHT", datum_api_var_STRATUM_JOB_BLOCK_HEIGHT}, {"STRATUM_JOB_BLOCK_VALUE_FORMATTED", datum_api_var_STRATUM_JOB_BLOCK_VALUE_FORMATTED}, {"STRATUM_JOB_BLOCK_VALUE", datum_api_var_STRATUM_JOB_BLOCK_VALUE}, + {"STRATUM_JOB_PREVBLOCK_FORMATTED", datum_api_var_STRATUM_JOB_PREVBLOCK_FORMATTED}, {"STRATUM_JOB_PREVBLOCK", datum_api_var_STRATUM_JOB_PREVBLOCK}, + {"STRATUM_JOB_TARGET_FORMATTED", datum_api_var_STRATUM_JOB_TARGET_FORMATTED}, {"STRATUM_JOB_TARGET", datum_api_var_STRATUM_JOB_TARGET}, {"STRATUM_JOB_WITNESS", datum_api_var_STRATUM_JOB_WITNESS}, {"STRATUM_JOB_DIFF", datum_api_var_STRATUM_JOB_DIFF}, diff --git a/www/home.html b/www/home.html index 41cd701..ca0b5e9 100644 --- a/www/home.html +++ b/www/home.html @@ -120,11 +120,11 @@

Current Stratum Job

Previous Block: - ${STRATUM_JOB_PREVBLOCK} + ${STRATUM_JOB_PREVBLOCK_FORMATTED} Block Target: - ${STRATUM_JOB_TARGET} + ${STRATUM_JOB_TARGET_FORMATTED} Witness Commitment: From 6b568831b6306069b53ee3e4ce6ef11dcc4a0621 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sun, 20 Oct 2024 18:09:07 +0000 Subject: [PATCH 10/15] api: Split STRATUM_JOB_VERSION into STRATUM_JOB_VERSION and STRATUM_JOB_VERSION_HEX --- src/datum_api.c | 6 +++--- www/home.html | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/datum_api.c b/src/datum_api.c index 64ddf3d..3336cd8 100644 --- a/src/datum_api.c +++ b/src/datum_api.c @@ -186,9 +186,8 @@ MAKE_API_S(STRATUM_JOB_WITNESS, vardata->sjob->block_template->default_witness_c void datum_api_var_STRATUM_JOB_DIFF(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { snprintf(buffer, buffer_size, "%.3Lf", calc_network_difficulty(vardata->sjob->nbits)); } -void datum_api_var_STRATUM_JOB_VERSION(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { - snprintf(buffer, buffer_size, "%s (%u)", vardata->sjob->version, (unsigned)vardata->sjob->version_uint); -} +MAKE_API_S(STRATUM_JOB_VERSION_HEX, vardata->sjob->version) +MAKE_API_LLU(STRATUM_JOB_VERSION, vardata->sjob->version_uint) MAKE_API_S(STRATUM_JOB_BITS, vardata->sjob->nbits) void datum_api_var_STRATUM_JOB_TIMEINFO(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { snprintf(buffer, buffer_size, "Current: %llu / Min: %llu", (unsigned long long)vardata->sjob->block_template->curtime, (unsigned long long)vardata->sjob->block_template->mintime); @@ -238,6 +237,7 @@ DATUM_API_VarEntry var_entries[] = { {"STRATUM_JOB_WITNESS", datum_api_var_STRATUM_JOB_WITNESS}, {"STRATUM_JOB_DIFF", datum_api_var_STRATUM_JOB_DIFF}, {"STRATUM_JOB_VERSION", datum_api_var_STRATUM_JOB_VERSION}, + {"STRATUM_JOB_VERSION_HEX", datum_api_var_STRATUM_JOB_VERSION_HEX}, {"STRATUM_JOB_BITS", datum_api_var_STRATUM_JOB_BITS}, {"STRATUM_JOB_TIMEINFO", datum_api_var_STRATUM_JOB_TIMEINFO}, {"STRATUM_JOB_LIMITINFO", datum_api_var_STRATUM_JOB_LIMITINFO}, diff --git a/www/home.html b/www/home.html index ca0b5e9..b9cab18 100644 --- a/www/home.html +++ b/www/home.html @@ -136,7 +136,7 @@

Current Stratum Job

Version: - ${STRATUM_JOB_VERSION} + ${STRATUM_JOB_VERSION_HEX} (${STRATUM_JOB_VERSION}) Bits: From ca365becc32306cb7119203928eeee068c751c4d Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sun, 20 Oct 2024 18:11:16 +0000 Subject: [PATCH 11/15] api: Split STRATUM_JOB_TIMEINFO into STRATUM_JOB_CURTIME and STRATUM_JOB_MINTIME --- src/datum_api.c | 8 ++++---- www/home.html | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/datum_api.c b/src/datum_api.c index 3336cd8..5ef2f55 100644 --- a/src/datum_api.c +++ b/src/datum_api.c @@ -189,9 +189,8 @@ void datum_api_var_STRATUM_JOB_DIFF(char *buffer, size_t buffer_size, const T_DA MAKE_API_S(STRATUM_JOB_VERSION_HEX, vardata->sjob->version) MAKE_API_LLU(STRATUM_JOB_VERSION, vardata->sjob->version_uint) MAKE_API_S(STRATUM_JOB_BITS, vardata->sjob->nbits) -void datum_api_var_STRATUM_JOB_TIMEINFO(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { - snprintf(buffer, buffer_size, "Current: %llu / Min: %llu", (unsigned long long)vardata->sjob->block_template->curtime, (unsigned long long)vardata->sjob->block_template->mintime); -} +MAKE_API_LLU(STRATUM_JOB_CURTIME, vardata->sjob->block_template->curtime) +MAKE_API_LLU(STRATUM_JOB_MINTIME, vardata->sjob->block_template->mintime) void datum_api_var_STRATUM_JOB_LIMITINFO(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { snprintf(buffer, buffer_size, "Size: %lu, Weight: %lu, SigOps: %lu", (unsigned long)vardata->sjob->block_template->sizelimit, (unsigned long)vardata->sjob->block_template->weightlimit, (unsigned long)vardata->sjob->block_template->sigoplimit); } @@ -239,7 +238,8 @@ DATUM_API_VarEntry var_entries[] = { {"STRATUM_JOB_VERSION", datum_api_var_STRATUM_JOB_VERSION}, {"STRATUM_JOB_VERSION_HEX", datum_api_var_STRATUM_JOB_VERSION_HEX}, {"STRATUM_JOB_BITS", datum_api_var_STRATUM_JOB_BITS}, - {"STRATUM_JOB_TIMEINFO", datum_api_var_STRATUM_JOB_TIMEINFO}, + {"STRATUM_JOB_CURTIME", datum_api_var_STRATUM_JOB_CURTIME}, + {"STRATUM_JOB_MINTIME", datum_api_var_STRATUM_JOB_MINTIME}, {"STRATUM_JOB_LIMITINFO", datum_api_var_STRATUM_JOB_LIMITINFO}, {"STRATUM_JOB_SIZE", datum_api_var_STRATUM_JOB_SIZE}, {"STRATUM_JOB_WEIGHT", datum_api_var_STRATUM_JOB_WEIGHT}, diff --git a/www/home.html b/www/home.html index b9cab18..303c096 100644 --- a/www/home.html +++ b/www/home.html @@ -144,7 +144,7 @@

Current Stratum Job

Time: - ${STRATUM_JOB_TIMEINFO} + Current: ${STRATUM_JOB_CURTIME} / Min: ${STRATUM_JOB_MINTIME} Limits: From 38ec98d11edaa20e62c32cb976ee4d2dc557a9d6 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sun, 20 Oct 2024 18:13:55 +0000 Subject: [PATCH 12/15] api: Split STRATUM_JOB_LIMITINFO into STRATUM_JOB_SIZE_LIMIT, STRATUM_JOB_WEIGHT_LIMIT and STRATUM_JOB_SIGOP_LIMIT --- src/datum_api.c | 10 ++++++---- www/home.html | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/datum_api.c b/src/datum_api.c index 5ef2f55..8968ce5 100644 --- a/src/datum_api.c +++ b/src/datum_api.c @@ -191,9 +191,9 @@ MAKE_API_LLU(STRATUM_JOB_VERSION, vardata->sjob->version_uint) MAKE_API_S(STRATUM_JOB_BITS, vardata->sjob->nbits) MAKE_API_LLU(STRATUM_JOB_CURTIME, vardata->sjob->block_template->curtime) MAKE_API_LLU(STRATUM_JOB_MINTIME, vardata->sjob->block_template->mintime) -void datum_api_var_STRATUM_JOB_LIMITINFO(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { - snprintf(buffer, buffer_size, "Size: %lu, Weight: %lu, SigOps: %lu", (unsigned long)vardata->sjob->block_template->sizelimit, (unsigned long)vardata->sjob->block_template->weightlimit, (unsigned long)vardata->sjob->block_template->sigoplimit); -} +MAKE_API_LLU(STRATUM_JOB_SIZE_LIMIT, vardata->sjob->block_template->sizelimit) +MAKE_API_LLU(STRATUM_JOB_WEIGHT_LIMIT, vardata->sjob->block_template->weightlimit) +MAKE_API_LLU(STRATUM_JOB_SIGOP_LIMIT, vardata->sjob->block_template->sigoplimit) MAKE_API_LLU(STRATUM_JOB_SIZE, vardata->sjob->block_template->txn_total_size) MAKE_API_LLU(STRATUM_JOB_WEIGHT, vardata->sjob->block_template->txn_total_weight) MAKE_API_LLU(STRATUM_JOB_SIGOPS, vardata->sjob->block_template->txn_total_sigops) @@ -240,7 +240,9 @@ DATUM_API_VarEntry var_entries[] = { {"STRATUM_JOB_BITS", datum_api_var_STRATUM_JOB_BITS}, {"STRATUM_JOB_CURTIME", datum_api_var_STRATUM_JOB_CURTIME}, {"STRATUM_JOB_MINTIME", datum_api_var_STRATUM_JOB_MINTIME}, - {"STRATUM_JOB_LIMITINFO", datum_api_var_STRATUM_JOB_LIMITINFO}, + {"STRATUM_JOB_SIZE_LIMIT", datum_api_var_STRATUM_JOB_SIZE_LIMIT}, + {"STRATUM_JOB_WEIGHT_LIMIT", datum_api_var_STRATUM_JOB_WEIGHT_LIMIT}, + {"STRATUM_JOB_SIGOP_LIMIT", datum_api_var_STRATUM_JOB_SIGOP_LIMIT}, {"STRATUM_JOB_SIZE", datum_api_var_STRATUM_JOB_SIZE}, {"STRATUM_JOB_WEIGHT", datum_api_var_STRATUM_JOB_WEIGHT}, {"STRATUM_JOB_SIGOPS", datum_api_var_STRATUM_JOB_SIGOPS}, diff --git a/www/home.html b/www/home.html index 303c096..b6fe316 100644 --- a/www/home.html +++ b/www/home.html @@ -148,7 +148,7 @@

Current Stratum Job

Limits: - ${STRATUM_JOB_LIMITINFO} + Size: ${STRATUM_JOB_SIZE_LIMIT}, Weight: ${STRATUM_JOB_WEIGHT_LIMIT}, SigOps: ${STRATUM_JOB_SIGOP_LIMIT} Size: From 51a24058a97f371f00b4b96b224fd0b6b7eb6770 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sun, 20 Oct 2024 18:24:46 +0000 Subject: [PATCH 13/15] api: Avoid running STRATUM_JOB_* variables if there's no stratum job set --- src/datum_api.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/datum_api.c b/src/datum_api.c index 8968ce5..6dc74ec 100644 --- a/src/datum_api.c +++ b/src/datum_api.c @@ -160,13 +160,11 @@ void datum_api_var_STRATUM_HASHRATE_ESTIMATE(char *buffer, size_t buffer_size, c snprintf(buffer, buffer_size, "%.0f", vardata->STRATUM_HASHRATE_ESTIMATE * 1e12); } void datum_api_var_STRATUM_JOB_INFO(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { - if (!vardata->sjob) return; snprintf(buffer, buffer_size, "%s (%d) @ %.3f", vardata->sjob->job_id, vardata->sjob->global_index, (double)vardata->sjob->tsms / 1000.0); } MAKE_API_S(STRATUM_JOB_ID, vardata->sjob->job_id) MAKE_API_D(STRATUM_JOB_INDEX, vardata->sjob->global_index) void datum_api_var_STRATUM_JOB_TIMESTAMP(char *buffer, size_t buffer_size, const T_DATUM_API_DASH_VARS *vardata) { - if (!vardata->sjob) return; snprintf(buffer, buffer_size, "%.3f", (double)vardata->sjob->tsms / 1000.0); } MAKE_API_LLU(STRATUM_JOB_BLOCK_HEIGHT, vardata->sjob->block_template->height) @@ -299,7 +297,10 @@ void datum_api_fill_vars(const char *input, char *output, size_t max_output_size DATUM_API_VarFunc func = datum_api_find_var_func(var_name); if (func) { replacement[0] = 0; - func(replacement, sizeof(replacement), vardata); + // Skip running STRATUM_JOB functions if there's no sjob + if (var_name[8] != 'J' || vardata->sjob) { + func(replacement, sizeof(replacement), vardata); + } replacement_len = strlen(replacement); if (replacement_len) { to_copy = (replacement_len < max_output_size - output_len - 1) ? replacement_len : max_output_size - output_len - 1; From 1e7bb33d86a3338fc0a6b66653e5b7ebc17521c1 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sun, 20 Oct 2024 18:43:07 +0000 Subject: [PATCH 14/15] api: Create /v1/VAR endpoint to get the value of any var --- src/datum_api.c | 73 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/src/datum_api.c b/src/datum_api.c index 6dc74ec..770dfc0 100644 --- a/src/datum_api.c +++ b/src/datum_api.c @@ -56,6 +56,7 @@ const char * const homepage_html_end = ""; #define DATUM_API_HOMEPAGE_MAX_SIZE 128000 +#define DATUM_API_VAR_MAX_SIZE 128 const char *cbnames[] = { "Blank", @@ -690,24 +691,21 @@ int datum_api_client_dashboard(struct MHD_Connection *connection) { return ret; } -int datum_api_homepage(struct MHD_Connection *connection) { - struct MHD_Response *response; - char output[DATUM_API_HOMEPAGE_MAX_SIZE]; - int j, k = 0, kk = 0, ii, ret; +static void datum_api_prepare_vardata(T_DATUM_API_DASH_VARS * const vardata) { + int j, k = 0, kk = 0, ii; T_DATUM_MINER_DATA *m; - T_DATUM_API_DASH_VARS vardata; unsigned char astat; double thr = 0.0; double hr; uint64_t tsms; - memset(&vardata, 0, sizeof(T_DATUM_API_DASH_VARS)); - + memset(vardata, 0, sizeof(T_DATUM_API_DASH_VARS)); + pthread_rwlock_rdlock(&stratum_global_job_ptr_lock); j = global_latest_stratum_job_index; - vardata.sjob = (j >= 0 && j < MAX_STRATUM_JOBS) ? global_cur_stratum_jobs[j] : NULL; + vardata->sjob = (j >= 0 && j < MAX_STRATUM_JOBS) ? global_cur_stratum_jobs[j] : NULL; pthread_rwlock_unlock(&stratum_global_job_ptr_lock); - + tsms = current_time_millis(); if (global_stratum_app) { @@ -732,16 +730,25 @@ int datum_api_homepage(struct MHD_Connection *connection) { } } } - vardata.STRATUM_ACTIVE_THREADS = global_stratum_app->datum_active_threads; - vardata.STRATUM_TOTAL_CONNECTIONS = k; - vardata.STRATUM_TOTAL_SUBSCRIPTIONS = kk; - vardata.STRATUM_HASHRATE_ESTIMATE = thr; + vardata->STRATUM_ACTIVE_THREADS = global_stratum_app->datum_active_threads; + vardata->STRATUM_TOTAL_CONNECTIONS = k; + vardata->STRATUM_TOTAL_SUBSCRIPTIONS = kk; + vardata->STRATUM_HASHRATE_ESTIMATE = thr; } else { - vardata.STRATUM_ACTIVE_THREADS = 0; - vardata.STRATUM_TOTAL_CONNECTIONS = 0; - vardata.STRATUM_TOTAL_SUBSCRIPTIONS = 0; - vardata.STRATUM_HASHRATE_ESTIMATE = 0.0; + vardata->STRATUM_ACTIVE_THREADS = 0; + vardata->STRATUM_TOTAL_CONNECTIONS = 0; + vardata->STRATUM_TOTAL_SUBSCRIPTIONS = 0; + vardata->STRATUM_HASHRATE_ESTIMATE = 0.0; } +} + +int datum_api_homepage(struct MHD_Connection *connection) { + struct MHD_Response *response; + char output[DATUM_API_HOMEPAGE_MAX_SIZE]; + int ret; + T_DATUM_API_DASH_VARS vardata; + + datum_api_prepare_vardata(&vardata); output[0] = 0; datum_api_fill_vars(www_home_html, output, DATUM_API_HOMEPAGE_MAX_SIZE, &vardata); @@ -946,6 +953,38 @@ enum MHD_Result datum_api_answer(void *cls, struct MHD_Connection *connection, c break; } + case 'v': { + if (!strncmp(url, "/v1/", 4)) { + const char * const var_name = &url[4]; + DATUM_API_VarFunc func = datum_api_find_var_func(var_name); + if (!func) break; + + T_DATUM_API_DASH_VARS vardata; + datum_api_prepare_vardata(&vardata); + + // Skip running STRATUM_JOB functions if there's no sjob + if (var_name[8] == 'J' && !vardata.sjob) { + response = MHD_create_response_from_buffer(0, "", MHD_RESPMEM_PERSISTENT); + http_resp_prevent_caching(response); + ret = MHD_queue_response(connection, MHD_HTTP_NO_CONTENT, response); + MHD_destroy_response(response); + return ret; + } + + char val[DATUM_API_VAR_MAX_SIZE]; + val[0] = 0; + func(val, sizeof(val), &vardata); + + response = MHD_create_response_from_buffer (strlen(val), val, MHD_RESPMEM_MUST_COPY); + MHD_add_response_header(response, "Content-Type", "text/plain"); + http_resp_prevent_caching(response); + ret = MHD_queue_response(connection, MHD_HTTP_OK, response); + MHD_destroy_response(response); + return ret; + } + break; + } + default: break; } From 13b2d5dc5c637bfa9f5e2a77cc8e6087b98b1e28 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Sun, 20 Oct 2024 18:51:53 +0000 Subject: [PATCH 15/15] api: Accept mixed case API v1 requests --- src/datum_api.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/datum_api.c b/src/datum_api.c index 770dfc0..5ee9ded 100644 --- a/src/datum_api.c +++ b/src/datum_api.c @@ -35,6 +35,7 @@ // This is quick and dirty for now. Will be improved over time. +#include #include #include #include @@ -955,7 +956,12 @@ enum MHD_Result datum_api_answer(void *cls, struct MHD_Connection *connection, c case 'v': { if (!strncmp(url, "/v1/", 4)) { - const char * const var_name = &url[4]; + if (strlen(&url[3]) > DATUM_API_VAR_MAX_SIZE) break; + char var_name[DATUM_API_VAR_MAX_SIZE]; + for (size_t i = 0; ; ++i) { + var_name[i] = toupper(url[4 + i]); + if (!var_name[i]) break; + } DATUM_API_VarFunc func = datum_api_find_var_func(var_name); if (!func) break;