diem/diem · critical

[BlockStore] failed to insert block during build {:?}

Error message

[BlockStore] failed to insert block during build {:?}

What it means

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.

Source

Thrown at consensus/src/block_storage/block_store.rs:261

            root_qc,
            root_ordered_cert,
            root_commit_li,
            max_pruned_blocks_in_mem,
            highest_timeout_cert.map(Arc::new),
            highest_2chain_timeout_cert.map(Arc::new),
        );

        let block_store = Self {
            inner: Arc::new(RwLock::new(tree)),
            state_computer,
            storage,
            time_service,
        };
        for block in blocks {
            block_store
                .execute_and_insert_block(block)
                .unwrap_or_else(|e| {
                    panic!("[BlockStore] failed to insert block during build {:?}", e)
                });
        }
        for qc in quorum_certs {
            block_store
                .insert_single_quorum_cert(qc)
                .unwrap_or_else(|e| {
                    panic!("[BlockStore] failed to insert quorum during build{:?}", e)
                });
        }

        counters::LAST_COMMITTED_ROUND.set(block_store.ordered_root().round() as i64);
        block_store
    }
    #[allow(clippy::unwrap_or_else_default)]
    #[allow(clippy::needless_borrow)]
    /// Commit the given block id with the proof, returns () on success or error
    pub async fn commit(&self, finality_proof: LedgerInfoWithSignatures) -> anyhow::Result<()> {
        let block_id_to_commit = finality_proof.ledger_info().consensus_block_id();

View on GitHub (pinned to fc4714a8ea)

Solutions

  1. Inspect the wrapped error for the root cause (missing parent vs execution failure) and fix the input set passed to build.
  2. If restarting after a crash, resync the node from peers / re-execute from the last committed state rather than replaying corrupt blocks.
  3. Verify block ordering: ensure parents precede children in the `blocks` list.
  4. File an issue with the error payload if the blocks came from consensus's own recovery path — this indicates state corruption.

Example fix

// before
for block in blocks {
    block_store.execute_and_insert_block(block).unwrap_or_else(|e| panic!(...));
}
// after: guarantee parents are inserted first
blocks.sort_by_key(|b| b.height());
for block in blocks {
    block_store.execute_and_insert_block(block).unwrap_or_else(|e| panic!("[BlockStore] failed to insert block during build {:?}", e));
}
Defensive patterns

Strategy: validation

Validate before calling

// Pre-flight: verify every block's parent exists in the input set
let ids: HashSet<_> = blocks.iter().map(|b| b.id()).collect();
for b in &blocks {
    if let Some(p) = b.parent_id() {
        if p != LedgerInfo::genesis().consensus_block_id() && !ids.contains(&p) {
            panic!("block {:?} parent {:?} missing from build input", b.id(), p);
        }
    }
}

Try / catch

// Panics internally, so validate inputs before build; if integrating, isolate:
let result = std::panic::catch_unwind(|| BlockStore::new(...build inputs...));
match result {
    Ok(store) => store,
    Err(e) => { /* trigger resync from peers */ }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of diem/diem@fc4714a8ea (2026-09-04). Data as JSON: /api/errors/b1e3b0ac0a1046cc. Report an issue: GitHub.