hyperledger/fabric · error

nil block

Error message

nil block

What it means

EndpointconfigFromConfigBlock in orderer/common/cluster/util.go extracts TLS CA certificates and ordering endpoints from a config block. This error is returned when the *common.Block argument passed to it is nil. The library throws it as a defensive guard, since extracting an envelope from a nil block would otherwise panic with a nil pointer dereference.

Source

Thrown at orderer/common/cluster/util.go:318

	}

	formattedEndpointCriteria := make(map[string]any)
	formattedEndpointCriteria["Endpoint"] = ep.Endpoint
	formattedEndpointCriteria["CAs"] = formattedCAs

	rawJSON, err := json.Marshal(formattedEndpointCriteria)
	if err != nil {
		return fmt.Sprintf("{\"Endpoint\": \"%s\"}", ep.Endpoint)
	}

	return string(rawJSON)
}

// EndpointconfigFromConfigBlock retrieves TLS CA certificates and endpoints
// from a config block.
func EndpointconfigFromConfigBlock(block *common.Block, bccsp bccsp.BCCSP) ([]EndpointCriteria, error) {
	if block == nil {
		return nil, errors.New("nil block")
	}
	envelopeConfig, err := protoutil.ExtractEnvelope(block, 0)
	if err != nil {
		return nil, err
	}

	bundle, err := channelconfig.NewBundleFromEnvelope(envelopeConfig, bccsp)
	if err != nil {
		return nil, errors.Wrap(err, "failed extracting bundle from envelope")
	}
	msps, err := bundle.MSPManager().GetMSPs()
	if err != nil {
		return nil, errors.Wrap(err, "failed obtaining MSPs from MSPManager")
	}
	ordererConfig, ok := bundle.OrdererConfig()
	if !ok {
		return nil, errors.New("failed obtaining orderer config from bundle")
	}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Check why the block was nil before the call: if it came from BlockPuller, inspect the puller's logs (TLS CA errors, endpoint unreachable) and fix the underlying pull failure.
  2. Add an explicit nil check on the block before calling EndpointconfigFromConfigBlock and handle the empty case gracefully.
  3. Ensure the local ledger actually contains the config block being requested (genesis block present; channel joined correctly).
  4. Verify channel/TLS configuration so the puller can retrieve the config block from a valid orderer endpoint.

Example fix

// before
block, _ := puller.PullBlock(targetSeq)
criteria, err := cluster.EndpointconfigFromConfigBlock(block, bccsp) // error: nil block
// after
block, err := puller.PullBlock(targetSeq)
if err != nil { return nil, errors.Wrap(err, "failed pulling config block") }
if block == nil { return nil, errors.New("no config block available") }
criteria, err := cluster.EndpointconfigFromConfigBlock(block, bccsp)
Defensive patterns

Strategy: type-guard

Validate before calling

if block == nil || block.Header == nil {
    return nil, errors.New("cannot extract endpoint config: no config block available")
}
criteria, err := cluster.EndpointconfigFromConfigBlock(block, bccsp)

Type guard

func isConfigBlockReady(b *common.Block) bool { return b != nil && b.Header != nil && b.Data != nil }
// usage: if !isConfigBlockReady(block) { re-pull or abort }

Try / catch

criteria, err := cluster.EndpointconfigFromConfigBlock(block, bccsp)
if err != nil {
    if err.Error() == "nil block" {
        // the puller failed upstream; re-pull the config block and retry once
        block, perr := puller.PullBlock(targetSeq)
        if perr == nil && block != nil { criteria, err = cluster.EndpointconfigFromConfigBlock(block, bccsp) }
    }
    if err != nil { return err }
}

Prevention

When it happens

Trigger: Calling cluster.EndpointconfigFromConfigBlock(nil, bccsp) directly, or indirectly when BlockPuller/EndpointconfigFromSupport passes a nil block — e.g., pullUntilTarget returned nil because the target block could not be pulled, or a caller passed the result of a failed block fetch without a nil check.

Common situations: BlockPuller fails to pull the target block (network/TLS issues, node not joined to the channel) and its nil result flows into endpoint extraction; a genesis/config block lookup returns nil on an empty or uninitialized ledger; chaincode or test code calls the API with an unset block variable.

Related errors


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