Repository navigation
feat: socket hardening, throttling, chain read cache, and HTTP cache policies - #174
Open
rubbathabrahband wants to merge 1 commit into
Open
rubbathabrahband wants to merge 1 commit into
rubbathabrahband wants to merge 1 commit into
Conversation
…policies - Coalesce high-frequency socket price updates and add slow-consumer protection (Issue OracleDesk#96) - Harden socket.io server against connection floods, rate abuse, and oversized messages (Issue OracleDesk#97) - Add Redis-backed chain read cache with single-flight and ledger-aware invalidation (Issue OracleDesk#98) - Implement declarative HTTP cache policies, strong ETags, and 304 conditional request handling (Issue OracleDesk#99) Closes OracleDesk#96, OracleDesk#97, OracleDesk#98, OracleDesk#99
|
@rubbathabrahband 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 was referenced Oct 17, 2026
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.
Summary
This PR resolves issues #96, #97, #98, and #99 by implementing socket update coalescing and slow consumer protection, hardening the socket server against floods and abuse, adding a Redis-backed chain read-through cache with single-flight and ledger invalidation, and establishing explicit HTTP cache policies with strong ETags and conditional request (304) handling.
Key Changes
1. Coalesce High-Frequency Socket Updates & Slow Consumer Protection (#96)
MARKET_PRICEevents coalesced latest-wins per market and emitted at most once perSOCKET_PRICE_TICK_MS(default 1000 ms).TRADE_EXECUTEDas volatile delivery (SOCKET_TRADE_VOLATILE=true) emitted only to sockets in therealtime:fullroom.src/services/indexer.service.ts(SOCKET_LIVE_LEDGER_LAG, default 12 ledgers). Historical trades during catch-up are suppressed, emitting a singleCATCHUP_COMPLETEsummary instead.attachSlowConsumerGuardto monitor socket buffered amounts. Sockets aboveSOCKET_SLOW_WARN_BYTES(256 KB) degrade to receiving only price ticks; sockets aboveSOCKET_SLOW_DROP_BYTES(2 MB) are disconnected.tests/socket-throttle.test.tsand load soak scriptscripts/socket-load.mjs.2. Harden Socket.io Server Against Connection Floods & Oversized Messages (#97)
maxHttpBufferSize(SOCKET_MAX_BUFFER_BYTES, default 16 KB),pingInterval,pingTimeout,connectTimeout,transports, and disabledperMessageDeflate.isAllowedOrigin()between Express CORS and socket engineallowRequestto reject unauthorized WebSocket upgrades.redisConnectionLimiter/memoryConnectionLimiter).clientIp()walkingX-Forwarded-Forright-to-left skipping proxies inTRUSTED_PROXIESand normalizing IPv6-mapped IPv4 addresses./healthfor non-production environments.tests/socket-limits.test.ts.3. Cache Live Chain Reads in Redis with Ledger Invalidation & Single-Flight (#98)
src/lib/chain-cache.tssupportingbigint,Buffer/Uint8Array, tagged unions, and contract types.chain:gen:<tag>) and ledger watermark checks (chain:minLedger:<tag>) to prevent race conditions from stale simulations overwriting fresh updates.getOnChainMarketCached,resolverStateCached, andtreasuryAvailableCapitalCached. Invalidate affected tags on live agent writes and indexer events.tests/chain-cache.test.ts.4. HTTP Cache Middleware, Strong ETags & Conditional Requests (#99)
cachePolicymiddleware supportingshared,immutable,personalised, andno-store.If-None-Matchwith304 Not Modifiedbefore running expensive handlers.sendSuccesswhen cheap validators are not present.app.set('etag', false)). Requests carryingAuthorizationare never served public cache headers. Compressed responses append encoding suffixes withVary: Accept-Encoding.tests/http-cache.test.ts.Closes #96,
Closes #97,
Closes #98,
Closes #99