hyperledger/fabric · error
invalid chaincode data %v (%v)
Error message
invalid chaincode data %v (%v)
What it means
ValidateCC compares the ChaincodeData name/version against the package's depSpec ChaincodeId and, if they differ, reports 'invalid chaincode data'. It also unmarshals ccdata.Data into CDSData and compares with the package's computed data; any inconsistency between the metadata and the actual package contents triggers this error.
Source
Thrown at core/common/ccprovider/cdspackage.go:163
return errors.New("uninitialized package")
}
if ccpack.data == nil {
return errors.New("nil data")
}
// This is a hack. LSCC expects a specific LSCC error when names are invalid so it
// has its own validation code. We can't use that error because of import cycles.
// Unfortunately, we also need to check if what have makes some sort of sense as
// protobuf will gladly deserialize garbage and there are paths where we assume that
// a successful unmarshal means everything works but, if it fails, we try to unmarshal
// into something different.
if !isPrintable(ccdata.Name) {
return fmt.Errorf("invalid chaincode name: %q", ccdata.Name)
}
if ccdata.Name != ccpack.depSpec.ChaincodeSpec.ChaincodeId.Name || ccdata.Version != ccpack.depSpec.ChaincodeSpec.ChaincodeId.Version {
return fmt.Errorf("invalid chaincode data %v (%v)", ccdata, ccpack.depSpec.ChaincodeSpec.ChaincodeId)
}
otherdata := &CDSData{}
err := proto.Unmarshal(ccdata.Data, otherdata)
if err != nil {
return err
}
if !proto.Equal(ccpack.data, otherdata) {
return errors.New("data mismatch")
}
return nil
}
// InitFromBuffer sets the buffer if valid and returns ChaincodeData
func (ccpack *CDSPackage) InitFromBuffer(buf []byte) (*ChaincodeData, error) {
depSpec := &pb.ChaincodeDeploymentSpec{}View on GitHub (pinned to 2736b63f8f)
Solutions
- Ensure the ChaincodeData comes from the same package — recompute it via InitFromBuffer/InitFromPath rather than hand-building
- Align the name/version used at install with the CDS ChaincodeId
- Reinstall the chaincode package if its data hash does not match the metadata
- Check for corruption if Data unmarshals but mismatches
Example fix
// before
ccdata := &ChaincodeData{Name: "othercc", Version: "1.0"}
ccpack.ValidateCC(ccdata) // mismatch vs depSpec mycc:1.0
// after
ccdata := ccpack.GetChaincodeData() // derive data from the same package
ccpack.ValidateCC(ccdata) Defensive patterns
Strategy: validation
Validate before calling
// confirm data and spec agree before validation
if ccdata.Name != depSpec.ChaincodeSpec.ChaincodeId.Name ||
ccdata.Version != depSpec.ChaincodeSpec.ChaincodeId.Version {
return fmt.Errorf("chaincode data %s:%s does not match package %s:%s",
ccdata.Name, ccdata.Version,
depSpec.ChaincodeSpec.ChaincodeId.Name, depSpec.ChaincodeSpec.ChaincodeId.Version)
} Type guard
func dataMatchesSpec(ccdata *ccprovider.ChaincodeData, spec *pb.ChaincodeSpec) bool {
return ccdata != nil && spec != nil &&
ccdata.Name == spec.ChaincodeId.Name && ccdata.Version == spec.ChaincodeId.Version
} Try / catch
if err := ccpack.ValidateCC(ccdata); err != nil {
if strings.HasPrefix(err.Error(), "invalid chaincode data") {
// re-derive data from the package instead of failing permanently
fresh, ierr := ccpack.InitFromBuffer(originalBuf)
if ierr == nil { ccdata = fresh }
}
return err
} Prevention
- Always derive ChaincodeData from the same package via GetChaincodeData/InitFromBuffer
- Keep install-time name/version identical to the CDS ChaincodeId
- Never mix metadata from one package with bytes from another
- Version-pin chaincode packages across peers
When it happens
Trigger: ChaincodeData supplied to ValidateCC has Name or Version not matching depSpec.ChaincodeSpec.ChaincodeId, or its serialized Data does not match the package's computed CDSData hash content.
Common situations: Chaincode installed under a different name/version than referenced; mixing data from two packages; corrupted Data blob after unmarshal of garbage protobuf.
Related errors
- illegal file name in payload: %s
- cannot collect files from empty chaincode path
- invalid chaincode ID
- inconsistent ccid info (%s/%s)
- invalid chaincode deployment spec
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/20ea51ab6a350f60.
Report an issue: GitHub.