{"record":{"id":"5869e83a2ea31f93","repo":"hyperledger/fabric","slug":"expected-cc-version-s-found-s","errorCode":null,"errorMessage":"expected cc version %s, found %s","messagePattern":"expected cc version (.+?), found (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/handlers/validation/builtin/v12/validation_logic.go","lineNumber":621,"sourceCode":"\t\t\treturn policyErr(fmt.Errorf(\"LSCC must issue at least one single putState upon deploy/upgrade\"))\n\t\t}\n\t\t// the first key name must be the chaincode id provided in the deployment spec\n\t\tif lsccrwset.Writes[0].Key != cdsArgs.ChaincodeSpec.ChaincodeId.Name {\n\t\t\treturn policyErr(fmt.Errorf(\"expected key %s, found %s\", cdsArgs.ChaincodeSpec.ChaincodeId.Name, lsccrwset.Writes[0].Key))\n\t\t}\n\t\t// the value must be a ChaincodeData struct\n\t\tcdRWSet := &ccprovider.ChaincodeData{}\n\t\terr = proto.Unmarshal(lsccrwset.Writes[0].Value, cdRWSet)\n\t\tif err != nil {\n\t\t\treturn policyErr(fmt.Errorf(\"unmarshalling of ChaincodeData failed, error %s\", err))\n\t\t}\n\t\t// the chaincode name in the lsccwriteset must match the chaincode name in the deployment spec\n\t\tif cdRWSet.Name != cdsArgs.ChaincodeSpec.ChaincodeId.Name {\n\t\t\treturn policyErr(fmt.Errorf(\"expected cc name %s, found %s\", cdsArgs.ChaincodeSpec.ChaincodeId.Name, cdRWSet.Name))\n\t\t}\n\t\t// the chaincode version in the lsccwriteset must match the chaincode version in the deployment spec\n\t\tif cdRWSet.Version != cdsArgs.ChaincodeSpec.ChaincodeId.Version {\n\t\t\treturn policyErr(fmt.Errorf(\"expected cc version %s, found %s\", cdsArgs.ChaincodeSpec.ChaincodeId.Version, cdRWSet.Version))\n\t\t}\n\t\t// it must only write to 2 namespaces: LSCC's and the cc that we are deploying/upgrading\n\t\tfor _, ns := range txRWSet.NsRwSets {\n\t\t\tif ns.NameSpace != \"lscc\" && ns.NameSpace != cdRWSet.Name && len(ns.KvRwSet.Writes) > 0 {\n\t\t\t\treturn policyErr(fmt.Errorf(\"LSCC invocation is attempting to write to namespace %s\", ns.NameSpace))\n\t\t\t}\n\t\t}\n\n\t\tlogger.Debugf(\"Validating %s for cc %s version %s\", lsccFunc, cdRWSet.Name, cdRWSet.Version)\n\n\t\tswitch lsccFunc {\n\t\tcase lscc.DEPLOY:\n\n\t\t\t/******************************************************************/\n\t\t\t/* security check 1 - cc not in the LCCC table of instantiated cc */\n\t\t\t/******************************************************************/\n\t\t\tif ccExistsOnLedger {\n\t\t\t\treturn policyErr(fmt.Errorf(\"Chaincode %s is already instantiated\", cdsArgs.ChaincodeSpec.ChaincodeId.Name))","sourceCodeStart":603,"sourceCodeEnd":639,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/handlers/validation/builtin/v12/validation_logic.go#L603-L639","documentation":"The ChaincodeData.Version written by lscc must match the version in the deployment spec. Mismatch means the ledger would record a different chaincode version than the transaction claims to deploy, so validation rejects it.","triggerScenarios":"cdRWSet.Version != cdsArgs.ChaincodeSpec.ChaincodeId.Version — e.g. upgrading 'mycc' to version 2.0 but the rwset records version 1.0 (stale package, wrong spec, or replayed endorsement).","commonSituations":"Upgrade attempts where the chaincode package was not rebuilt with the new version; SDK caching an old ChaincodeData; manual envelope construction mixing versions.","solutions":["Rebuild/install the chaincode package with the new version string and use the same version in the upgrade request.","Ensure ChaincodeSpec.ChaincodeId.Version matches the version lscc simulates (same package).","Clear SDK-side cached deployment specs and rebuild the upgrade proposal.","Re-endorse and resubmit instead of replaying older envelopes."],"exampleFix":"// before\nrequest.chaincodeVersion = '1.0' // upgrading with stale version\n// after\nrequest.chaincodeVersion = '2.0' // matches repackaged chaincode","handlingStrategy":"validation","validationCode":"if cdRWSet.Version != chaincodeSpec.ChaincodeId.Version {\n    return fmt.Errorf(\"ChaincodeData version %q != spec version %q\", cdRWSet.Version, chaincodeSpec.ChaincodeId.Version)\n}","typeGuard":"func versionMatchesSpec(cd *ccprovider.ChaincodeData, spec *pb.ChaincodeSpec) bool {\n    return cd != nil && cd.Version == spec.ChaincodeId.Version\n}","tryCatchPattern":"if err := submitTx(envelope); err != nil {\n    if strings.Contains(err.Error(), \"expected cc version \") {\n        // rebuild package with correct version and redo install + upgrade\n    }\n}","preventionTips":["Bump the chaincode version on every package rebuild","Use the same version string in install and upgrade calls","Clear stale cached specs in the SDK before upgrading"],"tags":["hyperledger-fabric","lscc","chaincode-version","transaction-validation"],"backgroundTag":"chaincode-deploy-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"}