{"record":{"id":"d6a9a4c3e34a4199","repo":"hyperledger/fabric","slug":"requested-sequence-is-0-but-first-definable-seque","errorCode":null,"errorMessage":"requested sequence is 0, but first definable sequence number is 1","messagePattern":"requested sequence is 0, but first definable sequence number is 1","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/lifecycle/lifecycle.go","lineNumber":431,"sourceCode":"\t}\n\n\treturn nil\n}\n\n// ApproveChaincodeDefinitionForOrg adds a chaincode definition entry into the passed in Org state.  The definition must be\n// for either the currently defined sequence number or the next sequence number.  If the definition is\n// for the current sequence number, then it must match exactly the current definition or it will be rejected.\nfunc (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)","sourceCodeStart":413,"sourceCodeEnd":449,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/lifecycle/lifecycle.go#L413-L449","documentation":"The approved chaincode definition was submitted with Sequence 0 while the currently committed sequence for the namespace is also 0 (nothing committed yet). Lifecycle requires the first definable sequence to be 1, so a zero sequence is invalid in every case.","triggerScenarios":"Calling ApproveChaincodeDefinitionForOrg (or 'peer lifecycle chaincode approveformyorg') with --sequence 0 for a chaincode that has never been defined on the channel.","commonSituations":"Copy-paste of approve commands with an unset/placeholder sequence value; scripts computing sequence numbers incorrectly; first-time deployment where operators forget the sequence starts at 1.","solutions":["Resubmit the approval with --sequence 1 for the first definition","Compute the next sequence as (last committed sequence + 1) via querycommitted","Fix deployment scripts to default the sequence to 1 when no prior definition exists"],"exampleFix":"// before\npeer lifecycle chaincode approveformyorg -C mychannel --sequence 0\n// after\npeer lifecycle chaincode approveformyorg -C mychannel --sequence 1","handlingStrategy":"validation","validationCode":"// Ensure sequence >= 1 before approving\nif def.Sequence < 1 {\n    return fmt.Errorf(\"sequence must be >= 1 for first definition; got %d\", def.Sequence)\n}\n// then approve","typeGuard":"func validFirstSequence(seq int64) bool { return seq >= 1 }","tryCatchPattern":"err := ef.ApproveChaincodeDefinitionForOrg(...)\nif err != nil && strings.Contains(err.Error(), \"first definable sequence number is 1\") {\n    def.Sequence = 1\n    err = ef.ApproveChaincodeDefinitionForOrg(...)\n}","preventionTips":["Never hard-code 0 as a sequence; default first deployment to 1","Derive sequence numbers from querycommitted output in scripts","Add pre-flight asserts in CI that sequence >= 1"],"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"}