hyperledger/fabric · error

currently defined sequence %d is larger than requested seque

Error message

currently defined sequence %d is larger than requested sequence %d

What it means

ApproveChaincodeDefinitionForOrg guard: the org's approval request names a sequence number that is lower than the sequence already committed in public state, so approving it would move the definition backwards.

Source

Thrown at core/chaincode/lifecycle/lifecycle.go:435

// ApproveChaincodeDefinitionForOrg adds a chaincode definition entry into the passed in Org state.  The definition must be
// for either the currently defined sequence number or the next sequence number.  If the definition is
// for the current sequence number, then it must match exactly the current definition or it will be rejected.
func (ef *ExternalFunctions) ApproveChaincodeDefinitionForOrg(chname, ccname string, cd *ChaincodeDefinition, packageID string, publicState ReadableState, orgState ReadWritableState) error {
	// Get the current sequence from the public state
	currentSequence, err := ef.Resources.Serializer.DeserializeFieldAsInt64(NamespacesName, ccname, "Sequence", publicState)
	if err != nil {
		return errors.WithMessage(err, "could not get current sequence")
	}

	requestedSequence := cd.Sequence

	if currentSequence == requestedSequence && requestedSequence == 0 {
		return errors.Errorf("requested sequence is 0, but first definable sequence number is 1")
	}

	if requestedSequence < currentSequence {
		return errors.Errorf("currently defined sequence %d is larger than requested sequence %d", currentSequence, requestedSequence)
	}

	if requestedSequence > currentSequence+1 {
		return errors.Errorf("requested sequence %d is larger than the next available sequence number %d", requestedSequence, currentSequence+1)
	}

	if err := ef.SetChaincodeDefinitionDefaults(chname, cd); err != nil {
		return errors.WithMessagef(err, "could not set defaults for chaincode definition in channel %s", chname)
	}

	privateName := fmt.Sprintf("%s#%d", ccname, requestedSequence)

	if requestedSequence == currentSequence {
		metadata, ok, err := ef.Resources.Serializer.DeserializeMetadata(NamespacesName, ccname, publicState)
		if err != nil {
			return errors.WithMessage(err, "could not fetch metadata for current definition")
		}
		if !ok {

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Query the committed sequence ('peer lifecycle chaincode querycommitted -C mychannel') and approve with currentSequence+1
  2. Stop replaying stale approve commands; regenerate scripts with the up-to-date sequence
  3. If the downgrade was intentional, it is not supported — create a new definition at the next sequence instead

Example fix

// before
peer lifecycle chaincode approveformyorg -C mychannel --sequence 1  # committed=2
// after
peer lifecycle chaincode approveformyorg -C mychannel --sequence 3  # current+1
Defensive patterns

Strategy: validation

Validate before calling

// Compare against the committed sequence before approving
committed := queryCommittedSequence(ch, ccname) // via querycommitted
if def.Sequence < committed {
    return fmt.Errorf("requested %d < committed %d; use %d", def.Sequence, committed, committed+1)
}

Try / catch

err := ef.ApproveChaincodeDefinitionForOrg(...)
if err != nil && strings.Contains(err.Error(), "is larger than requested sequence") {
    // refresh sequence from querycommitted and retry with committed+1
}

Prevention

When it happens

Trigger: Approving a definition whose Sequence field is less than the current committed sequence — e.g., re-running an old approve command with --sequence 1 after sequence 2 is already committed, or deploying a chaincode package built from a stale definition.

Common situations: Replaying old scripts after an upgrade; two teams using divergent sequence numbers; rebuilding a peer's org approval from an old checkout.

Related errors


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