Skip to content

feat: Cache network fee variables in StellarService - #1

Open
Devadakene wants to merge 124 commits into
mainfrom
feat/stellar-fee-cache
Open

feat: Cache network fee variables in StellarService#1
Devadakene wants to merge 124 commits into
mainfrom
feat/stellar-fee-cache

Conversation

@Devadakene

Copy link
Copy Markdown
Owner

Description

This PR resolves the issue by caching the network base fee details retrieved from the Horizon client to reduce redundant API calls on startup and during transaction dispatches.

  • Added Cache State: Implemented an in-memory cache variable feeCache and a corresponding TTL parameter FEE_CACHE_TTL_MS (set to 1 minute) in stellarService.ts.
  • Added Dynamic Fetching: Implemented a private helper getNetworkBaseFee() that queries the Horizon client using this.server.fetchBaseFee() and stores the result in the cache, returning the cached value if it is still fresh.
  • Updated dispatches: Refactored submitFeeBumpTransaction(), sendPayment(), enableClawback(), and executeClawback() to use the cached network fee.

Acceptance Criteria Checklist

  • Memory cache implemented for network fee variables.
  • Cache expiry set to 1 minute.
  • Performs fewer HTTP queries to Horizon on startup and dispatches by using the cache.

martoniel and others added 30 commits June 23, 2026 11:37
- Add Pino logger imports to auth middleware
- Replace console.error with structured logger in auth.ts
- Replace console.log/error with structured logger in reconciler service
- Add logger to reconciliation script with structured JSON output
- All logs now include service name, environment, and ISO timestamps
- Sensitive data (API keys, auth headers) automatically redacted by Pino
- Logs structured as JSON for easy parsing by log aggregators

Fixes: sublime247#1332
- Create accounting retry queue with exponential backoff (60s-10 attempts)
- Add accounting retry worker with structured logging
- Route failed sync operations to retry queue for manual/scheduled retry
- Replace console logs with structured Pino logging in syncWorker
- Add event listeners for job completion and failure monitoring
- Implement distinction between transient and permanent errors
- Transient errors (rate limit, network) auto-retry with backoff
- Permanent errors moved to retry queue after exhausting primary attempts
- Export retry queue functions and worker in queue index
- Update queue shutdown to include retry queue and worker cleanup
- Add logger mocking to accounting sync tests
- Update test assertions to use mocked logger instead of console spies

Key features:
- Failed updates retry correctly with exponential backoff
- Operators can manually retry operations via retryAccountingOperation()
- Queue stats and job inspection available via getAccountingRetryQueueStats()
- Structured logging for debugging and monitoring
- Conservative 2-concurrency limit to respect API rate limits

Fixes sublime247#1312
Add KmsFileSigner to hsmService.ts that signs SHA-256 file digests
using AWS KMS asymmetric keys, with automatic signing on upload
via s3Upload.ts and signature verification on read paths.

Closes sublime247#1286
feat(sep31): implement dynamic fee bump strategy using Horizon base fee
- Strip optional 'sha256=' prefix from incoming signature headers before timing-safe comparison.
- Utilize raw request body when available for HMAC verification.
…roduction

- Register existing profile command handlers in CLI main entry point
- Enables saving, loading, switching, listing, and deleting profiles
- Profiles stored in .momo-profiles.json with API URL and key per environment
- Active profile selection allows seamless environment switching
- Fallback to environment variables or .momorc when no profile is active
- No breaking changes to existing configuration system
…7#1310)

- Add src/services/providerReconciliationService.ts
  - ProviderReconciliationService class with runDailySettlement()
    entry point that: audits the double-entry ledger, aggregates
    per-provider merchant fees + provider fees from completed
    transactions, posts two balanced double-entry ledger transactions
    per provider (merchant fee sweep DR1100/CR4000 and provider fee
    expense DR5000/CR1100), persists a settlement record, and returns
    a structured SettlementSummary
  - getSettlementHistory() and getLatestSettlement() query helpers
  - Exported as providerReconciliationService singleton
- Add src/jobs/dailySettlementJob.ts
  - runDailySettlementJob() handler; throws on any provider failure
    so the scheduler logs a fatal error and PagerDuty is notified
- Add migrations/20260624_create_provider_settlement_records.sql
  - provider_settlement_records table with unique constraint on
    (settlement_date, provider) for idempotent upserts
  - Indexes on settlement_date, provider, and status
- Update src/jobs/scheduler.ts
  - Register daily-settlement job at 01:00 AM UTC
  - Schedule overridable via DAILY_SETTLEMENT_CRON env var

Closes sublime247#1310
…1273

Closes sublime247#1258, sublime247#1261, sublime247#1273

## Issue sublime247#1258 - Provider Latency Watchdog and Dynamic Circuit Breaker Tweaking
- Created src/services/providerLatencyWatchdog.ts with sliding window latency tracking
- Integrated recordProviderLatency() into MobileMoneyService.executeProviderOperation()
- Added tripCircuitBreaker() to src/utils/circuitBreaker.ts
- Updated all providers to return providerResponseTimeMs consistently

## Issue sublime247#1261 - Automated Callback Retry Queue for Webhooks
- Created src/queue/webhookRetryQueue.ts (BullMQ queue with exponential backoff)
- Created src/queue/webhookRetryWorker.ts (retry worker)
- Integrated retry queue into WebhookService.notifyTransactionWebhook() and notifyFlatTransactionWebhook()
- Registered worker in src/index.ts and added to graceful shutdown

## Issue sublime247#1273 - SEP-24 Interactive Deposit and Withdrawal Flow validation
- Added token limits (MAX_ACTIVE_TRANSACTIONS_PER_ACCOUNT) in src/stellar/sep24.ts
- generateInteractiveUrl() now signs URLs with HMAC-SHA256 via generateSignedSep24Url()
- Added GET /sep24/callback/:id endpoint with verifySep24Signature middleware
- Add swagger-ui-react component with Try It Out enabled
- New /sandbox route for interactive API testing
- Link from API Reference page and navbar
- Configurable via API_BASE_URL env var
…s-snapshot-export-entrypoint

feat(analytics): add versioned analytics snapshot export
…ool-rebalancing-engine

Add atomic LP reserve rebalancer and QuickBooks sales receipt sync
…rovider-settlement-automation

Feature/1310 daily provider settlement automation
…l-swagger-sandbox

feat(docs-portal): add interactive Swagger UI sandbox page
[MEDIUM] Build Liquidity Pool Rebalancing Engine for Stellar Assets
feat(cli): add telemetry config toggle to momo-cli setup wizard
…l-error-matrix

feat(providers): map Vodacom and Tigo transaction codes to global error matrix
…ess-worker-bundle-assets-sizes

Issue 1048 compress worker bundle assets sizes
…ount

Add VIP Fee Discount Tier logic check
…t-coverage

Feature/syncworker test coverage
…provider

feat: add Wave Senegal mobile money provider (sublime247#1256)
…-callback-ingest

Tune performance metric of parsing in the pipeline
…d-sanctions-engine

Feature/automated sanctions engine
Log Provider Status Changes on Dashboard
…pliance-ivms101

Feature/webhook compliance ivms101
…ity-tax-config

fix: password complexity validation (sublime247#1295) and configurable tax rates (sublime247#1311)
…-image-load-times

feat: optimize image load times in docs portal using sharp
…list-middleware

feat: add IP blacklist middleware and worker-level IP check
[MEDIUM] Automate API Specs Generation Sync during docs builds
…tions-sync-cron

feat(aml): implement periodic sanctions list sync cron (sublime247#1293)
…olver-spans

sublime247#1015 Add Datadog APM Tracing for GraphQL Resolvers execution
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.