{"record":{"id":"47eef8f11a63713f","repo":"FuelLabs/fuel-core","slug":"missing-utxo-for-contract-id","errorCode":null,"errorMessage":"Missing utxo for contract: {id}","messagePattern":"Missing utxo for contract: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/chain-config/src/config/state.rs","lineNumber":227,"sourceCode":"            .contract_utxo\n            .into_iter()\n            .map(|entry| match entry.value {\n                ContractUtxoInfo::V1(utxo) => {\n                    (entry.key, (utxo.utxo_id, utxo.tx_pointer))\n                }\n                _ => unreachable!(),\n            })\n            .collect();\n\n        let contracts = contract_ids\n            .into_iter()\n            .map(|id| -> anyhow::Result<_> {\n                let code = contract_code\n                    .remove(&id)\n                    .ok_or_else(|| anyhow::anyhow!(\"Missing code for contract: {id}\"))?;\n                let (utxo_id, tx_pointer) = contract_utxos\n                    .remove(&id)\n                    .ok_or_else(|| anyhow::anyhow!(\"Missing utxo for contract: {id}\"))?;\n                let states = state.remove(&id).unwrap_or_default();\n                let balances = balance.remove(&id).unwrap_or_default();\n\n                Ok(ContractConfig {\n                    contract_id: id,\n                    code,\n                    tx_id: *utxo_id.tx_id(),\n                    output_index: utxo_id.output_index(),\n                    tx_pointer_block_height: tx_pointer.block_height(),\n                    tx_pointer_tx_idx: tx_pointer.tx_index(),\n                    states,\n                    balances,\n                })\n            })\n            .try_collect()?;\n\n        Ok(StateConfig {\n            coins,","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/FuelLabs/fuel-core/blob/b9d4d170da3a31c9ace5f963d633b326348e0d42/crates/chain-config/src/config/state.rs#L209-L245","documentation":"The chain-config state builder requires every contract that has bytecode to also carry a UTXO record (utxo_id + tx_pointer from ContractUtxoInfo::V1). When contract_code contains an id missing from contract_utxos, conversion fails with 'Missing utxo for contract: {id}' (crates/chain-config/src/config/state.rs:224-227). The code check runs first, so this error specifically means the bytecode was snapshotted but the contract's UTXO entry was not — again an inconsistent snapshot.","triggerScenarios":"Generating the StateConfig where the contract-code table contains a ContractId with no matching ContractUtxoInfo::V1 entry in the UTXO map.","commonSituations":"UTXO table truncated or pruned independently of the code table; snapshot exported at slightly different heights per table; hand-edited snapshots; versions of snapshot tables whose ContractUtxoInfo format the reader does not map (only V1 is handled — other variants hit unreachable!).","solutions":["Regenerate the snapshot so code, UTXO, state, and balance tables are written atomically at the same block height.","Validate up front that code ids and UTXO ids are the same set (see validation snippet).","If the contract was spent/pruned deliberately, drop its code row too.","Ensure the snapshot's ContractUtxoInfo entries are V1; older/different versions are rejected by this same code path."],"exampleFix":"// before — fails with 'Missing utxo for contract: 0x…'\nlet state_config = StateConfig::generate(&mut reader)?;\n\n// after — require identical id sets before building the config\nlet code_ids: HashSet<_> = contract_code.keys().copied().collect();\nlet utxo_ids: HashSet<_> = contract_utxos.keys().copied().collect();\nanyhow::ensure!(\n    code_ids == utxo_ids,\n    \"snapshot tables inconsistent: code-only {:?}, utxo-only {:?}\",\n    code_ids.difference(&utxo_ids),\n    utxo_ids.difference(&code_ids)\n);","handlingStrategy":"validation","validationCode":"// Require identical contract id sets across code and UTXO tables before conversion\nlet code_ids: HashSet<_> = contract_code.keys().copied().collect();\nlet utxo_ids: HashSet<_> = contract_utxos.keys().copied().collect();\nanyhow::ensure!(\n    code_ids == utxo_ids,\n    \"snapshot tables inconsistent: code-only {:?}, utxo-only {:?}\",\n    code_ids.difference(&utxo_ids),\n    utxo_ids.difference(&code_ids)\n);","typeGuard":null,"tryCatchPattern":"match build_config(&reader) {\n    Err(e) if e.to_string().contains(\"Missing utxo for contract\") => {\n        // bytecode exists but the UTXO record does not → regenerate snapshot\n        regenerate_snapshot(&node_url).await?;\n    }\n    other => other?,\n}","preventionTips":["Export all contract tables from the same node and block height in one pass.","Ensure snapshot ContractUtxoInfo entries are V1; other variants hit unreachable!() in the same code path.","Automate the id-set comparison in snapshot tooling so mismatches never reach the config builder."],"tags":["rust","fuel-core","chain-config","snapshot","genesis","utxo","data-integrity"],"backgroundTag":null,"analyzedSha":"b9d4d170da3a31c9ace5f963d633b326348e0d42","analyzedAt":"2026-08-16T08:56:42.692Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}