Skip to content

feat(chain-watcher): Add HTTP polling fallback when WebSocket fails#56

Merged
geminimir merged 1 commit intomainfrom
feature/http-polling-fallback
Mar 14, 2026
Merged

feat(chain-watcher): Add HTTP polling fallback when WebSocket fails#56
geminimir merged 1 commit intomainfrom
feature/http-polling-fallback

Conversation

@geminimir
Copy link
Owner

Summary

Implement HTTP polling fallback for the Chain Watcher when WebSocket connection to the RPC drops. This ensures no Transfer events are missed during connection instability.

Changes

  • Add ConnectionManager class to handle WebSocket connections with automatic fallback
  • Detect WebSocket disconnect/error events and switch to polling mode
  • Poll eth_getLogs at configurable interval (default: 2s) with block range tracking
  • Resume WebSocket subscription when connection is re-established
  • Implement exponential backoff for reconnection attempts (5s -> 10s -> 20s -> 60s max)
  • Log mode transitions for observability
  • Add ConnectionMode and TransferLog types to shared package
  • Add CHAIN_WATCHER constants for polling/reconnect configuration

How to Test

  1. npm ci
  2. npm run typecheck
  3. npm test --workspace=@stripeonchain/chain-watcher

Tests

  • Tests added/updated (16 new tests for ConnectionManager)
  • All tests pass (npm test)
  • Lint passes (npm run lint)
  • Type-check passes (npm run typecheck for chain-watcher)
  • Formatting passes (npm run format:check)

Checklist

  • No secrets or credentials committed
  • Migrations run cleanly up and down (npm run migrate:up / npm run migrate:down)
  • Docker Compose starts without errors (docker compose up)

Related Issues

Closes #14

Made with Cursor

- Add ConnectionManager class to handle WebSocket connections with fallback
- Detect WebSocket disconnect/error events and switch to polling mode
- Poll eth_getLogs at configurable interval (default 2s) with block range tracking
- Resume WebSocket subscription when connection is re-established
- Log mode transitions (websocket <-> polling)
- Add comprehensive unit tests (16 new tests)

Closes #14

Made-with: Cursor
@geminimir geminimir merged commit c561512 into main Mar 14, 2026
1 check passed
@geminimir geminimir deleted the feature/http-polling-fallback branch March 14, 2026 16:04
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.

Add HTTP polling fallback when WebSocket connection fails

1 participant