feat: add WebSocket subscription service with connection manager and polling fallback#8
Merged
Merged
Conversation
…ling fallback
Implement real-time subscription infrastructure per en-p0ha architecture directive:
- WebSocketConnectionManager: connection pool (one WS per chain), lazy
establishment, reconnection with exponential backoff (1s-30s, 10 retries),
heartbeat (30s ping, 5s pong timeout), subscription registry
- NewHeadsSubscription: eth_subscribe('newHeads') per chain, batch-fetches
balances for all tracked addresses on each new block
- TransferLogsSubscription: ERC-20 Transfer event logs filtered to tracked
addresses using keccak256('Transfer(address,address,uint256)') topic
- PollManager: 30s HTTP polling fallback when WS fails, continuous WS recovery
attempts every 60s, emits same events as WS path (transport-agnostic)
- SubscriptionService: unified API — subscribeBalances, subscribeTokenTransfers,
subscribeNewBlocks, subscribePendingTransactions, subscribeContractEvents,
unsubscribe, getSubscriptionStatus
- EventBus: domain event emitter for 11 event types (WEBSOCKET_CONNECTED,
DISCONNECTED, RECONNECTING, FAILED, SUBSCRIPTION_CREATED/REMOVED,
TRANSPORT_FALLBACK/RESTORED, LIVE_BALANCE/TRANSFER/BLOCK)
- All 8 EVM chains: Ethereum, Polygon, Arbitrum, Optimism, Base, BNB,
Avalanche, Fantom with default WS + HTTP endpoints
- 101 new tests across 6 test files, 985 total tests passing
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
src/subscriptions/moduleSubscriptionServiceorchestrates subscriptions with WebSocket-first, polling fallback strategyWebSocketConnectionManagerhandles connection lifecycle, reconnection, and health monitoringNewHeadsSubscriptionandTransferLogsSubscriptionfor block and ERC20 transfer eventsPollManagerprovides reliable polling fallback when WebSocket unavailableEventBusfor decoupled event distribution across componentsTest plan
MQ: ev-essv | Branch: polecat/obsidian/ev-keps@mlrpglwp