solanaRpcLatencyWatcher function monitors the latency between Portal and external RPC providers, helping you track indexing performance.
Import
Signature
Parameters
Return Value
Returns a query-transformer combo that already includes the block query it needs. Pass it directly as the source’soutputs. You can chain .pipe() transforms to it.
Output Data Structure
Each batch carries the samples that became decidable in it, so iterate the result:rpc carries one entry per configured endpoint on every sample.
portalDelayMs is signed. A negative value means the Portal delivered the slot before that endpoint did. If these values feed a histogram, revisit the buckets and any max(0, ...) clamping, or Portal leads fold back into the zero bucket.
portalDelayMs and receivedAt are absent whenever unresolved is set:
Count unresolved entries rather than charting them. A missing delay is not zero.
Basic Usage
Example Output
Multiple RPC Endpoints
Monitor multiple RPC providers simultaneously:Metrics Integration
Export latency data to Prometheus via the built-in metrics registry. Skip the entries that carryunresolved, since they have no delay to record. See the Data freshness monitoring guide for the full example:
How It Works
The RPC latency watcher:- Subscribes to slot updates via WebSocket (
slotsUpdatesSubscribe) - Listens for
optimisticConfirmationevents from each RPC - Holds each slot until both sides have reported it, or until
resolveTimeoutMspasses - Reports the signed delay as
portalDelayMs, orunresolvedwhen an endpoint never reported the slot
Use Cases
- Performance monitoring - Track indexing latency in production
- RPC comparison - Compare performance across different RPC providers
- Alerting - Trigger alerts when latency exceeds thresholds
- Optimization - Identify bottlenecks in your indexing pipeline