{"record":{"id":"e5e20b99737318f0","repo":"linera-io/linera-protocol","slug":"badinitialization-e5e20b","errorCode":"BadInitialization","errorMessage":"ExporterError::BadInitialization","messagePattern":"ExporterError::BadInitialization","errorType":"exception","errorClass":"ExporterError","httpStatus":null,"severity":"error","filePath":"linera-exporter/src/storage.rs","lineNumber":303,"sourceCode":"        if let Some(status) = self.chain_states_cache.get(&block_id.chain_id) {\n            return Ok(status.height >= block_id.height);\n        }\n\n        if let Some(status) = self\n            .exporter_state_view\n            .get_chain_status(&block_id.chain_id)\n            .await?\n        {\n            let result = status.height >= block_id.height;\n            self.chain_states_cache.insert(block_id.chain_id, status);\n            return Ok(result);\n        }\n\n        Err(ExporterError::UnprocessedChain)\n    }\n\n    pub(super) async fn index_chain(&mut self, block_id: &BlockId) -> Result<(), ExporterError> {\n        ensure!(\n            block_id.height == BlockHeight::ZERO,\n            ExporterError::BadInitialization\n        );\n        self.exporter_state_view.initialize_chain(*block_id).await?;\n        self.chain_states_cache\n            .insert(block_id.chain_id, (*block_id).into());\n\n        Ok(())\n    }\n\n    pub(super) async fn index_block(&mut self, block_id: &BlockId) -> Result<bool, ExporterError> {\n        if block_id.height == BlockHeight::ZERO {\n            self.index_chain(block_id).await?;\n            return Ok(true);\n        }\n\n        if self.exporter_state_view.index_block(*block_id).await? {\n            self.chain_states_cache","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/linera-io/linera-protocol/blob/6c226ddcb332ef55118dc8d0aafbd093d5420899/linera-exporter/src/storage.rs#L285-L321","documentation":"The exporter storage layer processes blocks for chains it has not seen before via index_chain, which must register them from their height-0 block. This BadInitialization is raised when a chain's first indexed block is not at BlockHeight::ZERO — the chain cannot be registered from a mid-chain block.","triggerScenarios":"index_block forwards a BlockId for an unknown chain whose height is greater than 0, so index_chain falls through to initialize_chain with a non-genesis block.","commonSituations":"Exporter attached to an already-running network; exporter started with an offset or after chains were created; gaps in the exporter's source data so block 0 is never ingested.","solutions":["Restart or rewind the exporter so it ingests each chain from height 0","Verify the exporter's start position and that the source node retains block 0 (check pruning settings)","For chains legitimately discovered mid-way, pre-seed the exporter state so the chain is already registered when the later block arrives"],"exampleFix":"// before\nstorage.index_block(&block_id).await?; // first block seen for this chain is height 42 -> BadInitialization\n\n// after\n// ingest the chain genesis first, then the later block\nstorage.index_block(&BlockId { chain_id, height: BlockHeight::ZERO, hash: genesis_hash }).await?;\nstorage.index_block(&block_id).await?;","handlingStrategy":"validation","validationCode":"fn is_chain_genesis(block_id: &BlockId) -> bool {\n    block_id.height == BlockHeight::ZERO\n}\n\n// before indexing an unknown chain, ensure its genesis is indexed first:\nif !exporter_knows_chain(&block_id.chain_id) {\n    anyhow::ensure!(is_chain_genesis(block_id), \"first block for a new chain must be height 0\");\n}","typeGuard":"fn is_chain_genesis(block_id: &BlockId) -> bool {\n    block_id.height == BlockHeight::ZERO\n}","tryCatchPattern":null,"preventionTips":["Ingest chains from height 0; rewind the exporter when a chain appears mid-stream","Check pruning/retention on the source node so block 0 stays available","Pre-register chains in exporter state before pointing it at later blocks"],"tags":["exporter","indexing","block-height","linera-exporter"],"backgroundTag":"initialization-height-mismatch","analyzedSha":"6c226ddcb332ef55118dc8d0aafbd093d5420899","analyzedAt":"2026-08-22T22:49:09.787Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}