{"record":{"id":"63a8123bc6495142","repo":"hyperledger/fabric","slug":"upgrading-non-existent-chaincode-s-63a812","errorCode":null,"errorMessage":"Upgrading non-existent chaincode %s","messagePattern":"Upgrading non-existent chaincode (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/handlers/validation/builtin/v13/lscc_validation_logic.go","lineNumber":538,"sourceCode":"\t\t\tif pol == nil {\n\t\t\t\treturn policyErr(fmt.Errorf(\"no instantiation policy was specified\"))\n\t\t\t}\n\t\t\t// FIXME: could we actually pull the cds package from the\n\t\t\t// file system to verify whether the policy that is specified\n\t\t\t// here is the same as the one on disk?\n\t\t\t// PROS: we prevent attacks where the policy is replaced\n\t\t\t// CONS: this would be a point of non-determinism\n\t\t\terr := vscc.checkInstantiationPolicy(chid, env, pol, payl)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\n\t\tcase lscc.UPGRADE:\n\t\t\t/**************************************************************/\n\t\t\t/* security check 1 - cc in the LCCC table of instantiated cc */\n\t\t\t/**************************************************************/\n\t\t\tif !ccExistsOnLedger {\n\t\t\t\treturn policyErr(fmt.Errorf(\"Upgrading non-existent chaincode %s\", cdsArgs.ChaincodeSpec.ChaincodeId.Name))\n\t\t\t}\n\n\t\t\t/**********************************************************/\n\t\t\t/* security check 2 - existing cc's version was different */\n\t\t\t/**********************************************************/\n\t\t\tif cdLedger.Version == cdsArgs.ChaincodeSpec.ChaincodeId.Version {\n\t\t\t\treturn policyErr(fmt.Errorf(\"Existing version of the cc on the ledger (%s) should be different from the upgraded one\", cdsArgs.ChaincodeSpec.ChaincodeId.Version))\n\t\t\t}\n\n\t\t\t/****************************************************************************/\n\t\t\t/* security check 3 validation of rwset (and of collections if enabled) */\n\t\t\t/****************************************************************************/\n\t\t\t// Only in v1.2, a collection can be updated during a chaincode upgrade\n\t\t\tif ac.V1_2Validation() {\n\t\t\t\t// do extra validation for collections\n\t\t\t\terr := vscc.validateRWSetAndCollection(lsccrwset, cdRWSet, lsccArgs, lsccFunc, ac, chid)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn err","sourceCodeStart":520,"sourceCodeEnd":556,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/handlers/validation/builtin/v13/lscc_validation_logic.go#L520-L556","documentation":"On the lscc UPGRADE path, the validator requires the chaincode to already exist on the ledger (ccExistsOnLedger). Attempting to upgrade a chaincode that was never instantiated (or whose record is missing) fails this security check and the transaction is rejected.","triggerScenarios":"Submitting an lscc upgrade for a chaincode name with no ChaincodeData record on the channel — e.g. upgrading before ever instantiating, upgrading on the wrong channel, or after the chaincode's lscc record was removed.","commonSituations":"Typos in the chaincode name during upgrade, running upgrade scripts against a fresh channel where instantiate never ran, channel mix-ups (upgrade issued on channel B while deployed on channel A), ledger restored to a state before deployment.","solutions":["Instantiate (deploy) the chaincode first, then upgrade.","Verify the chaincode name and channel you are targeting with lscc getchaincodes.","Check for typos or casing differences in the chaincode name in the upgrade proposal.","Confirm peers have the chaincode installed and the ledger actually contains its record."],"exampleFix":"// before: upgrade on fresh channel\nclient.sendUpgradeProposal(req) // mycc never instantiated here\n// after\nif (!lscc.getChaincodes().contains(\"mycc\")) { client.sendInstantiateProposal(req); } else { client.sendUpgradeProposal(req); }","handlingStrategy":"validation","validationCode":"// check instantiation exists before upgrading\nresp, _ := lsccClient.Query(\"getchaincodes\")\nif !chaincodeListContains(resp, \"mycc\") {\n    return errors.New(\"mycc not instantiated on this channel; instantiate first\")\n}","typeGuard":"func isDeployed(codes []lscc.ChaincodeQueryResponse, name string) bool {\n    for _, c := range codes { if c.Name == name { return true } }\n    return false\n}","tryCatchPattern":"catch (err) { if (String(err).includes('Upgrading non-existent chaincode')) { /* verify channel and name, then run instantiate first */ } }","preventionTips":["Verify chaincode name and channel before upgrade","Run lifecycle queries (getchaincodes) in upgrade scripts","Keep deploy/upgrade pipelines ordered: install -> instantiate -> upgrade"],"tags":["hyperledger-fabric","lscc","upgrade","chaincode-not-found"],"backgroundTag":"chaincode-not-instantiated","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"}