Skip to content

fix: finance v2 handler RPC regressions#67

Merged
tekwani merged 4 commits intotetherto:developfrom
mukama:fix/finance-v2-handlers
Apr 28, 2026
Merged

fix: finance v2 handler RPC regressions#67
tekwani merged 4 commits intotetherto:developfrom
mukama:fix/finance-v2-handlers

Conversation

@mukama
Copy link
Copy Markdown
Contributor

@mukama mukama commented Apr 28, 2026

  • Bug A processTailLogData now drills into .val for nested TAIL_LOG_RANGE_AGGR items; RevenueSummary's Avg Power / Avg Hashrate / Capacity Factor populate.
  • Bug B same .val fix in processHashrateData; flat-shape detection in processNetworkHashrateData; HashBalance populates.
  • Bug C processBlockData parses the flat HISTORICAL_BLOCKSIZES shape; blockSize plumbed through for the Sats/vByte chart; SubsidyFee renders.
  • Bug D wrong RPC key ('prices''HISTORICAL_PRICES'); processEbitdaPrices handles the flat shape and priceUSD field; cost-summary returns real per-day btcPrice.

89/89 unit tests pass; lint clean. All four fixes smoke-verified end-to-end against dev-moria.tether.to.

mukama added 4 commits April 28, 2026 13:55
The mempool worker's getWrkExtData returns a flat array of block records
[{ts, blockSize, blockReward, blockTotalFees}, ...], but processBlockData
only handled nested .data/.blocks wrappers - it iterated entry's own field
names, Number('ts') returned NaN, and produced an empty daily map. The
SubsidyFee page then rendered "No data available".

Detect the flat shape (entry has .ts/.timestamp/.time) and process it
directly. Also surface blockSize on getSubsidyFees and getRevenueSummary
log entries (and totalBlockSize/avgBlockSize on the summary) - needed for
SubsidyFee's "Avg Fees in Sats/vByte" chart to render after this fix.
Two compounding bugs in getCostSummary caused btcPrice=0 for every log
entry, leaving ProductionCostPriceChart's overlay line at 0:

1. Wrong RPC key. The handler queried mempool with key: 'prices', which
   the worker doesn't recognize and so returns the live snapshot
   ({currentPrice, blockHeight, ...}). Switched to 'HISTORICAL_PRICES',
   which returns [{ts, priceUSD}, ...].

2. processEbitdaPrices couldn't parse the production shape. Same class
   as the processBlockData fix (Bug C): the mempool worker returns a flat
   per-ORK array of records, not a wrapper. Detect when entry has
   .ts/.timestamp/.time and process it as the item directly; also accept
   priceUSD (the actual upstream field name) alongside price.

The processEbitdaPrices fix incidentally makes getRevenueSummary and
getHashRevenue use real per-day prices instead of falling back to
currentBtcPrice. getEbitda still uses the wrong key: 'prices' (line 344)
and is left for a follow-up.
The TAIL_LOG_RANGE_AGGR RPC returns per-day items as
{ts, val: {site_power_w, hashrate_mhs_5m_sum_aggr}}, but
processTailLogData read item[AGGR_FIELDS.SITE_POWER] directly without
drilling into .val, so powerW and hashrateMhs were 0 for every entry.
RevenueSummary then showed 0 for Avg Power, Avg Hashrate, and Hashrate
Capacity Factor; EBITDA's per-day power/hashrate were similarly zeroed.

Mirror the .val/.flat fallback pattern that processConsumptionData
already uses (workers/lib/server/handlers/finance.handlers.js:172).
Two bugs in getHashRevenue caused hashrateMhs and networkHashrateMhs
to be 0 for every log entry, leaving HashBalance entirely zeroed:

1. processHashrateData read item[AGGR_FIELDS.HASHRATE_SUM] directly,
   but TAIL_LOG_RANGE_AGGR wraps measurements as
   {ts, val: {hashrate_mhs_5m_sum_aggr}}. Same .val drilling fix as
   processTailLogData.

2. processNetworkHashrateData expected entries wrapped under .data,
   but the HISTORICAL_HASHRATE RPC returns a flat per-ORK array of
   {ts, avgHashrateMHs} records. Same flat-shape detection as
   processBlockData (Bug C).
@mukama mukama force-pushed the fix/finance-v2-handlers branch from 4db6753 to d130147 Compare April 28, 2026 10:55
@tekwani tekwani merged commit b48c8e0 into tetherto:develop Apr 28, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants