hyperledger/fabric · error

expected cc version %s, found %s

Error message

expected cc version %s, found %s

What it means

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.

Source

Thrown at core/handlers/validation/builtin/v12/validation_logic.go:621

			return policyErr(fmt.Errorf("LSCC must issue at least one single putState upon deploy/upgrade"))
		}
		// the first key name must be the chaincode id provided in the deployment spec
		if lsccrwset.Writes[0].Key != cdsArgs.ChaincodeSpec.ChaincodeId.Name {
			return policyErr(fmt.Errorf("expected key %s, found %s", cdsArgs.ChaincodeSpec.ChaincodeId.Name, lsccrwset.Writes[0].Key))
		}
		// the value must be a ChaincodeData struct
		cdRWSet := &ccprovider.ChaincodeData{}
		err = proto.Unmarshal(lsccrwset.Writes[0].Value, cdRWSet)
		if err != nil {
			return policyErr(fmt.Errorf("unmarshalling of ChaincodeData failed, error %s", err))
		}
		// the chaincode name in the lsccwriteset must match the chaincode name in the deployment spec
		if cdRWSet.Name != cdsArgs.ChaincodeSpec.ChaincodeId.Name {
			return policyErr(fmt.Errorf("expected cc name %s, found %s", cdsArgs.ChaincodeSpec.ChaincodeId.Name, cdRWSet.Name))
		}
		// the chaincode version in the lsccwriteset must match the chaincode version in the deployment spec
		if cdRWSet.Version != cdsArgs.ChaincodeSpec.ChaincodeId.Version {
			return policyErr(fmt.Errorf("expected cc version %s, found %s", cdsArgs.ChaincodeSpec.ChaincodeId.Version, cdRWSet.Version))
		}
		// it must only write to 2 namespaces: LSCC's and the cc that we are deploying/upgrading
		for _, ns := range txRWSet.NsRwSets {
			if ns.NameSpace != "lscc" && ns.NameSpace != cdRWSet.Name && len(ns.KvRwSet.Writes) > 0 {
				return policyErr(fmt.Errorf("LSCC invocation is attempting to write to namespace %s", ns.NameSpace))
			}
		}

		logger.Debugf("Validating %s for cc %s version %s", lsccFunc, cdRWSet.Name, cdRWSet.Version)

		switch lsccFunc {
		case lscc.DEPLOY:

			/******************************************************************/
			/* security check 1 - cc not in the LCCC table of instantiated cc */
			/******************************************************************/
			if ccExistsOnLedger {
				return policyErr(fmt.Errorf("Chaincode %s is already instantiated", cdsArgs.ChaincodeSpec.ChaincodeId.Name))

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Rebuild/install the chaincode package with the new version string and use the same version in the upgrade request.
  2. Ensure ChaincodeSpec.ChaincodeId.Version matches the version lscc simulates (same package).
  3. Clear SDK-side cached deployment specs and rebuild the upgrade proposal.
  4. Re-endorse and resubmit instead of replaying older envelopes.

Example fix

// before
request.chaincodeVersion = '1.0' // upgrading with stale version
// after
request.chaincodeVersion = '2.0' // matches repackaged chaincode
Defensive patterns

Strategy: validation

Validate before calling

if cdRWSet.Version != chaincodeSpec.ChaincodeId.Version {
    return fmt.Errorf("ChaincodeData version %q != spec version %q", cdRWSet.Version, chaincodeSpec.ChaincodeId.Version)
}

Type guard

func versionMatchesSpec(cd *ccprovider.ChaincodeData, spec *pb.ChaincodeSpec) bool {
    return cd != nil && cd.Version == spec.ChaincodeId.Version
}

Try / catch

if err := submitTx(envelope); err != nil {
    if strings.Contains(err.Error(), "expected cc version ") {
        // rebuild package with correct version and redo install + upgrade
    }
}

Prevention

When it happens

Trigger: 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).

Common situations: Upgrade attempts where the chaincode package was not rebuilt with the new version; SDK caching an old ChaincodeData; manual envelope construction mixing versions.

Related errors


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/5869e83a2ea31f93. Report an issue: GitHub.