{"record":{"id":"ac0a08f766f3406e","repo":"FuelLabs/fuel-core","slug":"contract-utxo-should-not-exist","errorCode":null,"errorMessage":"Contract utxo should not exist","messagePattern":"Contract utxo should not exist","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/fuel-core/src/service/genesis/importer/on_chain.rs","lineNumber":267,"sourceCode":"fn init_contract_latest_utxo(\n    transaction: &mut StorageTransaction<&mut GenesisDatabase>,\n    entry: &TableEntry<ContractsLatestUtxo>,\n    height: BlockHeight,\n) -> anyhow::Result<()> {\n    let contract_id = entry.key;\n\n    if entry.value.tx_pointer().block_height() > height {\n        return Err(anyhow!(\n            \"contract tx_pointer cannot be greater than genesis block\"\n        ));\n    }\n\n    if transaction\n        .storage::<ContractsLatestUtxo>()\n        .replace(&contract_id, &entry.value)?\n        .is_some()\n    {\n        return Err(anyhow!(\"Contract utxo should not exist\"));\n    }\n\n    Ok(())\n}\n\nfn init_blob_payload(\n    transaction: &mut StorageTransaction<&mut GenesisDatabase>,\n    entry: &TableEntry<BlobData>,\n) -> anyhow::Result<()> {\n    let payload = entry.value.as_ref();\n    let blob_id = entry.key;\n\n    // insert blob payload\n    if transaction\n        .storage::<BlobData>()\n        .replace(&blob_id, payload)?\n        .is_some()\n    {","sourceCodeStart":249,"sourceCodeEnd":285,"githubUrl":"https://github.com/FuelLabs/fuel-core/blob/b9d4d170da3a31c9ace5f963d633b326348e0d42/crates/fuel-core/src/service/genesis/importer/on_chain.rs#L249-L285","documentation":"Duplicate guard for ContractsLatestUtxo during on-chain genesis import: replace(&contract_id, &entry.value) returned Some, meaning this contract id already has a latest-utxo record — either another entry with the same contract id earlier in the same genesis batch, or an existing record in the database.","triggerScenarios":"The genesis state lists the same contract id twice under contracts_latest_utxo, or the importer runs against a database that already contains records for those contracts.","commonSituations":"Merging two state snapshots that both contain the same contracts; snapshot generation bugs emitting multiple latest-utxo records per contract; restarting genesis import into a populated db directory.","solutions":["Dedupe contracts_latest_utxo entries by contract id in the genesis state and re-import.","Wipe the on-chain db directory and retry so the importer starts from empty storage.","Regenerate the snapshot with tooling that guarantees a single latest-utxo record per contract id."],"exampleFix":"// before: two entries with the same key 0xdead...\n\"contracts_latest_utxo\": [\n  { \"key\": \"0xdead...\", \"value\": { \"utxo_id\": \"0x01\", \"tx_pointer\": { \"block_height\": 0, \"tx_index\": 0 } } },\n  { \"key\": \"0xdead...\", \"value\": { \"utxo_id\": \"0x02\", \"tx_pointer\": { \"block_height\": 0, \"tx_index\": 1 } } }\n]\n\n// after: keep only one entry per contract id\n\"contracts_latest_utxo\": [\n  { \"key\": \"0xdead...\", \"value\": { \"utxo_id\": \"0x02\", \"tx_pointer\": { \"block_height\": 0, \"tx_index\": 1 } } }\n]","handlingStrategy":"validation","validationCode":"fn validate_contract_utxo_uniqueness(\n    entries: &[TableEntry<ContractsLatestUtxo>],\n) -> Result<(), String> {\n    let mut seen = std::collections::HashSet::new();\n    for e in entries {\n        if !seen.insert(e.key) {\n            return Err(format!(\"duplicate ContractsLatestUtxo entry for contract {}\", e.key));\n        }\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"match importer.run().await {\n    Err(e) if e.to_string().contains(\"Contract utxo should not exist\") => {\n        // dedupe contracts_latest_utxo by contract id, wipe db, re-import\n    }\n    rest => rest,\n}","preventionTips":["Dedupe every keyed table by its primary key before importing a snapshot.","Avoid merging snapshots by concatenation; merge by key with last-write-wins tooling.","Keep db directories empty before first import of a chain."],"tags":["genesis","storage","duplicate-data","contracts","fuel-core","rust"],"backgroundTag":null,"analyzedSha":"b9d4d170da3a31c9ace5f963d633b326348e0d42","analyzedAt":"2026-08-16T08:56:42.692Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}