Skip to content

feat: cache soroban contracts, decouple notifications, tenant isolation, read replica#794

Merged
0xVida merged 2 commits into
Stellar-Fluid:mainfrom
Ogstevyn:TTL-based-in-memory-cache
Jun 1, 2026
Merged

feat: cache soroban contracts, decouple notifications, tenant isolation, read replica#794
0xVida merged 2 commits into
Stellar-Fluid:mainfrom
Ogstevyn:TTL-based-in-memory-cache

Conversation

@Ogstevyn
Copy link
Copy Markdown
Contributor

@Ogstevyn Ogstevyn commented Jun 1, 2026

Summary

  • Adds a TTL-based in-memory cache (ContractCache) in fluid-server for Soroban contract definitions and ledger footprint schemas, with a background eviction task and HTTP endpoints (/contract/definition, /contract/footprint, /contract/cache/stats). TTL is configurable via CONTRACT_CACHE_TTL_SECS.
  • Decouples the fluid-server alert delivery path into a standalone NotificationEngine Tokio background task. The hot request path enqueues events on a bounded channel (NotificationHandle::send); backends (Slack webhook, extensible to SMTP/PagerDuty) consume events asynchronously with no impact on fee-bump latency.
  • Adds a tenantIsolationMiddleware and requireTenantId helper in server that extract a verified tenantId from the resolved API key and gate all downstream database access to that tenant. A tenantIsolationService provides scoped query helpers (getTenantTransactions, getTenantApiKeys, getTenantWebhookDeliveries, getTenantDailySpend, getTenantById, getTenantQuotaTopUps) that hard-code the tenantId predicate.
  • Introduces a dedicated readPrisma client (server/src/utils/readDb.ts) backed by READ_REPLICA_URL (falls back to DATABASE_URL). Analytics queries in adminAnalytics.ts are migrated to this client so analytical reads no longer contend with write transactions on the primary database.

Test plan

  • fluid-server: 8 unit tests in contract_cache.rs (#[tokio::test]) covering set/get, TTL expiry, invalidation, eviction, overwrite, and count. 7 unit tests in notifications/mod.rs covering severity labels, serialisation, channel capacity, handle cloning, multi-event processing, and backend name routing.
  • server: Unit tests in tenantIsolationService.test.ts (14 cases), tenantIsolation.test.ts (7 cases), readDb.test.ts (5 cases). Existing adminAnalytics.test.ts updated to mock readDb instead of db to reflect the replica switch.
  • Documentation added under docs/ for all four features.

closes #706
closes #708
closes #702
closes #703

@Ogstevyn Ogstevyn force-pushed the TTL-based-in-memory-cache branch from 7dc3004 to 03bb219 Compare June 1, 2026 01:53
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Jun 1, 2026

@Ogstevyn 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

@0xVida 0xVida merged commit a2895c7 into Stellar-Fluid:main Jun 1, 2026
9 of 12 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

2 participants