{"record":{"id":"b1e3b0ac0a1046cc","repo":"diem/diem","slug":"blockstore-failed-to-insert-block-during-build","errorCode":null,"errorMessage":"[BlockStore] failed to insert block during build {:?}","messagePattern":"\\[BlockStore\\] failed to insert block during build (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"consensus/src/block_storage/block_store.rs","lineNumber":261,"sourceCode":"            root_qc,\n            root_ordered_cert,\n            root_commit_li,\n            max_pruned_blocks_in_mem,\n            highest_timeout_cert.map(Arc::new),\n            highest_2chain_timeout_cert.map(Arc::new),\n        );\n\n        let block_store = Self {\n            inner: Arc::new(RwLock::new(tree)),\n            state_computer,\n            storage,\n            time_service,\n        };\n        for block in blocks {\n            block_store\n                .execute_and_insert_block(block)\n                .unwrap_or_else(|e| {\n                    panic!(\"[BlockStore] failed to insert block during build {:?}\", e)\n                });\n        }\n        for qc in quorum_certs {\n            block_store\n                .insert_single_quorum_cert(qc)\n                .unwrap_or_else(|e| {\n                    panic!(\"[BlockStore] failed to insert quorum during build{:?}\", e)\n                });\n        }\n\n        counters::LAST_COMMITTED_ROUND.set(block_store.ordered_root().round() as i64);\n        block_store\n    }\n    #[allow(clippy::unwrap_or_else_default)]\n    #[allow(clippy::needless_borrow)]\n    /// Commit the given block id with the proof, returns () on success or error\n    pub async fn commit(&self, finality_proof: LedgerInfoWithSignatures) -> anyhow::Result<()> {\n        let block_id_to_commit = finality_proof.ledger_info().consensus_block_id();","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/diem/diem/blob/fc4714a8ea273b6efe8b13dbce72ea60aad9a16c/consensus/src/block_storage/block_store.rs#L243-L279","documentation":"BlockStore::build inserts each initial block with execute_and_insert_block and panics on the first failure. This means a block supplied to the constructor (typically from the initial payload/ordering state) could not be executed and inserted into the in-memory block tree — e.g. a missing parent, inconsistent state, or a storage execution error.","triggerScenarios":"Calling BlockStore::build with a `blocks` vector containing a block whose parent is absent, whose execution fails, or that violates tree invariants, so execute_and_insert_block returns Err.","commonSituations":"Restarting a node whose persisted block data is inconsistent or truncated; replaying blocks out of order; a bug in execution/SyncState after an upgrade producing blocks the store cannot link.","solutions":["Inspect the wrapped error for the root cause (missing parent vs execution failure) and fix the input set passed to build.","If restarting after a crash, resync the node from peers / re-execute from the last committed state rather than replaying corrupt blocks.","Verify block ordering: ensure parents precede children in the `blocks` list.","File an issue with the error payload if the blocks came from consensus's own recovery path — this indicates state corruption."],"exampleFix":"// before\nfor block in blocks {\n    block_store.execute_and_insert_block(block).unwrap_or_else(|e| panic!(...));\n}\n// after: guarantee parents are inserted first\nblocks.sort_by_key(|b| b.height());\nfor block in blocks {\n    block_store.execute_and_insert_block(block).unwrap_or_else(|e| panic!(\"[BlockStore] failed to insert block during build {:?}\", e));\n}","handlingStrategy":"validation","validationCode":"// Pre-flight: verify every block's parent exists in the input set\nlet ids: HashSet<_> = blocks.iter().map(|b| b.id()).collect();\nfor b in &blocks {\n    if let Some(p) = b.parent_id() {\n        if p != LedgerInfo::genesis().consensus_block_id() && !ids.contains(&p) {\n            panic!(\"block {:?} parent {:?} missing from build input\", b.id(), p);\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"// Panics internally, so validate inputs before build; if integrating, isolate:\nlet result = std::panic::catch_unwind(|| BlockStore::new(...build inputs...));\nmatch result {\n    Ok(store) => store,\n    Err(e) => { /* trigger resync from peers */ }\n}","preventionTips":["Ensure blocks passed to build are ordered parents-before-children and include the root.","Resync from peers instead of replaying a possibly-corrupt local block store after crashes.","Log the failing block id from the wrapped error before restart loops.","Add integration tests around crash-recovery replay paths."],"tags":["consensus","block-store","panic","state-sync"],"backgroundTag":"block-insert-failed","analyzedSha":"fc4714a8ea273b6efe8b13dbce72ea60aad9a16c","analyzedAt":"2026-09-04T21:07:05.890Z","contentChangedAt":"2026-09-04T21:07:05.890Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}