hyperledger/fabric · error
error unmarshalling last persisted commit hash
Error message
error unmarshalling last persisted commit hash
What it means
This error is returned by lastPersistedCommitHash when protobuf unmarshalling of the COMMIT_HASH entry in the last block's metadata fails. Fabric stores a hash of the committed block in block metadata; the ledger reads and unmarshals it into common.Metadata at ledger open time. A malformed, truncated, or corrupt block metadata blob causes proto.Unmarshal to fail.
Source
Thrown at core/ledger/kvledger/kv_ledger.go:350
)
return hex.DecodeString(l.bootSnapshotMetadata.LastBlockCommitHashInHex)
}
logger.Debugf("Fetching block [%d] to retrieve the currentCommitHash", bcInfo.Height-1)
block, err := l.GetBlockByNumber(bcInfo.Height - 1)
if err != nil {
return nil, err
}
if len(block.Metadata.Metadata) < int(common.BlockMetadataIndex_COMMIT_HASH+1) {
logger.Debugf("Last block metadata does not contain commit hash")
return nil, nil
}
commitHash := &common.Metadata{}
err = proto.Unmarshal(block.Metadata.Metadata[common.BlockMetadataIndex_COMMIT_HASH], commitHash)
if err != nil {
return nil, errors.Wrap(err, "error unmarshalling last persisted commit hash")
}
return commitHash.Value, nil
}
func (l *kvLedger) isPvtDataStoreAheadOfBlockStore() (bool, error) {
blockStoreInfo, err := l.blockStore.GetBlockchainInfo()
if err != nil {
return false, err
}
pvtstoreHeight, err := l.pvtdataStore.LastCommittedBlockHeight()
if err != nil {
return false, err
}
return pvtstoreHeight > blockStoreInfo.Height, nil
}
func (l *kvLedger) recoverDBs() error {
logger.Debugf("Entering recoverDB()")View on GitHub (pinned to 2736b63f8f)
Solutions
- Verify disk health and check for filesystem corruption; run fsck if needed
- If the ledger data is expendable, reset the ledger data (peer node reset) and resync from genesis or a snapshot
- Restore ledgersData from a known-good, consistently taken backup
- Recreate the ledger/peer and rejoin channels if corruption persists
Example fix
// corrupted COMMIT_HASH metadata cannot be patched in place by callers // before: peer start fails // after (operational fix): // peer node reset # then resync blocks, or restore a consistent backup of ledgersData
Defensive patterns
Strategy: validation
Validate before calling
// Before starting a peer on restored/copied data, verify blockstore integrity:
// ensure a consistent backup was taken (peer stopped) and check the ledger data dir
if !backupTakenWhilePeerStopped {
return errors.New("restore only consistent, peer-stopped backups of ledgersData")
} Prevention
- Only copy/restore ledgersData while the peer is fully stopped
- Monitor disk health (SMART, fsck) on the ledger data volume
- Keep verified backups taken at consistent points in time
When it happens
Trigger: Opening a ledger (newKVLedger -> lastPersistedCommitHash) where block.Metadata.Metadata[common.BlockMetadataIndex_COMMIT_HASH] contains bytes that are not a valid protobuf-encoded common.Metadata message, e.g. after disk corruption or a bad manual edit/copy of the block store.
Common situations: Corrupted LevelDB block store files, partial file copy/restore of ledgersData, restore from an inconsistent backup, or tampering with blockstore data files under peer filesystem.
Understand the failure class
Background: "cannot parse invalid wire-format data", "cannot unmarshal", "failed unmarshalling": protobuf unmarshal errors explained — this error's family across 10 libraries.
Related errors
- error decoding the block number
- error decoding the data hash
- error decoding the previous hash
- error decoding the length of block data
- error decoding the transaction envelope
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/92d7ea2cfa810d31.
Report an issue: GitHub.