Skip to content

Fix: read what the workers actually write on the finance data path - #202

Merged
paragmore merged 2 commits into
tetherto:developfrom
mukama:fix/cross-worker-timestamp-parsing
Aug 27, 2026
Merged

Fix: read what the workers actually write on the finance data path#202
paragmore merged 2 commits into
tetherto:developfrom
mukama:fix/cross-worker-timestamp-parsing

Conversation

@mukama

@mukama mukama commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Fixes four defects where the finance handlers disagreed with what the workers actually write, each of which failed silently rather than erroring.

Ocean revenue was being dropped entirely. Ocean stamps pool earnings with an ISO-8601 string ("2026-05-28T16:46:30"); normalizeTimestampMs returned it unchanged, getStartOfDay turned it into NaN, and the if (!ts) continue guard skipped every record. Replaying the live dev-moria minerpool payload through processTransactions:

before   days with revenue: 55   revenueBTC: 0.00550000   feesBTC: 0.00005500
after    days with revenue: 74   revenueBTC: 5.74481918   feesBTC: 0.05875102

Numeric strings failed the same way, ISO strings are now pinned to UTC rather than read as host-local, and processDailyRevenueBtc no longer coerces with Number() before normalizing.

getEbitda and getHashRevenue asked the mempool worker for key 'prices' — the one field its fallback reply destructures away (const { prices, ...apiData } = this.mempoolData). Both silently fell back to the current spot price, valuing every historical day at today's rate on /auth/finance/ebitda and /auth/finance/hash-revenue. The other four call sites already used HISTORICAL_PRICES.

Monthly and yearly buckets were grouped in host-local time over UTC day timestamps, so west of UTC a day's revenue could land in the previous month. The weekly branch was already UTC. Same fix for the production-cost month key, duplicated at four sites, which priced a UTC first-of-month against the previous month's costs and pinned LCOE.

energy-balance meanKeys omitted powerW, energyRevenuePerMWh and allInCostPerMWh, so a monthly bucket reported 62 MW and 2 MW for the same site in one object. revenue-summary already lists these.

Note: npm run test:unit has a pre-existing failure on develop (getEbitda - a monthly LCOE override only moves its own month) whose unhandled rejection aborts the run; confirmed present before these changes, unrelated to them. finance.utils and period.utils suites are green, and finance.handlers passes the same 85 assertions as develop up to that abort.

mukama added 2 commits August 26, 2026 23:17
…the record

Ocean stamps pool earnings with an ISO-8601 string, which normalizeTimestampMs
returned unchanged, turning into NaN in getStartOfDay so every earning was
silently skipped. Numeric strings failed the same way. ISO strings carry no
timezone designator and are treated as UTC rather than host-local, and
processDailyRevenueBtc no longer coerces with Number() before normalizing.
Three defects on the same finance data contract:

- getEbitda and getHashRevenue asked the mempool worker for key 'prices',
  which is the one field its fallback reply destructures away. Both fell back
  to the current spot price, valuing every historical day at today's rate. The
  other four call sites already used HISTORICAL_PRICES.
- aggregateByPeriod grouped and stamped monthly/yearly buckets with local-time
  getters over UTC day timestamps, so west of UTC a day's revenue could land in
  the previous month. The weekly branch was already UTC.
- The production-cost month key was derived with local getters at four sites,
  pricing a UTC first-of-month against the previous month's costs and LCOE.

Also adds powerW, energyRevenuePerMWh and allInCostPerMWh to the energy-balance
meanKeys, so rate columns are averaged over a period rather than summed, as
revenue-summary already does.
@paragmore
paragmore merged commit 8808d8d into tetherto:develop Aug 27, 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