Context
The WebSocket block stream is the primary real-time data source for the EVM indexer. It subscribes to newHeads via eth_subscribe, detects reorgs by checking parent hashes, handles gap detection on reconnect, and fetches full block + receipt data via batch JSON-RPC. This is the most complex streaming adapter, analogous to the Solana WebSocketTransactionStream.
Specification
- Layer: Infrastructure (
infrastructure/evm/EvmWebSocketBlockStream.java)
- Implements:
EvmBlockStream domain port
- WebSocket: JDK
java.net.http.WebSocket (no external WS library)
- Subscription: Sends
eth_subscribe newHeads on connect
- Per-block flow (on each
newHeads notification):
- Extract
blockNumber + parentHash from notification
- Check reorg via
ParentHashTracker: if stored hash for blockNumber - 1 does not match parentHash, reorg detected
- If reorg: delegate to
ReorgHandler (cascade delete + re-index)
- Confirmation delay: if
CONFIRMATION_BLOCKS > 0, only process blocks when chainHead - blockNumber >= confirmationBlocks
- Fetch full block + receipts via
EvmJsonRpcClient.batchCall() (single batch with eth_getBlockByNumber + eth_getBlockReceipts)
- Parse via
EvmTransactionParser into domain objects
- Enqueue block + transactions to consumers
- Reconnect handling:
- On reconnect: run
GapDetector.detectGap() + backfill() before resuming live stream
- Uses shared
ReconnectHandler pattern
- Idle timeout: 60 seconds
- Track: Update
ParentHashTracker after each successfully processed block
Acceptance Criteria
Dependencies
- EVM-30: EvmJsonRpcClient (batch RPC for block + receipts)
- EVM-34: EvmTransactionParser (JSON to domain objects)
- EVM-35: ParentHashTracker (reorg detection)
- EVM-36: GapDetector (reconnect gap fill)
- EVM-20: ReorgHandler (reorg cascade)
References
Context
The WebSocket block stream is the primary real-time data source for the EVM indexer. It subscribes to
newHeadsviaeth_subscribe, detects reorgs by checking parent hashes, handles gap detection on reconnect, and fetches full block + receipt data via batch JSON-RPC. This is the most complex streaming adapter, analogous to the SolanaWebSocketTransactionStream.Specification
infrastructure/evm/EvmWebSocketBlockStream.java)EvmBlockStreamdomain portjava.net.http.WebSocket(no external WS library)eth_subscribe newHeadson connectnewHeadsnotification):blockNumber+parentHashfrom notificationParentHashTracker: if stored hash forblockNumber - 1does not matchparentHash, reorg detectedReorgHandler(cascade delete + re-index)CONFIRMATION_BLOCKS > 0, only process blocks whenchainHead - blockNumber >= confirmationBlocksEvmJsonRpcClient.batchCall()(single batch witheth_getBlockByNumber+eth_getBlockReceipts)EvmTransactionParserinto domain objectsGapDetector.detectGap()+backfill()before resuming live streamReconnectHandlerpatternParentHashTrackerafter each successfully processed blockAcceptance Criteria
eth_subscribe newHeadsJSON on WebSocket connectnewHeadsnotifications and fetches full block + receipts via batch RPCReorgHandlerParentHashTrackerafter each processed blockDependencies
References