hyperledger/fabric · error
failed unmarshalling lscc read value into ChaincodeData
Error message
failed unmarshalling lscc read value into ChaincodeData
What it means
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'.
Source
Thrown at core/cclifecycle/util.go:94
}
res = append(res, instCC)
}
Logger.Debug("Returning", res)
return res, nil
}
func deployedCCToNameVersion(cc chaincode.Metadata) nameVersion {
return nameVersion{
name: cc.Name,
version: cc.Version,
}
}
func extractCCInfo(data []byte) (*ccprovider.ChaincodeData, error) {
cd := &ccprovider.ChaincodeData{}
if err := proto.Unmarshal(data, cd); err != nil {
return nil, errors.Wrap(err, "failed unmarshalling lscc read value into ChaincodeData")
}
return cd, nil
}
type nameVersion struct {
name string
version string
}
func installedCCToNameVersion(cc chaincode.InstalledChaincode) nameVersion {
return nameVersion{
name: cc.Name,
version: cc.Version,
}
}
func names(installedChaincodes []chaincode.InstalledChaincode) []string {
var ccs []stringView on GitHub (pinned to 2736b63f8f)
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.
Example fix
// before: manually inserting a JSON blob under a chaincode key
state.Put("lscc/mycc", jsonBytes)
// after: only LSCC writes ChaincodeData protobufs
cd := &ccprovider.ChaincodeData{Name: "mycc", Version: "1.0", ...}
cdBytes, _ := proto.Marshal(cd)
state.Put("lscc/mycc", cdBytes) Defensive patterns
Strategy: type-guard
Validate before calling
cd := &ccprovider.ChaincodeData{}
if err := proto.Unmarshal(lsccValue, cd); err != nil {
// key holds foreign/corrupt data; skip or repair
} Type guard
func isChaincodeData(raw []byte) (*ccprovider.ChaincodeData, bool) {
cd := &ccprovider.ChaincodeData{}
if err := proto.Unmarshal(raw, cd); err != nil || cd.GetName() == "" { return nil, false }
return cd, true
} Try / catch
if _, err := extractCCInfo(data); err != nil {
if strings.Contains(err.Error(), "failed unmarshalling lscc read value") {
// mark LSCC entry corrupt; re-instantiate chaincode or rebuild state
}
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- failed to parse collection config
- unmarshalling ChaincodeQueryResponse failed
- malformed chaincode invocation spec
- unmarshalling of ChaincodeData failed, error %s
- unmarshalling of ChaincodeData failed, error %s
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/ee476cf8b1edea7c.
Report an issue: GitHub.