Skip to content

[P0] Implement WebSocket Server for Real-Time Blockchain Event Streaming #79

@BlocksScanIO

Description

@BlocksScanIO

Feature Request: WebSocket Server for Real-Time Event Streaming

Background

Competitor Analysis Reference: QuickNode, Alchemy, Infura

XDC Gateway currently lacks real-time streaming capabilities. Leading providers like QuickNode offer WebSocket connections for subscribing to live blockchain events with low latency.

Requirements

Core Functionality

  • WebSocket server supporting eth_subscribe and eth_unsubscribe methods
  • Subscription types:
    • newHeads - New block headers
    • logs - Contract event logs with address/topic filtering
    • newPendingTransactions - Pending transaction pool
    • syncing - Node sync status

Technical Specifications

  • Protocol: WebSocket (ws/wss) on port 8546
  • Frame Size: Support up to 10MB for large log batches
  • Connection Limit: 100 concurrent connections per IP (configurable)
  • Heartbeat: Ping/pong every 30 seconds
  • Reconnection: Client-side exponential backoff support

Performance Targets

  • Latency: <50ms from block import to WebSocket delivery
  • Throughput: 1000+ concurrent subscriptions
  • Message delivery: At-least-once semantics

Implementation Plan

Phase 1: Core Server (Week 1-2)

// Proposed architecture
package websocket

type Server struct {
    upgrader    websocket.Upgrader
    subscriptions map[string]*Subscription
    blockFeed   chan *types.Block
    eventBus    *EventBus
}

type Subscription struct {
    ID        string
    Type      SubscriptionType
    Filters   FilterCriteria
    Client    *ClientConn
    CreatedAt time.Time
}

Phase 2: Integration (Week 3)

  • Hook into XDC node block import pipeline
  • Subscribe to internal event feeds
  • Implement filtering logic

Phase 3: Testing & Deployment (Week 4)

  • Load testing with 10k concurrent connections
  • Reorg handling verification
  • Documentation and SDK updates

API Specification

// Subscribe request
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "eth_subscribe",
  "params": ["logs", {"address": "0x...", "topics": ["0x..."]}]
}

// Response
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x9ce59a13059e417087c02d32e8f8f9f8"
}

Acceptance Criteria

  • WebSocket endpoint accessible at wss://gateway.xdc.network/ws
  • All subscription types functional
  • Filter criteria working for logs
  • Load test: 1000 concurrent connections, 1 hour stability
  • Documentation published

Competitor Comparison

Feature QuickNode Alchemy XDC Gateway (Target)
WebSocket 🔄 In Progress
Subscription Types 4 4 4
Latency <50ms <100ms <50ms
Concurrent 10k+ 10k+ 1000+

References

Priority: P0 - Critical for DeFi and real-time applications
Estimated Effort: 4 weeks
Labels: enhancement, infrastructure, P0, websocket

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions