Repository navigation
fix(provider-rewards): delta formula parity + remove misleading estimates - #31
Merged
Merged
Conversation
Delta's adjustedRewards formula sums CU only from relay_payments rows where all 3 QoS metrics are non-null and > 0. The endpoint was using total CU (all rows) whenever any QoS data existed, inflating QosCus for providers with mixed QoS/non-QoS traffic. Use the new qos_cu MV column that applies delta's exact AND filter.
Delta computes AVG(qos_latency) etc. as unweighted row-level averages
where each relay_payments record counts equally regardless of relay count.
The endpoint was using relay-weighted averages from the MV (qosSyncW /
qosWeight), which over-represents high-relay records. Switch to the new
qos{Sync,Avail,Latency}Sum / qosCount columns that reproduce delta's
exact AVG() + AND-filter semantics.
Delta filters blocks with datetime >= from AND datetime < to (exclusive end). The endpoint was using lessThanOrEqualTo which includes the full end date, adding an extra day of data. Switch to lessThan for parity.
Add qosCus, avgLatency, avgAvailability, avgSync and their excellence variants to the response, matching delta's CSV columns. When results span multiple chains, QoS averages are correctly combined using raw sums and counts (not pre-averaged values) so cross-chain aggregation is exact.
The estimatedRewardsUsd/Lava fields used share × poolBalance × price, but pool balance is a point-in-time snapshot that doesn't represent the actual monthly distribution. After a payout the pools are near-empty; before one they're full — the number was arbitrary. The existing /provider-estimated-rewards endpoint already calls the chain's estimated_provider_rewards RPC for accurate per-provider values. Remove: estimatedRewardsLava, estimatedRewardsUsd, lavaUsdPrice, providerPoolLava. Keep: rewardShare (pure QoS metric). Drop the CoinGecko price and reward pool fetches that only served these fields.
- Strict calendar-date validation: reject 2025-02-30 / 2025-04-31 etc. via Date.UTC round-trip instead of naive `new Date()` parsing. - Conditional cacheTTL: 86400s for immutable past windows (to < today), 300s for live windows. Cache plugin now honors request.cacheTTL as a per-request override of route config. - Clarify BigInt rule in CLAUDE.md and api-conventions.md — the weighted-QoS rule has an explicit exception for /provider-rewards (unweighted row-level averaging for delta parity), and an inline comment at the aggregation loop explains the choice plus why CU stays as Number (CU is not ulava; totals stay within safe-int). - Add tests for the two new calendar-invalid cases.
nimrod-teich
force-pushed
the
fix/provider-rewards-delta-parity
branch
from
April 16, 2026 17:36
e481654 to
d16861f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
qosCu(QoS-filtered CU) instead of total CU — delta only counts CU from rows with valid QoSqosSyncW/qosWeight) to unweighted row-level averages (qosSyncSum/qosCount), matching delta'sAVG()semanticslessThanOrEqualTo→lessThanso thetodate is exclusive, matching delta'sdatetime < toqosCus,avgLatency,avgAvailability,avgSync,avgLatencyExc,avgAvailabilityExc,avgSyncExc— cross-chain aggregation uses raw sums/counts for exact averagingestimatedRewardsLava/Usd,lavaUsdPrice,providerPoolLava— pool balance snapshot ≠ actual distribution; consumers should use/provider-estimated-rewardsfor real chain-sourced valuesTest plan
/provider-rewards?from=2026-03-17&to=2026-04-17&specs[]=LAVAand verify response includes new QoS fieldsadjustedRewardsvalues against delta's WebSocket output for the same date range + spec/provider-estimated-rewardsstill serves USD estimates independently