Skip to content

Investigate and address #590-#593: two premises did not match realitytwo had a real underlying fix - #664

Open
Johnero542 wants to merge 1 commit into
Refract-Protocol:mainfrom
Johnero542:fix/issues-590-591-592-593
Open

Johnero542 wants to merge 1 commit into
Refract-Protocol:mainfrom
Johnero542:fix/issues-590-591-592-593

Conversation

@Johnero542

Copy link
Copy Markdown

#593: claim.repository.ts has no stats-aggregation method and never did JS-side reduction over all claims. The claim-stats DTO (activePolicies/processedClaims/ totalPayout) is fed entirely by in-memory counters in claim.service.ts (processedCount, payoutTotal, policyService.listActive()), already O(1) relative to claim volume. The repository's one stats-shaped method (getSettlementLatencyStats) already uses SQL aggregation with PERCENTILE_CONT. No change made: there is no load-all-then-reduce path to fix, and converting the already-O(1) in-memory counters into a DB query would be a regression.

#592: http-json.ts never opened new Agent() per call - it used axios's default global instance with no explicit agent. But that default has no keep-alive, so every request still opened a fresh TCP connection. Created one module-scoped AxiosInstance with keepAlive HTTP/HTTPS agents, used as the default for getJsonWithEvidence (coingecko/defillama/horizon adapters all flow through it unchanged), and wired destroyHttpJsonAgents() into AppModule's onApplicationShutdown so the pooled sockets close cleanly. Timeout/retry logic in the request wrapper is untouched.

#591: claim-settlement.repository.ts has no row-by-row insert loop - its only writes are single-row UPSERTs against claim_settlements (a different table, one row per decision). The settlement_attempts table from migrations/001_settlement_attempts.sql is currently unwritten by any code path; claim.service.ts tracks attempt counts purely in-memory (failureCounts Map), never persisting to this table. Added recordAttemptsBatch(), a single multi-row INSERT ... ON CONFLICT upsert against the real settlement_attempts schema, so that whenever attempt persistence is wired up, N policies can be recorded in one round trip instead of N. The attempt-counter-cap decision (settlement-attempt.ts's classification logic) is unchanged; this only persists whatever records a caller hands it.

#590: metrics.service.ts already uses prom-client Counter/Gauge/Histogram objects incremented from call sites (recordSchedulerRun, recordOracleCheck, recordRelayerBalance, etc.) exactly as the issue asks for, and metrics() simply renders already-maintained state via registry.metrics() with no recomputation. metrics.controller.ts does nothing extra on top. No change made: this file already implements the issue's desired end state.

Closes #591
Closes #592
Closes #590
Closes #593

Summary

Type of change

  • Bug fix
  • New feature
  • Refactor / cleanup
  • Docs
  • Tests / CI

Checklist

  • I read CONTRIBUTING.md
  • Tests added/updated for the change
  • Local gate passes (lint / typecheck or fmt + clippy + test / build)
  • No secrets, keys, or .env values committed
  • Behavioural changes are documented in the README where relevant

Notes for reviewers

…o premises did not match reality, two had a real underlying fix

Refract-Protocol#593: claim.repository.ts has no stats-aggregation method and never did JS-side
reduction over all claims. The claim-stats DTO (activePolicies/processedClaims/
totalPayout) is fed entirely by in-memory counters in claim.service.ts
(processedCount, payoutTotal, policyService.listActive()), already O(1)
relative to claim volume. The repository's one stats-shaped method
(getSettlementLatencyStats) already uses SQL aggregation with PERCENTILE_CONT.
No change made: there is no load-all-then-reduce path to fix, and converting
the already-O(1) in-memory counters into a DB query would be a regression.

Refract-Protocol#592: http-json.ts never opened `new Agent()` per call - it used axios's
default global instance with no explicit agent. But that default has no
keep-alive, so every request still opened a fresh TCP connection. Created one
module-scoped AxiosInstance with keepAlive HTTP/HTTPS agents, used as the
default for getJsonWithEvidence (coingecko/defillama/horizon adapters all
flow through it unchanged), and wired destroyHttpJsonAgents() into AppModule's
onApplicationShutdown so the pooled sockets close cleanly. Timeout/retry
logic in the request wrapper is untouched.

Refract-Protocol#591: claim-settlement.repository.ts has no row-by-row insert loop - its only
writes are single-row UPSERTs against claim_settlements (a different table,
one row per decision). The settlement_attempts table from
migrations/001_settlement_attempts.sql is currently unwritten by any code
path; claim.service.ts tracks attempt counts purely in-memory (failureCounts
Map), never persisting to this table. Added recordAttemptsBatch(), a single
multi-row INSERT ... ON CONFLICT upsert against the real settlement_attempts
schema, so that whenever attempt persistence is wired up, N policies can be
recorded in one round trip instead of N. The attempt-counter-cap decision
(settlement-attempt.ts's classification logic) is unchanged; this only
persists whatever records a caller hands it.

Refract-Protocol#590: metrics.service.ts already uses prom-client Counter/Gauge/Histogram
objects incremented from call sites (recordSchedulerRun, recordOracleCheck,
recordRelayerBalance, etc.) exactly as the issue asks for, and metrics()
simply renders already-maintained state via registry.metrics() with no
recomputation. metrics.controller.ts does nothing extra on top. No change
made: this file already implements the issue's desired end state.

Closes Refract-Protocol#591
Closes Refract-Protocol#592
@drips-wave

drips-wave Bot commented Nov 24, 2026

Copy link
Copy Markdown

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant