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

  1. Verify disk health and check for filesystem corruption; run fsck if needed
  2. If the ledger data is expendable, reset the ledger data (peer node reset) and resync from genesis or a snapshot
  3. Restore ledgersData from a known-good, consistently taken backup
  4. 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

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


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/92d7ea2cfa810d31. Report an issue: GitHub.