Repository navigation
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
Open
Investigate and address #590-#593: two premises did not match realitytwo had a real underlying fix#664Johnero542 wants to merge 1 commit into
Johnero542 wants to merge 1 commit into
Conversation
…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
|
@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! 🚀 |
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.
#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
Checklist
.envvalues committedNotes for reviewers