hyperledger/fabric · error
Upgrading non-existent chaincode %s
Error message
Upgrading non-existent chaincode %s
What it means
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.
Source
Thrown at core/handlers/validation/builtin/v13/lscc_validation_logic.go:538
if pol == nil {
return policyErr(fmt.Errorf("no instantiation policy was specified"))
}
// FIXME: could we actually pull the cds package from the
// file system to verify whether the policy that is specified
// here is the same as the one on disk?
// PROS: we prevent attacks where the policy is replaced
// CONS: this would be a point of non-determinism
err := vscc.checkInstantiationPolicy(chid, env, pol, payl)
if err != nil {
return err
}
case lscc.UPGRADE:
/**************************************************************/
/* security check 1 - cc in the LCCC table of instantiated cc */
/**************************************************************/
if !ccExistsOnLedger {
return policyErr(fmt.Errorf("Upgrading non-existent chaincode %s", cdsArgs.ChaincodeSpec.ChaincodeId.Name))
}
/**********************************************************/
/* security check 2 - existing cc's version was different */
/**********************************************************/
if cdLedger.Version == cdsArgs.ChaincodeSpec.ChaincodeId.Version {
return policyErr(fmt.Errorf("Existing version of the cc on the ledger (%s) should be different from the upgraded one", cdsArgs.ChaincodeSpec.ChaincodeId.Version))
}
/****************************************************************************/
/* security check 3 validation of rwset (and of collections if enabled) */
/****************************************************************************/
// Only in v1.2, a collection can be updated during a chaincode upgrade
if ac.V1_2Validation() {
// do extra validation for collections
err := vscc.validateRWSetAndCollection(lsccrwset, cdRWSet, lsccArgs, lsccFunc, ac, chid)
if err != nil {
return errView on GitHub (pinned to 2736b63f8f)
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.
Example fix
// before: upgrade on fresh channel
client.sendUpgradeProposal(req) // mycc never instantiated here
// after
if (!lscc.getChaincodes().contains("mycc")) { client.sendInstantiateProposal(req); } else { client.sendUpgradeProposal(req); } Defensive patterns
Strategy: validation
Validate before calling
// check instantiation exists before upgrading
resp, _ := lsccClient.Query("getchaincodes")
if !chaincodeListContains(resp, "mycc") {
return errors.New("mycc not instantiated on this channel; instantiate first")
} Type guard
func isDeployed(codes []lscc.ChaincodeQueryResponse, name string) bool {
for _, c := range codes { if c.Name == name { return true } }
return false
} Try / catch
catch (err) { if (String(err).includes('Upgrading non-existent chaincode')) { /* verify channel and name, then run instantiate first */ } } Prevention
- Verify chaincode name and channel before upgrade
- Run lifecycle queries (getchaincodes) in upgrade scripts
- Keep deploy/upgrade pipelines ordered: install -> instantiate -> upgrade
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- lscc's state for [%s] not found.
- Existing version of the cc on the ledger (%s) should be diff
- LSCC can only issue a single putState upon upgrade
- chaincode %s not found
- failed unmarshalling lscc read value into ChaincodeData
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/63a8123bc6495142.
Report an issue: GitHub.