XChain Platform Indexer: Operations

Prerequisites

  • Node.js 22 (22.x LTS), pinned in .nvmrc. Node 24 is outside the consensus runtime this component’s vendored xchain-vm pins (Node ABI 127, which checkConsensusRuntime() enforces); isolated-vm itself installs there from a prebuilt binding.
  • MariaDB server (for both Decoder and Indexer databases)
  • A running xchain-decoder instance (populating the Decoder database)

Running the Indexer

npm run api
# or directly:
node ./src/api.js

On startup, the indexer:

  1. Validates all required environment variables
  2. Starts the Express JSON-RPC API server
  3. Creates the Indexer database if it doesn’t exist
  4. Creates all required tables if they don’t exist
  5. Begins the block polling loop

Docker

The indexer is designed to run inside Docker. The Dockerfile copies source to /XChainIndexer/. The coin config path is resolved relative to the source directory, so the indexer must either run inside the Docker container or have the source mounted at that path.

Stopping

The indexer can be stopped gracefully by calling the stop() method on the XChainIndexer instance, which sets a flag that causes the main loop to exit after the current iteration completes. In Docker, send SIGTERM to allow the process to shut down cleanly.

API

The indexer exposes a minimal JSON-RPC API on the configured INDEXER_API_PORT:

ping

Health check endpoint.

Request:

{
    "jsonrpc": "2.0",
    "method": "ping",
    "id": 1
}

Response:

{
    "jsonrpc": "2.0",
    "result": { "status": "success" },
    "id": 1
}

health

Detailed health status. Unlike ping (which only confirms the HTTP server is up), health reports sync progress plus the circuit-breaker state of both database connections, so an operator can tell a healthy, syncing indexer apart from one silently stalled at an open circuit after a database outage.

Request:

{
    "jsonrpc": "2.0",
    "method": "health",
    "id": 1
}

Response:

{
    "jsonrpc": "2.0",
    "result": {
        "status": "healthy",
        "running": true,
        "synced": true,
        "lastIndexedBlock": 893000,
        "inFlightBlock": 893001,
        "decoderBlock": 893001,
        "lag": 1,
        "decoderDbCircuit": "closed",
        "indexerDbCircuit": "closed",
        "error": null
    },
    "id": 1
}
Field Type Description
status string "healthy" when the indexer is running and neither DB circuit is open; "unhealthy" otherwise.
running boolean Whether the indexer process is alive.
synced boolean Whether the indexer has caught up to the decoder.
lastIndexedBlock number|null Highest committed block index in the indexer DB; null if the indexer DB is unreachable. Safe to query at: it is read on the same committed-only connection the block-scoped query endpoints use, so a caller may poll health and immediately query at this height.
inFlightBlock number|null The block being parsed right now, inside the indexer’s open transaction, or null when no block is in flight. It is not indexed yet: block-scoped queries at this height are rejected, and a reorg may mean it never commits. Reported for visibility only.
decoderBlock number|null Decoder’s current tip as last observed by the indexer.
lag number|null decoderBlock − lastIndexedBlock; null when either value is unavailable. Measured against the committed height, so a poll landing mid-block reads as lag 1 rather than lag 0.
decoderDbCircuit string|null Decoder DB circuit-breaker state ("closed", "open", "half-open"), or null if no handle is configured.
indexerDbCircuit string|null Indexer DB circuit-breaker state, same value set as above.
error string|null Last fatal indexer error message, or null.

feequote

Native-coin fee pre-flight for a single action. Called internally by the explorer’s /{COIN}/api/feequote proxy; also usable directly by the SDK or wallet.

Request:

{
    "jsonrpc": "2.0",
    "method": "feequote",
    "params": {
        "action": "ISSUE",
        "params": "0|NEWTICK",
        "source": "bc1q...",
        "feeOutputSats": 0
    },
    "id": 1
}

Response: { fee_sats, fee_usd, fee_xchain, mode } plus validation fields. Returns an error string when the action is unknown or parameters are invalid.


feequotedryrun

Opt-in deep dry-run for a single action. Unlike feequote (which only covers create-action fee estimation), feequotedryrun runs the real action handler against current committed state inside a forced-rollback transaction, so it can authoritatively report { valid, status } for any action type. Native-fee sizing from feequote is merged into the response. The transaction is always rolled back; nothing persists.

Only available on regtest nodes with INDEXER_ENABLE_DRYRUN=true (or 1) set. On any other node the method is removed at startup and calls return a JSON-RPC method-not-found error. When enabled, calls require the x-api-key header (same key as other gated methods) if INDEXER_API_KEY is configured.

The source address must already be indexed; the dry-run will refuse an unknown source to avoid skewing AUTO_INCREMENT sequences.

Request:

{
    "jsonrpc": "2.0",
    "method": "feequotedryrun",
    "params": {
        "action": "EXECUTE",
        "params": "contract_hash|method|arg1",
        "source": "bc1q...",
        "feeOutputs": []
    },
    "id": 1
}
Field Type Required Description
action string yes ACTION type (e.g. DEPLOY, EXECUTE, SEND)
params string|string[] yes Pipe-delimited param string or array of param strings
source string yes Sending address (must already be indexed)
feeOutputs array no Transaction outputs used for native-fee verification

Response:

{
    "jsonrpc": "2.0",
    "result": {
        "dryRun": true,
        "blockIndex": 893000,
        "valid": true,
        "status": "valid",
        "error": null,
        "feeSupported": true,
        "requiredFeeNative": 1000
    },
    "id": 1
}
Field Type Description
dryRun boolean Always true when a dry-run was attempted; false if the source address was not indexed.
blockIndex number Block height used as the execution context.
valid boolean Whether the handler accepted the action.
status string|null Raw STATUS from the action handler (e.g. "valid", "invalid", handler-specific strings).
error string|null Null on success; reason string on failure.
feeSupported boolean Whether native-fee estimation is available for this action type.
requiredFeeNative number|null Required native-coin fee in satoshis; null when fee estimation is unsupported for this action.

Additional fields from feequote (e.g. fee_sats, fee_usd, fee_xchain) are merged into the response when fee estimation succeeds.

Warning: This endpoint runs the real VM inside a rollback. It holds the shared transaction lock for the duration of the handler, so concurrent block processing is paused. Keep the regtest indexer used for dry-runs isolated from a live consensus node.


feeschedule

Full native-coin fee schedule plus current oracle prices. Called internally by the explorer’s /{COIN}/api/feeschedule proxy.

Request:

{
    "jsonrpc": "2.0",
    "method": "feeschedule",
    "id": 1
}

Response: Fee schedule map (action → { base_sats, per_byte_sats }) and current coin/XCHAIN oracle prices used for USD-pegged fee calculation.

The response also carries priceSource: { hubDb, database }, saying which database those prices were read from. hubDb is true when HUB_DB_HOST and HUB_DB_NAME are both set and the indexer therefore routes price lookups through its hub connection, false when it reads its own database. database names that database on testnet and regtest and is null on mainnet. Anything that writes prices for a node to read (test fixtures, a seeding tool) should follow this field rather than infer the answer from its own environment: the setting lives on the indexer alone, and writing to the other database fails every priced action with no current oracle price while both databases look healthy.


getactionconfirmations

Confirmation count for a single action, used by the hub’s CrossChainEngine to gate cross-chain match progression.

Request:

{
    "jsonrpc": "2.0",
    "method": "getactionconfirmations",
    "params": { "action_index": 42 },
    "id": 1
}

Response:

{
    "jsonrpc": "2.0",
    "result": {
        "coin": "BTC",
        "network": "mainnet",
        "action_index": 42,
        "exists": true,
        "action": "SEND",
        "block_index": 800000,
        "latest_block_index": 800006,
        "confirmations": 7
    },
    "id": 1
}

When exists is false, confirmations is 0 and action/block_index are absent.


getpricebatches

Which oracle rounds in a closed range already ride a valid PRICE batch on this chain. The hub’s batch publisher calls it before re-proposing a buffered window, because a validator cannot answer from its own tables: its snapshots keep the per-round proof for rounds it finalized itself, and its published-round markers cover only the batches it broadcast. Only valid, version-0 batch rows are counted; an invalid wire does not carry its rounds for a replaying node, so the publisher is right to fill that window. Federation read (x-api-key), like getactionconfirmations.

Request:

{
    "jsonrpc": "2.0",
    "method": "getpricebatches",
    "params": { "first_round": 21, "last_round": 1568, "limit": 500 },
    "id": 1
}

limit is optional (default 500, ceiling 1000).

Response:

{
    "jsonrpc": "2.0",
    "result": {
        "block_index": 67875698,
        "first_round": 21,
        "last_round": 1568,
        "batches": [
            {
                "action_index": 10,
                "first_round": 49,
                "last_round": 53,
                "round_count": 5,
                "block_index": 67875001,
                "block_time": 1712500000
            },
            {
                "action_index": 270,
                "first_round": 52,
                "last_round": 53,
                "round_count": 2,
                "block_index": null,
                "block_time": null
            }
        ],
        "truncated": false
    },
    "id": 1
}

Each object in batches includes the landing block_index and that block’s protocol block_time, the same clock carried by pushpricebatch. block_index is null when the batch action has no resolvable landing block. block_time is null when the landing block is absent or its protocol time cannot be resolved. Neither field is guessed.

Batches are ordered by first_round, then action_index, and may overlap (a window published under a different split is still a valid carrier of its rounds). truncated is true when the page filled: the range past the last returned batch is unanswered, not empty, and the caller pages by asking again from there.


getattestbatches

Which closed attestation windows in an inclusive range already have a valid, complete ATTEST batch on this chain. The hub’s attestation batch publisher calls it before publishing its pending windows so a batch learned by another indexer’s push path is not published again. A result is a valid v5 head whose full batch is available: either the head is a single wire, or every v6 continuation has arrived and the batch has reassembled. Invalid heads and incomplete multi-wire batches are omitted. Federation read (x-api-key), like getpricebatches.

Request:

{
    "jsonrpc": "2.0",
    "method": "getattestbatches",
    "params": {
        "window_start_from": 1704067200,
        "window_start_to": 1704153600,
        "limit": 500
    },
    "id": 1
}

Both window-start bounds are inclusive. limit is optional (default 500, ceiling 1000).

Response:

{
    "jsonrpc": "2.0",
    "result": {
        "batches": [
            {
                "window_start": 1704067200,
                "window_end": 1704070800,
                "row_count": 12,
                "action_index": 42,
                "block_index": 67875698,
                "tx_hash": "0123456789abcdef..."
            }
        ],
        "truncated": false
    },
    "id": 1
}

Batches are ordered by window_start, then action_index. An empty head with row_count 0 is returned when valid and complete. truncated is true when the page filled, so the caller must not treat the unanswered remainder of the range as empty.


Administrative methods such as reparse and rollback are not exposed via the JSON-RPC API; reorg recovery runs automatically via the internal Rollback class.

Hub Feed Selection and Failover

Hub failover applies when HUB_DB_SYNC_ENABLED=true. Set HUB_SEED_URLS to a comma-separated list of hub feed base URLs. The selector shuffles the seeds, follows one while it is healthy, and adds the addresses returned by that hub’s gethubs call after a certified drain. A move chooses another candidate from the shuffled set. The new hub cannot release a mirror barrier until its first full drain has certified.

HUB_SEED_URLS=default expands to the built-in validator feed URLs for the configured INDEXER_NETWORK: port 10001 on mainnet and port 10002 on testnet. Regtest has no built-in hub addresses, so default is refused there. Supply explicit URLs for every regtest hub instead.

Leave HUB_SEED_URLS unset and set HUB_API_URL to retain pinned mode. A pinned indexer always reconnects to that one URL and never moves. HUB_CONFIG_URL is also pinned and never follows feed selection, because getallconfigs belongs on the private configuration API. An indexer that reads a hub MariaDB directly instead of enabling hub DB sync remains pinned as well.

The selector moves to another candidate for either of these reasons:

  • A connection fails HUB_FAILOVER_RECONNECT_ATTEMPTS consecutive times. The default is 3, which is about 15 seconds at the default reconnect cadence.
  • The stream watermark remains frozen for HUB_SYNC_WATERMARK_STALL_S seconds, survives one same-hub resync, and remains frozen for another HUB_SYNC_WATERMARK_STALL_EXIT_S seconds. The defaults are 180 and 300 seconds, respectively, so a quiet hub is left after about 8 minutes. A hub whose ready frame says caught_up: false is not certified and is skipped when another candidate is available.

HUB_FAILOVER_MIN_DWELL_MS prevents rapid movement between hubs after a selection change. Its default is 120000 (2 minutes). Set the same failover and watermark values on peer indexers when predictable fleet-wide timing is important.

Use HUB_FEED_API_KEY for the read-only snapshot, subscription, and gethubs feed. If it is unset, those reads fall back to HUB_API_KEY. Outbound reports continue to use HUB_API_KEY, with retraction reports using HUB_REORG_API_KEY when configured. The durable report queue tracks delivery per hub and sends every report to every known hub; one unavailable hub leaves only that hub’s delivery pending.

Match barrier tip lag: 120-second grace and 60-second waits defer fresh tip blocks by about two minutes

With HUB_DB_SYNC_ENABLED=true, the block loop holds each block behind the cross-chain match barrier until the local cross_chain_matches mirror has caught up to that block’s time. The barrier opens when the mirror stream watermark passes the block time plus a grace margin. The grace is 120 seconds (HUB_SYNC_WATERMARK_GRACE_S.match), and each wait attempt is bounded by HUB_PRICE_SYNC_TIMEOUT_MS (default 60000 ms) before the block is deferred and retried.

A block stamped at or near the current time, which is every block at the chain tip, therefore cannot clear the barrier until the watermark reaches its time plus the 120 second grace. Expect a node following the tip of a chain such as TBTC to commit each new block about two minutes after the block arrives. This is normal. Catch-up and reindex runs are unaffected because the mirror is already far ahead of the old blocks and the barrier opens immediately.

While a block waits, /health reports stallReason: "match_sync_barrier" and a stallClearsAt estimate of the instant the barrier can first clear. Deferral log lines read Deferring block N (cross-chain match sync). A block that sits behind any mirror barrier for longer than HUB_SYNC_BARRIER_HOLD_CEILING_S (default 900 seconds) is reported under a distinct name and forces the mirror to reconnect and re-bootstrap. That ceiling is operational only and never opens a barrier early.

The grace is a frozen protocol constant, not a tuning knob. Every node must settle matches at the same block, so a per-node value would fork settlement. HUB_SYNC_MATCH_GRACE_S is honored on regtest only, and any differing value is ignored with a startup warning on other networks. Do not shorten the lag by editing the constant on one node. A change to the margin is a fleet-wide protocol change.

Resilience and Recovery

Database Connection Recovery

The Database class includes a circuit breaker pattern for connection management:

  • Closed (normal): Connections proceed normally
  • Open (failing): After 10 consecutive failures, the circuit opens and rejects connections for 30 seconds
  • Half-open (testing): After the cooldown period, a single connection attempt is allowed; success closes the circuit, failure re-opens it
stateDiagram-v2
    [*] --> Closed
    Closed: Connections proceed normally
    Open: Rejects connections for 30 seconds
    HalfOpen: A single connection attempt is allowed

    Closed --> Open: 10 consecutive failures
    Open --> HalfOpen: cooldown elapses
    HalfOpen --> Closed: attempt succeeds
    HalfOpen --> Open: attempt fails

Database Verification on Startup

On startup, the indexer retries database connections indefinitely with a 5-second delay between attempts. This allows the indexer to start before the database is fully available (common in Docker orchestration).

Atomic Block Processing

Every block is processed within a single database transaction. If any error occurs during processing (validation failure, SQL error, timeout) the entire block is rolled back. The indexer then retries the block on the next polling cycle.

Reorg Recovery

When a blockchain reorganization is detected:

  1. The reorg block number is recorded in the events table
  2. All data at or after the reorg block is deleted within a single transaction
  3. Balances and token state are recalculated from the remaining ledger data
  4. The sanity check verifies consistency after the rollback
  5. Normal block processing resumes from the reorg point

Troubleshooting

Indexer won’t start

“Missing required environment variable: X” All variables listed in the Configuration reference must be set. Check your .env file exists and contains all required keys.

“Database XChain_…_Decoder doesn’t exist!” The Decoder database must exist before the indexer can read from it. Ensure xchain-decoder has been started and has created its database.

“Database XChain_…_Indexer tables don’t exist!” The indexer creates tables automatically on first startup. If this error occurs, check that the database user has CREATE TABLE permissions.

Indexer stalls or stops processing

“Error while parsing block data” Check the error details in the console output. The block will be retried on the next polling cycle. Persistent failures on the same block indicate a bug in an action handler.

Block processing timeout If a block consistently takes longer than BLOCK_PROCESS_TIMEOUT (default 5 minutes), it may contain an unusually large number of transactions. The timeout can be increased via the config, but investigate the root cause first.

Data inconsistency

Sanity check failures A sanity check failure means token supply does not match the sum of credits minus debits. This indicates a bug in the indexer’s ledger logic. The affected block is rolled back automatically. Report the block number and error details.

Connection issues

“Database connection error” The indexer retries database connections automatically. If the error persists, verify the database server is running and the connection credentials are correct. The circuit breaker will pause connection attempts for 30 seconds after 10 consecutive failures.


Copyright © 2025–2026 Dankest, LLC

Based on XChain Platform by Dankest, LLC – https://dankest.llc

Licensed under the GNU Affero General Public License v3.0 (AGPL-3.0-or-later) with a commercial license available for proprietary use.

You may use, modify, and distribute this material under the terms of the License. See LICENSE and NOTICE for full terms. See the licensing overview.

Edit this page on GitHub ↗