{"record":{"id":"b1b7d8e5a00d26e6","repo":"FuelLabs/fuel-core","slug":"missing-code-for-contract-id","errorCode":null,"errorMessage":"Missing code for contract: {id}","messagePattern":"Missing code for contract: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/chain-config/src/config/state.rs","lineNumber":224,"sourceCode":"            .collect();\n\n        let mut contract_utxos: HashMap<_, _> = self\n            .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()?;","sourceCodeStart":206,"sourceCodeEnd":242,"githubUrl":"https://github.com/FuelLabs/fuel-core/blob/b9d4d170da3a31c9ace5f963d633b326348e0d42/crates/chain-config/src/config/state.rs#L206-L242","documentation":"While converting snapshot tables into a chain/genesis StateConfig, the chain-config crate joins per-contract records: bytecode from a contract-code table, (utxo_id, tx_pointer) from ContractUtxoInfo::V1 entries, plus states and balances (crates/chain-config/src/config/state.rs:213-227). If a contract id appears in the UTXO set but has no entry in the contract-code map, building the config fails with 'Missing code for contract: {id}'. The snapshot's tables are inconsistent: the contract exists on-chain but its bytecode was not captured.","triggerScenarios":"Generating the StateConfig (snapshot-to-genesis conversion in chain-config) where contract_utxos contains a ContractId that the contract_code table lacks.","commonSituations":"Regenerating a genesis/snapshot with table ranges that don't line up; a partial or interrupted snapshot export that skipped code rows; manually pruning or editing parquet/JSON snapshot tables; mixing tables from two different snapshots or node versions.","solutions":["Regenerate the full snapshot from a synced node so the code and UTXO tables cover exactly the same contracts and block height.","Before conversion, verify consistency: every contract id in the UTXO table must exist in the code table (see validation snippet).","If the contract is intentionally absent, remove its UTXO, state, and balance rows from the snapshot tables as well.","If a freshly generated snapshot still misses code, report upstream — the export path may have a gap for some contract types."],"exampleFix":"// before — fails inside the config builder\nlet state_config = StateConfig::generate(&mut reader)?; // Missing code for contract: 0x…\n\n// after — check table consistency before conversion\nlet missing: Vec<_> = contract_utxo_ids\n    .iter()\n    .filter(|id| !contract_code.contains_key(*id))\n    .copied()\n    .collect();\nanyhow::ensure!(\n    missing.is_empty(),\n    \"snapshot tables inconsistent, contracts without code: {missing:?}\"\n);","handlingStrategy":"validation","validationCode":"// Verify snapshot table consistency before building the chain/genesis config\nlet missing_code: Vec<ContractId> = contract_utxo_ids\n    .iter()\n    .filter(|id| !contract_code.contains_key(*id))\n    .copied()\n    .collect();\nanyhow::ensure!(\n    missing_code.is_empty(),\n    \"snapshot tables inconsistent; contracts without code: {missing_code:?}\"\n);","typeGuard":null,"tryCatchPattern":"match build_config(&reader) {\n    Err(e) if e.to_string().contains(\"Missing code for contract\") => {\n        // snapshot tables are inconsistent → regenerate rather than patch\n        regenerate_snapshot(&node_url).await?;\n    }\n    other => other?,\n}","preventionTips":["Generate code, UTXO, state, and balance tables atomically at the same block height.","Never hand-prune one contract table without the others.","After export, run a consistency pass comparing contract id sets across tables before loading."],"tags":["rust","fuel-core","chain-config","snapshot","genesis","contract","data-integrity"],"backgroundTag":null,"analyzedSha":"b9d4d170da3a31c9ace5f963d633b326348e0d42","analyzedAt":"2026-08-16T08:56:42.692Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}