Skip to main content
Compare Portal data availability against external RPC providers to monitor relative latency. The evmRpcLatencyWatcher subscribes to RPC endpoints via WebSocket and measures when blocks arrive at the Portal versus when they appear at the RPC endpoints.
The measured values include client-side network latency. For RPC endpoints, only the arrival time of blocks is measured—this does not capture the node’s internal processing or response latency if queried directly. Results represent end-to-end delays as experienced by the client, not pure Portal or RPC processing performance.
import { formatBlock } from "@subsquid/pipes";
import { evmPortalSource, evmRpcLatencyWatcher } from "@subsquid/pipes/evm";
import { metricsServer } from "@subsquid/pipes/metrics/node";

async function main() {
const stream = evmPortalSource({
  portal: "https://portal.sqd.dev/datasets/base-mainnet",
  query: { from: "latest" },
  metrics: metricsServer({ port: 9090 }),
}).pipe(
  evmRpcLatencyWatcher({
    rpcUrl: ["https://base.drpc.org", "https://base-rpc.publicnode.com"],
  }).pipe((data, { metrics }) => {
    if (!data) return;

    // Update Prometheus metrics for each RPC endpoint
    for (const rpc of data.rpc) {
      metrics
        .gauge({
          name: "rpc_latency_ms",
          help: "RPC Latency in ms",
          labelNames: ["url"],
        })
        .set({ url: rpc.url }, rpc.portalDelayMs);
    }

    return data;
  })
);

for await (const { data } of stream) {
  if (!data) continue;

  console.log(`Block: ${formatBlock(data.number)} / ${data.timestamp}`);
  console.table(data.rpc);
}
}

void main()

Output Format

The latency data includes:
  • url: RPC endpoint URL
  • receivedAt: Timestamp when the RPC endpoint received the block
  • portalDelayMs: Milliseconds between RPC arrival and Portal availability
Block: 36,046,611 / Fri Sep 26 2025 14:29:29 GMT+0400
┌───┬─────────────────────────────────┬──────────────────────────┬───────────────┐
│   │ url                             │ receivedAt               │ portalDelayMs │
├───┼─────────────────────────────────┼──────────────────────────┼───────────────┤
│ 0 │ https://base.drpc.org           │ 2025-09-26T10:29:29.134Z │ 646           │
│ 1 │ https://base-rpc.publicnode.com │ 2025-09-26T10:29:29.130Z │ 642           │
└───┴─────────────────────────────────┴──────────────────────────┴───────────────┘