hyperledger/fabric · error

Attempted to set the batch size preferred max bytes to an in

Error message

Attempted to set the batch size preferred max bytes to an invalid value: 0

What it means

validateBatchSize requires BatchSize.PreferredMaxBytes to be non-zero; PreferredMaxBytes is the soft target batch size the orderer cuts a block at, and 0 is considered invalid, so orderer config validation fails. This runs as part of OrdererConfig.Validate whenever the orderer group is processed.

Source

Thrown at common/channelconfig/orderer.go:222

		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)
	}
	if oc.batchTimeout <= 0 {
		return fmt.Errorf("Attempted to set the batch timeout to a non-positive value: %s", oc.batchTimeout)
	}
	return nil
}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Set PreferredMaxBytes to a positive value (Fabric default 2097152, i.e. 2 MB) in Orderer.BatchSize and regenerate the config.
  2. Keep PreferredMaxBytes <= AbsoluteMaxBytes to also pass the ordering check that follows.
  3. When constructing ab.BatchSize in code, set all three fields before marshaling.
  4. Validate the profile with configtxgen before channel creation/update.

Example fix

// before (configtx.yaml)
Orderer:
  BatchSize:
    MaxMessageCount: 500
    AbsoluteMaxBytes: 10 MB
// after
Orderer:
  BatchSize:
    MaxMessageCount: 500
    AbsoluteMaxBytes: 10 MB
    PreferredMaxBytes: 2 MB
Defensive patterns

Strategy: validation

Validate before calling

func checkPreferredMaxBytes(bs *ab.BatchSize) error {
	if bs == nil || bs.PreferredMaxBytes == 0 {
		return errors.New("BatchSize.PreferredMaxBytes must be positive (e.g. 2097152 for 2 MB)")
	}
	if bs.PreferredMaxBytes > bs.AbsoluteMaxBytes {
		return errors.New("BatchSize.PreferredMaxBytes must not exceed AbsoluteMaxBytes")
	}
	return nil
}

Type guard

func hasValidPreferredMaxBytes(bs *ab.BatchSize) bool {
	return bs != nil && bs.PreferredMaxBytes > 0 && bs.PreferredMaxBytes <= bs.AbsoluteMaxBytes
}

Try / catch

_, err := channelconfig.NewChannelConfig(env.Config)
if err != nil {
	if strings.Contains(err.Error(), "preferred max bytes to an invalid value: 0") {
		return fmt.Errorf("set Orderer.BatchSize.PreferredMaxBytes (default 2 MB, <= AbsoluteMaxBytes) and regenerate: %w", err)
	}
	return err
}

Prevention

When it happens

Trigger: Calling NewOrdererConfig with an orderer group whose BatchSize value has PreferredMaxBytes == 0 — an empty/partially populated ab.BatchSize proto or a configtx profile missing the PreferredMaxBytes field.

Common situations: configtx.yaml Orderer.BatchSize omitting PreferredMaxBytes while setting the other two fields; programmatic config generation with a partially filled struct; configtxlator edits that drop the field; test fixtures with zero-valued BatchSize.

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


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