Skip to content

feat: implement fee estimation caching to reduce RPC calls#53

Merged
Just-Bamford merged 2 commits into
Sorokit:mainfrom
samjay8:feat/implement-fee-estimation
Jun 24, 2026
Merged

feat: implement fee estimation caching to reduce RPC calls#53
Just-Bamford merged 2 commits into
Sorokit:mainfrom
samjay8:feat/implement-fee-estimation

Conversation

@samjay8

@samjay8 samjay8 commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Closes #8

Summary

  • Cache check before RPC: estimateFee() now checks the pluggable SorokitCache (if provided) using a SHA256 hash of the transaction XDR as the cache key, before ever calling simulateTransaction().
  • Cache miss path: On a miss, the function simulates as before, then stores the FeeEstimate result in the cache for future calls.
  • Default TTL of 5 minutes: Added DEFAULT_FEE_CACHE_TTL_MS = 300_000 to src/shared/constants.ts. The TTL is configurable per-call via an optional cacheTtlMs parameter.
  • Client wired: createSorokitClient passes config.cache through to estimateFee, so any client configured with a cache automatically benefits.
  • Backward compatible: When no cache is provided, behaviour is identical to before.

Changes

File Change
src/shared/constants.ts Add DEFAULT_FEE_CACHE_TTL_MS = 300_000
src/transaction/estimateFee.ts Add cache? + cacheTtlMs? params; SHA256 key; cache get/set around simulation
src/client/createSorokitClient.ts Pass config.cache to estimateFee
src/tests/transaction.test.ts New: 11 tests covering cache hit, miss, expiry, default TTL, custom TTL, and backward compat

Test plan

  • Cache hit: returns cached FeeEstimate without calling simulateTransaction
  • Cache miss: calls RPC simulation and stores result with SHA256 key
  • Cache expiry: cache.get() returning undefined triggers fresh simulation
  • Default TTL: cache.set() called with DEFAULT_FEE_CACHE_TTL_MS (300000 ms)
  • Custom TTL: cache.set() called with caller-provided TTL
  • No cache: RPC called and result returned normally (backward compat)

@drips-wave

drips-wave Bot commented Jun 23, 2026

Copy link
Copy Markdown

@samjay8 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! 🚀

Learn more about application limits

- Add SHA256-keyed cache lookup in estimateFee() before calling simulateTransaction()
- Cache hits short-circuit the RPC call entirely; misses simulate then populate the cache
- Default TTL is 5 minutes (DEFAULT_FEE_CACHE_TTL_MS); callers can override per-call
- Wire client's SorokitCache into transaction.estimateFee via createSorokitClient
- Add transaction.test.ts covering cache hit, miss, expiry, default/custom TTL, and
  backward compatibility when no cache is provided

Closes Sorokit#8
@samjay8 samjay8 closed this Jun 23, 2026
@samjay8 samjay8 reopened this Jun 23, 2026
@samjay8 samjay8 force-pushed the feat/implement-fee-estimation branch from 66585bf to 4c7af32 Compare June 23, 2026 18:34
@Just-Bamford

Copy link
Copy Markdown
Collaborator

@samjay8 the code looks good to me. resolve the conflict so i can merge

@samjay8

samjay8 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

@Just-Bamford , it has been resolved, thank you.

@Just-Bamford Just-Bamford merged commit 57737d0 into Sorokit:main Jun 24, 2026
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.

Implement fee estimation caching to reduce RPC calls

2 participants