hyperledger/fabric · error
Attempted to set the batch size max message count to an inva
Error message
Attempted to set the batch size max message count to an invalid value: 0
What it means
OrdererConfig.Validate() calls validateBatchSize, which requires BatchSize.MaxMessageCount to be non-zero. A value of 0 would allow batches of unlimited/unusable message counts, so the library rejects it during orderer config validation. This is a semantic validation of the ab.BatchSize proto decoded from the Orderer group.
Source
Thrown at common/channelconfig/orderer.go:216
return capabilities.NewOrdererProvider(oc.protos.Capabilities.Capabilities)
}
func (oc *OrdererConfig) Validate() error {
for _, validator := range []func() error{
oc.validateBatchSize,
oc.validateBatchTimeout,
} {
if err := validator(); err != nil {
return err
}
}
return nil
}
func (oc *OrdererConfig) validateBatchSize() error {
if oc.protos.BatchSize.MaxMessageCount == 0 {
return fmt.Errorf("Attempted to set the batch size max message count to an invalid value: 0")
}
if oc.protos.BatchSize.AbsoluteMaxBytes == 0 {
return fmt.Errorf("Attempted to set the batch size absolute max bytes to an invalid value: 0")
}
if oc.protos.BatchSize.PreferredMaxBytes == 0 {
return fmt.Errorf("Attempted to set the batch size preferred max bytes to an invalid value: 0")
}
if oc.protos.BatchSize.PreferredMaxBytes > oc.protos.BatchSize.AbsoluteMaxBytes {
return fmt.Errorf("Attempted to set the batch size preferred max bytes (%v) greater than the absolute max bytes (%v).", oc.protos.BatchSize.PreferredMaxBytes, oc.protos.BatchSize.AbsoluteMaxBytes)
}
return nil
}
func (oc *OrdererConfig) validateBatchTimeout() error {
var err error
oc.batchTimeout, err = time.ParseDuration(oc.protos.BatchTimeout.Timeout)
if err != nil {
return fmt.Errorf("Attempted to set the batch timeout to a invalid value: %s", err)View on GitHub (pinned to 2736b63f8f)
Solutions
- Set MaxMessageCount to a positive integer (e.g. 500, the Fabric default) in the channel profile's Orderer.BatchSize section and regenerate the config.
- If constructing ab.BatchSize in code, populate MaxMessageCount before marshaling into the ConfigValue.
- If BatchSize is missing entirely, add the full BatchSize block (MaxMessageCount, AbsoluteMaxBytes, PreferredMaxBytes) to the configtx profile.
- In tests, use a populated BatchSize fixture before calling the validation path.
Example fix
// before (configtx.yaml)
Orderer:
BatchSize:
AbsoluteMaxBytes: 10 MB
PreferredMaxBytes: 2 MB
// after
Orderer:
BatchSize:
MaxMessageCount: 500
AbsoluteMaxBytes: 10 MB
PreferredMaxBytes: 2 MB Defensive patterns
Strategy: validation
Validate before calling
func checkBatchSize(bs *ab.BatchSize) error {
if bs == nil || bs.MaxMessageCount == 0 {
return errors.New("BatchSize.MaxMessageCount must be a positive integer (e.g. 500)")
}
return nil
} Type guard
func hasValidMaxMessageCount(bs *ab.BatchSize) bool {
return bs != nil && bs.MaxMessageCount > 0
} Try / catch
_, err := channelconfig.NewChannelConfig(env.Config)
if err != nil {
if strings.Contains(err.Error(), "max message count to an invalid value: 0") {
return fmt.Errorf("fix Orderer.BatchSize.MaxMessageCount in configtx.yaml (set to e.g. 500) and regenerate: %w", err)
}
return err
} Prevention
- Always include MaxMessageCount in the Orderer.BatchSize section of configtx.yaml profiles.
- Use Fabric defaults (MaxMessageCount: 500) as a starting point.
- Never construct ab.BatchSize without setting all three fields.
- Run configtxgen to validate the profile before channel creation.
When it happens
Trigger: Calling NewOrdererConfig (via NewChannelConfig, or TestBatchSize in tests) with an orderer group whose BatchSize value has MaxMessageCount == 0 — typically because the BatchSize proto was left as a zero-valued struct or only partially populated.
Common situations: Generating channel config programmatically and forgetting to set MaxMessageCount; configtx profiles omitting BatchSize so defaults are never applied; test fixtures constructing ab.BatchSize{} empty; configtxlator edits that zero out the field.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Attempted to set the batch size absolute max bytes to an inv
- Attempted to set the batch size preferred max bytes to an in
- Attempted to set the batch size preferred max bytes (%v) gre
- Attempted to set the batch timeout to a non-positive value:
- unexpected missing policy %s for item %s
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/616122f892be064e.
Report an issue: GitHub.