fix: cache payment-side token prices and add oracle HTTP timeouts#529
Conversation
Greptile SummaryThis PR addresses two issues from #519: it adds 5 s connect and 10 s read timeouts to the
Confidence Score: 5/5Safe to merge; production logic is correct and the refactoring is consistent with the existing batch-fetch pattern in calculate_spl_transfers_value_in_lamports. The production changes are straightforward: named timeout constants wired into the reqwest client, and a two-pass batching refactor that mirrors the already-proven pattern in calculate_spl_transfers_value_in_lamports. The only findings are in test code — a silently discarded initialize() result that would surface as a confusing test failure rather than a silent pass, and a hanging-server helper that is fragile if max_retries were ever raised. Neither affects production behaviour. No production files require special attention; the minor issues are confined to test helpers in token.rs and oracle_mock.rs. Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant TokenUtil
participant CacheUtil
participant Oracle as RetryingPriceOracle
participant RPC
Caller->>TokenUtil: calculate_payment_lamport_totals(config, tx, rpc, owner)
Note over TokenUtil: First pass — collect payment_mints & valid_transfers
TokenUtil->>TokenUtil: resolve accounts, filter inflow/outflow
TokenUtil->>TokenUtil: collect unique mints into payment_mints HashSet
TokenUtil->>CacheUtil: get_or_fetch_token_prices(rpc, config, mint_addresses)
CacheUtil->>Oracle: get_token_prices(mint_addresses) [batched, once]
Oracle-->>CacheUtil: "HashMap<mint, TokenPrice>"
CacheUtil-->>TokenUtil: "HashMap<mint, TokenPrice>"
alt "max_price_staleness_slots > 0"
TokenUtil->>RPC: get_slot()
RPC-->>TokenUtil: current_slot
end
TokenUtil->>TokenUtil: check_price_staleness for each price
loop per unique mint
TokenUtil->>RPC: get_mint_decimals(mint)
RPC-->>TokenUtil: decimals
end
Note over TokenUtil: Second pass — compute lamports per transfer
loop per valid_transfer
TokenUtil->>TokenUtil: calculate_token_value_in_lamports_from_price(amount, price, decimals)
TokenUtil->>TokenUtil: totals.checked_add_assign(inflow, outflow)
end
TokenUtil-->>Caller: PaymentLamportTotals
Reviews (6): Last reviewed commit: "fix: make TestOracleProxy fallback consi..." | Re-trigger Greptile |
b7a3d8e to
761da69
Compare
|
This PR has been inactive for 7 days and has been marked as stale. It will be closed in 5 days if there is no further activity. |
|
Ping! Just keeping this PR active. |
761da69 to
7bd02af
Compare
7bd02af to
1364b7f
Compare
dev-jodee
left a comment
There was a problem hiding this comment.
Some other changes to do, also can you not rebase / force push your changes and just commit on top of whats already there? Makes it easier to review just the diff from last reviewed commit. Thanks !
…simplify lamport calculation
I thought rebasing was the normal flow for keeping a PR up to date, so that's why I did it. Anyway, noted for future Kora contributions. |
|
✅ Fork external live tests passed. fork-external-live-pass:b85c8cd8823908e1edb4f46d28fac90b6459432f |
Added 5s connect and 10s read timeouts to the Jupiter oracle reqwest client via named Duration constants so retry logic can actually fire on hanging requests. Hanging server helper and HangingOracle extracted to oracle_mock.rs.
Refactored
calculate_payment_lamport_totalsto batch fetch prices viaCacheUtil::get_or_fetch_token_pricesand decimals once per unique mint instead of per transfer matchingcalculate_spl_transfers_value_in_lamports. Extracted repeated lamport math intocalculate_token_value_in_lamports_from_priceand updatedcalculate_token_value_in_lamportsto use it.Closes #519