feat: implement Stellar network fee estimation caching#133
Open
Phantomcall wants to merge 1 commit into
Open
Conversation
- Add stellarFeeStatsCache service with Redis + Horizon fallback - Add stellar-fee-stats background job (every 30s) - Update getTransactionBaseFee() to read from cache first - Register job in scheduler and warm cache on startup - Log cached fee values at startup and on each refresh closes Pidoko257#113
|
@Phantomcall Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
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.
Stellar Network Fee Estimation Caching
Problem
Every payment initiation currently fetches the current fee from Stellar Horizon synchronously via
server.fetchBaseFee(), adding latency to each transaction. This is particularly impactful for high-throughput payment processing where every millisecond counts.Solution
Implement a Redis-backed caching layer for Stellar Horizon fee statistics with a 30-second TTL, refreshed by a background cron job. The payment service reads from the cache instead of making a Horizon call per payment, eliminating redundant network round-trips.
Changes
New Files
src/services/stellarFeeStatsCache.tssrc/jobs/stellarFeeStatsJob.tsModified Files
src/stellar/transactions.tsgetTransactionBaseFee()now reads from Redis cache first; falls back toserver.fetchBaseFee()on cache misssrc/jobs/scheduler.tsstellar-fee-statsjob at*/30 * * * * *src/index.tsHow It Works
server.feeStats()from Horizon, and writeslast_ledger_base_feeto Redis under keystellar:fee_statswith a 30-second TTL.getTransactionBaseFee()attempts to read from Redis first. If the key exists, it returns the cached value immediately (no network call). On cache miss, it falls back to the originalserver.fetchBaseFee().Acceptance Criteria
closes #113