{"record":{"id":"2db66720d77b2f5d","repo":"hyperledger/fabric","slug":"invalid-chaincode-data-v-v-2db667","errorCode":null,"errorMessage":"invalid chaincode data %v (%v)","messagePattern":"invalid chaincode data (.+?) \\((.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/common/ccprovider/sigcdspackage.go","lineNumber":206,"sourceCode":"\t\treturn errors.New(\"signed chaincode deployment spec cannot be nil in a package\")\n\t}\n\n\tif ccpack.depSpec == nil {\n\t\treturn errors.New(\"chaincode deployment spec cannot be nil in a package\")\n\t}\n\n\t// This is a hack. LSCC expects a specific LSCC error when names are invalid so it\n\t// has its own validation code. We can't use that error because of import cycles.\n\t// Unfortunately, we also need to check if what have makes some sort of sense as\n\t// protobuf will gladly deserialize garbage and there are paths where we assume that\n\t// a successful unmarshal means everything works but, if it fails, we try to unmarshal\n\t// into something different.\n\tif !isPrintable(ccdata.Name) {\n\t\treturn fmt.Errorf(\"invalid chaincode name: %q\", ccdata.Name)\n\t}\n\n\tif ccdata.Name != ccpack.depSpec.ChaincodeSpec.ChaincodeId.Name || ccdata.Version != ccpack.depSpec.ChaincodeSpec.ChaincodeId.Version {\n\t\treturn fmt.Errorf(\"invalid chaincode data %v (%v)\", ccdata, ccpack.depSpec.ChaincodeSpec.ChaincodeId)\n\t}\n\n\totherdata := &SignedCDSData{}\n\terr := proto.Unmarshal(ccdata.Data, otherdata)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif !proto.Equal(ccpack.data, otherdata) {\n\t\treturn errors.New(\"data mismatch\")\n\t}\n\n\treturn nil\n}\n\n// InitFromBuffer sets the buffer if valid and returns ChaincodeData\nfunc (ccpack *SignedCDSPackage) InitFromBuffer(buf []byte) (*ChaincodeData, error) {\n\tenv := &common.Envelope{}","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/common/ccprovider/sigcdspackage.go#L188-L224","documentation":"ValidateCC compares the name/version in the ChaincodeData against the name/version in the inner ChaincodeDeploymentSpec's ChaincodeId. A mismatch means the metadata and the deployment spec inside the package disagree, so the package is internally inconsistent.","triggerScenarios":"GetCCPackage -> ValidateCC on a package where ccdata.Name/Version differ from ccpack.depSpec.ChaincodeSpec.ChaincodeId.Name/Version, e.g. after editing one of them or mixing package parts.","commonSituations":"Manually editing the chaincode name or version in package metadata; combining a CDS from one package with metadata from another; upgrading chaincode but only updating part of the package.","solutions":["Rebuild the package so name and version match across ChaincodeData and ChaincodeDeploymentSpec","Use `peer chaincode package` / `peer chaincode signpackage` instead of hand-assembling packages","Ensure the install and upgrade flows use the same version string everywhere"],"exampleFix":"// before\nccdata.Version = \"v2\"; depSpec.ChaincodeSpec.ChaincodeId.Version = \"v1\" // mismatch\n// after\nccdata.Version = \"v1\"; depSpec.ChaincodeSpec.ChaincodeId.Version = \"v1\"","handlingStrategy":"validation","validationCode":"func consistentNameVersion(c *pb.ChaincodeData, cds *pb.ChaincodeDeploymentSpec) bool {\n    return c.Name == cds.ChaincodeSpec.ChaincodeId.Name &&\n        c.Version == cds.ChaincodeSpec.ChaincodeId.Version\n}","typeGuard":"func matchesSpec(c *pb.ChaincodeData, cds *pb.ChaincodeDeploymentSpec) bool {\n    return c != nil && cds != nil && consistentNameVersion(c, cds)\n}","tryCatchPattern":"cd, err := GetCCPackage(buf, idFunc)\nif err != nil {\n    if strings.Contains(err.Error(), \"invalid chaincode data\") {\n        return fmt.Errorf(\"package metadata/spec mismatch; rebuild with peer chaincode package: %w\", err)\n    }\n    return err\n}","preventionTips":["Always set name/version in one place when packaging","Regenerate the whole package on upgrade instead of patching parts","Keep install/upgrade scripts using a single source of truth for version strings"],"tags":["chaincode","packaging","fabric","version-mismatch"],"backgroundTag":"chaincode-version-mismatch","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"}