{"record":{"id":"ee476cf8b1edea7c","repo":"hyperledger/fabric","slug":"failed-unmarshalling-lscc-read-value-into-chaincod","errorCode":null,"errorMessage":"failed unmarshalling lscc read value into ChaincodeData","messagePattern":"failed unmarshalling lscc read value into ChaincodeData","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/cclifecycle/util.go","lineNumber":94,"sourceCode":"\t\t}\n\n\t\tres = append(res, instCC)\n\t}\n\tLogger.Debug(\"Returning\", res)\n\treturn res, nil\n}\n\nfunc deployedCCToNameVersion(cc chaincode.Metadata) nameVersion {\n\treturn nameVersion{\n\t\tname:    cc.Name,\n\t\tversion: cc.Version,\n\t}\n}\n\nfunc extractCCInfo(data []byte) (*ccprovider.ChaincodeData, error) {\n\tcd := &ccprovider.ChaincodeData{}\n\tif err := proto.Unmarshal(data, cd); err != nil {\n\t\treturn nil, errors.Wrap(err, \"failed unmarshalling lscc read value into ChaincodeData\")\n\t}\n\treturn cd, nil\n}\n\ntype nameVersion struct {\n\tname    string\n\tversion string\n}\n\nfunc installedCCToNameVersion(cc chaincode.InstalledChaincode) nameVersion {\n\treturn nameVersion{\n\t\tname:    cc.Name,\n\t\tversion: cc.Version,\n\t}\n}\n\nfunc names(installedChaincodes []chaincode.InstalledChaincode) []string {\n\tvar ccs []string","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/cclifecycle/util.go#L76-L112","documentation":"extractCCInfo unmarshals the value read from LSCC state for a chaincode key into a ccprovider.ChaincodeData protobuf. When the stored bytes are not a valid ChaincodeData, the failure is wrapped as 'failed unmarshalling lscc read value into ChaincodeData'.","triggerScenarios":"DeployedChaincodes -> extractCCInfo where the LSCC read for a chaincode name returns bytes that do not decode as ChaincodeData (wrong key read, corrupt value, or foreign data written under a chaincode-looking key).","commonSituations":"State database corruption or manual state manipulation; LSCC keys created by a much older Fabric version with an incompatible serialization; iterating keys whose naming collides with chaincode keys but store non-ChaincodeData values.","solutions":["Inspect the wrapped proto error to confirm the bytes are corrupt vs. simply not ChaincodeData.","Query LSCC directly (qscc GetChaincodes) to see which entries fail; identify and clean corrupt or colliding state entries.","Re-instantiate/redeploy affected chaincodes so LSCC writes fresh, valid ChaincodeData.","If the state DB (e.g. CouchDB) was restored inconsistently, rebuild the state from block replay."],"exampleFix":"// before: manually inserting a JSON blob under a chaincode key\nstate.Put(\"lscc/mycc\", jsonBytes)\n// after: only LSCC writes ChaincodeData protobufs\ncd := &ccprovider.ChaincodeData{Name: \"mycc\", Version: \"1.0\", ...}\ncdBytes, _ := proto.Marshal(cd)\nstate.Put(\"lscc/mycc\", cdBytes)","handlingStrategy":"type-guard","validationCode":"cd := &ccprovider.ChaincodeData{}\nif err := proto.Unmarshal(lsccValue, cd); err != nil {\n    // key holds foreign/corrupt data; skip or repair\n}","typeGuard":"func isChaincodeData(raw []byte) (*ccprovider.ChaincodeData, bool) {\n    cd := &ccprovider.ChaincodeData{}\n    if err := proto.Unmarshal(raw, cd); err != nil || cd.GetName() == \"\" { return nil, false }\n    return cd, true\n}","tryCatchPattern":"if _, err := extractCCInfo(data); err != nil {\n    if strings.Contains(err.Error(), \"failed unmarshalling lscc read value\") {\n        // mark LSCC entry corrupt; re-instantiate chaincode or rebuild state\n    }\n}","preventionTips":["Read chaincode info through LSCC/qscc APIs, not raw state keys","Detect state DB corruption early with periodic GetChaincodes queries","Rebuild state from the ledger after any inconsistent DB restore"],"tags":["hyperledger-fabric","lscc","protobuf","state-database"],"backgroundTag":"lscc-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"}