Chain State Synchronization
Real-time chain monitoring and cache synchronization through WebSocket subscriptions.
Table of Contents
Overview
┌─────────────────────────────────────────────────────────┐
│ WebSocket Flow │
├─────────────────────────────────────────────────────────┤
│ │
│ 1. Connect to wss://upstream.provider.com │
│ 2. Subscribe: eth_subscribe("newHeads") │
│ 3. Receive: Block header notifications │
│ 4. Process: │
│ ├─ Update chain tip │
│ ├─ Detect reorgs │
│ ├─ Fetch full block data │
│ └─ Cache block, transactions, receipts │
│ │
└─────────────────────────────────────────────────────────┘Key Components
Why Use WebSocket
1. Cache Accuracy
2. Reorg Detection
3. Reduced Upstream Load
4. Lower Latency
Metric
HTTP-only
With WebSocket
Configuration
Basic Configuration
Multiple Upstreams with WebSocket
WebSocket-Only Upstream
URL Format Requirements
WebSocket Subscriptions
Subscription Flow
1. Connection Establishment
2. Subscription Request
3. Subscription Confirmation
4. Block Notifications
Subscription Lifecycle
Real-Time Chain Tip Updates
Update Process
Step 1: Extract Block Data
Step 2: Update Chain Tip
Step 3: Fetch Full Block Data
Benefits
Reorg Detection
Detection Scenarios
Scenario 1: Same Height, Different Hash
Scenario 2: Rollback Detection
Reorg Coalescing
Problem Without Coalescing
Solution: Coalescing Window
Finality Boundaries
Failure Handling & Reconnection
Failure Scenarios
1. Connection Refused
2. Method Not Allowed (405)
3. Forbidden (403)
4. Protocol Mismatch (200 OK)
5. Subscription Failure
6. Connection Drop
Reconnection Logic
Backoff Strategies
WebSocketFailureTracker
Failure Thresholds
Normal Failures (1-2)
Threshold Reached (3)
Permanent Failure (6+)
Failure Reset
Configuration
Monitoring WebSocket Health
Logs
Connection Events
Block Processing
Disconnection Events
Error Events
Metrics
Connection Status
Failure Tracking
Block Processing
Reorg Detection
Grafana Dashboards
Alerting
When to Use WebSocket vs HTTP-Only
Use WebSocket When
Use HTTP-Only When
Hybrid Configuration
Troubleshooting
Issue: WebSocket Won't Connect
Issue: WebSocket Connects But No Blocks
Issue: Frequent Reconnections
Issue: High Failure Count
Issue: WebSocket Marked Permanently Failed
Issue: Cache Not Updating in Real-Time
Issue: Reorg Not Detected
Summary
Last updated