hyperledger/fabric · warning

chaincode cache at sequence %d but current sequence is %d, c

Error message

chaincode cache at sequence %d but current sequence is %d, chaincode definition for '%s' changed during invoke

What it means

CachedChaincodeInfo detects that the chaincode definition sequence in the lifecycle cache differs from the sequence read from the current query executor's committed state. Per the source comment, the cache can be ahead of committed state but never behind, so this transient condition means the chaincode definition changed while the invoke was executing; the transaction must be aborted and re-executed with a fresh query executor.

Source

Thrown at core/chaincode/lifecycle/endorsement_info.go:85

		return nil, false, errors.WithMessagef(err, "could not get current sequence for chaincode '%s' on channel '%s'", chaincodeName, channelID)
	}

	// Committed sequences begin at 1
	if currentSequence == 0 {
		return nil, false, nil
	}

	chaincodeInfo, err := cei.Cache.ChaincodeInfo(channelID, chaincodeName)
	if err != nil {
		return nil, false, errors.WithMessage(err, "could not get approved chaincode info from cache")
	}

	if chaincodeInfo.Definition.Sequence != currentSequence {
		// TODO this is a transient error which indicates that this query executor is executing against a chaincode
		// whose definition has already changed (the cache may be ahead of the committed state, but never behind).  In this
		// case, we should simply abort the tx, and re-acquire a query executor and re-execute.  There is no reason this
		// error needs to be returned to the client.
		return nil, false, errors.Errorf("chaincode cache at sequence %d but current sequence is %d, chaincode definition for '%s' changed during invoke", chaincodeInfo.Definition.Sequence, currentSequence, chaincodeName)
	}

	if !chaincodeInfo.Approved {
		return nil, false, errors.Errorf("chaincode definition for '%s' at sequence %d on channel '%s' has not yet been approved by this org", chaincodeName, currentSequence, channelID)
	}

	if chaincodeInfo.InstallInfo == nil {
		if cei.UserRunsCC {
			chaincodeInfo.InstallInfo = &ChaincodeInstallInfo{
				PackageID: chaincodeName + ":" + chaincodeInfo.Definition.EndorsementInfo.Version,
			}
			return chaincodeInfo, true, nil
		}
		return nil, false, errors.Errorf("chaincode definition for '%s' exists, but chaincode is not installed", chaincodeName)
	}

	return chaincodeInfo, true, nil
}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Retry the transaction — the error is explicitly designed to be transient and retried with a fresh query executor.
  2. Coordinate chaincode upgrades with deployment downtime or retry logic in the client SDK.
  3. Enable client-side retry-on-error for transient lifecycle errors during upgrade windows.

Example fix

// before: single attempt
resp := await contract.submitTransaction('tx', arg)
// after: retry transient 'changed during invoke'
for i := 0; i < 3; i++ {
  resp, err = submit(); if err == nil || !strings.Contains(err.Error(), "changed during invoke") { break }
  time.Sleep(time.Second)
}
Defensive patterns

Strategy: retry

Validate before calling

// Go: read current sequence before submit and retry on mismatch
defn, _ := client.Lifecycle().QueryChaincodeDefinition(ccName, channel)
// submit; if 'changed during invoke' error, re-read defn.Sequence and retry

Try / catch

err := contract.SubmitTransaction("tx", arg)
if err != nil && strings.Contains(err.Error(), "changed during invoke") {
  // transient: rebuild tx with fresh query executor and retry
  time.Sleep(500 * time.Millisecond); return submitWithRetry()
}

Prevention

When it happens

Trigger: A chaincode definition commit (sequence bump) lands on the channel while an invocation of that chaincode is mid-flight using a query executor snapshot from the older sequence; ChaincodeEndorsementInfo then calls CachedChaincodeInfo and the sequences mismatch.

Common situations: Committing a chaincode upgrade concurrently with live traffic; long-running invocations overlapping an upgrade window; multiple orgs committing definitions while endorsements are in progress.

Related errors


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