{"record":{"id":"49c099c8615a6634","repo":"hyperledger/fabric","slug":"expected-initrequired-t-does-not-match-passed-i","errorCode":null,"errorMessage":"expected InitRequired '%t' does not match passed InitRequired '%t'","messagePattern":"expected InitRequired '%t' does not match passed InitRequired '%t'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/lifecycle/lifecycle.go","lineNumber":130,"sourceCode":"\n// ChaincodeParameters are the parts of the chaincode definition which are serialized\n// as values in the statedb.  It is expected that any instance will have no nil fields once initialized.\n// WARNING: This structure is serialized/deserialized from the DB, re-ordering or adding fields\n// will cause opaque checks to fail.\ntype ChaincodeParameters struct {\n\tEndorsementInfo *lb.ChaincodeEndorsementInfo\n\tValidationInfo  *lb.ChaincodeValidationInfo\n\tCollections     *pb.CollectionConfigPackage\n}\n\nfunc (cp *ChaincodeParameters) Equal(ocp *ChaincodeParameters) error {\n\tswitch {\n\tcase cp.EndorsementInfo.Version != ocp.EndorsementInfo.Version:\n\t\treturn errors.Errorf(\"expected Version '%s' does not match passed Version '%s'\", cp.EndorsementInfo.Version, ocp.EndorsementInfo.Version)\n\tcase cp.EndorsementInfo.EndorsementPlugin != ocp.EndorsementInfo.EndorsementPlugin:\n\t\treturn errors.Errorf(\"expected EndorsementPlugin '%s' does not match passed EndorsementPlugin '%s'\", cp.EndorsementInfo.EndorsementPlugin, ocp.EndorsementInfo.EndorsementPlugin)\n\tcase cp.EndorsementInfo.InitRequired != ocp.EndorsementInfo.InitRequired:\n\t\treturn errors.Errorf(\"expected InitRequired '%t' does not match passed InitRequired '%t'\", cp.EndorsementInfo.InitRequired, ocp.EndorsementInfo.InitRequired)\n\tcase cp.ValidationInfo.ValidationPlugin != ocp.ValidationInfo.ValidationPlugin:\n\t\treturn errors.Errorf(\"expected ValidationPlugin '%s' does not match passed ValidationPlugin '%s'\", cp.ValidationInfo.ValidationPlugin, ocp.ValidationInfo.ValidationPlugin)\n\tcase !bytes.Equal(cp.ValidationInfo.ValidationParameter, ocp.ValidationInfo.ValidationParameter):\n\t\treturn errors.Errorf(\"expected ValidationParameter '%x' does not match passed ValidationParameter '%x'\", cp.ValidationInfo.ValidationParameter, ocp.ValidationInfo.ValidationParameter)\n\tcase !proto.Equal(cp.Collections, ocp.Collections):\n\t\treturn errors.Errorf(\"Collections do not match\")\n\tdefault:\n\t}\n\treturn nil\n}\n\n// ChaincodeDefinition contains the chaincode parameters, as well as the sequence number of the definition.\n// Note, it does not embed ChaincodeParameters so as not to complicate the serialization.  It is expected\n// that any instance will have no nil fields once initialized.\n// WARNING: This structure is serialized/deserialized from the DB, re-ordering or adding fields\n// will cause opaque checks to fail.\ntype ChaincodeDefinition struct {\n\tSequence        int64","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/lifecycle/lifecycle.go#L112-L148","documentation":"Thrown by ChaincodeParameters.Equal when the InitRequired boolean in the new definition differs from the committed definition. The lifecycle system treats a change of init requirement as a redefinition that must go through a new sequence number.","triggerScenarios":"Committing a chaincode definition where EndorsementInfo.InitRequired differs from the stored definition; checked during commit-readiness/redefine comparison.","commonSituations":"Fabric v2.x chaincodes flipping --init-required on/off between approvals; one org approving with InitRequired=true and the operator re-committing with false without bumping the sequence.","solutions":["Set InitRequired to the same value as the committed definition, or bump the sequence number","Check the committed definition with 'peer lifecycle chaincode querycommitted' for the Requires-init flag","Re-approve consistently across all organizations with the intended InitRequired value"],"exampleFix":"// before\nInitRequired: true, sequence: 1 // committed has InitRequired=false\n// after\nInitRequired: false, sequence: 1 // or sequence: 2 with InitRequired: true","handlingStrategy":"validation","validationCode":"committed, err := lifecycle.QueryChaincodeDefinition(chname, ccname, publicState)\nif err == nil && newDef.EndorsementInfo.InitRequired != committed.EndorsementInfo.InitRequired && newDef.Sequence == committed.Sequence {\n    return fmt.Errorf(\"InitRequired change requires sequence bump\")\n}","typeGuard":"func sameInitRequired(a, b *lifecycle.ChaincodeParameters) bool {\n    return a != nil && b != nil && a.EndorsementInfo.InitRequired == b.EndorsementInfo.InitRequired\n}","tryCatchPattern":"if err := params.Equal(committedParams); err != nil {\n    if strings.Contains(err.Error(), \"InitRequired\") {\n        // re-approve with the committed InitRequired value or sequence+1\n    }\n    return err\n}","preventionTips":["Decide the init-required policy once per chaincode and record it in deployment scripts","Do not pass --init-required on re-approvals unless it is an intentional change with sequence+1","Verify the Requires-init flag with querycommitted after approval"],"tags":["hyperledger-fabric","lifecycle","init-required","definition-mismatch"],"backgroundTag":"chaincode-definition-mismatch","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}