hyperledger/fabric · error
failed to get last block
Error message
failed to get last block
What it means
NewChain fetches the last block of the channel ledger (support.Block(support.Height()-1)) to initialize chain state (block number, appended terms). If that block is nil despite the height, the ledger is inconsistent and chain startup is aborted with 'failed to get last block'. This prevents initializing raft on top of an unreadable ledger tip.
Source
Thrown at orderer/consensus/etcdraft/chain.go:261
}
sizeLimit := opts.SnapshotIntervalSize
if sizeLimit == 0 {
sizeLimit = DefaultSnapshotIntervalSize
}
// get block number in last snapshot, if exists
var snapBlkNum uint64
cc := &raftpb.ConfState{}
if s := storage.Snapshot(); !raft.IsEmptySnap(s) {
b := protoutil.UnmarshalBlockOrPanic(s.GetData())
snapBlkNum = b.GetHeader().GetNumber()
cc = s.GetMetadata().GetConfState()
}
b := support.Block(support.Height() - 1)
if b == nil {
return nil, errors.Errorf("failed to get last block")
}
c := &Chain{
configurator: conf,
rpc: rpc,
channelID: support.ChannelID(),
raftID: opts.RaftID,
submitC: make(chan *submit),
applyC: make(chan apply),
haltC: make(chan struct{}),
doneC: make(chan struct{}),
startC: make(chan struct{}),
snapC: make(chan *raftpb.Snapshot),
errorC: make(chan struct{}),
gcC: make(chan *gc),
observeC: observeC,
support: support,
fresh: fresh,View on GitHub (pinned to 2736b63f8f)
Solutions
- Check the orderer log for prior ledger read errors and validate the channel's block files (blockindex/ledger data integrity).
- Remove and re-join the channel via the participation API to rebuild the ledger from other consenters.
- Restore the ledger from a healthy snapshot or copy block files from a working orderer of the same channel (with the orderer stopped).
- Verify disk health and free space; replace failing storage before restarting.
Defensive patterns
Strategy: retry
Validate before calling
b := support.Block(support.Height() - 1)
if b == nil {
return errors.New("ledger tip unreadable; re-sync channel before starting chain")
} Prevention
- Guard against ledger truncation from crashes (fsync, healthy storage)
- Verify snapshot restore completes before chain start
- Monitor block file integrity on orderer nodes
When it happens
Trigger: Creating a chain where support.Height() > 0 but the last block cannot be retrieved — ledger truncation/corruption, height advanced but block data missing, or a race with ledger initialization.
Common situations: Orderer crash mid-block-write corrupting the ledger tip; snapshot restore leaving the ledger height inconsistent; FileLedger directory partially deleted or on a failing disk.
Related errors
- unable to retrieve block [%d]
- failed to restore persisted raft data: %s
- chain is stopped
- chain is not started
- failed to process Raft Step message: %s
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/9203aa553d46663b.
Report an issue: GitHub.