hyperledger/fabric · error

collection-name: %s -- requiredPeerCount (%d) cannot be less

Error message

collection-name: %s -- requiredPeerCount (%d) cannot be less than zero (%d)

What it means

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.

Source

Thrown at core/handlers/validation/builtin/v13/lscc_validation_logic.go:90

		if err := validateCollectionName(collectionName); err != nil {
			return err
		}

		if _, ok := newCollectionsMap[collectionName]; !ok {
			newCollectionsMap[collectionName] = true
		} else {
			return fmt.Errorf("collection-name: %s -- found duplicate collection configuration", collectionName)
		}

		// Validate gossip related parameters present in the collection config
		maximumPeerCount := newCollection.GetMaximumPeerCount()
		requiredPeerCount := newCollection.GetRequiredPeerCount()
		if maximumPeerCount < requiredPeerCount {
			return fmt.Errorf("collection-name: %s -- maximum peer count (%d) cannot be less than the required peer count (%d)",
				collectionName, maximumPeerCount, requiredPeerCount)
		}
		if requiredPeerCount < 0 {
			return fmt.Errorf("collection-name: %s -- requiredPeerCount (%d) cannot be less than zero (%d)",
				collectionName, maximumPeerCount, requiredPeerCount)
		}

		// make sure that the signature policy is meaningful (only consists of ORs)
		err := validateSpOrConcat(newCollection.MemberOrgsPolicy.GetSignaturePolicy().Rule)
		if err != nil {
			return errors.WithMessagef(err, "collection-name: %s -- error in member org policy", collectionName)
		}
	}
	return nil
}

// validateSpOrConcat checks if the supplied signature policy is just an OR-concatenation of identities
func validateSpOrConcat(sp *common.SignaturePolicy) error {
	if sp.GetNOutOf() == nil {
		return nil
	}
	// check if N == 1 (OR concatenation)

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Set requiredPeerCount to 0 or a positive integer in the collection config
  2. Validate all collection configs before submission: reject any entry with requiredPeerCount < 0
  3. If values come from generated code or computed logic, check for integer underflow or uninitialized fields

Example fix

// before
{"name": "coll1", "requiredPeerCount": -1, "maxPeerCount": 3}
// after
{"name": "coll1", "requiredPeerCount": 1, "maxPeerCount": 3}
Defensive patterns

Strategy: validation

Validate before calling

function validateCollectionConfig(c) {
  if (c.requiredPeerCount < 0) {
    throw new Error(`collection ${c.name}: requiredPeerCount must be >= 0`);
  }
}

Type guard

function hasNonNegativeRequiredPeerCount(c) {
  return Number.isInteger(c.requiredPeerCount) && c.requiredPeerCount >= 0;
}

Try / catch

try {
  await contract.submitTransaction('DeployChaincode', ...args);
} catch (err) {
  if (String(err).includes('cannot be less than zero')) {
    // correct requiredPeerCount in the collections config
  }
  throw err;
}

Prevention

When it happens

Trigger: Submitting a collection config where StaticCollectionConfig.RequiredPeerCount < 0, e.g. requiredPeerCount=-1, via lifecycle chaincode commit with --collections-config or a crafted CollectionConfigPackage.

Common situations: 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.

Related errors


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