{"record":{"id":"5569a0547a424a5a","repo":"hyperledger/fabric","slug":"requested-sequence-d-is-larger-than-the-next-avai","errorCode":null,"errorMessage":"requested sequence %d is larger than the next available sequence number %d","messagePattern":"requested sequence (.+?) is larger than the next available sequence number (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/lifecycle/lifecycle.go","lineNumber":439,"sourceCode":"func (ef *ExternalFunctions) ApproveChaincodeDefinitionForOrg(chname, ccname string, cd *ChaincodeDefinition, packageID string, publicState ReadableState, orgState ReadWritableState) error {\n\t// Get the current sequence from the public state\n\tcurrentSequence, err := ef.Resources.Serializer.DeserializeFieldAsInt64(NamespacesName, ccname, \"Sequence\", publicState)\n\tif err != nil {\n\t\treturn errors.WithMessage(err, \"could not get current sequence\")\n\t}\n\n\trequestedSequence := cd.Sequence\n\n\tif currentSequence == requestedSequence && requestedSequence == 0 {\n\t\treturn errors.Errorf(\"requested sequence is 0, but first definable sequence number is 1\")\n\t}\n\n\tif requestedSequence < currentSequence {\n\t\treturn errors.Errorf(\"currently defined sequence %d is larger than requested sequence %d\", currentSequence, requestedSequence)\n\t}\n\n\tif requestedSequence > currentSequence+1 {\n\t\treturn errors.Errorf(\"requested sequence %d is larger than the next available sequence number %d\", requestedSequence, currentSequence+1)\n\t}\n\n\tif err := ef.SetChaincodeDefinitionDefaults(chname, cd); err != nil {\n\t\treturn errors.WithMessagef(err, \"could not set defaults for chaincode definition in channel %s\", chname)\n\t}\n\n\tprivateName := fmt.Sprintf(\"%s#%d\", ccname, requestedSequence)\n\n\tif requestedSequence == currentSequence {\n\t\tmetadata, ok, err := ef.Resources.Serializer.DeserializeMetadata(NamespacesName, ccname, publicState)\n\t\tif err != nil {\n\t\t\treturn errors.WithMessage(err, \"could not fetch metadata for current definition\")\n\t\t}\n\t\tif !ok {\n\t\t\treturn errors.Errorf(\"missing metadata for currently committed sequence number (%d)\", currentSequence)\n\t\t}\n\n\t\tdefinedChaincode := &ChaincodeDefinition{}","sourceCodeStart":421,"sourceCodeEnd":457,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/lifecycle/lifecycle.go#L421-L457","documentation":"The requested sequence skips ahead: it is greater than currentSequence+1, leaving a gap in the strictly consecutive definition history. Lifecycle requires each new definition to be exactly one greater than the last committed one.","triggerScenarios":"Approving with --sequence 5 when only sequence 2 is committed; teams bumping sequences arbitrarily or hard-coding high sequence numbers after multiple failed attempts.","commonSituations":"Operators 'jumping' sequences hoping to bypass a failed definition; CI pipelines incrementing a cached counter across retries.","solutions":["Approve with exactly currentSequence+1 based on the committed sequence","Reset any cached/incremented sequence counters in CI to derive from querycommitted output","Re-run the approval for the skipped sequences in order if intermediate definitions are needed"],"exampleFix":"// before\npeer lifecycle chaincode approveformyorg -C mychannel --sequence 5  # current=2\n// after\npeer lifecycle chaincode approveformyorg -C mychannel --sequence 3  # current+1","handlingStrategy":"validation","validationCode":"// Enforce sequence == committed+1\ncurrent := queryCommittedSequence(ch, ccname)\nif def.Sequence != current+1 {\n    return fmt.Errorf(\"sequence must be %d (committed %d + 1), got %d\", current+1, current, def.Sequence)\n}","typeGuard":null,"tryCatchPattern":"err := ef.ApproveChaincodeDefinitionForOrg(...)\nif err != nil && strings.Contains(err.Error(), \"larger than the next available sequence\") {\n    // set def.Sequence = current+1 and retry\n}","preventionTips":["Compute next sequence from querycommitted, never from cached counters","Reset CI sequence counters per deployment run","Reject configs that skip sequences in pre-flight checks"],"tags":["fabric","lifecycle","sequence-number"],"backgroundTag":"invalid-sequence-number","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"}