{"record":{"id":"df5233305f2040a8","repo":"hyperledger/fabric","slug":"collection-name-s-requiredpeercount-d-cann-df5233","errorCode":null,"errorMessage":"collection-name: %s -- requiredPeerCount (%d) cannot be less than zero (%d)","messagePattern":"collection-name: (.+?) -- requiredPeerCount \\((.+?)\\) cannot be less than zero \\((.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/handlers/validation/builtin/v13/lscc_validation_logic.go","lineNumber":90,"sourceCode":"\t\tif err := validateCollectionName(collectionName); err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tif _, ok := newCollectionsMap[collectionName]; !ok {\n\t\t\tnewCollectionsMap[collectionName] = true\n\t\t} else {\n\t\t\treturn fmt.Errorf(\"collection-name: %s -- found duplicate collection configuration\", collectionName)\n\t\t}\n\n\t\t// Validate gossip related parameters present in the collection config\n\t\tmaximumPeerCount := newCollection.GetMaximumPeerCount()\n\t\trequiredPeerCount := newCollection.GetRequiredPeerCount()\n\t\tif maximumPeerCount < requiredPeerCount {\n\t\t\treturn fmt.Errorf(\"collection-name: %s -- maximum peer count (%d) cannot be less than the required peer count (%d)\",\n\t\t\t\tcollectionName, maximumPeerCount, requiredPeerCount)\n\t\t}\n\t\tif requiredPeerCount < 0 {\n\t\t\treturn fmt.Errorf(\"collection-name: %s -- requiredPeerCount (%d) cannot be less than zero (%d)\",\n\t\t\t\tcollectionName, maximumPeerCount, requiredPeerCount)\n\t\t}\n\n\t\t// make sure that the signature policy is meaningful (only consists of ORs)\n\t\terr := validateSpOrConcat(newCollection.MemberOrgsPolicy.GetSignaturePolicy().Rule)\n\t\tif err != nil {\n\t\t\treturn errors.WithMessagef(err, \"collection-name: %s -- error in member org policy\", collectionName)\n\t\t}\n\t}\n\treturn nil\n}\n\n// validateSpOrConcat checks if the supplied signature policy is just an OR-concatenation of identities\nfunc validateSpOrConcat(sp *common.SignaturePolicy) error {\n\tif sp.GetNOutOf() == nil {\n\t\treturn nil\n\t}\n\t// check if N == 1 (OR concatenation)","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/handlers/validation/builtin/v13/lscc_validation_logic.go#L72-L108","documentation":"Thrown by validateNewCollectionConfigs when a private data collection's requiredPeerCount is negative. requiredPeerCount specifies how many peers must receive the private data for it to be considered distributed; a negative value is meaningless, so the transaction is rejected. Note the error message mistakenly prints maximumPeerCount for the first %d but the condition checks requiredPeerCount < 0.","triggerScenarios":"Submitting a collection config where StaticCollectionConfig.RequiredPeerCount < 0, e.g. requiredPeerCount=-1, via lifecycle chaincode commit with --collections-config or a crafted CollectionConfigPackage.","commonSituations":"Signed-integer underflow or a default/uninitialized int32 field in generated protobuf code; misconfigured JSON with a negative number; programmatic config generation that subtracts from requiredPeerCount.","solutions":["Set requiredPeerCount to 0 or a positive integer in the collection config","Validate all collection configs before submission: reject any entry with requiredPeerCount < 0","If values come from generated code or computed logic, check for integer underflow or uninitialized fields"],"exampleFix":"// before\n{\"name\": \"coll1\", \"requiredPeerCount\": -1, \"maxPeerCount\": 3}\n// after\n{\"name\": \"coll1\", \"requiredPeerCount\": 1, \"maxPeerCount\": 3}","handlingStrategy":"validation","validationCode":"function validateCollectionConfig(c) {\n  if (c.requiredPeerCount < 0) {\n    throw new Error(`collection ${c.name}: requiredPeerCount must be >= 0`);\n  }\n}","typeGuard":"function hasNonNegativeRequiredPeerCount(c) {\n  return Number.isInteger(c.requiredPeerCount) && c.requiredPeerCount >= 0;\n}","tryCatchPattern":"try {\n  await contract.submitTransaction('DeployChaincode', ...args);\n} catch (err) {\n  if (String(err).includes('cannot be less than zero')) {\n    // correct requiredPeerCount in the collections config\n  }\n  throw err;\n}","preventionTips":["Validate all numeric fields are non-negative before submitting","Watch for signed-int underflow when computing peer counts programmatically","Never leave numeric fields unset when relying on protobuf defaults"],"tags":["hyperledger-fabric","private-data","collection-config","validation"],"backgroundTag":"invalid-collection-config","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"}