{"record":{"id":"92d7ea2cfa810d31","repo":"hyperledger/fabric","slug":"error-unmarshalling-last-persisted-commit-hash","errorCode":null,"errorMessage":"error unmarshalling last persisted commit hash","messagePattern":"error unmarshalling last persisted commit hash","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/ledger/kvledger/kv_ledger.go","lineNumber":350,"sourceCode":"\t\t)\n\t\treturn hex.DecodeString(l.bootSnapshotMetadata.LastBlockCommitHashInHex)\n\t}\n\n\tlogger.Debugf(\"Fetching block [%d] to retrieve the currentCommitHash\", bcInfo.Height-1)\n\tblock, err := l.GetBlockByNumber(bcInfo.Height - 1)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif len(block.Metadata.Metadata) < int(common.BlockMetadataIndex_COMMIT_HASH+1) {\n\t\tlogger.Debugf(\"Last block metadata does not contain commit hash\")\n\t\treturn nil, nil\n\t}\n\n\tcommitHash := &common.Metadata{}\n\terr = proto.Unmarshal(block.Metadata.Metadata[common.BlockMetadataIndex_COMMIT_HASH], commitHash)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"error unmarshalling last persisted commit hash\")\n\t}\n\treturn commitHash.Value, nil\n}\n\nfunc (l *kvLedger) isPvtDataStoreAheadOfBlockStore() (bool, error) {\n\tblockStoreInfo, err := l.blockStore.GetBlockchainInfo()\n\tif err != nil {\n\t\treturn false, err\n\t}\n\tpvtstoreHeight, err := l.pvtdataStore.LastCommittedBlockHeight()\n\tif err != nil {\n\t\treturn false, err\n\t}\n\treturn pvtstoreHeight > blockStoreInfo.Height, nil\n}\n\nfunc (l *kvLedger) recoverDBs() error {\n\tlogger.Debugf(\"Entering recoverDB()\")","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/kvledger/kv_ledger.go#L332-L368","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// corrupted COMMIT_HASH metadata cannot be patched in place by callers\n// before: peer start fails\n// after (operational fix):\n//   peer node reset   # then resync blocks, or restore a consistent backup of ledgersData","handlingStrategy":"validation","validationCode":"// Before starting a peer on restored/copied data, verify blockstore integrity:\n// ensure a consistent backup was taken (peer stopped) and check the ledger data dir\nif !backupTakenWhilePeerStopped {\n    return errors.New(\"restore only consistent, peer-stopped backups of ledgersData\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["hyperledger-fabric","ledger","protobuf","corruption"],"backgroundTag":"protobuf-unmarshal-failed","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}