nautechsystems/nautilus_trader · error · anyhow::Error

Unknown chain_id: {chain_id}

Error message

Unknown chain_id: {chain_id}

What it means

The snapshot row's `chain_id` integer does not map to any known `Chain` in the library's chain registry (`Chain::from_chain_id` returned None). The loader cannot determine which blockchain the snapshot belongs to, so it fails. This guards against rows written for chains the current build does not support.

Source

Thrown at crates/adapters/blockchain/src/cache/database.rs:2536

                .await?;

            let ticks = self
                .load_pool_ticks_for_snapshot(
                    chain_id,
                    pool_identifier,
                    block,
                    transaction_index,
                    log_index,
                )
                .await?;

            let dex_name = row
                .try_get::<Option<String>, _>("dex_name")?
                .ok_or_else(|| {
                    anyhow::anyhow!("Missing dex_name for pool snapshot {}", pool_identifier)
                })?;
            let chain = Chain::from_chain_id(chain_id)
                .ok_or_else(|| anyhow::anyhow!("Unknown chain_id: {chain_id}"))?;

            let dex_type = DexType::from_dex_name(&dex_name)
                .ok_or_else(|| anyhow::anyhow!("Unknown dex_name: {dex_name}"))?;

            let dex_extended = crate::exchanges::get_dex_extended(chain.name, &dex_type)
                .ok_or_else(|| {
                    anyhow::anyhow!("No DEX extended found for {} on {}", dex_name, chain.name)
                })?;

            let instrument_id =
                Pool::create_instrument_id(chain.name, &dex_extended.dex, pool_identifier.as_ref());

            Ok(Some(PoolSnapshot::new(
                instrument_id,
                state,
                positions,
                ticks,
                analytics,

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Upgrade to an adapter version whose `Chain` registry includes the offending chain_id.
  2. Check the chain_id value in the row against supported chains; delete the row if it was written in error.
  3. Verify the deployment is pointed at the database for the intended network.
  4. Log the full set of supported chain_ids and add the new chain upstream if it's legitimately needed.

Example fix

// before: chain added only in DB, not in code
let chain = Chain::from_chain_id(chain_id).ok_or_else(...)?;
// after: extend the registry in the source of truth
// chain_registry.rs
(11155111, Chain::EthereumSepolia), // add missing chain id
Defensive patterns

Strategy: validation

Validate before calling

// before loading, verify every chain_id in the table is supported
let bad: Vec<i32> = sqlx::query_scalar(
    "SELECT DISTINCT chain_id FROM pool_snapshots")
    .fetch_all(&db).await?
    .into_iter().filter(|id| Chain::from_chain_id(*id as u64).is_none()).collect();
if !bad.is_empty() { return Err(format!("unsupported chain_ids: {bad:?}")); }

Try / catch

match load_snapshot(...).await {
    Err(e) if e.to_string().contains("Unknown chain_id") => {
        tracing::error!("upgrade adapter or purge rows for unsupported chain");
        Err(e)
    }
    other => other,
}

Prevention

When it happens

Trigger: A snapshot row persisted with a chain_id that the current binary's `Chain` enum/registry doesn't recognize — e.g. a newer chain added by a different adapter version, a test/dev chain id, or a typo'd chain id written by custom code.

Common situations: Running an older adapter version against a database written by a newer version that supports extra chains; custom fork with an added EVM chain; misconfigured deployment pointing the adapter at another network's database.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/c5e06c97ce98778e. Report an issue: GitHub.