{"record":{"id":"c8bb1637a3e1bcc1","repo":"hyperledger/fabric","slug":"error-unmarshalling-chaincode-state-data","errorCode":null,"errorMessage":"error unmarshalling chaincode state data","messagePattern":"error unmarshalling chaincode state data","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/scc/lscc/deployedcc_infoprovider.go","lineNumber":78,"sourceCode":"\nfunc (p *DeployedCCInfoProvider) ImplicitCollections(channelName, chaincodeName string, qe ledger.SimpleQueryExecutor) ([]*peer.StaticCollectionConfig, error) {\n\treturn nil, nil\n}\n\n// GenerateImplicitCollectionForOrg is not implemented for legacy chaincodes\nfunc (p *DeployedCCInfoProvider) GenerateImplicitCollectionForOrg(mspid string) *peer.StaticCollectionConfig {\n\treturn nil\n}\n\n// ChaincodeInfo implements function in interface ledger.DeployedChaincodeInfoProvider\nfunc (p *DeployedCCInfoProvider) ChaincodeInfo(channelName, chaincodeName string, qe ledger.SimpleQueryExecutor) (*ledger.DeployedChaincodeInfo, error) {\n\tchaincodeDataBytes, err := qe.GetState(lsccNamespace, chaincodeName)\n\tif err != nil || chaincodeDataBytes == nil {\n\t\treturn nil, err\n\t}\n\tchaincodeData := &ccprovider.ChaincodeData{}\n\tif err := proto.Unmarshal(chaincodeDataBytes, chaincodeData); err != nil {\n\t\treturn nil, errors.Wrap(err, \"error unmarshalling chaincode state data\")\n\t}\n\tcollConfigPkg, err := fetchCollConfigPkg(chaincodeName, qe)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn &ledger.DeployedChaincodeInfo{\n\t\tName:                        chaincodeName,\n\t\tHash:                        chaincodeData.Id,\n\t\tVersion:                     chaincodeData.Version,\n\t\tExplicitCollectionConfigPkg: collConfigPkg,\n\t\tIsLegacy:                    true,\n\t}, nil\n}\n\n// AllChaincodesInfo returns the mapping of chaincode name to DeployedChaincodeInfo for legacy chaincodes\nfunc (p *DeployedCCInfoProvider) AllChaincodesInfo(channelName string, qe ledger.SimpleQueryExecutor) (map[string]*ledger.DeployedChaincodeInfo, error) {\n\titer, err := qe.GetStateRangeScanIterator(lsccNamespace, \"\", \"\")\n\tif err != nil {","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/scc/lscc/deployedcc_infoprovider.go#L60-L96","documentation":"Raised by ChaincodeInfo in lscc's deployed-chaincode info provider when the raw bytes stored under the chaincode name in the lscc namespace cannot be proto-unmarshalled into ccprovider.ChaincodeData. It means the ledger state for that chaincode definition is corrupt, truncated, or was written by an incompatible format. The wrapped underlying error is carried via errors.Wrap.","triggerScenarios":"Calling ChaincodeInfo (directly or via AllChaincodesInfo) on a query executor whose GetState(lsccNamespace, chaincodeName) returns bytes that fail proto.Unmarshal into ChaincodeData.","commonSituations":"Corrupted or hand-edited ledger state; state written by a much older Fabric version with a different ChaincodeData schema; database corruption after an upgrade or restore from inconsistent backup.","solutions":["Inspect the state entry for the chaincode under the lscc namespace and check the wrapped error for the protobuf decode cause","Re-deploy/redefine the chaincode so a valid ChaincodeData is written","Restore the peer's state database from a consistent backup","Check Fabric version compatibility of the ledger data (state written by an incompatible release)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Go: verify state bytes decode before relying on ChaincodeInfo\nraw, err := qe.GetState(\"lscc\", chaincodeName)\nif err != nil { return err }\nif raw == nil { return fmt.Errorf(\"chaincode %s not defined\", chaincodeName) }\ndata := &ccprovider.ChaincodeData{}\nif err := proto.Unmarshal(raw, data); err != nil {\n    return fmt.Errorf(\"corrupt ChaincodeData for %s: %w\", chaincodeName, err)\n}","typeGuard":null,"tryCatchPattern":"// Go\ninfo, err := provider.ChaincodeInfo(channelID, chaincodeName, qe)\nif err != nil {\n    if strings.Contains(err.Error(), \"error unmarshalling chaincode state data\") {\n        // corrupt state: alert ops, do not retry blindly\n        return fmt.Errorf(\"corrupt chaincode data in ledger for %s: %w\", chaincodeName, err)\n    }\n    return err\n}","preventionTips":["Never write raw/non-proto bytes into the lscc namespace","Restore state DBs only from consistent backups of the same Fabric version","Run peer upgrade procedures so ChaincodeData schema stays compatible","Monitor ledger integrity and re-deploy chaincodes whose stored data is suspect"],"tags":["hyperledger-fabric","protobuf","unmarshal","ledger-state"],"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"}